No subject


Tue Dec 8 09:22:11 UTC 2009


--Joe Amenta

--azLHFNyN32YCQGCU
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="match_refactored.patch"

diff -r 261cc6b0f15c contrib/perf.py
--- a/contrib/perf.py	Thu Feb 18 23:23:17 2010 -0600
+++ b/contrib/perf.py	Sun Feb 21 19:32:22 2010 -0500
@@ -31,11 +31,11 @@
 
 def perfwalk(ui, repo, *pats):
     try:
-        m = cmdutil.match(repo, pats, {})
+        m = match.matchpat(repo, pats, {})
         timer(lambda: len(list(repo.dirstate.walk(m, [], True, False))))
     except:
         try:
-            m = cmdutil.match(repo, pats, {})
+            m = match.matchpat(repo, pats, {})
             timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)]))
         except:
             timer(lambda: len(list(cmdutil.walk(repo, pats, {}))))
diff -r 261cc6b0f15c hgext/churn.py
--- a/hgext/churn.py	Thu Feb 18 23:23:17 2010 -0600
+++ b/hgext/churn.py	Sun Feb 21 19:32:22 2010 -0500
@@ -9,7 +9,7 @@
 '''command to display statistics about repository history'''
 
 from mercurial.i18n import _
-from mercurial import patch, cmdutil, util, templater
+from mercurial import patch, cmdutil, util, templater, match
 import sys, os
 import time, datetime
 
@@ -24,7 +24,7 @@
 
 def changedlines(ui, repo, ctx1, ctx2, fns):
     added, removed = 0, 0
-    fmatch = cmdutil.matchfiles(repo, fns)
+    fmatch = match.matchfiles(repo, fns)
     diff = ''.join(patch.diff(repo, ctx1.node(), ctx2.node(), fmatch))
     for l in diff.split('\n'):
         if l.startswith("+") and not l.startswith("+++ "):
@@ -54,7 +54,7 @@
     if opts.get('date'):
         df = util.matchdate(opts['date'])
 
-    m = cmdutil.match(repo, pats, opts)
+    m = match.matchpat(repo, pats, opts)
     def prep(ctx, fns):
         rev = ctx.rev()
         if df and not df(ctx.date()[0]): # doesn't match date format
diff -r 261cc6b0f15c hgext/extdiff.py
--- a/hgext/extdiff.py	Thu Feb 18 23:23:17 2010 -0600
+++ b/hgext/extdiff.py	Sun Feb 21 19:32:22 2010 -0500
@@ -43,7 +43,7 @@
 
 from mercurial.i18n import _
 from mercurial.node import short, nullid
-from mercurial import cmdutil, util, commands, encoding
+from mercurial import cmdutil, util, commands, encoding, match
 import os, shlex, shutil, tempfile, re
 
 def snapshot(ui, repo, files, node, tmproot):
@@ -117,7 +117,7 @@
         if node1b == nullid:
             do3way = False
 
-    matcher = cmdutil.match(repo, pats, opts)
+    matcher = match.matchpat(repo, pats, opts)
     mod_a, add_a, rem_a = map(set, repo.status(node1a, node2, matcher)[:3])
     if do3way:
         mod_b, add_b, rem_b = map(set, repo.status(node1b, node2, matcher)[:3])
diff -r 261cc6b0f15c hgext/hgk.py
--- a/hgext/hgk.py	Thu Feb 18 23:23:17 2010 -0600
+++ b/hgext/hgk.py	Sun Feb 21 19:32:22 2010 -0500
@@ -45,7 +45,7 @@
         assert node2 is not None
         mmap = repo[node1].manifest()
         mmap2 = repo[node2].manifest()
-        m = cmdutil.match(repo, files)
+        m = match.matchpat(repo, files)
         modified, added, removed  = repo.status(node1, node2, m)[:3]
         empty = short(nullid)
 
@@ -81,7 +81,7 @@
         if opts['patch']:
             if opts['pretty']:
                 catcommit(ui, repo, node2, "")
-            m = cmdutil.match(repo, files)
+            m = match.matchpat(repo, files)
             chunks = patch.diff(repo, node1, node2, match=m,
                                 opts=patch.diffopts(ui, {'git': True}))
             for chunk in chunks:
diff -r 261cc6b0f15c hgext/keyword.py
--- a/hgext/keyword.py	Thu Feb 18 23:23:17 2010 -0600
+++ b/hgext/keyword.py	Sun Feb 21 19:32:22 2010 -0500
@@ -253,7 +253,7 @@
     if kwt:
         unknown = (opts.get('unknown') or opts.get('all')
                    or opts.get('untracked'))
-        return repo.status(match=cmdutil.match(repo, pats, opts), clean=True,
+        return repo.status(match=match.matchpat(repo, pats, opts), clean=True,
                            unknown=unknown)
     if ui.configitems('keyword'):
         raise util.Abort(_('[keyword] patterns cannot match'))
diff -r 261cc6b0f15c hgext/mq.py
--- a/hgext/mq.py	Thu Feb 18 23:23:17 2010 -0600
+++ b/hgext/mq.py	Sun Feb 21 19:32:22 2010 -0500
@@ -44,7 +44,7 @@
 from mercurial.node import bin, hex, short, nullid, nullrev
 from mercurial.lock import release
 from mercurial import commands, cmdutil, hg, patch, util
-from mercurial import repair, extensions, url, error
+from mercurial import repair, extensions, url, error, match
 import os, sys, re, errno
 
 commands.norepo += " qclone"
@@ -492,8 +492,8 @@
         if stat:
             opts['unified'] = '0'
 
-        m = cmdutil.match(repo, files, opts)
-        chunks = patch.diff(repo, node1, node2, m, changes, diffopts)
+        fmatch = match.matchpat(repo, files, opts)
+        chunks = patch.diff(repo, node1, node2, fmatch, changes, diffopts)
         write = fp is None and repo.ui.write or fp.write
         if stat:
             width = self.ui.interactive() and util.termwidth() or 80
@@ -697,8 +697,8 @@
                 repo.dirstate.setparents(p1, merge)
 
             files = patch.updatedir(self.ui, repo, files)
-            match = cmdutil.matchfiles(repo, files or [])
-            n = repo.commit(message, ph.user, ph.date, match=match, force=True)
+            fmatch = match.matchfiles(repo, files or [])
+            n = repo.commit(message, ph.user, ph.date, match=fmatch, force=True)
 
             if n is None:
                 raise util.Abort(_("repo commit failed"))
@@ -831,15 +831,15 @@
         if os.path.exists(self.join(patchfn)):
             raise util.Abort(_('patch "%s" already exists') % patchfn)
         if opts.get('include') or opts.get('exclude') or pats:
-            match = cmdutil.match(repo, pats, opts)
+            fmatch = match.matchpat(repo, pats, opts)
             # detect missing files in pats
             def badfn(f, msg):
                 raise util.Abort('%s: %s' % (f, msg))
-            match.bad = badfn
-            m, a, r, d = repo.status(match=match)[:4]
+            fmatch.bad = badfn
+            m, a, r, d = repo.status(match=fmatch)[:4]
         else:
             m, a, r, d = self.check_localchanges(repo, force=True)
-            match = cmdutil.matchfiles(repo, m + a + r)
+            fmatch = match.matchfiles(repo, m + a + r)
         if len(repo[None].parents()) > 1:
             raise util.Abort(_('cannot manage merge changesets'))
         commitfiles = m + a + r
@@ -868,7 +868,7 @@
                 if hasattr(msg, '__call__'):
                     msg = msg()
                 commitmsg = msg and msg or ("[mq]: %s" % patchfn)
-                n = repo.commit(commitmsg, user, date, match=match, force=True)
+                n = repo.commit(commitmsg, user, date, match=fmatch, force=True)
                 if n is None:
                     raise util.Abort(_("repo commit failed"))
                 try:
@@ -883,7 +883,7 @@
                     if commitfiles:
                         parent = self.qparents(repo, n)
                         chunks = patch.diff(repo, node1=parent, node2=n,
-                                            match=match, opts=diffopts)
+                                            match=fmatch, opts=diffopts)
                         for chunk in chunks:
                             p.write(chunk)
                     p.close()
@@ -1268,18 +1268,18 @@
             changes = repo.changelog.read(top)
             man = repo.manifest.read(changes[0])
             aaa = aa[:]
-            matchfn = cmdutil.match(repo, pats, opts)
+            matchfn = match.matchpat(repo, pats, opts)
             # in short mode, we only diff the files included in the
             # patch already plus specified files
             if opts.get('short'):
                 # if amending a patch, we start with existing
                 # files plus specified files - unfiltered
-                match = cmdutil.matchfiles(repo, mm + aa + dd + matchfn.files())
+                fmatch = match.matchfiles(repo, mm + aa + dd + matchfn.files())
                 # filter with inc/exl options
-                matchfn = cmdutil.match(repo, opts=opts)
+                matchfn = match.matchpat(repo, opts=opts)
             else:
-                match = cmdutil.matchall(repo)
-            m, a, r, d = repo.status(match=match)[:4]
+                fmatch = match.matchall(repo)
+            m, a, r, d = repo.status(match=fmatch)[:4]
 
             # we might end up with files that were added between
             # qtip and the dirstate parent, but then changed in the
@@ -1313,8 +1313,8 @@
             r = list(set(dd))
             a = list(set(aa))
             c = [filter(matchfn, l) for l in (m, a, r)]
-            match = cmdutil.matchfiles(repo, set(c[0] + c[1] + c[2]))
-            chunks = patch.diff(repo, patchparent, match=match,
+            fmatch = match.matchfiles(repo, set(c[0] + c[1] + c[2]))
+            chunks = patch.diff(repo, patchparent, match=fmatch,
                                 changes=c, opts=diffopts)
             for chunk in chunks:
                 patchf.write(chunk)
@@ -1389,7 +1389,7 @@
             try:
                 # might be nice to attempt to roll back strip after this
                 patchf.rename()
-                n = repo.commit(message, user, ph.date, match=match,
+                n = repo.commit(message, user, ph.date, match=fmatch,
                                 force=True)
                 self.applied.append(statusentry(hex(n), patchfn))
             except:
diff -r 261cc6b0f15c hgext/purge.py
--- a/hgext/purge.py	Thu Feb 18 23:23:17 2010 -0600
+++ b/hgext/purge.py	Sun Feb 21 19:32:22 2010 -0500
@@ -25,7 +25,7 @@
 
 '''command to delete untracked files from the working directory'''
 
-from mercurial import util, commands, cmdutil
+from mercurial import util, commands, cmdutil, match
 from mercurial.i18n import _
 import os, stat
 
@@ -85,16 +85,16 @@
             os.remove(path)
 
     directories = []
-    match = cmdutil.match(repo, dirs, opts)
-    match.dir = directories.append
-    status = repo.status(match=match, ignored=opts['all'], unknown=True)
+    found = match.matchpat(repo, dirs, opts)
+    found.dir = directories.append
+    status = repo.status(match=found, ignored=opts['all'], unknown=True)
 
     for f in sorted(status[4] + status[5]):
         ui.note(_('Removing file %s\n') % f)
         remove(removefile, f)
 
     for f in sorted(directories, reverse=True):
-        if match(f) and not os.listdir(repo.wjoin(f)):
+        if found(f) and not os.listdir(repo.wjoin(f)):
             ui.note(_('Removing directory %s\n') % f)
             remove(os.rmdir, f)
 
diff -r 261cc6b0f15c mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Thu Feb 18 23:23:17 2010 -0600
+++ b/mercurial/cmdutil.py	Sun Feb 21 19:32:22 2010 -0500
@@ -10,6 +10,8 @@
 import os, sys, errno, re, glob, tempfile
 import mdiff, bdiff, util, templater, patch, error, encoding, templatekw
 import match as _match
+# expose these names for backwards compatibility with external code
+from match import matchpat as match, matchall, matchfiles, expandpats
 
 revrangesep = ':'
 
@@ -252,39 +254,6 @@
                               pathname),
                 mode)
 
-def expandpats(pats):
-    if not util.expandglobs:
-        return list(pats)
-    ret = []
-    for p in pats:
-        kind, name = _match._patsplit(p, None)
-        if kind is None:
-            try:
-                globbed = glob.glob(name)
-            except re.error:
-                globbed = [name]
-            if globbed:
-                ret.extend(globbed)
-                continue
-        ret.append(p)
-    return ret
-
-def match(repo, pats=[], opts={}, globbed=False, default='relpath'):
-    if not globbed and default == 'relpath':
-        pats = expandpats(pats or [])
-    m = _match.match(repo.root, repo.getcwd(), pats,
-                    opts.get('include'), opts.get('exclude'), default)
-    def badfn(f, msg):
-        repo.ui.warn("%s: %s\n" % (m.rel(f), msg))
-    m.bad = badfn
-    return m
-
-def matchall(repo):
-    return _match.always(repo.root, repo.getcwd())
-
-def matchfiles(repo, files):
-    return _match.exact(repo.root, repo.getcwd(), files)
-
 def findrenames(repo, added, removed, threshold):
     '''find renamed files -- yields (before, after, score) tuples'''
     copies = {}
@@ -332,7 +301,7 @@
     # we'd use status here, except handling of symlinks and ignore is tricky
     added, unknown, deleted, removed = [], [], [], []
     audit_path = util.path_auditor(repo.root)
-    m = match(repo, pats, opts)
+    m = _match.matchpat(repo, pats, opts)
     for abs in repo.walk(m):
         target = repo.wjoin(abs)
         good = True
@@ -381,7 +350,7 @@
 
     def walkpat(pat):
         srcs = []
-        m = match(repo, [pat], opts, globbed=True)
+        m = _match.matchpat(repo, [pat], opts, globbed=True)
         for abs in repo.walk(m):
             state = repo.dirstate[abs]
             rel = m.rel(abs)
@@ -537,7 +506,7 @@
         return res
 
 
-    pats = expandpats(pats)
+    pats = _match.expandpats(pats)
     if not pats:
         raise util.Abort(_('no source or destination specified'))
     if len(pats) == 1:
@@ -891,7 +860,7 @@
     # options
     patch = False
     if opts.get('patch'):
-        patch = matchfn or matchall(repo)
+        patch = matchfn or _match.matchall(repo)
 
     tmpl = opts.get('template')
     style = None
@@ -932,7 +901,7 @@
     """Find the tipmost changeset that matches the given date spec"""
 
     df = util.matchdate(date)
-    m = matchall(repo)
+    m = _match.matchall(repo)
     results = {}
 
     def prep(ctx, fns):
@@ -1147,7 +1116,7 @@
     if opts.get('addremove'):
         addremove(repo, pats, opts)
 
-    return commitfunc(ui, repo, message, match(repo, pats, opts), opts)
+    return commitfunc(ui, repo, message, _match.matchpat(repo, pats, opts), opts)
 
 def commiteditor(repo, ctx, subs):
     if ctx.description():
diff -r 261cc6b0f15c mercurial/commands.py
--- a/mercurial/commands.py	Thu Feb 18 23:23:17 2010 -0600
+++ b/mercurial/commands.py	Sun Feb 21 19:32:22 2010 -0500
@@ -10,7 +10,7 @@
 from i18n import _, gettext
 import os, re, sys, difflib, time, tempfile
 import hg, util, revlog, bundlerepo, extensions, copies, error
-import patch, help, mdiff, url, encoding, templatekw
+import patch, help, mdiff, url, encoding, templatekw, match
 import archival, changegroup, cmdutil, sshserver, hbisect
 from hgweb import server
 import merge as merge_
@@ -46,7 +46,7 @@
 
     bad = []
     names = []
-    m = cmdutil.match(repo, pats, opts)
+    m = match.matchpat(repo, pats, opts)
     oldbad = m.bad
     m.bad = lambda x, y: bad.append(x) or oldbad(x, y)
 
@@ -126,7 +126,7 @@
         funcmap[-1] = lambda x: "%s:%s" % (lastfunc(x), x[1])
 
     ctx = repo[opts.get('rev')]
-    m = cmdutil.match(repo, pats, opts)
+    m = match.matchpat(repo, pats, opts)
     follow = not opts.get('no_follow')
     for abs in ctx.walk(m):
         fctx = ctx[abs]
@@ -179,7 +179,7 @@
     dest = cmdutil.make_filename(repo, dest, node)
     if os.path.realpath(dest) == repo.root:
         raise util.Abort(_('repository root cannot be destination'))
-    matchfn = cmdutil.match(repo, [], opts)
+    matchfn = match.matchpat(repo, [], opts)
     kind = opts.get('type') or 'files'
     prefix = opts.get('prefix')
     if dest == '-':
@@ -589,7 +589,7 @@
     """
     ctx = repo[opts.get('rev')]
     err = 1
-    m = cmdutil.match(repo, (file1,) + pats, opts)
+    m = match.matchpat(repo, (file1,) + pats, opts)
     for abs in ctx.walk(m):
         fp = cmdutil.make_file(repo, opts.get('output'), ctx.node(), pathname=abs)
         data = ctx[abs].data()
@@ -1074,7 +1074,7 @@
     """dump rename information"""
 
     ctx = repo[opts.get('rev')]
-    m = cmdutil.match(repo, (file1,) + pats, opts)
+    m = match.matchpat(repo, (file1,) + pats, opts)
     for abs in ctx.walk(m):
         fctx = ctx[abs]
         o = fctx.filelog().renamed(fctx.filenode())
@@ -1086,7 +1086,7 @@
 
 def debugwalk(ui, repo, *pats, **opts):
     """show how files match on given patterns"""
-    m = cmdutil.match(repo, pats, opts)
+    m = match.matchpat(repo, pats, opts)
     items = list(repo.walk(m))
     if not items:
         return
@@ -1143,7 +1143,7 @@
         opts['unified'] = '0'
     diffopts = patch.diffopts(ui, opts)
 
-    m = cmdutil.match(repo, pats, opts)
+    m = match.matchpat(repo, pats, opts)
     it = patch.diff(repo, node1, node2, match=m, opts=diffopts)
     if stat:
         width = ui.interactive() and util.termwidth() or 80
@@ -1216,7 +1216,7 @@
     if not pats:
         raise util.Abort(_('no files specified'))
 
-    m = cmdutil.match(repo, pats, opts)
+    m = match.matchpat(repo, pats, opts)
     s = repo.status(match=m, clean=True)
     forget = sorted(s[0] + s[1] + s[3] + s[6])
 
@@ -1344,7 +1344,7 @@
 
     skip = {}
     revfiles = {}
-    matchfn = cmdutil.match(repo, pats, opts)
+    matchfn = match.matchpat(repo, pats, opts)
     found = False
     follow = opts.get('follow')
 
@@ -1907,7 +1907,7 @@
                 if opts.get('exact'):
                     m = None
                 else:
-                    m = cmdutil.matchfiles(repo, files or [])
+                    m = match.matchfiles(repo, files or [])
                 n = repo.commit(message, opts.get('user') or user,
                                 opts.get('date') or date, match=m,
                                 editor=cmdutil.commiteditor)
@@ -2061,7 +2061,7 @@
     rev = opts.get('rev') or None
 
     ret = 1
-    m = cmdutil.match(repo, pats, opts, default='relglob')
+    m = match.matchpat(repo, pats, opts, default='relglob')
     m.bad = lambda x, y: False
     for abs in repo[rev].walk(m):
         if not rev and abs not in repo.dirstate:
@@ -2103,7 +2103,7 @@
     will appear in files:.
     """
 
-    matchfn = cmdutil.match(repo, pats, opts)
+    matchfn = match.matchpat(repo, pats, opts)
     limit = cmdutil.loglimit(opts)
     count = 0
 
@@ -2299,7 +2299,7 @@
         ctx = repo[None]
 
     if file_:
-        m = cmdutil.match(repo, (file_,), opts)
+        m = match.matchpat(repo, (file_,), opts)
         if m.anypats() or len(m.files()) != 1:
             raise util.Abort(_('can only specify an explicit filename'))
         file_ = m.files()[0]
@@ -2475,7 +2475,7 @@
     if not pats and not after:
         raise util.Abort(_('no files specified'))
 
-    m = cmdutil.match(repo, pats, opts)
+    m = match.matchpat(repo, pats, opts)
     s = repo.status(match=m, clean=True)
     modified, added, deleted, clean = s[0], s[1], s[3], s[6]
 
@@ -2560,7 +2560,7 @@
                            'use --all to remerge all files'))
 
     ms = merge_.mergestate(repo)
-    m = cmdutil.match(repo, pats, opts)
+    m = match.matchpat(repo, pats, opts)
 
     for f in ms:
         if m(f):
@@ -2652,7 +2652,7 @@
     try:
         # walk dirstate.
 
-        m = cmdutil.match(repo, pats, opts)
+        m = match.matchpat(repo, pats, opts)
         m.bad = lambda x, y: False
         for abs in repo.walk(m):
             names[abs] = m.rel(abs), m.exact(abs)
@@ -2668,13 +2668,13 @@
                     return
             ui.warn("%s: %s\n" % (m.rel(path), msg))
 
-        m = cmdutil.match(repo, pats, opts)
+        m = match.matchpat(repo, pats, opts)
         m.bad = badfn
         for abs in repo[node].walk(m):
             if abs not in names:
                 names[abs] = m.rel(abs), m.exact(abs)
 
-        m = cmdutil.matchfiles(repo, names)
+        m = match.matchfiles(repo, names)
         changes = repo.status(match=m)[:4]
         modified, added, removed, deleted = map(set, changes)
 
@@ -2964,7 +2964,7 @@
     if not show:
         show = ui.quiet and states[:4] or states[:5]
 
-    stat = repo.status(node1, node2, cmdutil.match(repo, pats, opts),
+    stat = repo.status(node1, node2, match.matchpat(repo, pats, opts),
                        'ignored' in show, 'clean' in show, 'unknown' in show)
     changestates = zip(states, 'MAR!?IC', stat)
 
diff -r 261cc6b0f15c mercurial/match.py
--- a/mercurial/match.py	Thu Feb 18 23:23:17 2010 -0600
+++ b/mercurial/match.py	Sun Feb 21 19:32:22 2010 -0500
@@ -248,3 +248,37 @@
     for kind, name in patterns:
         if kind in ('glob', 're', 'relglob', 'relre'):
             return True
+
+def expandpats(pats):
+    if not util.expandglobs:
+        return list(pats)
+    ret = []
+    for p in pats:
+        kind, name = _patsplit(p, None)
+        if kind is None:
+            try:
+                globbed = glob.glob(name)
+            except re.error:
+                globbed = [name]
+            if globbed:
+                ret.extend(globbed)
+                continue
+        ret.append(p)
+    return ret
+        
+def matchpat(repo, pats=[], opts={}, globbed=False, default='relpath'):
+    if not globbed and default == 'relpath':
+        pats = expandpats(pats or [])
+    m = match(repo.root, repo.getcwd(), pats,
+                    opts.get('include'), opts.get('exclude'), default)
+    def badfn(f, msg):
+        repo.ui.warn("%s: %s\n" % (m.rel(f), msg))
+    m.bad = badfn
+    return m
+
+def matchall(repo):
+    return always(repo.root, repo.getcwd())
+
+def matchfiles(repo, files):
+    return exact(repo.root, repo.getcwd(), files)
+
diff -r 261cc6b0f15c tests/autodiff.py
--- a/tests/autodiff.py	Thu Feb 18 23:23:17 2010 -0600
+++ b/tests/autodiff.py	Sun Feb 21 19:32:22 2010 -0500
@@ -1,7 +1,7 @@
 # Extension dedicated to test patch.diff() upgrade modes
 #
 #
-from mercurial import cmdutil, patch, util
+from mercurial import cmdutil, patch, util, match
 
 def autodiff(ui, repo, *pats, **opts):
     diffopts = patch.diffopts(ui, opts)
@@ -29,7 +29,7 @@
         raise util.Abort('--git must be yes, no or auto')
 
     node1, node2 = cmdutil.revpair(repo, [])
-    m = cmdutil.match(repo, pats, opts)
+    m = match.matchpat(repo, pats, opts)
     it = patch.diff(repo, node1, node2, match=m, opts=diffopts,
                     losedatafn=losedatafn)
     for chunk in it:

--azLHFNyN32YCQGCU--


More information about the Mercurial-devel mailing list