Ticket #18224: 18224.patch

File 18224.patch, 4.0 KB (added by Aymeric Augustin, 13 years ago)
  • django/__init__.py

    diff --git a/django/__init__.py b/django/__init__.py
    index 20ca234..6191e26 100644
    a b  
     1import datetime
     2import os
     3import subprocess
     4
     5
    16VERSION = (1, 5, 0, 'alpha', 0)
    27
     8
    39def get_version(version=None):
    410    """Derives a PEP386-compliant version number from VERSION."""
    511    if version is None:
    def get_version(version=None):  
    1723
    1824    sub = ''
    1925    if version[3] == 'alpha' and version[4] == 0:
    20         # At the toplevel, this would cause an import loop.
    21         from django.utils.version import get_svn_revision
    22         svn_revision = get_svn_revision()[4:]
    23         if svn_revision != 'unknown':
    24             sub = '.dev%s' % svn_revision
     26        git_changeset = get_git_changeset()
     27        if git_changeset:
     28            sub = '.dev%s' % git_changeset
    2529
    2630    elif version[3] != 'final':
    2731        mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'}
    2832        sub = mapping[version[3]] + str(version[4])
    2933
    3034    return main + sub
     35
     36
     37def get_git_changeset():
     38    """Return an identifier the latest git changeset.
     39
     40    The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
     41    This value isn't guaranteed to be unique but collisions are very unlikely,
     42    so it's sufficient for generating the development version numbers.
     43    """
     44    repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     45    git_show = subprocess.Popen('git show --pretty=format:%ct --quiet HEAD',
     46            stdout=subprocess.PIPE, stderr=subprocess.PIPE,
     47            shell=True, cwd=repo_dir, universal_newlines=True)
     48    timestamp = git_show.communicate()[0].partition('\n')[0]
     49    try:
     50        timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
     51    except ValueError:
     52        return None
     53    return timestamp.strftime('%Y%m%d%H%M%S')
  • deleted file django/utils/version.py

    diff --git a/django/utils/version.py b/django/utils/version.py
    deleted file mode 100644
    index cb8623b..0000000
    + -  
    1 import django
    2 import re
    3 
    4 def get_svn_revision(path=None):
    5     """
    6     Returns the SVN revision in the form SVN-XXXX,
    7     where XXXX is the revision number.
    8 
    9     Returns SVN-unknown if anything goes wrong, such as an unexpected
    10     format of internal SVN files.
    11 
    12     If path is provided, it should be a directory whose SVN info you want to
    13     inspect. If it's not provided, this will use the root django/ package
    14     directory.
    15     """
    16     rev = None
    17     if path is None:
    18         path = django.__path__[0]
    19     entries_path = '%s/.svn/entries' % path
    20 
    21     try:
    22         entries = open(entries_path, 'r').read()
    23     except IOError:
    24         pass
    25     else:
    26         # Versions >= 7 of the entries file are flat text.  The first line is
    27         # the version number. The next set of digits after 'dir' is the revision.
    28         if re.match('(\d+)', entries):
    29             rev_match = re.search('\d+\s+dir\s+(\d+)', entries)
    30             if rev_match:
    31                 rev = rev_match.groups()[0]
    32         # Older XML versions of the file specify revision as an attribute of
    33         # the first entries node.
    34         else:
    35             from xml.dom import minidom
    36             dom = minidom.parse(entries_path)
    37             rev = dom.getElementsByTagName('entry')[0].getAttribute('revision')
    38 
    39     if rev:
    40         return u'SVN-%s' % rev
    41     return u'SVN-unknown'
  • tests/regressiontests/version/tests.py

    diff --git a/tests/regressiontests/version/tests.py b/tests/regressiontests/version/tests.py
    index 1a67483..9b849ee 100644
    a b class VersionTests(TestCase):  
    88    def test_development(self):
    99        ver_tuple = (1, 4, 0, 'alpha', 0)
    1010        # This will return a different result when it's run within or outside
    11         # of a SVN checkout: 1.4.devNNNNN or 1.4.
     11        # of a git clone: 1.4.devYYYYMMDDHHMMSS or 1.4.
    1212        ver_string = get_version(ver_tuple)
    1313        self.assertRegexpMatches(ver_string, r'1\.4(\.dev\d+)?')
    1414
Back to Top