Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0b29a72

Browse files
committed
git-dot: better handling of merge commits
when using `git-dot -m ...` with short (e.g., single letter) commit messages, merge commits look awful because of the length of the generated merge message. This commit introduces the -M (--fake-merge-message) option that synthesizes a label for merge commits from the parent messages.
1 parent 5dc787e commit 0b29a72

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

‎git-dot‎

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,35 @@ def git(*args):
1212
).decode()
1313

1414

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+
1537
@click.command()
1638
@click.option('-o', '--output')
1739
@click.option('-r', '--render', is_flag=True)
1840
@click.option('-v', '--view', is_flag=True)
1941
@click.option('-f', '--format', default='svg')
2042
@click.option('-m', '--use-message', is_flag=True)
43+
@click.option('-M', '--fake-merge-message', is_flag=True)
2144
@click.option('-g', '--gather', type=click.Choice(['free', 'commit', 'branch']),
2245
default='free')
2346
@click.option('--shortref-len', default=10)
@@ -27,11 +50,11 @@ def git(*args):
2750
@click.option('--remote/--no-remote', '-R', 'flag_remote')
2851
@click.option('--tags/--no-tags', '-t', 'flag_tags')
2952
@click.option('--rankdir', default='TB')
30-
@click.option('--shape')
53+
@click.option('--shape', default='circle')
3154
def main(output, render, view, format, flag_remote, flag_tags,
3255
rankdir, use_message, gather, shortref_len,
3356
exclude_remote, exclude_tag, exclude_branch,
34-
shape):
57+
shape, fake_merge_message):
3558

3659
def _shortref(ref):
3760
return ref[:shortref_len]
@@ -41,9 +64,6 @@ def main(output, render, view, format, flag_remote, flag_tags,
4164

4265
seen = set()
4366

44-
if shape is None:
45-
shape = 'box' if use_message else 'circle'
46-
4767
graph = Digraph(name='git', format='svg',
4868
graph_attr=dict(rankdir=rankdir),
4969
node_attr=dict(shape=shape),
@@ -89,19 +109,20 @@ def main(output, render, view, format, flag_remote, flag_tags,
89109
continue
90110
seen.add(commit)
91111

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)))
93116

94117
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)
96121
else:
97-
args = dict(tooltip=commit_summary)
122+
args = dict(tooltip=message)
98123

99124
sub.node(_shortref(commit), **args)
100125

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-
105126
if gather != 'free':
106127
for sub in commits:
107128
graph.subgraph(sub)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /