public
Description: A bunch of random scripts I've either written, downloaded or clipped from #git.
Homepage:
Clone URL: git://github.com/jwiegley/git-scripts.git
git-scripts / git-changelog
100755 80 lines (58 sloc) 1.82 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
 
# git-changelog
#
# version 1.0, by John Wiegley
#
# The purpose of this code is to turn "git log" output into a complete
# ChangeLog, for projects who wish to begin using a ChangeLog, but haven't
# been.
 
import datetime
import string
import sys
import re
 
from subprocess import *
 
p = Popen("git log --stat %s" % string.join(sys.argv[1:], " "),
          shell = True, stdout = PIPE).stdout
 
line = p.readline()
while line:
    match = re.match("commit ([0-9a-f]+)", line)
    assert match
    hash_id = match.group(1)
 
    line = p.readline()
 
    match = re.match("Author: (.+)", line)
    assert match
    author = match.group(1)
    author = re.sub(" <", " <", author)
 
    line = p.readline()
 
    match = re.match("Date: +(.+?) [-+][0-9]{4}", line)
    assert match
    # Tue Sep 30 05:43:49 2003 +0000
    date = datetime.datetime.strptime(match.group(1), '%a %b %d %H:%M:%S %Y')
 
    line = p.readline() # absorb separator
    line = p.readline()
 
    log_text = ""
    while line and line != '\n':
        if not log_text:
            log_text += line[4:]
        else:
            log_text += "\t" + line[4:]
 
        line = p.readline()
 
    line = p.readline()
 
    files = []
    while line and line != '\n':
        match = re.match(" (.+?) +\\|", line)
        if match:
            files.append(match.group(1))
            line = p.readline()
        else:
            break
 
    line = p.readline()
 
    fp = Popen("fmt", shell = True, stdin = PIPE, stdout = PIPE)
 
    fp.stdin.write("\t* %s: %s\n" % (string.join(files, ",\n\t"), log_text))
    fp.stdin.close()
    log_text = fp.stdout.read()
 
    del fp
 
    print "%s %s\n\n%s\t* commit %s\n" % \
        (date.strftime("%Y-%m-%d"), author, log_text, hash_id)
 
    line = p.readline()
 
# git-changelog ends here