2 # Copyright 2008 Marcus D. Hanwell <marcus@cryos.org>
3 # Distributed under the terms of the GNU General Public License v2 or later
5 # Modified by (C) 2012-2014 TAMUKI Shoichi <tamuki@linet.gr.jp>
9 # Execute git log with the desired command line options.
10 fin = os.popen("git log --date=short --stat --summary --since=\"1970-01-01 00:00:00\"", "r")
11 # Create a ChangeLog file in the current directory.
12 fout = open("ChangeLog", "w")
14 # Set up the loop variables in order to locate the blocks we want
27 # The main part of the loop
29 # The commit line marks the start of a new commit object.
30 if re.search("^commit ", line):
31 # Start all over again...
41 # Match the author line and extract the part we want
42 elif re.search("^Author: ", line):
43 author = line[8:].strip()
46 elif re.search("^Date: ", line):
47 date = line[8:].strip()
49 # Extract the actual commit message for this commit
50 elif authorFound and dateFound and not messageFound:
51 # Find the commit message if we can
58 if not message.endswith("\n"):
60 # The sign off line is ignored
61 elif re.search("^ Signed-off-by: ", line):
63 # This is a special workaround for the git log of LXC Facility
64 elif date == "2014-03-02" and re.search("^ This patch series", line):
66 elif date == "2014-03-02" and re.search("^ MIME-Version: ", line):
72 if not message.endswith("\n"):
73 if not re.search("^ \s*[^*-]", line):
75 if not re.search("^ \s*[*-]", line):
78 if re.search("^ \s*[*-]", line):
79 if not message.endswith("\n"):
82 if message.endswith("."):
84 elif not message.endswith("\n"):
86 message += line.strip()
87 # Collect the files for this commit. FIXME: Still need to add +/- to files
88 elif authorFound and dateFound and messageFound and not filesFound:
89 fileList = line.split(" | ", 1)
90 if len(fileList) == 2:
93 files += fileList[0].strip()
94 # If this line is hit all of the files have been stored for this commit
95 elif re.search("^ [0-9]* files? changed, ", line):
97 # All of the parts of the commit have been found - write out the entry
98 if authorFound and dateFound and messageFound and filesFound:
99 # First the author line, only outputted if it is the first for that
101 authorLine = date + " " + author
102 if not prevAuthorLine:
103 fout.write(authorLine + "\n")
105 elif authorLine != prevAuthorLine:
106 # Write out the commit lines
107 fout.write(commitSet + "\n")
108 fout.write("\n" + authorLine + "\n")
111 # Assemble the actual commit message line(s) and limit the line length
113 commitLine = files + ":" + message
120 commit += "\n\t* " if i == 0 else "\n\t "
123 if i + 68 - lv * 2 >= lc:
127 for s in re.finditer("\s", commitLine[i:i + 69 - lv * 2]):
129 i2 = i + 67 - lv * 2 if p == -1 else p
130 p = commitLine.find("\n", i, i + 68 - lv * 2)
134 p = commitLine.find("\n", i)
135 j = lc if p == -1 else p + 1
136 if re.search("^[*-]", commitLine[i:i + j - 1]):
138 commit += commitLine[i:i2 + 1].strip()
141 # Concatenate the commit lines in ascending order by time
142 commitSet = commit + commitSet
144 # Now reset all the variables ready for a new commit block.
154 prevAuthorLine = authorLine
156 # Write out the commit lines
157 fout.write(commitSet + "\n")
159 # Write out the relay message
160 #fout.write("\nFor the changes before 1.0.0, see ChangeLog.1\n")
162 # Close the input and output lines now that we are finished.