Rev 3733: fix bzr st -rbranch:path-to-branch (Lukas Lalinsky) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Sep 24 08:26:51 BST 2008


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

------------------------------------------------------------
revno: 3733
revision-id: pqm at pqm.ubuntu.com-20080924072647-hpc17iasylpwiaem
parent: pqm at pqm.ubuntu.com-20080924051033-89pfepccns2637pr
parent: ian.clatworthy at canonical.com-20080924065203-69aq3cbypyyo30zs
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2008-09-24 08:26:47 +0100
message:
  fix bzr st -rbranch:path-to-branch (Lukas Lalinsky)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/diff.py                 diff.py-20050309040759-26944fbbf2ebbf36
  bzrlib/revisionspec.py         revisionspec.py-20050907152633-17567659fd5c0ddb
  bzrlib/status.py               status.py-20050505062338-431bfa63ec9b19e6
  bzrlib/tests/blackbox/test_annotate.py testannotate.py-20051013044000-457f44801bfa9d39
  bzrlib/tests/blackbox/test_status.py teststatus.py-20050712014354-508855eb9f29f7dc
  bzrlib/tests/test_revisionspec.py testrevisionnamespaces.py-20050711050225-8b4af89e6b1efe84
    ------------------------------------------------------------
    revno: 3732.1.1
    revision-id: ian.clatworthy at canonical.com-20080924065203-69aq3cbypyyo30zs
    parent: pqm at pqm.ubuntu.com-20080924051033-89pfepccns2637pr
    parent: lalinsky at gmail.com-20080828134115-265uyumclq5qvetg
    committer: Ian Clatworthy <ian.clatworthy at canonical.com>
    branch nick: ianc-integration
    timestamp: Wed 2008-09-24 16:52:03 +1000
    message:
      fix bzr st -rbranch:path-to-branch (Lukas Lalinsky)
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/diff.py                 diff.py-20050309040759-26944fbbf2ebbf36
      bzrlib/revisionspec.py         revisionspec.py-20050907152633-17567659fd5c0ddb
      bzrlib/status.py               status.py-20050505062338-431bfa63ec9b19e6
      bzrlib/tests/blackbox/test_annotate.py testannotate.py-20051013044000-457f44801bfa9d39
      bzrlib/tests/blackbox/test_status.py teststatus.py-20050712014354-508855eb9f29f7dc
      bzrlib/tests/test_revisionspec.py testrevisionnamespaces.py-20050711050225-8b4af89e6b1efe84
    ------------------------------------------------------------
    revno: 3655.3.1
    revision-id: lalinsky at gmail.com-20080828134115-265uyumclq5qvetg
    parent: pqm at pqm.ubuntu.com-20080828092217-98wmtek2p8cie8sc
    committer: Lukáš Lalinský <lalinsky at gmail.com>
    branch nick: revspec_as_tree
    timestamp: Thu 2008-08-28 15:41:15 +0200
    message:
      Fix `bzr st -rbranch:PATH_TO_BRANCH`
      
      * Add RevisionSpec.as_tree which returns a tree representation of the revision specifier. This might return a remote revision tree.
      * Make status use this new method and not require RevisionSpec.as_revision_id, which for RevisionSpec_branch fetches data to the local repository.
      * Refactor common code for getting either a revision tree or a tree/branch's basis tree into a private function _get_revision_tree and make it use RevisionSpec.as_tree.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/diff.py                 diff.py-20050309040759-26944fbbf2ebbf36
      bzrlib/revisionspec.py         revisionspec.py-20050907152633-17567659fd5c0ddb
      bzrlib/status.py               status.py-20050505062338-431bfa63ec9b19e6
      bzrlib/tests/blackbox/test_annotate.py testannotate.py-20051013044000-457f44801bfa9d39
      bzrlib/tests/blackbox/test_ls.py test_ls.py-20060712232047-0jraqpecwngee12y-1
      bzrlib/tests/blackbox/test_status.py teststatus.py-20050712014354-508855eb9f29f7dc
      bzrlib/tests/test_revisionspec.py testrevisionnamespaces.py-20050711050225-8b4af89e6b1efe84
=== modified file 'NEWS'
--- a/NEWS	2008-09-24 04:15:03 +0000
+++ b/NEWS	2008-09-24 06:52:03 +0000
@@ -65,6 +65,10 @@
       when doing ``bzr pull`` or ``bzr merge`` from a ``bzr+ssh`` URL.
       (Andrew Bennetts, #246233)
 
+    * Fixed ``bzr st -r branch:PATH_TO_BRANCH`` where the other branch
+      is in a different repository than the current one.
+      (Lukáš Lalinský, #144421)
+
     * Make the first line of the manpage preamble a comment again.
       (David Futcher, #242106)
 
@@ -99,6 +103,9 @@
       tree walking, and modular directory listing code to aid future
       performance optimisations and refactoring. (Robert Collins)
 
+    * New method ``RevisionSpec.as_tree`` for representing the revision
+      specifier as a revision tree object. (Lukáš Lalinský)
+
     * New win32utils.get_local_appdata_location() provides access to a local
       directory for storing data.  (Mark Hammond)
 

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2008-09-22 23:21:26 +0000
+++ b/bzrlib/builtins.py	2008-09-24 06:52:03 +0000
@@ -67,6 +67,23 @@
                                      (e.path, file_list[0]))
 
 
+def _get_one_revision_tree(command_name, revisions, branch=None, tree=None):
+    if branch is None:
+        branch = tree.branch
+    if revisions is None:
+        if tree is not None:
+            rev_tree = tree.basis_tree()
+        else:
+            rev_tree = branch.basis_tree()
+    else:
+        if len(revisions) != 1:
+            raise errors.BzrCommandError(
+                'bzr %s --revision takes exactly one revision identifier' % (
+                    command_name,))
+        rev_tree = revisions[0].as_tree(branch)
+    return rev_tree
+
+
 # XXX: Bad function name; should possibly also be a class method of
 # WorkingTree rather than a function.
 def internal_tree_files(file_list, default_branch=u'.'):
@@ -490,8 +507,7 @@
                     raise errors.BzrCommandError(
                         'bzr inventory --revision takes exactly one revision'
                         ' identifier')
-                revision_id = revision[0].as_revision_id(work_tree.branch)
-                tree = work_tree.branch.repository.revision_tree(revision_id)
+                tree = revision[0].as_tree(work_tree.branch)
 
                 extra_trees = [work_tree]
                 tree.lock_read()
@@ -1850,11 +1866,8 @@
             relpath = u''
         elif relpath:
             relpath += '/'
-        if revision is not None:
-            tree = branch.repository.revision_tree(
-                revision[0].as_revision_id(branch))
-        elif tree is None:
-            tree = branch.basis_tree()
+        if revision is not None or tree is None:
+            tree = _get_one_revision_tree('ls', revision, branch=branch)
 
         tree.lock_read()
         try:
@@ -2078,17 +2091,11 @@
             subdir = None
         else:
             b, subdir = Branch.open_containing(branch_or_subdir)
-            
-        if revision is None:
-            # should be tree.last_revision  FIXME
-            rev_id = b.last_revision()
-        else:
-            if len(revision) != 1:
-                raise errors.BzrCommandError('bzr export --revision takes exactly 1 argument')
-            rev_id = revision[0].as_revision_id(b)
-        t = b.repository.revision_tree(rev_id)
+            tree = None
+
+        rev_tree = _get_one_revision_tree('export', revision, branch=b, tree=tree)
         try:
-            export(t, dest, format, root, subdir)
+            export(rev_tree, dest, format, root, subdir)
         except errors.NoSuchExportFormat, e:
             raise errors.BzrCommandError('Unsupported export format: %s' % e.format)
 
@@ -2127,19 +2134,16 @@
     def _run(self, tree, b, relpath, filename, revision, name_from_revision):
         if tree is None:
             tree = b.basis_tree()
-        if revision is None:
-            revision_id = b.last_revision()
-        else:
-            revision_id = revision[0].as_revision_id(b)
+        rev_tree = _get_one_revision_tree('cat', revision, branch=b)
 
         cur_file_id = tree.path2id(relpath)
-        rev_tree = b.repository.revision_tree(revision_id)
         old_file_id = rev_tree.path2id(relpath)
-        
+
         if name_from_revision:
             if old_file_id is None:
-                raise errors.BzrCommandError("%r is not present in revision %s"
-                                                % (filename, revision_id))
+                raise errors.BzrCommandError(
+                    "%r is not present in revision %s" % (
+                        filename, rev_tree.get_revision_id()))
             else:
                 content = rev_tree.get_file_text(old_file_id)
         elif cur_file_id is not None:
@@ -2147,8 +2151,9 @@
         elif old_file_id is not None:
             content = rev_tree.get_file_text(old_file_id)
         else:
-            raise errors.BzrCommandError("%r is not present in revision %s" %
-                                         (filename, revision_id))
+            raise errors.BzrCommandError(
+                "%r is not present in revision %s" % (
+                    filename, rev_tree.get_revision_id()))
         self.outf.write(content)
 
 
@@ -3250,17 +3255,11 @@
 
     @staticmethod
     def _revert_tree_to_revision(tree, revision, file_list, no_backup):
-        if revision is None:
-            rev_id = tree.last_revision()
-        elif len(revision) != 1:
-            raise errors.BzrCommandError('bzr revert --revision takes exactly 1 argument')
-        else:
-            rev_id = revision[0].as_revision_id(tree.branch)
+        rev_tree = _get_one_revision_tree('revert', revision, tree=tree)
         pb = ui.ui_factory.nested_progress_bar()
         try:
-            tree.revert(file_list,
-                        tree.branch.repository.revision_tree(rev_id),
-                        not no_backup, pb, report_changes=True)
+            tree.revert(file_list, rev_tree, not no_backup, pb,
+                report_changes=True)
         finally:
             pb.finished()
 
@@ -3561,13 +3560,7 @@
         else:
             branch.lock_read()
         try:
-            if revision is None:
-                revision_id = branch.last_revision()
-            elif len(revision) != 1:
-                raise errors.BzrCommandError('bzr annotate --revision takes exactly 1 argument')
-            else:
-                revision_id = revision[0].as_revision_id(branch)
-            tree = branch.repository.revision_tree(revision_id)
+            tree = _get_one_revision_tree('annotate', revision, branch=branch)
             if wt is not None:
                 file_id = wt.path2id(relpath)
             else:

=== modified file 'bzrlib/diff.py'
--- a/bzrlib/diff.py	2008-08-26 08:25:27 +0000
+++ b/bzrlib/diff.py	2008-09-24 06:52:03 +0000
@@ -370,10 +370,7 @@
                 return branch.basis_tree()
         else:
             return tree
-    if not spec.needs_branch():
-        branch = _mod_branch.Branch.open(spec.get_branch())
-    revision_id = spec.as_revision_id(branch)
-    return branch.repository.revision_tree(revision_id)
+    return spec.as_tree(branch)
 
 
 def _relative_paths_in_tree(tree, paths):

=== modified file 'bzrlib/revisionspec.py'
--- a/bzrlib/revisionspec.py	2008-09-04 19:07:58 +0000
+++ b/bzrlib/revisionspec.py	2008-09-24 06:52:03 +0000
@@ -252,6 +252,25 @@
         """
         return self.in_history(context_branch).rev_id
 
+    def as_tree(self, context_branch):
+        """Return the tree object for this revisions spec.
+
+        Some revision specs require a context_branch to be able to determine
+        the revision id and access the repository. Not all specs will make
+        use of it.
+        """
+        return self._as_tree(context_branch)
+
+    def _as_tree(self, context_branch):
+        """Implementation of as_tree().
+
+        Classes should override this function to provide appropriate
+        functionality. The default is to just call '.as_revision_id()'
+        and get the revision tree from context_branch's repository.
+        """
+        revision_id = self.as_revision_id(context_branch)
+        return context_branch.repository.revision_tree(revision_id)
+
     def __repr__(self):
         # this is mostly for helping with testing
         return '<%s %s>' % (self.__class__.__name__,
@@ -779,6 +798,15 @@
             raise errors.NoCommits(other_branch)
         return last_revision
 
+    def _as_tree(self, context_branch):
+        from bzrlib.branch import Branch
+        other_branch = Branch.open(self.spec)
+        last_revision = other_branch.last_revision()
+        last_revision = revision.ensure_null(last_revision)
+        if last_revision == revision.NULL_REVISION:
+            raise errors.NoCommits(other_branch)
+        return other_branch.repository.revision_tree(last_revision)
+
 SPEC_TYPES.append(RevisionSpec_branch)
 
 

=== modified file 'bzrlib/status.py'
--- a/bzrlib/status.py	2008-08-16 22:28:01 +0000
+++ b/bzrlib/status.py	2008-08-28 13:41:15 +0000
@@ -87,14 +87,12 @@
             old = new.basis_tree()
         elif len(revision) > 0:
             try:
-                rev_id = revision[0].as_revision_id(wt.branch)
-                old = wt.branch.repository.revision_tree(rev_id)
+                old = revision[0].as_tree(wt.branch)
             except errors.NoSuchRevision, e:
                 raise errors.BzrCommandError(str(e))
             if (len(revision) > 1) and (revision[1].spec is not None):
                 try:
-                    rev_id = revision[1].as_revision_id(wt.branch)
-                    new = wt.branch.repository.revision_tree(rev_id)
+                    new = revision[1].as_tree(wt.branch)
                     new_is_working_tree = False
                 except errors.NoSuchRevision, e:
                     raise errors.BzrCommandError(str(e))

=== modified file 'bzrlib/tests/blackbox/test_annotate.py'
--- a/bzrlib/tests/blackbox/test_annotate.py	2008-09-23 01:23:06 +0000
+++ b/bzrlib/tests/blackbox/test_annotate.py	2008-09-24 06:52:03 +0000
@@ -146,7 +146,7 @@
                                 retcode=3)
         self.assertEqual('', out)
         self.assertEqual('bzr: ERROR: bzr annotate --revision takes'
-                         ' exactly 1 argument\n',
+                         ' exactly one revision identifier\n',
                          err)
 
 

=== modified file 'bzrlib/tests/blackbox/test_status.py'
--- a/bzrlib/tests/blackbox/test_status.py	2008-08-28 11:01:33 +0000
+++ b/bzrlib/tests/blackbox/test_status.py	2008-09-24 06:52:03 +0000
@@ -298,6 +298,21 @@
         self.assertEqual("working tree is out of date, run 'bzr update'\n",
                          err)
 
+    def test_status_write_lock(self):
+        """Test that status works without fetching history and
+        having a write lock.
+
+        See https://bugs.launchpad.net/bzr/+bug/149270
+        """
+        mkdir('branch1')
+        wt = self.make_branch_and_tree('branch1')
+        b = wt.branch
+        wt.commit('Empty commit 1')
+        wt2 = b.bzrdir.sprout('branch2').open_workingtree()
+        wt2.commit('Empty commit 2')
+        out, err = self.run_bzr('status branch1 -rbranch:branch2')
+        self.assertEqual('', out)
+
 
 class CheckoutStatus(BranchStatus):
 

=== modified file 'bzrlib/tests/test_revisionspec.py'
--- a/bzrlib/tests/test_revisionspec.py	2008-06-16 16:13:26 +0000
+++ b/bzrlib/tests/test_revisionspec.py	2008-08-28 13:41:15 +0000
@@ -23,6 +23,7 @@
     bzrdir,
     errors,
     repository,
+    revision as _mod_revision,
     )
 from bzrlib.tests import TestCase, TestCaseWithTransport
 from bzrlib.revisionspec import (
@@ -100,6 +101,12 @@
         self.assertEqual(revision_id,
                          spec.as_revision_id(self.tree.branch))
 
+    def get_as_tree(self, revision_spec, tree=None):
+        if tree is None:
+            tree = self.tree
+        spec = RevisionSpec.from_string(revision_spec)
+        return spec.as_tree(tree.branch)
+
 
 class RevisionSpecMatchOnTrap(RevisionSpec):
 
@@ -300,6 +307,20 @@
         self.assertAsRevisionId('r2', '-1')
         self.assertAsRevisionId('alt_r2', '1.1.1')
 
+    def test_as_tree(self):
+        tree = self.get_as_tree('0')
+        self.assertEquals(_mod_revision.NULL_REVISION, tree.get_revision_id())
+        tree = self.get_as_tree('1')
+        self.assertEquals('r1', tree.get_revision_id())
+        tree = self.get_as_tree('2')
+        self.assertEquals('r2', tree.get_revision_id())
+        tree = self.get_as_tree('-2')
+        self.assertEquals('r1', tree.get_revision_id())
+        tree = self.get_as_tree('-1')
+        self.assertEquals('r2', tree.get_revision_id())
+        tree = self.get_as_tree('1.1.1')
+        self.assertEquals('alt_r2', tree.get_revision_id())
+
 
 class TestRevisionSpec_revid(TestRevisionSpec):
     
@@ -564,10 +585,17 @@
         new_tree = self.make_branch_and_tree('new_tree')
         self.assertRaises(errors.NoCommits,
                           self.get_in_history, 'branch:new_tree')
+        self.assertRaises(errors.NoCommits,
+                          self.get_as_tree, 'branch:new_tree')
 
     def test_as_revision_id(self):
         self.assertAsRevisionId('alt_r2', 'branch:tree2')
 
+    def test_as_tree(self):
+        tree = self.get_as_tree('branch:tree', self.tree2)
+        self.assertEquals('r2', tree.get_revision_id())
+        self.assertFalse(self.tree2.branch.repository.has_revision('r2'))
+
 
 class TestRevisionSpec_submit(TestRevisionSpec):
 




More information about the bazaar-commits mailing list