4 # This python program has been copied from
5 # https://github.com/GNOME/gnet/blob/master/gen-changelog.py
7 # It has been authored by Edward Hervey, of GStreamer fame. I have
8 # asked his permission to copy it and re-use it here, as part of the
9 # Libabigail project. He granted me the permission to distribute the
10 # program under the terms of the GNU Lesser Public License as
11 # published by the Free Software Foundaion; either version 2, or (at
12 # your option) any later version.
14 # Thus, this program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU Lesser General Public License
16 # as published by the Free Software Foundation; either version 2, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 # General Lesser Public License for more details.
24 # You should have received a copy of the GNU Lesser General Public
25 # License along with this program; see the file COPYING-LGPLV2. If
26 # not, see <http://www.gnu.org/licenses/>.
32 # Makes a GNU-Style ChangeLog from a git repository
33 # Handles git-svn repositories also
35 # Arguments : same as for git log
38 def process_commit(lines, files):
46 lines = [x.strip() for x in lines if x.strip() and not x.startswith('git-svn-id')]
47 files = [x.strip() for x in files if x.strip()]
49 if l.startswith('* '):
54 subject_line_index = 0 if lines[1].startswith('*') else 1;
55 first_cl_body_line_index = 0;
57 for i in range(1, len(lines)):
58 if lines[i].startswith('*'):
59 first_cl_body_line_index = i
62 # Clean up top line of ChangeLog entry:
63 fields = top_line.split(' ')
65 # 1. remove the time and timezone stuff in "2008-05-13 07:10:28 +0000 name"
66 if fields[2].startswith('+') or fields[2].startswith('-'):
68 if fields[1][2] == ':' and fields[1][5] == ':':
71 # 2. munge at least my @src.gnome.org e-mail address...
72 if fields[-1] == '<tpm@src.gnome.org>':
73 fields[-1] = '<tim@centricular.net>'
75 top_line = ' '.join(fields)
76 print top_line.strip()
79 if subject_line_index > 0:
80 print '\t', lines[subject_line_index]
87 if first_cl_body_line_index > 0:
88 for l in lines[first_cl_body_line_index:]:
89 if l.startswith('Signed-off-by:'):
95 cmd = ['git', 'log', '--pretty=format:--START-COMMIT--%H%n%ai %an <%ae>%n%n%s%n%b%n--END-COMMIT--',
96 '--date=short', '--name-only']
98 start_tag = find_start_tag()
100 if start_tag is None:
101 cmd.extend(sys.argv[1:])
103 cmd.extend(["%s..HEAD" % (start_tag)])
105 p = subprocess.Popen(args=cmd, shell=False, stdout=subprocess.PIPE)
109 for lin in p.stdout.readlines():
110 if lin.startswith("--START-COMMIT--"):
112 process_commit(buf, files)
113 hash = lin[16:].strip()
115 rel = release_refs[hash]
116 print "=== release %d.%d.%d ===\n" % (int(rel[0]), int(rel[1]), int(rel[2]))
122 elif lin.startswith("--END-COMMIT--"):
124 elif filemode == True:
129 process_commit(buf, files)
132 # Populate the release_refs dict with the tags for previous releases
133 reltagre = re.compile("^([a-z0-9]{40}) refs\/tags\/GNET-([0-9]+)[-_.]([0-9]+)[-_.]([0-9]+)")
135 cmd = ['git', 'show-ref', '--tags', '--dereference']
136 p = subprocess.Popen(args=cmd, shell=False, stdout=subprocess.PIPE)
137 for lin in p.stdout.readlines():
138 match = reltagre.search (lin)
140 (sha, maj, min, nano) = match.groups()
141 release_refs[sha] = (maj, min, nano)
143 def find_start_tag():
144 starttagre = re.compile("^([a-z0-9]{40}) refs\/tags\/CHANGELOG_START")
145 cmd = ['git', 'show-ref', '--tags']
146 p = subprocess.Popen(args=cmd, shell=False, stdout=subprocess.PIPE)
147 for lin in p.stdout.readlines():
148 match = starttagre.search (lin)
150 return match.group(1)
153 if __name__ == "__main__":