[PATCH] churn and stats commands merged

Alexander Solovyov piranha at piranha.org.ua
Wed Oct 8 16:47:08 CDT 2008


# HG changeset patch
# User Alexander Solovyov <piranha at piranha.org.ua>
# Date 1223500460 -10800
# Node ID c9c19bea93fcdcd8c8efcc6f8e435740d4d3187a
# Parent  9bc46d069a76fca828379a08cc28751885f4e2bd
churn and stats commands merged

diff --git a/hgext/churn.py b/hgext/churn.py
--- a/hgext/churn.py
+++ b/hgext/churn.py
@@ -85,7 +85,9 @@
         ctx = repo[rev]
         key = getkey(ctx)
         key = amap.get(key, key) # alias remap
-        if opts.get('lines'):
+        if opts.get('changesets'):
+            rate[key] = rate.get(key, 0) + 1
+        else:
             parents = ctx.parents()
             if len(parents) > 1:
                 ui.note(_('Revision %d is a merge, ignoring...\n') % (rev,))
@@ -94,8 +96,6 @@
             ctx1 = parents[0]
             lines = changedlines(ui, repo, ctx1, ctx)
             rate[key] = rate.get(key, 0) + lines
-        else:
-            rate[key] = rate.get(key, 0) + 1
 
         if opts.get('progress'):
             count += 1
@@ -112,28 +112,32 @@
     return rate
 
 
-def stats(ui, repo, *pats, **opts):
+def churn(ui, repo, *pats, **opts):
     '''Graph count of revisions grouped by template
 
-    Will graph count of revisions grouped by template or alternatively by
-    date, if dateformat is used. In this case it will override template.
+    Will graph count of changed lines or revisions grouped by template or
+    alternatively by date, if dateformat is used. In this case it will override
+    template.
 
-    By default statistics are counted for number of revisions.
+    By default statistics are counted for number of changed lines.
 
     Examples:
 
-      # display count of revisions for every committer
-      hg stats -t '{author|email}'
+      # display count of changed lines for every committer
+      hg churn -t '{author|email}'
 
       # display daily activity graph
-      hg stats -f '%H' -s
+      hg churn -f '%H' -s -c
 
       # display activity of developers by month
-      hg stats -f '%Y-%m' -s
+      hg churn -f '%Y-%m' -s -c
 
       # display count of lines changed in every year
-      hg stats -l -f '%Y' -s
-    '''
+      hg churn -f '%Y' -s
+
+    The map file format used to specify aliases is fairly simple:
+
+    <alias email> <actual email>'''
     def pad(s, l):
         return (s + " " * l)[:l]
 
@@ -163,32 +167,18 @@
         print "%s %6d %s" % (pad(date, maxname), count,
                              "*" * int(count * width / maxcount))
 
-def churn(ui, repo, **opts):
-    '''graphs the number of lines changed
-
-    The map file format used to specify aliases is fairly simple:
-
-    <alias email> <actual email>'''
-    stats(ui, repo, lines=True, sort=False, template='{author|email}', **opts)
-
 
 cmdtable = {
-    "stats":
-        (stats,
+    "churn":
+        (churn,
          [('r', 'rev', [], _('count rate for the specified revision or range')),
           ('d', 'date', '', _('count rate for revs matching date spec')),
           ('t', 'template', '{author|email}', _('template to group changesets')),
           ('f', 'dateformat', '',
               _('strftime-compatible format for grouping by date')),
-          ('l', 'lines', False, _('count rate by number of changed lines')),
+          ('c', 'changesets', False, _('count rate by number of changesets')),
           ('s', 'sort', False, _('sort by key (default: sort by count)')),
           ('', 'aliases', '', _('file with email aliases')),
           ('', 'progress', None, _('show progress'))],
-         _("hg stats [-d DATE] [-r REV] [FILE]")),
-    "churn":
-        (churn,
-         [('r', 'rev', [], _('limit statistics to the specified revisions')),
-          ('', 'aliases', '', _('file with email aliases')),
-          ('', 'progress', None, _('show progress'))],
-         'hg churn [-r REVISIONS] [--aliases FILE] [--progress]'),
+         _("hg stats [-d DATE] [-r REV] [--aliases FILE] [--progress] [FILE]")),
 }
diff --git a/tests/test-churn b/tests/test-churn
--- a/tests/test-churn
+++ b/tests/test-churn
@@ -9,19 +9,22 @@
 hg init repo
 cd repo
 echo a > a
-hg ci -Am adda -u user1
+hg ci -Am adda -u user1 -d 6:00
 echo b >> a
 echo b > b
-hg ci -Am addb -u user2
+hg ci -m changeba -u user2 -d 9:00 a
+hg ci -Am addb -u user2 -d 9:30
 echo c >> a
 echo c >> b
 echo c > c
-hg ci -Am addc -u user3
+hg ci -m changeca -u user3 -d 12:00 a
+hg ci -m changecb -u user3 -d 12:15 b
+hg ci -Am addc -u user3 -d 12:30
 
 echo % churn all
 hg churn
-echo % churn up to rev 1
-hg churn -r :1
+echo % churn up to rev 2
+hg churn -r :2
 echo % churn with aliases
 cat > ../aliases <<EOF
 user1 alias1
@@ -30,4 +33,6 @@
 hg churn --aliases ../aliases
 echo % churn with column specifier
 COLUMNS=40 hg churn
+echo % churn by hour
+hg churn -f '%H' -s
 
diff --git a/tests/test-churn.out b/tests/test-churn.out
--- a/tests/test-churn.out
+++ b/tests/test-churn.out
@@ -6,7 +6,7 @@
 user3      3 ***************************************************************
 user2      2 ******************************************
 user1      1 *********************
-% churn up to rev 1
+% churn up to rev 2
 user2      2 ***************************************************************
 user1      1 *******************************
 % churn with aliases
@@ -17,3 +17,7 @@
 user3      3 ***********************
 user2      2 ***************
 user1      1 *******
+% churn by hour
+06      1 **********************
+09      2 ********************************************
+12      3 ******************************************************************
diff --git a/tests/test-stats b/tests/test-stats
deleted file mode 100755
--- a/tests/test-stats
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/sh
-
-echo "[extensions]" >> $HGRCPATH
-echo "churn=" >> $HGRCPATH
-
-COLUMNS=80; export COLUMNS
-
-echo % create test repository
-hg init repo
-cd repo
-echo a > a
-hg ci -Am adda -u user1 -d 6:00
-echo b >> a
-echo b > b
-hg ci -m changeba -u user2 -d 9:00 a
-hg ci -Am addb -u user2 -d 9:30
-echo c >> a
-echo c >> b
-echo c > c
-hg ci -m changeca -u user3 -d 12:00 a
-hg ci -m changecb -u user3 -d 12:15 b
-hg ci -Am addc -u user3 -d 12:30
-
-echo % all stats
-hg stats
-echo % stats by hour
-hg stats -f '%H' -s
-echo % stats with aliases
-cat > ../aliases <<EOF
-06 09
-EOF
-hg stats -f '%H' -s --aliases ../aliases
-echo % stats with column specifier
-COLUMNS=40 hg stats -f '%Y' -s
-
diff --git a/tests/test-stats.out b/tests/test-stats.out
deleted file mode 100644
--- a/tests/test-stats.out
+++ /dev/null
@@ -1,17 +0,0 @@
-% create test repository
-adding a
-adding b
-adding c
-% all stats
-user3      3 ***************************************************************
-user2      2 ******************************************
-user1      1 *********************
-% stats by hour
-06      1 **********************
-09      2 ********************************************
-12      3 ******************************************************************
-% stats with aliases
-09      3 ******************************************************************
-12      3 ******************************************************************
-% stats with column specifier
-2008      6 ************************


More information about the Mercurial-devel mailing list