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 os
import subprocess import subprocess
from django.utils.lru_cache import lru_cache
def get_version(version=None): def get_version(version=None):
"Returns a PEP 386-compliant version number from VERSION." "Returns a PEP 386-compliant version number from VERSION."
@ -50,6 +52,7 @@ def get_complete_version(version=None):
return version return version
@lru_cache()
def get_git_changeset(): def get_git_changeset():
"""Returns a numeric identifier of the latest 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, This value isn't guaranteed to be unique, but collisions are very unlikely,
so it's sufficient for generating the development version numbers. 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__))) repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
git_log = subprocess.Popen('git log --pretty=format:%ct --quiet -1 HEAD', git_log = subprocess.Popen('git log --pretty=format:%ct --quiet -1 HEAD',
stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
@ -69,9 +68,5 @@ def get_git_changeset():
try: try:
timestamp = datetime.datetime.utcfromtimestamp(int(timestamp)) timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
except ValueError: except ValueError:
changeset = None return None
else: return timestamp.strftime('%Y%m%d%H%M%S')
changeset = timestamp.strftime('%Y%m%d%H%M%S')
get_git_changeset.cache = changeset
return changeset