Skip to content

Commit 715f094

Browse files
Fix list index out of range error when simulating some rebases
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent d974cef commit 715f094

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

git_sim/git_sim_base_command.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ def get_commits(self, start="HEAD"):
7070
self.numCommits -= 1
7171
self.get_commits(start=start)
7272

73-
def parse_commits(self, commit, prevCircle=None, shift=numpy.array([0., 0., 0.])):
73+
def parse_commits(self, commit, prevCircle=None, shift=numpy.array([0., 0., 0.]), dots=False):
7474
if self.stop:
7575
return
7676
if ( self.i < self.numCommits and commit in self.commits ):
77-
commitId, circle, arrow, hide_refs = self.draw_commit(commit, prevCircle, shift)
77+
commitId, circle, arrow, hide_refs = self.draw_commit(commit, prevCircle, shift, dots)
7878

7979
if commit != "dark":
8080
if not hide_refs and not self.stop:
@@ -89,7 +89,7 @@ def parse_commits(self, commit, prevCircle=None, shift=numpy.array([0., 0., 0.])
8989

9090
if self.i < len(self.commits)-1:
9191
self.i += 1
92-
self.parse_commits(self.commits[self.i], circle)
92+
self.parse_commits(self.commits[self.i], circle, dots=True)
9393
else:
9494
self.i = 0
9595

@@ -138,7 +138,7 @@ def get_centers(self):
138138
centers.append(commit.get_center())
139139
return centers
140140

141-
def draw_commit(self, commit, prevCircle, shift=numpy.array([0., 0., 0.])):
141+
def draw_commit(self, commit, prevCircle, shift=numpy.array([0., 0., 0.]), dots=False):
142142
if commit == "dark":
143143
commitFill = m.WHITE if self.scene.args.light_mode else m.BLACK
144144
elif ( len(commit.parents) <= 1 ):
@@ -170,7 +170,7 @@ def draw_commit(self, commit, prevCircle, shift=numpy.array([0., 0., 0.])):
170170
length = numpy.linalg.norm(start-end) - ( 1.5 if start[1] == end[1] else 3 )
171171
arrow.set_length(length)
172172

173-
commitId, commitMessage, commit, hide_refs = self.build_commit_id_and_message(commit)
173+
commitId, commitMessage, commit, hide_refs = self.build_commit_id_and_message(commit, dots)
174174
commitId.next_to(circle, m.UP)
175175

176176
message = m.Text('\n'.join(commitMessage[j:j+20] for j in range(0, len(commitMessage), 20))[:100], font="Monospace", font_size=14, color=self.scene.fontColor).next_to(circle, m.DOWN)
@@ -190,11 +190,14 @@ def draw_commit(self, commit, prevCircle, shift=numpy.array([0., 0., 0.])):
190190

191191
return commitId, circle, arrow, hide_refs
192192

193-
def build_commit_id_and_message(self, commit):
193+
def build_commit_id_and_message(self, commit, dots=False):
194194
hide_refs = False
195195
if commit == "dark":
196196
commitId = m.Text("", font="Monospace", font_size=20, color=self.scene.fontColor)
197197
commitMessage = ""
198+
elif dots and commit.hexsha == self.commits[-1].hexsha:
199+
commitId = m.Text("...", font="Monospace", font_size=20, color=self.scene.fontColor)
200+
commitMessage = "..."
198201
else:
199202
commitId = m.Text(commit.hexsha[0:6], font="Monospace", font_size=20, color=self.scene.fontColor)
200203
commitMessage = commit.message.split("\n")[0][:40].replace("\n", " ")

git_sim/git_sim_rebase.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ def execute(self):
4242
self.orig_commits = self.commits
4343
self.i = 0
4444
self.get_commits()
45-
self.parse_commits(self.commits[0], shift=4*m.DOWN)
45+
46+
reached_base = False
47+
for commit in self.commits:
48+
if self.scene.args.branch[0] in self.repo.git.branch("--contains", commit):
49+
reached_base = True
50+
51+
self.parse_commits(self.commits[0], shift=4*m.DOWN, dots=False if reached_base else True)
4652
self.center_frame_on_commit(self.orig_commits[0])
4753

4854
to_rebase = []
@@ -51,11 +57,18 @@ def execute(self):
5157
while self.scene.args.branch[0] not in self.repo.git.branch("--contains", current):
5258
to_rebase.append(current)
5359
i += 1
60+
if i >= len(self.commits):
61+
break
5462
current = self.commits[i]
5563

5664
parent = self.orig_commits[0].hexsha
57-
for tr in reversed(to_rebase):
58-
parent = self.setup_and_draw_parent(parent, tr.message)
65+
66+
for j, tr in enumerate(reversed(to_rebase)):
67+
if ( not reached_base and j == 0 ):
68+
message = "..."
69+
else:
70+
message = tr.message
71+
parent = self.setup_and_draw_parent(parent, message)
5972
self.draw_arrow_between_commits(tr.hexsha, parent)
6073

6174
self.recenter_frame()
@@ -75,8 +88,9 @@ def setup_and_draw_parent(self, child, commitMessage="New commit", shift=numpy.a
7588
arrow = m.Arrow(start, end, color=self.scene.fontColor)
7689
length = numpy.linalg.norm(start-end) - ( 1.5 if start[1] == end[1] else 3 )
7790
arrow.set_length(length)
78-
sha = "".join(chr(ord(letter)+1) if (chr(ord(letter)+1).isalpha() or chr(ord(letter)+1).isdigit()) else letter for letter in child[:6])
79-
commitId = m.Text(sha, font="Monospace", font_size=20, color=self.scene.fontColor).next_to(circle, m.UP)
91+
92+
sha = "".join(chr(ord(letter)+1) if ((chr(ord(letter)+1).isalpha() and letter < "f") or chr(ord(letter)+1).isdigit()) else letter for letter in child[:6])
93+
commitId = m.Text(sha if commitMessage != "..." else "...", font="Monospace", font_size=20, color=self.scene.fontColor).next_to(circle, m.UP)
8094
self.toFadeOut.add(commitId)
8195

8296
commitMessage = commitMessage[:40].replace("\n", " ")

0 commit comments

Comments
 (0)