... |
... |
@@ -152,24 +152,26 @@ def get_refs(ref_type, name_start): |
152
|
152
|
or "head") that starts with the given 'name_start'.
|
153
|
153
|
"""
|
154
|
154
|
if ref_type == "tag":
|
155
|
|
- # Instead of returning tag hash, return the commit hash it points to.
|
156
|
|
- fstring = "%(*objectname)"
|
157
|
155
|
ref_start = "refs/tags/"
|
158
|
156
|
elif ref_type == "remote":
|
159
|
|
- fstring = "%(objectname)"
|
160
|
157
|
ref_start = "refs/remotes/"
|
161
|
158
|
elif ref_type == "head":
|
162
|
|
- fstring = "%(objectname)"
|
163
|
159
|
ref_start = "refs/heads/"
|
164
|
160
|
else:
|
165
|
161
|
raise TypeError(f"Unknown type {ref_type}")
|
166
|
162
|
|
167
|
|
- fstring = f"{fstring},%(refname)"
|
|
163
|
+ fstring = "%(*objectname),%(objectname),%(refname)"
|
168
|
164
|
pattern = f"{ref_start}{name_start}**"
|
169
|
165
|
|
170
|
166
|
def line_to_ref(line):
|
171
|
|
- [commit, ref_name] = line.split(",", 1)
|
172
|
|
- return Reference(ref_name.replace(ref_start, "", 1), commit)
|
|
167
|
+ [objectname_reference, objectname, ref_name] = line.split(",", 2)
|
|
168
|
+ # For annotated tags, the objectname_reference is non-empty and points
|
|
169
|
+ # to an actual commit.
|
|
170
|
+ # For remotes, heads and lightweight tags, the objectname_reference will
|
|
171
|
+ # be empty and objectname will point directly to the commit.
|
|
172
|
+ return Reference(
|
|
173
|
+ ref_name.replace(ref_start, "", 1), objectname_reference or objectname
|
|
174
|
+ )
|
173
|
175
|
|
174
|
176
|
return [
|
175
|
177
|
line_to_ref(line)
|
... |
... |
@@ -245,7 +247,7 @@ def file_contains(filename, regex): |
245
|
247
|
Return whether the file is a utf-8 text file containing the regular
|
246
|
248
|
expression given by 'regex'.
|
247
|
249
|
"""
|
248
|
|
- with open(filename, "r", encoding="utf-8") as file:
|
|
250
|
+ with open(filename, encoding="utf-8") as file:
|
249
|
251
|
try:
|
250
|
252
|
for line in file:
|
251
|
253
|
if regex.search(line):
|