Patchwork [04,of,35] churn: declare command using decorator

login
register
mail settings
Submitter Gregory Szorc
Date May 5, 2014, 5:51 a.m.
Message ID <e091bbd5a74696294672.1399269069@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4595/
State Accepted
Commit 75c8720092bad9e9de5abef9404246d75bb239fe
Headers show

Comments

Gregory Szorc - May 5, 2014, 5:51 a.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1399265184 25200
#      Sun May 04 21:46:24 2014 -0700
# Branch stable
# Node ID e091bbd5a746962946723485c099310dfa9fece0
# Parent  80930eaa89d13d73063412ec2843034c8058a684
churn: declare command using decorator

Patch

diff --git a/hgext/churn.py b/hgext/churn.py
--- a/hgext/churn.py
+++ b/hgext/churn.py
@@ -9,16 +9,18 @@ 
 '''command to display statistics about repository history'''
 
 from mercurial.i18n import _
 from mercurial import patch, cmdutil, scmutil, util, templater, commands
 from mercurial import encoding
 import os
 import time, datetime
 
+cmdtable = {}
+command = cmdutil.command(cmdtable)
 testedwith = 'internal'
 
 def maketemplater(ui, repo, tmpl):
     tmpl = templater.parsestring(tmpl, quoted=False)
     try:
         t = cmdutil.changeset_templater(ui, repo, False, None, tmpl,
                                         None, False)
     except SyntaxError, inst:
@@ -83,16 +85,31 @@  def countrate(ui, repo, amap, *pats, **o
     for ctx in cmdutil.walkchangerevs(repo, m, opts, prep):
         continue
 
     ui.progress(_('analyzing'), None)
 
     return rate
 
 
+@command('churn',
+    [('r', 'rev', [],
+     _('count rate for the specified revision or range'), _('REV')),
+    ('d', 'date', '',
+     _('count rate for revisions matching date spec'), _('DATE')),
+    ('t', 'template', '{author|email}',
+     _('template to group changesets'), _('TEMPLATE')),
+    ('f', 'dateformat', '',
+     _('strftime-compatible format for grouping by date'), _('FORMAT')),
+    ('c', 'changesets', False, _('count rate by number of changesets')),
+    ('s', 'sort', False, _('sort by key (default: sort by count)')),
+    ('', 'diffstat', False, _('display added/removed lines separately')),
+    ('', 'aliases', '', _('file with email aliases'), _('FILE')),
+    ] + commands.walkopts,
+    _("hg churn [-d DATE] [-r REV] [--aliases FILE] [FILE]"))
 def churn(ui, repo, *pats, **opts):
     '''histogram of changes to the repository
 
     This command will display a histogram representing the number
     of changed lines or revisions, grouped according to the given
     template. The default template will group changes by author.
     The --dateformat option may be used to group the results by
     date instead.
@@ -176,30 +193,9 @@  def churn(ui, repo, *pats, **opts):
                                     '*' * charnum(sum(count)))
 
     def charnum(count):
         return int(round(count * width / maxcount))
 
     for name, count in rate:
         ui.write(format(name, count))
 
-
-cmdtable = {
-    "churn":
-        (churn,
-         [('r', 'rev', [],
-           _('count rate for the specified revision or range'), _('REV')),
-          ('d', 'date', '',
-           _('count rate for revisions matching date spec'), _('DATE')),
-          ('t', 'template', '{author|email}',
-           _('template to group changesets'), _('TEMPLATE')),
-          ('f', 'dateformat', '',
-           _('strftime-compatible format for grouping by date'), _('FORMAT')),
-          ('c', 'changesets', False, _('count rate by number of changesets')),
-          ('s', 'sort', False, _('sort by key (default: sort by count)')),
-          ('', 'diffstat', False, _('display added/removed lines separately')),
-          ('', 'aliases', '',
-           _('file with email aliases'), _('FILE')),
-          ] + commands.walkopts,
-         _("hg churn [-d DATE] [-r REV] [--aliases FILE] [FILE]")),
-}
-
 commands.inferrepo += " churn"