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
--- 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):