changeset 9367:1ef630452e0b

cmdutil: use context objects for walkchangerevs()
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Thu, 20 Aug 2009 08:34:22 +0200
parents 9ff178e7b627
children 8a4773bcbaec
files hgext/churn.py mercurial/cmdutil.py mercurial/commands.py tests/test-grep
diffstat 4 files changed, 36 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/churn.py	Tue Aug 18 22:07:43 2009 -0400
+++ b/hgext/churn.py	Thu Aug 20 08:34:22 2009 +0200
@@ -53,15 +53,17 @@
     if opts.get('date'):
         df = util.matchdate(opts['date'])
 
-    get = util.cachefunc(lambda r: repo[r].changeset())
+    get = util.cachefunc(lambda r: repo[r])
     changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
     for st, rev, fns in changeiter:
+
         if not st == 'add':
             continue
-        if df and not df(get(rev)[2][0]): # doesn't match date format
+
+        ctx = get(rev)
+        if df and not df(ctx.date()[0]): # doesn't match date format
             continue
 
-        ctx = repo[rev]
         key = getkey(ctx)
         key = amap.get(key, key) # alias remap
         if opts.get('changesets'):
--- a/mercurial/cmdutil.py	Tue Aug 18 22:07:43 2009 -0400
+++ b/mercurial/cmdutil.py	Thu Aug 20 08:34:22 2009 +0200
@@ -987,12 +987,12 @@
 def finddate(ui, repo, date):
     """Find the tipmost changeset that matches the given date spec"""
     df = util.matchdate(date)
-    get = util.cachefunc(lambda r: repo[r].changeset())
+    get = util.cachefunc(lambda r: repo[r])
     changeiter, matchfn = walkchangerevs(ui, repo, [], get, {'rev':None})
     results = {}
     for st, rev, fns in changeiter:
         if st == 'add':
-            d = get(rev)[2]
+            d = get(rev).date()
             if df(d[0]):
                 results[rev] = d
         elif st == 'iter':
@@ -1118,13 +1118,13 @@
         def changerevgen():
             for i, window in increasing_windows(len(repo) - 1, nullrev):
                 for j in xrange(i - window, i + 1):
-                    yield j, change(j)[3]
+                    yield change(j)
 
-        for rev, changefiles in changerevgen():
-            matches = filter(m, changefiles)
+        for ctx in changerevgen():
+            matches = filter(m, ctx.files())
             if matches:
-                fncache[rev] = matches
-                wanted.add(rev)
+                fncache[ctx.rev()] = matches
+                wanted.add(ctx.rev())
 
     class followfilter(object):
         def __init__(self, onlyfirst=False):
@@ -1189,7 +1189,7 @@
                 fns = fncache.get(rev)
                 if not fns:
                     def fns_generator():
-                        for f in change(rev)[3]:
+                        for f in change(rev).files():
                             if m(f):
                                 yield f
                     fns = fns_generator()
--- a/mercurial/commands.py	Tue Aug 18 22:07:43 2009 -0400
+++ b/mercurial/commands.py	Thu Aug 20 08:34:22 2009 +0200
@@ -1275,9 +1275,9 @@
             if opts.get('all'):
                 cols.append(change)
             if opts.get('user'):
-                cols.append(ui.shortuser(get(r)[1]))
+                cols.append(ui.shortuser(get(r).user()))
             if opts.get('date'):
-                cols.append(datefunc(get(r)[2]))
+                cols.append(datefunc(get(r).date()))
             if opts.get('files_with_matches'):
                 c = (fn, r)
                 if c in filerevmatches:
@@ -1291,7 +1291,7 @@
 
     skip = {}
     revfiles = {}
-    get = util.cachefunc(lambda r: repo[r].changeset())
+    get = util.cachefunc(lambda r: repo[r])
     changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
     found = False
     follow = opts.get('follow')
@@ -1300,7 +1300,7 @@
             matches.clear()
             revfiles.clear()
         elif st == 'add':
-            ctx = repo[rev]
+            ctx = get(rev)
             pctx = ctx.parents()[0]
             parent = pctx.rev()
             matches.setdefault(rev, {})
@@ -1334,7 +1334,7 @@
                     except error.LookupError:
                         pass
         elif st == 'iter':
-            parent = repo[rev].parents()[0].rev()
+            parent = get(rev).parents()[0].rev()
             for fn in sorted(revfiles.get(rev, [])):
                 states = matches[rev][fn]
                 copy = copies.get(rev, {}).get(fn)
@@ -1982,7 +1982,7 @@
     will appear in files:.
     """
 
-    get = util.cachefunc(lambda r: repo[r].changeset())
+    get = util.cachefunc(lambda r: repo[r])
     changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
 
     limit = cmdutil.loglimit(opts)
@@ -2040,40 +2040,37 @@
             if opts.get('only_merges') and len(parents) != 2:
                 continue
 
-            if only_branches:
-                revbranch = get(rev)[5]['branch']
-                if revbranch not in only_branches:
-                    continue
-
-            if df:
-                changes = get(rev)
-                if not df(changes[2][0]):
-                    continue
+            ctx = get(rev)
+            if only_branches and ctx.branch() not in only_branches:
+                continue
+
+            if df and not df(ctx.date()):
+                continue
 
             if opts.get('keyword'):
-                changes = get(rev)
                 miss = 0
                 for k in [kw.lower() for kw in opts['keyword']]:
-                    if not (k in changes[1].lower() or
-                            k in changes[4].lower() or
-                            k in " ".join(changes[3]).lower()):
+                    if not (k in ctx.user().lower() or
+                            k in ctx.description().lower() or
+                            k in " ".join(ctx.files()[3]).lower()):
                         miss = 1
                         break
                 if miss:
                     continue
 
             if opts['user']:
-                changes = get(rev)
-                if not [k for k in opts['user'] if k in changes[1]]:
+                if not [k for k in opts['user'] if k in ctx.user()]:
                     continue
 
             copies = []
             if opts.get('copies') and rev:
-                for fn in get(rev)[3]:
+                for fn in ctx.files():
                     rename = getrenamed(fn, rev)
                     if rename:
                         copies.append((fn, rename[0]))
-            displayer.show(context.changectx(repo, rev), copies=copies)
+
+            displayer.show(ctx, copies=copies)
+
         elif st == 'iter':
             if count == limit: break
             if displayer.flush(rev):
--- a/tests/test-grep	Tue Aug 18 22:07:43 2009 -0400
+++ b/tests/test-grep	Thu Aug 20 08:34:22 2009 +0200
@@ -22,14 +22,14 @@
 echo % simple
 hg grep port port
 echo % all
-hg grep --all -nu port port
+hg grep --traceback --all -nu port port
 echo % other
 hg grep import port
 
 hg cp port port2
 hg commit -m 4 -u spam -d '5 0'
-echo '% follow'
-hg grep -f 'import$' port2
+echo % follow
+hg grep --traceback -f 'import$' port2
 echo deport >> port2
 hg commit -m 5 -u eggs -d '6 0'
 hg grep -f --all -nu port port2