Make sure going to last capture also works after refile
[org-mode/org-jambu.git] / UTILITIES / git-changelog
blobe15374a50f19aa90238ed0b1f8c19dc2ec8db340
1 #!/usr/bin/env python
3 # git-changelog
5 # version 2.0, by John Wiegley
7 # The purpose of this code is to turn "git log" output into a complete
8 # ChangeLog, for projects who wish to begin using a ChangeLog, but haven't
9 # been.
11 # This version of git-changelog depends on GitPython:
12 # git://gitorious.org/git-python/mainline.git
14 import time
15 import string
16 import sys
17 import re
18 import os
20 from git import * # GitPython
21 from subprocess import *
23 repo = Repo(os.getcwd())
24 ref = 'origin/master..'
25 path = ''
27 # Usage: git changelog [COMMITISH] [-- [PATH]]
29 saw_dashdash = False
30 if len(sys.argv) > 1:
31 for arg in sys.argv[1:]:
32 if arg == "--":
33 saw_dashdash = True
34 elif saw_dashdash:
35 path = arg
36 else:
37 ref = arg
39 for commit in repo.iter_commits(ref, paths=path):
40 hash_id = commit.sha
41 author = commit.author
42 date = commit.committed_date
43 log_text = commit.message.split('\n')[0]
45 log_text_remainder = commit.message.split('\n\n')[1:]
46 while len(log_text_remainder) > 0 and not log_text_remainder[0]:
47 log_text_remainder = log_text_remainder[1:]
48 log_text_remainder = string.join(log_text_remainder, '\n\t')
49 if log_text_remainder:
50 log_text_remainder = '\n\t' + log_text_remainder
52 diff = commit.diff(commit.parents[0])
53 files = []
54 for f in diff:
55 p = f.a_blob.path or f.b_blob.path
56 p2 = re.sub('^' + path + '/', '', p)
57 if p != p2:
58 files.append(p2)
60 fp = Popen(["fmt", "-72"], shell = True, stdin = PIPE, stdout = PIPE)
61 fp.stdin.write("\t* %s: %s" % (string.join(files, ",\n\t"), log_text))
62 fp.stdin.close()
63 log_text = fp.stdout.read()
64 del fp
66 print "%s %s <%s>\n\n%s%s" % \
67 (time.strftime("%Y-%m-%d", time.gmtime(date)),
68 author.name, author.email, log_text, log_text_remainder)
70 # git-changelog ends here