Rev 3157: Don't require a working tree in cmd_annotate. (Lukas Lalinsky, #90049) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Jan 3 09:38:47 GMT 2008


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

------------------------------------------------------------
revno: 3157
revision-id:pqm at pqm.ubuntu.com-20080103093833-5bwfhwbkrke2b0cb
parent: pqm at pqm.ubuntu.com-20080103073604-bdu4u15nqv5hlqb4
parent: ian.clatworthy at internode.on.net-20080103083727-c10xa4jrvbl6jblb
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2008-01-03 09:38:33 +0000
message:
  Don't require a working tree in cmd_annotate. (Lukas Lalinsky, #90049)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/blackbox/test_annotate.py testannotate.py-20051013044000-457f44801bfa9d39
    ------------------------------------------------------------
    revno: 3156.1.1
    revision-id:ian.clatworthy at internode.on.net-20080103083727-c10xa4jrvbl6jblb
    parent: pqm at pqm.ubuntu.com-20080103073604-bdu4u15nqv5hlqb4
    parent: lalinsky at gmail.com-20071229185520-42dr3votzal51sl8
    committer: Ian Clatworthy <ian.clatworthy at internode.on.net>
    branch nick: ianc-integration
    timestamp: Thu 2008-01-03 18:37:27 +1000
    message:
      Don't require a working tree in cmd_annotate. (Lukas Lalinsky, #90049)
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/tests/blackbox/test_annotate.py testannotate.py-20051013044000-457f44801bfa9d39
    ------------------------------------------------------------
    revno: 3146.2.1
    revision-id:lalinsky at gmail.com-20071229185520-42dr3votzal51sl8
    parent: pqm at pqm.ubuntu.com-20071228175832-9kboqtkemnuzzlab
    committer: Lukáš Lalinský <lalinsky at gmail.com>
    branch nick: annotate-wt
    timestamp: Sat 2007-12-29 19:55:20 +0100
    message:
      Don't require a working tree in cmd_annotate.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/tests/blackbox/test_annotate.py testannotate.py-20051013044000-457f44801bfa9d39
=== modified file 'NEWS'
--- a/NEWS	2008-01-03 07:36:04 +0000
+++ b/NEWS	2008-01-03 08:37:27 +0000
@@ -27,6 +27,9 @@
 
   IMPROVEMENTS:
 
+   * ``annotate`` now doesn't require a working tree. (Lukáš Lalinský,
+     #90049)
+
    * ``branch`` and ``checkout`` can now use files from a working tree to
      to speed up the process.  For checkout, this requires the new
      --files-from flag.  (Aaron Bentley)

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2007-12-28 17:58:32 +0000
+++ b/bzrlib/builtins.py	2007-12-29 18:55:20 +0000
@@ -3408,9 +3408,12 @@
     def run(self, filename, all=False, long=False, revision=None,
             show_ids=False):
         from bzrlib.annotate import annotate_file
-        tree, relpath = WorkingTree.open_containing(filename)
-        branch = tree.branch
-        branch.lock_read()
+        wt, branch, relpath = \
+            bzrdir.BzrDir.open_containing_tree_or_branch(filename)
+        if wt is not None:
+            wt.lock_read()
+        else:
+            branch.lock_read()
         try:
             if revision is None:
                 revision_id = branch.last_revision()
@@ -3418,15 +3421,21 @@
                 raise errors.BzrCommandError('bzr annotate --revision takes exactly 1 argument')
             else:
                 revision_id = revision[0].in_history(branch).rev_id
-            file_id = tree.path2id(relpath)
+            tree = branch.repository.revision_tree(revision_id)
+            if wt is not None:
+                file_id = wt.path2id(relpath)
+            else:
+                file_id = tree.path2id(relpath)
             if file_id is None:
                 raise errors.NotVersionedError(filename)
-            tree = branch.repository.revision_tree(revision_id)
             file_version = tree.inventory[file_id].revision
             annotate_file(branch, file_version, file_id, long, all, self.outf,
                           show_ids=show_ids)
         finally:
-            branch.unlock()
+            if wt is not None:
+                wt.unlock()
+            else:
+                branch.unlock()
 
 
 class cmd_re_sign(Command):

=== modified file 'bzrlib/tests/blackbox/test_annotate.py'
--- a/bzrlib/tests/blackbox/test_annotate.py	2007-08-23 14:10:48 +0000
+++ b/bzrlib/tests/blackbox/test_annotate.py	2007-12-29 18:55:20 +0000
@@ -167,3 +167,16 @@
         out, err = self.run_bzr("annotate doesnotexist", retcode=3)
         self.assertEqual('', out)
         self.assertEqual("bzr: ERROR: doesnotexist is not versioned.\n", err)
+
+    def test_annotate_without_workingtree(self):
+        tree = self.make_branch_and_tree('branch')
+        self.build_tree_contents([('branch/empty', '')])
+        tree.add('empty')
+        tree.commit('add empty file')
+        bzrdir = tree.branch.bzrdir
+        bzrdir.destroy_workingtree()
+        self.assertFalse(bzrdir.has_workingtree())
+
+        os.chdir('branch')
+        out, err = self.run_bzr('annotate empty')
+        self.assertEqual('', out)




More information about the bazaar-commits mailing list