Rev 4494: Add --tree to revno and revision-info in http://bazaar.launchpad.net/%7Evila/bzr/integration

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Jun 30 18:00:39 BST 2009


At http://bazaar.launchpad.net/%7Evila/bzr/integration

------------------------------------------------------------
revno: 4494 [merge]
revision-id: v.ladeuil+lp at free.fr-20090630170026-5kfdfs33sqd1j9ds
parent: pqm at pqm.ubuntu.com-20090630102058-mkgmx4g87dkdpu63
parent: v.ladeuil+lp at free.fr-20090630165921-jdg42f5unm33nz8a
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: integration
timestamp: Tue 2009-06-30 19:00:26 +0200
message:
  Add --tree to revno and revision-info
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/blackbox/test_revision_info.py test_revision_info.py-20050917162600-21dab3877aa348d7
  bzrlib/tests/blackbox/test_revno.py test_revno.py-20051204214528-2f0bf83a71b7656a
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2009-06-30 09:21:21 +0000
+++ b/NEWS	2009-06-30 17:00:26 +0000
@@ -26,6 +26,10 @@
   speified. The configuration option ``push_strict`` can be used to set the
   default for this behavior.  (Vincent Ladeuil, #284038, #322808, #65286)
 
+* ``bzr revno`` and ``bzr revision-info`` now have a ``--tree`` option to
+  show revision info for the working tree instead of the branch.
+  (Matthew Fuller, John Arbash Meinel)
+
 
 Bug Fixes
 *********
@@ -135,6 +139,11 @@
   or ``bzr+ssh://`` is now much faster and involves no VFS operations.
   This speeds up commands like ``bzr pull -r 123``.  (Andrew Bennetts)
 
+* ``revision-info`` now properly aligns the revnos/revids in the output
+  and doesn't traceback when given revisions not in the current branch.
+  Performance is also significantly improved when requesting multiple revs
+  at once.  (Matthew Fuller, John Arbash Meinel)
+
 Documentation
 *************
 

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2009-06-29 09:02:28 +0000
+++ b/bzrlib/builtins.py	2009-06-30 17:00:26 +0000
@@ -474,11 +474,36 @@
 
     _see_also = ['info']
     takes_args = ['location?']
+    takes_options = [
+        Option('tree', help='Show revno of working tree'),
+        ]
 
     @display_command
-    def run(self, location=u'.'):
-        self.outf.write(str(Branch.open_containing(location)[0].revno()))
-        self.outf.write('\n')
+    def run(self, tree=False, location=u'.'):
+        if tree:
+            try:
+                wt = WorkingTree.open_containing(location)[0]
+                wt.lock_read()
+            except (errors.NoWorkingTree, errors.NotLocalUrl):
+                raise errors.NoWorkingTree(location)
+            try:
+                revid = wt.last_revision()
+                try:
+                    revno_t = wt.branch.revision_id_to_dotted_revno(revid)
+                except errors.NoSuchRevision:
+                    revno_t = ('???',)
+                revno = ".".join(str(n) for n in revno_t)
+            finally:
+                wt.unlock()
+        else:
+            b = Branch.open_containing(location)[0]
+            b.lock_read()
+            try:
+                revno = b.revno()
+            finally:
+                b.unlock()
+
+        self.outf.write(str(revno) + '\n')
 
 
 class cmd_revision_info(Command):
@@ -494,31 +519,56 @@
             short_name='d',
             type=unicode,
             ),
+        Option('tree', help='Show revno of working tree'),
         ]
 
     @display_command
-    def run(self, revision=None, directory=u'.', revision_info_list=[]):
-
-        revs = []
-        if revision is not None:
-            revs.extend(revision)
-        if revision_info_list is not None:
-            for rev in revision_info_list:
-                revs.append(RevisionSpec.from_string(rev))
-
-        b = Branch.open_containing(directory)[0]
-
-        if len(revs) == 0:
-            revs.append(RevisionSpec.from_string('-1'))
-
-        for rev in revs:
-            revision_id = rev.as_revision_id(b)
-            try:
-                revno = '%4d' % (b.revision_id_to_revno(revision_id))
-            except errors.NoSuchRevision:
-                dotted_map = b.get_revision_id_to_revno_map()
-                revno = '.'.join(str(i) for i in dotted_map[revision_id])
-            print '%s %s' % (revno, revision_id)
+    def run(self, revision=None, directory=u'.', tree=False,
+            revision_info_list=[]):
+
+        try:
+            wt = WorkingTree.open_containing(directory)[0]
+            b = wt.branch
+            wt.lock_read()
+        except (errors.NoWorkingTree, errors.NotLocalUrl):
+            wt = None
+            b = Branch.open_containing(directory)[0]
+            b.lock_read()
+        try:
+            revision_ids = []
+            if revision is not None:
+                revision_ids.extend(rev.as_revision_id(b) for rev in revision)
+            if revision_info_list is not None:
+                for rev_str in revision_info_list:
+                    rev_spec = RevisionSpec.from_string(rev_str)
+                    revision_ids.append(rev_spec.as_revision_id(b))
+            # No arguments supplied, default to the last revision
+            if len(revision_ids) == 0:
+                if tree:
+                    if wt is None:
+                        raise errors.NoWorkingTree(directory)
+                    revision_ids.append(wt.last_revision())
+                else:
+                    revision_ids.append(b.last_revision())
+
+            revinfos = []
+            maxlen = 0
+            for revision_id in revision_ids:
+                try:
+                    dotted_revno = b.revision_id_to_dotted_revno(revision_id)
+                    revno = '.'.join(str(i) for i in dotted_revno)
+                except errors.NoSuchRevision:
+                    revno = '???'
+                maxlen = max(maxlen, len(revno))
+                revinfos.append([revno, revision_id])
+        finally:
+            if wt is None:
+                b.unlock()
+            else:
+                wt.unlock()
+
+        for ri in revinfos:
+            self.outf.write('%*s %s\n' % (maxlen, ri[0], ri[1]))
 
 
 class cmd_add(Command):

=== modified file 'bzrlib/tests/blackbox/test_revision_info.py'
--- a/bzrlib/tests/blackbox/test_revision_info.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/blackbox/test_revision_info.py	2009-06-30 16:59:21 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2004, 2005 Canonical Ltd
+# Copyright (C) 2004, 2005, 2009 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -47,9 +47,9 @@
 
         # Expected return values
         values = {
-            '1'    : '   1 a at r-0-1\n',
+            '1'    : '1 a at r-0-1\n',
             '1.1.1': '1.1.1 a at r-0-1.1.1\n',
-            '2'    : '   2 a at r-0-2\n'
+            '2'    : '2 a at r-0-2\n'
         }
 
         # Make sure with no arg it defaults to the head
@@ -60,7 +60,9 @@
         self.check_output(values['1.1.1'], 'revision-info 1.1.1')
         self.check_output(values['2'], 'revision-info 2')
         self.check_output(values['1']+values['2'], 'revision-info 1 2')
-        self.check_output(values['1']+values['1.1.1']+values['2'],
+        self.check_output('    '+values['1']+
+                                 values['1.1.1']+
+                          '    '+values['2'],
                           'revision-info 1 1.1.1 2')
         self.check_output(values['2']+values['1'], 'revision-info 2 1')
 
@@ -70,7 +72,9 @@
         self.check_output(values['1.1.1'], 'revision-info --revision 1.1.1')
         self.check_output(values['2'], 'revision-info -r 2')
         self.check_output(values['1']+values['2'], 'revision-info -r 1..2')
-        self.check_output(values['1']+values['1.1.1']+values['2'],
+        self.check_output('    '+values['1']+
+                                 values['1.1.1']+
+                          '    '+values['2'],
                           'revision-info -r 1..1.1.1..2')
         self.check_output(values['2']+values['1'], 'revision-info -r 2..1')
 
@@ -85,4 +89,40 @@
         wt = self.make_branch_and_tree('branch')
 
         wt.commit('Commit one', rev_id='a at r-0-1')
-        self.check_output('   1 a at r-0-1\n', 'revision-info -d branch')
+        self.check_output('1 a at r-0-1\n', 'revision-info -d branch')
+
+    def test_revision_info_tree(self):
+        # Make branch and checkout
+        wt = self.make_branch_and_tree('branch')
+        wt.commit('Commit one', rev_id='a at r-0-1')
+
+        # Make checkout and move the branch forward
+        wt.branch.create_checkout('checkout', lightweight=True)
+        wt.commit('Commit two', rev_id='a at r-0-2')
+
+        # Make sure the checkout gives the right answer for branch and
+        # tree
+        self.check_output('2 a at r-0-2\n', 'revision-info -d checkout')
+        self.check_output('1 a at r-0-1\n', 'revision-info --tree -d checkout')
+
+    def test_revision_info_tree_no_working_tree(self):
+        # Make branch with no tree
+        b = self.make_branch('branch')
+
+        # Try getting the --tree revision-info
+        out,err = self.run_bzr('revision-info --tree -d branch', retcode=3)
+        self.assertEqual('', out)
+        self.assertEqual('bzr: ERROR: No WorkingTree exists for "branch".\n',
+            err)
+
+    def test_revision_info_not_in_history(self):
+        builder = self.make_branch_builder('branch')
+        builder.start_series()
+        builder.build_snapshot('A-id', None, [
+            ('add', ('', 'root-id', 'directory', None))])
+        builder.build_snapshot('B-id', ['A-id'], [])
+        builder.build_snapshot('C-id', ['A-id'], [])
+        builder.finish_series()
+        self.check_output('  1 A-id\n??? B-id\n  2 C-id\n',
+                          'revision-info -d branch'
+                          ' revid:A-id revid:B-id revid:C-id')

=== modified file 'bzrlib/tests/blackbox/test_revno.py'
--- a/bzrlib/tests/blackbox/test_revno.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/blackbox/test_revno.py	2009-06-30 16:59:21 +0000
@@ -1,5 +1,4 @@
-# Copyright (C) 2005 Canonical Ltd
-# -*- coding: utf-8 -*-
+# Copyright (C) 2005, 2006, 2007, 2009 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -21,10 +20,9 @@
 
 import os
 
-from bzrlib.branch import Branch
-from bzrlib.tests import TestCaseInTempDir
+from bzrlib import tests
 
-class TestRevno(TestCaseInTempDir):
+class TestRevno(tests.TestCaseWithTransport):
 
     def test_revno(self):
 
@@ -50,4 +48,72 @@
         self.assertEquals(int(bzr('revno a')), 2)
         self.assertEquals(int(bzr('revno a/baz')), 2)
 
-
+    def test_revno_tree(self):
+        # Make branch and checkout
+        wt = self.make_branch_and_tree('branch')
+        checkout = wt.branch.create_checkout('checkout', lightweight=True)
+
+        # Get the checkout out of date
+        self.build_tree(['branch/file'])
+        wt.add(['file'])
+        wt.commit('mkfile')
+
+        # Make sure revno says we're on 1
+        out,err = self.run_bzr('revno checkout')
+        self.assertEqual('', err)
+        self.assertEqual('1\n', out)
+
+        # Make sure --tree knows it's still on 0
+        out,err = self.run_bzr('revno --tree checkout')
+        self.assertEqual('', err)
+        self.assertEqual('0\n', out)
+
+    def test_revno_tree_no_tree(self):
+        # Make treeless branch
+        b = self.make_branch('branch')
+
+        # Try getting it's --tree revno
+        out,err = self.run_bzr('revno --tree branch', retcode=3)
+        self.assertEqual('', out)
+        self.assertEqual('bzr: ERROR: No WorkingTree exists for "branch".\n',
+            err)
+
+    def test_dotted_revno_tree(self):
+        builder = self.make_branch_builder('branch')
+        builder.start_series()
+        builder.build_snapshot('A-id', None, [
+            ('add', ('', 'root-id', 'directory', None)),
+            ('add', ('file', 'file-id', 'file', 'content\n'))])
+        builder.build_snapshot('B-id', ['A-id'], [])
+        builder.build_snapshot('C-id', ['A-id', 'B-id'], [])
+        builder.finish_series()
+        b = builder.get_branch()
+        co_b = b.create_checkout('checkout_b', lightweight=True,
+                                 revision_id='B-id')
+        out, err = self.run_bzr('revno checkout_b')
+        self.assertEqual('', err)
+        self.assertEqual('2\n', out)
+        out, err = self.run_bzr('revno --tree checkout_b')
+        self.assertEqual('', err)
+        self.assertEqual('1.1.1\n', out)
+
+    def test_stale_revno_tree(self):
+        builder = self.make_branch_builder('branch')
+        builder.start_series()
+        builder.build_snapshot('A-id', None, [
+            ('add', ('', 'root-id', 'directory', None)),
+            ('add', ('file', 'file-id', 'file', 'content\n'))])
+        builder.build_snapshot('B-id', ['A-id'], [])
+        builder.build_snapshot('C-id', ['A-id'], [])
+        builder.finish_series()
+        b = builder.get_branch()
+        # The branch is now at "C-id", but the checkout is still at "B-id"
+        # which is no longer in the history
+        co_b = b.create_checkout('checkout_b', lightweight=True,
+                                 revision_id='B-id')
+        out, err = self.run_bzr('revno checkout_b')
+        self.assertEqual('', err)
+        self.assertEqual('2\n', out)
+        out, err = self.run_bzr('revno --tree checkout_b')
+        self.assertEqual('', err)
+        self.assertEqual('???\n', out)



More information about the bazaar-commits mailing list