[PATCH 1 of 3] commands: unify argument handling for revlog debug commands

Gregory Szorc gregory.szorc at gmail.com
Sun Dec 6 08:45:01 UTC 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1449380859 28800
#      Sat Dec 05 21:47:39 2015 -0800
# Node ID 36a0e4caa4bfaf0a7040c6e8652271d7c4672b03
# Parent  30a20167ae29e1874163b59a489de0cb1d859565
commands: unify argument handling for revlog debug commands

The same 3 options are used in a few locations and I'm about to
add another. Might as well consolidate the pattern.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -166,16 +166,22 @@ similarityopts = [
      _('guess renamed files by similarity (0<=s<=100)'), _('SIMILARITY'))
 ]
 
 subrepoopts = [
     ('S', 'subrepos', None,
      _('recurse into subrepositories'))
 ]
 
+debugrevlogopts = [
+    ('c', 'changelog', False, _('open changelog')),
+    ('m', 'manifest', False, _('open manifest')),
+    ('', 'dir', False, _('open directory manifest')),
+]
+
 # Commands start here, listed alphabetically
 
 @command('^add',
     walkopts + subrepoopts + dryrunopts,
     _('[OPTION]... [FILE]...'),
     inferrepo=True)
 def add(ui, repo, *pats, **opts):
     """add the specified files on the next commit
@@ -2198,21 +2204,17 @@ def debugdag(ui, repo, file_=None, *revs
                                        wraplabels=True,
                                        wrapannotations=True,
                                        wrapnonlinear=dots,
                                        usedots=dots,
                                        maxlinewidth=70):
         ui.write(line)
         ui.write("\n")
 
- at command('debugdata',
-    [('c', 'changelog', False, _('open changelog')),
-     ('m', 'manifest', False, _('open manifest')),
-     ('', 'dir', False, _('open directory manifest'))],
-    _('-c|-m|FILE REV'))
+ at command('debugdata', debugrevlogopts, _('-c|-m|FILE REV'))
 def debugdata(ui, repo, file_, rev=None, **opts):
     """dump the contents of a data file revision"""
     if opts.get('changelog') or opts.get('manifest'):
         file_, rev = None, file_
     elif rev is None:
         raise error.CommandError('debugdata', _('invalid arguments'))
     r = cmdutil.openrevlog(repo, 'debugdata', file_, opts)
     try:
@@ -2408,21 +2410,18 @@ def debugignore(ui, repo, *values, **opt
     """display the combined ignore pattern"""
     ignore = repo.dirstate._ignore
     includepat = getattr(ignore, 'includepat', None)
     if includepat is not None:
         ui.write("%s\n" % includepat)
     else:
         raise error.Abort(_("no ignore patterns found"))
 
- at command('debugindex',
-    [('c', 'changelog', False, _('open changelog')),
-     ('m', 'manifest', False, _('open manifest')),
-     ('', 'dir', False, _('open directory manifest')),
-     ('f', 'format', 0, _('revlog format'), _('FORMAT'))],
+ at command('debugindex', debugrevlogopts +
+    [('f', 'format', 0, _('revlog format'), _('FORMAT'))],
     _('[-f FORMAT] -c|-m|FILE'),
     optionalrepo=True)
 def debugindex(ui, repo, file_=None, **opts):
     """dump the contents of an index file"""
     r = cmdutil.openrevlog(repo, 'debugindex', file_, opts)
     format = opts.get('format', 0)
     if format not in (0, 1):
         raise error.Abort(_("unknown format %d") % format)
@@ -3015,21 +3014,18 @@ def debugrename(ui, repo, file1, *pats, 
         fctx = ctx[abs]
         o = fctx.filelog().renamed(fctx.filenode())
         rel = m.rel(abs)
         if o:
             ui.write(_("%s renamed from %s:%s\n") % (rel, o[0], hex(o[1])))
         else:
             ui.write(_("%s not renamed\n") % rel)
 
- at command('debugrevlog',
-    [('c', 'changelog', False, _('open changelog')),
-     ('m', 'manifest', False, _('open manifest')),
-     ('', 'dir', False, _('open directory manifest')),
-     ('d', 'dump', False, _('dump index data'))],
+ at command('debugrevlog', debugrevlogopts +
+    [('d', 'dump', False, _('dump index data'))],
     _('-c|-m|FILE'),
     optionalrepo=True)
 def debugrevlog(ui, repo, file_=None, **opts):
     """show data and statistics about a revlog"""
     r = cmdutil.openrevlog(repo, 'debugrevlog', file_, opts)
 
     if opts.get("dump"):
         numrevs = len(r)


More information about the Mercurial-devel mailing list