11 return os.popen (x).read ()
16 class PatchFailed(Exception):
20 def __init__ (self, dict):
25 self.__dict__[v] = dict[v]
27 # Sat Oct 28 18:52:30 2006 +0200
29 self.date = ' '.join (self.date.split (' ')[:-1])
30 self.date = time.strptime (self.date, '%a %b %d %H:%M:%S %Y')
32 m = re.search ('(.*)<(.*)>', self.author)
33 self.email = m.group (2).strip ()
34 self.name = m.group (1).strip ()
35 self.diff = read_pipe ('git show %s' % self.committish)
37 def touched_files (self):
40 files.append (x.group (1))
43 re.sub ('\n--- a/([^\n]+)\n',
45 re.sub('\n--- /dev/null\n\\+\\+\\+ b/([^\n]+)',
50 def apply (self, add_del_files):
51 def note_add_file (x):
52 add_del_files.append (('add', x.group (1)))
55 def note_del_file (x):
56 add_del_files.append (('del', x.group (1)))
59 re.sub('\n--- /dev/null\n\\+\\+\\+ b/([^\n]+)',
60 note_add_file, self.diff)
62 re.sub('\n--- a/([^\n]+)\n\\+\\+\\+ /dev/null',
63 note_del_file, self.diff)
65 p = os.popen ('patch -f -p1 ', 'w')
69 raise PatchFailed, self.committish
72 def parse_commit_log (log):
73 committish = re.search ('^([^\n]+)', log).group (1)
74 author = re.search ('\nAuthor:\s+([^\n]+)', log).group (1)
75 date_match = re.search ('\nDate:\s+([^\n]+)', log)
76 date = date_match.group (1)
77 log = log[date_match.end (1):]
79 message = re.sub ("\n *", '', log)
80 message = message.strip ()
82 c = Commit (locals ())
85 def parse_add_changes (from_commit):
87 log = read_pipe ('git log %(from_commit)s..' % locals ())
89 log = log[len ('commit '):]
95 commits = map (parse_commit_log, re.split ('\ncommit ', log))
102 return '%d-%02d-%02d %s <%s>\n' % (commit.date[:3] + (commit.name, commit.email))
104 def changelog_body (commit):
107 s += ''.join ('\n* %s: ' % f for f in commit.touched_files())
108 s += '\n' + commit.message
110 s = s.replace ('\n', '\n\t')
115 p = optparse.OptionParser (usage="usage git-update-changelog.py [options]",
117 Apply GIT patches and update change log.
119 Run this file from the CVS directory, with --git-dir
121 p.add_option ("--start",
125 help="start of log messages to merge.")
127 p.add_option ("--git-dir",
131 help="the GIT directory to merge.")
133 (options, args) = p.parse_args ()
135 log = open ('ChangeLog').read ()
137 if not options.start:
138 print 'Must set start committish.'
142 os.environ['GIT_DIR'] = options.gitdir
144 commits = parse_add_changes (options.start)
151 first = header (commits[0]) + '\n'
152 if first == log[:len (first)]:
153 log = log[len (first):]
157 print 'patch ', c.committish
159 c.apply (file_adddel)
163 if c.touched_files () == ['ChangeLog']:
167 and c.author != last_commit.author
168 and c.date[:3] != last_commit.date[:3]):
170 new_log += header (last_commit)
172 new_log += changelog_body (c)
175 for (op, f) in file_adddel:
177 system ('cvs remove %(f)s' % locals ())
179 system ('cvs add %(f)s' % locals ())
181 new_log = header (last_commit) + new_log + '\n'
186 os.unlink ('ChangeLog~')
190 os.rename ('ChangeLog', 'ChangeLog~')
191 open ('ChangeLog', 'w').write (log)