localrepository.status: only acquire wlock if actually needed.
authorBryan O'Sullivan <bos@serpentine.com>
Tue, 24 Apr 2007 11:05:39 -0700
changeset 4372 4ddc6d374265
parent 4371 d7ad1e42a368
child 4373 abeb3edb2b4e
localrepository.status: only acquire wlock if actually needed. This speeds up the common case of not needing to update the dirstate, and avoids the need to reload and parse the dirstate "just in case".
mercurial/localrepo.py
--- a/mercurial/localrepo.py	Tue Apr 24 10:53:25 2007 -0700
+++ b/mercurial/localrepo.py	Tue Apr 24 11:05:39 2007 -0700
@@ -919,13 +919,10 @@
             # all the revisions in parent->child order.
             mf1 = mfmatches(node1)
 
+        mywlock = False
+
         # are we comparing the working directory?
         if not node2:
-            if not wlock:
-                try:
-                    wlock = self.wlock(wait=0)
-                except lock.LockException:
-                    wlock = None
             (lookup, modified, added, removed, deleted, unknown,
              ignored, clean) = self.dirstate.status(files, match,
                                                     list_ignored, list_clean)
@@ -942,7 +939,13 @@
                             modified.append(f)
                         else:
                             clean.append(f)
-                            if wlock is not None:
+                            if not wlock and not mywlock:
+                                mywlock = True
+                                try:
+                                    wlock = self.wlock(wait=0)
+                                except lock.LockException:
+                                    pass
+                            if wlock:
                                 self.dirstate.update([f], "n")
             else:
                 # we are comparing working dir against non-parent
@@ -957,6 +960,9 @@
                 for f in removed:
                     if f in mf2:
                         del mf2[f]
+
+            if mywlock and wlock:
+                wlock.release()
         else:
             # we are comparing two revisions
             mf2 = mfmatches(node2)