comparison hgext/churn.py @ 9662:f3d60543924f

walkchangerevs: move 'add' to callback Now walkchangerevs is a simple iterator over contexts
author Matt Mackall <mpm@selenic.com>
date Thu, 29 Oct 2009 17:07:51 -0500
parents 6d7d3f849062
children 1de5ebfa5585
comparison
equal deleted inserted replaced
9661:c4f6c02e33c4 9662:f3d60543924f
52 df = False 52 df = False
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 m = cmdutil.match(repo, pats, opts) 56 m = cmdutil.match(repo, pats, opts)
57 for st, ctx, fns in cmdutil.walkchangerevs(ui, repo, m, opts): 57 def prep(ctx, fns):
58 if not st == 'add':
59 continue
60
61 rev = ctx.rev() 58 rev = ctx.rev()
62 if df and not df(ctx.date()[0]): # doesn't match date format 59 if df and not df(ctx.date()[0]): # doesn't match date format
63 continue 60 return
64 61
65 key = getkey(ctx) 62 key = getkey(ctx)
66 key = amap.get(key, key) # alias remap 63 key = amap.get(key, key) # alias remap
67 if opts.get('changesets'): 64 if opts.get('changesets'):
68 rate[key] = rate.get(key, 0) + 1 65 rate[key] = rate.get(key, 0) + 1
69 else: 66 else:
70 parents = ctx.parents() 67 parents = ctx.parents()
71 if len(parents) > 1: 68 if len(parents) > 1:
72 ui.note(_('Revision %d is a merge, ignoring...\n') % (rev,)) 69 ui.note(_('Revision %d is a merge, ignoring...\n') % (rev,))
73 continue 70 return
74 71
75 ctx1 = parents[0] 72 ctx1 = parents[0]
76 lines = changedlines(ui, repo, ctx1, ctx, fns) 73 lines = changedlines(ui, repo, ctx1, ctx, fns)
77 rate[key] = rate.get(key, 0) + lines 74 rate[key] = rate.get(key, 0) + lines
78 75
81 newpct = int(100.0 * count / max(len(repo), 1)) 78 newpct = int(100.0 * count / max(len(repo), 1))
82 if pct < newpct: 79 if pct < newpct:
83 pct = newpct 80 pct = newpct
84 ui.write("\r" + _("generating stats: %d%%") % pct) 81 ui.write("\r" + _("generating stats: %d%%") % pct)
85 sys.stdout.flush() 82 sys.stdout.flush()
83
84 for ctx in cmdutil.walkchangerevs(ui, repo, m, opts, prep):
85 continue
86 86
87 if opts.get('progress'): 87 if opts.get('progress'):
88 ui.write("\r") 88 ui.write("\r")
89 sys.stdout.flush() 89 sys.stdout.flush()
90 90