-#!/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):
+ base = os.path.join(directory)
+ 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+)$")
+ re_keywords = re.compile("^\s+[-+]file_prop: (\S+) svn:keywords ?(\S*)$")
+
+ 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))
+ 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)
+
def parse_svn_unhandled(g):
try:
os.mkdir(gsk(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'):
- 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)
+ _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')
ignore = True
if ignore:
continue
-
- kw_rev = max(filter(lambda x: x <= rev_head, map(int, FILES.options(path))))
+ try:
+ kw_rev = max(filter(lambda x: x <= rev_head, map(int, FILES.options(path))))
+ except ValueError:
+ continue
info_dict = {}
if not options.clean:
print "You are not in a git repository or working directory."
exit(1)
+ if g.bare:
+ print "This appears to be a bare git repository."
+ exit(1)
+
+ os.chdir(g.wd)
+
CONFIG_PATH = os.path.join(gsk(g), 'conf.ini')
FILES_PATH = os.path.join(gsk(g), 'files.ini')
FILEINFO_PATH = os.path.join(gsk(g), 'fileinfo.ini')