Fixed #22867 -- Memoized django.utils.version.get_git_changeset().

Restored original fix that had to be removed because the old djangoproject
server was still using Python 2.6.
This commit is contained in:
Tim Graham 2014-08-23 09:26:59 -04:00
parent 1c660d0de2
commit 2c681e8a8c
1 changed files with 5 additions and 10 deletions

View File

@ -4,6 +4,8 @@ import datetime
import os
import subprocess
from django.utils.lru_cache import lru_cache
def get_version(version=None):
"Returns a PEP 386-compliant version number from VERSION."
@ -50,6 +52,7 @@ def get_complete_version(version=None):
return version
@lru_cache()
def get_git_changeset():
"""Returns a numeric identifier of the latest git changeset.
@ -57,10 +60,6 @@ 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,
@ -69,9 +68,5 @@ def get_git_changeset():
try:
timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
except ValueError:
changeset = None
else:
changeset = timestamp.strftime('%Y%m%d%H%M%S')
get_git_changeset.cache = changeset
return changeset
return None
return timestamp.strftime('%Y%m%d%H%M%S')