2019-11-01 23:24:22 +03:00
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
2019-05-25 02:19:14 +03:00
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
2019-11-01 23:24:22 +03:00
|
|
|
# GNU General Public License version 2.
|
|
|
|
|
|
|
|
# checkserverbookmark.py - check whether the bookmark is where we expect
|
|
|
|
# it to be on a server
|
2019-05-25 02:19:14 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2020-02-04 23:32:03 +03:00
|
|
|
from edenscm.mercurial import error, hg
|
2019-05-25 02:19:14 +03:00
|
|
|
from edenscm.mercurial.commands import command
|
|
|
|
from edenscm.mercurial.i18n import _
|
|
|
|
from edenscm.mercurial.node import hex
|
|
|
|
|
|
|
|
|
|
|
|
def getremote(ui, path):
|
|
|
|
remote = hg.peer(ui, {}, path)
|
|
|
|
return remote
|
|
|
|
|
|
|
|
|
|
|
|
def runlookup(ui, remote, name):
|
2019-05-25 20:54:40 +03:00
|
|
|
return remote.lookup(name)
|
2019-05-25 02:19:14 +03:00
|
|
|
|
|
|
|
|
|
|
|
def runlistkeys(ui, remote):
|
2019-05-25 20:54:40 +03:00
|
|
|
return remote.listkeys("bookmarks")
|
2019-05-25 02:19:14 +03:00
|
|
|
|
|
|
|
|
|
|
|
def verifyexisting(ui, remote, name, hash):
|
|
|
|
location = hex(runlookup(ui, remote, name))
|
|
|
|
if location.strip() != hash.strip():
|
|
|
|
ui.warn(
|
|
|
|
_(
|
|
|
|
"hg server does not have an expected bookmark location. "
|
|
|
|
+ "book: %s, server: %s; expected %s\n"
|
|
|
|
)
|
|
|
|
% (name, location, hash)
|
|
|
|
)
|
|
|
|
return 1
|
|
|
|
ui.warn(
|
|
|
|
_("hg server has expected bookmark location. book: %s, hash: %s\n")
|
|
|
|
% (name, hash)
|
|
|
|
)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
def verifydeleted(ui, remote, name):
|
|
|
|
serverkeys = runlistkeys(ui, remote)
|
|
|
|
if name in serverkeys:
|
|
|
|
ui.warn(
|
|
|
|
_("hg server has bookmark, which is expected to have been deleted: %s\n")
|
|
|
|
% (name,)
|
|
|
|
)
|
|
|
|
return 1
|
|
|
|
ui.warn(_("hg server expectedly does not have a bookmark: %s\n") % (name,))
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
@command(
|
commands: define prefixes as aliases
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
2019-10-08 19:44:04 +03:00
|
|
|
"checkserverbookmark",
|
2019-05-25 02:19:14 +03:00
|
|
|
[
|
|
|
|
("", "path", "", _("hg server remotepath (ssh)"), ""),
|
|
|
|
("", "name", "", _("bookmark name to check"), ""),
|
|
|
|
("", "hash", "", _("hash to verify against the bookmark"), ""),
|
|
|
|
(
|
|
|
|
"",
|
|
|
|
"deleted",
|
|
|
|
False,
|
|
|
|
_("bookmark is expected to not exist, cannot be used with `--hash`"),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
_("[OPTION]..."),
|
|
|
|
norepo=True,
|
|
|
|
)
|
|
|
|
def checkserverbookmark(ui, **opts):
|
|
|
|
"""Verify whether the bookmark on hg server points to a given hash"""
|
|
|
|
name = opts["name"]
|
|
|
|
path = opts["path"]
|
|
|
|
hash = opts["hash"]
|
|
|
|
deleted = opts["deleted"]
|
|
|
|
if hash and deleted:
|
|
|
|
raise error.Abort("can't use `--hash` and `--deleted`")
|
|
|
|
|
|
|
|
if not (hash or deleted):
|
|
|
|
raise error.Abort("either `--hash` or `--deleted` should be used")
|
|
|
|
|
|
|
|
remote = getremote(ui, path)
|
|
|
|
if deleted:
|
|
|
|
return verifydeleted(ui, remote, name)
|
|
|
|
else:
|
|
|
|
return verifyexisting(ui, remote, name, hash)
|