comparison mercurial/commands.py @ 9655:6d7d3f849062

walkchangerevs: internalize ctx caching
author Matt Mackall <mpm@selenic.com>
date Tue, 27 Oct 2009 17:01:32 -0500
parents 96fe91be9c1e
children 2ae3758526d8
comparison
equal deleted inserted replaced
9654:96fe91be9c1e 9655:6d7d3f849062
1255 for i in xrange(alo, ahi): 1255 for i in xrange(alo, ahi):
1256 yield ('-', a[i]) 1256 yield ('-', a[i])
1257 for i in xrange(blo, bhi): 1257 for i in xrange(blo, bhi):
1258 yield ('+', b[i]) 1258 yield ('+', b[i])
1259 1259
1260 def display(fn, r, pstates, states): 1260 def display(fn, ctx, pstates, states):
1261 rev = ctx.rev()
1261 datefunc = ui.quiet and util.shortdate or util.datestr 1262 datefunc = ui.quiet and util.shortdate or util.datestr
1262 found = False 1263 found = False
1263 filerevmatches = {} 1264 filerevmatches = {}
1264 if opts.get('all'): 1265 if opts.get('all'):
1265 iter = difflinestates(pstates, states) 1266 iter = difflinestates(pstates, states)
1266 else: 1267 else:
1267 iter = [('', l) for l in states] 1268 iter = [('', l) for l in states]
1268 for change, l in iter: 1269 for change, l in iter:
1269 cols = [fn, str(r)] 1270 cols = [fn, str(rev)]
1270 if opts.get('line_number'): 1271 if opts.get('line_number'):
1271 cols.append(str(l.linenum)) 1272 cols.append(str(l.linenum))
1272 if opts.get('all'): 1273 if opts.get('all'):
1273 cols.append(change) 1274 cols.append(change)
1274 if opts.get('user'): 1275 if opts.get('user'):
1275 cols.append(ui.shortuser(get(r).user())) 1276 cols.append(ui.shortuser(ctx.user()))
1276 if opts.get('date'): 1277 if opts.get('date'):
1277 cols.append(datefunc(get(r).date())) 1278 cols.append(datefunc(ctx.date()))
1278 if opts.get('files_with_matches'): 1279 if opts.get('files_with_matches'):
1279 c = (fn, r) 1280 c = (fn, rev)
1280 if c in filerevmatches: 1281 if c in filerevmatches:
1281 continue 1282 continue
1282 filerevmatches[c] = 1 1283 filerevmatches[c] = 1
1283 else: 1284 else:
1284 cols.append(l.line) 1285 cols.append(l.line)
1286 found = True 1287 found = True
1287 return found 1288 return found
1288 1289
1289 skip = {} 1290 skip = {}
1290 revfiles = {} 1291 revfiles = {}
1291 get = util.cachefunc(lambda r: repo[r])
1292 matchfn = cmdutil.match(repo, pats, opts) 1292 matchfn = cmdutil.match(repo, pats, opts)
1293 found = False 1293 found = False
1294 follow = opts.get('follow') 1294 follow = opts.get('follow')
1295 for st, ctx, fns in cmdutil.walkchangerevs(ui, repo, matchfn, get, opts): 1295 for st, ctx, fns in cmdutil.walkchangerevs(ui, repo, matchfn, opts):
1296 if st == 'add': 1296 if st == 'add':
1297 rev = ctx.rev() 1297 rev = ctx.rev()
1298 pctx = ctx.parents()[0] 1298 pctx = ctx.parents()[0]
1299 parent = pctx.rev() 1299 parent = pctx.rev()
1300 matches.setdefault(rev, {}) 1300 matches.setdefault(rev, {})
1327 grepbody(pfn, parent, flog.read(fnode)) 1327 grepbody(pfn, parent, flog.read(fnode))
1328 except error.LookupError: 1328 except error.LookupError:
1329 pass 1329 pass
1330 elif st == 'iter': 1330 elif st == 'iter':
1331 rev = ctx.rev() 1331 rev = ctx.rev()
1332 parent = get(rev).parents()[0].rev() 1332 parent = ctx.parents()[0].rev()
1333 for fn in sorted(revfiles.get(rev, [])): 1333 for fn in sorted(revfiles.get(rev, [])):
1334 states = matches[rev][fn] 1334 states = matches[rev][fn]
1335 copy = copies.get(rev, {}).get(fn) 1335 copy = copies.get(rev, {}).get(fn)
1336 if fn in skip: 1336 if fn in skip:
1337 if copy: 1337 if copy:
1338 skip[copy] = True 1338 skip[copy] = True
1339 continue 1339 continue
1340 pstates = matches.get(parent, {}).get(copy or fn, []) 1340 pstates = matches.get(parent, {}).get(copy or fn, [])
1341 if pstates or states: 1341 if pstates or states:
1342 r = display(fn, rev, pstates, states) 1342 r = display(fn, ctx, pstates, states)
1343 found = found or r 1343 found = found or r
1344 if r and not opts.get('all'): 1344 if r and not opts.get('all'):
1345 skip[fn] = True 1345 skip[fn] = True
1346 if copy: 1346 if copy:
1347 skip[copy] = True 1347 skip[copy] = True
1977 changesets, as it will only compare the merge changeset against 1977 changesets, as it will only compare the merge changeset against
1978 its first parent. Also, only files different from BOTH parents 1978 its first parent. Also, only files different from BOTH parents
1979 will appear in files:. 1979 will appear in files:.
1980 """ 1980 """
1981 1981
1982 get = util.cachefunc(lambda r: repo[r])
1983 matchfn = cmdutil.match(repo, pats, opts) 1982 matchfn = cmdutil.match(repo, pats, opts)
1984 limit = cmdutil.loglimit(opts) 1983 limit = cmdutil.loglimit(opts)
1985 count = 0 1984 count = 0
1986 1985
1987 if opts.get('copies') and opts.get('rev'): 1986 if opts.get('copies') and opts.get('rev'):
2025 df = util.matchdate(opts["date"]) 2024 df = util.matchdate(opts["date"])
2026 2025
2027 only_branches = opts.get('only_branch') 2026 only_branches = opts.get('only_branch')
2028 2027
2029 displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn) 2028 displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn)
2030 for st, ctx, fns in cmdutil.walkchangerevs(ui, repo, matchfn, get, opts): 2029 for st, ctx, fns in cmdutil.walkchangerevs(ui, repo, matchfn, opts):
2030 rev = ctx.rev()
2031 if st == 'add': 2031 if st == 'add':
2032 rev = ctx.rev()
2033 parents = [p for p in repo.changelog.parentrevs(rev) 2032 parents = [p for p in repo.changelog.parentrevs(rev)
2034 if p != nullrev] 2033 if p != nullrev]
2035 if opts.get('no_merges') and len(parents) == 2: 2034 if opts.get('no_merges') and len(parents) == 2:
2036 continue 2035 continue
2037 if opts.get('only_merges') and len(parents) != 2: 2036 if opts.get('only_merges') and len(parents) != 2:
2067 2066
2068 displayer.show(ctx, copies=copies) 2067 displayer.show(ctx, copies=copies)
2069 2068
2070 elif st == 'iter': 2069 elif st == 'iter':
2071 if count == limit: break 2070 if count == limit: break
2072 if displayer.flush(ctx.rev()): 2071
2072 if displayer.flush(rev):
2073 count += 1 2073 count += 1
2074 2074
2075 def manifest(ui, repo, node=None, rev=None): 2075 def manifest(ui, repo, node=None, rev=None):
2076 """output the current or given revision of the project manifest 2076 """output the current or given revision of the project manifest
2077 2077