-#!/usr/bin/python
+#!/usr/bin/python2.6
# -*- coding: utf-8 -*-
# Copyright (c) 2009 Alejandro R. Sedeño <asedeno@mit.edu>
from fnmatch import fnmatch
import git
-VERSION = "0.9"
+VERSION = "0.9.1"
# Where we keep data in the repo.
def gsk(g):
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+)$")
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:
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)
# 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')