MCPcopy
hub / github.com/django/django / get_git_changeset

Function get_git_changeset

django/utils/version.py:78–103  ·  view source on GitHub ↗

Return a numeric identifier of the latest git changeset. The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format. This value isn't guaranteed to be unique, but collisions are very unlikely, so it's sufficient for generating the development version numbers.

()

Source from the content-addressed store, hash-verified

76
77@functools.lru_cache
78def get_git_changeset():
79 """Return a numeric identifier of the latest git changeset.
80
81 The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
82 This value isn't guaranteed to be unique, but collisions are very unlikely,
83 so it's sufficient for generating the development version numbers.
84 """
85 # Repository may not be found if __file__ is undefined, e.g. in a frozen
86 # module.
87 if "__file__" not in globals():
88 return None
89 repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
90 git_log = subprocess.run(
91 "git log --pretty=format:%ct --quiet -1 HEAD",
92 capture_output=True,
93 shell=True,
94 cwd=repo_dir,
95 text=True,
96 )
97 timestamp = git_log.stdout
98 tz = datetime.UTC
99 try:
100 timestamp = datetime.datetime.fromtimestamp(int(timestamp), tz=tz)
101 except ValueError:
102 return None
103 return timestamp.strftime("%Y%m%d%H%M%S")
104
105
106version_component_re = _lazy_re_compile(r"(\d+|[a-z]+|\.)")

Callers 1

get_versionFunction · 0.85

Calls 1

runMethod · 0.45

Tested by

no test coverage detected