Patchwork [1,of,8,sparse,V2] sparse: move config updating function into core

login
register
mail settings
Submitter Gregory Szorc
Date July 11, 2017, 4:57 a.m.
Message ID <dfbbb15fb7c3790c983f.1499749020@ubuntu-vm-main>
Download mbox | patch
Permalink /patch/22213/
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 1499747989 25200
#      Mon Jul 10 21:39:49 2017 -0700
# Node ID dfbbb15fb7c3790c983fa12fbb75ec93a84509bb
# Parent  c6415195fa780a808ef655729fff008c6165a028
sparse: move config updating function into core

As part of the move, the ui argument was dropped.

Additional fixups will be made in a follow-up commit.

Patch

diff --git a/hgext/sparse.py b/hgext/sparse.py
--- a/hgext/sparse.py
+++ b/hgext/sparse.py
@@ -163,8 +163,8 @@  def _clonesparsecmd(orig, ui, repo, *arg
         raise error.Abort(_("too many flags specified."))
     if include or exclude or enableprofile:
         def clonesparse(orig, self, node, overwrite, *args, **kwargs):
-            _config(self.ui, self.unfiltered(), pat, {}, include=include,
-                    exclude=exclude, enableprofile=enableprofile)
+            sparse.updateconfig(self.unfiltered(), pat, {}, include=include,
+                                exclude=exclude, enableprofile=enableprofile)
             return orig(self, node, overwrite, *args, **kwargs)
         extensions.wrapfunction(hg, 'updaterepo', clonesparse)
     return orig(ui, repo, *args, **opts)
@@ -190,7 +190,7 @@  def _setupadd(ui):
             for pat in pats:
                 dirname, basename = util.split(pat)
                 dirs.add(dirname)
-            _config(ui, repo, list(dirs), opts, include=True)
+            sparse.updateconfig(repo, list(dirs), opts, include=True)
         return orig(ui, repo, *pats, **opts)
 
     extensions.wrapcommand(commands.table, 'add', _add)
@@ -356,9 +356,10 @@  def debugsparse(ui, repo, *pats, **opts)
         return
 
     if include or exclude or delete or reset or enableprofile or disableprofile:
-        _config(ui, repo, pats, opts, include=include, exclude=exclude,
-                reset=reset, delete=delete, enableprofile=enableprofile,
-                disableprofile=disableprofile, force=force)
+        sparse.updateconfig(repo, pats, opts, include=include, exclude=exclude,
+                            reset=reset, delete=delete,
+                            enableprofile=enableprofile,
+                            disableprofile=disableprofile, force=force)
 
     if importrules:
         sparse.importfromfiles(repo, opts, pats, force=force)
@@ -377,70 +378,3 @@  def debugsparse(ui, repo, *pats, **opts)
                                 conflicting=fcounts[2])
         finally:
             wlock.release()
-
-def _config(ui, repo, pats, opts, include=False, exclude=False, reset=False,
-            delete=False, enableprofile=False, disableprofile=False,
-            force=False):
-    """
-    Perform a sparse config update. Only one of the kwargs may be specified.
-    """
-    wlock = repo.wlock()
-    try:
-        oldsparsematch = sparse.matcher(repo)
-
-        raw = repo.vfs.tryread('sparse')
-        if raw:
-            oldinclude, oldexclude, oldprofiles = map(
-                set, sparse.parseconfig(ui, raw))
-        else:
-            oldinclude = set()
-            oldexclude = set()
-            oldprofiles = set()
-
-        try:
-            if reset:
-                newinclude = set()
-                newexclude = set()
-                newprofiles = set()
-            else:
-                newinclude = set(oldinclude)
-                newexclude = set(oldexclude)
-                newprofiles = set(oldprofiles)
-
-            oldstatus = repo.status()
-
-            if any(pat.startswith('/') for pat in pats):
-                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)
-
-            sparse.writeconfig(repo, newinclude, newexclude, newprofiles)
-
-            fcounts = map(
-                len,
-                sparse.refreshwdir(repo, oldstatus, oldsparsematch,
-                                   force=force))
-
-            profilecount = (len(newprofiles - oldprofiles) -
-                            len(oldprofiles - newprofiles))
-            includecount = (len(newinclude - oldinclude) -
-                            len(oldinclude - newinclude))
-            excludecount = (len(newexclude - oldexclude) -
-                            len(oldexclude - newexclude))
-            sparse.printchanges(ui, opts, profilecount, includecount,
-                                excludecount, *fcounts)
-        except Exception:
-            sparse.writeconfig(repo, oldinclude, oldexclude, oldprofiles)
-            raise
-    finally:
-        wlock.release()
diff --git a/mercurial/sparse.py b/mercurial/sparse.py
--- a/mercurial/sparse.py
+++ b/mercurial/sparse.py
@@ -583,6 +583,76 @@  def importfromfiles(repo, opts, paths, f
         printchanges(repo.ui, opts, profilecount, includecount, excludecount,
                      *fcounts)
 
+def updateconfig(repo, pats, opts, include=False, exclude=False, reset=False,
+                 delete=False, enableprofile=False, disableprofile=False,
+                 force=False):
+    """Perform a sparse config update.
+
+    Only one of the actions may be performed.
+
+    The new config is written out and a working directory refresh is performed.
+    """
+    wlock = repo.wlock()
+    try:
+        oldsparsematch = 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()
+
+        try:
+            if reset:
+                newinclude = set()
+                newexclude = set()
+                newprofiles = set()
+            else:
+                newinclude = set(oldinclude)
+                newexclude = set(oldexclude)
+                newprofiles = set(oldprofiles)
+
+            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)
+
+            writeconfig(repo, newinclude, newexclude, newprofiles)
+
+            fcounts = map(
+                len,
+                refreshwdir(repo, oldstatus, oldsparsematch, 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:
+            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):
     """Print output summarizing sparse config changes."""