Skip to content

Commit 7fb6dc1

Browse files
Extend --all as a global flag to subcommands that don't show table/zones
Signed-off-by: Jacob Stopak <[email protected]>
1 parent b900b30 commit 7fb6dc1

10 files changed

+49
-23
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ $ git-sim [global options] <subcommand> [subcommand options]
133133

134134
The `[global options]` apply to the overarching `git-sim` simulation itself, including:
135135

136+
`-n <number>`: Number of commits to display from each branch head.
137+
`--all`: Display all local branches in the log output.
136138
`--light-mode`: Use a light mode color scheme instead of default dark mode.
137139
`--animate`: Instead of outputting a static image, animate the Git command behavior in a .mp4 video.
138140
`--media-dir`: The path at which to store the simulated output media files.
@@ -160,9 +162,11 @@ The `[subcommand options]` are like regular Git options specific to the specifie
160162
The following is a list of Git commands that can be simulated and their corresponding options/flags.
161163

162164
### git log
163-
Usage: `git-sim log`
165+
Usage: `git-sim log [-n <number>] [--all]`
164166

165167
- Simulated output will show the most recent 5 commits on the active branch by default
168+
- Use `-n <number>` to set number of commits to display from each branch head
169+
- Set `--all` to display all local branches in the log output
166170

167171
![git-sim-log_01-05-23_22-02-39](https://user-images.githubusercontent.com/49353917/210940300-aadd14c6-72ab-4529-a1be-b494ed5dd4c9.jpg)
168172

git_sim/__main__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ def main(
120120
settings.hide_merged_branches,
121121
help="Hide commits from merged branches, i.e. only display mainline commits",
122122
),
123+
all: bool = typer.Option(
124+
settings.all,
125+
help="Display all local branches in the log output",
126+
),
123127
):
124128
settings.animate = animate
125129
settings.n = n
@@ -142,6 +146,7 @@ def main(
142146
settings.stdout = stdout
143147
settings.invert_branches = invert_branches
144148
settings.hide_merged_branches = hide_merged_branches
149+
settings.all = all
145150

146151
if sys.platform == "linux" or sys.platform == "darwin":
147152
repo_name = git.repo.Repo(

git_sim/branch.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def construct(self):
1717

1818
self.show_intro()
1919
self.parse_commits()
20-
self.recenter_frame()
21-
self.scale_frame()
20+
self.parse_all()
21+
self.center_frame_on_commit(self.get_commit())
2222

2323
branchText = m.Text(
2424
self.name,
@@ -47,6 +47,8 @@ def construct(self):
4747
self.toFadeOut.add(branchRec, branchText)
4848
self.drawnRefs[self.name] = fullbranch
4949

50+
self.recenter_frame()
51+
self.scale_frame()
5052
self.fadeout()
5153
self.show_outro()
5254

git_sim/cherrypick.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def construct(self):
5757
self.parse_commits(head_commit)
5858
cherry_picked_commit = self.get_commit(self.commit)
5959
self.parse_commits(cherry_picked_commit, shift=4 * m.DOWN)
60+
self.parse_all()
6061
self.center_frame_on_commit(head_commit)
6162
self.setup_and_draw_parent(
6263
head_commit,

git_sim/git_sim_base_command.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@ def __init__(self):
1919
self.drawnCommits = {}
2020
self.drawnRefs = {}
2121
self.drawnCommitIds = {}
22-
self.zoomOuts = 0
2322
self.toFadeOut = m.Group()
24-
self.trimmed = False
2523
self.prevRef = None
2624
self.topref = None
2725
self.n_default = settings.n_default
2826
self.n = settings.n
2927
self.n_orig = self.n
3028
self.selected_branches = []
31-
self.stop = False
3229
self.zone_title_offset = 2.6 if platform.system() == "Windows" else 2.6
3330
self.arrow_map = []
31+
self.all = settings.all
32+
self.first_parse = True
3433

3534
self.logo = m.ImageMobject(settings.logo)
3635
self.logo.width = 3
@@ -97,6 +96,7 @@ def parse_commits(
9796
if i == 0 and len(self.drawnRefs) < 2:
9897
self.draw_dark_ref()
9998

99+
self.first_parse = False
100100
if i < self.n:
101101
i += 1
102102
commitParents = list(commit.parents)
@@ -110,6 +110,11 @@ def parse_commits(
110110
for p in range(len(commitParents)):
111111
self.parse_commits(commitParents[p], i, circle)
112112

113+
def parse_all(self):
114+
if self.all:
115+
for branch in self.get_nonparent_branch_names():
116+
self.parse_commits(self.get_commit(branch.name))
117+
113118
def show_intro(self):
114119
if settings.animate and settings.show_intro:
115120
self.add(self.logo)
@@ -195,7 +200,7 @@ def draw_commit(self, commit, i, prevCircle, shift=numpy.array([0.0, 0.0, 0.0]))
195200
)
196201

197202
while any((circle.get_center() == c).all() for c in self.get_centers()):
198-
circle.next_to(circle, m.DOWN, buff=3.5)
203+
circle.shift(m.DOWN * 4)
199204

200205
isNewCommit = commit.hexsha not in self.drawnCommits
201206

@@ -324,7 +329,7 @@ def draw_head(self, commit, i, commitId):
324329
self.drawnRefs["HEAD"] = head
325330
self.prevRef = head
326331

327-
if i == 0:
332+
if i == 0 and self.first_parse:
328333
self.topref = self.prevRef
329334

330335
def draw_branch(self, commit, i):
@@ -340,8 +345,6 @@ def draw_branch(self, commit, i):
340345
branches.insert(0, branches.pop(branches.index(selected_branch)))
341346

342347
for branch in branches:
343-
# Use forward slash to check if branch is local or remote tracking
344-
# and draw the branch label if its hexsha matches the current commit
345348
if (
346349
not self.is_remote_tracking_branch(branch) # local branch
347350
and commit.hexsha == self.repo.heads[branch].commit.hexsha
@@ -375,7 +378,7 @@ def draw_branch(self, commit, i):
375378
self.toFadeOut.add(branchRec, branchText)
376379
self.drawnRefs[branch] = fullbranch
377380

378-
if i == 0:
381+
if i == 0 and self.first_parse:
379382
self.topref = self.prevRef
380383

381384
x += 1
@@ -421,7 +424,7 @@ def draw_tag(self, commit, i):
421424

422425
self.toFadeOut.add(tagRec, tagText)
423426

424-
if i == 0:
427+
if i == 0 and self.first_parse:
425428
self.topref = self.prevRef
426429

427430
x += 1
@@ -925,7 +928,7 @@ def draw_ref(self, commit, i, top, text="HEAD", color=m.BLUE):
925928
self.drawnRefs[text] = ref
926929
self.prevRef = ref
927930

928-
if i == 0:
931+
if i == 0 and self.first_parse:
929932
self.topref = self.prevRef
930933

931934
def draw_dark_ref(self):

git_sim/log.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,27 @@ def __init__(self, ctx: typer.Context, n: int, all: bool):
2020
self.n = n
2121
self.n_orig = self.n
2222

23+
all_command = ctx.parent.params.get("all")
24+
self.all_subcommand = all
25+
if self.all_subcommand:
26+
all = self.all_subcommand
27+
else:
28+
all = all_command
29+
self.all = all
30+
2331
try:
2432
self.selected_branches.append(self.repo.active_branch.name)
2533
except TypeError:
2634
pass
27-
self.all = all
2835

2936
def construct(self):
3037
if not settings.stdout:
3138
print(
32-
f"{settings.INFO_STRING} {type(self).__name__.lower()}{' --all' if self.all else ''}{' -n ' + str(self.n) if self.n_subcommand else ''}"
39+
f"{settings.INFO_STRING} {type(self).__name__.lower()}{' --all' if self.all_subcommand else ''}{' -n ' + str(self.n) if self.n_subcommand else ''}"
3340
)
3441
self.show_intro()
3542
self.parse_commits()
36-
if self.all:
37-
for branch in self.get_nonparent_branch_names():
38-
self.parse_commits(self.get_commit(branch.name))
43+
self.parse_all()
3944
self.recenter_frame()
4045
self.scale_frame()
4146
self.fadeout()
@@ -45,13 +50,13 @@ def construct(self):
4550
def log(
4651
ctx: typer.Context,
4752
n: int = typer.Option(
48-
settings.n_subcommand,
53+
None,
4954
"-n",
5055
help="Number of commits to display from branch heads",
51-
min=1,
5256
),
5357
all: bool = typer.Option(
5458
False,
59+
"--all",
5560
help="Display all local branches in the log output",
5661
),
5762
):

git_sim/merge.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def construct(self):
7070

7171
if self.ff:
7272
self.parse_commits(branch_commit)
73+
self.parse_all()
7374
reset_head_to = branch_commit.hexsha
7475
shift = numpy.array([0.0, 0.6, 0.0])
7576

@@ -95,6 +96,7 @@ def construct(self):
9596
else:
9697
self.parse_commits(head_commit)
9798
self.parse_commits(branch_commit, shift=4 * m.DOWN)
99+
self.parse_all()
98100
self.center_frame_on_commit(head_commit)
99101
self.setup_and_draw_parent(
100102
head_commit,

git_sim/rebase.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def construct(self):
7676
reached_base = True
7777

7878
self.parse_commits(head_commit, shift=4 * m.DOWN)
79+
self.parse_all()
7980
self.center_frame_on_commit(branch_commit)
8081

8182
to_rebase = []

git_sim/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class Settings(BaseSettings):
2121
auto_open = True
2222
n_default = 5
2323
n = 5
24-
n_subcommand: Union[int, None] = None
2524
files: Union[List[pathlib.Path], None] = None
2625
hide_first_tag = False
2726
img_format: ImgFormat = ImgFormat.jpg
@@ -43,6 +42,7 @@ class Settings(BaseSettings):
4342
stdout = False
4443
invert_branches = False
4544
hide_merged_branches = False
45+
all = False
4646

4747
class Config:
4848
env_prefix = "git_sim_"

git_sim/tag.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def construct(self):
1717

1818
self.show_intro()
1919
self.parse_commits()
20-
self.recenter_frame()
21-
self.scale_frame()
20+
self.parse_all()
21+
self.center_frame_on_commit(self.get_commit())
2222

2323
tagText = m.Text(
2424
self.name,
@@ -45,7 +45,10 @@ def construct(self):
4545
self.add(fulltag)
4646

4747
self.toFadeOut.add(tagRec, tagText)
48+
self.drawnRefs[self.name] = fulltag
4849

50+
self.recenter_frame()
51+
self.scale_frame()
4952
self.fadeout()
5053
self.show_outro()
5154

0 commit comments

Comments
 (0)