]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Show git branch in version output. fixes #1953
authorDaira Hopwood <david-sarah@jacaranda.org>
Thu, 25 Apr 2013 01:14:50 +0000 (02:14 +0100)
committerDaira Hopwood <david-sarah@jacaranda.org>
Wed, 1 May 2013 21:38:08 +0000 (22:38 +0100)
Also make sure strings in _version.py are correctly escaped, and repair a test.

Signed-off-by: Daira Hopwood <david-sarah@jacaranda.org>
setup.py
src/allmydata/__init__.py
src/allmydata/test/test_runner.py

index 0aa5cc66bff599ba6d679ca016024114a379406d..d2c0b8756e912f6e2cd67b93cfad4070e086d07a 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -243,10 +243,11 @@ class MakeExecutable(Command):
 GIT_VERSION_BODY = '''
 # This _version.py is generated from git metadata by the tahoe setup.py.
 
-__pkgname__ = "%(pkgname)s"
-real_version = "%(version)s"
-full_version = "%(full)s"
-verstr = "%(normalized)s"
+__pkgname__ = %(pkgname)r
+real_version = %(version)r
+full_version = %(full)r
+branch = %(branch)r
+verstr = %(normalized)r
 __version__ = verstr
 '''
 
@@ -309,6 +310,7 @@ def versions_from_git(tag_prefix, verbose=False):
         normalized_version = pieces[0]
     else:
         normalized_version = "%s.post%s" % (pieces[0], pieces[1])
+
     stdout = run_command([GIT, "rev-parse", "HEAD"], cwd=source_dir)
     if stdout is None:
         return {}
@@ -316,7 +318,12 @@ def versions_from_git(tag_prefix, verbose=False):
     if version.endswith("-dirty"):
         full += "-dirty"
         normalized_version += ".dev0"
-    return {"version": version, "normalized": normalized_version, "full": full}
+
+    # Thanks to Jistanidiot at <http://stackoverflow.com/questions/6245570/get-current-branch-name>.
+    stdout = run_command([GIT, "rev-parse", "--abbrev-ref", "HEAD"], cwd=source_dir)
+    branch = (stdout or "unknown").strip()
+
+    return {"version": version, "normalized": normalized_version, "full": full, "branch": branch}
 
 # setup.cfg has an [aliases] section which runs "update_version" before many
 # commands (like "build" and "sdist") that need to know our package version
@@ -350,7 +357,9 @@ class UpdateVersion(Command):
                     { "pkgname": self.distribution.get_name(),
                       "version": versions["version"],
                       "normalized": versions["normalized"],
-                      "full": versions["full"] })
+                      "full": versions["full"],
+                      "branch": versions["branch"],
+                    })
             f.close()
             print("git-version: wrote '%s' into '%s'" % (versions["version"], fn))
         return versions.get("normalized", None)
index f6eff199e45019d2da08faa1f0a1182aca81d3b4..4bafed474fb19e56e85efc44292cb937eb394295 100644 (file)
@@ -15,9 +15,19 @@ __version__ = "unknown"
 try:
     from allmydata._version import __version__
 except ImportError:
-    # We're running in a tree that hasn't run "./setup.py darcsver", and didn't
-    # come with a _version.py, so we don't know what our version is. This should
-    # not happen very often.
+    # We're running in a tree that hasn't run update_version, and didn't
+    # come with a _version.py, so we don't know what our version is.
+    # This should not happen very often.
+    pass
+
+full_version = "unknown"
+branch = "unknown"
+try:
+    from allmydata._version import full_version, branch
+except ImportError:
+    # We're running in a tree that hasn't run update_version, and didn't
+    # come with a _version.py, so we don't know what our full version or
+    # branch is. This should not happen very often.
     pass
 
 __appname__ = "unknown"
@@ -191,7 +201,9 @@ def get_package_versions_and_locations():
                 packages.append( (pkgname, (None, None, trace_info)) )
             else:
                 comment = None
-                if pkgname == 'setuptools' and hasattr(module, '_distribute'):
+                if pkgname == __appname__:
+                    comment = "%s: %s" % (branch, full_version)
+                elif pkgname == 'setuptools' and hasattr(module, '_distribute'):
                     # distribute does not report its version in any module variables
                     comment = 'distribute'
                 packages.append( (pkgname, (get_version(module, '__version__'), package_dir(module.__file__), comment)) )
index 33974e2eb0390ef18002a1e47a6b9b2df58bc3c0..b5ccaa568639a6573da3ed48fc3c1a2574026feb 100644 (file)
@@ -160,7 +160,9 @@ class BinTahoe(common_util.SignalMixin, unittest.TestCase, RunBinTahoeMixin):
             info = repr((res, allmydata.__appname__, required_verstr, srcdir))
 
             appverpath = out.split(')')[0]
-            (appver, path) = appverpath.split(' (')
+            (appverfull, path) = appverpath.split('] (')
+            (appver, comment) = appverfull.split(' [')
+            (branch, full_version) = comment.split(': ')
             (app, ver) = appver.split(': ')
 
             self.failUnlessEqual(app, allmydata.__appname__, info)
@@ -168,6 +170,8 @@ class BinTahoe(common_util.SignalMixin, unittest.TestCase, RunBinTahoeMixin):
             norm_required = normalized_version(required_verstr)
             self.failUnlessEqual(norm_ver, norm_required, info)
             self.failUnlessEqual(path, srcdir, info)
+            self.failUnlessEqual(branch, allmydata.branch)
+            self.failUnlessEqual(full_version, allmydata.full_version)
         d.addCallback(_cb)
         return d