Rev 4135: (vila) cat use old file id if current one is not found is requested in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Mar 12 13:43:20 GMT 2009


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

------------------------------------------------------------
revno: 4135
revision-id: pqm at pqm.ubuntu.com-20090312134315-vcpiopkmky1ch5s0
parent: pqm at pqm.ubuntu.com-20090312130316-vmqowmbcu2tzynem
parent: v.ladeuil+lp at free.fr-20090312100453-6txhip85enlh3fwo
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2009-03-12 13:43:15 +0000
message:
  (vila) cat use old file id if current one is not found is requested
  	revision
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
  bzrlib/tests/blackbox/test_cat.py test_cat.py-20051201162916-f0937e4e19ea24b3
    ------------------------------------------------------------
    revno: 4132.1.1
    revision-id: v.ladeuil+lp at free.fr-20090312100453-6txhip85enlh3fwo
    parent: pqm at pqm.ubuntu.com-20090312112116-550sw6tk8syaaxku
    parent: v.ladeuil+lp at free.fr-20090312085929-lq1xbyzbe1qgojct
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: trunk
    timestamp: Thu 2009-03-12 20:04:53 +1000
    message:
      cat use old file id if current one is not found is requested revision
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
      bzrlib/tests/blackbox/test_cat.py test_cat.py-20051201162916-f0937e4e19ea24b3
    ------------------------------------------------------------
    revno: 4112.1.3
    revision-id: v.ladeuil+lp at free.fr-20090312085929-lq1xbyzbe1qgojct
    parent: v.ladeuil+lp at free.fr-20090312041553-d50jirkqhq0vmr72
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 4117-cat-wrong-file-id
    timestamp: Thu 2009-03-12 18:59:29 +1000
    message:
      As James mentioned, the bug is also #253806.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 4112.1.2
    revision-id: v.ladeuil+lp at free.fr-20090312041553-d50jirkqhq0vmr72
    parent: v.ladeuil+lp at free.fr-20090312040048-x8w6pv3h7xfcn7mx
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 4117-cat-wrong-file-id
    timestamp: Thu 2009-03-12 14:15:53 +1000
    message:
      Mention bug number in NEWS.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 4112.1.1
    revision-id: v.ladeuil+lp at free.fr-20090312040048-x8w6pv3h7xfcn7mx
    parent: pqm at pqm.ubuntu.com-20090311072239-dm56af7pf1j4i1nq
    committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
    branch nick: 4117-cat-wrong-file-id
    timestamp: Thu 2009-03-12 14:00:48 +1000
    message:
      Fallback to old revision id if the current one doesn't exist in
      the requested revision inventory.
      
      * bzrlib/tests/blackbox/test_cat.py:
      (TestCat.test_cat_different_id): Complete test.
      
      * bzrlib/inventory.py:
      (Inventory.__repr__): Limit debug output to 2048 characters or big
      inventories produce too much noise.
      
      * bzrlib/builtins.py:
      (cmd_cat._run): The file id in the basis tree may not exist in the
      requested revision. Catch the exception and try with the file id
      in the revision tree.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/inventory.py            inventory.py-20050309040759-6648b84ca2005b37
      bzrlib/tests/blackbox/test_cat.py test_cat.py-20051201162916-f0937e4e19ea24b3
=== modified file 'NEWS'
--- a/NEWS	2009-03-12 13:03:16 +0000
+++ b/NEWS	2009-03-12 13:43:15 +0000
@@ -153,6 +153,10 @@
       unable to read a file in the working directory, for example because
       of a permission error.  (Martin Pool, #338653)
 
+    * ``bzr cat -r<old> <path>`` doesn't traceback anymore when <path> has a
+      file id in the working tree different from the one in revision <old>.
+      (Vincent Ladeuil, #341517, #253806)
+
     * ``bzr send`` help is more specific about how to apply merge
       directives.  (Neil Martinsen-Burrell, #253470)
 

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2009-03-12 13:03:16 +0000
+++ b/bzrlib/builtins.py	2009-03-12 13:43:15 +0000
@@ -2584,24 +2584,36 @@
             tree = b.basis_tree()
         rev_tree = _get_one_revision_tree('cat', revision, branch=b)
 
-        cur_file_id = tree.path2id(relpath)
         old_file_id = rev_tree.path2id(relpath)
 
         if name_from_revision:
+            # Try in revision if requested
             if old_file_id is None:
                 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:
-            content = rev_tree.get_file_text(cur_file_id)
-        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, rev_tree.get_revision_id()))
+            cur_file_id = tree.path2id(relpath)
+            found = False
+            if cur_file_id is not None:
+                # Then try with the actual file id
+                try:
+                    content = rev_tree.get_file_text(cur_file_id)
+                    found = True
+                except errors.NoSuchId:
+                    # The actual file id didn't exist at that time
+                    pass
+            if not found and old_file_id is not None:
+                # Finally try with the old file id
+                content = rev_tree.get_file_text(old_file_id)
+                found = True
+            if not found:
+                # Can't be found anywhere
+                raise errors.BzrCommandError(
+                    "%r is not present in revision %s" % (
+                        filename, rev_tree.get_revision_id()))
         self.outf.write(content)
 
 

=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py	2009-03-12 08:01:41 +0000
+++ b/bzrlib/inventory.py	2009-03-12 10:04:53 +0000
@@ -771,7 +771,13 @@
         self.revision_id = revision_id
 
     def __repr__(self):
-        return "<Inventory object at %x, contents=%r>" % (id(self), self._byid)
+        # More than one page of ouput is not useful anymore to debug
+        max_len = 2048
+        closing = '...}'
+        contents = repr(self._byid)
+        if len(contents) > max_len:
+            contents = contents[:(max_len-len(closing))] + closing
+        return "<Inventory object at %x, contents=%r>" % (id(self), contents)
 
     def apply_delta(self, delta):
         """Apply a delta to this inventory.

=== modified file 'bzrlib/tests/blackbox/test_cat.py'
--- a/bzrlib/tests/blackbox/test_cat.py	2009-01-17 01:30:58 +0000
+++ b/bzrlib/tests/blackbox/test_cat.py	2009-03-12 04:00:48 +0000
@@ -74,17 +74,20 @@
         # a-rev-tree is special because it appears in both the revision
         # tree and the working tree
         self.build_tree_contents([('a-rev-tree', 'foo\n'),
-            ('c-rev', 'baz\n'), ('d-rev', 'bar\n')])
+            ('c-rev', 'baz\n'), ('d-rev', 'bar\n'), ('e-rev', 'qux\n')])
         tree.lock_write()
         try:
-            tree.add(['a-rev-tree', 'c-rev', 'd-rev'])
-            tree.commit('add test files')
+            tree.add(['a-rev-tree', 'c-rev', 'd-rev', 'e-rev'])
+            tree.commit('add test files', rev_id='first')
             # remove currently uses self._write_inventory -
             # work around that for now.
             tree.flush()
             tree.remove(['d-rev'])
             tree.rename_one('a-rev-tree', 'b-tree')
             tree.rename_one('c-rev', 'a-rev-tree')
+            tree.rename_one('e-rev', 'old-rev')
+            self.build_tree_contents([('e-rev', 'new\n')])
+            tree.add(['e-rev'])
         finally:
             # calling bzr as another process require free lock on win32
             tree.unlock()
@@ -108,6 +111,11 @@
         self.assertEqual('baz\n', out)
         self.assertEqual('', err)
 
+        # the actual file-id for e-rev doesn't exist in the old tree
+        out, err = self.run_bzr_subprocess('cat e-rev -rrevid:first')
+        self.assertEqual('qux\n', out)
+        self.assertEqual('', err)
+
     def test_remote_cat(self):
         wt = self.make_branch_and_tree('.')
         self.build_tree(['README'])




More information about the bazaar-commits mailing list