Parcourir la source

Avoid using regular expressions for gitfile parsing.

Jelmer Vernooij il y a 9 ans
Parent
commit
304dae8bbf
2 fichiers modifiés avec 17 ajouts et 3 suppressions
  1. 17 2
      dulwich/repo.py
  2. 0 1
      relicensing-apachev2.txt

+ 17 - 2
dulwich/repo.py

@@ -632,6 +632,21 @@ class BaseRepo(object):
         return c.id
 
 
+
+def read_gitfile(f):
+    """Read a ``.git`` file.
+
+    The first line of the file should start with "gitdir: "
+
+    :param f: File-like object to read from
+    :return: A path
+    """
+    cs = f.read()
+    if not cs.startswith("gitdir: "):
+        raise ValueError("Expected file to start with 'gitdir: '")
+    return cs[len("gitdir: "):].rstrip("\n")
+
+
 class Repo(BaseRepo):
     """A git repository backed by local disk.
 
@@ -651,9 +666,9 @@ class Repo(BaseRepo):
             self.bare = True
             self._controldir = root
         elif os.path.isfile(hidden_path):
-            import re
+            self.bare = False
             with open(hidden_path, 'r') as f:
-                _, path = re.match('(gitdir: )(.+$)', f.read()).groups()
+                path = read_gitfile(f)
             self.bare = False
             self._controldir = os.path.join(root, path)
         else:

+ 0 - 1
relicensing-apachev2.txt

@@ -18,7 +18,6 @@ under dual Apachev2/GPLv2:
 Artem Tikhomirov <artem.tikhomirov@syntevo.com>
 Dmitriy <dkomarov@gmail.com>
 Gary van der Merwé <garyvdm@gmail.com>
-Nick Ward <ward.nickjames@gmail.com>
 Risto Kankkunen <risto.kankkunen@f-secure.com> <risto.kankkunen@iki.fi>
 
 If your name is in this list and you'd be happy to relicense your contribution