annotate hgext/churn.py @ 35506:fa865878a849

lfs: show a friendly message when pushing lfs to a server without lfs enabled Upfront disclaimer: I don't know anything about the wire protocol, and this was pretty much cargo-culted from largefiles, and then clonebundles, since it seems more modern. I was surprised that exchange.push() will ensure all of the proper requirements when exchanging between two local repos, but doesn't care when one is remote. All this new capability marker does is inform the client that the extension is enabled remotely. It may or may not contain commits with external blobs. Open issues: - largefiles uses 'largefiles=serve' for its capability. Someday I hope to be able to push lfs blobs to an `hg serve` instance. That will probably require a distinct capability. Should it change to '=serve' then? Or just add an 'lfs-serve' capability then? - The flip side of this is more complicated. It looks like largefiles adds an 'lheads' command for the client to signal to the server that the extension is loaded. That is then converted to 'heads' and sent through the normal wire protocol plumbing. A client using the 'heads' command directly is kicked out with a message indicating that the largefiles extension must be loaded. We could do similar with 'lfsheads', but then a repo with both largefiles and lfs blobs can't be pushed over the wire. Hopefully somebody with more wire protocol experience can think of something else. I see 'x-hgarg-1' on some commands in the tests, but not on heads, and didn't dig any further.
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 23 Dec 2017 17:49:12 -0500
parents 26ed66ab1e72
children c8e2d6ed1f9e
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 #
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
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 9672
diff changeset
7 # GNU General Public License version 2 or any later version.
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
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
10
28094
79fc627578ac churn: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
11 from __future__ import absolute_import
79fc627578ac churn: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
12
79fc627578ac churn: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
13 import datetime
79fc627578ac churn: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
14 import os
79fc627578ac churn: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
15 import time
79fc627578ac churn: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
16
7051
5f201f711932 i18n, churn: mark string for translation
Martin Geisler <mg@daimi.au.dk>
parents: 6955
diff changeset
17 from mercurial.i18n import _
28094
79fc627578ac churn: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
18 from mercurial import (
79fc627578ac churn: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
19 cmdutil,
79fc627578ac churn: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
20 encoding,
79fc627578ac churn: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
21 patch,
34974
26ed66ab1e72 py3: handle keyword arguments in hgext/churn.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32837
diff changeset
22 pycompat,
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32198
diff changeset
23 registrar,
28094
79fc627578ac churn: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
24 scmutil,
79fc627578ac churn: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
25 util,
79fc627578ac churn: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26587
diff changeset
26 )
4955
9bbc0217209b churn: get current terminal width if possible
Christian Ebert <blacktrash@gmx.net>
parents: 3963
diff changeset
27
21245
75c8720092ba churn: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21163
diff changeset
28 cmdtable = {}
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32198
diff changeset
29 command = registrar.command(cmdtable)
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 28628
diff changeset
30 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
25186
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24987
diff changeset
31 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24987
diff changeset
32 # be specifying the version(s) of Mercurial they are tested with, or
80c5b2666a96 extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents: 24987
diff changeset
33 # leave the attribute unspecified.
29841
d5883fd055c6 extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents: 28628
diff changeset
34 testedwith = 'ships-with-hg-core'
16743
38caf405d010 hgext: mark all first-party extensions as such
Augie Fackler <raf@durin42.com>
parents: 16231
diff changeset
35
7870
7bcce39e8f07 Returns lines changed for paths specified as arguments correctly.
madhu@madhu
parents: 7762
diff changeset
36 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
37 added, removed = 0, 0
14322
a90131b85fd8 scmutil: drop aliases in cmdutil for match functions
Matt Mackall <mpm@selenic.com>
parents: 14040
diff changeset
38 fmatch = scmutil.matchfiles(repo, fns)
7870
7bcce39e8f07 Returns lines changed for paths specified as arguments correctly.
madhu@madhu
parents: 7762
diff changeset
39 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
40 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
41 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
42 added += 1
9b127e888640 churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9665
diff changeset
43 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
44 removed += 1
9b127e888640 churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9665
diff changeset
45 return (added, removed)
3050
dd1a142988d3 [churn] progress meter
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3049
diff changeset
46
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
47 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
48 """Calculate stats"""
34974
26ed66ab1e72 py3: handle keyword arguments in hgext/churn.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32837
diff changeset
49 opts = pycompat.byteskwargs(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
50 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
51 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
52 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
53 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
54 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
55 else:
24139
73b3218bb078 churn: deprecate -t option in favour of -T
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 23091
diff changeset
56 tmpl = opts.get('oldtemplate') or opts.get('template')
32837
50586a0a946f cmdutil: factor out helper to create changeset_templater with literal template
Yuya Nishihara <yuya@tcha.org>
parents: 32375
diff changeset
57 tmpl = cmdutil.makelogtemplater(ui, repo, tmpl)
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
58 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
59 ui.pushbuffer()
7369
87158be081b8 cmdutil: use change contexts for cset-printer and cset-templater
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 7308
diff changeset
60 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
61 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
62
10647
4ba41eebb3a8 churn: use ui.progress instead of --progress
Eric Eisner <ede@mit.edu>
parents: 10282
diff changeset
63 state = {'count': 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
64 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
65 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
66 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
67 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
68
14671
35c2cc322ba8 scmutil: switch match users to supplying contexts
Matt Mackall <mpm@selenic.com>
parents: 14322
diff changeset
69 m = scmutil.match(repo[None], pats, opts)
9662
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9655
diff changeset
70 def prep(ctx, fns):
9654
96fe91be9c1e walkchangerevs: yield contexts
Matt Mackall <mpm@selenic.com>
parents: 9652
diff changeset
71 rev = ctx.rev()
9367
1ef630452e0b cmdutil: use context objects for walkchangerevs()
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 9321
diff changeset
72 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
73 return
3049
461573aa02ef [churn] Ignore merge csets
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3048
diff changeset
74
14040
9d2be7e17fc1 churn: strip key earlier to avoid false negative seach in aliases
Alexander Solovyov <alexander@solovyov.net>
parents: 13123
diff changeset
75 key = getkey(ctx).strip()
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
76 key = amap.get(key, key) # alias remap
7070
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
77 if opts.get('changesets'):
9670
7d56b6ffef72 churn: fix changeset count (broken by 9b127e888640)
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9669
diff changeset
78 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
79 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
80 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
81 if len(parents) > 1:
16924
21b12b22c024 churn: lowercase message
Martin Geisler <mg@aragost.com>
parents: 16743
diff changeset
82 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
83 return
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
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 ctx1 = parents[0]
7870
7bcce39e8f07 Returns lines changed for paths specified as arguments correctly.
madhu@madhu
parents: 7762
diff changeset
86 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
87 rate[key] = [r + l for r, l in zip(rate.get(key, (0, 0)), lines)]
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
88
10647
4ba41eebb3a8 churn: use ui.progress instead of --progress
Eric Eisner <ede@mit.edu>
parents: 10282
diff changeset
89 state['count'] += 1
28472
70d3dc05e118 churn: specify unit for ui.progress when analyzing revisions
Anton Shestakov <av6@dwimlabs.net>
parents: 28094
diff changeset
90 ui.progress(_('analyzing'), state['count'], total=len(repo),
70d3dc05e118 churn: specify unit for ui.progress when analyzing revisions
Anton Shestakov <av6@dwimlabs.net>
parents: 28094
diff changeset
91 unit=_('revisions'))
3050
dd1a142988d3 [churn] progress meter
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3049
diff changeset
92
9665
1de5ebfa5585 walkchangerevs: drop ui arg
Matt Mackall <mpm@selenic.com>
parents: 9662
diff changeset
93 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
94 continue
f3d60543924f walkchangerevs: move 'add' to callback
Matt Mackall <mpm@selenic.com>
parents: 9655
diff changeset
95
10700
b2b71c304de0 progress: use a verb in present participle
Martin Geisler <mg@lazybytes.net>
parents: 10647
diff changeset
96 ui.progress(_('analyzing'), None)
3050
dd1a142988d3 [churn] progress meter
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents: 3049
diff changeset
97
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
98 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
99
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
21245
75c8720092ba churn: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21163
diff changeset
101 @command('churn',
75c8720092ba churn: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21163
diff changeset
102 [('r', 'rev', [],
23091
8d43c6bb38c0 doc: change 'revision or range' to 'revision or revset'
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 21779
diff changeset
103 _('count rate for the specified revision or revset'), _('REV')),
21245
75c8720092ba churn: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21163
diff changeset
104 ('d', 'date', '',
75c8720092ba churn: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21163
diff changeset
105 _('count rate for revisions matching date spec'), _('DATE')),
24139
73b3218bb078 churn: deprecate -t option in favour of -T
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 23091
diff changeset
106 ('t', 'oldtemplate', '',
73b3218bb078 churn: deprecate -t option in favour of -T
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 23091
diff changeset
107 _('template to group changesets (DEPRECATED)'), _('TEMPLATE')),
73b3218bb078 churn: deprecate -t option in favour of -T
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 23091
diff changeset
108 ('T', 'template', '{author|email}',
21245
75c8720092ba churn: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21163
diff changeset
109 _('template to group changesets'), _('TEMPLATE')),
75c8720092ba churn: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21163
diff changeset
110 ('f', 'dateformat', '',
75c8720092ba churn: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21163
diff changeset
111 _('strftime-compatible format for grouping by date'), _('FORMAT')),
75c8720092ba churn: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21163
diff changeset
112 ('c', 'changesets', False, _('count rate by number of changesets')),
75c8720092ba churn: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21163
diff changeset
113 ('s', 'sort', False, _('sort by key (default: sort by count)')),
75c8720092ba churn: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21163
diff changeset
114 ('', 'diffstat', False, _('display added/removed lines separately')),
75c8720092ba churn: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21163
diff changeset
115 ('', 'aliases', '', _('file with email aliases'), _('FILE')),
32375
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32337
diff changeset
116 ] + cmdutil.walkopts,
21779
a57deb45c744 churn: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21245
diff changeset
117 _("hg churn [-d DATE] [-r REV] [--aliases FILE] [FILE]"),
a57deb45c744 churn: define inferrepo in command decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21245
diff changeset
118 inferrepo=True)
7070
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
119 def churn(ui, repo, *pats, **opts):
8823
d9f4c182aeca churn: improve description
Cédric Duval <cedricduval@free.fr>
parents: 8254
diff changeset
120 '''histogram of changes to the repository
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
121
8823
d9f4c182aeca churn: improve description
Cédric Duval <cedricduval@free.fr>
parents: 8254
diff changeset
122 This command will display a histogram representing the number
d9f4c182aeca churn: improve description
Cédric Duval <cedricduval@free.fr>
parents: 8254
diff changeset
123 of changed lines or revisions, grouped according to the given
d9f4c182aeca churn: improve description
Cédric Duval <cedricduval@free.fr>
parents: 8254
diff changeset
124 template. The default template will group changes by author.
d9f4c182aeca churn: improve description
Cédric Duval <cedricduval@free.fr>
parents: 8254
diff changeset
125 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
126 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
127
8823
d9f4c182aeca churn: improve description
Cédric Duval <cedricduval@free.fr>
parents: 8254
diff changeset
128 Statistics are based on the number of changed lines, or
d9f4c182aeca churn: improve description
Cédric Duval <cedricduval@free.fr>
parents: 8254
diff changeset
129 alternatively the number of matching revisions if the
d9f4c182aeca churn: improve description
Cédric Duval <cedricduval@free.fr>
parents: 8254
diff changeset
130 --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
131
9205
83132980e9cd churn: use reST syntax for literal blocks
Martin Geisler <mg@lazybytes.net>
parents: 9056
diff changeset
132 Examples::
6666
53465a7464e2 convert comments to docstrings in a bunch of extensions
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6598
diff changeset
133
7070
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
134 # display count of changed lines for every committer
32198
a0e46f6b248b churn: use the non-deprecated template option in the examples
Matt Harbison <matt_harbison@yahoo.com>
parents: 29841
diff changeset
135 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
136
9bc46d069a76 churn: generalisation, now it is possible to see statistics grouped by custom template
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7051
diff changeset
137 # display daily activity graph
19959
9ef92384415c doc: use double quotation mark to quote arguments in examples for Windows users
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19464
diff changeset
138 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
139
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
140 # display activity of developers by month
19959
9ef92384415c doc: use double quotation mark to quote arguments in examples for Windows users
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19464
diff changeset
141 hg churn -f "%Y-%m" -s -c
3223
53e843840349 Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3090
diff changeset
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 # display count of lines changed in every year
19959
9ef92384415c doc: use double quotation mark to quote arguments in examples for Windows users
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 19464
diff changeset
144 hg churn -f "%Y" -s
7070
2627ef59195d churn and stats commands merged
Alexander Solovyov <piranha@piranha.org.ua>
parents: 7065
diff changeset
145
8823
d9f4c182aeca churn: improve description
Cédric Duval <cedricduval@free.fr>
parents: 8254
diff changeset
146 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
147 by providing a file using the following format::
8843
eb7b247a98ea kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8823
diff changeset
148
11264
30c620e48d1c churn: support spaces in aliases (issue2222)
Alexander Solovyov <piranha@piranha.org.ua>
parents: 10905
diff changeset
149 <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
150
9254
db13255617b3 churn: wrap docstrings at 70 characters
Martin Geisler <mg@lazybytes.net>
parents: 9205
diff changeset
151 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
152 a .hgchurn file will be looked for in the working directory root.
19464
68f7129af6a8 churn: split email aliases from the right
Matthew Turk <matthewturk@gmail.com>
parents: 18369
diff changeset
153 Aliases will be split from the rightmost "=".
8254
f108e89400d8 churn: use .hgchurn in repo root as default map file
Martin Geisler <mg@lazybytes.net>
parents: 8228
diff changeset
154 '''
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
155 def pad(s, l):
21163
9846b40d01e7 churn: compute padding with unicode strings
Isaac Jurado <diptongo@gmail.com>
parents: 20667
diff changeset
156 return s + " " * (l - encoding.colwidth(s))
3223
53e843840349 Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents: 3090
diff changeset
157
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
158 amap = {}
34974
26ed66ab1e72 py3: handle keyword arguments in hgext/churn.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32837
diff changeset
159 aliases = opts.get(r'aliases')
8254
f108e89400d8 churn: use .hgchurn in repo root as default map file
Martin Geisler <mg@lazybytes.net>
parents: 8228
diff changeset
160 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
161 aliases = repo.wjoin('.hgchurn')
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
162 if aliases:
6759
9d2ab50803e9 churn: major refactor
Matt Mackall <mpm@selenic.com>
parents: 6750
diff changeset
163 for l in open(aliases, "r"):
12069
7c3c44413bc1 churn: do not crash on malformed lines in alias file
Martin Geisler <mg@lazybytes.net>
parents: 12068
diff changeset
164 try:
19464
68f7129af6a8 churn: split email aliases from the right
Matthew Turk <matthewturk@gmail.com>
parents: 18369
diff changeset
165 alias, actual = l.rsplit('=' in l and '=' or None, 1)
12069
7c3c44413bc1 churn: do not crash on malformed lines in alias file
Martin Geisler <mg@lazybytes.net>
parents: 12068
diff changeset
166 amap[alias.strip()] = actual.strip()
7c3c44413bc1 churn: do not crash on malformed lines in alias file
Martin Geisler <mg@lazybytes.net>
parents: 12068
diff changeset
167 except ValueError:
7c3c44413bc1 churn: do not crash on malformed lines in alias file
Martin Geisler <mg@lazybytes.net>
parents: 12068
diff changeset
168 l = l.strip()
7c3c44413bc1 churn: do not crash on malformed lines in alias file
Martin Geisler <mg@lazybytes.net>
parents: 12068
diff changeset
169 if l:
16231
ce292f1379ba i18n: fix all remaining uses of % inside _()
Matt Mackall <mpm@selenic.com>
parents: 14671
diff changeset
170 ui.warn(_("skipping malformed alias: %s\n") % l)
12068
2e7647d25458 churn: do not crash on empty lines in alias file
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 11321
diff changeset
171 continue
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
172
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
173 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
174 if not rate:
5588
083b6e3142a2 churn: avoid division by zero
Matt Mackall <mpm@selenic.com>
parents: 5482
diff changeset
175 return
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
176
34974
26ed66ab1e72 py3: handle keyword arguments in hgext/churn.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32837
diff changeset
177 if opts.get(r'sort'):
18369
2150e70c0ee1 churn: sort users with same churn by name
Mads Kiilerich <mads@kiilerich.com>
parents: 17773
diff changeset
178 rate.sort()
2150e70c0ee1 churn: sort users with same churn by name
Mads Kiilerich <mads@kiilerich.com>
parents: 17773
diff changeset
179 else:
2150e70c0ee1 churn: sort users with same churn by name
Mads Kiilerich <mads@kiilerich.com>
parents: 17773
diff changeset
180 rate.sort(key=lambda x: (-sum(x[1]), x))
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
9388
f7968bba2307 churn: issue833 was reintroduced in 9bc46d069a76, correct it and add a test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 8934
diff changeset
182 # 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
183 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
184 maxname = max(len(k) for k, v in rate)
3040
f74077473b36 Churn extension
Josef "Jeff" Sipek <jeff@josefsipek.net>
parents:
diff changeset
185
12689
c52c629ce19e termwidth: move to ui.ui from util
Augie Fackler <durin42@gmail.com>
parents: 12070
diff changeset
186 ttywidth = ui.termwidth()
9467
4c041f1ee1b4 do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents: 9390
diff changeset
187 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
188 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
189
34974
26ed66ab1e72 py3: handle keyword arguments in hgext/churn.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32837
diff changeset
190 if opts.get(r'diffstat'):
9669
9b127e888640 churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9665
diff changeset
191 width -= 15
11501
deb5d02ae91c churn: remove tuple parameter unpacking (deprecated in py3k)
Renato Cunha <renatoc@gmail.com>
parents: 11321
diff changeset
192 def format(name, diffstat):
deb5d02ae91c churn: remove tuple parameter unpacking (deprecated in py3k)
Renato Cunha <renatoc@gmail.com>
parents: 11321
diff changeset
193 added, removed = diffstat
11310
ac873ecfc3c2 Backed out changeset: e1dde7363601
Steve Borho <steve@borho.org>
parents: 11302
diff changeset
194 return "%s %15s %s%s\n" % (pad(name, maxname),
ac873ecfc3c2 Backed out changeset: e1dde7363601
Steve Borho <steve@borho.org>
parents: 11302
diff changeset
195 '+%d/-%d' % (added, removed),
10821
a6ac91c313af churn: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents: 10700
diff changeset
196 ui.label('+' * charnum(added),
a6ac91c313af churn: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents: 10700
diff changeset
197 'diffstat.inserted'),
a6ac91c313af churn: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents: 10700
diff changeset
198 ui.label('-' * charnum(removed),
a6ac91c313af churn: make use of output labeling
Brodie Rao <brodie@bitheap.org>
parents: 10700
diff changeset
199 'diffstat.deleted'))
9669
9b127e888640 churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9665
diff changeset
200 else:
9b127e888640 churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9665
diff changeset
201 width -= 6
9b127e888640 churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9665
diff changeset
202 def format(name, count):
11310
ac873ecfc3c2 Backed out changeset: e1dde7363601
Steve Borho <steve@borho.org>
parents: 11302
diff changeset
203 return "%s %6d %s\n" % (pad(name, maxname), sum(count),
ac873ecfc3c2 Backed out changeset: e1dde7363601
Steve Borho <steve@borho.org>
parents: 11302
diff changeset
204 '*' * charnum(sum(count)))
9669
9b127e888640 churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9665
diff changeset
205
9b127e888640 churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9665
diff changeset
206 def charnum(count):
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10263
diff changeset
207 return int(round(count * width / maxcount))
9669
9b127e888640 churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9665
diff changeset
208
9b127e888640 churn: ability to display added/removed lines separately
Alexander Solovyov <piranha@piranha.org.ua>
parents: 9665
diff changeset
209 for name, count in rate:
11310
ac873ecfc3c2 Backed out changeset: e1dde7363601
Steve Borho <steve@borho.org>
parents: 11302
diff changeset
210 ui.write(format(name, count))