##// END OF EJS Templates
churn: ability to display added/removed lines separately
Alexander Solovyov -
r9669:9b127e88 default
parent child Browse files
Show More
@@ -23,14 +23,15 b' def maketemplater(ui, repo, tmpl):'
23 return t
23 return t
24
24
25 def changedlines(ui, repo, ctx1, ctx2, fns):
25 def changedlines(ui, repo, ctx1, ctx2, fns):
26 lines = 0
26 added, removed = 0, 0
27 fmatch = cmdutil.matchfiles(repo, fns)
27 fmatch = cmdutil.matchfiles(repo, fns)
28 diff = ''.join(patch.diff(repo, ctx1.node(), ctx2.node(), fmatch))
28 diff = ''.join(patch.diff(repo, ctx1.node(), ctx2.node(), fmatch))
29 for l in diff.split('\n'):
29 for l in diff.split('\n'):
30 if (l.startswith("+") and not l.startswith("+++ ") or
30 if l.startswith("+") and not l.startswith("+++ "):
31 l.startswith("-") and not l.startswith("--- ")):
31 added += 1
32 lines += 1
32 elif l.startswith("-") and not l.startswith("--- "):
33 return lines
33 removed += 1
34 return (added, removed)
34
35
35 def countrate(ui, repo, amap, *pats, **opts):
36 def countrate(ui, repo, amap, *pats, **opts):
36 """Calculate stats"""
37 """Calculate stats"""
@@ -71,7 +72,7 b' def countrate(ui, repo, amap, *pats, **o'
71
72
72 ctx1 = parents[0]
73 ctx1 = parents[0]
73 lines = changedlines(ui, repo, ctx1, ctx, fns)
74 lines = changedlines(ui, repo, ctx1, ctx, fns)
74 rate[key] = rate.get(key, 0) + lines
75 rate[key] = [r + l for r, l in zip(rate.get(key, (0, 0)), lines)]
75
76
76 if opts.get('progress'):
77 if opts.get('progress'):
77 count += 1
78 count += 1
@@ -143,20 +144,35 b' def churn(ui, repo, *pats, **opts):'
143 if not rate:
144 if not rate:
144 return
145 return
145
146
146 sortkey = ((not opts.get('sort')) and (lambda x: -x[1]) or None)
147 sortkey = ((not opts.get('sort')) and (lambda x: -sum(x[1])) or None)
147 rate.sort(key=sortkey)
148 rate.sort(key=sortkey)
148
149
149 # Be careful not to have a zero maxcount (issue833)
150 # Be careful not to have a zero maxcount (issue833)
150 maxcount = float(max(v for k, v in rate)) or 1.0
151 maxcount = float(max(sum(v) for k, v in rate)) or 1.0
151 maxname = max(len(k) for k, v in rate)
152 maxname = max(len(k) for k, v in rate)
152
153
153 ttywidth = util.termwidth()
154 ttywidth = util.termwidth()
154 ui.debug("assuming %i character terminal\n" % ttywidth)
155 ui.debug("assuming %i character terminal\n" % ttywidth)
155 width = ttywidth - maxname - 2 - 6 - 2 - 2
156 width = ttywidth - maxname - 2 - 2 - 2
156
157
157 for date, count in rate:
158 if opts.get('diffstat'):
158 print "%s %6d %s" % (pad(date, maxname), count,
159 width -= 15
159 "*" * int(count * width / maxcount))
160 def format(name, (added, removed)):
161 return "%s %15s %s%s\n" % (pad(name, maxname),
162 '+%d/-%d' % (added, removed),
163 '+' * charnum(added),
164 '-' * charnum(removed))
165 else:
166 width -= 6
167 def format(name, count):
168 return "%s %6d %s\n" % (pad(name, maxname), sum(count),
169 '*' * charnum(sum(count)))
170
171 def charnum(count):
172 return int(round(count*width/maxcount))
173
174 for name, count in rate:
175 ui.write(format(name, count))
160
176
161
177
162 cmdtable = {
178 cmdtable = {
@@ -169,6 +185,7 b' cmdtable = {'
169 _('strftime-compatible format for grouping by date')),
185 _('strftime-compatible format for grouping by date')),
170 ('c', 'changesets', False, _('count rate by number of changesets')),
186 ('c', 'changesets', False, _('count rate by number of changesets')),
171 ('s', 'sort', False, _('sort by key (default: sort by count)')),
187 ('s', 'sort', False, _('sort by key (default: sort by count)')),
188 ('', 'diffstat', False, _('display added/removed lines separately')),
172 ('', 'aliases', '', _('file with email aliases')),
189 ('', 'aliases', '', _('file with email aliases')),
173 ('', 'progress', None, _('show progress'))],
190 ('', 'progress', None, _('show progress'))],
174 _("hg churn [-d DATE] [-r REV] [--aliases FILE] [--progress] [FILE]")),
191 _("hg churn [-d DATE] [-r REV] [--aliases FILE] [--progress] [FILE]")),
@@ -50,6 +50,11 b' COLUMNS=40 hg churn'
50 echo % churn by hour
50 echo % churn by hour
51 hg churn -f '%H' -s
51 hg churn -f '%H' -s
52
52
53 echo % churn with separated added/removed lines
54 hg rm d/g/f2.txt
55 hg ci -Am "removed d/g/f2.txt" -u user1 -d 14:00 d/g/f2.txt
56 hg churn --diffstat
57
53 cd ..
58 cd ..
54
59
55 # issue 833: ZeroDivisionError
60 # issue 833: ZeroDivisionError
@@ -10,7 +10,7 b' user1 3 ***************************'
10 user2 2 ******************************************
10 user2 2 ******************************************
11 % churn up to rev 2
11 % churn up to rev 2
12 user2 2 ***************************************************************
12 user2 2 ***************************************************************
13 user1 1 *******************************
13 user1 1 ********************************
14 % churn with aliases
14 % churn with aliases
15 alias3 3 **************************************************************
15 alias3 3 **************************************************************
16 alias1 3 **************************************************************
16 alias1 3 **************************************************************
@@ -24,9 +24,13 b' user3 3 ***********************'
24 user1 3 ***********************
24 user1 3 ***********************
25 user2 2 ***************
25 user2 2 ***************
26 % churn by hour
26 % churn by hour
27 06 1 ****************
27 06 1 *****************
28 09 2 *********************************
28 09 2 *********************************
29 12 4 ******************************************************************
29 12 4 ******************************************************************
30 13 1 ****************
30 13 1 *****************
31 % churn with separated added/removed lines
32 user1 +3/-1 +++++++++++++++++++++++++++++++++++++++++--------------
33 user3 +3/-0 +++++++++++++++++++++++++++++++++++++++++
34 user2 +2/-0 +++++++++++++++++++++++++++
31 adding foo
35 adding foo
32 test 0
36 test 0
General Comments 0
You need to be logged in to leave comments. Login now