Rev 4252: (Jelmer) Fix version-info in empty branches. in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Apr 3 23:31:04 BST 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4252
revision-id: pqm at pqm.ubuntu.com-20090403223059-0bqboagykhewobst
parent: pqm at pqm.ubuntu.com-20090403190338-yy0lftj7t2v9vah3
parent: jelmer at samba.org-20090403212355-z81946ra1auxlkme
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2009-04-03 23:30:59 +0100
message:
  (Jelmer) Fix version-info in empty branches.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/tests/test_version_info.py test_version_info.py-20051228204928-2c364e30b702b41b
  bzrlib/version_info_formats/format_custom.py format_custom.py-20071029100350-ajovqhbpb5khf6gu-1
  bzrlib/version_info_formats/format_python.py format_python.py-20060809202444-ike7i9ub03gb432p-1
  bzrlib/version_info_formats/format_rio.py format_rio.py-20060809202444-ike7i9ub03gb432p-2
    ------------------------------------------------------------
    revno: 4250.1.1
    revision-id: jelmer at samba.org-20090403212355-z81946ra1auxlkme
    parent: pqm at pqm.ubuntu.com-20090403175303-dff3pm9dvtg26be9
    committer: Jelmer Vernooij <jelmer at samba.org>
    branch nick: versioninfo-null
    timestamp: Fri 2009-04-03 23:23:55 +0200
    message:
      Fix version-info in empty branches.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/tests/test_version_info.py test_version_info.py-20051228204928-2c364e30b702b41b
      bzrlib/version_info_formats/format_custom.py format_custom.py-20071029100350-ajovqhbpb5khf6gu-1
      bzrlib/version_info_formats/format_python.py format_python.py-20060809202444-ike7i9ub03gb432p-1
      bzrlib/version_info_formats/format_rio.py format_rio.py-20060809202444-ike7i9ub03gb432p-2
=== modified file 'NEWS'
--- a/NEWS	2009-04-03 19:03:38 +0000
+++ b/NEWS	2009-04-03 22:30:59 +0000
@@ -131,6 +131,9 @@
 * bzr gives a better message if an invalid regexp is passed to ``bzr log
   -m``.  (Anne Mohsen, Martin Pool)
 
+* ``bzr version-info`` now works in empty branches. (Jelmer Vernooij, 
+  #313028)
+
 * Fix "is not a stackable format" error when pushing a
   stackable-format branch with an unstackable-format repository to a
   destination with a default stacking policy.  (Andrew Bennetts)

=== modified file 'bzrlib/tests/test_version_info.py'
--- a/bzrlib/tests/test_version_info.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/test_version_info.py	2009-04-03 21:23:55 +0000
@@ -53,6 +53,16 @@
 
         return wt
 
+    def test_rio_null(self):
+        wt = self.make_branch_and_tree('branch')
+
+        sio = StringIO()
+        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
+        builder.generate(sio)
+        val = sio.getvalue()
+        self.assertContainsRe(val, 'build-date:')
+        self.assertContainsRe(val, 'revno: 0')
+
     def test_rio_version_text(self):
         wt = self.create_branch()
 
@@ -154,6 +164,16 @@
         self.assertEqual(['r4', 'r4', 'unversioned', 'removed'],
                          file_rev_stanza.get_all('revision'))
 
+    def test_python_null(self):
+        wt = self.make_branch_and_tree('branch')
+
+        sio = StringIO()
+        builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
+        builder.generate(sio)
+        val = sio.getvalue()
+        self.assertContainsRe(val, "'revision_id': None")
+        self.assertContainsRe(val, "'revno': 0")
+
     def test_python_version(self):
         wt = self.create_branch()
 
@@ -229,6 +249,20 @@
         self.assertEqual('unversioned', tvi.file_revisions['c'])
         self.assertEqual('removed', tvi.file_revisions['d'])
 
+    def test_custom_null(self):
+        sio = StringIO()
+        wt = self.make_branch_and_tree('branch')
+        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
+            template='revno: {revno}')
+        builder.generate(sio)
+        self.assertEquals("revno: 0", sio.getvalue())
+
+        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt, 
+            template='{revno} revid: {revision_id}')
+        # revision_id is not available yet
+        self.assertRaises(errors.MissingTemplateVariable, 
+            builder.generate, sio)
+
     def test_custom_version_text(self):
         wt = self.create_branch()
 

=== modified file 'bzrlib/version_info_formats/format_custom.py'
--- a/bzrlib/version_info_formats/format_custom.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/version_info_formats/format_custom.py	2009-04-03 21:23:55 +0000
@@ -18,6 +18,9 @@
    tree info."""
 
 from bzrlib import errors
+from bzrlib.revision import (
+   NULL_REVISION,
+   )
 from bzrlib.lazy_regex import lazy_compile
 from bzrlib.version_info_formats import (
    create_date_str,
@@ -87,7 +90,7 @@
         info.add('branch_nick', self._branch.nick)
 
         revision_id = self._get_revision_id()
-        if revision_id is None:
+        if revision_id == NULL_REVISION:
             info.add('revno', 0)
         else:
             info.add('revno', self._branch.revision_id_to_revno(revision_id))

=== modified file 'bzrlib/version_info_formats/format_python.py'
--- a/bzrlib/version_info_formats/format_python.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/version_info_formats/format_python.py	2009-04-03 21:23:55 +0000
@@ -18,6 +18,9 @@
 
 import pprint
 
+from bzrlib.revision import (
+    NULL_REVISION,
+    )
 from bzrlib.version_info_formats import (
     create_date_str,
     VersionInfoBuilder,
@@ -57,7 +60,7 @@
         revisions = []
 
         revision_id = self._get_revision_id()
-        if revision_id is None:
+        if revision_id == NULL_REVISION:
             info['revno'] = 0
         else:
             info['revno'] = self._branch.revision_id_to_revno(revision_id)

=== modified file 'bzrlib/version_info_formats/format_rio.py'
--- a/bzrlib/version_info_formats/format_rio.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/version_info_formats/format_rio.py	2009-04-03 21:23:55 +0000
@@ -16,6 +16,9 @@
 
 """A generator which creates a rio stanza of the current tree info"""
 
+from bzrlib.revision import (
+    NULL_REVISION,
+    )
 from bzrlib.rio import RioWriter, Stanza
 
 from bzrlib.version_info_formats import (
@@ -30,7 +33,7 @@
     def generate(self, to_file):
         info = Stanza()
         revision_id = self._get_revision_id()
-        if revision_id is not None:
+        if revision_id != NULL_REVISION:
             info.add('revision-id', revision_id)
             rev = self._branch.repository.get_revision(revision_id)
             info.add('date', create_date_str(rev.timestamp, rev.timezone))




More information about the bazaar-commits mailing list