diff --git a/django/__init__.py b/django/__init__.py
index 20ca234..21469e4 100644
a
|
b
|
def get_version(version=None):
|
18 | 18 | sub = '' |
19 | 19 | if version[3] == 'alpha' and version[4] == 0: |
20 | 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 |
| 21 | from django.utils.version import get_git_revision |
| 22 | git_revision = get_git_revision()[:10] |
| 23 | if git_revision != 'unknown': |
| 24 | sub = '.dev%s' % git_revision |
25 | 25 | |
26 | 26 | elif version[3] != 'final': |
27 | 27 | mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'} |
diff --git a/django/utils/version.py b/django/utils/version.py
index cb8623b..ad6fbcb 100644
a
|
b
|
|
1 | 1 | import django |
| 2 | import os.path |
2 | 3 | import re |
3 | 4 | |
4 | 5 | def get_svn_revision(path=None): |
… |
… |
def get_svn_revision(path=None):
|
39 | 40 | if rev: |
40 | 41 | return u'SVN-%s' % rev |
41 | 42 | return u'SVN-unknown' |
| 43 | |
| 44 | |
| 45 | def get_git_revision(path=None): |
| 46 | """ |
| 47 | Returns the full 40-char hexadecimal Git revision, mimicing the behaviour |
| 48 | of 'git rev-parse HEAD'. Returns 'unknown' if anything goes wrong. |
| 49 | |
| 50 | If path is provided, it should be a top-level directory of a Git clone. If |
| 51 | it's not provided, this will use the parent directory of the django package |
| 52 | directory. |
| 53 | """ |
| 54 | rev = 'unknown' |
| 55 | if path is None: |
| 56 | path = os.path.dirname(os.path.realpath(django.__path__[0])) |
| 57 | git_path = os.path.join(path, '.git') |
| 58 | |
| 59 | try: |
| 60 | head_ref = open(os.path.join(git_path, 'HEAD'), 'r').readline().strip() |
| 61 | ref_path = os.path.join(git_path, head_ref.split(' ')[1]) |
| 62 | head = open(ref_path, 'r').readline() |
| 63 | except IOError: |
| 64 | pass |
| 65 | else: |
| 66 | rev_match = re.match(r'([0-9a-f]{40})', head) |
| 67 | if rev_match: |
| 68 | rev = rev_match.group(1) |
| 69 | |
| 70 | return rev |