126126cursor = connection .cursor ()
127127builds = cursor .execute ("SELECT DISTINCT build_commit FROM test;" ).fetchall ()
128128
129+ commit_short_len = len (builds [0 ][0 ])
130+
129131try :
130132 repo = git .Repo ("." , search_parent_directories = True )
131133except git .InvalidGitRepositoryError :
@@ -138,11 +140,11 @@ def find_parent_in_data(commit: git.Commit):
138140 seen_hexsha8 = set ()
139141 while heap :
140142 depth , current_commit = heapq .heappop (heap )
141- current_hexsha8 = commit .hexsha [:8 ]
143+ current_hexsha8 = commit .hexsha [:commit_short_len ]
142144 if (current_hexsha8 ,) in builds :
143145 return current_hexsha8
144146 for parent in commit .parents :
145- parent_hexsha8 = parent .hexsha [:8 ]
147+ parent_hexsha8 = parent .hexsha [:commit_short_len ]
146148 if parent_hexsha8 not in seen_hexsha8 :
147149 seen_hexsha8 .add (parent_hexsha8 )
148150 heapq .heappush (heap , (depth + 1 , parent ))
@@ -156,9 +158,9 @@ def get_all_parent_hexsha8s(commit: git.Commit):
156158
157159 while unvisited :
158160 current_commit = unvisited .pop (0 )
159- visited .append (current_commit .hexsha [:8 ])
161+ visited .append (current_commit .hexsha [:commit_short_len ])
160162 for parent in current_commit .parents :
161- if parent .hexsha [:8 ] not in visited :
163+ if parent .hexsha [:commit_short_len ] not in visited :
162164 unvisited .append (parent )
163165
164166 return visited
@@ -169,10 +171,10 @@ def get_commit_name(hexsha8):
169171 if repo is None :
170172 return hexsha8
171173 for h in repo .heads :
172- if h .commit .hexsha [:8 ] == hexsha8 :
174+ if h .commit .hexsha [:commit_short_len ] == hexsha8 :
173175 return h .name
174176 for t in repo .tags :
175- if t .commit .hexsha [:8 ] == hexsha8 :
177+ if t .commit .hexsha [:commit_short_len ] == hexsha8 :
176178 return t .name
177179 return hexsha8
178180
@@ -183,13 +185,13 @@ def get_commit_hexsha8(name):
183185 return None
184186 for h in repo .heads :
185187 if h .name == name :
186- return h .commit .hexsha [:8 ]
188+ return h .commit .hexsha [:commit_short_len ]
187189 for t in repo .tags :
188190 if t .name == name :
189- return t .commit .hexsha [:8 ]
191+ return t .commit .hexsha [:commit_short_len ]
190192 for c in repo .iter_commits ("--all" ):
191- if c .hexsha [:8 ] == name [:8 ]:
192- return c .hexsha [:8 ]
193+ if c .hexsha [:commit_short_len ] == name [:commit_short_len ]:
194+ return c .hexsha [:commit_short_len ]
193195 return None
194196
195197
0 commit comments