mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 17:27:53 +03:00
ac7e07dbdf
Summary: At a recent team meeting we've decided to remove the command prefix matching behavior, as it can be really annoying for the Rust parser (since it needs to know all the names, but it wants to avoid spinning up Python). It's even more annoying for subcommand support. FWIW git does not have prefix matching. This diff adds various aliases to "roughly" keep the command prefix matching behavior. The list of aliases are obtained by this script in `hg dbsh`: def unique(prefix, names): m = __import__('edenscm.mercurial').mercurial try: return m.cmdutil.findcmd(prefix, m.commands.table, False)[0][0] in names except: return False nameslist=sorted([i.replace('^','') for i in m.commands.table]) aliases = {} for names in nameslist: names = names.split('|') for name in names: if name.startswith('debug'): continue for prefix in [name[:i] for i in xrange(1, len(name))]: if unique(prefix, names): aliases.setdefault(name, []).append(prefix) Debug commands, and commands that are rarely used are not changed, including: 'backfillmanifestrevlog': ['backfillm', 'backfillma', 'backfillman', 'backfillmani', 'backfillmanif', 'backfillmanife', 'backfillmanifes', 'backfillmanifest', 'backfillmanifestr', 'backfillmanifestre', 'backfillmanifestrev', 'backfillmanifestrevl', 'backfillmanifestrevlo'], 'backfilltree': ['backfillt', 'backfilltr', 'backfilltre']} 'blackbox': ['blac', 'black', 'blackb', 'blackbo'], 'cachemanifest': ['cac', 'cach', 'cache', 'cachem', 'cachema', 'cacheman', 'cachemani', 'cachemanif', 'cachemanife', 'cachemanifes'], 'chistedit': ['chi', 'chis', 'chist', 'chiste', 'chisted', 'chistedi'], 'clone': ['clon'], 'cloud': ['clou'], 'convert': ['conv', 'conve', 'conver'], 'copy': ['cop'], 'fastannotate': ['fa', 'fas', 'fast', 'fasta', 'fastan', 'fastann', 'fastanno', 'fastannot', 'fastannota', 'fastannotat'], 'fold': ['fol'], 'githelp': ['gi', 'git', 'gith', 'githe', 'githel'], 'histgrep': ['histg', 'histgr', 'histgre'], 'incoming': ['in', 'inc', 'inco', 'incom', 'incomi', 'incomin'], 'isbackedup': ['is', 'isb', 'isba', 'isbac', 'isback', 'isbacke', 'isbacked', 'isbackedu'], 'manifest': ['ma', 'man', 'mani', 'manif', 'manife', 'manifes'], 'outgoing': ['o', 'ou', 'out', 'outg', 'outgo', 'outgoi', 'outgoin'], 'prefetch': ['pref', 'prefe', 'prefet', 'prefetc'], 'prune': ['pru', 'prun'], 'pushbackup': ['pushb', 'pushba', 'pushbac', 'pushback', 'pushbacku'], 'rage': ['ra', 'rag'], 'record': ['recor'], 'recover': ['recov', 'recove'], 'redo': ['red'], 'repack': ['rep', 'repa', 'repac'], 'reset': ['rese'], 'rollback': ['rol', 'roll', 'rollb', 'rollba', 'rollbac'], 'root': ['roo'], 'serve': ['se', 'ser', 'serv'], 'share': ['sha', 'shar'], 'sparse': ['spa', 'spar', 'spars'], 'svn': ['sv'], 'undo': ['und'], 'unshare': ['unsha', 'unshar'], 'verifyremotefilelog': ['verifyr', 'verifyre', 'verifyrem', 'verifyremo', 'verifyremot', 'verifyremote', 'verifyremotef', 'verifyremotefi', 'verifyremotefil', 'verifyremotefile', 'verifyremotefilel', 'verifyremotefilelo'], Reviewed By: sfilipco Differential Revision: D17644676 fbshipit-source-id: f60f5e6810279b52f9a4a1e048eeb529a96bd735
69 lines
2.0 KiB
Python
69 lines
2.0 KiB
Python
# Copyright 2015 Facebook, Inc.
|
|
#
|
|
# This software may be used and distributed according to the terms of the
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
import os
|
|
|
|
from edenscm.mercurial import cmdutil, registrar, scmutil, util
|
|
from edenscm.mercurial.i18n import _
|
|
|
|
|
|
cmdtable = {}
|
|
command = registrar.command(cmdtable)
|
|
testedwith = "ships-with-fb-hgext"
|
|
|
|
|
|
@command(
|
|
"catnotate",
|
|
[
|
|
("r", "rev", "", _("print the given revision"), _("REV")),
|
|
("a", "text", None, _("treat all files as text")),
|
|
],
|
|
_("[OPTION]... FILE..."),
|
|
)
|
|
def catnotate(ui, repo, file1, *args, **opts):
|
|
"""output the current or given revision of files annotated with filename
|
|
and line number.
|
|
|
|
Print the specified files as they were at the given revision. If
|
|
no revision is given, the parent of the working directory is used.
|
|
|
|
Binary files are skipped unless -a/--text option is provided.
|
|
"""
|
|
ctx = scmutil.revsingle(repo, opts.get("rev"))
|
|
matcher = scmutil.match(ctx, (file1,) + args, opts)
|
|
prefix = ""
|
|
|
|
err = 1
|
|
# modified and stripped mercurial.cmdutil.cat follows
|
|
def write(path):
|
|
fp = cmdutil.makefileobj(
|
|
repo, opts.get("output"), ctx.node(), pathname=os.path.join(prefix, path)
|
|
)
|
|
data = ctx[path].data()
|
|
if not opts.get("text") and util.binary(data):
|
|
fp.write("%s: binary file\n" % path)
|
|
return
|
|
|
|
for (num, line) in enumerate(data.split("\n"), start=1):
|
|
line = line + "\n"
|
|
fp.write("%s:%s: %s" % (path, num, line))
|
|
fp.close()
|
|
|
|
# Automation often uses hg cat on single files, so special case it
|
|
# for performance to avoid the cost of parsing the manifest.
|
|
if len(matcher.files()) == 1 and not matcher.anypats():
|
|
file = matcher.files()[0]
|
|
mfl = repo.manifestlog
|
|
mfnode = ctx.manifestnode()
|
|
if mfnode and mfl[mfnode].find(file)[0]:
|
|
write(file)
|
|
return 0
|
|
|
|
for abs in ctx.walk(matcher):
|
|
write(abs)
|
|
err = 0
|
|
|
|
return err
|