@@ -19,7 +19,6 @@ def __init__(self):
1919 self .drawnCommits = {}
2020 self .drawnRefs = {}
2121 self .drawnCommitIds = {}
22- self .commits = []
2322 self .zoomOuts = 0
2423 self .toFadeOut = m .Group ()
2524 self .trimmed = False
@@ -46,45 +45,31 @@ def init_repo(self):
4645 def construct (self ):
4746 print (f"{ settings .INFO_STRING } { type (self ).__name__ .lower ()} " )
4847 self .show_intro ()
49- self .get_commits ()
48+ self .parse_commits ()
5049 self .fadeout ()
5150 self .show_outro ()
5251
53- def get_commits (self , start = "HEAD" ):
54- if not self .n :
55- if settings .allow_no_commits :
56- self .n = self .n_default
57- self .commits = ["dark" ] * 5
58- self .zone_title_offset = 2
59- return
60- else :
61- print ("git-sim error: No commits in current Git repository." )
62- sys .exit (1 )
63-
64- try :
65- self .commits = (
66- list (self .repo .iter_commits (start ))
67- if self .n == 1
68- else list (
69- self .repo .iter_commits (start + "~" + str (self .n ) + "..." + start )
70- )
71- )
72- if len (self .commits ) < self .n_default :
73- self .commits = list (self .repo .iter_commits (start ))
74- while len (self .commits ) < self .n_default :
75- self .commits .append (self .create_dark_commit ())
76- self .n = self .n_orig
52+ def get_commit (self , sha_or_ref = "HEAD" ):
53+ return self .repo .commit (sha_or_ref )
7754
78- except GitCommandError :
79- self .n -= 1
80- self .get_commits (start = start )
55+ def get_default_commits (self ):
56+ defaultCommits = [self .get_commit ()]
57+ for x in range (self .n_default - 1 ):
58+ defaultCommits .append (defaultCommits [- 1 ].parents [0 ])
59+ return defaultCommits
8160
8261 def parse_commits (
83- self , commit , i , prevCircle = None , shift = numpy .array ([0.0 , 0.0 , 0.0 ])
62+ self ,
63+ commit = None ,
64+ i = 0 ,
65+ prevCircle = None ,
66+ shift = numpy .array ([0.0 , 0.0 , 0.0 ]),
8467 ):
68+ commit = commit or self .get_commit ()
69+
8570 isNewCommit = commit .hexsha not in self .drawnCommits
8671
87- if i < self .n and commit in self . commits :
72+ if i < self .n :
8873 commitId , circle , arrow , hide_refs = self .draw_commit (
8974 commit , i , prevCircle , shift
9075 )
@@ -303,20 +288,11 @@ def get_nonparent_branch_names(self):
303288 exclude .append (b1 .name )
304289 return [b for b in branches if b .name not in exclude ]
305290
306- def build_commit_id_and_message (self , commit , i , dots = False ):
291+ def build_commit_id_and_message (self , commit , i ):
307292 hide_refs = False
308293 if commit == "dark" :
309294 commitId = m .Text ("" , font = "Monospace" , font_size = 20 , color = self .fontColor )
310295 commitMessage = ""
311- elif (
312- dots
313- and self .commits [- 1 ] != "dark"
314- and commit .hexsha == self .commits [- 1 ].hexsha
315- ):
316- commitId = m .Text (
317- "..." , font = "Monospace" , font_size = 20 , color = self .fontColor
318- )
319- commitMessage = "..."
320296 else :
321297 commitId = m .Text (
322298 commit .hexsha [0 :6 ],
@@ -924,9 +900,6 @@ def create_dark_commit(self):
924900
925901 def get_nondark_commits (self ):
926902 nondark_commits = []
927- for commit in self .commits :
928- if commit != "dark" :
929- nondark_commits .append (commit )
930903 return nondark_commits
931904
932905 def draw_ref (self , commit , i , top , text = "HEAD" , color = m .BLUE ):
0 commit comments