def read_pipe (x):
print 'pipe', x
return os.popen (x).read ()
+def system (x):
+ print x
+ return os.system (x)
+
+class PatchFailed(Exception):
+ pass
class Commit:
def __init__ (self, dict):
self.date = ' '.join (self.date.split (' ')[:-1])
self.date = time.strptime (self.date, '%a %b %d %H:%M:%S %Y')
-
+
m = re.search ('(.*)<(.*)>', self.author)
- self.email = m.group (2)
- self.name = m.group (1)
-
+ self.email = m.group (2).strip ()
+ self.name = m.group (1).strip ()
+ self.diff = read_pipe ('git show %s' % self.committish)
def touched_files (self):
files = []
def note_file (x):
files.append (x.group (1))
return ''
-
- diff = read_pipe ('git show %s' % self.committish)
+
re.sub ('\n--- a/([^\n]+)\n',
- note_file, diff)
+ note_file, self.diff)
re.sub('\n--- /dev/null\n\\+\\+\\+ b/([^\n]+)',
- note_file, diff)
+ note_file, self.diff)
return files
-def parse_commit_log (log):
- print log
+ def apply (self, add_del_files):
+ def note_add_file (x):
+ add_del_files.append (('add', x.group (1)))
+ return ''
+
+ def note_del_file (x):
+ add_del_files.append (('del', x.group (1)))
+ return ''
+
+
+ re.sub('\n--- /dev/null\n\\+\\+\\+ b/([^\n]+)',
+ note_add_file, self.diff)
+
+ re.sub('\n--- a/([^\n]+)\n\\+\\+\\+ /dev/null',
+ note_del_file, self.diff)
+
+ p = os.popen ('patch -f -p1 ', 'w')
+ p.write (self.diff)
+
+ if p.close ():
+ raise PatchFailed, self.committish
+
+def parse_commit_log (log):
committish = re.search ('^([^\n]+)', log).group (1)
author = re.search ('\nAuthor:\s+([^\n]+)', log).group (1)
date_match = re.search ('\nDate:\s+([^\n]+)', log)
return []
commits = map (parse_commit_log, re.split ('\ncommit ', log))
+ commits.reverse ()
return commits
def main ():
- p = optparse.OptionParser ("usage git-update-changelog.py --options")
+ p = optparse.OptionParser (usage="usage git-update-changelog.py [options]",
+ description="""
+Apply GIT patches and update change log.
+
+Run this file from the CVS directory, with --git-dir
+""")
p.add_option ("--start",
action='store',
default='',
dest="start",
help="start of log messages to merge.")
+
+ p.add_option ("--git-dir",
+ action='store',
+ default='',
+ dest="gitdir",
+ help="the GIT directory to merge.")
(options, args) = p.parse_args ()
print 'processing commits from ', id, options.start
+ if options.gitdir:
+ os.environ['GIT_DIR'] = options.gitdir
+
commits = parse_add_changes (options.start)
if not commits:
return
first = header (commits[0]) + '\n'
if first == log[:len (first)]:
log = log[len (first):]
-
+
+ file_adddel = []
for c in commits:
+ print 'patch ', c.committish
+ try:
+ c.apply (file_adddel)
+ except PatchFailed:
+ break
+
if c.touched_files () == ['ChangeLog']:
continue
new_log += changelog_body (c)
last_commit = c
+ for (op, f) in file_adddel:
+ if op == 'del':
+ system ('cvs remove %(f)s' % locals ())
+ if op == 'add':
+ system ('cvs add %(f)s' % locals ())
+
new_log = header (last_commit) + new_log + '\n'
log = new_log + log
+
try:
os.unlink ('ChangeLog~')
- except IOError:
+ except OSError:
pass
os.rename ('ChangeLog', 'ChangeLog~')