Patchwork [2,of,8] scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns

login
register
mail settings
Submitter Matt Harbison
Date Nov. 27, 2014, 1:12 a.m.
Message ID <0a826a7d6222c6170d7c.1417050735@Envy>
Download mbox | patch
Permalink /patch/6872/
State Superseded
Headers show

Comments

Matt Harbison - Nov. 27, 2014, 1:12 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1415581022 18000
#      Sun Nov 09 19:57:02 2014 -0500
# Node ID 0a826a7d6222c6170d7c1c9c8cbe3a735d4ad3b7
# Parent  36938964dbce5fc575dce8d6c07d4aec4d3d8af3
scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns

This will make it easier to support subrepository operations.
Matt Harbison - Nov. 28, 2014, 6:47 a.m.
On Wed, 26 Nov 2014 20:12:15 -0500, Matt Harbison wrote:

> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1415581022 18000
> #      Sun Nov 09 19:57:02 2014 -0500
> # Node ID 0a826a7d6222c6170d7c1c9c8cbe3a735d4ad3b7
> # Parent  36938964dbce5fc575dce8d6c07d4aec4d3d8af3
> scmutil: pass a matcher to scmutil.addremove() instead of a list of patterns
> 
> diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
> --- a/mercurial/scmutil.py
> +++ b/mercurial/scmutil.py
> @@ -732,9 +731,9 @@
>          if repo.ui.verbose or not m.exact(abs):
>              rel = m.rel(abs)
>              if abs in unknownset:
> -                status = _('adding %s\n') % ((pats and rel) or abs)
> +                status = _('adding %s\n') % ((m.anypats() and rel) or abs)
>              else:
> -                status = _('removing %s\n') % ((pats and rel) or abs)
> +                status = _('removing %s\n') % ((m.anypats() and rel) or abs)

I misunderstood the comment for anypats() in the matcher class.  Both of
these should be 'm.files()'.  I'll wait another day or so for any comments
before resending.

>              repo.ui.status(status)
>  
>      renames = _findrenames(repo, m, added + unknown, removed + deleted,

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -94,7 +94,8 @@ 
     try:
         oldquiet = repo.ui.quiet
         repo.ui.quiet = True
-        timer(lambda: scmutil.addremove(repo, dry_run=True))
+        matcher = scmutil.match(repo[None])
+        timer(lambda: scmutil.addremove(repo, matcher, dry_run=True))
     finally:
         repo.ui.quiet = oldquiet
         fm.end()
diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -73,7 +73,7 @@ 
     scmutil.matchandpats = getattr(scmutil.matchandpats, 'oldmatchandpats',
             scmutil.matchandpats)
 
-def addlargefiles(ui, repo, *pats, **opts):
+def addlargefiles(ui, repo, matcher, **opts):
     large = opts.pop('large', None)
     lfsize = lfutil.getminsize(
         ui, lfutil.islfilesrepo(repo), opts.pop('lfsize', None))
@@ -85,7 +85,7 @@ 
             lfmatcher = match_.match(repo.root, '', list(lfpats))
 
     lfnames = []
-    m = scmutil.match(repo[None], pats, opts)
+    m = copy.copy(matcher)
     m.bad = lambda x, y: None
     wctx = repo[None]
     for f in repo.walk(m):
@@ -223,7 +223,8 @@ 
         if opts.get('large'):
             raise util.Abort(_('--normal cannot be used with --large'))
         return orig(ui, repo, *pats, **opts)
-    bad = addlargefiles(ui, repo, *pats, **opts)
+    matcher = scmutil.match(repo[None], pats, opts)
+    bad = addlargefiles(ui, repo, matcher, **opts)
     installnormalfilesmatchfn(repo[None].manifest())
     result = orig(ui, repo, *pats, **opts)
     restorematchfn()
@@ -1084,10 +1085,10 @@ 
     finally:
         repo.lfstatus = False
 
-def scmutiladdremove(orig, repo, pats=[], opts={}, dry_run=None,
+def scmutiladdremove(orig, repo, matcher, opts={}, dry_run=None,
                      similarity=None):
     if not lfutil.islfilesrepo(repo):
-        return orig(repo, pats, opts, dry_run, similarity)
+        return orig(repo, matcher, opts, dry_run, similarity)
     # Get the list of missing largefiles so we can remove them
     lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
     unsure, s = lfdirstate.status(match_.always(repo.root, repo.getcwd()), [],
@@ -1102,13 +1103,12 @@ 
         removelargefiles(repo.ui, repo, True, *m, **opts)
     # Call into the normal add code, and any files that *should* be added as
     # largefiles will be
-    addlargefiles(repo.ui, repo, *pats, **opts)
+    addlargefiles(repo.ui, repo, matcher, **opts)
     # Now that we've handled largefiles, hand off to the original addremove
     # function to take care of the rest.  Make sure it doesn't do anything with
-    # largefiles by installing a matcher that will ignore them.
-    installnormalfilesmatchfn(repo[None].manifest())
-    result = orig(repo, pats, opts, dry_run, similarity)
-    restorematchfn()
+    # largefiles by passing a matcher that will ignore them.
+    matcher = composenormalfilematcher(matcher, repo[None].manifest())
+    result = orig(repo, matcher, opts, dry_run, similarity)
     return result
 
 # Calling purge with --all will cause the largefiles to be deleted.
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2195,14 +2195,14 @@ 
     if date:
         opts['date'] = util.parsedate(date)
     message = logmessage(ui, opts)
+    matcher = scmutil.match(repo[None], pats, opts)
 
     # extract addremove carefully -- this function can be called from a command
     # that doesn't support addremove
     if opts.get('addremove'):
-        scmutil.addremove(repo, pats, opts)
-
-    return commitfunc(ui, repo, message,
-                      scmutil.match(repo[None], pats, opts), opts)
+        scmutil.addremove(repo, matcher, opts)
+
+    return commitfunc(ui, repo, message, matcher, opts)
 
 def amend(ui, repo, commitfunc, old, extra, pats, opts):
     # amend will reuse the existing user if not specified, but the obsolete
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -235,7 +235,8 @@ 
         raise util.Abort(_('similarity must be a number'))
     if sim < 0 or sim > 100:
         raise util.Abort(_('similarity must be between 0 and 100'))
-    return scmutil.addremove(repo, pats, opts, similarity=sim / 100.0)
+    matcher = scmutil.match(repo[None], pats, opts)
+    return scmutil.addremove(repo, matcher, opts, similarity=sim / 100.0)
 
 @command('^annotate|blame',
     [('r', 'rev', '', _('annotate the specified revision'), _('REV')),
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -713,13 +713,12 @@ 
     '''Return a matcher that will efficiently match exactly these files.'''
     return matchmod.exact(repo.root, repo.getcwd(), files)
 
-def addremove(repo, pats=[], opts={}, dry_run=None, similarity=None):
+def addremove(repo, m, opts={}, dry_run=None, similarity=None):
     if dry_run is None:
         dry_run = opts.get('dry_run')
     if similarity is None:
         similarity = float(opts.get('similarity') or 0)
-    # we'd use status here, except handling of symlinks and ignore is tricky
-    m = match(repo[None], pats, opts)
+
     rejected = []
     m.bad = lambda x, y: rejected.append(x)
 
@@ -732,9 +731,9 @@ 
         if repo.ui.verbose or not m.exact(abs):
             rel = m.rel(abs)
             if abs in unknownset:
-                status = _('adding %s\n') % ((pats and rel) or abs)
+                status = _('adding %s\n') % ((m.anypats() and rel) or abs)
             else:
-                status = _('removing %s\n') % ((pats and rel) or abs)
+                status = _('removing %s\n') % ((m.anypats() and rel) or abs)
             repo.ui.status(status)
 
     renames = _findrenames(repo, m, added + unknown, removed + deleted,