comparison hgext/churn.py @ 3045:c0be8990e819

Add revision range support
author Brendan Cully <brendan@kublai.com>
date Fri, 18 Aug 2006 22:08:48 -0700
parents fe0e3508ec6e
children 2a4d4aecb2b4
comparison
equal deleted inserted replaced
3043:fe0e3508ec6e 3045:c0be8990e819
10 # format: 10 # format:
11 # 11 #
12 # <alias email> <actual email> 12 # <alias email> <actual email>
13 13
14 from mercurial.demandload import * 14 from mercurial.demandload import *
15 from mercurial.i18n import gettext as _
15 demandload(globals(), 'time sys signal os') 16 demandload(globals(), 'time sys signal os')
16 demandload(globals(), 'mercurial:hg,mdiff,fancyopts,commands,ui,util,templater') 17 demandload(globals(), 'mercurial:hg,mdiff,fancyopts,commands,ui,util,templater')
17 18
18 def __gather(ui, repo, node1, node2): 19 def __gather(ui, repo, node1, node2):
19 def dirtywork(f, mmap1, mmap2): 20 def dirtywork(f, mmap1, mmap2):
67 for f in unknown: 68 for f in unknown:
68 lines += dirtywork(f, mmap1, mmap2) 69 lines += dirtywork(f, mmap1, mmap2)
69 70
70 return (who, lines) 71 return (who, lines)
71 72
72 def gather_stats(ui, repo, amap): 73 def gather_stats(ui, repo, amap, revs=None):
73 stats = {} 74 stats = {}
74 75
75 cl = repo.changelog 76 cl = repo.changelog
76 77
77 for rev in range(1,cl.count()): 78 if not revs:
79 revs = range(1, cl.count())
80
81 for rev in revs:
78 node2 = cl.node(rev) 82 node2 = cl.node(rev)
79 node1 = cl.parents(node2)[0] 83 node1 = cl.parents(node2)[0]
80 84
81 who, lines = __gather(ui, repo, node1, node2) 85 who, lines = __gather(ui, repo, node1, node2)
82 86
91 95
92 ui.note("rev %d: %d lines by %s\n" % (rev, lines, who)) 96 ui.note("rev %d: %d lines by %s\n" % (rev, lines, who))
93 97
94 return stats 98 return stats
95 99
96 def churn(ui, repo, aliases): 100 def churn(ui, repo, **opts):
97 "Graphs the number of lines changed" 101 "Graphs the number of lines changed"
98 102
99 def pad(s, l): 103 def pad(s, l):
100 if len(s) < l: 104 if len(s) < l:
101 return s + " " * (l-len(s)) 105 return s + " " * (l-len(s))
115 aliases[alias] = actual 119 aliases[alias] = actual
116 120
117 return aliases 121 return aliases
118 122
119 amap = {} 123 amap = {}
124 aliases = opts.get('aliases')
120 if aliases: 125 if aliases:
121 try: 126 try:
122 f = open(aliases,"r") 127 f = open(aliases,"r")
123 except OSError, e: 128 except OSError, e:
124 print "Error: " + e 129 print "Error: " + e
125 return 130 return
126 131
127 amap = get_aliases(f) 132 amap = get_aliases(f)
128 f.close() 133 f.close()
129 134
130 stats = gather_stats(ui, repo, amap) 135 revs = [int(r) for r in commands.revrange(ui, repo, opts['rev'])]
136 revs.sort()
137 stats = gather_stats(ui, repo, amap, revs)
131 138
132 # make a list of tuples (name, lines) and sort it in descending order 139 # make a list of tuples (name, lines) and sort it in descending order
133 ordered = stats.items() 140 ordered = stats.items()
134 ordered.sort(cmp=lambda x, y: cmp(y[1], x[1])) 141 ordered.sort(cmp=lambda x, y: cmp(y[1], x[1]))
135 142
145 graph(lines, maximum, width - 20 - 1 - 6 - 2 - 2, '*')) 152 graph(lines, maximum, width - 20 - 1 - 6 - 2 - 2, '*'))
146 153
147 cmdtable = { 154 cmdtable = {
148 "churn": 155 "churn":
149 (churn, 156 (churn,
150 [('', 'aliases', '', 'file with email aliases')], 157 [('r', 'rev', [], _('limit statistics to the specified revisions')),
151 'hg churn [-a file]'), 158 ('', 'aliases', '', _('file with email aliases'))],
159 'hg churn [-r revision range] [-a file]'),
152 } 160 }
153
154 def reposetup(ui, repo):
155 pass
156