##// END OF EJS Templates
cmdutil: use context objects for walkchangerevs()
Dirkjan Ochtman -
r9367:1ef63045 default
parent child Browse files
Show More
@@ -53,15 +53,17 b' def countrate(ui, repo, amap, *pats, **o'
53 if opts.get('date'):
53 if opts.get('date'):
54 df = util.matchdate(opts['date'])
54 df = util.matchdate(opts['date'])
55
55
56 get = util.cachefunc(lambda r: repo[r].changeset())
56 get = util.cachefunc(lambda r: repo[r])
57 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
57 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
58 for st, rev, fns in changeiter:
58 for st, rev, fns in changeiter:
59
59 if not st == 'add':
60 if not st == 'add':
60 continue
61 continue
61 if df and not df(get(rev)[2][0]): # doesn't match date format
62
63 ctx = get(rev)
64 if df and not df(ctx.date()[0]): # doesn't match date format
62 continue
65 continue
63
66
64 ctx = repo[rev]
65 key = getkey(ctx)
67 key = getkey(ctx)
66 key = amap.get(key, key) # alias remap
68 key = amap.get(key, key) # alias remap
67 if opts.get('changesets'):
69 if opts.get('changesets'):
@@ -987,12 +987,12 b' def show_changeset(ui, repo, opts, buffe'
987 def finddate(ui, repo, date):
987 def finddate(ui, repo, date):
988 """Find the tipmost changeset that matches the given date spec"""
988 """Find the tipmost changeset that matches the given date spec"""
989 df = util.matchdate(date)
989 df = util.matchdate(date)
990 get = util.cachefunc(lambda r: repo[r].changeset())
990 get = util.cachefunc(lambda r: repo[r])
991 changeiter, matchfn = walkchangerevs(ui, repo, [], get, {'rev':None})
991 changeiter, matchfn = walkchangerevs(ui, repo, [], get, {'rev':None})
992 results = {}
992 results = {}
993 for st, rev, fns in changeiter:
993 for st, rev, fns in changeiter:
994 if st == 'add':
994 if st == 'add':
995 d = get(rev)[2]
995 d = get(rev).date()
996 if df(d[0]):
996 if df(d[0]):
997 results[rev] = d
997 results[rev] = d
998 elif st == 'iter':
998 elif st == 'iter':
@@ -1118,13 +1118,13 b' def walkchangerevs(ui, repo, pats, chang'
1118 def changerevgen():
1118 def changerevgen():
1119 for i, window in increasing_windows(len(repo) - 1, nullrev):
1119 for i, window in increasing_windows(len(repo) - 1, nullrev):
1120 for j in xrange(i - window, i + 1):
1120 for j in xrange(i - window, i + 1):
1121 yield j, change(j)[3]
1121 yield change(j)
1122
1122
1123 for rev, changefiles in changerevgen():
1123 for ctx in changerevgen():
1124 matches = filter(m, changefiles)
1124 matches = filter(m, ctx.files())
1125 if matches:
1125 if matches:
1126 fncache[rev] = matches
1126 fncache[ctx.rev()] = matches
1127 wanted.add(rev)
1127 wanted.add(ctx.rev())
1128
1128
1129 class followfilter(object):
1129 class followfilter(object):
1130 def __init__(self, onlyfirst=False):
1130 def __init__(self, onlyfirst=False):
@@ -1189,7 +1189,7 b' def walkchangerevs(ui, repo, pats, chang'
1189 fns = fncache.get(rev)
1189 fns = fncache.get(rev)
1190 if not fns:
1190 if not fns:
1191 def fns_generator():
1191 def fns_generator():
1192 for f in change(rev)[3]:
1192 for f in change(rev).files():
1193 if m(f):
1193 if m(f):
1194 yield f
1194 yield f
1195 fns = fns_generator()
1195 fns = fns_generator()
@@ -1275,9 +1275,9 b' def grep(ui, repo, pattern, *pats, **opt'
1275 if opts.get('all'):
1275 if opts.get('all'):
1276 cols.append(change)
1276 cols.append(change)
1277 if opts.get('user'):
1277 if opts.get('user'):
1278 cols.append(ui.shortuser(get(r)[1]))
1278 cols.append(ui.shortuser(get(r).user()))
1279 if opts.get('date'):
1279 if opts.get('date'):
1280 cols.append(datefunc(get(r)[2]))
1280 cols.append(datefunc(get(r).date()))
1281 if opts.get('files_with_matches'):
1281 if opts.get('files_with_matches'):
1282 c = (fn, r)
1282 c = (fn, r)
1283 if c in filerevmatches:
1283 if c in filerevmatches:
@@ -1291,7 +1291,7 b' def grep(ui, repo, pattern, *pats, **opt'
1291
1291
1292 skip = {}
1292 skip = {}
1293 revfiles = {}
1293 revfiles = {}
1294 get = util.cachefunc(lambda r: repo[r].changeset())
1294 get = util.cachefunc(lambda r: repo[r])
1295 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
1295 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
1296 found = False
1296 found = False
1297 follow = opts.get('follow')
1297 follow = opts.get('follow')
@@ -1300,7 +1300,7 b' def grep(ui, repo, pattern, *pats, **opt'
1300 matches.clear()
1300 matches.clear()
1301 revfiles.clear()
1301 revfiles.clear()
1302 elif st == 'add':
1302 elif st == 'add':
1303 ctx = repo[rev]
1303 ctx = get(rev)
1304 pctx = ctx.parents()[0]
1304 pctx = ctx.parents()[0]
1305 parent = pctx.rev()
1305 parent = pctx.rev()
1306 matches.setdefault(rev, {})
1306 matches.setdefault(rev, {})
@@ -1334,7 +1334,7 b' def grep(ui, repo, pattern, *pats, **opt'
1334 except error.LookupError:
1334 except error.LookupError:
1335 pass
1335 pass
1336 elif st == 'iter':
1336 elif st == 'iter':
1337 parent = repo[rev].parents()[0].rev()
1337 parent = get(rev).parents()[0].rev()
1338 for fn in sorted(revfiles.get(rev, [])):
1338 for fn in sorted(revfiles.get(rev, [])):
1339 states = matches[rev][fn]
1339 states = matches[rev][fn]
1340 copy = copies.get(rev, {}).get(fn)
1340 copy = copies.get(rev, {}).get(fn)
@@ -1982,7 +1982,7 b' def log(ui, repo, *pats, **opts):'
1982 will appear in files:.
1982 will appear in files:.
1983 """
1983 """
1984
1984
1985 get = util.cachefunc(lambda r: repo[r].changeset())
1985 get = util.cachefunc(lambda r: repo[r])
1986 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
1986 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, opts)
1987
1987
1988 limit = cmdutil.loglimit(opts)
1988 limit = cmdutil.loglimit(opts)
@@ -2040,40 +2040,37 b' def log(ui, repo, *pats, **opts):'
2040 if opts.get('only_merges') and len(parents) != 2:
2040 if opts.get('only_merges') and len(parents) != 2:
2041 continue
2041 continue
2042
2042
2043 if only_branches:
2043 ctx = get(rev)
2044 revbranch = get(rev)[5]['branch']
2044 if only_branches and ctx.branch() not in only_branches:
2045 if revbranch not in only_branches:
2046 continue
2045 continue
2047
2046
2048 if df:
2047 if df and not df(ctx.date()):
2049 changes = get(rev)
2050 if not df(changes[2][0]):
2051 continue
2048 continue
2052
2049
2053 if opts.get('keyword'):
2050 if opts.get('keyword'):
2054 changes = get(rev)
2055 miss = 0
2051 miss = 0
2056 for k in [kw.lower() for kw in opts['keyword']]:
2052 for k in [kw.lower() for kw in opts['keyword']]:
2057 if not (k in changes[1].lower() or
2053 if not (k in ctx.user().lower() or
2058 k in changes[4].lower() or
2054 k in ctx.description().lower() or
2059 k in " ".join(changes[3]).lower()):
2055 k in " ".join(ctx.files()[3]).lower()):
2060 miss = 1
2056 miss = 1
2061 break
2057 break
2062 if miss:
2058 if miss:
2063 continue
2059 continue
2064
2060
2065 if opts['user']:
2061 if opts['user']:
2066 changes = get(rev)
2062 if not [k for k in opts['user'] if k in ctx.user()]:
2067 if not [k for k in opts['user'] if k in changes[1]]:
2068 continue
2063 continue
2069
2064
2070 copies = []
2065 copies = []
2071 if opts.get('copies') and rev:
2066 if opts.get('copies') and rev:
2072 for fn in get(rev)[3]:
2067 for fn in ctx.files():
2073 rename = getrenamed(fn, rev)
2068 rename = getrenamed(fn, rev)
2074 if rename:
2069 if rename:
2075 copies.append((fn, rename[0]))
2070 copies.append((fn, rename[0]))
2076 displayer.show(context.changectx(repo, rev), copies=copies)
2071
2072 displayer.show(ctx, copies=copies)
2073
2077 elif st == 'iter':
2074 elif st == 'iter':
2078 if count == limit: break
2075 if count == limit: break
2079 if displayer.flush(rev):
2076 if displayer.flush(rev):
@@ -22,14 +22,14 b" hg grep '**test**'"
22 echo % simple
22 echo % simple
23 hg grep port port
23 hg grep port port
24 echo % all
24 echo % all
25 hg grep --all -nu port port
25 hg grep --traceback --all -nu port port
26 echo % other
26 echo % other
27 hg grep import port
27 hg grep import port
28
28
29 hg cp port port2
29 hg cp port port2
30 hg commit -m 4 -u spam -d '5 0'
30 hg commit -m 4 -u spam -d '5 0'
31 echo '% follow'
31 echo % follow
32 hg grep -f 'import$' port2
32 hg grep --traceback -f 'import$' port2
33 echo deport >> port2
33 echo deport >> port2
34 hg commit -m 5 -u eggs -d '6 0'
34 hg commit -m 5 -u eggs -d '6 0'
35 hg grep -f --all -nu port port2
35 hg grep -f --all -nu port port2
General Comments 0
You need to be logged in to leave comments. Login now