Patchwork [2,of,2] strip.stripcmd: remove redundant wlock acquire/release

login
register
mail settings
Submitter Siddharth Agarwal
Date Nov. 18, 2013, 5:23 p.m.
Message ID <bf7df0d08d6e4026be62.1384795403@dev1091.prn1.facebook.com>
Download mbox | patch
Permalink /patch/3060/
State Accepted
Commit 04eaa8eec6a07912891763e80b463cc2cac493fb
Headers show

Comments

Siddharth Agarwal - Nov. 18, 2013, 5:23 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1384794545 28800
#      Mon Nov 18 09:09:05 2013 -0800
# Node ID bf7df0d08d6e4026be624663c9b7f4c5e01acfed
# Parent  ff06af69dbaf102c340ffb459907a8fd73b509f5
strip.stripcmd: remove redundant wlock acquire/release

Now that we acquire and release a wlock in the outer scope, this is redundant.
Matt Mackall - Nov. 25, 2013, 6:19 p.m.
On Mon, 2013-11-18 at 09:23 -0800, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1384794545 28800
> #      Mon Nov 18 09:09:05 2013 -0800
> # Node ID bf7df0d08d6e4026be624663c9b7f4c5e01acfed
> # Parent  ff06af69dbaf102c340ffb459907a8fd73b509f5
> strip.stripcmd: remove redundant wlock acquire/release
> 
> Now that we acquire and release a wlock in the outer scope, this is redundant.

This one is a cleanup, so I've put on default (after merging 1 of 2 from
stable).

Patch

diff --git a/hgext/strip.py b/hgext/strip.py
--- a/hgext/strip.py
+++ b/hgext/strip.py
@@ -182,33 +182,28 @@ 
 
         revs = sorted(rootnodes)
         if update and opts.get('keep'):
-            wlock = repo.wlock()
-            try:
-                urev, p2 = repo.changelog.parents(revs[0])
-                if (util.safehasattr(repo, 'mq') and p2 != nullid
-                    and p2 in [x.node for x in repo.mq.applied]):
-                    urev = p2
-                uctx = repo[urev]
+            urev, p2 = repo.changelog.parents(revs[0])
+            if (util.safehasattr(repo, 'mq') and p2 != nullid
+                and p2 in [x.node for x in repo.mq.applied]):
+                urev = p2
+            uctx = repo[urev]
 
-                # only reset the dirstate for files that would actually change
-                # between the working context and uctx
-                descendantrevs = repo.revs("%s::." % uctx.rev())
-                changedfiles = []
-                for rev in descendantrevs:
-                    # blindly reset the files, regardless of what actually
-                    # changed
-                    changedfiles.extend(repo[rev].files())
+            # only reset the dirstate for files that would actually change
+            # between the working context and uctx
+            descendantrevs = repo.revs("%s::." % uctx.rev())
+            changedfiles = []
+            for rev in descendantrevs:
+                # blindly reset the files, regardless of what actually changed
+                changedfiles.extend(repo[rev].files())
 
-                # reset files that only changed in the dirstate too
-                dirstate = repo.dirstate
-                dirchanges = [f for f in dirstate if dirstate[f] != 'n']
-                changedfiles.extend(dirchanges)
+            # reset files that only changed in the dirstate too
+            dirstate = repo.dirstate
+            dirchanges = [f for f in dirstate if dirstate[f] != 'n']
+            changedfiles.extend(dirchanges)
 
-                repo.dirstate.rebuild(urev, uctx.manifest(), changedfiles)
-                repo.dirstate.write()
-                update = False
-            finally:
-                wlock.release()
+            repo.dirstate.rebuild(urev, uctx.manifest(), changedfiles)
+            repo.dirstate.write()
+            update = False
 
         if opts.get('bookmark'):
             if mark == repo._bookmarkcurrent: