[PATCH 16 of 35] commands: define norepo in command decorator

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu May 8 14:21:00 CDT 2014



On 05/04/2014 10:51 PM, Gregory Szorc wrote:
> # HG changeset patch
> # User Gregory Szorc <gregory.szorc at gmail.com>
> # Date 1399262221 25200
> #      Sun May 04 20:57:01 2014 -0700
> # Branch stable
> # Node ID e82a4869a0b3f0b19a9d99ef7bb60a87d3c866e6
> # Parent  28363b7aa15d67a3136a642beb678366d5fdecf1
> commands: define norepo in command decorator
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -21,19 +21,19 @@ import dagparser, context, simplemerge,
>   import random
>   import setdiscovery, treediscovery, dagutil, pvec, localrepo
>   import phases, obsolete, exchange
>
>   table = {}
>
>   command = cmdutil.command(table)
>
> -norepo = ("clone init version help debugcommands debugcomplete"
> -          " debugdate debuginstall debugfsinfo debugpushkey debugwireargs"
> -          " debugknown debuggetbundle debugbundle")

When doing a massive an repetitive changes, the new fashion is to have 
a patch for each elements in the set. This make much smaller patches 
where it is easy to check anything remove from the old way is properly 
and identically added in the new way.

This increase the number of patch but usually speedup review and helps 
catching a few errors.

This is a good example of a case were you want start by validating the 
idea and the implementation for a few elements with other people (IRC or 
mailing list) and when the first example are validated, you provide the 
full stack (either by pull, or patchbombing if it is not too huge.)

> +# Space delimited list of commands that don't require local repositories.
> +# This should be populated by passing norepo=True into the @command decorator.
> +norepo = ''

(note: I hate this space delimited list, but I agree that not 
gratuitously brealing the extension API is sonthing nice for all our 
user out there)


>   optionalrepo = ("identify paths serve config showconfig debugancestor debugdag"
>                   " debugdata debugindex debugindexdot debugrevlog")
>   inferrepo = ("add addremove annotate cat commit diff grep forget log parents"
>                " remove resolve status debugwalk")
>   # common command options
>
>   globalopts = [
>       ('R', 'repository', '',
> @@ -1192,17 +1192,18 @@ def cat(ui, repo, file1, *pats, **opts):
>       [('U', 'noupdate', None,
>        _('the clone will include an empty working copy (only a repository)')),
>       ('u', 'updaterev', '', _('revision, tag or branch to check out'), _('REV')),
>       ('r', 'rev', [], _('include the specified changeset'), _('REV')),
>       ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')),
>       ('', 'pull', None, _('use pull protocol to copy metadata')),
>       ('', 'uncompressed', None, _('use uncompressed transfer (fast over LAN)')),
>       ] + remoteopts,
> -    _('[OPTION]... SOURCE [DEST]'))
> +    _('[OPTION]... SOURCE [DEST]'),
> +    norepo=True)
>   def clone(ui, source, dest=None, **opts):
>       """make a copy of an existing repository
>
>       Create a copy of an existing repository in a new directory.
>
>       If no destination directory name is specified, it defaults to the
>       basename of the source.
>
> @@ -1738,17 +1739,20 @@ def debugbuilddag(ui, repo, text=None,
>           tr.close()
>
>           if tags:
>               repo.opener.write("localtags", "".join(tags))
>       finally:
>           ui.progress(_('building'), None)
>           release(tr, lock)
>
> - at command('debugbundle', [('a', 'all', None, _('show all details'))], _('FILE'))
> + at command('debugbundle',
> +        [('a', 'all', None, _('show all details'))],
> +        _('FILE'),
> +        norepo=True)
>   def debugbundle(ui, bundlepath, all=None, **opts):
>       """lists the contents of a bundle"""
>       f = hg.openpath(ui, bundlepath)
>       try:
>           gen = exchange.readbundle(ui, f, bundlepath)
>           if all:
>               ui.write(("format: id, p1, p2, cset, delta base, len(delta)\n"))
>
> @@ -1816,27 +1820,28 @@ def debugcheckstate(ui, repo):
>           state = repo.dirstate[f]
>           if state not in "nrm":
>               ui.warn(_("%s in manifest1, but listed as state %s") % (f, state))
>               errors += 1
>       if errors:
>           error = _(".hg/dirstate inconsistent with current parent's manifest")
>           raise util.Abort(error)
>
> - at command('debugcommands', [], _('[COMMAND]'))
> + at command('debugcommands', [], _('[COMMAND]'), norepo=True)
>   def debugcommands(ui, cmd='', *args):
>       """list all available commands and options"""
>       for cmd, vals in sorted(table.iteritems()):
>           cmd = cmd.split('|')[0].strip('^')
>           opts = ', '.join([i[1] for i in vals[1]])
>           ui.write('%s: %s\n' % (cmd, opts))
>
>   @command('debugcomplete',
>       [('o', 'options', None, _('show the command options'))],
> -    _('[-o] CMD'))
> +    _('[-o] CMD'),
> +    norepo=True)
>   def debugcomplete(ui, cmd='', **opts):
>       """returns the completion list associated with the given command"""
>
>       if opts.get('options'):
>           options = []
>           otables = [globalopts]
>           if cmd:
>               aliases, entry = cmdutil.findcmd(cmd, table, False)
> @@ -1930,17 +1935,18 @@ def debugdata(ui, repo, file_, rev=None,
>       r = cmdutil.openrevlog(repo, 'debugdata', file_, opts)
>       try:
>           ui.write(r.revision(r.lookup(rev)))
>       except KeyError:
>           raise util.Abort(_('invalid revision identifier %s') % rev)
>
>   @command('debugdate',
>       [('e', 'extended', None, _('try extended date formats'))],
> -    _('[-e] DATE [RANGE]'))
> +    _('[-e] DATE [RANGE]'),
> +    norepo=True)
>   def debugdate(ui, date, range=None, **opts):
>       """parse and display a date"""
>       if opts["extended"]:
>           d = util.parsedate(date, util.extendeddateformats)
>       else:
>           d = util.parsedate(date)
>       ui.write(("internal: %s %s\n") % d)
>       ui.write(("standard: %s\n") % util.datestr(d))
> @@ -2026,32 +2032,33 @@ def debugfileset(ui, repo, expr, **opts)
>       ctx = scmutil.revsingle(repo, opts.get('rev'), None)
>       if ui.verbose:
>           tree = fileset.parse(expr)[0]
>           ui.note(tree, "\n")
>
>       for f in ctx.getfileset(expr):
>           ui.write("%s\n" % f)
>
> - at command('debugfsinfo', [], _('[PATH]'))
> + at command('debugfsinfo', [], _('[PATH]'), norepo=True)
>   def debugfsinfo(ui, path="."):
>       """show information detected about current filesystem"""
>       util.writefile('.debugfsinfo', '')
>       ui.write(('exec: %s\n') % (util.checkexec(path) and 'yes' or 'no'))
>       ui.write(('symlink: %s\n') % (util.checklink(path) and 'yes' or 'no'))
>       ui.write(('hardlink: %s\n') % (util.checknlink(path) and 'yes' or 'no'))
>       ui.write(('case-sensitive: %s\n') % (util.checkcase('.debugfsinfo')
>                                   and 'yes' or 'no'))
>       os.unlink('.debugfsinfo')
>
>   @command('debuggetbundle',
>       [('H', 'head', [], _('id of head node'), _('ID')),
>       ('C', 'common', [], _('id of common node'), _('ID')),
>       ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE'))],
> -    _('REPO FILE [-H|-C ID]...'))
> +    _('REPO FILE [-H|-C ID]...'),
> +    norepo=True)
>   def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts):
>       """retrieves a bundle from a repo
>
>       Every ID must be a full-length hex node id string. Saves the bundle to the
>       given file.
>       """
>       repo = hg.peer(ui, opts, repopath)
>       if not repo.capable('getbundle'):
> @@ -2142,17 +2149,17 @@ def debugindexdot(ui, repo, file_):
>       for i in r:
>           node = r.node(i)
>           pp = r.parents(node)
>           ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i))
>           if pp[1] != nullid:
>               ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i))
>       ui.write("}\n")
>
> - at command('debuginstall', [], '')
> + at command('debuginstall', [], '', norepo=True)
>   def debuginstall(ui):
>       '''test Mercurial installation
>
>       Returns 0 on success.
>       '''
>
>       def writetemp(contents):
>           (fd, name) = tempfile.mkstemp(prefix="hg-debuginstall-")
> @@ -2240,17 +2247,17 @@ def debuginstall(ui):
>       if not problems:
>           ui.status(_("no problems detected\n"))
>       else:
>           ui.write(_("%s problems detected,"
>                      " please check your install!\n") % problems)
>
>       return problems
>
> - at command('debugknown', [], _('REPO ID...'))
> + at command('debugknown', [], _('REPO ID...'), norepo=True)
>   def debugknown(ui, repopath, *ids, **opts):
>       """test whether node ids are known to a repo
>
>       Every ID must be a full-length hex node id string. Returns a list of 0s
>       and 1s indicating unknown/known.
>       """
>       repo = hg.peer(ui, opts, repopath)
>       if not repo.capable('known'):
> @@ -2377,17 +2384,17 @@ def debugpathcomplete(ui, repo, *specs,
>       for spec in specs:
>           f, d = complete(spec, acceptable or 'nmar')
>           files.update(f)
>           dirs.update(d)
>       files.update(dirs)
>       ui.write('\n'.join(repo.pathto(p, cwd) for p in sorted(files)))
>       ui.write('\n')
>
> - at command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'))
> + at command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'), norepo=True)
>   def debugpushkey(ui, repopath, namespace, *keyinfo, **opts):
>       '''access the pushkey key/value protocol
>
>       With two args, list the keys in the given namespace.
>
>       With five args, set a key to new if it currently is set to old.
>       Reports success or failure.
>       '''
> @@ -2791,17 +2798,18 @@ def debugwalk(ui, repo, *pats, **opts):
>           line = fmt % (abs, f(m.rel(abs)), m.exact(abs) and 'exact' or '')
>           ui.write("%s\n" % line.rstrip())
>
>   @command('debugwireargs',
>       [('', 'three', '', 'three'),
>       ('', 'four', '', 'four'),
>       ('', 'five', '', 'five'),
>       ] + remoteopts,
> -    _('REPO [OPTIONS]... [ONE [TWO]]'))
> +    _('REPO [OPTIONS]... [ONE [TWO]]'),
> +    norepo=True)
>   def debugwireargs(ui, repopath, *vals, **opts):
>       repo = hg.peer(ui, opts, repopath)
>       for opt in remoteopts:
>           del opts[opt[1]]
>       args = {}
>       for k, v in opts.iteritems():
>           if v:
>               args[k] = v
> @@ -3518,17 +3526,18 @@ def heads(ui, repo, *branchrevs, **opts)
>           displayer.show(ctx)
>       displayer.close()
>
>   @command('help',
>       [('e', 'extension', None, _('show only help for extensions')),
>        ('c', 'command', None, _('show only help for commands')),
>        ('k', 'keyword', '', _('show topics matching keyword')),
>        ],
> -    _('[-ec] [TOPIC]'))
> +    _('[-ec] [TOPIC]'),
> +    norepo=True)
>   def help_(ui, name=None, **opts):
>       """show help for a given topic or a help overview
>
>       With no arguments, print a list of commands with short help messages.
>
>       Given a topic, extension, or command name, print help for that
>       topic.
>
> @@ -3914,17 +3923,18 @@ def incoming(ui, repo, source="default",
>
>       repo._subtoppath = ui.expandpath(source)
>       try:
>           return hg.incoming(ui, repo, source, opts)
>       finally:
>           del repo._subtoppath
>
>
> - at command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'))
> + at command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'),
> +         norepo=True)
>   def init(ui, dest=".", **opts):
>       """create a new repository in the given directory
>
>       Initialize a new repository in the given directory. If the given
>       directory does not exist, it will be created.
>
>       If no directory is given, the current directory is used.
>
> @@ -5904,17 +5914,17 @@ def verify(ui, repo):
>       Please see http://mercurial.selenic.com/wiki/RepositoryCorruption
>       for more information about recovery from corruption of the
>       repository.
>
>       Returns 0 on success, 1 if errors are encountered.
>       """
>       return hg.verify(repo)
>
> - at command('version', [])
> + at command('version', [], norepo=True)
>   def version_(ui):
>       """output version and copyright information"""
>       ui.write(_("Mercurial Distributed SCM (version %s)\n")
>                % util.version())
>       ui.status(_(
>           "(see http://mercurial.selenic.com for more information)\n"
>           "\nCopyright (C) 2005-2014 Matt Mackall and others\n"
>           "This is free software; see the source for copying conditions. "
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>


More information about the Mercurial-devel mailing list