diff hgext/sparse.py @ 33371:c6415195fa78

sparse: move code for importing rules from files into core This is a pretty straightforward port. Some code cleanup was performed. But no major changes to the logic were made. I'm not a huge fan of this function because it does multiple things. I'd like to get things into core first to facilitate refactoring later. Please also note the added inline comment about the oddities of writeconfig() and the try..except to undo it. This is because of the hackiness in which the sparse matcher is obtained by various consumers, notably dirstate. We'll need a massive refactor to address this. That refactor is effectively blocked on having the sparse dirstate hacks live in core.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 08 Jul 2017 14:15:07 -0700
parents 482320104672
children 4481f1fd27b1
line wrap: on
line diff
--- a/hgext/sparse.py	Sat Jul 08 14:01:32 2017 -0700
+++ b/hgext/sparse.py	Sat Jul 08 14:15:07 2017 -0700
@@ -361,7 +361,7 @@
                 disableprofile=disableprofile, force=force)
 
     if importrules:
-        _import(ui, repo, pats, opts, force=force)
+        sparse.importfromfiles(repo, opts, pats, force=force)
 
     if clearrules:
         sparse.clearrules(repo, force=force)
@@ -444,51 +444,3 @@
             raise
     finally:
         wlock.release()
-
-def _import(ui, repo, files, opts, force=False):
-    with repo.wlock():
-        # read current configuration
-        raw = repo.vfs.tryread('sparse')
-        oincludes, oexcludes, oprofiles = sparse.parseconfig(ui, raw)
-        includes, excludes, profiles = map(
-                set, (oincludes, oexcludes, oprofiles))
-
-        aincludes, aexcludes, aprofiles = sparse.activeconfig(repo)
-
-        # import rules on top; only take in rules that are not yet
-        # part of the active rules.
-        changed = False
-        for file in files:
-            with util.posixfile(util.expandpath(file)) as importfile:
-                iincludes, iexcludes, iprofiles = sparse.parseconfig(
-                    ui, importfile.read())
-                oldsize = len(includes) + len(excludes) + len(profiles)
-                includes.update(iincludes - aincludes)
-                excludes.update(iexcludes - aexcludes)
-                profiles.update(set(iprofiles) - aprofiles)
-                if len(includes) + len(excludes) + len(profiles) > oldsize:
-                    changed = True
-
-        profilecount = includecount = excludecount = 0
-        fcounts = (0, 0, 0)
-
-        if changed:
-            profilecount = len(profiles - aprofiles)
-            includecount = len(includes - aincludes)
-            excludecount = len(excludes - aexcludes)
-
-            oldstatus = repo.status()
-            oldsparsematch = sparse.matcher(repo)
-            sparse.writeconfig(repo, includes, excludes, profiles)
-
-            try:
-                fcounts = map(
-                    len,
-                    sparse.refreshwdir(repo, oldstatus, oldsparsematch,
-                                       force=force))
-            except Exception:
-                sparse.writeconfig(repo, oincludes, oexcludes, oprofiles)
-                raise
-
-        sparse.printchanges(ui, opts, profilecount, includecount, excludecount,
-                            *fcounts)