Patchwork [3,of,8,sparse,V2] sparse: shorten try..except block in updateconfig()

login
register
mail settings
Submitter Gregory Szorc
Date July 11, 2017, 4:57 a.m.
Message ID <ec1d258a7940fd3104d7.1499749022@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/22215/
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 1499748943 25200
#      Mon Jul 10 21:55:43 2017 -0700
# Node ID ec1d258a7940fd3104d7cf001150d69e6c4da0ce
# Parent  571f059fcdcb998236173166e75e05017342db15
sparse: shorten try..except block in updateconfig()

It now only covers refreshwdir(). This is what importfromfiles()
does. I think it is the more appropriate behavior.

Patch

diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -599,46 +599,48 @@  def updateconfig(repo, pats, opts, inclu
         oldinclude, oldexclude, oldprofiles = parseconfig(repo.ui, raw)
         oldprofiles = set(oldprofiles)
 
-        try:
-            if reset:
-                newinclude = set()
-                newexclude = set()
-                newprofiles = set()
-            else:
-                newinclude = set(oldinclude)
-                newexclude = set(oldexclude)
-                newprofiles = set(oldprofiles)
+        if reset:
+            newinclude = set()
+            newexclude = set()
+            newprofiles = set()
+        else:
+            newinclude = set(oldinclude)
+            newexclude = set(oldexclude)
+            newprofiles = set(oldprofiles)
 
-            oldstatus = repo.status()
+        oldstatus = repo.status()
 
-            if any(pat.startswith('/') for pat in pats):
-                repo.ui.warn(_('warning: paths cannot start with /, '
-                               'ignoring: %s\n') %
-                             ([pat for pat in pats if pat.startswith('/')]))
-            elif include:
-                newinclude.update(pats)
-            elif exclude:
-                newexclude.update(pats)
-            elif enableprofile:
-                newprofiles.update(pats)
-            elif disableprofile:
-                newprofiles.difference_update(pats)
-            elif delete:
-                newinclude.difference_update(pats)
-                newexclude.difference_update(pats)
+        if any(pat.startswith('/') for pat in pats):
+            repo.ui.warn(_('warning: paths cannot start with /, ignoring: %s\n')
+                         % ([pat for pat in pats if pat.startswith('/')]))
+        elif include:
+            newinclude.update(pats)
+        elif exclude:
+            newexclude.update(pats)
+        elif enableprofile:
+            newprofiles.update(pats)
+        elif disableprofile:
+            newprofiles.difference_update(pats)
+        elif delete:
+            newinclude.difference_update(pats)
+            newexclude.difference_update(pats)
 
-            writeconfig(repo, newinclude, newexclude, newprofiles)
+        profilecount = (len(newprofiles - oldprofiles) -
+                        len(oldprofiles - newprofiles))
+        includecount = (len(newinclude - oldinclude) -
+                        len(oldinclude - newinclude))
+        excludecount = (len(newexclude - oldexclude) -
+                        len(oldexclude - newexclude))
 
+        # TODO clean up this writeconfig() + try..except pattern once we can.
+        # See comment in importfromfiles() explaining it.
+        writeconfig(repo, newinclude, newexclude, newprofiles)
+
+        try:
             fcounts = map(
                 len,
                 refreshwdir(repo, oldstatus, oldmatcher, force=force))
 
-            profilecount = (len(newprofiles - oldprofiles) -
-                            len(oldprofiles - newprofiles))
-            includecount = (len(newinclude - oldinclude) -
-                            len(oldinclude - newinclude))
-            excludecount = (len(newexclude - oldexclude) -
-                            len(oldexclude - newexclude))
             printchanges(repo.ui, opts, profilecount, includecount,
                          excludecount, *fcounts)
         except Exception: