]> asedeno.scripts.mit.edu Git - git-svn-keywords.git/commitdiff
Refactor parsing on the unhandled.log file
authorAlejandro R. Sedeño <asedeno@mit.edu>
Tue, 9 Feb 2010 15:59:27 +0000 (10:59 -0500)
committerAlejandro R. Sedeño <asedeno@mit.edu>
Tue, 9 Feb 2010 15:59:27 +0000 (10:59 -0500)
Split off opening from reading, so we can try locations for the unhandled.log.

git-svn-keywords.py

index ae62300e9054098753dbf5782e4c6cd67b16adb2..bf8191c68607dc58d91bf3282f8f403be1dd90c4 100755 (executable)
@@ -67,6 +67,33 @@ def get_svn_keyword_re(s):
     return svn_keywords_re[s]
 
 # Parse the unhandled log.
+def _do_parse_unhandled(f, lastrev=None):
+    # Compile the regular expressions we'll be using here.
+    re_rev = re.compile("^r(\d+)$")
+    re_keywords = re.compile("^\s+[-+]file_prop: (\S+) svn:keywords ?(\S*)$")
+
+    rev = None
+    for line in f:
+        m = re_rev.match(line)
+        if m:
+            rev = m.group(1)
+            continue
+
+        if (lastrev >= int(rev)):
+            continue
+
+        m = re_keywords.match(line)
+        if m:
+            path = urllib.unquote(m.group(1))
+            keywords = set(urllib.unquote(m.group(2)).split(' '))
+            if not FILES.has_section(path):
+                FILES.add_section(path)
+            FILES.set(path, rev, keywords)
+
+    lastrev = max(int(rev), lastrev)
+    CONFIG.set('core', 'lastrev', lastrev)
+    CONFIG.set('core', 'version', VERSION)
+
 def parse_svn_unhandled(g):
     try:
         os.mkdir(gsk(g))
@@ -84,32 +111,8 @@ def parse_svn_unhandled(g):
         if CONFIG.has_option('core', 'lastrev'):
             lastrev = CONFIG.getint('core', 'lastrev')
 
-    with open(g.path + '/svn/git-svn/unhandled.log', 'r') as f:
-        # Compile the regular expressions we'll be using here.
-        re_rev = re.compile("^r(\d+)$")
-        re_keywords = re.compile("^\s+[-+]file_prop: (\S+) svn:keywords ?(\S*)$")
-
-        rev = None
-        for line in f:
-            m = re_rev.match(line)
-            if m:
-                rev = m.group(1)
-                continue
-
-            if (lastrev >= int(rev)):
-                continue
-
-            m = re_keywords.match(line)
-            if m:
-                path = urllib.unquote(m.group(1))
-                keywords = set(urllib.unquote(m.group(2)).split(' '))
-                if not FILES.has_section(path):
-                    FILES.add_section(path)
-                FILES.set(path, rev, keywords)
-
-        lastrev = max(int(rev), lastrev)
-        CONFIG.set('core', 'lastrev', lastrev)
-        CONFIG.set('core', 'version', VERSION)
+    with open(g.path + '/svn/refs/remotes/git-svn/unhandled.log', 'r') as f:
+        _do_parse_unhandled(f, lastrev=lastrev)
 
     with open(FILES_PATH, 'wb') as f:
         FILES.write(f)