walkchangerevs: pull out matchfn
authorMatt Mackall <mpm@selenic.com>
Sun, 25 Oct 2009 18:43:56 -0500
changeset 9652 2cb0cab10d2e
parent 9632 16698d87ad20
child 9653 e4de75343743
walkchangerevs: pull out matchfn * * * imported patch mercurial/commands.py
hgext/churn.py
mercurial/cmdutil.py
mercurial/commands.py
--- a/hgext/churn.py	Mon Sep 21 19:21:32 2009 +0200
+++ b/hgext/churn.py	Sun Oct 25 18:43:56 2009 -0500
@@ -54,8 +54,8 @@
         df = util.matchdate(opts['date'])
 
     get = util.cachefunc(lambda r: repo[r])
-    changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
-    for st, rev, fns in changeiter:
+    m = cmdutil.match(repo, pats, opts)
+    for st, rev, fns in cmdutil.walkchangerevs(ui, repo, m, get, opts):
 
         if not st == 'add':
             continue
--- a/mercurial/cmdutil.py	Mon Sep 21 19:21:32 2009 +0200
+++ b/mercurial/cmdutil.py	Sun Oct 25 18:43:56 2009 -0500
@@ -1024,9 +1024,9 @@
     """Find the tipmost changeset that matches the given date spec"""
     df = util.matchdate(date)
     get = util.cachefunc(lambda r: repo[r])
-    changeiter, matchfn = walkchangerevs(ui, repo, [], get, {'rev':None})
+    m = matchall(repo)
     results = {}
-    for st, rev, fns in changeiter:
+    for st, rev, fns in walkchangerevs(ui, repo, m, get, {'rev':None}):
         if st == 'add':
             d = get(rev).date()
             if df(d[0]):
@@ -1039,7 +1039,7 @@
 
     raise util.Abort(_("revision matching date not found"))
 
-def walkchangerevs(ui, repo, pats, change, opts):
+def walkchangerevs(ui, repo, match, change, opts):
     '''Iterate over files and the revs in which they changed.
 
     Callers most commonly need to iterate backwards over the history
@@ -1050,8 +1050,8 @@
     window, we first walk forwards to gather data, then in the desired
     order (usually backwards) to display it.
 
-    This function returns an (iterator, matchfn) tuple. The iterator
-    yields 3-tuples. They will be of one of the following forms:
+    This function returns an iterator. The iterator yields 3-tuples.
+    They will be of one of the following forms:
 
     "window", incrementing, lastrev: stepping through a window,
     positive if walking forwards through revs, last rev in the
@@ -1078,11 +1078,10 @@
                 if windowsize < sizelimit:
                     windowsize *= 2
 
-    m = match(repo, pats, opts)
     follow = opts.get('follow') or opts.get('follow_first')
 
     if not len(repo):
-        return [], m
+        return []
 
     if follow:
         defrange = '%s:0' % repo['.'].rev()
@@ -1090,10 +1089,10 @@
         defrange = '-1:0'
     revs = revrange(repo, opts['rev'] or [defrange])
     wanted = set()
-    slowpath = m.anypats() or (m.files() and opts.get('removed'))
+    slowpath = match.anypats() or (match.files() and opts.get('removed'))
     fncache = {}
 
-    if not slowpath and not m.files():
+    if not slowpath and not match.files():
         # No files, no patterns.  Display all revs.
         wanted = set(revs)
     copies = []
@@ -1117,7 +1116,7 @@
                     if rev[0] < cl_count:
                         yield rev
         def iterfiles():
-            for filename in m.files():
+            for filename in match.files():
                 yield filename, None
             for filename_node in copies:
                 yield filename_node
@@ -1157,7 +1156,7 @@
                     yield change(j)
 
         for ctx in changerevgen():
-            matches = filter(m, ctx.files())
+            matches = filter(match, ctx.files())
             if matches:
                 fncache[ctx.rev()] = matches
                 wanted.add(ctx.rev())
@@ -1210,7 +1209,7 @@
                 wanted.discard(x)
 
     def iterate():
-        if follow and not m.files():
+        if follow and not match.files():
             ff = followfilter(onlyfirst=opts.get('follow_first'))
             def want(rev):
                 return ff.match(rev) and rev in wanted
@@ -1226,13 +1225,13 @@
                 if not fns:
                     def fns_generator():
                         for f in change(rev).files():
-                            if m(f):
+                            if match(f):
                                 yield f
                     fns = fns_generator()
                 yield 'add', rev, fns
             for rev in nrevs:
                 yield 'iter', rev, None
-    return iterate(), m
+    return iterate()
 
 def commit(ui, repo, commitfunc, pats, opts):
     '''commit the specified files or all outstanding changes'''
--- a/mercurial/commands.py	Mon Sep 21 19:21:32 2009 +0200
+++ b/mercurial/commands.py	Sun Oct 25 18:43:56 2009 -0500
@@ -1289,10 +1289,10 @@
     skip = {}
     revfiles = {}
     get = util.cachefunc(lambda r: repo[r])
-    changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
+    matchfn = cmdutil.match(repo, pats, opts)
     found = False
     follow = opts.get('follow')
-    for st, rev, fns in changeiter:
+    for st, rev, fns in cmdutil.walkchangerevs(ui, repo, matchfn, get, opts):
         if st == 'window':
             matches.clear()
             revfiles.clear()
@@ -1980,8 +1980,7 @@
     """
 
     get = util.cachefunc(lambda r: repo[r])
-    changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
-
+    matchfn = cmdutil.match(repo, pats, opts)
     limit = cmdutil.loglimit(opts)
     count = 0
 
@@ -2028,7 +2027,7 @@
     only_branches = opts.get('only_branch')
 
     displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn)
-    for st, rev, fns in changeiter:
+    for st, rev, fns in cmdutil.walkchangerevs(ui, repo, matchfn, get, opts):
         if st == 'add':
             parents = [p for p in repo.changelog.parentrevs(rev)
                        if p != nullrev]