summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Bistuer <loic.bistuer@gmail.com>2014-06-23 00:03:58 +0700
committerLoic Bistuer <loic.bistuer@gmail.com>2014-06-23 00:03:58 +0700
commitf07735c619c121d8785082972acd8fbad8b236af (patch)
tree508255d1cf80dad978305cc28abcdfa50bf0014f
parentc6a711d9e50835eca0f3fcf79089ef75251ec931 (diff)
Fixed #22867 -- Memoized django.utils.version.get_git_changeset().
This follows commits 80f4487 and 01399fa; original patch had to be reverted because it wasn't Python 2.6 compatible and we need it to be in order to build docs on the djangoproject.com server. This fix should be replaced by @lru_cache as soon as we drop Python 2.6 compatibility. Thanks Florian Apolloner for the review and Alexander Schepanovski for the original patch.
-rw-r--r--django/utils/version.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/django/utils/version.py b/django/utils/version.py
index c680dbdc4a..90a41adc8d 100644
--- a/django/utils/version.py
+++ b/django/utils/version.py
@@ -57,6 +57,10 @@ def get_git_changeset():
This value isn't guaranteed to be unique, but collisions are very unlikely,
so it's sufficient for generating the development version numbers.
"""
+ # FIXME: Replace with @lru_cache when we upgrade the docs server to PY2.7+.
+ if hasattr(get_git_changeset, 'cache'):
+ return get_git_changeset.cache
+
repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
git_log = subprocess.Popen('git log --pretty=format:%ct --quiet -1 HEAD',
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
@@ -65,5 +69,9 @@ def get_git_changeset():
try:
timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
except ValueError:
- return None
- return timestamp.strftime('%Y%m%d%H%M%S')
+ changeset = None
+ else:
+ changeset = timestamp.strftime('%Y%m%d%H%M%S')
+
+ get_git_changeset.cache = changeset
+ return changeset