sparse: clean up updateconfig()
authorGregory Szorc <gregory.szorc@gmail.com>
Mon, 10 Jul 2017 21:43:19 -0700
changeset 33375 df6dd6d536bb
parent 33374 4dc04cdf2520
child 33376 d5a38eae67e5
sparse: clean up updateconfig() * Use context manager for wlock * Rename oldsparsematch to oldmatcher * Always call parseconfig() because parsing an empty string yields the same result as the old code
mercurial/sparse.py
--- a/mercurial/sparse.py	Mon Jul 10 21:39:49 2017 -0700
+++ b/mercurial/sparse.py	Mon Jul 10 21:43:19 2017 -0700
@@ -592,18 +592,12 @@
 
     The new config is written out and a working directory refresh is performed.
     """
-    wlock = repo.wlock()
-    try:
-        oldsparsematch = matcher(repo)
+    with repo.wlock():
+        oldmatcher = matcher(repo)
 
         raw = repo.vfs.tryread('sparse')
-        if raw:
-            oldinclude, oldexclude, oldprofiles = map(
-                set, parseconfig(repo.ui, raw))
-        else:
-            oldinclude = set()
-            oldexclude = set()
-            oldprofiles = set()
+        oldinclude, oldexclude, oldprofiles = parseconfig(repo.ui, raw)
+        oldprofiles = set(oldprofiles)
 
         try:
             if reset:
@@ -637,7 +631,7 @@
 
             fcounts = map(
                 len,
-                refreshwdir(repo, oldstatus, oldsparsematch, force=force))
+                refreshwdir(repo, oldstatus, oldmatcher, force=force))
 
             profilecount = (len(newprofiles - oldprofiles) -
                             len(oldprofiles - newprofiles))
@@ -650,8 +644,6 @@
         except Exception:
             writeconfig(repo, oldinclude, oldexclude, oldprofiles)
             raise
-    finally:
-        wlock.release()
 
 def printchanges(ui, opts, profilecount=0, includecount=0, excludecount=0,
                  added=0, dropped=0, conflicting=0):