11 return os.popen (x).read ()
16 class PatchFailed(Exception):
20 def __init__ (self, dict):
25 self.__dict__[v] = dict[v]
27 self.date = ' '.join (self.date.split (' ')[:-1])
28 self.date = time.strptime (self.date, '%a %b %d %H:%M:%S %Y')
30 m = re.search ('(.*)<(.*)>', self.author)
31 self.email = m.group (2).strip ()
32 self.name = m.group (1).strip ()
33 self.diff = read_pipe ('git show %s' % self.committish)
35 def touched_files (self):
38 files.append (x.group (1))
41 re.sub ('\n--- a/([^\n]+)\n',
43 re.sub('\n--- /dev/null\n\\+\\+\\+ b/([^\n]+)',
48 def apply (self, add_del_files):
49 def note_add_file (x):
50 add_del_files.append (('add', x.group (1)))
53 def note_del_file (x):
54 add_del_files.append (('del', x.group (1)))
57 re.sub('\n--- /dev/null\n\\+\\+\\+ b/([^\n]+)',
58 note_add_file, self.diff)
60 re.sub('\n--- a/([^\n]+)\n\\+\\+\\+ /dev/null',
61 note_del_file, self.diff)
63 p = os.popen ('patch -f -p1 ', 'w')
67 raise PatchFailed, self.committish
70 def parse_commit_log (log):
71 committish = re.search ('^([^\n]+)', log).group (1)
72 author = re.search ('\nAuthor:\s+([^\n]+)', log).group (1)
73 date_match = re.search ('\nDate:\s+([^\n]+)', log)
74 date = date_match.group (1)
75 log = log[date_match.end (1):]
77 message = re.sub ("\n *", '', log)
78 message = message.strip ()
80 c = Commit (locals ())
83 def parse_add_changes (from_commit):
85 log = read_pipe ('git log %(from_commit)s..' % locals ())
87 log = log[len ('commit '):]
93 commits = map (parse_commit_log, re.split ('\ncommit ', log))
100 return '%d-%02d-%02d %s <%s>\n' % (commit.date[:3] + (commit.name, commit.email))
102 def changelog_body (commit):
104 s += ''.join ('\n* %s: ' % f for f in commit.touched_files())
105 s += '\n' + commit.message
107 s = s.replace ('\n', '\n\t')
112 p = optparse.OptionParser (usage="usage git-update-changelog.py [options]",
114 Apply GIT patches and update change log.
116 Run this file from the CVS directory, with --git-dir
118 p.add_option ("--start",
122 help="start of log messages to merge.")
124 p.add_option ("--git-dir",
128 help="the GIT directory to merge.")
130 (options, args) = p.parse_args ()
132 log = open ('ChangeLog').read ()
134 if not options.start:
135 print 'Must set start committish.'
139 os.environ['GIT_DIR'] = options.gitdir
141 commits = parse_add_changes (options.start)
148 first = header (commits[0]) + '\n'
149 if first == log[:len (first)]:
150 log = log[len (first):]
156 print 'patch ', c.committish
158 c.apply (file_adddel)
162 if c.touched_files () == ['ChangeLog']:
166 and c.author != last_commit.author
167 and c.date[:3] != last_commit.date[:3]):
169 new_log += header (last_commit)
171 new_log = changelog_body (c) + new_log
174 # FIXME: correct fix?
175 # final_log += self.message + '\n'
179 for (op, f) in file_adddel:
181 system ('cvs remove %(f)s' % locals ())
183 system ('cvs add %(f)s' % locals ())
185 new_log = header (last_commit) + new_log + '\n'
190 os.unlink ('ChangeLog~')
194 os.rename ('ChangeLog', 'ChangeLog~')
195 open ('ChangeLog', 'w').write (log)
197 open ('.msg','w').write (final_log)
198 print 'cvs commit -F .msg '