[PATCH 09 of 35] hgk: declare commands using decorator

Gregory Szorc gregory.szorc at gmail.com
Mon May 5 00:51:14 CDT 2014


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1399264311 25200
#      Sun May 04 21:31:51 2014 -0700
# Branch stable
# Node ID 2cfe4a1d739b46f3daa9956a418b6293e78c0922
# Parent  1ca8d982041c4161a9fd5c3d4d71568ca9115b99
hgk: declare commands using decorator

diff --git a/hgext/hgk.py b/hgext/hgk.py
--- a/hgext/hgk.py
+++ b/hgext/hgk.py
@@ -30,22 +30,32 @@ Assuming you had already configured extd
   [hgk]
   vdiff=vdiff
 
 Revisions context menu will now display additional entries to fire
 vdiff on hovered and selected revisions.
 '''
 
 import os
-from mercurial import commands, util, patch, revlog, scmutil
+from mercurial import cmdutil, commands, util, patch, revlog, scmutil
 from mercurial.node import nullid, nullrev, short
 from mercurial.i18n import _
 
+cmdtable = {}
+command = cmdutil.command(cmdtable)
 testedwith = 'internal'
 
+ at command('debug-diff-tree',
+    [('p', 'patch', None, _('generate patch')),
+    ('r', 'recursive', None, _('recursive')),
+    ('P', 'pretty', None, _('pretty')),
+    ('s', 'stdin', None, _('stdin')),
+    ('C', 'copy', None, _('detect copies')),
+    ('S', 'search', "", _('search'))],
+    ('hg git-diff-tree [OPTION]... NODE1 NODE2 [FILE]...'))
 def difftree(ui, repo, node1=None, node2=None, *files, **opts):
     """diff trees from two commits"""
     def __difftree(repo, node1, node2, files=[]):
         assert node2 is not None
         mmap = repo[node1].manifest()
         mmap2 = repo[node2].manifest()
         m = scmutil.match(repo[node1], files)
         modified, added, removed  = repo.status(node1, node2, m)[:3]
@@ -120,23 +130,27 @@ def catcommit(ui, repo, n, prefix, ctx=N
     if prefix != "":
         ui.write("%s%s\n" % (prefix,
                              description.replace('\n', nlprefix).strip()))
     else:
         ui.write(description + "\n")
     if prefix:
         ui.write('\0')
 
+ at command('debug-merge-base', [], _('hg debug-merge-base REV REV'))
 def base(ui, repo, node1, node2):
     """output common ancestor information"""
     node1 = repo.lookup(node1)
     node2 = repo.lookup(node2)
     n = repo.changelog.ancestor(node1, node2)
     ui.write(short(n) + "\n")
 
+ at command('debug-cat-file',
+    [('s', 'stdin', None, _('stdin'))],
+    _('hg debug-cat-file [OPTION]... TYPE FILE'))
 def catfile(ui, repo, type=None, r=None, **opts):
     """cat a specific revision"""
     # in stdin mode, every line except the commit is prefixed with two
     # spaces.  This way the our caller can find the commit without magic
     # strings
     #
     prefix = ""
     if opts['stdin']:
@@ -271,86 +285,64 @@ def revtree(ui, args, repo, full="tree",
                 mask = is_reachable(want_sha1, reachable, p2)
                 if i2 != nullrev and mask > 0:
                     ui.write("%s:%s " % (h2, mask))
                 ui.write("\n")
             if maxnr and count >= maxnr:
                 break
             count += 1
 
+ at command('debug-rev-parse',
+    [('', 'default', '', _('ignored'))],
+    _('hg debug-rev-parse REV'))
 def revparse(ui, repo, *revs, **opts):
     """parse given revisions"""
     def revstr(rev):
         if rev == 'HEAD':
             rev = 'tip'
         return revlog.hex(repo.lookup(rev))
 
     for r in revs:
         revrange = r.split(':', 1)
         ui.write('%s\n' % revstr(revrange[0]))
         if len(revrange) == 2:
             ui.write('^%s\n' % revstr(revrange[1]))
 
 # git rev-list tries to order things by date, and has the ability to stop
 # at a given commit without walking the whole repo.  TODO add the stop
 # parameter
+ at command('debug-rev-list',
+    [('H', 'header', None, _('header')),
+    ('t', 'topo-order', None, _('topo-order')),
+    ('p', 'parents', None, _('parents')),
+    ('n', 'max-count', 0, _('max-count'))],
+    ('hg debug-rev-list [OPTION]... REV...'))
 def revlist(ui, repo, *revs, **opts):
     """print revisions"""
     if opts['header']:
         full = "commit"
     else:
         full = None
     copy = [x for x in revs]
     revtree(ui, copy, repo, full, opts['max_count'], opts['parents'])
 
+ at command('debug-config', [], _('hg debug-config'))
 def config(ui, repo, **opts):
     """print extension options"""
     def writeopt(name, value):
         ui.write(('k=%s\nv=%s\n' % (name, value)))
 
     writeopt('vdiff', ui.config('hgk', 'vdiff', ''))
 
 
+ at command('view',
+    [('l', 'limit', '',
+     _('limit number of changes displayed'), _('NUM'))],
+    _('hg view [-l LIMIT] [REVRANGE]'))
 def view(ui, repo, *etc, **opts):
     "start interactive history viewer"
     os.chdir(repo.root)
     optstr = ' '.join(['--%s %s' % (k, v) for k, v in opts.iteritems() if v])
     cmd = ui.config("hgk", "path", "hgk") + " %s %s" % (optstr, " ".join(etc))
     ui.debug("running %s\n" % cmd)
     util.system(cmd)
 
-cmdtable = {
-    "^view":
-        (view,
-         [('l', 'limit', '',
-           _('limit number of changes displayed'), _('NUM'))],
-         _('hg view [-l LIMIT] [REVRANGE]')),
-    "debug-diff-tree":
-        (difftree,
-         [('p', 'patch', None, _('generate patch')),
-          ('r', 'recursive', None, _('recursive')),
-          ('P', 'pretty', None, _('pretty')),
-          ('s', 'stdin', None, _('stdin')),
-          ('C', 'copy', None, _('detect copies')),
-          ('S', 'search', "", _('search'))],
-         _('hg git-diff-tree [OPTION]... NODE1 NODE2 [FILE]...')),
-    "debug-cat-file":
-        (catfile,
-         [('s', 'stdin', None, _('stdin'))],
-         _('hg debug-cat-file [OPTION]... TYPE FILE')),
-    "debug-config":
-        (config, [], _('hg debug-config')),
-    "debug-merge-base":
-        (base, [], _('hg debug-merge-base REV REV')),
-    "debug-rev-parse":
-        (revparse,
-         [('', 'default', '', _('ignored'))],
-         _('hg debug-rev-parse REV')),
-    "debug-rev-list":
-        (revlist,
-         [('H', 'header', None, _('header')),
-          ('t', 'topo-order', None, _('topo-order')),
-          ('p', 'parents', None, _('parents')),
-          ('n', 'max-count', 0, _('max-count'))],
-         _('hg debug-rev-list [OPTION]... REV...')),
-}
-
 commands.inferrepo += " debug-diff-tree debug-cat-file"


More information about the Mercurial-devel mailing list