Patchwork [2,of,8,sparse,V2] sparse: clean up updateconfig()

login
register
mail settings
Submitter Gregory Szorc
Date July 11, 2017, 4:57 a.m.
Message ID <571f059fcdcb99823617.1499749021@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/22214/
State Accepted
Headers show

Comments

Gregory Szorc - July 11, 2017, 4:57 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1499748199 25200
#      Mon Jul 10 21:43:19 2017 -0700
# Node ID 571f059fcdcb998236173166e75e05017342db15
# Parent  dfbbb15fb7c3790c983fa12fbb75ec93a84509bb
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

Patch

diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -592,18 +592,12 @@  def updateconfig(repo, pats, opts, inclu
 
     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 @@  def updateconfig(repo, pats, opts, inclu
 
             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 @@  def updateconfig(repo, pats, opts, inclu
         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):