]> asedeno.scripts.mit.edu Git - git-svn-keywords.git/commitdiff
Lots of updates
authorAlejandro R. Sedeño <asedeno@mit.edu>
Thu, 11 Feb 2010 16:20:24 +0000 (11:20 -0500)
committerAlejandro R. Sedeño <asedeno@mit.edu>
Thu, 11 Feb 2010 16:20:24 +0000 (11:20 -0500)
* Bump version number to 0.9.1
* Require python 2.6 (for os.path.relpath)
* Refactor config fetching
* Store lastrev for each unhandled.log
* Strip git svn fetch path from paths in unhandled.log

git-svn-keywords.py

index 6ee27af66347dcdd11a954be1a3a1646de1c7792..ba6c2a8b70bef165aaac67e61dd40e4bfe2a8039 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python2.6
 # -*- coding: utf-8 -*-
 
 # Copyright (c) 2009 Alejandro R. Sedeño <asedeno@mit.edu>
@@ -32,7 +32,7 @@ from optparse import OptionParser
 from fnmatch import fnmatch
 import git
 
-VERSION = "0.9"
+VERSION = "0.9.1"
 
 # Where we keep data in the repo.
 def gsk(g):
@@ -66,13 +66,38 @@ def get_svn_keyword_re(s):
         svn_keywords_re[s] = re.compile('\$(' + ('|'.join(svn_keywords[s])) + ')[^$]*\$')
     return svn_keywords_re[s]
 
+def conf_right_version():
+    ver = -1
+    if CONFIG.has_option('core', 'version'):
+        ver = CONFIG.get('core', 'version')
+    return ver == VERSION
+
+def read_file_data():
+    if conf_right_version():
+        FILES.read(FILES_PATH)
+
+def get_last_rev(path):
+    if not CONFIG.has_section(path):
+        CONFIG.add_section(path)
+
+    lastrev = None
+    if conf_right_version() and CONFIG.has_option(path, 'lastrev'):
+        try:
+            lastrev = CONFIG.getint(path, 'lastrev')
+        except ValueError:
+            lastrev = None
+    return lastrev
+
+
 # Parse the unhandled log.
-def _do_parse_unhandled(directory, lastrev=None):
+def _do_parse_unhandled(directory):
     base = os.path.join(directory)
-    rev = None
     for d in os.listdir(base):
         subent = os.path.join(base, d)
         if (d == 'unhandled.log' and os.path.isfile(subent)):
+            rev = None
+            strip_prefix = g.git.config('--get','svn-remote.svn.fetch').split(':')[0]
+            lastrev = get_last_rev(subent)
             with open(subent, 'r') as f:
                 # Compile the regular expressions we'll be using here.
                 re_rev = re.compile("^r(\d+)$")
@@ -90,17 +115,16 @@ def _do_parse_unhandled(directory, lastrev=None):
                     m = re_keywords.match(line)
                     if m:
                         path = urllib.unquote(m.group(1))
+                        path = os.path.relpath(path, strip_prefix)
                         keywords = set(urllib.unquote(m.group(2)).split(' '))
                         if not FILES.has_section(path):
                             FILES.add_section(path)
                         FILES.set(path, rev, keywords)
+            if rev:
+                lastrev = max(int(rev), lastrev)
+                CONFIG.set(subent, 'lastrev', lastrev)
         elif (os.path.isdir(subent)):
-            _do_parse_unhandled(subent, lastrev=lastrev)
-
-    if rev:
-        lastrev = max(int(rev), lastrev)
-        CONFIG.set('core', 'lastrev', lastrev)
-    CONFIG.set('core', 'version', VERSION)
+            _do_parse_unhandled(subent)
 
 def parse_svn_unhandled(g):
     try:
@@ -109,20 +133,8 @@ def parse_svn_unhandled(g):
         if e.errno != errno.EEXIST:
             raise
 
-    ver = -1
-    if CONFIG.has_option('core', 'version'):
-        ver = CONFIG.get('core', 'version')
-
-    lastrev = None
-    if ver == VERSION:
-        FILES.read(FILES_PATH)
-        if CONFIG.has_option('core', 'lastrev'):
-            try:
-                lastrev = CONFIG.getint('core', 'lastrev')
-            except ValueError:
-                lastrev = None
-
-    _do_parse_unhandled(os.path.join(g.path, 'svn'), lastrev=lastrev)
+    _do_parse_unhandled(os.path.join(g.path, 'svn'))
+    CONFIG.set('core', 'version', VERSION)
 
     with open(FILES_PATH, 'wb') as f:
         FILES.write(f)
@@ -179,6 +191,7 @@ def find_last_svn_rev(treeish, parent=0):
 
 # Do the work.
 def smudge(g, options):
+    read_file_data()
     parse_svn_unhandled(g)
     rev_head = find_last_svn_rev('HEAD')
     url_base = g.git.svn('info', '--url')