#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright (c) 2009 Alejandro R. SedeƱo # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation files # (the "Software"), to deal in the Software without restriction, # including without limitation the rights to use, copy, modify, merge, # publish, distribute, sublicense, and/or sell copies of the Software, # and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # git svn keyword parsing, populating, and clearing. from __future__ import with_statement import ConfigParser, errno, os, re, urllib import git VERSION = 0 def parse_svn_unhandled(g): gsk = g.path + '/svn_keywords' try: os.mkdir(gsk) except os.error, e: if e.errno != errno.EEXIST: raise config = ConfigParser.ConfigParser() config_path = gsk + '/conf.ini' config.read(config_path) files = ConfigParser.ConfigParser() files_path = gsk + '/files.ini' if not config.has_section('core'): config.add_section('core') if config.has_option('core', 'version'): ver = config.getint('core', 'ver') 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) with open(files_path, 'wb') as f: files.write(f) with open(config_path, 'wb') as f: config.write(f) def smudge(g): return 0 def clean(g): return 0 if __name__ == '__main__': try: g = git.Repo() except git.errors.InvalidGitRepositoryError: print "You are not in a git repository or working directory." exit(1) parse_svn_unhandled(g)