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 e67c071

Browse files
committed
use git cli instead of git module
1 parent 1c722de commit e67c071

File tree

1 file changed

+38
-22
lines changed

1 file changed

+38
-22
lines changed

‎git-dot‎

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
#!/usr/bin/python
22

33
import click
4-
import git
4+
import subprocess
55

66
from graphviz import Digraph
7-
from itertools import chain
7+
8+
9+
def git(*args):
10+
return subprocess.check_output(
11+
('git',) + args
12+
).decode()
813

914

1015
@click.command()
@@ -27,12 +32,11 @@ def main(output, render, view, format, flag_remote, flag_tags,
2732
exclude_remote, exclude_tag, exclude_branch):
2833

2934
def _shortref(ref):
30-
return ref.hexsha[:shortref_len]
35+
return ref[:shortref_len]
3136

3237
if (render or view) and not output:
3338
raise click.ClickException('--render and --view require --output')
3439

35-
repo = git.Repo()
3640
seen = set()
3741

3842
graph = Digraph(name='git', format='svg',
@@ -53,15 +57,18 @@ def main(output, render, view, format, flag_remote, flag_tags,
5357
commit_links = set()
5458
tag_links = set()
5559

56-
for head in repo.heads:
57-
if head.name in exclude_branch:
60+
for info in git('for-each-ref',
61+
'--format=%(objectname) %(refname:short)',
62+
'refs/heads/').splitlines():
63+
headid, head = info.split()
64+
if head in exclude_branch:
5865
continue
5966

60-
heads.node(head.name)
61-
branch_links.add((head.name, _shortref(head.commit)))
67+
heads.node(head)
68+
branch_links.add((head, _shortref(headid)))
6269

6370
if gather == 'branch':
64-
sub = Digraph(node_attr=dict(group=f'{head.name}_commits'))
71+
sub = Digraph(node_attr=dict(group=f'{head}_commits'))
6572
commits.append(sub)
6673
elif not commits and gather == 'commit':
6774
sub = Digraph(node_attr=dict(group='commits'))
@@ -72,19 +79,22 @@ def main(output, render, view, format, flag_remote, flag_tags,
7279
else:
7380
sub = commits[0]
7481

75-
for commit in chain([head.commit], head.commit.traverse()):
82+
for commit in git('rev-list', head).splitlines():
7683
if commit in seen:
7784
continue
7885
seen.add(commit)
7986

87+
commit_summary = git('show', '--quiet', '--format=%s', commit).splitlines()[0]
88+
8089
if use_message:
81-
args = dict(tooltip=commit.hexsha, label=commit.summary)
90+
args = dict(tooltip=commit, label=commit_summary)
8291
else:
83-
args = dict(tooltip=commit.summary)
92+
args = dict(tooltip=commit_summary)
8493

8594
sub.node(_shortref(commit), **args)
8695

87-
for parent in commit.parents:
96+
commit_parents = git('rev-list', '--parents', '-n1', commit).split()[1:]
97+
for parent in commit_parents:
8898
commit_links.add((_shortref(commit), _shortref(parent)))
8999

90100
if gather != 'free':
@@ -100,13 +110,16 @@ def main(output, render, view, format, flag_remote, flag_tags,
100110
fontcolor='white',
101111
))
102112

103-
for remote in repo.remotes:
104-
if remote.name in exclude_remote:
113+
for remote in git('remote').splitlines():
114+
if remote in exclude_remote:
105115
continue
106116

107-
for ref in remote.refs:
108-
remote_heads.node(ref.name)
109-
branch_links.add((ref.name, _shortref(ref.commit)))
117+
for info in git('for-each-ref',
118+
'--format=%(objectname) %(refname:short)',
119+
f'refs/remotes/{remote}/').splitlines():
120+
refid, ref = info.split()
121+
remote_heads.node(ref)
122+
branch_links.add((ref, _shortref(refid)))
110123
graph.subgraph(remote_heads)
111124

112125
if flag_tags:
@@ -116,12 +129,15 @@ def main(output, render, view, format, flag_remote, flag_tags,
116129
fontcolor='black',
117130
))
118131

119-
for tag in repo.tags:
120-
if tag.name in exclude_tag:
132+
for info in git('for-each-ref',
133+
'--format=%(objectname) %(refname:short)',
134+
'refs/tags/').splitlines():
135+
tagid, tag = info.split()
136+
if tag in exclude_tag:
121137
continue
122138

123-
tags.node(tag.name)
124-
tag_links.add((tag.name, _shortref(tag.commit)))
139+
tags.node(tag)
140+
tag_links.add((tag, _shortref(tagid)))
125141
graph.subgraph(tags)
126142

127143
if branch_links:

0 commit comments

Comments
(0)

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