7 def __init__ (self, dict):
12 self.__dict__[v] = dict[v]
14 # Sat Oct 28 18:52:30 2006 +0200
16 self.date = ' '.join (self.date.split (' ')[:-1])
17 self.date = time.strptime (self.date, '%a %b %d %H:%M:%S %Y')
19 m = re.search ('(.*)<(.*)>', self.author)
20 self.email = m.group (2)
21 self.name = m.group (1)
23 def touched_files (self):
27 files.append (x.group (1))
30 diff = os.popen ('git show %s' % self.committish).read ()
31 re.sub ('\n--- a/([^\n]+)\n',
33 re.sub('\n--- /dev/null\n\\+\\+\\+ b/([^\n]+)',
38 def parse_commit_log (log):
39 committish = re.search ('^([^\n]+)', log).group (1)
40 author = re.search ('\nAuthor:\s+([^\n]+)', log).group (1)
41 date_match = re.search ('\nDate:\s+([^\n]+)', log)
42 date = date_match.group (1)
43 log = log[date_match.end (1):]
45 message = re.sub ("\n *", '', log)
46 message = message.strip ()
48 c = Commit (locals ())
51 def parse_add_changes (from_commit):
52 log = os.popen ('git log %(from_commit)s..' % locals ()).read ()
54 log = log[len ('commit '):]
55 commits = map (parse_commit_log, re.split ('\ncommit ', log))
62 return '%d-%02d-%02d %s <%s>\n' % (commit.date[:3] + (commit.name, commit.email))
64 def changelog_body (commit):
67 s += "\ngit commit %s\n" % commit.committish
68 s += ''.join ('\n* %s: ' % f for f in commit.touched_files())
69 s += '\n' + commit.message
71 s = s.replace ('\n', '\n\t')
75 def to_change_log (commit, last_commit):
79 date = commit.date[:3]
80 if (last_commit == None
81 or commit.author != last_commit.author
82 or commit.date[:3] != last_commit.date[:3]):
84 s += header (last_commit)
86 s += changelog_body (commit)
90 def find_last_checked_in_commit (log):
91 m = re.search (r'^(\d+-\d+\d+)[^\n]+\n*\t\*git commit ([a-f0-9]+):', log)
94 return (m.group (0), m.group (1))
102 p = optparse.OptionParser ("usage git-update-changelog.py --options")
103 p.add_option ("--start",
107 help="start of log messages to merge.")
109 (options, args) = p.parse_args ()
111 log = open ('ChangeLog').read ()
113 if not options.start:
114 options.start = find_last_checked_in_commit (log)
116 commits = parse_add_changes (options.start)
124 first = header (commits[0])
125 if first == log[:len (first)]:
126 log = log[len (first):]
130 and c.author != last_commit.author
131 and c.date[:3] != last_commit.date[:3]):
133 new_log += header (last_commit)
135 new_log += changelog_body (c)
138 new_log = header (last_commit) + new_log + '\n'
142 os.unlink ('ChangeLog~')
146 os.rename ('ChangeLog', 'ChangeLog~')
147 open ('ChangeLog', 'w').write (log)