mercurial/commands.py
changeset 21768 16aeb28caaa6
parent 21767 75a96326cecb
child 21775 5403245edb3a
equal deleted inserted replaced
21767:75a96326cecb 21768:16aeb28caaa6
    24 
    24 
    25 table = {}
    25 table = {}
    26 
    26 
    27 command = cmdutil.command(table)
    27 command = cmdutil.command(table)
    28 
    28 
    29 norepo = ("clone init version help debugcommands debugcomplete"
    29 # Space delimited list of commands that don't require local repositories.
    30           " debugdate debuginstall debugfsinfo debugpushkey debugwireargs"
    30 # This should be populated by passing norepo=True into the @command decorator.
    31           " debugknown debuggetbundle debugbundle")
    31 norepo = ''
    32 optionalrepo = ("identify paths serve config showconfig debugancestor debugdag"
    32 optionalrepo = ("identify paths serve config showconfig debugancestor debugdag"
    33                 " debugdata debugindex debugindexdot debugrevlog")
    33                 " debugdata debugindex debugindexdot debugrevlog")
    34 inferrepo = ("add addremove annotate cat commit diff grep forget log parents"
    34 inferrepo = ("add addremove annotate cat commit diff grep forget log parents"
    35              " remove resolve status debugwalk")
    35              " remove resolve status debugwalk")
    36 # common command options
    36 # common command options
  1210     ('r', 'rev', [], _('include the specified changeset'), _('REV')),
  1210     ('r', 'rev', [], _('include the specified changeset'), _('REV')),
  1211     ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')),
  1211     ('b', 'branch', [], _('clone only the specified branch'), _('BRANCH')),
  1212     ('', 'pull', None, _('use pull protocol to copy metadata')),
  1212     ('', 'pull', None, _('use pull protocol to copy metadata')),
  1213     ('', 'uncompressed', None, _('use uncompressed transfer (fast over LAN)')),
  1213     ('', 'uncompressed', None, _('use uncompressed transfer (fast over LAN)')),
  1214     ] + remoteopts,
  1214     ] + remoteopts,
  1215     _('[OPTION]... SOURCE [DEST]'))
  1215     _('[OPTION]... SOURCE [DEST]'),
       
  1216     norepo=True)
  1216 def clone(ui, source, dest=None, **opts):
  1217 def clone(ui, source, dest=None, **opts):
  1217     """make a copy of an existing repository
  1218     """make a copy of an existing repository
  1218 
  1219 
  1219     Create a copy of an existing repository in a new directory.
  1220     Create a copy of an existing repository in a new directory.
  1220 
  1221 
  1752             repo.opener.write("localtags", "".join(tags))
  1753             repo.opener.write("localtags", "".join(tags))
  1753     finally:
  1754     finally:
  1754         ui.progress(_('building'), None)
  1755         ui.progress(_('building'), None)
  1755         release(tr, lock)
  1756         release(tr, lock)
  1756 
  1757 
  1757 @command('debugbundle', [('a', 'all', None, _('show all details'))], _('FILE'))
  1758 @command('debugbundle',
       
  1759         [('a', 'all', None, _('show all details'))],
       
  1760         _('FILE'),
       
  1761         norepo=True)
  1758 def debugbundle(ui, bundlepath, all=None, **opts):
  1762 def debugbundle(ui, bundlepath, all=None, **opts):
  1759     """lists the contents of a bundle"""
  1763     """lists the contents of a bundle"""
  1760     f = hg.openpath(ui, bundlepath)
  1764     f = hg.openpath(ui, bundlepath)
  1761     try:
  1765     try:
  1762         gen = exchange.readbundle(ui, f, bundlepath)
  1766         gen = exchange.readbundle(ui, f, bundlepath)
  1830             errors += 1
  1834             errors += 1
  1831     if errors:
  1835     if errors:
  1832         error = _(".hg/dirstate inconsistent with current parent's manifest")
  1836         error = _(".hg/dirstate inconsistent with current parent's manifest")
  1833         raise util.Abort(error)
  1837         raise util.Abort(error)
  1834 
  1838 
  1835 @command('debugcommands', [], _('[COMMAND]'))
  1839 @command('debugcommands', [], _('[COMMAND]'), norepo=True)
  1836 def debugcommands(ui, cmd='', *args):
  1840 def debugcommands(ui, cmd='', *args):
  1837     """list all available commands and options"""
  1841     """list all available commands and options"""
  1838     for cmd, vals in sorted(table.iteritems()):
  1842     for cmd, vals in sorted(table.iteritems()):
  1839         cmd = cmd.split('|')[0].strip('^')
  1843         cmd = cmd.split('|')[0].strip('^')
  1840         opts = ', '.join([i[1] for i in vals[1]])
  1844         opts = ', '.join([i[1] for i in vals[1]])
  1841         ui.write('%s: %s\n' % (cmd, opts))
  1845         ui.write('%s: %s\n' % (cmd, opts))
  1842 
  1846 
  1843 @command('debugcomplete',
  1847 @command('debugcomplete',
  1844     [('o', 'options', None, _('show the command options'))],
  1848     [('o', 'options', None, _('show the command options'))],
  1845     _('[-o] CMD'))
  1849     _('[-o] CMD'),
       
  1850     norepo=True)
  1846 def debugcomplete(ui, cmd='', **opts):
  1851 def debugcomplete(ui, cmd='', **opts):
  1847     """returns the completion list associated with the given command"""
  1852     """returns the completion list associated with the given command"""
  1848 
  1853 
  1849     if opts.get('options'):
  1854     if opts.get('options'):
  1850         options = []
  1855         options = []
  1944     except KeyError:
  1949     except KeyError:
  1945         raise util.Abort(_('invalid revision identifier %s') % rev)
  1950         raise util.Abort(_('invalid revision identifier %s') % rev)
  1946 
  1951 
  1947 @command('debugdate',
  1952 @command('debugdate',
  1948     [('e', 'extended', None, _('try extended date formats'))],
  1953     [('e', 'extended', None, _('try extended date formats'))],
  1949     _('[-e] DATE [RANGE]'))
  1954     _('[-e] DATE [RANGE]'),
       
  1955     norepo=True)
  1950 def debugdate(ui, date, range=None, **opts):
  1956 def debugdate(ui, date, range=None, **opts):
  1951     """parse and display a date"""
  1957     """parse and display a date"""
  1952     if opts["extended"]:
  1958     if opts["extended"]:
  1953         d = util.parsedate(date, util.extendeddateformats)
  1959         d = util.parsedate(date, util.extendeddateformats)
  1954     else:
  1960     else:
  2040         ui.note(tree, "\n")
  2046         ui.note(tree, "\n")
  2041 
  2047 
  2042     for f in ctx.getfileset(expr):
  2048     for f in ctx.getfileset(expr):
  2043         ui.write("%s\n" % f)
  2049         ui.write("%s\n" % f)
  2044 
  2050 
  2045 @command('debugfsinfo', [], _('[PATH]'))
  2051 @command('debugfsinfo', [], _('[PATH]'), norepo=True)
  2046 def debugfsinfo(ui, path="."):
  2052 def debugfsinfo(ui, path="."):
  2047     """show information detected about current filesystem"""
  2053     """show information detected about current filesystem"""
  2048     util.writefile('.debugfsinfo', '')
  2054     util.writefile('.debugfsinfo', '')
  2049     ui.write(('exec: %s\n') % (util.checkexec(path) and 'yes' or 'no'))
  2055     ui.write(('exec: %s\n') % (util.checkexec(path) and 'yes' or 'no'))
  2050     ui.write(('symlink: %s\n') % (util.checklink(path) and 'yes' or 'no'))
  2056     ui.write(('symlink: %s\n') % (util.checklink(path) and 'yes' or 'no'))
  2055 
  2061 
  2056 @command('debuggetbundle',
  2062 @command('debuggetbundle',
  2057     [('H', 'head', [], _('id of head node'), _('ID')),
  2063     [('H', 'head', [], _('id of head node'), _('ID')),
  2058     ('C', 'common', [], _('id of common node'), _('ID')),
  2064     ('C', 'common', [], _('id of common node'), _('ID')),
  2059     ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE'))],
  2065     ('t', 'type', 'bzip2', _('bundle compression type to use'), _('TYPE'))],
  2060     _('REPO FILE [-H|-C ID]...'))
  2066     _('REPO FILE [-H|-C ID]...'),
       
  2067     norepo=True)
  2061 def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts):
  2068 def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts):
  2062     """retrieves a bundle from a repo
  2069     """retrieves a bundle from a repo
  2063 
  2070 
  2064     Every ID must be a full-length hex node id string. Saves the bundle to the
  2071     Every ID must be a full-length hex node id string. Saves the bundle to the
  2065     given file.
  2072     given file.
  2156         ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i))
  2163         ui.write("\t%d -> %d\n" % (r.rev(pp[0]), i))
  2157         if pp[1] != nullid:
  2164         if pp[1] != nullid:
  2158             ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i))
  2165             ui.write("\t%d -> %d\n" % (r.rev(pp[1]), i))
  2159     ui.write("}\n")
  2166     ui.write("}\n")
  2160 
  2167 
  2161 @command('debuginstall', [], '')
  2168 @command('debuginstall', [], '', norepo=True)
  2162 def debuginstall(ui):
  2169 def debuginstall(ui):
  2163     '''test Mercurial installation
  2170     '''test Mercurial installation
  2164 
  2171 
  2165     Returns 0 on success.
  2172     Returns 0 on success.
  2166     '''
  2173     '''
  2254         ui.write(_("%s problems detected,"
  2261         ui.write(_("%s problems detected,"
  2255                    " please check your install!\n") % problems)
  2262                    " please check your install!\n") % problems)
  2256 
  2263 
  2257     return problems
  2264     return problems
  2258 
  2265 
  2259 @command('debugknown', [], _('REPO ID...'))
  2266 @command('debugknown', [], _('REPO ID...'), norepo=True)
  2260 def debugknown(ui, repopath, *ids, **opts):
  2267 def debugknown(ui, repopath, *ids, **opts):
  2261     """test whether node ids are known to a repo
  2268     """test whether node ids are known to a repo
  2262 
  2269 
  2263     Every ID must be a full-length hex node id string. Returns a list of 0s
  2270     Every ID must be a full-length hex node id string. Returns a list of 0s
  2264     and 1s indicating unknown/known.
  2271     and 1s indicating unknown/known.
  2391         dirs.update(d)
  2398         dirs.update(d)
  2392     files.update(dirs)
  2399     files.update(dirs)
  2393     ui.write('\n'.join(repo.pathto(p, cwd) for p in sorted(files)))
  2400     ui.write('\n'.join(repo.pathto(p, cwd) for p in sorted(files)))
  2394     ui.write('\n')
  2401     ui.write('\n')
  2395 
  2402 
  2396 @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'))
  2403 @command('debugpushkey', [], _('REPO NAMESPACE [KEY OLD NEW]'), norepo=True)
  2397 def debugpushkey(ui, repopath, namespace, *keyinfo, **opts):
  2404 def debugpushkey(ui, repopath, namespace, *keyinfo, **opts):
  2398     '''access the pushkey key/value protocol
  2405     '''access the pushkey key/value protocol
  2399 
  2406 
  2400     With two args, list the keys in the given namespace.
  2407     With two args, list the keys in the given namespace.
  2401 
  2408 
  2805 @command('debugwireargs',
  2812 @command('debugwireargs',
  2806     [('', 'three', '', 'three'),
  2813     [('', 'three', '', 'three'),
  2807     ('', 'four', '', 'four'),
  2814     ('', 'four', '', 'four'),
  2808     ('', 'five', '', 'five'),
  2815     ('', 'five', '', 'five'),
  2809     ] + remoteopts,
  2816     ] + remoteopts,
  2810     _('REPO [OPTIONS]... [ONE [TWO]]'))
  2817     _('REPO [OPTIONS]... [ONE [TWO]]'),
       
  2818     norepo=True)
  2811 def debugwireargs(ui, repopath, *vals, **opts):
  2819 def debugwireargs(ui, repopath, *vals, **opts):
  2812     repo = hg.peer(ui, opts, repopath)
  2820     repo = hg.peer(ui, opts, repopath)
  2813     for opt in remoteopts:
  2821     for opt in remoteopts:
  2814         del opts[opt[1]]
  2822         del opts[opt[1]]
  2815     args = {}
  2823     args = {}
  3531 @command('help',
  3539 @command('help',
  3532     [('e', 'extension', None, _('show only help for extensions')),
  3540     [('e', 'extension', None, _('show only help for extensions')),
  3533      ('c', 'command', None, _('show only help for commands')),
  3541      ('c', 'command', None, _('show only help for commands')),
  3534      ('k', 'keyword', '', _('show topics matching keyword')),
  3542      ('k', 'keyword', '', _('show topics matching keyword')),
  3535      ],
  3543      ],
  3536     _('[-ec] [TOPIC]'))
  3544     _('[-ec] [TOPIC]'),
       
  3545     norepo=True)
  3537 def help_(ui, name=None, **opts):
  3546 def help_(ui, name=None, **opts):
  3538     """show help for a given topic or a help overview
  3547     """show help for a given topic or a help overview
  3539 
  3548 
  3540     With no arguments, print a list of commands with short help messages.
  3549     With no arguments, print a list of commands with short help messages.
  3541 
  3550 
  3948         return hg.incoming(ui, repo, source, opts)
  3957         return hg.incoming(ui, repo, source, opts)
  3949     finally:
  3958     finally:
  3950         del repo._subtoppath
  3959         del repo._subtoppath
  3951 
  3960 
  3952 
  3961 
  3953 @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'))
  3962 @command('^init', remoteopts, _('[-e CMD] [--remotecmd CMD] [DEST]'),
       
  3963          norepo=True)
  3954 def init(ui, dest=".", **opts):
  3964 def init(ui, dest=".", **opts):
  3955     """create a new repository in the given directory
  3965     """create a new repository in the given directory
  3956 
  3966 
  3957     Initialize a new repository in the given directory. If the given
  3967     Initialize a new repository in the given directory. If the given
  3958     directory does not exist, it will be created.
  3968     directory does not exist, it will be created.
  5970 
  5980 
  5971     Returns 0 on success, 1 if errors are encountered.
  5981     Returns 0 on success, 1 if errors are encountered.
  5972     """
  5982     """
  5973     return hg.verify(repo)
  5983     return hg.verify(repo)
  5974 
  5984 
  5975 @command('version', [])
  5985 @command('version', [], norepo=True)
  5976 def version_(ui):
  5986 def version_(ui):
  5977     """output version and copyright information"""
  5987     """output version and copyright information"""
  5978     ui.write(_("Mercurial Distributed SCM (version %s)\n")
  5988     ui.write(_("Mercurial Distributed SCM (version %s)\n")
  5979              % util.version())
  5989              % util.version())
  5980     ui.status(_(
  5990     ui.status(_(