126
126
cursor = connection .cursor ()
127
127
builds = cursor .execute ("SELECT DISTINCT build_commit FROM test;" ).fetchall ()
128
128
129
+ commit_short_len = len (builds [0 ][0 ])
130
+
129
131
try :
130
132
repo = git .Repo ("." , search_parent_directories = True )
131
133
except git .InvalidGitRepositoryError :
@@ -138,11 +140,11 @@ def find_parent_in_data(commit: git.Commit):
138
140
seen_hexsha8 = set ()
139
141
while heap :
140
142
depth , current_commit = heapq .heappop (heap )
141
- current_hexsha8 = commit .hexsha [:8 ]
143
+ current_hexsha8 = commit .hexsha [:commit_short_len ]
142
144
if (current_hexsha8 ,) in builds :
143
145
return current_hexsha8
144
146
for parent in commit .parents :
145
- parent_hexsha8 = parent .hexsha [:8 ]
147
+ parent_hexsha8 = parent .hexsha [:commit_short_len ]
146
148
if parent_hexsha8 not in seen_hexsha8 :
147
149
seen_hexsha8 .add (parent_hexsha8 )
148
150
heapq .heappush (heap , (depth + 1 , parent ))
@@ -156,9 +158,9 @@ def get_all_parent_hexsha8s(commit: git.Commit):
156
158
157
159
while unvisited :
158
160
current_commit = unvisited .pop (0 )
159
- visited .append (current_commit .hexsha [:8 ])
161
+ visited .append (current_commit .hexsha [:commit_short_len ])
160
162
for parent in current_commit .parents :
161
- if parent .hexsha [:8 ] not in visited :
163
+ if parent .hexsha [:commit_short_len ] not in visited :
162
164
unvisited .append (parent )
163
165
164
166
return visited
@@ -169,10 +171,10 @@ def get_commit_name(hexsha8):
169
171
if repo is None :
170
172
return hexsha8
171
173
for h in repo .heads :
172
- if h .commit .hexsha [:8 ] == hexsha8 :
174
+ if h .commit .hexsha [:commit_short_len ] == hexsha8 :
173
175
return h .name
174
176
for t in repo .tags :
175
- if t .commit .hexsha [:8 ] == hexsha8 :
177
+ if t .commit .hexsha [:commit_short_len ] == hexsha8 :
176
178
return t .name
177
179
return hexsha8
178
180
@@ -183,13 +185,13 @@ def get_commit_hexsha8(name):
183
185
return None
184
186
for h in repo .heads :
185
187
if h .name == name :
186
- return h .commit .hexsha [:8 ]
188
+ return h .commit .hexsha [:commit_short_len ]
187
189
for t in repo .tags :
188
190
if t .name == name :
189
- return t .commit .hexsha [:8 ]
191
+ return t .commit .hexsha [:commit_short_len ]
190
192
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 ]
193
195
return None
194
196
195
197
0 commit comments