@@ -12,12 +12,35 @@ def git(*args):
12
12
).decode ()
13
13
14
14
15
+ def parents_of (commit ):
16
+ return git ('rev-list' , '--parents' , '-n1' , commit ).split ()[1 :]
17
+
18
+
19
+ def subject_of (commit ):
20
+ return git ('show' , '--quiet' , '--format=%s' , commit ).splitlines ()[0 ]
21
+
22
+
23
+ def make_message_from (* commits ):
24
+ messages = []
25
+ for commit in commits :
26
+ parents = parents_of (commit )
27
+ if len (parents ) > 1 :
28
+ message = make_message_from (* parents )
29
+ else :
30
+ message = subject_of (commit )
31
+
32
+ messages .append (message )
33
+
34
+ return '+' .join (messages )
35
+
36
+
15
37
@click .command ()
16
38
@click .option ('-o' , '--output' )
17
39
@click .option ('-r' , '--render' , is_flag = True )
18
40
@click .option ('-v' , '--view' , is_flag = True )
19
41
@click .option ('-f' , '--format' , default = 'svg' )
20
42
@click .option ('-m' , '--use-message' , is_flag = True )
43
+ @click .option ('-M' , '--fake-merge-message' , is_flag = True )
21
44
@click .option ('-g' , '--gather' , type = click .Choice (['free' , 'commit' , 'branch' ]),
22
45
default = 'free' )
23
46
@click .option ('--shortref-len' , default = 10 )
@@ -27,11 +50,11 @@ def git(*args):
27
50
@click .option ('--remote/--no-remote' , '-R' , 'flag_remote' )
28
51
@click .option ('--tags/--no-tags' , '-t' , 'flag_tags' )
29
52
@click .option ('--rankdir' , default = 'TB' )
30
- @click .option ('--shape' )
53
+ @click .option ('--shape' , default = 'circle' )
31
54
def main (output , render , view , format , flag_remote , flag_tags ,
32
55
rankdir , use_message , gather , shortref_len ,
33
56
exclude_remote , exclude_tag , exclude_branch ,
34
- shape ):
57
+ shape , fake_merge_message ):
35
58
36
59
def _shortref (ref ):
37
60
return ref [:shortref_len ]
@@ -41,9 +64,6 @@ def main(output, render, view, format, flag_remote, flag_tags,
41
64
42
65
seen = set ()
43
66
44
- if shape is None :
45
- shape = 'box' if use_message else 'circle'
46
-
47
67
graph = Digraph (name = 'git' , format = 'svg' ,
48
68
graph_attr = dict (rankdir = rankdir ),
49
69
node_attr = dict (shape = shape ),
@@ -89,19 +109,20 @@ def main(output, render, view, format, flag_remote, flag_tags,
89
109
continue
90
110
seen .add (commit )
91
111
92
- commit_summary = git ('show' , '--quiet' , '--format=%s' , commit ).splitlines ()[0 ]
112
+ message = subject_of (commit )
113
+ commit_parents = parents_of (commit )
114
+ for parent in commit_parents :
115
+ commit_links .add ((_shortref (commit ), _shortref (parent )))
93
116
94
117
if use_message :
95
- args = dict (tooltip = commit , label = commit_summary )
118
+ if fake_merge_message and len (commit_parents ) > 1 :
119
+ message = make_message_from (* commit_parents )
120
+ args = dict (tooltip = commit , label = message )
96
121
else :
97
- args = dict (tooltip = commit_summary )
122
+ args = dict (tooltip = message )
98
123
99
124
sub .node (_shortref (commit ), ** args )
100
125
101
- commit_parents = git ('rev-list' , '--parents' , '-n1' , commit ).split ()[1 :]
102
- for parent in commit_parents :
103
- commit_links .add ((_shortref (commit ), _shortref (parent )))
104
-
105
126
if gather != 'free' :
106
127
for sub in commits :
107
128
graph .subgraph (sub )
0 commit comments