forked from toddlipcon/tlipcon-bin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit-git-log
executable file
·65 lines (51 loc) · 1.27 KB
/
edit-git-log
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
#!/usr/bin/python
import sys
import re
import os
import tempfile
import subprocess
def do_user():
if len(sys.argv) != 2:
raise Exception("usage: %s fromcommit..tocommit")
commit_range = sys.argv[1]
tmp = tempfile.NamedTemporaryFile(mode="w+")
subprocess.check_call([
"git", "log", "-z", commit_range],
stdout=tmp)
tmp.flush()
# Allow user to edit log
subprocess.check_call([
os.getenv("EDITOR", "vim"),
tmp.name])
# Run filter branch
subprocess.check_call([
"git", "filter-branch",
"-f",
"--msg-filter",
"ACT_AS=filter %s %s" % (sys.argv[0], tmp.name),
commit_range])
tmp.close()
def apply_changes():
"""Called by filter-branch to apply the changes"""
method = sys.argv[1]
f = file(sys.argv[1])
data = f.read()
f.close()
lookfor = os.getenv("GIT_COMMIT")
entries = data.split("\0")
by_hash = dict()
for e in entries:
if lookfor not in e:
next
meta,log = e.split("\n\n", 1)
meta_lines = meta.split("\n")
commit = meta_lines[0].split(" ")[1]
if commit == lookfor:
print re.sub(r'(?m)^ {0,4}', '', log)
act_as = os.getenv("ACT_AS", "user")
if act_as == "filter":
apply_changes()
elif act_as == "user":
do_user()
else:
raise Exception("Unknown call type: " + act_as)