Skip to content

Commit 7a9473d

Browse files
Update --all flag to only display non-ancestral branches
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent 4595fbd commit 7a9473d

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

git_sim/log.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
class Log(GitSimBaseCommand):
1111
def __init__(self, commits: int, all: bool):
1212
super().__init__()
13-
self.numCommits = commits + 1
14-
self.defaultNumCommits = commits + 1
13+
self.numCommits = commits
14+
self.defaultNumCommits = commits
1515
try:
1616
self.selected_branches.append(self.repo.active_branch.name)
1717
except TypeError:
@@ -26,7 +26,7 @@ def construct(self):
2626
self.get_commits()
2727
self.parse_commits(self.commits[0], 0)
2828
if self.all:
29-
for branch in self.repo.branches:
29+
for branch in self.get_nonparent_branch_names():
3030
self.get_commits(start=branch.name)
3131
self.parse_commits(self.commits[0], 0)
3232
self.recenter_frame()
@@ -35,13 +35,13 @@ def construct(self):
3535
self.show_outro()
3636

3737
def parse_commits(
38-
self, commit, i, prevCircle=None, shift=numpy.array([0.0, 0.0, 0.0]), dots=False
38+
self, commit, i, prevCircle=None, shift=numpy.array([0.0, 0.0, 0.0])
3939
):
4040
isNewCommit = commit.hexsha not in self.drawnCommits
4141

4242
if i < self.numCommits and commit in self.commits:
4343
commitId, circle, arrow, hide_refs = self.draw_commit(
44-
commit, prevCircle, shift, dots
44+
commit, prevCircle, shift
4545
)
4646

4747
if commit != "dark":
@@ -67,7 +67,7 @@ def parse_commits(
6767
if i == 0 and len(self.drawnRefs) < 2:
6868
self.draw_dark_ref()
6969

70-
if i < len(self.commits) - 1:
70+
if i < self.numCommits: # len(self.commits) - 1:
7171
i += 1
7272
commitParents = list(commit.parents)
7373
if len(commitParents) > 0:
@@ -78,13 +78,9 @@ def parse_commits(
7878
# self.parseCommits(commitParents[0], i+1, prevCircle, toFadeOut)
7979
# else:
8080
for p in range(len(commitParents)):
81-
self.parse_commits(commitParents[p], i, circle, dots=True)
82-
else:
83-
self.i = 0
81+
self.parse_commits(commitParents[p], i, circle)
8482

85-
def draw_commit(
86-
self, commit, prevCircle, shift=numpy.array([0.0, 0.0, 0.0]), dots=False
87-
):
83+
def draw_commit(self, commit, prevCircle, shift=numpy.array([0.0, 0.0, 0.0])):
8884
if commit == "dark":
8985
commitFill = m.WHITE if settings.light_mode else m.BLACK
9086
elif len(commit.parents) <= 1:
@@ -152,7 +148,7 @@ def draw_commit(
152148
arrow.flip(m.RIGHT).shift(m.UP)
153149

154150
commitId, commitMessage, commit, hide_refs = self.build_commit_id_and_message(
155-
commit, dots
151+
commit
156152
)
157153
commitId.next_to(circle, m.UP)
158154

@@ -189,6 +185,16 @@ def draw_commit(
189185

190186
return commitId, circle, arrow, hide_refs
191187

188+
def get_nonparent_branch_names(self):
189+
branches = [b for b in self.repo.heads if not b.name.startswith("remotes/")]
190+
exclude = []
191+
for b1 in branches:
192+
for b2 in branches:
193+
if b1.name != b2.name:
194+
if self.repo.is_ancestor(b1.commit, b2.commit):
195+
exclude.append(b1.name)
196+
return [b for b in branches if b.name not in exclude]
197+
192198

193199
def log(
194200
commits: int = typer.Option(

0 commit comments

Comments
 (0)