Rev 4420: A bit more cleanup, using the same WT.open_containing else: B.open() paradigm. in http://bazaar.launchpad.net/~jameinel/bzr/tree_opt

John Arbash Meinel john at arbash-meinel.com
Fri Jun 5 14:40:28 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/tree_opt

------------------------------------------------------------
revno: 4420
revision-id: john at arbash-meinel.com-20090605134006-hewsalkr9d452xyq
parent: john at arbash-meinel.com-20090605133754-ngayy8f8eyop1nn7
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: tree_opt
timestamp: Fri 2009-06-05 08:40:06 -0500
message:
  A bit more cleanup, using the same WT.open_containing else: B.open() paradigm.
-------------- next part --------------
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2009-06-05 13:37:54 +0000
+++ b/bzrlib/builtins.py	2009-06-05 13:40:06 +0000
@@ -480,17 +480,29 @@
 
     @display_command
     def run(self, tree=False, location=u'.'):
-        if tree:
+        try:
             wt = WorkingTree.open_containing(location)[0]
-            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)
-        else:
-            branch = Branch.open_containing(location)[0]
-            revno = branch.revno()
+            b = wt.branch
+            wt.lock_read()
+        except (errors.NoWorkingTree, errors.NotLocalUrl):
+            wt = None
+            b = Branch.open(location)[0]
+            b.lock_read()
+        try:
+            if tree:
+                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)
+            else:
+                revno = b.revno()
+        finally:
+            if wt is None:
+                b.unlock()
+            else:
+                wt.unlock()
         self.outf.write(str(revno) + '\n')
 
 
@@ -543,7 +555,7 @@
                     revno = '.'.join(str(i) for i in dotted_revno)
                 except errors.NoSuchRevision:
                     revno = '???'
-                print '%4s %s' % (revno, revision_id)
+                self.outf.write('%4s %s\n' % (revno, revision_id))
         finally:
             if wt is None:
                 b.unlock()



More information about the bazaar-commits mailing list