Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gitlog2changelog.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 # Copyright 2008 Marcus D. Hanwell <marcus@cryos.org>
3 # Distributed under the terms of the GNU General Public License v2 or later
4 
5 import string, re, os, sys
6 
7 # Execute git log with the desired command line options.
8 fin = os.popen('git log --summary --stat --no-merges --date=short', 'r')
9 fout = sys.stdout
10 
11 # Set up the loop variables in order to locate the blocks we want
12 authorFound = False
13 dateFound = False
14 messageFound = False
15 filesFound = False
16 message = ""
17 messageNL = False
18 files = ""
19 prevAuthorLine = ""
20 
21 # The main part of the loop
22 for line in fin:
23  # The commit line marks the start of a new commit object.
24  if string.find(line, 'commit') >= 0:
25  # Start all over again...
26  authorFound = False
27  dateFound = False
28  messageFound = False
29  messageNL = False
30  message = ""
31  filesFound = False
32  files = ""
33  continue
34  # Match the author line and extract the part we want
35  elif re.match('Author:', line) >=0:
36  authorList = re.split(': ', line, 1)
37  author = authorList[1]
38  author = author[0:len(author)-1]
39  authorFound = True
40  # Match the date line
41  elif re.match('Date:', line) >= 0:
42  dateList = re.split(': ', line, 1)
43  date = dateList[1]
44  date = date[0:len(date)-1]
45  date = date.strip()
46  dateFound = True
47  # The svn-id lines are ignored
48  elif re.match(' git-svn-id:', line) >= 0:
49  continue
50  # The sign off line is ignored too
51  elif re.search('Signed-off-by', line) >= 0:
52  continue
53  # Extract the actual commit message for this commit
54  elif authorFound & dateFound & messageFound == False:
55  # Find the commit message if we can
56  if len(line) == 1:
57  if messageNL:
58  messageFound = True
59  else:
60  messageNL = True
61  elif len(line) == 4:
62  messageFound = True
63  elif line[0:6] == ' * ':
64  messageFound = True
65  else:
66  if len(message) == 0:
67  message = message + line.strip()
68  else:
69  message = message + " " + line.strip()
70  # If this line is hit all of the files have been stored for this commit
71  elif re.search('files changed', line) >= 0:
72  filesFound = True
73  continue
74  # Collect the files for this commit. FIXME: Still need to add +/- to files
75  elif authorFound & dateFound & messageFound:
76  fileList = re.split(' \| ', line, 2)
77  if len(fileList) > 1:
78  if len(files) > 0:
79  files = files + ", " + fileList[0].strip()
80  else:
81  files = fileList[0].strip()
82  # All of the parts of the commit have been found - write out the entry
83  if authorFound & dateFound & messageFound & filesFound:
84  # First the author line, only outputted if it is the first for that
85  # author on this day
86  authorLine = date + " " + author
87  if len(prevAuthorLine) == 0:
88  fout.write(authorLine + "\n")
89  elif authorLine == prevAuthorLine:
90  pass
91  else:
92  fout.write("\n" + authorLine + "\n")
93 
94  # Assemble the actual commit message line(s) and limit the line length
95  # to 80 characters.
96  commitLine = "* " + files + ": " + message
97  i = 0
98  commit = ""
99  while i < len(commitLine):
100  if len(commitLine) < i + 71:
101  commit = commit.rstrip() + "\n\t" + commitLine[i:len(commitLine)]
102  break
103  index = commitLine.rfind(' ', i, i+71)
104  if index > i:
105  commit = commit.rstrip() + "\n\t" + commitLine[i:index]
106  i = index+1
107  else:
108  commit = commit.rstrip() + "\n\t" + commitLine[i:71]
109  i = i+72
110 
111  # Write out the commit line
112  fout.write(commit.rstrip() + "\n")
113 
114  #Now reset all the variables ready for a new commit block.
115  authorFound = False
116  dateFound = False
117  messageFound = False
118  messageNL = False
119  message = ""
120  filesFound = False
121  files = ""
122  prevAuthorLine = authorLine
123 
124 # Close the input and output lines now that we are finished.
125 fin.close()
126 fout.close()