summaryrefslogtreecommitdiff
path: root/methods.py
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-07-25 08:45:40 +0200
committerGitHub <noreply@github.com>2022-07-25 08:45:40 +0200
commitcc09dc92c8ee06255a158d81533d35c6d2e8d31e (patch)
tree4884ac4b61899042395d913004908dcc1e97a1dc /methods.py
parentaf45036d1ac39591972fee2b7da9780fa4d09d28 (diff)
parent77cf65804c732431574a99063f2132567d54a6be (diff)
Merge pull request #63422 from nathanfranke/git-ready
Support git packed refs in version generator
Diffstat (limited to 'methods.py')
-rw-r--r--methods.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/methods.py b/methods.py
index 1db3a8aa01..571b134c8a 100644
--- a/methods.py
+++ b/methods.py
@@ -125,9 +125,21 @@ def update_version(module_version_string=""):
if os.path.isfile(os.path.join(gitfolder, "HEAD")):
head = open(os.path.join(gitfolder, "HEAD"), "r", encoding="utf8").readline().strip()
if head.startswith("ref: "):
- head = os.path.join(gitfolder, head[5:])
+ ref = head[5:]
+ head = os.path.join(gitfolder, ref)
+ packedrefs = os.path.join(gitfolder, "packed-refs")
if os.path.isfile(head):
githash = open(head, "r").readline().strip()
+ elif os.path.isfile(packedrefs):
+ # Git may pack refs into a single file. This code searches .git/packed-refs file for the current ref's hash.
+ # https://mirrors.edge.kernel.org/pub/software/scm/git/docs/git-pack-refs.html
+ for line in open(packedrefs, "r").read().splitlines():
+ if line.startswith("#"):
+ continue
+ (line_hash, line_ref) = line.split(" ")
+ if ref == line_ref:
+ githash = line_hash
+ break
else:
githash = head