diff -r 4dc04cdf2520 -r df6dd6d536bb 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):