annotate hgext/churn.py @ 7172:fb1d7a42663c

Use dummy diffstat in tests and remove older diffstat workaround. This makes test-notify pass on systems without diffstat installed or where the diffstat version yields a different output.
author Thomas Arendsen Hein <thomas@intevation.de>
date Sun, 19 Oct 2008 19:03:23 +0200
parents 7e6a3bae0e8e
children b6f5490effbf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
2 #
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
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
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
5 #
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
6 # This software may be used and distributed according to the terms
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
7 # of the GNU General Public License, incorporated herein by reference.
7127
9df67ee30ef5 help: better documentation intro for a few extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7076
diff changeset
8 '''command to show certain statistics about revision history'''
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
9
7051
5f201f711932 i18n, churn: mark string for translation
Martin Geisler <mg@daimi.au.dk>
parents: 6955
diff changeset
10 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
11 from mercurial import patch, cmdutil, util, templater
4955
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
12 import os, sys
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
13 import time, datetime
4955
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
14
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
15 def get_tty_width():
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
16 if 'COLUMNS' in os.environ:
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
17 try:
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
18 return int(os.environ['COLUMNS'])
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
19 except ValueError:
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
20 pass
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
21 try:
5419
041bd297f01e churn: simplify code to get terminal width
Christian Ebert <blacktrash@gmx.net>
parents: 4955
diff changeset
22 import termios, array, fcntl
4955
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
23 for dev in (sys.stdout, sys.stdin):
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
24 try:
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
25 fd = dev.fileno()
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
26 if not os.isatty(fd):
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
27 continue
5419
041bd297f01e churn: simplify code to get terminal width
Christian Ebert <blacktrash@gmx.net>
parents: 4955
diff changeset
28 arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8)
041bd297f01e churn: simplify code to get terminal width
Christian Ebert <blacktrash@gmx.net>
parents: 4955
diff changeset
29 return array.array('h', arri)[1]
4955
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
30 except ValueError:
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
31 pass
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
32 except ImportError:
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
33 pass
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
34 return 80
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
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 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
37 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
38 try:
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 t = cmdutil.changeset_templater(ui, repo, False, None, 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
40 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
41 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
42 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
43 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
44
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 def changedlines(ui, repo, ctx1, ctx2):
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 lines = 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
47 ui.pushbuffer()
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
48 patch.diff(repo, ctx1.node(), ctx2.node())
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 diff = 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 for l in diff.split('\n'):
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
51 if (l.startswith("+") and not l.startswith("+++ ") or
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 l.startswith("-") and not l.startswith("--- ")):
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 lines += 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
54 return lines
3050
dd1a142988d3 [churn] progress meter
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3049
diff changeset
55
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
56 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
57 """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
58 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
59 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
60 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
61 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
62 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
63 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
64 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
65 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
66 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
67 ui.pushbuffer()
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 tmpl.show(changenode=ctx.node())
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 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
70
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
71 count = pct = 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
72 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
73 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
74 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
75 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
76
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 get = util.cachefunc(lambda r: repo[r].changeset())
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
78 changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, pats, get, 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
79 for st, rev, fns in changeiter:
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
80 if not st == 'add':
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
81 continue
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
82 if df and not df(get(rev)[2][0]): # doesn't match date format
3050
dd1a142988d3 [churn] progress meter
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3049
diff changeset
83 continue
3049
461573aa02ef [churn] Ignore merge csets
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3048
diff changeset
84
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
85 ctx = repo[rev]
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
86 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
87 key = amap.get(key, key) # alias remap
7070
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
88 if opts.get('changesets'):
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
89 rate[key] = rate.get(key, 0) + 1
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
90 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
91 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
92 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
93 ui.note(_('Revision %d is a merge, ignoring...\n') % (rev,))
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 continue
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
95
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
96 ctx1 = parents[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
97 lines = changedlines(ui, repo, ctx1, 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
98 rate[key] = rate.get(key, 0) + lines
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
99
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
100 if opts.get('progress'):
6759
9d2ab50803e9 churn: major refactor
Matt Mackall <mpm@selenic.com>
parents: 6750
diff changeset
101 count += 1
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
102 newpct = int(100.0 * count / max(len(repo), 1))
6759
9d2ab50803e9 churn: major refactor
Matt Mackall <mpm@selenic.com>
parents: 6750
diff changeset
103 if pct < newpct:
9d2ab50803e9 churn: major refactor
Matt Mackall <mpm@selenic.com>
parents: 6750
diff changeset
104 pct = newpct
6955
a9411e29773f i18n: mark strings for translation in churn extension
Martin Geisler <mg@daimi.au.dk>
parents: 6843
diff changeset
105 ui.write(_("\rGenerating stats: %d%%") % pct)
3050
dd1a142988d3 [churn] progress meter
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3049
diff changeset
106 sys.stdout.flush()
dd1a142988d3 [churn] progress meter
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3049
diff changeset
107
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
108 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
109 ui.write("\r")
3050
dd1a142988d3 [churn] progress meter
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3049
diff changeset
110 sys.stdout.flush()
dd1a142988d3 [churn] progress meter
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3049
diff changeset
111
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 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
113
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
114
7070
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
115 def churn(ui, repo, *pats, **opts):
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 '''Graph count of revisions grouped by template
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
117
7070
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
118 Will graph count of changed lines or revisions grouped by template or
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
119 alternatively by date, if dateformat is used. In this case it will override
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
120 template.
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
121
7070
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
122 By default statistics are counted for number of changed lines.
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
123
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
124 Examples:
6666
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6598
diff changeset
125
7070
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
126 # display count of changed lines for every committer
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
127 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
128
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
129 # display daily activity graph
7070
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
130 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
131
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
132 # display activity of developers by month
7070
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
133 hg churn -f '%Y-%m' -s -c
3223
53e843840349 Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3090
diff changeset
134
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
135 # 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
136 hg churn -f '%Y' -s
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
137
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
138 The map file format used to specify aliases is fairly simple:
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
139
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
140 <alias email> <actual email>'''
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
141 def pad(s, l):
6759
9d2ab50803e9 churn: major refactor
Matt Mackall <mpm@selenic.com>
parents: 6750
diff changeset
142 return (s + " " * l)[:l]
3223
53e843840349 Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3090
diff changeset
143
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
144 amap = {}
3045
c0be8990e819 Add revision range support
Brendan Cully <brendan@kublai.com>
parents: 3043
diff changeset
145 aliases = opts.get('aliases')
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
146 if aliases:
6759
9d2ab50803e9 churn: major refactor
Matt Mackall <mpm@selenic.com>
parents: 6750
diff changeset
147 for l in open(aliases, "r"):
9d2ab50803e9 churn: major refactor
Matt Mackall <mpm@selenic.com>
parents: 6750
diff changeset
148 l = l.strip()
9d2ab50803e9 churn: major refactor
Matt Mackall <mpm@selenic.com>
parents: 6750
diff changeset
149 alias, actual = l.split()
9d2ab50803e9 churn: major refactor
Matt Mackall <mpm@selenic.com>
parents: 6750
diff changeset
150 amap[alias] = actual
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
151
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
152 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
153 if not rate:
5588
083b6e3142a2 churn: avoid division by zero
Matt Mackall <mpm@selenic.com>
parents: 5482
diff changeset
154 return
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
155
7076
c29d3f4ed967 churn: py2.3 compatibility fix
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7070
diff changeset
156 sortfn = ((not opts.get('sort')) and (lambda a, b: cmp(b[1], a[1])) or None)
c29d3f4ed967 churn: py2.3 compatibility fix
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7070
diff changeset
157 rate.sort(sortfn)
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
158
7076
c29d3f4ed967 churn: py2.3 compatibility fix
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7070
diff changeset
159 maxcount = float(max([v for k, v in rate]))
c29d3f4ed967 churn: py2.3 compatibility fix
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7070
diff changeset
160 maxname = max([len(k) for k, v in rate])
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
161
6759
9d2ab50803e9 churn: major refactor
Matt Mackall <mpm@selenic.com>
parents: 6750
diff changeset
162 ttywidth = get_tty_width()
9d2ab50803e9 churn: major refactor
Matt Mackall <mpm@selenic.com>
parents: 6750
diff changeset
163 ui.debug(_("assuming %i character terminal\n") % ttywidth)
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
164 width = ttywidth - maxname - 2 - 6 - 2 - 2
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
165
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
166 for date, count in 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
167 print "%s %6d %s" % (pad(date, maxname), count,
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
168 "*" * int(count * width / maxcount))
6223
bab6c8f2bb1a churn: show comitter email addresses unclipped (bug 1023)
Stephen Deasey <sdeasey@gmail.com>
parents: 6212
diff changeset
169
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
170
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
171 cmdtable = {
7070
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
172 "churn":
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
173 (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
174 [('r', 'rev', [], _('count rate for the specified revision or range')),
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
175 ('d', 'date', '', _('count rate for revs matching date spec')),
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
176 ('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
177 ('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
178 _('strftime-compatible format for grouping by date')),
7070
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
179 ('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
180 ('s', 'sort', False, _('sort by key (default: sort by count)')),
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 ('', '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
182 ('', 'progress', None, _('show progress'))],
7129
7e6a3bae0e8e churn: corrected help output
Martin Geisler <mg@daimi.au.dk>
parents: 7127
diff changeset
183 _("hg churn [-d DATE] [-r REV] [--aliases FILE] [--progress] [FILE]")),
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
184 }