[gnome-python-desktop] ChangeLog generation from GIT
- From: Gustavo J. A. M. Carneiro <gjc src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-python-desktop] ChangeLog generation from GIT
- Date: Sun, 3 May 2009 13:17:41 -0400 (EDT)
commit 4fd0cd538185621f70398e1e2cd9f0bdeadf9e25
Author: Gustavo Carneiro <gjc inescporto pt>
Date: Sat May 2 17:13:02 2009 +0100
ChangeLog generation from GIT
---
generate-ChangeLog | 27 ++++++++---
gitlog2changelog.py | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 144 insertions(+), 7 deletions(-)
diff --git a/generate-ChangeLog b/generate-ChangeLog
index 27b47ef..19b932b 100755
--- a/generate-ChangeLog
+++ b/generate-ChangeLog
@@ -1,12 +1,25 @@
#!/bin/sh
-## Uses the GNU ChangeLog formatter plugin:
-## http://telecom.inescporto.pt/~gjc/gnulog.py
-
-export BZR_PLUGIN_PATH=`pwd`/bzrplugins
-
ChangeLog=$(dirname $0)/ChangeLog
-
chmod u+w $ChangeLog 2> /dev/null
-bzr log -v --log-format 'gnu' -r 410..-1 > $ChangeLog
+
+if [ -d .bzr ]; then
+ ## Uses the GNU ChangeLog formatter plugin:
+ ## http://telecom.inescporto.pt/~gjc/gnulog.py
+ export BZR_PLUGIN_PATH=`pwd`/bzrplugins
+ bzr log -v --log-format 'gnu' -r 538..-1 > $ChangeLog
+
+elif [ -d .git ]; then
+
+ $(dirname $0)/gitlog2changelog.py
+
+else
+
+ echo "ERROR: not a bzr or git repository, cannot generate ChangeLog."
+ exit 2;
+
+fi
+
chmod a-w $ChangeLog
+
+
diff --git a/gitlog2changelog.py b/gitlog2changelog.py
new file mode 100755
index 0000000..ce69b68
--- /dev/null
+++ b/gitlog2changelog.py
@@ -0,0 +1,124 @@
+#!/usr/bin/python
+# Copyright 2008 Marcus D. Hanwell <marcus cryos org>
+# Distributed under the terms of the GNU General Public License v2 or later
+
+import string, re, os
+
+# Execute git log with the desired command line options.
+fin = os.popen('git log --summary --stat --no-merges --date=short', 'r')
+# Create a ChangeLog file in the current directory.
+fout = open('ChangeLog', 'w')
+
+# Set up the loop variables in order to locate the blocks we want
+authorFound = False
+dateFound = False
+messageFound = False
+filesFound = False
+message = ""
+messageNL = False
+files = ""
+prevAuthorLine = ""
+
+# The main part of the loop
+for line in fin:
+ # The commit line marks the start of a new commit object.
+ if string.find(line, 'commit') >= 0:
+ # Start all over again...
+ authorFound = False
+ dateFound = False
+ messageFound = False
+ messageNL = False
+ message = ""
+ filesFound = False
+ files = ""
+ continue
+ # Match the author line and extract the part we want
+ elif re.match('Author:', line) >=0:
+ authorList = re.split(': ', line, 1)
+ author = authorList[1]
+ author = author[0:len(author)-1]
+ authorFound = True
+ # Match the date line
+ elif re.match('Date:', line) >= 0:
+ dateList = re.split(': ', line, 1)
+ date = dateList[1]
+ date = date[0:len(date)-1]
+ dateFound = True
+ # The svn-id lines are ignored
+ elif re.match(' git-svn-id:', line) >= 0:
+ continue
+ # The sign off line is ignored too
+ elif re.search('Signed-off-by', line) >= 0:
+ continue
+ # Extract the actual commit message for this commit
+ elif authorFound & dateFound & messageFound == False:
+ # Find the commit message if we can
+ if len(line) == 1:
+ if messageNL:
+ messageFound = True
+ else:
+ messageNL = True
+ elif len(line) == 4:
+ messageFound = True
+ else:
+ if len(message) == 0:
+ message = message + line.strip()
+ else:
+ message = message + " " + line.strip()
+ # If this line is hit all of the files have been stored for this commit
+ elif re.search('files changed', line) >= 0:
+ filesFound = True
+ continue
+ # Collect the files for this commit. FIXME: Still need to add +/- to files
+ elif authorFound & dateFound & messageFound:
+ fileList = re.split(' \| ', line, 2)
+ if len(fileList) > 1:
+ if len(files) > 0:
+ files = files + ", " + fileList[0].strip()
+ else:
+ files = fileList[0].strip()
+ # All of the parts of the commit have been found - write out the entry
+ if authorFound & dateFound & messageFound & filesFound:
+ # First the author line, only outputted if it is the first for that
+ # author on this day
+ authorLine = date + " " + author
+ if len(prevAuthorLine) == 0:
+ fout.write(authorLine + "\n")
+ elif authorLine == prevAuthorLine:
+ pass
+ else:
+ fout.write("\n" + authorLine + "\n")
+
+ # Assemble the actual commit message line(s) and limit the line length
+ # to 80 characters.
+ commitLine = "* " + files + ": " + message
+ i = 0
+ commit = ""
+ while i < len(commitLine):
+ if len(commitLine) < i + 78:
+ commit = commit + "\n " + commitLine[i:len(commitLine)]
+ break
+ index = commitLine.rfind(' ', i, i+78)
+ if index > i:
+ commit = commit + "\n " + commitLine[i:index]
+ i = index+1
+ else:
+ commit = commit + "\n " + commitLine[i:78]
+ i = i+79
+
+ # Write out the commit line
+ fout.write(commit + "\n")
+
+ #Now reset all the variables ready for a new commit block.
+ authorFound = False
+ dateFound = False
+ messageFound = False
+ messageNL = False
+ message = ""
+ filesFound = False
+ files = ""
+ prevAuthorLine = authorLine
+
+# Close the input and output lines now that we are finished.
+fin.close()
+fout.close()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]