Commits

Dan Villiom Podlaski Christiansen committed 9ece435

Fix up Mercurial identification patch.

  • Participants
  • Parent commits c3f1f1b

Comments (0)

Files changed (2)

+sys-mercurial.diff
 hgignore.diff
 no-macports.diff
 visibility.diff
 sem_t.diff
 database-sentinels.diff
 w_star-doc.diff
-sys-mercurial.diff #+broken

sys-mercurial.diff

 # HG changeset patch
-# Parent 3a68a0810456d087a04056bdaed847144553b14a
+# Parent 0b2b2103636a54cae7ec0f2ac28f0c5aad309007
 # User Dan Villiom Podlaski Christiansen <danchr@gmail.com>
+Add sys._mercurial attribute.
+
+Based on the equivalent patch to CPython 2.7:
+<http://hg.python.org/pymigr/file/tip/build-identification/add-hg-build-id.diff>
+
+Example output:
+
+$ ./python.exe -c 'import sys; print sys.subversion; print sys._mercurial'
+('CPython', 'branches/release27-maint', '')
+('CPython', 'add-hg-build-id.diff qbase qtip tip', 'a40affe1a0c3')
+$ ./pypy-c -c 'import sys; print(sys.subversion); print(sys._mercurial)'
+('PyPy', '', '0')
+('PyPy', 'qbase qtip sys-mercurial.diff tip', '0d934b96b4d7+')
+
+The Mercurial version detection calls out to 'hg' rather than parsing
+the Mercurial dirstate directly. There are two reasons for this:
+
+1) The Mercurial dirstate is a binary file, and its format is an
+   implementation detail of Mercurial.
+2) Tags are used in the output, and the Mercurial logic for
+   determining what tags to apply is fairly complex and often extended
+   by extensions.
+
 diff --git a/pypy/module/sys/__init__.py b/pypy/module/sys/__init__.py
 --- a/pypy/module/sys/__init__.py
 +++ b/pypy/module/sys/__init__.py
 diff --git a/pypy/module/sys/version.py b/pypy/module/sys/version.py
 --- a/pypy/module/sys/version.py
 +++ b/pypy/module/sys/version.py
-@@ -84,6 +84,32 @@ def get_subversion_info(space):
+@@ -84,6 +84,30 @@ def get_subversion_info(space):
                             space.wrap(svnbranch),
                             space.wrap(str(svn_revision()))])
  
 +def get_mercurial_info(space):
++    '''Obtain Mercurial version information by invoking the 'hg' command.'''
++    # TODO: support extracting from .hg_archival.txt
 +    import py
-+    from pypy.tool.ansi_print import ansi_log
-+    log = py.log.Producer("version")
-+    py.log.setconsumer("version", ansi_log)
-+    log.ERROR("pypydir is %r" % pypydir)
 +
-+    if not os.path.isdir(os.path.join(pypydir, '..', '.hg')):
-+        return space.w_None
-+    else:
++    pypyroot = os.path.abspath(os.path.join(pypydir, '..'))
++    hgexe = py.path.local.sysfind('hg')
++
++    if hgexe and os.path.isdir(os.path.join(pypyroot, '.hg')):
 +        os.putenv('HGPLAIN', '1')
-+        fp = os.popen('hg id -i "%s"' % pypydir)
++        fp = os.popen('%s id -i "%s"' % (hgexe, os.path.join(pypydir, '..')))
 +        hgid = fp.read().strip()
 +        fp.close()
 +
-+        fp = os.popen('hg id -t "%s"' % pypydir)
++        fp = os.popen('%s id -t "%s"' % (hgexe, os.path.join(pypydir, '..')))
 +        hgtags = fp.read().strip()
 +        fp.close()
 +
-+        log.ERROR("tag is %r" % hgtags)
-+        log.ERROR("id is %r" % hgid)
-+
 +        return space.newtuple([space.wrap('PyPy'),
 +                               space.wrap(hgtags),
 +                               space.wrap(hgid)])
++    else:
++        return space.w_None
 +
  def tuple2hex(ver):
      d = {'alpha':     0xA,
           'beta':      0xB,
-@@ -133,4 +159,12 @@ def svn_revision():
-             f.close()
-     except (IOError, OSError):
-         pass
-+    if rev == 0 and os.path.isdir(os.path.join(pypydir, '..', '.hg')):
-+        try:
-+            os.putenv('HGPLAIN', '1')
-+            fp = os.popen('hg id -i "%s"' % pypydir)
-+            rev = fp.read().strip()
-+            fp.close()
-+        except (IOError, OSError), e:
-+            pass
-     return rev