Mercurial > hg
annotate hgext/churn.py @ 9801:8b7d4ab33b2b
merge with hg-stable
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Sun, 08 Nov 2009 18:18:46 +0100 |
parents | 5bbf4f130684 |
children | 25e572394f5c |
rev | line source |
---|---|
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
1 # churn.py - create a graph of revisions count grouped by template |
3040 | 2 # |
3 # Copyright 2006 Josef "Jeff" Sipek <jeffpc@josefsipek.net> | |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
4 # Copyright 2008 Alexander Solovyov <piranha@piranha.org.ua> |
3040 | 5 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8085
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8085
diff
changeset
|
7 # GNU General Public License version 2, incorporated herein by reference. |
8228
eee2319c5895
add blank line after copyright notices and after header
Martin Geisler <mg@lazybytes.net>
parents:
8225
diff
changeset
|
8 |
8934
9dda4c73fc3b
extensions: change descriptions for extensions providing a few commands
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8894
diff
changeset
|
9 '''command to display statistics about repository history''' |
3040 | 10 |
7051
5f201f711932
i18n, churn: mark string for translation
Martin Geisler <mg@daimi.au.dk>
parents:
6955
diff
changeset
|
11 from mercurial.i18n import _ |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
12 from mercurial import patch, cmdutil, util, templater |
8254
f108e89400d8
churn: use .hgchurn in repo root as default map file
Martin Geisler <mg@lazybytes.net>
parents:
8228
diff
changeset
|
13 import sys, os |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
14 import time, datetime |
4955
9bbc0217209b
churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents:
3963
diff
changeset
|
15 |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
16 def maketemplater(ui, repo, tmpl): |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
17 tmpl = templater.parsestring(tmpl, quoted=False) |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
18 try: |
7762
fece056bf240
add --git option to commands supporting --patch (log, incoming, history, tip)
Jim Correia <jim.correia@pobox.com>
parents:
7626
diff
changeset
|
19 t = cmdutil.changeset_templater(ui, repo, False, None, None, False) |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
20 except SyntaxError, inst: |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
21 raise util.Abort(inst.args[0]) |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
22 t.use_template(tmpl) |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
23 return t |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
24 |
7870
7bcce39e8f07
Returns lines changed for paths specified as arguments correctly.
madhu@madhu
parents:
7762
diff
changeset
|
25 def changedlines(ui, repo, ctx1, ctx2, fns): |
9669
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
26 added, removed = 0, 0 |
9321
d7b6429c5ad4
churn: correct output when run in subdirectories
Brendan Cully <brendan@kublai.com>
parents:
9254
diff
changeset
|
27 fmatch = cmdutil.matchfiles(repo, fns) |
7870
7bcce39e8f07
Returns lines changed for paths specified as arguments correctly.
madhu@madhu
parents:
7762
diff
changeset
|
28 diff = ''.join(patch.diff(repo, ctx1.node(), ctx2.node(), fmatch)) |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
29 for l in diff.split('\n'): |
9669
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
30 if l.startswith("+") and not l.startswith("+++ "): |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
31 added += 1 |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
32 elif l.startswith("-") and not l.startswith("--- "): |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
33 removed += 1 |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
34 return (added, removed) |
3050
dd1a142988d3
[churn] progress meter
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
3049
diff
changeset
|
35 |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
36 def countrate(ui, repo, amap, *pats, **opts): |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
37 """Calculate stats""" |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
38 if opts.get('dateformat'): |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
39 def getkey(ctx): |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
40 t, tz = ctx.date() |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
41 date = datetime.datetime(*time.gmtime(float(t) - tz)[:6]) |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
42 return date.strftime(opts['dateformat']) |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
43 else: |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
44 tmpl = opts.get('template', '{author|email}') |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
45 tmpl = maketemplater(ui, repo, tmpl) |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
46 def getkey(ctx): |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
47 ui.pushbuffer() |
7369
87158be081b8
cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
7308
diff
changeset
|
48 tmpl.show(ctx) |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
49 return ui.popbuffer() |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
50 |
9672
5bbf4f130684
churn: fix --progress (broken by f3d60543924f)
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9670
diff
changeset
|
51 state = {'count': 0, 'pct': 0} |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
52 rate = {} |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
53 df = False |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
54 if opts.get('date'): |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
55 df = util.matchdate(opts['date']) |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
56 |
9652
2cb0cab10d2e
walkchangerevs: pull out matchfn
Matt Mackall <mpm@selenic.com>
parents:
9569
diff
changeset
|
57 m = cmdutil.match(repo, pats, opts) |
9662
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9655
diff
changeset
|
58 def prep(ctx, fns): |
9654
96fe91be9c1e
walkchangerevs: yield contexts
Matt Mackall <mpm@selenic.com>
parents:
9652
diff
changeset
|
59 rev = ctx.rev() |
9367
1ef630452e0b
cmdutil: use context objects for walkchangerevs()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9321
diff
changeset
|
60 if df and not df(ctx.date()[0]): # doesn't match date format |
9662
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9655
diff
changeset
|
61 return |
3049
461573aa02ef
[churn] Ignore merge csets
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
3048
diff
changeset
|
62 |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
63 key = getkey(ctx) |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
64 key = amap.get(key, key) # alias remap |
7070
2627ef59195d
churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7065
diff
changeset
|
65 if opts.get('changesets'): |
9670
7d56b6ffef72
churn: fix changeset count (broken by 9b127e888640)
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9669
diff
changeset
|
66 rate[key] = (rate.get(key, (0,))[0] + 1, 0) |
7070
2627ef59195d
churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7065
diff
changeset
|
67 else: |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
68 parents = ctx.parents() |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
69 if len(parents) > 1: |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
70 ui.note(_('Revision %d is a merge, ignoring...\n') % (rev,)) |
9662
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9655
diff
changeset
|
71 return |
3040 | 72 |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
73 ctx1 = parents[0] |
7870
7bcce39e8f07
Returns lines changed for paths specified as arguments correctly.
madhu@madhu
parents:
7762
diff
changeset
|
74 lines = changedlines(ui, repo, ctx1, ctx, fns) |
9669
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
75 rate[key] = [r + l for r, l in zip(rate.get(key, (0, 0)), lines)] |
3040 | 76 |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
77 if opts.get('progress'): |
9672
5bbf4f130684
churn: fix --progress (broken by f3d60543924f)
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9670
diff
changeset
|
78 state['count'] += 1 |
5bbf4f130684
churn: fix --progress (broken by f3d60543924f)
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9670
diff
changeset
|
79 newpct = int(100.0 * state['count'] / max(len(repo), 1)) |
5bbf4f130684
churn: fix --progress (broken by f3d60543924f)
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9670
diff
changeset
|
80 if state['pct'] < newpct: |
5bbf4f130684
churn: fix --progress (broken by f3d60543924f)
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9670
diff
changeset
|
81 state['pct'] = newpct |
5bbf4f130684
churn: fix --progress (broken by f3d60543924f)
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9670
diff
changeset
|
82 ui.write("\r" + _("generating stats: %d%%") % state['pct']) |
3050
dd1a142988d3
[churn] progress meter
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
3049
diff
changeset
|
83 sys.stdout.flush() |
dd1a142988d3
[churn] progress meter
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
3049
diff
changeset
|
84 |
9665
1de5ebfa5585
walkchangerevs: drop ui arg
Matt Mackall <mpm@selenic.com>
parents:
9662
diff
changeset
|
85 for ctx in cmdutil.walkchangerevs(repo, m, opts, prep): |
9662
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9655
diff
changeset
|
86 continue |
f3d60543924f
walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents:
9655
diff
changeset
|
87 |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
88 if opts.get('progress'): |
5989
a7817ad608ea
added \r for progress counting in churn extension
Armin Ronacher <armin.ronacher@active-4.com>
parents:
5976
diff
changeset
|
89 ui.write("\r") |
3050
dd1a142988d3
[churn] progress meter
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
3049
diff
changeset
|
90 sys.stdout.flush() |
dd1a142988d3
[churn] progress meter
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
3049
diff
changeset
|
91 |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
92 return rate |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
93 |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
94 |
7070
2627ef59195d
churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7065
diff
changeset
|
95 def churn(ui, repo, *pats, **opts): |
8823
d9f4c182aeca
churn: improve description
Cédric Duval <cedricduval@free.fr>
parents:
8254
diff
changeset
|
96 '''histogram of changes to the repository |
3040 | 97 |
8823
d9f4c182aeca
churn: improve description
Cédric Duval <cedricduval@free.fr>
parents:
8254
diff
changeset
|
98 This command will display a histogram representing the number |
d9f4c182aeca
churn: improve description
Cédric Duval <cedricduval@free.fr>
parents:
8254
diff
changeset
|
99 of changed lines or revisions, grouped according to the given |
d9f4c182aeca
churn: improve description
Cédric Duval <cedricduval@free.fr>
parents:
8254
diff
changeset
|
100 template. The default template will group changes by author. |
d9f4c182aeca
churn: improve description
Cédric Duval <cedricduval@free.fr>
parents:
8254
diff
changeset
|
101 The --dateformat option may be used to group the results by |
d9f4c182aeca
churn: improve description
Cédric Duval <cedricduval@free.fr>
parents:
8254
diff
changeset
|
102 date instead. |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
103 |
8823
d9f4c182aeca
churn: improve description
Cédric Duval <cedricduval@free.fr>
parents:
8254
diff
changeset
|
104 Statistics are based on the number of changed lines, or |
d9f4c182aeca
churn: improve description
Cédric Duval <cedricduval@free.fr>
parents:
8254
diff
changeset
|
105 alternatively the number of matching revisions if the |
d9f4c182aeca
churn: improve description
Cédric Duval <cedricduval@free.fr>
parents:
8254
diff
changeset
|
106 --changesets option is specified. |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
107 |
9205
83132980e9cd
churn: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents:
9056
diff
changeset
|
108 Examples:: |
6666
53465a7464e2
convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6598
diff
changeset
|
109 |
7070
2627ef59195d
churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7065
diff
changeset
|
110 # display count of changed lines for every committer |
2627ef59195d
churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7065
diff
changeset
|
111 hg churn -t '{author|email}' |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
112 |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
113 # display daily activity graph |
7070
2627ef59195d
churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7065
diff
changeset
|
114 hg churn -f '%H' -s -c |
6666
53465a7464e2
convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6598
diff
changeset
|
115 |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
116 # display activity of developers by month |
7070
2627ef59195d
churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7065
diff
changeset
|
117 hg churn -f '%Y-%m' -s -c |
3223
53e843840349
Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3090
diff
changeset
|
118 |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
119 # display count of lines changed in every year |
7070
2627ef59195d
churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7065
diff
changeset
|
120 hg churn -f '%Y' -s |
2627ef59195d
churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7065
diff
changeset
|
121 |
8823
d9f4c182aeca
churn: improve description
Cédric Duval <cedricduval@free.fr>
parents:
8254
diff
changeset
|
122 It is possible to map alternate email addresses to a main address |
9254
db13255617b3
churn: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9205
diff
changeset
|
123 by providing a file using the following format:: |
8843
eb7b247a98ea
kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8823
diff
changeset
|
124 |
9205
83132980e9cd
churn: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents:
9056
diff
changeset
|
125 <alias email> <actual email> |
8254
f108e89400d8
churn: use .hgchurn in repo root as default map file
Martin Geisler <mg@lazybytes.net>
parents:
8228
diff
changeset
|
126 |
9254
db13255617b3
churn: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9205
diff
changeset
|
127 Such a file may be specified with the --aliases option, otherwise |
db13255617b3
churn: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents:
9205
diff
changeset
|
128 a .hgchurn file will be looked for in the working directory root. |
8254
f108e89400d8
churn: use .hgchurn in repo root as default map file
Martin Geisler <mg@lazybytes.net>
parents:
8228
diff
changeset
|
129 ''' |
3040 | 130 def pad(s, l): |
6759 | 131 return (s + " " * l)[:l] |
3223
53e843840349
Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
3090
diff
changeset
|
132 |
3040 | 133 amap = {} |
3045
c0be8990e819
Add revision range support
Brendan Cully <brendan@kublai.com>
parents:
3043
diff
changeset
|
134 aliases = opts.get('aliases') |
8254
f108e89400d8
churn: use .hgchurn in repo root as default map file
Martin Geisler <mg@lazybytes.net>
parents:
8228
diff
changeset
|
135 if not aliases and os.path.exists(repo.wjoin('.hgchurn')): |
f108e89400d8
churn: use .hgchurn in repo root as default map file
Martin Geisler <mg@lazybytes.net>
parents:
8228
diff
changeset
|
136 aliases = repo.wjoin('.hgchurn') |
3040 | 137 if aliases: |
6759 | 138 for l in open(aliases, "r"): |
139 l = l.strip() | |
140 alias, actual = l.split() | |
141 amap[alias] = actual | |
3040 | 142 |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
143 rate = countrate(ui, repo, amap, *pats, **opts).items() |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
144 if not rate: |
5588
083b6e3142a2
churn: avoid division by zero
Matt Mackall <mpm@selenic.com>
parents:
5482
diff
changeset
|
145 return |
3040 | 146 |
9669
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
147 sortkey = ((not opts.get('sort')) and (lambda x: -sum(x[1])) or None) |
9032
1fa80c5428b8
compat: use 'key' argument instead of 'cmp' when sorting a list
Alejandro Santos <alejolp@alejolp.com>
parents:
8934
diff
changeset
|
148 rate.sort(key=sortkey) |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
149 |
9388
f7968bba2307
churn: issue833 was reintroduced in 9bc46d069a76, correct it and add a test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
8934
diff
changeset
|
150 # Be careful not to have a zero maxcount (issue833) |
9669
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
151 maxcount = float(max(sum(v) for k, v in rate)) or 1.0 |
9390
637f2726ec7f
churn: use genexps now that we dropped 2.3 compatibility
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9389
diff
changeset
|
152 maxname = max(len(k) for k, v in rate) |
3040 | 153 |
7547
4949729ee9ee
python implementation of diffstat
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7369
diff
changeset
|
154 ttywidth = util.termwidth() |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9390
diff
changeset
|
155 ui.debug("assuming %i character terminal\n" % ttywidth) |
9669
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
156 width = ttywidth - maxname - 2 - 2 - 2 |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
157 |
9669
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
158 if opts.get('diffstat'): |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
159 width -= 15 |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
160 def format(name, (added, removed)): |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
161 return "%s %15s %s%s\n" % (pad(name, maxname), |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
162 '+%d/-%d' % (added, removed), |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
163 '+' * charnum(added), |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
164 '-' * charnum(removed)) |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
165 else: |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
166 width -= 6 |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
167 def format(name, count): |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
168 return "%s %6d %s\n" % (pad(name, maxname), sum(count), |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
169 '*' * charnum(sum(count))) |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
170 |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
171 def charnum(count): |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
172 return int(round(count*width/maxcount)) |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
173 |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
174 for name, count in rate: |
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
175 ui.write(format(name, count)) |
6223
bab6c8f2bb1a
churn: show comitter email addresses unclipped (bug 1023)
Stephen Deasey <sdeasey@gmail.com>
parents:
6212
diff
changeset
|
176 |
3040 | 177 |
178 cmdtable = { | |
7070
2627ef59195d
churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7065
diff
changeset
|
179 "churn": |
2627ef59195d
churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7065
diff
changeset
|
180 (churn, |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
181 [('r', 'rev', [], _('count rate for the specified revision or range')), |
8028
3aaca5901ade
expand "rev" to "revision" in help texts
Martin Geisler <mg@lazybytes.net>
parents:
7987
diff
changeset
|
182 ('d', 'date', '', _('count rate for revisions matching date spec')), |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
183 ('t', 'template', '{author|email}', _('template to group changesets')), |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
184 ('f', 'dateformat', '', |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
185 _('strftime-compatible format for grouping by date')), |
7070
2627ef59195d
churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7065
diff
changeset
|
186 ('c', 'changesets', False, _('count rate by number of changesets')), |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
187 ('s', 'sort', False, _('sort by key (default: sort by count)')), |
9669
9b127e888640
churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents:
9665
diff
changeset
|
188 ('', 'diffstat', False, _('display added/removed lines separately')), |
7065
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
189 ('', 'aliases', '', _('file with email aliases')), |
9bc46d069a76
churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents:
7051
diff
changeset
|
190 ('', 'progress', None, _('show progress'))], |
7129
7e6a3bae0e8e
churn: corrected help output
Martin Geisler <mg@daimi.au.dk>
parents:
7127
diff
changeset
|
191 _("hg churn [-d DATE] [-r REV] [--aliases FILE] [--progress] [FILE]")), |
3040 | 192 } |