debugcommands.py
4652 lines
| 148.3 KiB
| text/x-python
|
PythonLexer
/ mercurial / debugcommands.py
|
r30401 | # debugcommands.py - command processing for debug* commands | ||
# | ||||
# Copyright 2005-2016 Matt Mackall <mpm@selenic.com> | ||||
# | ||||
# This software may be used and distributed according to the terms of the | ||||
# GNU General Public License version 2 or any later version. | ||||
from __future__ import absolute_import | ||||
|
r34131 | import codecs | ||
|
r34027 | import collections | ||
|
r30952 | import difflib | ||
|
r30938 | import errno | ||
|
r44915 | import glob | ||
|
r30518 | import operator | ||
|
r30525 | import os | ||
|
r44603 | import platform | ||
|
r30517 | import random | ||
|
r37031 | import re | ||
|
r30938 | import socket | ||
|
r33493 | import ssl | ||
|
r36799 | import stat | ||
|
r30951 | import string | ||
|
r36545 | import subprocess | ||
|
r30918 | import sys | ||
|
r30938 | import time | ||
|
r30401 | |||
from .i18n import _ | ||||
|
r30402 | from .node import ( | ||
|
r30526 | bin, | ||
|
r30402 | hex, | ||
|
r30528 | nullid, | ||
|
r30951 | nullrev, | ||
|
r30517 | short, | ||
|
r30402 | ) | ||
|
r43359 | from .pycompat import ( | ||
getattr, | ||||
open, | ||||
) | ||||
|
r30401 | from . import ( | ||
|
r30501 | bundle2, | ||
|
r44915 | bundlerepo, | ||
|
r30501 | changegroup, | ||
|
r30401 | cmdutil, | ||
|
r31120 | color, | ||
|
r30402 | context, | ||
|
r41656 | copies, | ||
|
r30402 | dagparser, | ||
|
r30918 | encoding, | ||
|
r30401 | error, | ||
|
r30501 | exchange, | ||
|
r30518 | extensions, | ||
|
r32256 | filemerge, | ||
|
r38841 | filesetlang, | ||
|
r30957 | formatter, | ||
|
r30501 | hg, | ||
|
r37030 | httppeer, | ||
|
r30517 | localrepo, | ||
|
r30402 | lock as lockmod, | ||
|
r35906 | logcmdutil, | ||
|
r45383 | mergestate as mergestatemod, | ||
r46257 | metadata, | |||
|
r30939 | obsolete, | ||
r33143 | obsutil, | |||
|
r44032 | pathutil, | ||
|
r32745 | phases, | ||
|
r30918 | policy, | ||
|
r30947 | pvec, | ||
|
r30519 | pycompat, | ||
|
r32337 | registrar, | ||
|
r30775 | repair, | ||
|
r30401 | revlog, | ||
|
r30952 | revset, | ||
|
r31024 | revsetlang, | ||
|
r30401 | scmutil, | ||
|
r30517 | setdiscovery, | ||
|
r30402 | simplemerge, | ||
|
r36545 | sshpeer, | ||
|
r30918 | sslutil, | ||
|
r30502 | streamclone, | ||
|
r46477 | strip, | ||
|
r44772 | tags as tagsmod, | ||
|
r30918 | templater, | ||
|
r30517 | treediscovery, | ||
|
r31864 | upgrade, | ||
|
r35578 | url as urlmod, | ||
|
r30516 | util, | ||
|
r31239 | vfs as vfsmod, | ||
|
r37069 | wireprotoframing, | ||
|
r36544 | wireprotoserver, | ||
|
r37738 | wireprotov2peer, | ||
|
r30401 | ) | ||
|
r37102 | from .utils import ( | ||
|
r39480 | cborutil, | ||
r42208 | compression, | |||
|
r37102 | dateutil, | ||
|
r37138 | procutil, | ||
|
r37102 | stringutil, | ||
) | ||||
|
r30401 | |||
r44788 | from .revlogutils import ( | |||
deltas as deltautil, | ||||
nodemap, | ||||
r46257 | sidedata, | |||
r44788 | ) | |||
|
r39366 | |||
|
r30402 | release = lockmod.release | ||
|
r46477 | table = {} | ||
table.update(strip.command._table) | ||||
command = registrar.command(table) | ||||
|
r30401 | |||
|
r43346 | |||
|
r43347 | @command(b'debugancestor', [], _(b'[INDEX] REV1 REV2'), optionalrepo=True) | ||
|
r30401 | def debugancestor(ui, repo, *args): | ||
"""find the ancestor revision of two revisions in a given index""" | ||||
if len(args) == 3: | ||||
index, rev1, rev2 = args | ||||
|
r39843 | r = revlog.revlog(vfsmod.vfs(encoding.getcwd(), audit=False), index) | ||
|
r30401 | lookup = r.lookup | ||
elif len(args) == 2: | ||||
if not repo: | ||||
|
r43346 | raise error.Abort( | ||
|
r43387 | _(b'there is no Mercurial repository here (.hg not found)') | ||
|
r43346 | ) | ||
|
r30401 | rev1, rev2 = args | ||
r = repo.changelog | ||||
lookup = repo.lookup | ||||
else: | ||||
|
r43347 | raise error.Abort(_(b'either two or three arguments required')) | ||
|
r30401 | a = r.ancestor(lookup(rev1), lookup(rev2)) | ||
|
r43347 | ui.write(b'%d:%s\n' % (r.rev(a), hex(a))) | ||
|
r45709 | @command(b'debugantivirusrunning', []) | ||
def debugantivirusrunning(ui, repo): | ||||
"""attempt to trigger an antivirus scanner to see if one is active""" | ||||
with repo.cachevfs.open('eicar-test-file.com', b'wb') as f: | ||||
f.write( | ||||
util.b85decode( | ||||
# This is a base85-armored version of the EICAR test file. See | ||||
# https://en.wikipedia.org/wiki/EICAR_test_file for details. | ||||
b'ST#=}P$fV?P+K%yP+C|uG$>GBDK|qyDK~v2MM*<JQY}+dK~6+LQba95P' | ||||
b'E<)&Nm5l)EmTEQR4qnHOhq9iNGnJx' | ||||
) | ||||
) | ||||
# Give an AV engine time to scan the file. | ||||
time.sleep(2) | ||||
util.unlink(repo.cachevfs.join('eicar-test-file.com')) | ||||
|
r43347 | @command(b'debugapplystreamclonebundle', [], b'FILE') | ||
|
r30541 | def debugapplystreamclonebundle(ui, repo, fname): | ||
"""apply a stream clone bundle file""" | ||||
f = hg.openpath(ui, fname) | ||||
gen = exchange.readbundle(ui, f, fname) | ||||
gen.apply(repo) | ||||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugbuilddag', | ||
|
r43346 | [ | ||
|
r43347 | ( | ||
b'm', | ||||
b'mergeable-file', | ||||
None, | ||||
_(b'add single file mergeable changes'), | ||||
), | ||||
|
r43346 | ( | ||
|
r43347 | b'o', | ||
b'overwritten-file', | ||||
|
r43346 | None, | ||
|
r43347 | _(b'add single file all revs overwrite'), | ||
|
r43346 | ), | ||
|
r43347 | (b'n', b'new-file', None, _(b'add new file at each rev')), | ||
|
r43346 | ], | ||
|
r43347 | _(b'[OPTION]... [TEXT]'), | ||
|
r43346 | ) | ||
def debugbuilddag( | ||||
ui, | ||||
repo, | ||||
text=None, | ||||
mergeable_file=False, | ||||
overwritten_file=False, | ||||
new_file=False, | ||||
): | ||||
|
r30402 | """builds a repo with a given DAG from scratch in the current empty repo | ||
The description of the DAG is read from stdin if not given on the | ||||
command line. | ||||
Elements: | ||||
- "+n" is a linear run of n nodes based on the current default parent | ||||
- "." is a single node based on the current default parent | ||||
- "$" resets the default parent to null (implied at the start); | ||||
otherwise the default parent is always the last node created | ||||
- "<p" sets the default parent to the backref p | ||||
- "*p" is a fork at parent p, which is a backref | ||||
- "*p1/p2" is a merge of parents p1 and p2, which are backrefs | ||||
- "/p2" is a merge of the preceding node and p2 | ||||
- ":tag" defines a local tag for the preceding node | ||||
- "@branch" sets the named branch for subsequent nodes | ||||
- "#...\\n" is a comment up to the end of the line | ||||
Whitespace between the above elements is ignored. | ||||
A backref is either | ||||
- a number n, which references the node curr-n, where curr is the current | ||||
node, or | ||||
- the name of a local tag you placed earlier using ":tag", or | ||||
- empty to denote the default parent. | ||||
All string valued-elements are either strictly alphanumeric, or must | ||||
be enclosed in double quotes ("..."), with "\\" as escape character. | ||||
""" | ||||
if text is None: | ||||
|
r43347 | ui.status(_(b"reading DAG from stdin\n")) | ||
|
r30402 | text = ui.fin.read() | ||
cl = repo.changelog | ||||
if len(cl) > 0: | ||||
|
r43347 | raise error.Abort(_(b'repository is not empty')) | ||
|
r30402 | |||
# determine number of revs in DAG | ||||
total = 0 | ||||
for type, data in dagparser.parsedag(text): | ||||
|
r43347 | if type == b'n': | ||
|
r30402 | total += 1 | ||
if mergeable_file: | ||||
linesperrev = 2 | ||||
# make a file with k lines per rev | ||||
|
r43346 | initialmergedlines = [ | ||
|
r43347 | b'%d' % i for i in pycompat.xrange(0, total * linesperrev) | ||
|
r43346 | ] | ||
|
r43347 | initialmergedlines.append(b"") | ||
|
r30402 | |||
tags = [] | ||||
|
r43347 | progress = ui.makeprogress( | ||
_(b'building'), unit=_(b'revisions'), total=total | ||||
) | ||||
with progress, repo.wlock(), repo.lock(), repo.transaction(b"builddag"): | ||||
|
r30402 | at = -1 | ||
|
r43347 | atbranch = b'default' | ||
|
r30402 | nodeids = [] | ||
id = 0 | ||||
|
r38394 | progress.update(id) | ||
|
r30402 | for type, data in dagparser.parsedag(text): | ||
|
r43347 | if type == b'n': | ||
ui.note((b'node %s\n' % pycompat.bytestr(data))) | ||||
|
r30402 | id, ps = data | ||
files = [] | ||||
|
r35400 | filecontent = {} | ||
|
r30402 | |||
p2 = None | ||||
if mergeable_file: | ||||
|
r43347 | fn = b"mf" | ||
|
r30402 | p1 = repo[ps[0]] | ||
if len(ps) > 1: | ||||
p2 = repo[ps[1]] | ||||
pa = p1.ancestor(p2) | ||||
|
r43346 | base, local, other = [ | ||
x[fn].data() for x in (pa, p1, p2) | ||||
] | ||||
|
r30402 | m3 = simplemerge.Merge3Text(base, local, other) | ||
ml = [l.strip() for l in m3.merge_lines()] | ||||
|
r43347 | ml.append(b"") | ||
|
r30402 | elif at > 0: | ||
|
r43347 | ml = p1[fn].data().split(b"\n") | ||
|
r30402 | else: | ||
ml = initialmergedlines | ||||
|
r43347 | ml[id * linesperrev] += b" r%i" % id | ||
mergedtext = b"\n".join(ml) | ||||
|
r30402 | files.append(fn) | ||
|
r35400 | filecontent[fn] = mergedtext | ||
|
r30402 | |||
if overwritten_file: | ||||
|
r43347 | fn = b"of" | ||
|
r30402 | files.append(fn) | ||
|
r43347 | filecontent[fn] = b"r%i\n" % id | ||
|
r30402 | |||
if new_file: | ||||
|
r43347 | fn = b"nf%i" % id | ||
|
r30402 | files.append(fn) | ||
|
r43347 | filecontent[fn] = b"r%i\n" % id | ||
|
r30402 | if len(ps) > 1: | ||
if not p2: | ||||
p2 = repo[ps[1]] | ||||
for fn in p2: | ||||
|
r43347 | if fn.startswith(b"nf"): | ||
|
r30402 | files.append(fn) | ||
|
r35400 | filecontent[fn] = p2[fn].data() | ||
|
r30402 | |||
def fctxfn(repo, cx, path): | ||||
|
r35400 | if path in filecontent: | ||
|
r43346 | return context.memfilectx( | ||
repo, cx, path, filecontent[path] | ||||
) | ||||
|
r35400 | return None | ||
|
r30402 | |||
if len(ps) == 0 or ps[0] < 0: | ||||
pars = [None, None] | ||||
elif len(ps) == 1: | ||||
pars = [nodeids[ps[0]], None] | ||||
else: | ||||
pars = [nodeids[p] for p in ps] | ||||
|
r43346 | cx = context.memctx( | ||
repo, | ||||
pars, | ||||
|
r43347 | b"r%i" % id, | ||
|
r43346 | files, | ||
fctxfn, | ||||
date=(id, 0), | ||||
|
r43347 | user=b"debugbuilddag", | ||
extra={b'branch': atbranch}, | ||||
|
r43346 | ) | ||
|
r30402 | nodeid = repo.commitctx(cx) | ||
nodeids.append(nodeid) | ||||
at = id | ||||
|
r43347 | elif type == b'l': | ||
|
r30402 | id, name = data | ||
|
r43347 | ui.note((b'tag %s\n' % name)) | ||
tags.append(b"%s %s\n" % (hex(repo.changelog.node(id)), name)) | ||||
elif type == b'a': | ||||
ui.note((b'branch %s\n' % data)) | ||||
|
r30402 | atbranch = data | ||
|
r38394 | progress.update(id) | ||
|
r30402 | |||
if tags: | ||||
|
r43347 | repo.vfs.write(b"localtags", b"".join(tags)) | ||
|
r30501 | |||
|
r43346 | |||
|
r30501 | def _debugchangegroup(ui, gen, all=None, indent=0, **opts): | ||
|
r43347 | indent_string = b' ' * indent | ||
|
r30501 | if all: | ||
|
r43350 | ui.writenoi18n( | ||
|
r43347 | b"%sformat: id, p1, p2, cset, delta base, len(delta)\n" | ||
|
r43346 | % indent_string | ||
) | ||||
|
r30501 | |||
def showchunks(named): | ||||
|
r43347 | ui.write(b"\n%s%s\n" % (indent_string, named)) | ||
|
r34293 | for deltadata in gen.deltaiter(): | ||
node, p1, p2, cs, deltabase, delta, flags = deltadata | ||||
|
r43346 | ui.write( | ||
|
r43347 | b"%s%s %s %s %s %s %d\n" | ||
|
r43346 | % ( | ||
indent_string, | ||||
hex(node), | ||||
hex(p1), | ||||
hex(p2), | ||||
hex(cs), | ||||
hex(deltabase), | ||||
len(delta), | ||||
) | ||||
) | ||||
|
r30501 | |||
|
r44424 | gen.changelogheader() | ||
|
r43347 | showchunks(b"changelog") | ||
|
r44424 | gen.manifestheader() | ||
|
r43347 | showchunks(b"manifest") | ||
|
r30501 | for chunkdata in iter(gen.filelogheader, {}): | ||
|
r43347 | fname = chunkdata[b'filename'] | ||
|
r30501 | showchunks(fname) | ||
else: | ||||
if isinstance(gen, bundle2.unbundle20): | ||||
|
r43347 | raise error.Abort(_(b'use debugbundle2 for this file')) | ||
|
r44424 | gen.changelogheader() | ||
|
r34293 | for deltadata in gen.deltaiter(): | ||
node, p1, p2, cs, deltabase, delta, flags = deltadata | ||||
|
r43347 | ui.write(b"%s%s\n" % (indent_string, hex(node))) | ||
|
r30501 | |||
|
r43346 | |||
|
r33029 | def _debugobsmarkers(ui, part, indent=0, **opts): | ||
r32517 | """display version and markers contained in 'data'""" | |||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r33029 | data = part.read() | ||
|
r43347 | indent_string = b' ' * indent | ||
r32517 | try: | |||
version, markers = obsolete._readmarkers(data) | ||||
except error.UnknownVersion as exc: | ||||
|
r43347 | msg = b"%sunsupported version: %s (%d bytes)\n" | ||
r32517 | msg %= indent_string, exc.version, len(data) | |||
ui.write(msg) | ||||
else: | ||||
|
r43347 | msg = b"%sversion: %d (%d bytes)\n" | ||
r32517 | msg %= indent_string, version, len(data) | |||
ui.write(msg) | ||||
|
r43347 | fm = ui.formatter(b'debugobsolete', opts) | ||
r32517 | for rawmarker in sorted(markers): | |||
r33149 | m = obsutil.marker(None, rawmarker) | |||
r32517 | fm.startitem() | |||
fm.plain(indent_string) | ||||
cmdutil.showmarker(fm, m) | ||||
fm.end() | ||||
|
r43346 | |||
|
r33031 | def _debugphaseheads(ui, data, indent=0): | ||
"""display version and markers contained in 'data'""" | ||||
|
r43347 | indent_string = b' ' * indent | ||
|
r34321 | headsbyphase = phases.binarydecode(data) | ||
|
r33031 | for phase in phases.allphases: | ||
for head in headsbyphase[phase]: | ||||
ui.write(indent_string) | ||||
|
r43347 | ui.write(b'%s %s\n' % (hex(head), phases.phasenames[phase])) | ||
|
r33031 | |||
|
r43346 | |||
|
r34027 | def _quasirepr(thing): | ||
if isinstance(thing, (dict, util.sortdict, collections.OrderedDict)): | ||||
|
r43347 | return b'{%s}' % ( | ||
|
r43346 | b', '.join(b'%s: %s' % (k, thing[k]) for k in sorted(thing)) | ||
) | ||||
|
r34027 | return pycompat.bytestr(repr(thing)) | ||
|
r43346 | |||
|
r30501 | def _debugbundle2(ui, gen, all=None, **opts): | ||
"""lists the contents of a bundle2""" | ||||
if not isinstance(gen, bundle2.unbundle20): | ||||
|
r43347 | raise error.Abort(_(b'not a bundle2 file')) | ||
ui.write((b'Stream params: %s\n' % _quasirepr(gen.params))) | ||||
|
r43906 | parttypes = opts.get('part_type', []) | ||
|
r30501 | for part in gen.iterparts(): | ||
|
r32694 | if parttypes and part.type not in parttypes: | ||
continue | ||||
|
r43347 | msg = b'%s -- %s (mandatory: %r)\n' | ||
|
r37919 | ui.write((msg % (part.type, _quasirepr(part.params), part.mandatory))) | ||
|
r43347 | if part.type == b'changegroup': | ||
version = part.params.get(b'version', b'01') | ||||
cg = changegroup.getunbundler(version, part, b'UN') | ||||
|
r36969 | if not ui.quiet: | ||
_debugchangegroup(ui, cg, all=all, indent=4, **opts) | ||||
|
r43347 | if part.type == b'obsmarkers': | ||
|
r36969 | if not ui.quiet: | ||
_debugobsmarkers(ui, part, indent=4, **opts) | ||||
|
r43347 | if part.type == b'phase-heads': | ||
|
r36969 | if not ui.quiet: | ||
_debugphaseheads(ui, part, indent=4) | ||||
|
r30502 | |||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugbundle', | ||
|
r43346 | [ | ||
|
r43347 | (b'a', b'all', None, _(b'show all details')), | ||
(b'', b'part-type', [], _(b'show only the named part type')), | ||||
(b'', b'spec', None, _(b'print the bundlespec of the bundle')), | ||||
|
r43346 | ], | ||
|
r43347 | _(b'FILE'), | ||
|
r43346 | norepo=True, | ||
) | ||||
|
r30541 | def debugbundle(ui, bundlepath, all=None, spec=None, **opts): | ||
"""lists the contents of a bundle""" | ||||
with hg.openpath(ui, bundlepath) as f: | ||||
if spec: | ||||
spec = exchange.getbundlespec(ui, f) | ||||
|
r43347 | ui.write(b'%s\n' % spec) | ||
|
r30541 | return | ||
|
r30502 | |||
|
r30541 | gen = exchange.readbundle(ui, f, bundlepath) | ||
if isinstance(gen, bundle2.unbundle20): | ||||
return _debugbundle2(ui, gen, all=all, **opts) | ||||
_debugchangegroup(ui, gen, all=all, **opts) | ||||
|
r30503 | |||
|
r43346 | |||
|
r43347 | @command(b'debugcapabilities', [], _(b'PATH'), norepo=True) | ||
|
r34960 | def debugcapabilities(ui, path, **opts): | ||
"""lists the capabilities of a remote peer""" | ||||
|
r35402 | opts = pycompat.byteskwargs(opts) | ||
|
r34960 | peer = hg.peer(ui, opts, path) | ||
caps = peer.capabilities() | ||||
|
r43350 | ui.writenoi18n(b'Main capabilities:\n') | ||
|
r34960 | for c in sorted(caps): | ||
|
r43347 | ui.write(b' %s\n' % c) | ||
|
r34961 | b2caps = bundle2.bundle2caps(peer) | ||
if b2caps: | ||||
|
r43350 | ui.writenoi18n(b'Bundle2 capabilities:\n') | ||
|
r43376 | for key, values in sorted(pycompat.iteritems(b2caps)): | ||
|
r43347 | ui.write(b' %s\n' % key) | ||
|
r34961 | for v in values: | ||
|
r43347 | ui.write(b' %s\n' % v) | ||
r46257 | @command(b'debugchangedfiles', [], b'REV') | |||
def debugchangedfiles(ui, repo, rev): | ||||
"""list the stored files changes for a revision""" | ||||
ctx = scmutil.revsingle(repo, rev, None) | ||||
sd = repo.changelog.sidedata(ctx.rev()) | ||||
files_block = sd.get(sidedata.SD_FILES) | ||||
if files_block is not None: | ||||
files = metadata.decode_files_sidedata(sd) | ||||
for f in sorted(files.touched): | ||||
if f in files.added: | ||||
action = b"added" | ||||
elif f in files.removed: | ||||
action = b"removed" | ||||
elif f in files.merged: | ||||
action = b"merged" | ||||
elif f in files.salvaged: | ||||
action = b"salvaged" | ||||
else: | ||||
action = b"touched" | ||||
copy_parent = b"" | ||||
copy_source = b"" | ||||
if f in files.copied_from_p1: | ||||
copy_parent = b"p1" | ||||
copy_source = files.copied_from_p1[f] | ||||
elif f in files.copied_from_p2: | ||||
copy_parent = b"p2" | ||||
copy_source = files.copied_from_p2[f] | ||||
data = (action, copy_parent, f, copy_source) | ||||
template = b"%-8s %2s: %s, %s;\n" | ||||
ui.write(template % data) | ||||
|
r43347 | @command(b'debugcheckstate', [], b'') | ||
|
r30503 | def debugcheckstate(ui, repo): | ||
"""validate the correctness of the current dirstate""" | ||||
parent1, parent2 = repo.dirstate.parents() | ||||
m1 = repo[parent1].manifest() | ||||
m2 = repo[parent2].manifest() | ||||
errors = 0 | ||||
for f in repo.dirstate: | ||||
state = repo.dirstate[f] | ||||
|
r43347 | if state in b"nr" and f not in m1: | ||
ui.warn(_(b"%s in state %s, but not in manifest1\n") % (f, state)) | ||||
|
r30503 | errors += 1 | ||
|
r43347 | if state in b"a" and f in m1: | ||
ui.warn(_(b"%s in state %s, but also in manifest1\n") % (f, state)) | ||||
|
r30503 | errors += 1 | ||
|
r43347 | if state in b"m" and f not in m1 and f not in m2: | ||
|
r43346 | ui.warn( | ||
|
r43347 | _(b"%s in state %s, but not in either manifest\n") % (f, state) | ||
|
r43346 | ) | ||
|
r30503 | errors += 1 | ||
for f in m1: | ||||
state = repo.dirstate[f] | ||||
|
r43347 | if state not in b"nrm": | ||
ui.warn(_(b"%s in manifest1, but listed as state %s") % (f, state)) | ||||
|
r30503 | errors += 1 | ||
if errors: | ||||
|
r44034 | errstr = _(b".hg/dirstate inconsistent with current parent's manifest") | ||
raise error.Abort(errstr) | ||||
|
r30504 | |||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugcolor', | ||
[(b'', b'style', None, _(b'show all configured styles'))], | ||||
b'hg debugcolor', | ||||
|
r43346 | ) | ||
|
r31120 | def debugcolor(ui, repo, **opts): | ||
"""show available color, effects or style""" | ||||
|
r43350 | ui.writenoi18n(b'color mode: %s\n' % stringutil.pprint(ui._colormode)) | ||
|
r43906 | if opts.get('style'): | ||
|
r31120 | return _debugdisplaystyle(ui) | ||
else: | ||||
return _debugdisplaycolor(ui) | ||||
|
r43346 | |||
|
r31120 | def _debugdisplaycolor(ui): | ||
|
r31121 | ui = ui.copy() | ||
ui._styles.clear() | ||||
|
r31689 | for effect in color._activeeffects(ui).keys(): | ||
|
r31121 | ui._styles[effect] = effect | ||
if ui._terminfoparams: | ||||
|
r43347 | for k, v in ui.configitems(b'color'): | ||
if k.startswith(b'color.'): | ||||
|
r31121 | ui._styles[k] = k[6:] | ||
|
r43347 | elif k.startswith(b'terminfo.'): | ||
|
r31121 | ui._styles[k] = k[9:] | ||
|
r43347 | ui.write(_(b'available colors:\n')) | ||
|
r31121 | # sort label with a '_' after the other to group '_background' entry. | ||
|
r43347 | items = sorted(ui._styles.items(), key=lambda i: (b'_' in i[0], i[0], i[1])) | ||
|
r31121 | for colorname, label in items: | ||
|
r43347 | ui.write(b'%s\n' % colorname, label=label) | ||
|
r43346 | |||
|
r31120 | |||
def _debugdisplaystyle(ui): | ||||
|
r43347 | ui.write(_(b'available style:\n')) | ||
|
r37841 | if not ui._styles: | ||
return | ||||
|
r31120 | width = max(len(s) for s in ui._styles) | ||
for label, effects in sorted(ui._styles.items()): | ||||
|
r43347 | ui.write(b'%s' % label, label=label) | ||
|
r31120 | if effects: | ||
# 50 | ||||
|
r43347 | ui.write(b': ') | ||
ui.write(b' ' * (max(0, width - len(label)))) | ||||
ui.write(b', '.join(ui.label(e, e) for e in effects.split())) | ||||
ui.write(b'\n') | ||||
@command(b'debugcreatestreamclonebundle', [], b'FILE') | ||||
|
r30541 | def debugcreatestreamclonebundle(ui, repo, fname): | ||
"""create a stream clone bundle file | ||||
Stream bundles are special bundles that are essentially archives of | ||||
revlog files. They are commonly used for cloning very quickly. | ||||
""" | ||||
|
r32745 | # TODO we may want to turn this into an abort when this functionality | ||
# is moved into `hg bundle`. | ||||
if phases.hassecret(repo): | ||||
|
r43346 | ui.warn( | ||
_( | ||||
|
r43347 | b'(warning: stream clone bundle will contain secret ' | ||
b'revisions)\n' | ||||
|
r43346 | ) | ||
) | ||||
|
r32745 | |||
|
r30541 | requirements, gen = streamclone.generatebundlev1(repo) | ||
changegroup.writechunks(ui, gen, fname) | ||||
|
r43347 | ui.write(_(b'bundle requirements: %s\n') % b', '.join(sorted(requirements))) | ||
|
r30541 | |||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugdag', | ||
|
r43346 | [ | ||
|
r43347 | (b't', b'tags', None, _(b'use tags as labels')), | ||
(b'b', b'branches', None, _(b'annotate with branch names')), | ||||
(b'', b'dots', None, _(b'use dots for runs')), | ||||
(b's', b'spaces', None, _(b'separate elements by spaces')), | ||||
|
r43346 | ], | ||
|
r43347 | _(b'[OPTION]... [FILE [REV]...]'), | ||
|
r43346 | optionalrepo=True, | ||
) | ||||
|
r30514 | def debugdag(ui, repo, file_=None, *revs, **opts): | ||
"""format the changelog or an index DAG as a concise textual description | ||||
If you pass a revlog index, the revlog's DAG is emitted. If you list | ||||
revision numbers, they get labeled in the output as rN. | ||||
Otherwise, the changelog DAG of the current repo is emitted. | ||||
""" | ||||
|
r43906 | spaces = opts.get('spaces') | ||
dots = opts.get('dots') | ||||
|
r30514 | if file_: | ||
|
r43346 | rlog = revlog.revlog(vfsmod.vfs(encoding.getcwd(), audit=False), file_) | ||
|
r44937 | revs = {int(r) for r in revs} | ||
|
r43346 | |||
|
r30514 | def events(): | ||
for r in rlog: | ||||
|
r43347 | yield b'n', (r, list(p for p in rlog.parentrevs(r) if p != -1)) | ||
|
r30514 | if r in revs: | ||
|
r43347 | yield b'l', (r, b"r%i" % r) | ||
|
r43346 | |||
|
r30514 | elif repo: | ||
cl = repo.changelog | ||||
|
r43906 | tags = opts.get('tags') | ||
branches = opts.get('branches') | ||||
|
r30514 | if tags: | ||
labels = {} | ||||
for l, n in repo.tags().items(): | ||||
labels.setdefault(cl.rev(n), []).append(l) | ||||
|
r43346 | |||
|
r30514 | def events(): | ||
|
r43347 | b = b"default" | ||
|
r30514 | for r in cl: | ||
if branches: | ||||
|
r43347 | newb = cl.read(cl.node(r))[5][b'branch'] | ||
|
r30514 | if newb != b: | ||
|
r43347 | yield b'a', newb | ||
|
r30514 | b = newb | ||
|
r43347 | yield b'n', (r, list(p for p in cl.parentrevs(r) if p != -1)) | ||
|
r30514 | if tags: | ||
ls = labels.get(r) | ||||
if ls: | ||||
for l in ls: | ||||
|
r43347 | yield b'l', (r, l) | ||
|
r43346 | |||
|
r30514 | else: | ||
|
r43347 | raise error.Abort(_(b'need repo for changelog dag')) | ||
|
r30514 | |||
|
r43346 | for line in dagparser.dagtextlines( | ||
events(), | ||||
addspaces=spaces, | ||||
wraplabels=True, | ||||
wrapannotations=True, | ||||
wrapnonlinear=dots, | ||||
usedots=dots, | ||||
maxlinewidth=70, | ||||
): | ||||
|
r30514 | ui.write(line) | ||
|
r43347 | ui.write(b"\n") | ||
@command(b'debugdata', cmdutil.debugrevlogopts, _(b'-c|-m|FILE REV')) | ||||
|
r30515 | def debugdata(ui, repo, file_, rev=None, **opts): | ||
"""dump the contents of a data file revision""" | ||||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r43347 | if opts.get(b'changelog') or opts.get(b'manifest') or opts.get(b'dir'): | ||
|
r30515 | if rev is not None: | ||
|
r43347 | raise error.CommandError(b'debugdata', _(b'invalid arguments')) | ||
|
r30515 | file_, rev = None, file_ | ||
elif rev is None: | ||||
|
r43347 | raise error.CommandError(b'debugdata', _(b'invalid arguments')) | ||
r = cmdutil.openstorage(repo, b'debugdata', file_, opts) | ||||
|
r30515 | try: | ||
r43041 | ui.write(r.rawdata(r.lookup(rev))) | |||
|
r30515 | except KeyError: | ||
|
r43347 | raise error.Abort(_(b'invalid revision identifier %s') % rev) | ||
|
r30516 | |||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugdate', | ||
[(b'e', b'extended', None, _(b'try extended date formats'))], | ||||
_(b'[-e] DATE [RANGE]'), | ||||
|
r43346 | norepo=True, | ||
optionalrepo=True, | ||||
) | ||||
|
r30516 | def debugdate(ui, date, range=None, **opts): | ||
"""parse and display a date""" | ||||
|
r43809 | if opts["extended"]: | ||
|
r44330 | d = dateutil.parsedate(date, dateutil.extendeddateformats) | ||
|
r30516 | else: | ||
|
r36625 | d = dateutil.parsedate(date) | ||
|
r43350 | ui.writenoi18n(b"internal: %d %d\n" % d) | ||
ui.writenoi18n(b"standard: %s\n" % dateutil.datestr(d)) | ||||
|
r30516 | if range: | ||
|
r36625 | m = dateutil.matchdate(range) | ||
|
r43350 | ui.writenoi18n(b"match: %s\n" % m(d[0])) | ||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugdeltachain', | ||
|
r32375 | cmdutil.debugrevlogopts + cmdutil.formatteropts, | ||
|
r43347 | _(b'-c|-m|FILE'), | ||
|
r43346 | optionalrepo=True, | ||
) | ||||
|
r30541 | def debugdeltachain(ui, repo, file_=None, **opts): | ||
"""dump information about delta chains in a revlog | ||||
Output can be templatized. Available template keywords are: | ||||
:``rev``: revision number | ||||
:``chainid``: delta chain identifier (numbered by unique base) | ||||
:``chainlen``: delta chain length to this revision | ||||
:``prevrev``: previous revision in delta chain | ||||
:``deltatype``: role of delta / how it was computed | ||||
:``compsize``: compressed size of revision | ||||
:``uncompsize``: uncompressed size of revision | ||||
:``chainsize``: total size of compressed revisions in chain | ||||
:``chainratio``: total chain size divided by uncompressed revision size | ||||
(new delta chains typically start at ratio 2.00) | ||||
:``lindist``: linear distance from base revision in delta chain to end | ||||
of this revision | ||||
:``extradist``: total size of revisions not part of this delta chain from | ||||
base of delta chain to end of this revision; a measurement | ||||
of how much extra data we need to read/seek across to read | ||||
the delta chain for this revision | ||||
:``extraratio``: extradist divided by chainsize; another representation of | ||||
how much unrelated data is needed to load this delta chain | ||||
|
r35050 | |||
If the repository is configured to use the sparse read, additional keywords | ||||
are available: | ||||
:``readsize``: total size of data read from the disk for a revision | ||||
(sum of the sizes of all the blocks) | ||||
:``largestblock``: size of the largest block of data read from the disk | ||||
:``readdensity``: density of useful bytes in the data read from the disk | ||||
|
r35696 | :``srchunks``: in how many data hunks the whole revision would be read | ||
|
r35050 | |||
The sparse read can be enabled with experimental.sparse-read = True | ||||
|
r30541 | """ | ||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r43347 | r = cmdutil.openrevlog(repo, b'debugdeltachain', file_, opts) | ||
|
r30541 | index = r.index | ||
|
r38127 | start = r.start | ||
length = r.length | ||||
|
r32316 | generaldelta = r.version & revlog.FLAG_GENERALDELTA | ||
|
r35050 | withsparseread = getattr(r, '_withsparseread', False) | ||
|
r30541 | |||
def revinfo(rev): | ||||
e = index[rev] | ||||
compsize = e[1] | ||||
uncompsize = e[2] | ||||
chainsize = 0 | ||||
if generaldelta: | ||||
if e[3] == e[5]: | ||||
|
r43347 | deltatype = b'p1' | ||
|
r30541 | elif e[3] == e[6]: | ||
|
r43347 | deltatype = b'p2' | ||
|
r30541 | elif e[3] == rev - 1: | ||
|
r43347 | deltatype = b'prev' | ||
|
r30541 | elif e[3] == rev: | ||
|
r43347 | deltatype = b'base' | ||
|
r30541 | else: | ||
|
r43347 | deltatype = b'other' | ||
|
r30541 | else: | ||
if e[3] == rev: | ||||
|
r43347 | deltatype = b'base' | ||
|
r30541 | else: | ||
|
r43347 | deltatype = b'prev' | ||
|
r30541 | |||
chain = r._deltachain(rev)[0] | ||||
for iterrev in chain: | ||||
e = index[iterrev] | ||||
chainsize += e[1] | ||||
return compsize, uncompsize, deltatype, chain, chainsize | ||||
|
r43347 | fm = ui.formatter(b'debugdeltachain', opts) | ||
|
r30541 | |||
|
r43346 | fm.plain( | ||
|
r43347 | b' rev chain# chainlen prev delta ' | ||
b'size rawsize chainsize ratio lindist extradist ' | ||||
b'extraratio' | ||||
|
r43346 | ) | ||
|
r35050 | if withsparseread: | ||
|
r43347 | fm.plain(b' readsize largestblk rddensity srchunks') | ||
fm.plain(b'\n') | ||||
|
r30541 | |||
chainbases = {} | ||||
for rev in r: | ||||
comp, uncomp, deltatype, chain, chainsize = revinfo(rev) | ||||
chainbase = chain[0] | ||||
chainid = chainbases.setdefault(chainbase, len(chainbases) + 1) | ||||
|
r35050 | basestart = start(chainbase) | ||
revstart = start(rev) | ||||
|
r30541 | lineardist = revstart + comp - basestart | ||
extradist = lineardist - chainsize | ||||
try: | ||||
prevrev = chain[-2] | ||||
except IndexError: | ||||
prevrev = -1 | ||||
|
r38668 | if uncomp != 0: | ||
chainratio = float(chainsize) / float(uncomp) | ||||
else: | ||||
chainratio = chainsize | ||||
if chainsize != 0: | ||||
extraratio = float(extradist) / float(chainsize) | ||||
else: | ||||
extraratio = extradist | ||||
|
r30541 | |||
fm.startitem() | ||||
|
r43346 | fm.write( | ||
|
r43347 | b'rev chainid chainlen prevrev deltatype compsize ' | ||
b'uncompsize chainsize chainratio lindist extradist ' | ||||
b'extraratio', | ||||
b'%7d %7d %8d %8d %7s %10d %10d %10d %9.5f %9d %9d %10.5f', | ||||
|
r43346 | rev, | ||
chainid, | ||||
len(chain), | ||||
prevrev, | ||||
deltatype, | ||||
comp, | ||||
uncomp, | ||||
chainsize, | ||||
chainratio, | ||||
lineardist, | ||||
extradist, | ||||
extraratio, | ||||
rev=rev, | ||||
chainid=chainid, | ||||
chainlen=len(chain), | ||||
prevrev=prevrev, | ||||
deltatype=deltatype, | ||||
compsize=comp, | ||||
uncompsize=uncomp, | ||||
chainsize=chainsize, | ||||
chainratio=chainratio, | ||||
lindist=lineardist, | ||||
extradist=extradist, | ||||
extraratio=extraratio, | ||||
) | ||||
|
r35050 | if withsparseread: | ||
readsize = 0 | ||||
largestblock = 0 | ||||
|
r35746 | srchunks = 0 | ||
|
r39366 | for revschunk in deltautil.slicechunk(r, chain): | ||
|
r35746 | srchunks += 1 | ||
|
r35050 | blkend = start(revschunk[-1]) + length(revschunk[-1]) | ||
blksize = blkend - start(revschunk[0]) | ||||
readsize += blksize | ||||
if largestblock < blksize: | ||||
largestblock = blksize | ||||
|
r38669 | if readsize: | ||
readdensity = float(chainsize) / float(readsize) | ||||
else: | ||||
readdensity = 1 | ||||
|
r35050 | |||
|
r43346 | fm.write( | ||
|
r43347 | b'readsize largestblock readdensity srchunks', | ||
b' %10d %10d %9.5f %8d', | ||||
|
r43346 | readsize, | ||
largestblock, | ||||
readdensity, | ||||
srchunks, | ||||
readsize=readsize, | ||||
largestblock=largestblock, | ||||
readdensity=readdensity, | ||||
srchunks=srchunks, | ||||
) | ||||
|
r35050 | |||
|
r43347 | fm.plain(b'\n') | ||
|
r30541 | |||
fm.end() | ||||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugdirstate|debugstate', | ||
|
r43346 | [ | ||
|
r43347 | ( | ||
b'', | ||||
b'nodates', | ||||
None, | ||||
_(b'do not display the saved mtime (DEPRECATED)'), | ||||
), | ||||
(b'', b'dates', True, _(b'display the saved mtime')), | ||||
(b'', b'datesort', None, _(b'sort by saved mtime')), | ||||
|
r43346 | ], | ||
|
r43347 | _(b'[OPTION]...'), | ||
|
r43346 | ) | ||
|
r30954 | def debugstate(ui, repo, **opts): | ||
"""show the contents of the current dirstate""" | ||||
|
r43906 | nodates = not opts['dates'] | ||
if opts.get('nodates') is not None: | ||||
|
r39796 | nodates = True | ||
|
r43906 | datesort = opts.get('datesort') | ||
|
r30954 | |||
if datesort: | ||||
|
r43346 | keyfunc = lambda x: (x[1][3], x[0]) # sort by mtime, then by filename | ||
|
r30954 | else: | ||
|
r43346 | keyfunc = None # sort by filename | ||
|
r43376 | for file_, ent in sorted(pycompat.iteritems(repo.dirstate), key=keyfunc): | ||
|
r30954 | if ent[3] == -1: | ||
|
r43347 | timestr = b'unset ' | ||
|
r30954 | elif nodates: | ||
|
r43347 | timestr = b'set ' | ||
|
r30954 | else: | ||
|
r43346 | timestr = time.strftime( | ||
|
r43809 | "%Y-%m-%d %H:%M:%S ", time.localtime(ent[3]) | ||
|
r43346 | ) | ||
|
r35205 | timestr = encoding.strtolocal(timestr) | ||
|
r30954 | if ent[1] & 0o20000: | ||
|
r43347 | mode = b'lnk' | ||
|
r30954 | else: | ||
|
r43347 | mode = b'%3o' % (ent[1] & 0o777 & ~util.umask) | ||
ui.write(b"%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_)) | ||||
|
r30954 | for f in repo.dirstate.copies(): | ||
|
r43347 | ui.write(_(b"copy: %s -> %s\n") % (repo.dirstate.copied(f), f)) | ||
|
r30954 | |||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugdiscovery', | ||
|
r43346 | [ | ||
|
r43347 | (b'', b'old', None, _(b'use old-style discovery')), | ||
|
r43346 | ( | ||
|
r43347 | b'', | ||
b'nonheads', | ||||
|
r43346 | None, | ||
|
r43347 | _(b'use old-style discovery with non-heads included'), | ||
|
r43346 | ), | ||
|
r43347 | (b'', b'rev', [], b'restrict discovery to this set of revs'), | ||
(b'', b'seed', b'12323', b'specify the random seed use for discovery'), | ||||
|
r43346 | ] | ||
+ cmdutil.remoteopts, | ||||
|
r43347 | _(b'[--rev REV] [OTHER]'), | ||
|
r43346 | ) | ||
|
r43347 | def debugdiscovery(ui, repo, remoteurl=b"default", **opts): | ||
|
r30517 | """runs the changeset discovery protocol in isolation""" | ||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r35418 | remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl)) | ||
|
r30517 | remote = hg.peer(repo, opts, remoteurl) | ||
|
r43347 | ui.status(_(b'comparing with %s\n') % util.hidepassword(remoteurl)) | ||
|
r30517 | |||
# make sure tests are repeatable | ||||
|
r43347 | random.seed(int(opts[b'seed'])) | ||
if opts.get(b'old'): | ||||
|
r43346 | |||
r42198 | def doit(pushedrevs, remoteheads, remote=remote): | |||
|
r43347 | if not util.safehasattr(remote, b'branches'): | ||
|
r30517 | # enable in-client legacy support | ||
remote = localrepo.locallegacypeer(remote.local()) | ||||
|
r43346 | common, _in, hds = treediscovery.findcommonincoming( | ||
repo, remote, force=True | ||||
) | ||||
|
r30517 | common = set(common) | ||
|
r43347 | if not opts.get(b'nonheads'): | ||
|
r43350 | ui.writenoi18n( | ||
|
r43347 | b"unpruned common: %s\n" | ||
% b" ".join(sorted(short(n) for n in common)) | ||||
|
r43346 | ) | ||
|
r39199 | |||
clnode = repo.changelog.node | ||||
|
r43347 | common = repo.revs(b'heads(::%ln)', common) | ||
|
r39199 | common = {clnode(r) for r in common} | ||
r42198 | return common, hds | |||
|
r43346 | |||
r42198 | else: | |||
|
r43346 | |||
r42198 | def doit(pushedrevs, remoteheads, remote=remote): | |||
|
r35305 | nodes = None | ||
if pushedrevs: | ||||
revs = scmutil.revrange(repo, pushedrevs) | ||||
nodes = [repo[r].node() for r in revs] | ||||
|
r43346 | common, any, hds = setdiscovery.findcommonheads( | ||
ui, repo, remote, ancestorsof=nodes | ||||
) | ||||
r42198 | return common, hds | |||
|
r30517 | |||
|
r35420 | remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, revs=None) | ||
|
r43347 | localrevs = opts[b'rev'] | ||
|
r43532 | with util.timedcm('debug-discovery') as t: | ||
r42202 | common, hds = doit(localrevs, remoterevs) | |||
r42198 | ||||
r42199 | # compute all statistics | |||
r46678 | heads_common = set(common) | |||
heads_remote = set(hds) | ||||
heads_local = set(repo.heads()) | ||||
# note: they cannot be a local or remote head that is in common and not | ||||
# itself a head of common. | ||||
heads_common_local = heads_common & heads_local | ||||
heads_common_remote = heads_common & heads_remote | ||||
heads_common_both = heads_common & heads_remote & heads_local | ||||
all = repo.revs(b'all()') | ||||
common = repo.revs(b'::%ln', common) | ||||
r46692 | roots_common = repo.revs(b'roots(::%ld)', common) | |||
r46678 | missing = repo.revs(b'not ::%ld', common) | |||
r46692 | heads_missing = repo.revs(b'heads(%ld)', missing) | |||
roots_missing = repo.revs(b'roots(%ld)', missing) | ||||
r46678 | assert len(common) + len(missing) == len(all) | |||
r42199 | ||||
r46693 | initial_undecided = repo.revs( | |||
b'not (::%ln or %ln::)', heads_common_remote, heads_common_local | ||||
) | ||||
heads_initial_undecided = repo.revs(b'heads(%ld)', initial_undecided) | ||||
roots_initial_undecided = repo.revs(b'roots(%ld)', initial_undecided) | ||||
common_initial_undecided = initial_undecided & common | ||||
missing_initial_undecided = initial_undecided & missing | ||||
r42199 | data = {} | |||
|
r43347 | data[b'elapsed'] = t.elapsed | ||
r46678 | data[b'nb-common-heads'] = len(heads_common) | |||
data[b'nb-common-heads-local'] = len(heads_common_local) | ||||
data[b'nb-common-heads-remote'] = len(heads_common_remote) | ||||
data[b'nb-common-heads-both'] = len(heads_common_both) | ||||
r46692 | data[b'nb-common-roots'] = len(roots_common) | |||
r46678 | data[b'nb-head-local'] = len(heads_local) | |||
data[b'nb-head-local-missing'] = len(heads_local) - len(heads_common_local) | ||||
data[b'nb-head-remote'] = len(heads_remote) | ||||
data[b'nb-head-remote-unknown'] = len(heads_remote) - len( | ||||
heads_common_remote | ||||
r46677 | ) | |||
r46678 | data[b'nb-revs'] = len(all) | |||
data[b'nb-revs-common'] = len(common) | ||||
data[b'nb-revs-missing'] = len(missing) | ||||
r46692 | data[b'nb-missing-heads'] = len(roots_missing) | |||
data[b'nb-missing-roots'] = len(heads_missing) | ||||
r46693 | data[b'nb-ini_und'] = len(initial_undecided) | |||
data[b'nb-ini_und-heads'] = len(heads_initial_undecided) | ||||
data[b'nb-ini_und-roots'] = len(roots_initial_undecided) | ||||
data[b'nb-ini_und-common'] = len(common_initial_undecided) | ||||
data[b'nb-ini_und-missing'] = len(missing_initial_undecided) | ||||
r42199 | ||||
# display discovery summary | ||||
|
r43350 | ui.writenoi18n(b"elapsed time: %(elapsed)f seconds\n" % data) | ||
ui.writenoi18n(b"heads summary:\n") | ||||
r46677 | ui.writenoi18n(b" total common heads: %(nb-common-heads)9d\n" % data) | |||
ui.writenoi18n( | ||||
b" also local heads: %(nb-common-heads-local)9d\n" % data | ||||
) | ||||
ui.writenoi18n( | ||||
b" also remote heads: %(nb-common-heads-remote)9d\n" % data | ||||
) | ||||
ui.writenoi18n(b" both: %(nb-common-heads-both)9d\n" % data) | ||||
ui.writenoi18n(b" local heads: %(nb-head-local)9d\n" % data) | ||||
ui.writenoi18n( | ||||
b" common: %(nb-common-heads-local)9d\n" % data | ||||
) | ||||
ui.writenoi18n( | ||||
b" missing: %(nb-head-local-missing)9d\n" % data | ||||
) | ||||
ui.writenoi18n(b" remote heads: %(nb-head-remote)9d\n" % data) | ||||
ui.writenoi18n( | ||||
b" common: %(nb-common-heads-remote)9d\n" % data | ||||
) | ||||
ui.writenoi18n( | ||||
b" unknown: %(nb-head-remote-unknown)9d\n" % data | ||||
) | ||||
|
r43350 | ui.writenoi18n(b"local changesets: %(nb-revs)9d\n" % data) | ||
ui.writenoi18n(b" common: %(nb-revs-common)9d\n" % data) | ||||
r46692 | ui.writenoi18n(b" heads: %(nb-common-heads)9d\n" % data) | |||
ui.writenoi18n(b" roots: %(nb-common-roots)9d\n" % data) | ||||
|
r43350 | ui.writenoi18n(b" missing: %(nb-revs-missing)9d\n" % data) | ||
r46692 | ui.writenoi18n(b" heads: %(nb-missing-heads)9d\n" % data) | |||
ui.writenoi18n(b" roots: %(nb-missing-roots)9d\n" % data) | ||||
r46693 | ui.writenoi18n(b" first undecided set: %(nb-ini_und)9d\n" % data) | |||
ui.writenoi18n(b" heads: %(nb-ini_und-heads)9d\n" % data) | ||||
ui.writenoi18n(b" roots: %(nb-ini_und-roots)9d\n" % data) | ||||
ui.writenoi18n(b" common: %(nb-ini_und-common)9d\n" % data) | ||||
ui.writenoi18n(b" missing: %(nb-ini_und-missing)9d\n" % data) | ||||
r42199 | ||||
r42201 | if ui.verbose: | |||
|
r43350 | ui.writenoi18n( | ||
r46678 | b"common heads: %s\n" | |||
% b" ".join(sorted(short(n) for n in heads_common)) | ||||
|
r43346 | ) | ||
|
r30518 | |||
|
r35578 | _chunksize = 4 << 10 | ||
|
r43346 | |||
|
r43347 | @command( | ||
|
r46554 | b'debugdownload', | ||
[ | ||||
(b'o', b'output', b'', _(b'path')), | ||||
], | ||||
optionalrepo=True, | ||||
|
r43347 | ) | ||
|
r35748 | def debugdownload(ui, repo, url, output=None, **opts): | ||
|
r46554 | """download a resource using Mercurial logic and config""" | ||
|
r35578 | fh = urlmod.open(ui, url, output) | ||
dest = ui | ||||
if output: | ||||
|
r43347 | dest = open(output, b"wb", _chunksize) | ||
|
r35578 | try: | ||
data = fh.read(_chunksize) | ||||
while data: | ||||
dest.write(data) | ||||
data = fh.read(_chunksize) | ||||
finally: | ||||
if output: | ||||
dest.close() | ||||
|
r43346 | |||
|
r43347 | @command(b'debugextensions', cmdutil.formatteropts, [], optionalrepo=True) | ||
|
r37998 | def debugextensions(ui, repo, **opts): | ||
|
r30518 | '''show information about active extensions''' | ||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r30518 | exts = extensions.extensions(ui) | ||
hgver = util.version() | ||||
|
r43347 | fm = ui.formatter(b'debugextensions', opts) | ||
|
r30518 | for extname, extmod in sorted(exts, key=operator.itemgetter(0)): | ||
isinternal = extensions.ismoduleinternal(extmod) | ||||
|
r44084 | extsource = None | ||
if util.safehasattr(extmod, '__file__'): | ||||
extsource = pycompat.fsencode(extmod.__file__) | ||||
elif getattr(sys, 'oxidized', False): | ||||
extsource = pycompat.sysexecutable | ||||
|
r30518 | if isinternal: | ||
exttestedwith = [] # never expose magic string to users | ||||
else: | ||||
|
r43347 | exttestedwith = getattr(extmod, 'testedwith', b'').split() | ||
|
r30518 | extbuglink = getattr(extmod, 'buglink', None) | ||
fm.startitem() | ||||
if ui.quiet or ui.verbose: | ||||
|
r43347 | fm.write(b'name', b'%s\n', extname) | ||
|
r30518 | else: | ||
|
r43347 | fm.write(b'name', b'%s', extname) | ||
|
r30518 | if isinternal or hgver in exttestedwith: | ||
|
r43347 | fm.plain(b'\n') | ||
|
r30518 | elif not exttestedwith: | ||
|
r43347 | fm.plain(_(b' (untested!)\n')) | ||
|
r30518 | else: | ||
lasttestedversion = exttestedwith[-1] | ||||
|
r43347 | fm.plain(b' (%s!)\n' % lasttestedversion) | ||
|
r30518 | |||
|
r43346 | fm.condwrite( | ||
ui.verbose and extsource, | ||||
|
r43347 | b'source', | ||
_(b' location: %s\n'), | ||||
extsource or b"", | ||||
|
r43346 | ) | ||
|
r30518 | |||
if ui.verbose: | ||||
|
r43347 | fm.plain(_(b' bundled: %s\n') % [b'no', b'yes'][isinternal]) | ||
|
r30518 | fm.data(bundled=isinternal) | ||
|
r43346 | fm.condwrite( | ||
ui.verbose and exttestedwith, | ||||
|
r43347 | b'testedwith', | ||
_(b' tested with: %s\n'), | ||||
fm.formatlist(exttestedwith, name=b'ver'), | ||||
|
r43346 | ) | ||
fm.condwrite( | ||||
ui.verbose and extbuglink, | ||||
|
r43347 | b'buglink', | ||
_(b' bug reporting: %s\n'), | ||||
extbuglink or b"", | ||||
|
r43346 | ) | ||
|
r30518 | |||
fm.end() | ||||
|
r30524 | |||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugfileset', | ||
|
r43346 | [ | ||
( | ||||
|
r43347 | b'r', | ||
b'rev', | ||||
b'', | ||||
_(b'apply the filespec on this revision'), | ||||
_(b'REV'), | ||||
|
r43346 | ), | ||
( | ||||
|
r43347 | b'', | ||
b'all-files', | ||||
False, | ||||
_(b'test files from all revisions and working directory'), | ||||
|
r43346 | ), | ||
( | ||||
|
r43347 | b's', | ||
b'show-matcher', | ||||
None, | ||||
_(b'print internal representation of matcher'), | ||||
), | ||||
( | ||||
b'p', | ||||
b'show-stage', | ||||
|
r43346 | [], | ||
|
r43347 | _(b'print parsed tree at the given stage'), | ||
_(b'NAME'), | ||||
|
r43346 | ), | ||
], | ||||
|
r43347 | _(b'[-r REV] [--all-files] [OPTION]... FILESPEC'), | ||
|
r43346 | ) | ||
|
r30524 | def debugfileset(ui, repo, expr, **opts): | ||
'''parse and apply a fileset specification''' | ||||
|
r39008 | from . import fileset | ||
|
r43346 | |||
fileset.symbols # force import of fileset so we have predicates to optimize | ||||
|
r38629 | opts = pycompat.byteskwargs(opts) | ||
|
r43347 | ctx = scmutil.revsingle(repo, opts.get(b'rev'), None) | ||
|
r38837 | |||
stages = [ | ||||
|
r43347 | (b'parsed', pycompat.identity), | ||
(b'analyzed', filesetlang.analyze), | ||||
(b'optimized', filesetlang.optimize), | ||||
|
r38837 | ] | ||
|
r44937 | stagenames = {n for n, f in stages} | ||
|
r38837 | |||
showalways = set() | ||||
|
r43347 | if ui.verbose and not opts[b'show_stage']: | ||
|
r38837 | # show parsed tree by --verbose (deprecated) | ||
|
r43347 | showalways.add(b'parsed') | ||
if opts[b'show_stage'] == [b'all']: | ||||
|
r38837 | showalways.update(stagenames) | ||
else: | ||||
|
r43347 | for n in opts[b'show_stage']: | ||
|
r38837 | if n not in stagenames: | ||
|
r43347 | raise error.Abort(_(b'invalid stage name: %s') % n) | ||
showalways.update(opts[b'show_stage']) | ||||
|
r38837 | |||
|
r38841 | tree = filesetlang.parse(expr) | ||
|
r38837 | for n, f in stages: | ||
tree = f(tree) | ||||
if n in showalways: | ||||
|
r43347 | if opts[b'show_stage'] or n != b'parsed': | ||
ui.write(b"* %s:\n" % n) | ||||
ui.write(filesetlang.prettyformat(tree), b"\n") | ||||
|
r30524 | |||
|
r38629 | files = set() | ||
|
r43347 | if opts[b'all_files']: | ||
|
r38629 | for r in repo: | ||
c = repo[r] | ||||
files.update(c.files()) | ||||
files.update(c.substate) | ||||
|
r43347 | if opts[b'all_files'] or ctx.rev() is None: | ||
|
r38629 | wctx = repo[None] | ||
|
r43346 | files.update( | ||
repo.dirstate.walk( | ||||
scmutil.matchall(repo), | ||||
subrepos=list(wctx.substate), | ||||
unknown=True, | ||||
ignored=True, | ||||
) | ||||
) | ||||
|
r38629 | files.update(wctx.substate) | ||
else: | ||||
files.update(ctx.files()) | ||||
files.update(ctx.substate) | ||||
|
r44461 | m = ctx.matchfileset(repo.getcwd(), expr) | ||
|
r43347 | if opts[b'show_matcher'] or (opts[b'show_matcher'] is None and ui.verbose): | ||
|
r43350 | ui.writenoi18n(b'* matcher:\n', stringutil.prettyrepr(m), b'\n') | ||
|
r38629 | for f in sorted(files): | ||
if not m(f): | ||||
continue | ||||
|
r43347 | ui.write(b"%s\n" % f) | ||
@command(b'debugformat', [] + cmdutil.formatteropts) | ||||
|
r35337 | def debugformat(ui, repo, **opts): | ||
|
r35338 | """display format information about the current repository | ||
Use --verbose to get extra information about current config value and | ||||
Mercurial default.""" | ||||
|
r35402 | opts = pycompat.byteskwargs(opts) | ||
|
r35337 | maxvariantlength = max(len(fv.name) for fv in upgrade.allformatvariant) | ||
|
r43347 | maxvariantlength = max(len(b'format-variant'), maxvariantlength) | ||
|
r35337 | |||
def makeformatname(name): | ||||
|
r43347 | return b'%s:' + (b' ' * (maxvariantlength - len(name))) | ||
fm = ui.formatter(b'debugformat', opts) | ||||
|
r35379 | if fm.isplain(): | ||
|
r43346 | |||
|
r35379 | def formatvalue(value): | ||
|
r43347 | if util.safehasattr(value, b'startswith'): | ||
|
r35379 | return value | ||
if value: | ||||
|
r43347 | return b'yes' | ||
|
r35379 | else: | ||
|
r43347 | return b'no' | ||
|
r43346 | |||
|
r35379 | else: | ||
formatvalue = pycompat.identity | ||||
|
r35337 | |||
|
r43347 | fm.plain(b'format-variant') | ||
fm.plain(b' ' * (maxvariantlength - len(b'format-variant'))) | ||||
fm.plain(b' repo') | ||||
|
r35338 | if ui.verbose: | ||
|
r43347 | fm.plain(b' config default') | ||
fm.plain(b'\n') | ||||
|
r35337 | for fv in upgrade.allformatvariant: | ||
|
r35378 | fm.startitem() | ||
|
r35337 | repovalue = fv.fromrepo(repo) | ||
|
r35338 | configvalue = fv.fromconfig(repo) | ||
|
r35337 | |||
|
r35339 | if repovalue != configvalue: | ||
|
r43347 | namelabel = b'formatvariant.name.mismatchconfig' | ||
repolabel = b'formatvariant.repo.mismatchconfig' | ||||
|
r35339 | elif repovalue != fv.default: | ||
|
r43347 | namelabel = b'formatvariant.name.mismatchdefault' | ||
repolabel = b'formatvariant.repo.mismatchdefault' | ||||
|
r35339 | else: | ||
|
r43347 | namelabel = b'formatvariant.name.uptodate' | ||
repolabel = b'formatvariant.repo.uptodate' | ||||
fm.write(b'name', makeformatname(fv.name), fv.name, label=namelabel) | ||||
fm.write(b'repo', b' %3s', formatvalue(repovalue), label=repolabel) | ||||
|
r35339 | if fv.default != configvalue: | ||
|
r43347 | configlabel = b'formatvariant.config.special' | ||
|
r35339 | else: | ||
|
r43347 | configlabel = b'formatvariant.config.default' | ||
|
r43346 | fm.condwrite( | ||
ui.verbose, | ||||
|
r43347 | b'config', | ||
b' %6s', | ||||
|
r43346 | formatvalue(configvalue), | ||
label=configlabel, | ||||
) | ||||
fm.condwrite( | ||||
ui.verbose, | ||||
|
r43347 | b'default', | ||
b' %7s', | ||||
|
r43346 | formatvalue(fv.default), | ||
|
r43347 | label=b'formatvariant.default', | ||
|
r43346 | ) | ||
|
r43347 | fm.plain(b'\n') | ||
|
r35378 | fm.end() | ||
|
r35337 | |||
|
r43346 | |||
|
r43347 | @command(b'debugfsinfo', [], _(b'[PATH]'), norepo=True) | ||
def debugfsinfo(ui, path=b"."): | ||||
|
r30525 | """show information detected about current filesystem""" | ||
|
r43350 | ui.writenoi18n(b'path: %s\n' % path) | ||
r43364 | ui.writenoi18n( | |||
b'mounted on: %s\n' % (util.getfsmountpoint(path) or b'(unknown)') | ||||
) | ||||
|
r43350 | ui.writenoi18n(b'exec: %s\n' % (util.checkexec(path) and b'yes' or b'no')) | ||
ui.writenoi18n(b'fstype: %s\n' % (util.getfstype(path) or b'(unknown)')) | ||||
r43364 | ui.writenoi18n( | |||
b'symlink: %s\n' % (util.checklink(path) and b'yes' or b'no') | ||||
) | ||||
ui.writenoi18n( | ||||
b'hardlink: %s\n' % (util.checknlink(path) and b'yes' or b'no') | ||||
) | ||||
|
r43347 | casesensitive = b'(unknown)' | ||
|
r31634 | try: | ||
|
r43347 | with pycompat.namedtempfile(prefix=b'.debugfsinfo', dir=path) as f: | ||
casesensitive = util.fscasesensitive(f.name) and b'yes' or b'no' | ||||
|
r31634 | except OSError: | ||
pass | ||||
|
r43350 | ui.writenoi18n(b'case-sensitive: %s\n' % casesensitive) | ||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debuggetbundle', | ||
|
r43346 | [ | ||
|
r43347 | (b'H', b'head', [], _(b'id of head node'), _(b'ID')), | ||
(b'C', b'common', [], _(b'id of common node'), _(b'ID')), | ||||
( | ||||
b't', | ||||
b'type', | ||||
b'bzip2', | ||||
_(b'bundle compression type to use'), | ||||
_(b'TYPE'), | ||||
), | ||||
|
r43346 | ], | ||
|
r43347 | _(b'REPO FILE [-H|-C ID]...'), | ||
|
r43346 | norepo=True, | ||
) | ||||
|
r30526 | 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. | ||||
""" | ||||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r30526 | repo = hg.peer(ui, opts, repopath) | ||
|
r43347 | if not repo.capable(b'getbundle'): | ||
raise error.Abort(b"getbundle() not supported by target repository") | ||||
|
r30526 | args = {} | ||
if common: | ||||
|
r43906 | args['common'] = [bin(s) for s in common] | ||
|
r30526 | if head: | ||
|
r43906 | args['heads'] = [bin(s) for s in head] | ||
|
r30526 | # TODO: get desired bundlecaps from command line. | ||
|
r43906 | args['bundlecaps'] = None | ||
|
r43347 | bundle = repo.getbundle(b'debug', **args) | ||
bundletype = opts.get(b'type', b'bzip2').lower() | ||||
|
r43346 | btypes = { | ||
|
r43347 | b'none': b'HG10UN', | ||
b'bzip2': b'HG10BZ', | ||||
b'gzip': b'HG10GZ', | ||||
b'bundle2': b'HG20', | ||||
|
r43346 | } | ||
|
r30526 | bundletype = btypes.get(bundletype) | ||
if bundletype not in bundle2.bundletypes: | ||||
|
r43347 | raise error.Abort(_(b'unknown bundle type specified with --type')) | ||
|
r30526 | bundle2.writebundle(ui, bundle, bundlepath, bundletype) | ||
|
r30527 | |||
|
r43346 | |||
|
r43347 | @command(b'debugignore', [], b'[FILE]') | ||
|
r30527 | def debugignore(ui, repo, *files, **opts): | ||
"""display the combined ignore pattern and information about ignored files | ||||
With no argument display the combined ignore pattern. | ||||
Given space separated file names, shows if the given file is ignored and | ||||
if so, show the ignore rule (file and line number) that matched it. | ||||
""" | ||||
ignore = repo.dirstate._ignore | ||||
if not files: | ||||
# Show all the patterns | ||||
|
r43347 | ui.write(b"%s\n" % pycompat.byterepr(ignore)) | ||
|
r30527 | else: | ||
|
r33507 | m = scmutil.match(repo[None], pats=files) | ||
|
r41785 | uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True) | ||
|
r33507 | for f in m.files(): | ||
|
r30527 | nf = util.normpath(f) | ||
ignored = None | ||||
ignoredata = None | ||||
|
r43347 | if nf != b'.': | ||
|
r30527 | if ignore(nf): | ||
ignored = nf | ||||
ignoredata = repo.dirstate._ignorefileandline(nf) | ||||
else: | ||||
|
r44032 | for p in pathutil.finddirs(nf): | ||
|
r30527 | if ignore(p): | ||
ignored = p | ||||
ignoredata = repo.dirstate._ignorefileandline(p) | ||||
break | ||||
if ignored: | ||||
if ignored == nf: | ||||
|
r43347 | ui.write(_(b"%s is ignored\n") % uipathfn(f)) | ||
|
r30527 | else: | ||
|
r43346 | ui.write( | ||
_( | ||||
|
r43347 | b"%s is ignored because of " | ||
b"containing directory %s\n" | ||||
|
r43346 | ) | ||
% (uipathfn(f), ignored) | ||||
) | ||||
|
r30527 | ignorefile, lineno, line = ignoredata | ||
|
r43346 | ui.write( | ||
|
r43347 | _(b"(ignore rule in %s, line %d: '%s')\n") | ||
|
r43346 | % (ignorefile, lineno, line) | ||
) | ||||
|
r30527 | else: | ||
|
r43347 | ui.write(_(b"%s is not ignored\n") % uipathfn(f)) | ||
|
r30528 | |||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugindex', | ||
|
r43346 | cmdutil.debugrevlogopts + cmdutil.formatteropts, | ||
|
r43347 | _(b'-c|-m|FILE'), | ||
|
r43346 | ) | ||
|
r30528 | def debugindex(ui, repo, file_=None, **opts): | ||
|
r39318 | """dump index data for a storage primitive""" | ||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r43347 | store = cmdutil.openstorage(repo, b'debugindex', file_, opts) | ||
|
r30528 | |||
if ui.debugflag: | ||||
shortfn = hex | ||||
else: | ||||
shortfn = short | ||||
idlen = 12 | ||||
|
r39318 | for i in store: | ||
idlen = len(shortfn(store.node(i))) | ||||
|
r30528 | break | ||
|
r43347 | fm = ui.formatter(b'debugindex', opts) | ||
|
r43346 | fm.plain( | ||
b' rev linkrev %s %s p2\n' | ||||
% (b'nodeid'.ljust(idlen), b'p1'.ljust(idlen)) | ||||
) | ||||
|
r39318 | |||
for rev in store: | ||||
node = store.node(rev) | ||||
parents = store.parents(node) | ||||
fm.startitem() | ||||
fm.write(b'rev', b'%6d ', rev) | ||||
|
r43347 | fm.write(b'linkrev', b'%7d ', store.linkrev(rev)) | ||
fm.write(b'node', b'%s ', shortfn(node)) | ||||
fm.write(b'p1', b'%s ', shortfn(parents[0])) | ||||
fm.write(b'p2', b'%s', shortfn(parents[1])) | ||||
|
r39318 | fm.plain(b'\n') | ||
fm.end() | ||||
|
r30528 | |||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugindexdot', | ||
cmdutil.debugrevlogopts, | ||||
_(b'-c|-m|FILE'), | ||||
optionalrepo=True, | ||||
|
r43346 | ) | ||
|
r30528 | def debugindexdot(ui, repo, file_=None, **opts): | ||
"""dump an index DAG as a graphviz dot file""" | ||||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r43347 | r = cmdutil.openstorage(repo, b'debugindexdot', file_, opts) | ||
|
r43350 | ui.writenoi18n(b"digraph G {\n") | ||
|
r30528 | for i in r: | ||
node = r.node(i) | ||||
pp = r.parents(node) | ||||
|
r43347 | ui.write(b"\t%d -> %d\n" % (r.rev(pp[0]), i)) | ||
|
r30528 | if pp[1] != nullid: | ||
|
r43347 | ui.write(b"\t%d -> %d\n" % (r.rev(pp[1]), i)) | ||
ui.write(b"}\n") | ||||
@command(b'debugindexstats', []) | ||||
|
r40016 | def debugindexstats(ui, repo): | ||
"""show stats related to the changelog index""" | ||||
repo.changelog.shortest(nullid, 1) | ||||
|
r40401 | index = repo.changelog.index | ||
|
r43347 | if not util.safehasattr(index, b'stats'): | ||
raise error.Abort(_(b'debugindexstats only works with native code')) | ||||
|
r40401 | for k, v in sorted(index.stats().items()): | ||
|
r43347 | ui.write(b'%s: %d\n' % (k, v)) | ||
@command(b'debuginstall', [] + cmdutil.formatteropts, b'', norepo=True) | ||||
|
r30918 | def debuginstall(ui, **opts): | ||
|
r46554 | """test Mercurial installation | ||
|
r30918 | |||
Returns 0 on success. | ||||
|
r46554 | """ | ||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r30918 | |||
problems = 0 | ||||
|
r43347 | fm = ui.formatter(b'debuginstall', opts) | ||
|
r30918 | fm.startitem() | ||
|
r45660 | # encoding might be unknown or wrong. don't translate these messages. | ||
fm.write(b'encoding', b"checking encoding (%s)...\n", encoding.encoding) | ||||
|
r30918 | err = None | ||
try: | ||||
|
r34131 | codecs.lookup(pycompat.sysstr(encoding.encoding)) | ||
except LookupError as inst: | ||||
|
r37102 | err = stringutil.forcebytestr(inst) | ||
|
r30918 | problems += 1 | ||
|
r43346 | fm.condwrite( | ||
err, | ||||
|
r43347 | b'encodingerror', | ||
|
r45660 | b" %s\n (check that your locale is properly set)\n", | ||
|
r43346 | err, | ||
) | ||||
|
r30918 | |||
# Python | ||||
|
r44083 | pythonlib = None | ||
if util.safehasattr(os, '__file__'): | ||||
pythonlib = os.path.dirname(pycompat.fsencode(os.__file__)) | ||||
elif getattr(sys, 'oxidized', False): | ||||
pythonlib = pycompat.sysexecutable | ||||
|
r43346 | fm.write( | ||
|
r43347 | b'pythonexe', | ||
_(b"checking Python executable (%s)\n"), | ||||
pycompat.sysexecutable or _(b"unknown"), | ||||
|
r43346 | ) | ||
fm.write( | ||||
|
r44603 | b'pythonimplementation', | ||
_(b"checking Python implementation (%s)\n"), | ||||
pycompat.sysbytes(platform.python_implementation()), | ||||
) | ||||
fm.write( | ||||
|
r43347 | b'pythonver', | ||
_(b"checking Python version (%s)\n"), | ||||
(b"%d.%d.%d" % sys.version_info[:3]), | ||||
|
r43346 | ) | ||
fm.write( | ||||
|
r43347 | b'pythonlib', | ||
_(b"checking Python lib (%s)...\n"), | ||||
|
r44083 | pythonlib or _(b"unknown"), | ||
|
r43346 | ) | ||
|
r30918 | |||
|
r44953 | try: | ||
from . import rustext | ||||
rustext.__doc__ # trigger lazy import | ||||
except ImportError: | ||||
rustext = None | ||||
|
r30918 | security = set(sslutil.supportedprotocols) | ||
if sslutil.hassni: | ||||
|
r43347 | security.add(b'sni') | ||
|
r30918 | |||
|
r43346 | fm.write( | ||
|
r43347 | b'pythonsecurity', | ||
_(b"checking Python security support (%s)\n"), | ||||
fm.formatlist(sorted(security), name=b'protocol', fmt=b'%s', sep=b','), | ||||
|
r43346 | ) | ||
|
r30918 | |||
# These are warnings, not errors. So don't increment problem count. This | ||||
# may change in the future. | ||||
|
r43347 | if b'tls1.2' not in security: | ||
|
r43346 | fm.plain( | ||
_( | ||||
|
r43347 | b' TLS 1.2 not supported by Python install; ' | ||
b'network connections lack modern security\n' | ||||
|
r43346 | ) | ||
) | ||||
|
r43347 | if b'sni' not in security: | ||
|
r43346 | fm.plain( | ||
_( | ||||
|
r43347 | b' SNI not supported by Python install; may have ' | ||
b'connectivity issues with some servers\n' | ||||
|
r43346 | ) | ||
) | ||||
|
r30918 | |||
|
r44953 | fm.plain( | ||
_( | ||||
b"checking Rust extensions (%s)\n" | ||||
% (b'missing' if rustext is None else b'installed') | ||||
), | ||||
) | ||||
|
r30918 | # TODO print CA cert info | ||
# hg version | ||||
hgver = util.version() | ||||
|
r43346 | fm.write( | ||
|
r43347 | b'hgver', _(b"checking Mercurial version (%s)\n"), hgver.split(b'+')[0] | ||
|
r43346 | ) | ||
fm.write( | ||||
|
r43347 | b'hgverextra', | ||
_(b"checking Mercurial custom build (%s)\n"), | ||||
b'+'.join(hgver.split(b'+')[1:]), | ||||
|
r43346 | ) | ||
|
r30918 | |||
# compiled modules | ||||
|
r44083 | hgmodules = None | ||
if util.safehasattr(sys.modules[__name__], '__file__'): | ||||
hgmodules = os.path.dirname(pycompat.fsencode(__file__)) | ||||
elif getattr(sys, 'oxidized', False): | ||||
hgmodules = pycompat.sysexecutable | ||||
|
r43346 | fm.write( | ||
|
r43347 | b'hgmodulepolicy', _(b"checking module policy (%s)\n"), policy.policy | ||
|
r43346 | ) | ||
fm.write( | ||||
|
r43347 | b'hgmodules', | ||
_(b"checking installed modules (%s)...\n"), | ||||
|
r44083 | hgmodules or _(b"unknown"), | ||
|
r43346 | ) | ||
|
r30918 | |||
|
r43347 | rustandc = policy.policy in (b'rust+c', b'rust+c-allow') | ||
|
r42651 | rustext = rustandc # for now, that's the only case | ||
|
r43347 | cext = policy.policy in (b'c', b'allow') or rustandc | ||
|
r42651 | nopure = cext or rustext | ||
if nopure: | ||||
|
r32204 | err = None | ||
try: | ||||
|
r42651 | if cext: | ||
|
r44102 | from .cext import ( # pytype: disable=import-error | ||
|
r42651 | base85, | ||
bdiff, | ||||
mpatch, | ||||
osutil, | ||||
) | ||||
|
r43346 | |||
|
r42651 | # quiet pyflakes | ||
dir(bdiff), dir(mpatch), dir(base85), dir(osutil) | ||||
if rustext: | ||||
|
r44102 | from .rustext import ( # pytype: disable=import-error | ||
|
r42651 | ancestor, | ||
dirstate, | ||||
) | ||||
|
r43346 | |||
dir(ancestor), dir(dirstate) # quiet pyflakes | ||||
|
r32204 | except Exception as inst: | ||
|
r37102 | err = stringutil.forcebytestr(inst) | ||
|
r32204 | problems += 1 | ||
|
r43347 | fm.condwrite(err, b'extensionserror', b" %s\n", err) | ||
|
r30918 | |||
compengines = util.compengines._engines.values() | ||||
|
r43346 | fm.write( | ||
|
r43347 | b'compengines', | ||
_(b'checking registered compression engines (%s)\n'), | ||||
|
r43346 | fm.formatlist( | ||
sorted(e.name() for e in compengines), | ||||
|
r43347 | name=b'compengine', | ||
fmt=b'%s', | ||||
sep=b', ', | ||||
|
r43346 | ), | ||
) | ||||
fm.write( | ||||
|
r43347 | b'compenginesavail', | ||
|
r43387 | _(b'checking available compression engines (%s)\n'), | ||
|
r43346 | fm.formatlist( | ||
sorted(e.name() for e in compengines if e.available()), | ||||
|
r43347 | name=b'compengine', | ||
fmt=b'%s', | ||||
sep=b', ', | ||||
|
r43346 | ), | ||
) | ||||
r42208 | wirecompengines = compression.compengines.supportedwireengines( | |||
|
r43346 | compression.SERVERROLE | ||
) | ||||
fm.write( | ||||
|
r43347 | b'compenginesserver', | ||
_( | ||||
b'checking available compression engines ' | ||||
b'for wire protocol (%s)\n' | ||||
), | ||||
|
r43346 | fm.formatlist( | ||
[e.name() for e in wirecompengines if e.wireprotosupport()], | ||||
|
r43347 | name=b'compengine', | ||
fmt=b'%s', | ||||
sep=b', ', | ||||
|
r43346 | ), | ||
) | ||||
|
r43347 | re2 = b'missing' | ||
|
r35464 | if util._re2: | ||
|
r43347 | re2 = b'available' | ||
fm.plain(_(b'checking "re2" regexp engine (%s)\n') % re2) | ||||
|
r35464 | fm.data(re2=bool(util._re2)) | ||
|
r30918 | |||
# templates | ||||
|
r45755 | p = templater.templatedir() | ||
|
r45773 | fm.write(b'templatedirs', b'checking templates (%s)...\n', p or b'') | ||
|
r43347 | fm.condwrite(not p, b'', _(b" no template directories found\n")) | ||
|
r30918 | if p: | ||
|
r45880 | (m, fp) = templater.try_open_template(b"map-cmdline.default") | ||
|
r30918 | if m: | ||
# template found, check if it is working | ||||
err = None | ||||
try: | ||||
templater.templater.frommapfile(m) | ||||
except Exception as inst: | ||||
|
r37102 | err = stringutil.forcebytestr(inst) | ||
|
r30918 | p = None | ||
|
r43347 | fm.condwrite(err, b'defaulttemplateerror', b" %s\n", err) | ||
|
r30918 | else: | ||
p = None | ||||
|
r43346 | fm.condwrite( | ||
|
r43347 | p, b'defaulttemplate', _(b"checking default template (%s)\n"), m | ||
|
r43346 | ) | ||
fm.condwrite( | ||||
not m, | ||||
|
r43347 | b'defaulttemplatenotfound', | ||
_(b" template '%s' not found\n"), | ||||
b"default", | ||||
|
r43346 | ) | ||
|
r30918 | if not p: | ||
problems += 1 | ||||
|
r43346 | fm.condwrite( | ||
|
r43347 | not p, b'', _(b" (templates seem to have been installed incorrectly)\n") | ||
|
r43346 | ) | ||
|
r30918 | |||
# editor | ||||
editor = ui.geteditor() | ||||
editor = util.expandpath(editor) | ||||
|
r37138 | editorbin = procutil.shellsplit(editor)[0] | ||
|
r43347 | fm.write(b'editor', _(b"checking commit editor... (%s)\n"), editorbin) | ||
|
r37138 | cmdpath = procutil.findexe(editorbin) | ||
|
r43346 | fm.condwrite( | ||
|
r43347 | not cmdpath and editor == b'vi', | ||
b'vinotfound', | ||||
|
r43346 | _( | ||
|
r43347 | b" No commit editor set and can't find %s in PATH\n" | ||
b" (specify a commit editor in your configuration" | ||||
b" file)\n" | ||||
|
r43346 | ), | ||
|
r43347 | not cmdpath and editor == b'vi' and editorbin, | ||
|
r43346 | ) | ||
fm.condwrite( | ||||
|
r43347 | not cmdpath and editor != b'vi', | ||
b'editornotfound', | ||||
|
r43346 | _( | ||
|
r43347 | b" Can't find editor '%s' in PATH\n" | ||
b" (specify a commit editor in your configuration" | ||||
b" file)\n" | ||||
|
r43346 | ), | ||
not cmdpath and editorbin, | ||||
) | ||||
|
r43347 | if not cmdpath and editor != b'vi': | ||
|
r30918 | problems += 1 | ||
# check username | ||||
username = None | ||||
err = None | ||||
try: | ||||
username = ui.username() | ||||
except error.Abort as e: | ||||
|
r46274 | err = e.message | ||
|
r30918 | problems += 1 | ||
|
r43347 | fm.condwrite( | ||
username, b'username', _(b"checking username (%s)\n"), username | ||||
) | ||||
|
r43346 | fm.condwrite( | ||
err, | ||||
|
r43347 | b'usernameerror', | ||
|
r43346 | _( | ||
|
r43347 | b"checking username...\n %s\n" | ||
b" (specify a username in your configuration file)\n" | ||||
|
r43346 | ), | ||
err, | ||||
) | ||||
|
r30918 | |||
|
r42878 | for name, mod in extensions.extensions(): | ||
handler = getattr(mod, 'debuginstall', None) | ||||
if handler is not None: | ||||
problems += handler(ui, fm) | ||||
|
r43347 | fm.condwrite(not problems, b'', _(b"no problems detected\n")) | ||
|
r30918 | if not problems: | ||
fm.data(problems=problems) | ||||
|
r43346 | fm.condwrite( | ||
problems, | ||||
|
r43347 | b'problems', | ||
|
r43387 | _(b"%d problems detected, please check your install!\n"), | ||
|
r43346 | problems, | ||
) | ||||
|
r30918 | fm.end() | ||
return problems | ||||
|
r43346 | |||
|
r43347 | @command(b'debugknown', [], _(b'REPO ID...'), norepo=True) | ||
|
r30919 | 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. | ||||
""" | ||||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r30919 | repo = hg.peer(ui, opts, repopath) | ||
|
r43347 | if not repo.capable(b'known'): | ||
raise error.Abort(b"known() not supported by target repository") | ||||
|
r30919 | flags = repo.known([bin(s) for s in ids]) | ||
|
r43347 | ui.write(b"%s\n" % (b"".join([f and b"1" or b"0" for f in flags]))) | ||
@command(b'debuglabelcomplete', [], _(b'LABEL...')) | ||||
|
r30935 | def debuglabelcomplete(ui, repo, *args): | ||
'''backwards compatibility with old bash completion scripts (DEPRECATED)''' | ||||
|
r31402 | debugnamecomplete(ui, repo, *args) | ||
|
r30935 | |||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debuglocks', | ||
|
r43346 | [ | ||
|
r43347 | (b'L', b'force-lock', None, _(b'free the store lock (DANGEROUS)')), | ||
|
r43346 | ( | ||
|
r43347 | b'W', | ||
b'force-wlock', | ||||
|
r43346 | None, | ||
|
r43347 | _(b'free the working state lock (DANGEROUS)'), | ||
|
r43346 | ), | ||
|
r43347 | (b's', b'set-lock', None, _(b'set the store lock until stopped')), | ||
( | ||||
b'S', | ||||
b'set-wlock', | ||||
None, | ||||
_(b'set the working state lock until stopped'), | ||||
), | ||||
|
r43346 | ], | ||
|
r43347 | _(b'[OPTION]...'), | ||
|
r43346 | ) | ||
|
r30938 | def debuglocks(ui, repo, **opts): | ||
"""show or modify state of locks | ||||
By default, this command will show which locks are held. This | ||||
includes the user and process holding the lock, the amount of time | ||||
the lock has been held, and the machine name where the process is | ||||
running if it's not local. | ||||
Locks protect the integrity of Mercurial's data, so should be | ||||
treated with care. System crashes or other interruptions may cause | ||||
locks to not be properly released, though Mercurial will usually | ||||
detect and remove such stale locks automatically. | ||||
However, detecting stale locks may not always be possible (for | ||||
instance, on a shared filesystem). Removing locks may also be | ||||
blocked by filesystem permissions. | ||||
|
r35396 | Setting a lock will prevent other commands from changing the data. | ||
The command will wait until an interruption (SIGINT, SIGTERM, ...) occurs. | ||||
The set locks are removed when the command exits. | ||||
|
r30938 | Returns 0 if no locks are held. | ||
""" | ||||
|
r43906 | if opts.get('force_lock'): | ||
|
r43347 | repo.svfs.unlink(b'lock') | ||
|
r43906 | if opts.get('force_wlock'): | ||
|
r43347 | repo.vfs.unlink(b'wlock') | ||
|
r43906 | if opts.get('force_lock') or opts.get('force_wlock'): | ||
|
r30938 | return 0 | ||
|
r35396 | locks = [] | ||
try: | ||||
|
r43906 | if opts.get('set_wlock'): | ||
|
r35396 | try: | ||
locks.append(repo.wlock(False)) | ||||
except error.LockHeld: | ||||
|
r43347 | raise error.Abort(_(b'wlock is already held')) | ||
|
r43906 | if opts.get('set_lock'): | ||
|
r35396 | try: | ||
locks.append(repo.lock(False)) | ||||
except error.LockHeld: | ||||
|
r43347 | raise error.Abort(_(b'lock is already held')) | ||
|
r35396 | if len(locks): | ||
|
r43347 | ui.promptchoice(_(b"ready to release the lock (y)? $$ &Yes")) | ||
|
r35396 | return 0 | ||
finally: | ||||
release(*locks) | ||||
|
r30938 | now = time.time() | ||
held = 0 | ||||
def report(vfs, name, method): | ||||
# this causes stale locks to get reaped for more accurate reporting | ||||
try: | ||||
l = method(False) | ||||
except error.LockHeld: | ||||
l = None | ||||
if l: | ||||
l.release() | ||||
else: | ||||
try: | ||||
|
r36799 | st = vfs.lstat(name) | ||
age = now - st[stat.ST_MTIME] | ||||
user = util.username(st.st_uid) | ||||
|
r30938 | locker = vfs.readlock(name) | ||
|
r43347 | if b":" in locker: | ||
host, pid = locker.split(b':') | ||||
|
r30938 | if host == socket.gethostname(): | ||
|
r43347 | locker = b'user %s, process %s' % (user or b'None', pid) | ||
|
r30938 | else: | ||
|
r43347 | locker = b'user %s, process %s, host %s' % ( | ||
|
r43346 | user or b'None', | ||
pid, | ||||
host, | ||||
) | ||||
|
r43350 | ui.writenoi18n(b"%-6s %s (%ds)\n" % (name + b":", locker, age)) | ||
|
r30938 | return 1 | ||
except OSError as e: | ||||
if e.errno != errno.ENOENT: | ||||
raise | ||||
|
r43350 | ui.writenoi18n(b"%-6s free\n" % (name + b":")) | ||
|
r30938 | return 0 | ||
|
r43347 | held += report(repo.svfs, b"lock", repo.lock) | ||
held += report(repo.vfs, b"wlock", repo.wlock) | ||||
|
r30938 | |||
return held | ||||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugmanifestfulltextcache', | ||
|
r43346 | [ | ||
|
r43347 | (b'', b'clear', False, _(b'clear the cache')), | ||
|
r43346 | ( | ||
|
r43347 | b'a', | ||
b'add', | ||||
|
r43346 | [], | ||
|
r43347 | _(b'add the given manifest nodes to the cache'), | ||
_(b'NODE'), | ||||
|
r43346 | ), | ||
], | ||||
|
r43347 | b'', | ||
|
r43346 | ) | ||
r42124 | def debugmanifestfulltextcache(ui, repo, add=(), **opts): | |||
|
r38803 | """show, clear or amend the contents of the manifest fulltext cache""" | ||
r42108 | ||||
def getcache(): | ||||
|
r39280 | r = repo.manifestlog.getstorage(b'') | ||
|
r38803 | try: | ||
r42108 | return r._fulltextcache | |||
|
r38803 | except AttributeError: | ||
|
r43346 | msg = _( | ||
|
r43347 | b"Current revlog implementation doesn't appear to have a " | ||
b"manifest fulltext cache\n" | ||||
|
r43346 | ) | ||
r42108 | raise error.Abort(msg) | |||
|
r43906 | if opts.get('clear'): | ||
r42130 | with repo.wlock(): | |||
r42108 | cache = getcache() | |||
r42113 | cache.clear(clear_persisted_data=True) | |||
return | ||||
|
r38803 | |||
r42108 | if add: | |||
r42130 | with repo.wlock(): | |||
r42124 | m = repo.manifestlog | |||
store = m.getstorage(b'') | ||||
for n in add: | ||||
try: | ||||
manifest = m[store.lookup(n)] | ||||
except error.LookupError as e: | ||||
|
r43347 | raise error.Abort(e, hint=b"Check your manifest node id") | ||
r42124 | manifest.read() # stores revisision in cache too | |||
r42109 | return | |||
|
r38803 | |||
r42108 | cache = getcache() | |||
if not len(cache): | ||||
|
r43347 | ui.write(_(b'cache empty\n')) | ||
r42108 | else: | |||
ui.write( | ||||
|
r43346 | _( | ||
|
r43347 | b'cache contains %d manifest entries, in order of most to ' | ||
b'least recent:\n' | ||||
|
r43346 | ) | ||
% (len(cache),) | ||||
) | ||||
r42108 | totalsize = 0 | |||
for nodeid in cache: | ||||
# Use cache.get to not update the LRU order | ||||
r42125 | data = cache.peek(nodeid) | |||
r42108 | size = len(data) | |||
|
r43346 | totalsize += size + 24 # 20 bytes nodeid, 4 bytes size | ||
ui.write( | ||||
|
r43347 | _(b'id: %s, size %s\n') % (hex(nodeid), util.bytecount(size)) | ||
|
r43346 | ) | ||
|
r43347 | ondisk = cache._opener.stat(b'manifestfulltextcache').st_size | ||
r42108 | ui.write( | |||
|
r43347 | _(b'total cache data size %s, on-disk %s\n') | ||
|
r43346 | % (util.bytecount(totalsize), util.bytecount(ondisk)) | ||
r42108 | ) | |||
|
r38803 | |||
|
r43346 | |||
|
r44880 | @command(b'debugmergestate', [] + cmdutil.templateopts, b'') | ||
def debugmergestate(ui, repo, *args, **opts): | ||||
|
r30936 | """print merge state | ||
Use --verbose to print out information about whether v1 or v2 merge state | ||||
was chosen.""" | ||||
|
r43346 | |||
|
r44880 | if ui.verbose: | ||
|
r45383 | ms = mergestatemod.mergestate(repo) | ||
|
r44880 | |||
# sort so that reasonable information is on top | ||||
v1records = ms._readrecordsv1() | ||||
v2records = ms._readrecordsv2() | ||||
if not v1records and not v2records: | ||||
pass | ||||
elif not v2records: | ||||
ui.writenoi18n(b'no version 2 merge state\n') | ||||
elif ms._v1v2match(v1records, v2records): | ||||
ui.writenoi18n(b'v1 and v2 states match: using v2\n') | ||||
|
r30936 | else: | ||
|
r44880 | ui.writenoi18n(b'v1 and v2 states mismatch: using v1\n') | ||
opts = pycompat.byteskwargs(opts) | ||||
if not opts[b'template']: | ||||
opts[b'template'] = ( | ||||
b'{if(commits, "", "no merge state found\n")}' | ||||
b'{commits % "{name}{if(label, " ({label})")}: {node}\n"}' | ||||
b'{files % "file: {path} (state \\"{state}\\")\n' | ||||
b'{if(local_path, "' | ||||
b' local path: {local_path} (hash {local_key}, flags \\"{local_flags}\\")\n' | ||||
b' ancestor path: {ancestor_path} (node {ancestor_node})\n' | ||||
b' other path: {other_path} (node {other_node})\n' | ||||
b'")}' | ||||
b'{if(rename_side, "' | ||||
b' rename side: {rename_side}\n' | ||||
b' renamed path: {renamed_path}\n' | ||||
b'")}' | ||||
b'{extras % " extra: {key} = {value}\n"}' | ||||
b'"}' | ||||
|
r46016 | b'{extras % "extra: {file} ({key} = {value})\n"}' | ||
|
r44880 | ) | ||
|
r45383 | ms = mergestatemod.mergestate.read(repo) | ||
|
r44880 | |||
fm = ui.formatter(b'debugmergestate', opts) | ||||
fm.startitem() | ||||
fm_commits = fm.nested(b'commits') | ||||
if ms.active(): | ||||
for name, node, label_index in ( | ||||
(b'local', ms.local, 0), | ||||
(b'other', ms.other, 1), | ||||
): | ||||
fm_commits.startitem() | ||||
fm_commits.data(name=name) | ||||
fm_commits.data(node=hex(node)) | ||||
if ms._labels and len(ms._labels) > label_index: | ||||
fm_commits.data(label=ms._labels[label_index]) | ||||
fm_commits.end() | ||||
fm_files = fm.nested(b'files') | ||||
if ms.active(): | ||||
for f in ms: | ||||
fm_files.startitem() | ||||
fm_files.data(path=f) | ||||
state = ms._state[f] | ||||
fm_files.data(state=state[0]) | ||||
if state[0] in ( | ||||
|
r45383 | mergestatemod.MERGE_RECORD_UNRESOLVED, | ||
mergestatemod.MERGE_RECORD_RESOLVED, | ||||
|
r44880 | ): | ||
fm_files.data(local_key=state[1]) | ||||
fm_files.data(local_path=state[2]) | ||||
fm_files.data(ancestor_path=state[3]) | ||||
fm_files.data(ancestor_node=state[4]) | ||||
fm_files.data(other_path=state[5]) | ||||
fm_files.data(other_node=state[6]) | ||||
fm_files.data(local_flags=state[7]) | ||||
elif state[0] in ( | ||||
|
r45383 | mergestatemod.MERGE_RECORD_UNRESOLVED_PATH, | ||
mergestatemod.MERGE_RECORD_RESOLVED_PATH, | ||||
|
r44880 | ): | ||
fm_files.data(renamed_path=state[1]) | ||||
fm_files.data(rename_side=state[2]) | ||||
fm_extras = fm_files.nested(b'extras') | ||||
|
r46017 | for k, v in sorted(ms.extras(f).items()): | ||
|
r44880 | fm_extras.startitem() | ||
fm_extras.data(key=k) | ||||
fm_extras.data(value=v) | ||||
fm_extras.end() | ||||
fm_files.end() | ||||
|
r46016 | fm_extras = fm.nested(b'extras') | ||
|
r46307 | for f, d in sorted(pycompat.iteritems(ms.allextras())): | ||
|
r46016 | if f in ms: | ||
# If file is in mergestate, we have already processed it's extras | ||||
continue | ||||
for k, v in pycompat.iteritems(d): | ||||
fm_extras.startitem() | ||||
fm_extras.data(file=f) | ||||
fm_extras.data(key=k) | ||||
fm_extras.data(value=v) | ||||
fm_extras.end() | ||||
|
r44880 | fm.end() | ||
|
r30936 | |||
|
r43346 | |||
|
r43347 | @command(b'debugnamecomplete', [], _(b'NAME...')) | ||
|
r30937 | def debugnamecomplete(ui, repo, *args): | ||
'''complete "names" - tags, open branch names, bookmark names''' | ||||
names = set() | ||||
# since we previously only listed open branches, we will handle that | ||||
# specially (after this for loop) | ||||
|
r43376 | for name, ns in pycompat.iteritems(repo.names): | ||
|
r43347 | if name != b'branches': | ||
|
r30937 | names.update(ns.listnames(repo)) | ||
|
r43346 | names.update( | ||
tag | ||||
for (tag, heads, tip, closed) in repo.branchmap().iterbranches() | ||||
if not closed | ||||
) | ||||
|
r30937 | completions = set() | ||
if not args: | ||||
|
r43347 | args = [b''] | ||
|
r30937 | for a in args: | ||
completions.update(n for n in names if n.startswith(a)) | ||||
|
r43347 | ui.write(b'\n'.join(sorted(completions))) | ||
ui.write(b'\n') | ||||
|
r30937 | |||
|
r43346 | |||
@command( | ||||
r44788 | b'debugnodemap', | |||
r44790 | [ | |||
( | ||||
b'', | ||||
b'dump-new', | ||||
False, | ||||
_(b'write a (new) persistent binary nodemap on stdin'), | ||||
), | ||||
(b'', b'dump-disk', False, _(b'dump on-disk data on stdin')), | ||||
r44799 | ( | |||
b'', | ||||
b'check', | ||||
False, | ||||
_(b'check that the data on disk data are correct.'), | ||||
), | ||||
r44806 | ( | |||
b'', | ||||
b'metadata', | ||||
False, | ||||
_(b'display the on disk meta data for the nodemap'), | ||||
), | ||||
r44790 | ], | |||
r44788 | ) | |||
def debugnodemap(ui, repo, **opts): | ||||
|
r46554 | """write and inspect on disk nodemap""" | ||
r44790 | if opts['dump_new']: | |||
r44788 | unfi = repo.unfiltered() | |||
cl = unfi.changelog | ||||
r44999 | if util.safehasattr(cl.index, "nodemap_data_all"): | |||
data = cl.index.nodemap_data_all() | ||||
else: | ||||
data = nodemap.persistent_data(cl.index) | ||||
r44788 | ui.write(data) | |||
r44790 | elif opts['dump_disk']: | |||
unfi = repo.unfiltered() | ||||
cl = unfi.changelog | ||||
r44804 | nm_data = nodemap.persisted_data(cl) | |||
if nm_data is not None: | ||||
docket, data = nm_data | ||||
r44843 | ui.write(data[:]) | |||
r44799 | elif opts['check']: | |||
unfi = repo.unfiltered() | ||||
cl = unfi.changelog | ||||
r44804 | nm_data = nodemap.persisted_data(cl) | |||
if nm_data is not None: | ||||
docket, data = nm_data | ||||
return nodemap.check_data(ui, cl.index, data) | ||||
r44806 | elif opts['metadata']: | |||
unfi = repo.unfiltered() | ||||
cl = unfi.changelog | ||||
nm_data = nodemap.persisted_data(cl) | ||||
if nm_data is not None: | ||||
docket, data = nm_data | ||||
ui.write((b"uid: %s\n") % docket.uid) | ||||
r44807 | ui.write((b"tip-rev: %d\n") % docket.tip_rev) | |||
r45002 | ui.write((b"tip-node: %s\n") % hex(docket.tip_node)) | |||
r44808 | ui.write((b"data-length: %d\n") % docket.data_length) | |||
ui.write((b"data-unused: %d\n") % docket.data_unused) | ||||
r45125 | unused_perc = docket.data_unused * 100.0 / docket.data_length | |||
ui.write((b"data-unused: %2.3f%%\n") % unused_perc) | ||||
r44788 | ||||
@command( | ||||
|
r43347 | b'debugobsolete', | ||
|
r43346 | [ | ||
|
r43347 | (b'', b'flags', 0, _(b'markers flag')), | ||
|
r43346 | ( | ||
|
r43347 | b'', | ||
b'record-parents', | ||||
|
r43346 | False, | ||
|
r43347 | _(b'record parent information for the precursor'), | ||
|
r43346 | ), | ||
|
r43347 | (b'r', b'rev', [], _(b'display markers relevant to REV')), | ||
|
r43346 | ( | ||
|
r43347 | b'', | ||
b'exclusive', | ||||
|
r43346 | False, | ||
|
r43387 | _(b'restrict display to markers only relevant to REV'), | ||
|
r43346 | ), | ||
|
r43347 | (b'', b'index', False, _(b'display index of the marker')), | ||
(b'', b'delete', [], _(b'delete markers specified by indices')), | ||||
|
r43346 | ] | ||
+ cmdutil.commitopts2 | ||||
+ cmdutil.formatteropts, | ||||
|
r43347 | _(b'[OBSOLETED [REPLACEMENT ...]]'), | ||
|
r43346 | ) | ||
|
r30939 | def debugobsolete(ui, repo, precursor=None, *successors, **opts): | ||
"""create arbitrary obsolete marker | ||||
With no arguments, displays the list of obsolescence markers.""" | ||||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r30939 | def parsenodeid(s): | ||
try: | ||||
# We do not use revsingle/revrange functions here to accept | ||||
# arbitrary node identifiers, possibly not present in the | ||||
# local repository. | ||||
n = bin(s) | ||||
if len(n) != len(nullid): | ||||
raise TypeError() | ||||
return n | ||||
except TypeError: | ||||
|
r46486 | raise error.InputError( | ||
|
r43347 | b'changeset references must be full hexadecimal ' | ||
b'node identifiers' | ||||
|
r43346 | ) | ||
|
r30939 | |||
|
r43347 | if opts.get(b'delete'): | ||
|
r30939 | indices = [] | ||
|
r43347 | for v in opts.get(b'delete'): | ||
|
r30939 | try: | ||
indices.append(int(v)) | ||||
except ValueError: | ||||
|
r46486 | raise error.InputError( | ||
|
r43347 | _(b'invalid index value: %r') % v, | ||
hint=_(b'use integers for indices'), | ||||
|
r43346 | ) | ||
|
r30939 | |||
if repo.currenttransaction(): | ||||
|
r43346 | raise error.Abort( | ||
|
r43387 | _(b'cannot delete obsmarkers in the middle of transaction.') | ||
|
r43346 | ) | ||
|
r30939 | |||
with repo.lock(): | ||||
n = repair.deleteobsmarkers(repo.obsstore, indices) | ||||
|
r43347 | ui.write(_(b'deleted %i obsolescence markers\n') % n) | ||
|
r30939 | |||
return | ||||
if precursor is not None: | ||||
|
r43347 | if opts[b'rev']: | ||
|
r46486 | raise error.InputError( | ||
b'cannot select revision when creating marker' | ||||
) | ||||
|
r30939 | metadata = {} | ||
|
r43347 | metadata[b'user'] = encoding.fromlocal(opts[b'user'] or ui.username()) | ||
|
r30939 | succs = tuple(parsenodeid(succ) for succ in successors) | ||
l = repo.lock() | ||||
try: | ||||
|
r43347 | tr = repo.transaction(b'debugobsolete') | ||
|
r30939 | try: | ||
|
r43347 | date = opts.get(b'date') | ||
|
r30939 | if date: | ||
|
r36625 | date = dateutil.parsedate(date) | ||
|
r30939 | else: | ||
date = None | ||||
prec = parsenodeid(precursor) | ||||
parents = None | ||||
|
r43347 | if opts[b'record_parents']: | ||
|
r30939 | if prec not in repo.unfiltered(): | ||
|
r43346 | raise error.Abort( | ||
|
r43347 | b'cannot used --record-parents on ' | ||
b'unknown changesets' | ||||
|
r43346 | ) | ||
|
r30939 | parents = repo.unfiltered()[prec].parents() | ||
parents = tuple(p.node() for p in parents) | ||||
|
r43346 | repo.obsstore.create( | ||
tr, | ||||
prec, | ||||
succs, | ||||
|
r43347 | opts[b'flags'], | ||
|
r43346 | parents=parents, | ||
date=date, | ||||
metadata=metadata, | ||||
ui=ui, | ||||
) | ||||
|
r30939 | tr.close() | ||
except ValueError as exc: | ||||
|
r43346 | raise error.Abort( | ||
|
r43347 | _(b'bad obsmarker input: %s') % pycompat.bytestr(exc) | ||
|
r43346 | ) | ||
|
r30939 | finally: | ||
tr.release() | ||||
finally: | ||||
l.release() | ||||
else: | ||||
|
r43347 | if opts[b'rev']: | ||
revs = scmutil.revrange(repo, opts[b'rev']) | ||||
|
r30939 | nodes = [repo[r].node() for r in revs] | ||
|
r43346 | markers = list( | ||
obsutil.getmarkers( | ||||
|
r43347 | repo, nodes=nodes, exclusive=opts[b'exclusive'] | ||
|
r43346 | ) | ||
) | ||||
|
r30939 | markers.sort(key=lambda x: x._data) | ||
else: | ||||
r33150 | markers = obsutil.getmarkers(repo) | |||
|
r30939 | |||
markerstoiter = markers | ||||
isrelevant = lambda m: True | ||||
|
r43347 | if opts.get(b'rev') and opts.get(b'index'): | ||
r33150 | markerstoiter = obsutil.getmarkers(repo) | |||
|
r30939 | markerset = set(markers) | ||
isrelevant = lambda m: m in markerset | ||||
|
r43347 | fm = ui.formatter(b'debugobsolete', opts) | ||
|
r30939 | for i, m in enumerate(markerstoiter): | ||
if not isrelevant(m): | ||||
# marker can be irrelevant when we're iterating over a set | ||||
# of markers (markerstoiter) which is bigger than the set | ||||
# of markers we want to display (markers) | ||||
# this can happen if both --index and --rev options are | ||||
# provided and thus we need to iterate over all of the markers | ||||
# to get the correct indices, but only display the ones that | ||||
# are relevant to --rev value | ||||
continue | ||||
fm.startitem() | ||||
|
r43347 | ind = i if opts.get(b'index') else None | ||
|
r30939 | cmdutil.showmarker(fm, m, index=ind) | ||
fm.end() | ||||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugp1copies', | ||
[(b'r', b'rev', b'', _(b'revision to debug'), _(b'REV'))], | ||||
_(b'[-r REV]'), | ||||
|
r43346 | ) | ||
|
r41921 | def debugp1copies(ui, repo, **opts): | ||
"""dump copy information compared to p1""" | ||||
opts = pycompat.byteskwargs(opts) | ||||
|
r43347 | ctx = scmutil.revsingle(repo, opts.get(b'rev'), default=None) | ||
|
r41921 | for dst, src in ctx.p1copies().items(): | ||
|
r43347 | ui.write(b'%s -> %s\n' % (src, dst)) | ||
|
r41921 | |||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugp2copies', | ||
[(b'r', b'rev', b'', _(b'revision to debug'), _(b'REV'))], | ||||
_(b'[-r REV]'), | ||||
|
r43346 | ) | ||
|
r41921 | def debugp1copies(ui, repo, **opts): | ||
"""dump copy information compared to p2""" | ||||
opts = pycompat.byteskwargs(opts) | ||||
|
r43347 | ctx = scmutil.revsingle(repo, opts.get(b'rev'), default=None) | ||
|
r41921 | for dst, src in ctx.p2copies().items(): | ||
|
r43347 | ui.write(b'%s -> %s\n' % (src, dst)) | ||
|
r41921 | |||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugpathcomplete', | ||
|
r43346 | [ | ||
|
r43347 | (b'f', b'full', None, _(b'complete an entire path')), | ||
(b'n', b'normal', None, _(b'show only normal files')), | ||||
(b'a', b'added', None, _(b'show only added files')), | ||||
(b'r', b'removed', None, _(b'show only removed files')), | ||||
|
r43346 | ], | ||
|
r43347 | _(b'FILESPEC...'), | ||
|
r43346 | ) | ||
|
r30940 | def debugpathcomplete(ui, repo, *specs, **opts): | ||
|
r46554 | """complete part or all of a tracked path | ||
|
r30940 | |||
This command supports shells that offer path name completion. It | ||||
currently completes only files already known to the dirstate. | ||||
Completion extends only to the next path segment unless | ||||
|
r46554 | --full is specified, in which case entire paths are used.""" | ||
|
r30940 | |||
def complete(path, acceptable): | ||||
dirstate = repo.dirstate | ||||
|
r39843 | spec = os.path.normpath(os.path.join(encoding.getcwd(), path)) | ||
|
r30940 | rootdir = repo.root + pycompat.ossep | ||
if spec != repo.root and not spec.startswith(rootdir): | ||||
return [], [] | ||||
if os.path.isdir(spec): | ||||
|
r43347 | spec += b'/' | ||
|
r43346 | spec = spec[len(rootdir) :] | ||
|
r43347 | fixpaths = pycompat.ossep != b'/' | ||
|
r30940 | if fixpaths: | ||
|
r43347 | spec = spec.replace(pycompat.ossep, b'/') | ||
|
r30940 | speclen = len(spec) | ||
|
r43906 | fullpaths = opts['full'] | ||
|
r30940 | files, dirs = set(), set() | ||
adddir, addfile = dirs.add, files.add | ||||
|
r43376 | for f, st in pycompat.iteritems(dirstate): | ||
|
r30940 | if f.startswith(spec) and st[0] in acceptable: | ||
if fixpaths: | ||||
|
r43347 | f = f.replace(b'/', pycompat.ossep) | ||
|
r30940 | if fullpaths: | ||
addfile(f) | ||||
continue | ||||
s = f.find(pycompat.ossep, speclen) | ||||
if s >= 0: | ||||
adddir(f[:s]) | ||||
else: | ||||
addfile(f) | ||||
return files, dirs | ||||
|
r43347 | acceptable = b'' | ||
|
r43906 | if opts['normal']: | ||
|
r43347 | acceptable += b'nm' | ||
|
r43906 | if opts['added']: | ||
|
r43347 | acceptable += b'a' | ||
|
r43906 | if opts['removed']: | ||
|
r43347 | acceptable += b'r' | ||
|
r30940 | cwd = repo.getcwd() | ||
if not specs: | ||||
|
r43347 | specs = [b'.'] | ||
|
r30940 | |||
files, dirs = set(), set() | ||||
for spec in specs: | ||||
|
r43347 | f, d = complete(spec, acceptable or b'nmar') | ||
|
r30940 | files.update(f) | ||
dirs.update(d) | ||||
files.update(dirs) | ||||
|
r43347 | ui.write(b'\n'.join(repo.pathto(p, cwd) for p in sorted(files))) | ||
ui.write(b'\n') | ||||
|
r30940 | |||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugpathcopies', | ||
|
r43346 | cmdutil.walkopts, | ||
|
r43347 | b'hg debugpathcopies REV1 REV2 [FILE]', | ||
|
r43346 | inferrepo=True, | ||
) | ||||
|
r41656 | def debugpathcopies(ui, repo, rev1, rev2, *pats, **opts): | ||
"""show copies between two revisions""" | ||||
ctx1 = scmutil.revsingle(repo, rev1) | ||||
ctx2 = scmutil.revsingle(repo, rev2) | ||||
m = scmutil.match(ctx1, pats, opts) | ||||
|
r41915 | for dst, src in sorted(copies.pathcopies(ctx1, ctx2, m).items()): | ||
|
r43347 | ui.write(b'%s -> %s\n' % (src, dst)) | ||
@command(b'debugpeer', [], _(b'PATH'), norepo=True) | ||||
|
r35947 | def debugpeer(ui, path): | ||
"""establish a connection to a peer repository""" | ||||
# Always enable peer request logging. Requires --debug to display | ||||
# though. | ||||
overrides = { | ||||
|
r43347 | (b'devel', b'debug.peer-request'): True, | ||
|
r35947 | } | ||
with ui.configoverride(overrides): | ||||
peer = hg.peer(ui, {}, path) | ||||
local = peer.local() is not None | ||||
canpush = peer.canpush() | ||||
|
r43347 | ui.write(_(b'url: %s\n') % peer.url()) | ||
ui.write(_(b'local: %s\n') % (_(b'yes') if local else _(b'no'))) | ||||
ui.write(_(b'pushable: %s\n') % (_(b'yes') if canpush else _(b'no'))) | ||||
|
r35947 | |||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugpickmergetool', | ||
|
r43346 | [ | ||
|
r43347 | (b'r', b'rev', b'', _(b'check for files in this revision'), _(b'REV')), | ||
(b'', b'changedelete', None, _(b'emulate merging change and delete')), | ||||
|
r43346 | ] | ||
+ cmdutil.walkopts | ||||
+ cmdutil.mergetoolopts, | ||||
|
r43347 | _(b'[PATTERN]...'), | ||
|
r43346 | inferrepo=True, | ||
) | ||||
|
r32256 | def debugpickmergetool(ui, repo, *pats, **opts): | ||
"""examine which merge tool is chosen for specified file | ||||
As described in :hg:`help merge-tools`, Mercurial examines | ||||
configurations below in this order to decide which merge tool is | ||||
chosen for specified file. | ||||
1. ``--tool`` option | ||||
2. ``HGMERGE`` environment variable | ||||
3. configurations in ``merge-patterns`` section | ||||
4. configuration of ``ui.merge`` | ||||
5. configurations in ``merge-tools`` section | ||||
6. ``hgmerge`` tool (for historical reason only) | ||||
7. default tool for fallback (``:merge`` or ``:prompt``) | ||||
This command writes out examination result in the style below:: | ||||
FILE = MERGETOOL | ||||
By default, all files known in the first parent context of the | ||||
working directory are examined. Use file patterns and/or -I/-X | ||||
options to limit target files. -r/--rev is also useful to examine | ||||
files in another context without actual updating to it. | ||||
With --debug, this command shows warning messages while matching | ||||
against ``merge-patterns`` and so on, too. It is recommended to | ||||
use this option with explicit file patterns and/or -I/-X options, | ||||
because this option increases amount of output per file according | ||||
to configurations in hgrc. | ||||
With -v/--verbose, this command shows configurations below at | ||||
first (only if specified). | ||||
- ``--tool`` option | ||||
- ``HGMERGE`` environment variable | ||||
- configuration of ``ui.merge`` | ||||
If merge tool is chosen before matching against | ||||
``merge-patterns``, this command can't show any helpful | ||||
information, even with --debug. In such case, information above is | ||||
useful to know why a merge tool is chosen. | ||||
""" | ||||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r32256 | overrides = {} | ||
|
r43347 | if opts[b'tool']: | ||
overrides[(b'ui', b'forcemerge')] = opts[b'tool'] | ||||
|
r43350 | ui.notenoi18n(b'with --tool %r\n' % (pycompat.bytestr(opts[b'tool']))) | ||
|
r43347 | |||
with ui.configoverride(overrides, b'debugmergepatterns'): | ||||
hgmerge = encoding.environ.get(b"HGMERGE") | ||||
|
r32256 | if hgmerge is not None: | ||
|
r43350 | ui.notenoi18n(b'with HGMERGE=%r\n' % (pycompat.bytestr(hgmerge))) | ||
|
r43347 | uimerge = ui.config(b"ui", b"merge") | ||
|
r32256 | if uimerge: | ||
|
r43350 | ui.notenoi18n(b'with ui.merge=%r\n' % (pycompat.bytestr(uimerge))) | ||
|
r43347 | |||
ctx = scmutil.revsingle(repo, opts.get(b'rev')) | ||||
|
r32256 | m = scmutil.match(ctx, pats, opts) | ||
|
r43347 | changedelete = opts[b'changedelete'] | ||
|
r32256 | for path in ctx.walk(m): | ||
fctx = ctx[path] | ||||
try: | ||||
if not ui.debugflag: | ||||
ui.pushbuffer(error=True) | ||||
|
r43346 | tool, toolpath = filemerge._picktool( | ||
repo, | ||||
ui, | ||||
path, | ||||
fctx.isbinary(), | ||||
|
r43347 | b'l' in fctx.flags(), | ||
|
r43346 | changedelete, | ||
) | ||||
|
r32256 | finally: | ||
if not ui.debugflag: | ||||
ui.popbuffer() | ||||
|
r43347 | ui.write(b'%s = %s\n' % (path, tool)) | ||
@command(b'debugpushkey', [], _(b'REPO NAMESPACE [KEY OLD NEW]'), norepo=True) | ||||
|
r30946 | def debugpushkey(ui, repopath, namespace, *keyinfo, **opts): | ||
|
r46554 | """access the pushkey key/value protocol | ||
|
r30946 | |||
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. | ||||
|
r46554 | """ | ||
|
r30946 | |||
target = hg.peer(ui, {}, repopath) | ||||
if keyinfo: | ||||
key, old, new = keyinfo | ||||
|
r37665 | with target.commandexecutor() as e: | ||
|
r43346 | r = e.callcommand( | ||
|
r43347 | b'pushkey', | ||
{ | ||||
b'namespace': namespace, | ||||
b'key': key, | ||||
b'old': old, | ||||
b'new': new, | ||||
}, | ||||
|
r43346 | ).result() | ||
|
r37665 | |||
|
r43347 | ui.status(pycompat.bytestr(r) + b'\n') | ||
|
r30946 | return not r | ||
else: | ||||
|
r43376 | for k, v in sorted(pycompat.iteritems(target.listkeys(namespace))): | ||
|
r43346 | ui.write( | ||
|
r43347 | b"%s\t%s\n" % (stringutil.escapestr(k), stringutil.escapestr(v)) | ||
|
r43346 | ) | ||
|
r30946 | |||
|
r43347 | @command(b'debugpvec', [], _(b'A B')) | ||
|
r30947 | def debugpvec(ui, repo, a, b=None): | ||
ca = scmutil.revsingle(repo, a) | ||||
cb = scmutil.revsingle(repo, b) | ||||
pa = pvec.ctxpvec(ca) | ||||
pb = pvec.ctxpvec(cb) | ||||
if pa == pb: | ||||
|
r43347 | rel = b"=" | ||
|
r30947 | elif pa > pb: | ||
|
r43347 | rel = b">" | ||
|
r30947 | elif pa < pb: | ||
|
r43347 | rel = b"<" | ||
|
r30947 | elif pa | pb: | ||
|
r43347 | rel = b"|" | ||
ui.write(_(b"a: %s\n") % pa) | ||||
ui.write(_(b"b: %s\n") % pb) | ||||
ui.write(_(b"depth(a): %d depth(b): %d\n") % (pa._depth, pb._depth)) | ||||
|
r43346 | ui.write( | ||
|
r43347 | _(b"delta: %d hdist: %d distance: %d relation: %s\n") | ||
|
r43346 | % ( | ||
abs(pa._depth - pb._depth), | ||||
pvec._hamming(pa._vec, pb._vec), | ||||
pa.distance(pb), | ||||
rel, | ||||
) | ||||
) | ||||
@command( | ||||
|
r43347 | b'debugrebuilddirstate|debugrebuildstate', | ||
|
r43346 | [ | ||
|
r43347 | (b'r', b'rev', b'', _(b'revision to rebuild to'), _(b'REV')), | ||
|
r43346 | ( | ||
|
r43347 | b'', | ||
b'minimal', | ||||
|
r43346 | None, | ||
_( | ||||
|
r43347 | b'only rebuild files that are inconsistent with ' | ||
b'the working copy parent' | ||||
|
r43346 | ), | ||
), | ||||
|
r30948 | ], | ||
|
r43347 | _(b'[-r REV]'), | ||
|
r43346 | ) | ||
|
r30948 | def debugrebuilddirstate(ui, repo, rev, **opts): | ||
"""rebuild the dirstate as it would look like for the given revision | ||||
If no revision is specified the first current parent will be used. | ||||
The dirstate will be set to the files of the given revision. | ||||
The actual working directory content or existing dirstate | ||||
information such as adds or removes is not considered. | ||||
``minimal`` will only rebuild the dirstate status for files that claim to be | ||||
tracked but are not in the parent manifest, or that exist in the parent | ||||
manifest but are not in the dirstate. It will not change adds, removes, or | ||||
modified files that are in the working copy parent. | ||||
One use of this command is to make the next :hg:`status` invocation | ||||
check the actual file content. | ||||
""" | ||||
ctx = scmutil.revsingle(repo, rev) | ||||
with repo.wlock(): | ||||
dirstate = repo.dirstate | ||||
changedfiles = None | ||||
# See command doc for what minimal does. | ||||
|
r43906 | if opts.get('minimal'): | ||
|
r30948 | manifestfiles = set(ctx.manifest().keys()) | ||
dirstatefiles = set(dirstate) | ||||
manifestonly = manifestfiles - dirstatefiles | ||||
dsonly = dirstatefiles - manifestfiles | ||||
|
r44937 | dsnotadded = {f for f in dsonly if dirstate[f] != b'a'} | ||
|
r30948 | changedfiles = manifestonly | dsnotadded | ||
dirstate.rebuild(ctx.node(), ctx.manifest(), changedfiles) | ||||
|
r43346 | |||
|
r43347 | @command(b'debugrebuildfncache', [], b'') | ||
|
r30949 | def debugrebuildfncache(ui, repo): | ||
"""rebuild the fncache file""" | ||||
repair.rebuildfncache(ui, repo) | ||||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugrename', | ||
[(b'r', b'rev', b'', _(b'revision to debug'), _(b'REV'))], | ||||
_(b'[-r REV] [FILE]...'), | ||||
|
r43346 | ) | ||
|
r41839 | def debugrename(ui, repo, *pats, **opts): | ||
|
r30950 | """dump rename information""" | ||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r43347 | ctx = scmutil.revsingle(repo, opts.get(b'rev')) | ||
|
r41839 | m = scmutil.match(ctx, pats, opts) | ||
|
r30950 | for abs in ctx.walk(m): | ||
fctx = ctx[abs] | ||||
o = fctx.filelog().renamed(fctx.filenode()) | ||||
|
r41808 | rel = repo.pathto(abs) | ||
|
r30950 | if o: | ||
|
r43347 | ui.write(_(b"%s renamed from %s:%s\n") % (rel, o[0], hex(o[1]))) | ||
|
r30950 | else: | ||
|
r43347 | ui.write(_(b"%s not renamed\n") % rel) | ||
|
r30950 | |||
|
r43346 | |||
|
r45667 | @command(b'debugrequires|debugrequirements', [], b'') | ||
def debugrequirements(ui, repo): | ||||
""" print the current repo requirements """ | ||||
for r in sorted(repo.requirements): | ||||
ui.write(b"%s\n" % r) | ||||
|
r43346 | @command( | ||
|
r43347 | b'debugrevlog', | ||
cmdutil.debugrevlogopts + [(b'd', b'dump', False, _(b'dump index data'))], | ||||
_(b'-c|-m|FILE'), | ||||
|
r43346 | optionalrepo=True, | ||
) | ||||
|
r30951 | def debugrevlog(ui, repo, file_=None, **opts): | ||
"""show data and statistics about a revlog""" | ||||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r43347 | r = cmdutil.openrevlog(repo, b'debugrevlog', file_, opts) | ||
if opts.get(b"dump"): | ||||
|
r30951 | numrevs = len(r) | ||
|
r43346 | ui.write( | ||
( | ||||
|
r43347 | b"# rev p1rev p2rev start end deltastart base p1 p2" | ||
b" rawsize totalsize compression heads chainlen\n" | ||||
|
r43346 | ) | ||
) | ||||
|
r30951 | ts = 0 | ||
heads = set() | ||||
|
r38806 | for rev in pycompat.xrange(numrevs): | ||
|
r30951 | dbase = r.deltaparent(rev) | ||
if dbase == -1: | ||||
dbase = rev | ||||
cbase = r.chainbase(rev) | ||||
clen = r.chainlen(rev) | ||||
p1, p2 = r.parentrevs(rev) | ||||
rs = r.rawsize(rev) | ||||
ts = ts + rs | ||||
heads -= set(r.parentrevs(rev)) | ||||
heads.add(rev) | ||||
try: | ||||
compression = ts / r.end(rev) | ||||
except ZeroDivisionError: | ||||
compression = 0 | ||||
|
r43346 | ui.write( | ||
|
r43347 | b"%5d %5d %5d %5d %5d %10d %4d %4d %4d %7d %9d " | ||
b"%11d %5d %8d\n" | ||||
|
r43346 | % ( | ||
rev, | ||||
p1, | ||||
p2, | ||||
r.start(rev), | ||||
r.end(rev), | ||||
r.start(dbase), | ||||
r.start(cbase), | ||||
r.start(p1), | ||||
r.start(p2), | ||||
rs, | ||||
ts, | ||||
compression, | ||||
len(heads), | ||||
clen, | ||||
) | ||||
) | ||||
|
r30951 | return 0 | ||
v = r.version | ||||
format = v & 0xFFFF | ||||
flags = [] | ||||
gdelta = False | ||||
|
r32316 | if v & revlog.FLAG_INLINE_DATA: | ||
|
r43347 | flags.append(b'inline') | ||
|
r32316 | if v & revlog.FLAG_GENERALDELTA: | ||
|
r30951 | gdelta = True | ||
|
r43347 | flags.append(b'generaldelta') | ||
|
r30951 | if not flags: | ||
|
r43347 | flags = [b'(none)'] | ||
|
r30951 | |||
|
r39115 | ### tracks merge vs single parent | ||
|
r30951 | nummerges = 0 | ||
|
r39115 | |||
### tracks ways the "delta" are build | ||||
|
r39116 | # nodelta | ||
numempty = 0 | ||||
|
r39117 | numemptytext = 0 | ||
numemptydelta = 0 | ||||
|
r39115 | # full file content | ||
|
r30951 | numfull = 0 | ||
|
r39187 | # intermediate snapshot against a prior snapshot | ||
numsemi = 0 | ||||
|
r39189 | # snapshot count per depth | ||
numsnapdepth = collections.defaultdict(lambda: 0) | ||||
|
r39115 | # delta against previous revision | ||
|
r30951 | numprev = 0 | ||
|
r39115 | # delta against first or second parent (not prev) | ||
|
r30951 | nump1 = 0 | ||
nump2 = 0 | ||||
|
r39115 | # delta against neither prev nor parents | ||
|
r30951 | numother = 0 | ||
|
r39115 | # delta against prev that are also first or second parent | ||
# (details of `numprev`) | ||||
|
r30951 | nump1prev = 0 | ||
nump2prev = 0 | ||||
|
r39115 | |||
# data about delta chain of each revs | ||||
|
r30951 | chainlengths = [] | ||
r33057 | chainbases = [] | |||
chainspans = [] | ||||
|
r30951 | |||
|
r39115 | # data about each revision | ||
|
r30951 | datasize = [None, 0, 0] | ||
fullsize = [None, 0, 0] | ||||
|
r39187 | semisize = [None, 0, 0] | ||
|
r39189 | # snapshot count per depth | ||
snapsizedepth = collections.defaultdict(lambda: [None, 0, 0]) | ||||
|
r30951 | deltasize = [None, 0, 0] | ||
chunktypecounts = {} | ||||
chunktypesizes = {} | ||||
def addsize(size, l): | ||||
if l[0] is None or size < l[0]: | ||||
l[0] = size | ||||
if size > l[1]: | ||||
l[1] = size | ||||
l[2] += size | ||||
numrevs = len(r) | ||||
|
r38806 | for rev in pycompat.xrange(numrevs): | ||
|
r30951 | p1, p2 = r.parentrevs(rev) | ||
delta = r.deltaparent(rev) | ||||
if format > 0: | ||||
addsize(r.rawsize(rev), datasize) | ||||
if p2 != nullrev: | ||||
nummerges += 1 | ||||
size = r.length(rev) | ||||
if delta == nullrev: | ||||
chainlengths.append(0) | ||||
r33057 | chainbases.append(r.start(rev)) | |||
chainspans.append(size) | ||||
|
r39116 | if size == 0: | ||
numempty += 1 | ||||
|
r39117 | numemptytext += 1 | ||
|
r39116 | else: | ||
numfull += 1 | ||||
|
r39189 | numsnapdepth[0] += 1 | ||
|
r39116 | addsize(size, fullsize) | ||
|
r39189 | addsize(size, snapsizedepth[0]) | ||
|
r30951 | else: | ||
chainlengths.append(chainlengths[delta] + 1) | ||||
r33057 | baseaddr = chainbases[delta] | |||
revaddr = r.start(rev) | ||||
chainbases.append(baseaddr) | ||||
chainspans.append((revaddr - baseaddr) + size) | ||||
|
r39116 | if size == 0: | ||
numempty += 1 | ||||
|
r39117 | numemptydelta += 1 | ||
|
r39187 | elif r.issnapshot(rev): | ||
addsize(size, semisize) | ||||
numsemi += 1 | ||||
|
r39189 | depth = r.snapshotdepth(rev) | ||
numsnapdepth[depth] += 1 | ||||
addsize(size, snapsizedepth[depth]) | ||||
|
r39116 | else: | ||
addsize(size, deltasize) | ||||
if delta == rev - 1: | ||||
numprev += 1 | ||||
if delta == p1: | ||||
nump1prev += 1 | ||||
elif delta == p2: | ||||
nump2prev += 1 | ||||
elif delta == p1: | ||||
nump1 += 1 | ||||
|
r30951 | elif delta == p2: | ||
|
r39116 | nump2 += 1 | ||
elif delta != nullrev: | ||||
numother += 1 | ||||
|
r30951 | |||
# Obtain data on the raw chunks in the revlog. | ||||
|
r43347 | if util.safehasattr(r, b'_getsegmentforrevs'): | ||
|
r39184 | segment = r._getsegmentforrevs(rev, rev)[1] | ||
else: | ||||
segment = r._revlog._getsegmentforrevs(rev, rev)[1] | ||||
|
r32224 | if segment: | ||
|
r33106 | chunktype = bytes(segment[0:1]) | ||
|
r30951 | else: | ||
|
r43347 | chunktype = b'empty' | ||
|
r30951 | |||
if chunktype not in chunktypecounts: | ||||
chunktypecounts[chunktype] = 0 | ||||
chunktypesizes[chunktype] = 0 | ||||
chunktypecounts[chunktype] += 1 | ||||
chunktypesizes[chunktype] += size | ||||
# Adjust size min value for empty cases | ||||
|
r39187 | for size in (datasize, fullsize, semisize, deltasize): | ||
|
r30951 | if size[0] is None: | ||
size[0] = 0 | ||||
|
r39187 | numdeltas = numrevs - numfull - numempty - numsemi | ||
|
r30951 | numoprev = numprev - nump1prev - nump2prev | ||
totalrawsize = datasize[2] | ||||
datasize[2] /= numrevs | ||||
fulltotal = fullsize[2] | ||||
r42757 | if numfull == 0: | |||
fullsize[2] = 0 | ||||
else: | ||||
fullsize[2] /= numfull | ||||
|
r39187 | semitotal = semisize[2] | ||
|
r39189 | snaptotal = {} | ||
|
r40065 | if numsemi > 0: | ||
|
r39187 | semisize[2] /= numsemi | ||
|
r39189 | for depth in snapsizedepth: | ||
snaptotal[depth] = snapsizedepth[depth][2] | ||||
snapsizedepth[depth][2] /= numsnapdepth[depth] | ||||
|
r30951 | deltatotal = deltasize[2] | ||
|
r39116 | if numdeltas > 0: | ||
deltasize[2] /= numdeltas | ||||
|
r39187 | totalsize = fulltotal + semitotal + deltatotal | ||
|
r30951 | avgchainlen = sum(chainlengths) / numrevs | ||
maxchainlen = max(chainlengths) | ||||
r33057 | maxchainspan = max(chainspans) | |||
|
r30951 | compratio = 1 | ||
if totalsize: | ||||
compratio = totalrawsize / totalsize | ||||
|
r43347 | basedfmtstr = b'%%%dd\n' | ||
basepcfmtstr = b'%%%dd %s(%%5.2f%%%%)\n' | ||||
|
r30951 | |||
def dfmtstr(max): | ||||
return basedfmtstr % len(str(max)) | ||||
|
r43346 | |||
|
r30951 | def pcfmtstr(max, padding=0): | ||
|
r43347 | return basepcfmtstr % (len(str(max)), b' ' * padding) | ||
|
r30951 | |||
def pcfmt(value, total): | ||||
if total: | ||||
return (value, 100 * float(value) / total) | ||||
else: | ||||
return value, 100.0 | ||||
|
r43350 | ui.writenoi18n(b'format : %d\n' % format) | ||
ui.writenoi18n(b'flags : %s\n' % b', '.join(flags)) | ||||
|
r43347 | |||
ui.write(b'\n') | ||||
|
r30951 | fmt = pcfmtstr(totalsize) | ||
fmt2 = dfmtstr(totalsize) | ||||
|
r43350 | ui.writenoi18n(b'revisions : ' + fmt2 % numrevs) | ||
ui.writenoi18n(b' merges : ' + fmt % pcfmt(nummerges, numrevs)) | ||||
r43364 | ui.writenoi18n( | |||
b' normal : ' + fmt % pcfmt(numrevs - nummerges, numrevs) | ||||
) | ||||
|
r43350 | ui.writenoi18n(b'revisions : ' + fmt2 % numrevs) | ||
ui.writenoi18n(b' empty : ' + fmt % pcfmt(numempty, numrevs)) | ||||
ui.writenoi18n( | ||||
|
r43347 | b' text : ' | ||
|
r43346 | + fmt % pcfmt(numemptytext, numemptytext + numemptydelta) | ||
) | ||||
|
r43350 | ui.writenoi18n( | ||
|
r43347 | b' delta : ' | ||
|
r43346 | + fmt % pcfmt(numemptydelta, numemptytext + numemptydelta) | ||
) | ||||
r43364 | ui.writenoi18n( | |||
b' snapshot : ' + fmt % pcfmt(numfull + numsemi, numrevs) | ||||
) | ||||
|
r39189 | for depth in sorted(numsnapdepth): | ||
|
r43346 | ui.write( | ||
|
r43347 | (b' lvl-%-3d : ' % depth) | ||
|
r43346 | + fmt % pcfmt(numsnapdepth[depth], numrevs) | ||
) | ||||
|
r43350 | ui.writenoi18n(b' deltas : ' + fmt % pcfmt(numdeltas, numrevs)) | ||
ui.writenoi18n(b'revision size : ' + fmt2 % totalsize) | ||||
ui.writenoi18n( | ||||
|
r43347 | b' snapshot : ' + fmt % pcfmt(fulltotal + semitotal, totalsize) | ||
) | ||||
|
r39189 | for depth in sorted(numsnapdepth): | ||
|
r43346 | ui.write( | ||
|
r43347 | (b' lvl-%-3d : ' % depth) | ||
|
r43346 | + fmt % pcfmt(snaptotal[depth], totalsize) | ||
) | ||||
|
r43350 | ui.writenoi18n(b' deltas : ' + fmt % pcfmt(deltatotal, totalsize)) | ||
|
r30951 | |||
def fmtchunktype(chunktype): | ||||
|
r43347 | if chunktype == b'empty': | ||
return b' %s : ' % chunktype | ||||
|
r33107 | elif chunktype in pycompat.bytestr(string.ascii_letters): | ||
|
r43347 | return b' 0x%s (%s) : ' % (hex(chunktype), chunktype) | ||
|
r30951 | else: | ||
|
r43347 | return b' 0x%s : ' % hex(chunktype) | ||
ui.write(b'\n') | ||||
|
r43350 | ui.writenoi18n(b'chunks : ' + fmt2 % numrevs) | ||
|
r30951 | for chunktype in sorted(chunktypecounts): | ||
ui.write(fmtchunktype(chunktype)) | ||||
ui.write(fmt % pcfmt(chunktypecounts[chunktype], numrevs)) | ||||
|
r43350 | ui.writenoi18n(b'chunks size : ' + fmt2 % totalsize) | ||
|
r30951 | for chunktype in sorted(chunktypecounts): | ||
ui.write(fmtchunktype(chunktype)) | ||||
ui.write(fmt % pcfmt(chunktypesizes[chunktype], totalsize)) | ||||
|
r43347 | ui.write(b'\n') | ||
|
r33062 | fmt = dfmtstr(max(avgchainlen, maxchainlen, maxchainspan, compratio)) | ||
|
r43350 | ui.writenoi18n(b'avg chain length : ' + fmt % avgchainlen) | ||
ui.writenoi18n(b'max chain length : ' + fmt % maxchainlen) | ||||
ui.writenoi18n(b'max chain reach : ' + fmt % maxchainspan) | ||||
ui.writenoi18n(b'compression ratio : ' + fmt % compratio) | ||||
|
r30951 | |||
if format > 0: | ||||
|
r43347 | ui.write(b'\n') | ||
|
r43350 | ui.writenoi18n( | ||
|
r43347 | b'uncompressed data size (min/max/avg) : %d / %d / %d\n' | ||
|
r43346 | % tuple(datasize) | ||
) | ||||
|
r43350 | ui.writenoi18n( | ||
|
r43347 | b'full revision size (min/max/avg) : %d / %d / %d\n' | ||
|
r43346 | % tuple(fullsize) | ||
) | ||||
|
r43350 | ui.writenoi18n( | ||
|
r43347 | b'inter-snapshot size (min/max/avg) : %d / %d / %d\n' | ||
|
r43346 | % tuple(semisize) | ||
) | ||||
|
r39189 | for depth in sorted(snapsizedepth): | ||
if depth == 0: | ||||
continue | ||||
|
r43350 | ui.writenoi18n( | ||
|
r43347 | b' level-%-3d (min/max/avg) : %d / %d / %d\n' | ||
|
r43346 | % ((depth,) + tuple(snapsizedepth[depth])) | ||
) | ||||
|
r43350 | ui.writenoi18n( | ||
|
r43347 | b'delta size (min/max/avg) : %d / %d / %d\n' | ||
|
r43346 | % tuple(deltasize) | ||
) | ||||
|
r30951 | |||
if numdeltas > 0: | ||||
|
r43347 | ui.write(b'\n') | ||
|
r30951 | fmt = pcfmtstr(numdeltas) | ||
fmt2 = pcfmtstr(numdeltas, 4) | ||||
r43364 | ui.writenoi18n( | |||
b'deltas against prev : ' + fmt % pcfmt(numprev, numdeltas) | ||||
) | ||||
|
r30951 | if numprev > 0: | ||
|
r43350 | ui.writenoi18n( | ||
|
r43347 | b' where prev = p1 : ' + fmt2 % pcfmt(nump1prev, numprev) | ||
|
r43346 | ) | ||
|
r43350 | ui.writenoi18n( | ||
|
r43347 | b' where prev = p2 : ' + fmt2 % pcfmt(nump2prev, numprev) | ||
|
r43346 | ) | ||
|
r43350 | ui.writenoi18n( | ||
|
r43347 | b' other : ' + fmt2 % pcfmt(numoprev, numprev) | ||
|
r43346 | ) | ||
|
r30951 | if gdelta: | ||
r43364 | ui.writenoi18n( | |||
b'deltas against p1 : ' + fmt % pcfmt(nump1, numdeltas) | ||||
) | ||||
ui.writenoi18n( | ||||
b'deltas against p2 : ' + fmt % pcfmt(nump2, numdeltas) | ||||
) | ||||
|
r43350 | ui.writenoi18n( | ||
|
r43347 | b'deltas against other : ' + fmt % pcfmt(numother, numdeltas) | ||
|
r43346 | ) | ||
@command( | ||||
|
r43347 | b'debugrevlogindex', | ||
|
r43346 | cmdutil.debugrevlogopts | ||
|
r43347 | + [(b'f', b'format', 0, _(b'revlog format'), _(b'FORMAT'))], | ||
_(b'[-f FORMAT] -c|-m|FILE'), | ||||
|
r43346 | optionalrepo=True, | ||
) | ||||
|
r39318 | def debugrevlogindex(ui, repo, file_=None, **opts): | ||
"""dump the contents of a revlog index""" | ||||
opts = pycompat.byteskwargs(opts) | ||||
|
r43347 | r = cmdutil.openrevlog(repo, b'debugrevlogindex', file_, opts) | ||
format = opts.get(b'format', 0) | ||||
|
r39318 | if format not in (0, 1): | ||
|
r43347 | raise error.Abort(_(b"unknown format %d") % format) | ||
|
r39318 | |||
if ui.debugflag: | ||||
shortfn = hex | ||||
else: | ||||
shortfn = short | ||||
# There might not be anything in r, so have a sane default | ||||
idlen = 12 | ||||
for i in r: | ||||
idlen = len(shortfn(r.node(i))) | ||||
break | ||||
if format == 0: | ||||
if ui.verbose: | ||||
|
r43386 | ui.writenoi18n( | ||
|
r43387 | b" rev offset length linkrev %s %s p2\n" | ||
|
r43347 | % (b"nodeid".ljust(idlen), b"p1".ljust(idlen)) | ||
|
r43346 | ) | ||
|
r39318 | else: | ||
|
r43350 | ui.writenoi18n( | ||
|
r43347 | b" rev linkrev %s %s p2\n" | ||
% (b"nodeid".ljust(idlen), b"p1".ljust(idlen)) | ||||
|
r43346 | ) | ||
|
r39318 | elif format == 1: | ||
if ui.verbose: | ||||
|
r43386 | ui.writenoi18n( | ||
|
r43346 | ( | ||
|
r43347 | b" rev flag offset length size link p1" | ||
b" p2 %s\n" | ||||
|
r43346 | ) | ||
|
r43347 | % b"nodeid".rjust(idlen) | ||
|
r43346 | ) | ||
|
r39318 | else: | ||
|
r43350 | ui.writenoi18n( | ||
|
r43347 | b" rev flag size link p1 p2 %s\n" | ||
% b"nodeid".rjust(idlen) | ||||
|
r43346 | ) | ||
|
r39318 | |||
for i in r: | ||||
node = r.node(i) | ||||
if format == 0: | ||||
try: | ||||
pp = r.parents(node) | ||||
except Exception: | ||||
pp = [nullid, nullid] | ||||
if ui.verbose: | ||||
|
r43346 | ui.write( | ||
|
r43347 | b"% 6d % 9d % 7d % 7d %s %s %s\n" | ||
|
r43346 | % ( | ||
i, | ||||
r.start(i), | ||||
r.length(i), | ||||
r.linkrev(i), | ||||
shortfn(node), | ||||
shortfn(pp[0]), | ||||
shortfn(pp[1]), | ||||
) | ||||
) | ||||
|
r39318 | else: | ||
|
r43346 | ui.write( | ||
|
r43347 | b"% 6d % 7d %s %s %s\n" | ||
|
r43346 | % ( | ||
i, | ||||
r.linkrev(i), | ||||
shortfn(node), | ||||
shortfn(pp[0]), | ||||
shortfn(pp[1]), | ||||
) | ||||
) | ||||
|
r39318 | elif format == 1: | ||
pr = r.parentrevs(i) | ||||
if ui.verbose: | ||||
|
r43346 | ui.write( | ||
|
r43347 | b"% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d %s\n" | ||
|
r43346 | % ( | ||
i, | ||||
r.flags(i), | ||||
r.start(i), | ||||
r.length(i), | ||||
r.rawsize(i), | ||||
r.linkrev(i), | ||||
pr[0], | ||||
pr[1], | ||||
shortfn(node), | ||||
) | ||||
) | ||||
|
r39318 | else: | ||
|
r43346 | ui.write( | ||
|
r43347 | b"% 6d %04x % 8d % 6d % 6d % 6d %s\n" | ||
|
r43346 | % ( | ||
i, | ||||
r.flags(i), | ||||
r.rawsize(i), | ||||
r.linkrev(i), | ||||
pr[0], | ||||
pr[1], | ||||
shortfn(node), | ||||
) | ||||
) | ||||
@command( | ||||
|
r43347 | b'debugrevspec', | ||
|
r43346 | [ | ||
( | ||||
|
r43347 | b'', | ||
b'optimize', | ||||
|
r43346 | None, | ||
|
r43347 | _(b'print parsed tree after optimizing (DEPRECATED)'), | ||
|
r43346 | ), | ||
( | ||||
|
r43347 | b'', | ||
b'show-revs', | ||||
True, | ||||
_(b'print list of result revisions (default)'), | ||||
|
r43346 | ), | ||
( | ||||
|
r43347 | b's', | ||
b'show-set', | ||||
None, | ||||
_(b'print internal representation of result set'), | ||||
), | ||||
( | ||||
b'p', | ||||
b'show-stage', | ||||
|
r43346 | [], | ||
|
r43347 | _(b'print parsed tree at the given stage'), | ||
_(b'NAME'), | ||||
|
r43346 | ), | ||
|
r43347 | (b'', b'no-optimized', False, _(b'evaluate tree without optimization')), | ||
(b'', b'verify-optimized', False, _(b'verify optimized result')), | ||||
|
r43346 | ], | ||
|
r43347 | b'REVSPEC', | ||
|
r43346 | ) | ||
|
r30952 | def debugrevspec(ui, repo, expr, **opts): | ||
"""parse and apply a revision specification | ||||
Use -p/--show-stage option to print the parsed tree at the given stages. | ||||
Use -p all to print tree at every stage. | ||||
|
r32796 | Use --no-show-revs option with -s or -p to print only the set | ||
representation or the parsed tree respectively. | ||||
|
r30952 | Use --verify-optimized to compare the optimized result with the unoptimized | ||
one. Returns 1 if the optimized result differs. | ||||
""" | ||||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r43347 | aliases = ui.configitems(b'revsetalias') | ||
|
r30952 | stages = [ | ||
|
r43347 | (b'parsed', lambda tree: tree), | ||
|
r43346 | ( | ||
|
r43347 | b'expanded', | ||
|
r43346 | lambda tree: revsetlang.expandaliases(tree, aliases, ui.warn), | ||
), | ||||
|
r43347 | (b'concatenated', revsetlang.foldconcat), | ||
(b'analyzed', revsetlang.analyze), | ||||
(b'optimized', revsetlang.optimize), | ||||
|
r30952 | ] | ||
|
r43347 | if opts[b'no_optimized']: | ||
|
r30952 | stages = stages[:-1] | ||
|
r43347 | if opts[b'verify_optimized'] and opts[b'no_optimized']: | ||
|
r43346 | raise error.Abort( | ||
|
r43387 | _(b'cannot use --verify-optimized with --no-optimized') | ||
|
r43346 | ) | ||
|
r44937 | stagenames = {n for n, f in stages} | ||
|
r30952 | |||
showalways = set() | ||||
showchanged = set() | ||||
|
r43347 | if ui.verbose and not opts[b'show_stage']: | ||
|
r30952 | # show parsed tree by --verbose (deprecated) | ||
|
r43347 | showalways.add(b'parsed') | ||
showchanged.update([b'expanded', b'concatenated']) | ||||
if opts[b'optimize']: | ||||
showalways.add(b'optimized') | ||||
if opts[b'show_stage'] and opts[b'optimize']: | ||||
raise error.Abort(_(b'cannot use --optimize with --show-stage')) | ||||
if opts[b'show_stage'] == [b'all']: | ||||
|
r30952 | showalways.update(stagenames) | ||
else: | ||||
|
r43347 | for n in opts[b'show_stage']: | ||
|
r30952 | if n not in stagenames: | ||
|
r43347 | raise error.Abort(_(b'invalid stage name: %s') % n) | ||
showalways.update(opts[b'show_stage']) | ||||
|
r30952 | |||
treebystage = {} | ||||
printedtree = None | ||||
|
r37368 | tree = revsetlang.parse(expr, lookup=revset.lookupfn(repo)) | ||
|
r30952 | for n, f in stages: | ||
treebystage[n] = tree = f(tree) | ||||
if n in showalways or (n in showchanged and tree != printedtree): | ||||
|
r43347 | if opts[b'show_stage'] or n != b'parsed': | ||
ui.write(b"* %s:\n" % n) | ||||
ui.write(revsetlang.prettyformat(tree), b"\n") | ||||
|
r30952 | printedtree = tree | ||
|
r43347 | if opts[b'verify_optimized']: | ||
arevs = revset.makematcher(treebystage[b'analyzed'])(repo) | ||||
brevs = revset.makematcher(treebystage[b'optimized'])(repo) | ||||
if opts[b'show_set'] or (opts[b'show_set'] is None and ui.verbose): | ||||
r43364 | ui.writenoi18n( | |||
b"* analyzed set:\n", stringutil.prettyrepr(arevs), b"\n" | ||||
) | ||||
ui.writenoi18n( | ||||
b"* optimized set:\n", stringutil.prettyrepr(brevs), b"\n" | ||||
) | ||||
|
r30952 | arevs = list(arevs) | ||
brevs = list(brevs) | ||||
if arevs == brevs: | ||||
return 0 | ||||
|
r43350 | ui.writenoi18n(b'--- analyzed\n', label=b'diff.file_a') | ||
ui.writenoi18n(b'+++ optimized\n', label=b'diff.file_b') | ||||
|
r30952 | sm = difflib.SequenceMatcher(None, arevs, brevs) | ||
for tag, alo, ahi, blo, bhi in sm.get_opcodes(): | ||||
|
r43906 | if tag in ('delete', 'replace'): | ||
|
r30952 | for c in arevs[alo:ahi]: | ||
|
r43347 | ui.write(b'-%d\n' % c, label=b'diff.deleted') | ||
|
r43906 | if tag in ('insert', 'replace'): | ||
|
r30952 | for c in brevs[blo:bhi]: | ||
|
r43347 | ui.write(b'+%d\n' % c, label=b'diff.inserted') | ||
|
r43906 | if tag == 'equal': | ||
|
r30952 | for c in arevs[alo:ahi]: | ||
|
r43347 | ui.write(b' %d\n' % c) | ||
|
r30952 | return 1 | ||
func = revset.makematcher(tree) | ||||
revs = func(repo) | ||||
|
r43347 | if opts[b'show_set'] or (opts[b'show_set'] is None and ui.verbose): | ||
|
r43350 | ui.writenoi18n(b"* set:\n", stringutil.prettyrepr(revs), b"\n") | ||
|
r43347 | if not opts[b'show_revs']: | ||
|
r32796 | return | ||
|
r30952 | for c in revs: | ||
|
r43347 | ui.write(b"%d\n" % c) | ||
|
r30952 | |||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugserve', | ||
|
r43346 | [ | ||
( | ||||
|
r43347 | b'', | ||
b'sshstdio', | ||||
|
r43346 | False, | ||
|
r43347 | _(b'run an SSH server bound to process handles'), | ||
|
r43346 | ), | ||
|
r43347 | (b'', b'logiofd', b'', _(b'file descriptor to log server I/O to')), | ||
(b'', b'logiofile', b'', _(b'file to log server I/O to')), | ||||
|
r43346 | ], | ||
|
r43347 | b'', | ||
|
r43346 | ) | ||
|
r36544 | def debugserve(ui, repo, **opts): | ||
"""run a server with advanced settings | ||||
This command is similar to :hg:`serve`. It exists partially as a | ||||
workaround to the fact that ``hg serve --stdio`` must have specific | ||||
arguments for security reasons. | ||||
""" | ||||
opts = pycompat.byteskwargs(opts) | ||||
|
r43347 | if not opts[b'sshstdio']: | ||
raise error.Abort(_(b'only --sshstdio is currently supported')) | ||||
|
r36544 | |||
logfh = None | ||||
|
r43347 | if opts[b'logiofd'] and opts[b'logiofile']: | ||
raise error.Abort(_(b'cannot use both --logiofd and --logiofile')) | ||||
if opts[b'logiofd']: | ||||
|
r44582 | # Ideally we would be line buffered. But line buffering in binary | ||
# mode isn't supported and emits a warning in Python 3.8+. Disabling | ||||
# buffering could have performance impacts. But since this isn't | ||||
# performance critical code, it should be fine. | ||||
|
r38333 | try: | ||
|
r44582 | logfh = os.fdopen(int(opts[b'logiofd']), 'ab', 0) | ||
|
r38333 | except OSError as e: | ||
if e.errno != errno.ESPIPE: | ||||
raise | ||||
# can't seek a pipe, so `ab` mode fails on py3 | ||||
|
r44582 | logfh = os.fdopen(int(opts[b'logiofd']), 'wb', 0) | ||
|
r43347 | elif opts[b'logiofile']: | ||
|
r44582 | logfh = open(opts[b'logiofile'], b'ab', 0) | ||
|
r36544 | |||
s = wireprotoserver.sshserver(ui, repo, logfh=logfh) | ||||
s.serve_forever() | ||||
|
r43346 | |||
|
r43347 | @command(b'debugsetparents', [], _(b'REV1 [REV2]')) | ||
|
r30953 | def debugsetparents(ui, repo, rev1, rev2=None): | ||
"""manually set the parents of the current working directory | ||||
This is useful for writing repository conversion tools, but should | ||||
be used with care. For example, neither the working directory nor the | ||||
dirstate is updated, so file status may be incorrect after running this | ||||
command. | ||||
Returns 0 on success. | ||||
""" | ||||
|
r37161 | node1 = scmutil.revsingle(repo, rev1).node() | ||
|
r43347 | node2 = scmutil.revsingle(repo, rev2, b'null').node() | ||
|
r30953 | |||
with repo.wlock(): | ||||
|
r37161 | repo.setparents(node1, node2) | ||
|
r30953 | |||
|
r43346 | |||
|
r43347 | @command(b'debugsidedata', cmdutil.debugrevlogopts, _(b'-c|-m|FILE REV')) | ||
r43309 | def debugsidedata(ui, repo, file_, rev=None, **opts): | |||
r43406 | """dump the side data for a cl/manifest/file revision | |||
Use --verbose to dump the sidedata content.""" | ||||
r43309 | opts = pycompat.byteskwargs(opts) | |||
|
r43347 | if opts.get(b'changelog') or opts.get(b'manifest') or opts.get(b'dir'): | ||
r43309 | if rev is not None: | |||
|
r43347 | raise error.CommandError(b'debugdata', _(b'invalid arguments')) | ||
r43309 | file_, rev = None, file_ | |||
elif rev is None: | ||||
|
r43347 | raise error.CommandError(b'debugdata', _(b'invalid arguments')) | ||
r = cmdutil.openstorage(repo, b'debugdata', file_, opts) | ||||
r43309 | r = getattr(r, '_revlog', r) | |||
try: | ||||
sidedata = r.sidedata(r.lookup(rev)) | ||||
except KeyError: | ||||
|
r43347 | raise error.Abort(_(b'invalid revision identifier %s') % rev) | ||
r43309 | if sidedata: | |||
sidedata = list(sidedata.items()) | ||||
sidedata.sort() | ||||
|
r43386 | ui.writenoi18n(b'%d sidedata entries\n' % len(sidedata)) | ||
r43309 | for key, value in sidedata: | |||
|
r43386 | ui.writenoi18n(b' entry-%04o size %d\n' % (key, len(value))) | ||
r43309 | if ui.verbose: | |||
|
r43386 | ui.writenoi18n(b' %s\n' % stringutil.pprint(value)) | ||
|
r43347 | |||
@command(b'debugssl', [], b'[SOURCE]', optionalrepo=True) | ||||
|
r33493 | def debugssl(ui, repo, source=None, **opts): | ||
|
r46554 | """test a secure connection to a server | ||
|
r33493 | |||
This builds the certificate chain for the server on Windows, installing the | ||||
missing intermediates and trusted root via Windows Update if necessary. It | ||||
does nothing on other platforms. | ||||
If SOURCE is omitted, the 'default' path will be used. If a URL is given, | ||||
that server is used. See :hg:`help urls` for more information. | ||||
If the update succeeds, retry the original operation. Otherwise, the cause | ||||
of the SSL error is likely another issue. | ||||
|
r46554 | """ | ||
|
r34646 | if not pycompat.iswindows: | ||
|
r43346 | raise error.Abort( | ||
|
r43387 | _(b'certificate chain building is only possible on Windows') | ||
|
r43346 | ) | ||
|
r33493 | |||
if not source: | ||||
|
r34031 | if not repo: | ||
|
r43346 | raise error.Abort( | ||
_( | ||||
|
r43347 | b"there is no Mercurial repository here, and no " | ||
b"server specified" | ||||
|
r43346 | ) | ||
) | ||||
|
r43347 | source = b"default" | ||
|
r33493 | |||
source, branches = hg.parseurl(ui.expandpath(source)) | ||||
url = util.url(source) | ||||
|
r43347 | defaultport = {b'https': 443, b'ssh': 22} | ||
|
r35444 | if url.scheme in defaultport: | ||
try: | ||||
addr = (url.host, int(url.port or defaultport[url.scheme])) | ||||
except ValueError: | ||||
|
r43347 | raise error.Abort(_(b"malformed port number in URL")) | ||
|
r33493 | else: | ||
|
r43347 | raise error.Abort(_(b"only https and ssh connections are supported")) | ||
|
r33493 | |||
from . import win32 | ||||
|
r43346 | s = ssl.wrap_socket( | ||
socket.socket(), | ||||
ssl_version=ssl.PROTOCOL_TLS, | ||||
cert_reqs=ssl.CERT_NONE, | ||||
ca_certs=None, | ||||
) | ||||
|
r33493 | |||
try: | ||||
s.connect(addr) | ||||
cert = s.getpeercert(True) | ||||
|
r43347 | ui.status(_(b'checking the certificate chain for %s\n') % url.host) | ||
|
r33493 | |||
complete = win32.checkcertificatechain(cert, build=False) | ||||
if not complete: | ||||
|
r43347 | ui.status(_(b'certificate chain is incomplete, updating... ')) | ||
|
r33493 | |||
if not win32.checkcertificatechain(cert): | ||||
|
r43347 | ui.status(_(b'failed.\n')) | ||
|
r33493 | else: | ||
|
r43347 | ui.status(_(b'done.\n')) | ||
|
r33493 | else: | ||
|
r43347 | ui.status(_(b'full certificate chain is available\n')) | ||
|
r33493 | finally: | ||
s.close() | ||||
|
r43346 | |||
@command( | ||||
|
r44915 | b"debugbackupbundle", | ||
[ | ||||
( | ||||
b"", | ||||
b"recover", | ||||
b"", | ||||
b"brings the specified changeset back into the repository", | ||||
) | ||||
] | ||||
+ cmdutil.logopts, | ||||
_(b"hg debugbackupbundle [--recover HASH]"), | ||||
) | ||||
def debugbackupbundle(ui, repo, *pats, **opts): | ||||
"""lists the changesets available in backup bundles | ||||
Without any arguments, this command prints a list of the changesets in each | ||||
backup bundle. | ||||
--recover takes a changeset hash and unbundles the first bundle that | ||||
contains that hash, which puts that changeset back in your repository. | ||||
--verbose will print the entire commit message and the bundle path for that | ||||
backup. | ||||
""" | ||||
backups = list( | ||||
filter( | ||||
os.path.isfile, glob.glob(repo.vfs.join(b"strip-backup") + b"/*.hg") | ||||
) | ||||
) | ||||
backups.sort(key=lambda x: os.path.getmtime(x), reverse=True) | ||||
opts = pycompat.byteskwargs(opts) | ||||
opts[b"bundle"] = b"" | ||||
opts[b"force"] = None | ||||
limit = logcmdutil.getlimit(opts) | ||||
def display(other, chlist, displayer): | ||||
if opts.get(b"newest_first"): | ||||
chlist.reverse() | ||||
count = 0 | ||||
for n in chlist: | ||||
if limit is not None and count >= limit: | ||||
break | ||||
parents = [True for p in other.changelog.parents(n) if p != nullid] | ||||
if opts.get(b"no_merges") and len(parents) == 2: | ||||
continue | ||||
count += 1 | ||||
displayer.show(other[n]) | ||||
recovernode = opts.get(b"recover") | ||||
if recovernode: | ||||
if scmutil.isrevsymbol(repo, recovernode): | ||||
ui.warn(_(b"%s already exists in the repo\n") % recovernode) | ||||
return | ||||
elif backups: | ||||
msg = _( | ||||
b"Recover changesets using: hg debugbackupbundle --recover " | ||||
b"<changeset hash>\n\nAvailable backup changesets:" | ||||
) | ||||
ui.status(msg, label=b"status.removed") | ||||
else: | ||||
ui.status(_(b"no backup changesets found\n")) | ||||
return | ||||
for backup in backups: | ||||
# Much of this is copied from the hg incoming logic | ||||
source = ui.expandpath(os.path.relpath(backup, encoding.getcwd())) | ||||
source, branches = hg.parseurl(source, opts.get(b"branch")) | ||||
try: | ||||
other = hg.peer(repo, opts, source) | ||||
except error.LookupError as ex: | ||||
msg = _(b"\nwarning: unable to open bundle %s") % source | ||||
hint = _(b"\n(missing parent rev %s)\n") % short(ex.name) | ||||
ui.warn(msg, hint=hint) | ||||
continue | ||||
revs, checkout = hg.addbranchrevs( | ||||
repo, other, branches, opts.get(b"rev") | ||||
) | ||||
if revs: | ||||
revs = [other.lookup(rev) for rev in revs] | ||||
quiet = ui.quiet | ||||
try: | ||||
ui.quiet = True | ||||
other, chlist, cleanupfn = bundlerepo.getremotechanges( | ||||
ui, repo, other, revs, opts[b"bundle"], opts[b"force"] | ||||
) | ||||
except error.LookupError: | ||||
continue | ||||
finally: | ||||
ui.quiet = quiet | ||||
try: | ||||
if not chlist: | ||||
continue | ||||
if recovernode: | ||||
with repo.lock(), repo.transaction(b"unbundle") as tr: | ||||
if scmutil.isrevsymbol(other, recovernode): | ||||
ui.status(_(b"Unbundling %s\n") % (recovernode)) | ||||
f = hg.openpath(ui, source) | ||||
gen = exchange.readbundle(ui, f, source) | ||||
if isinstance(gen, bundle2.unbundle20): | ||||
bundle2.applybundle( | ||||
repo, | ||||
gen, | ||||
tr, | ||||
source=b"unbundle", | ||||
url=b"bundle:" + source, | ||||
) | ||||
else: | ||||
gen.apply(repo, b"unbundle", b"bundle:" + source) | ||||
break | ||||
else: | ||||
backupdate = encoding.strtolocal( | ||||
time.strftime( | ||||
"%a %H:%M, %Y-%m-%d", | ||||
time.localtime(os.path.getmtime(source)), | ||||
) | ||||
) | ||||
ui.status(b"\n%s\n" % (backupdate.ljust(50))) | ||||
if ui.verbose: | ||||
ui.status(b"%s%s\n" % (b"bundle:".ljust(13), source)) | ||||
else: | ||||
opts[ | ||||
b"template" | ||||
] = b"{label('status.modified', node|short)} {desc|firstline}\n" | ||||
displayer = logcmdutil.changesetdisplayer( | ||||
ui, other, opts, False | ||||
) | ||||
display(other, chlist, displayer) | ||||
displayer.close() | ||||
finally: | ||||
cleanupfn() | ||||
@command( | ||||
|
r43347 | b'debugsub', | ||
[(b'r', b'rev', b'', _(b'revision to check'), _(b'REV'))], | ||||
_(b'[-r REV] [REV]'), | ||||
|
r43346 | ) | ||
|
r30955 | def debugsub(ui, repo, rev=None): | ||
ctx = scmutil.revsingle(repo, rev, None) | ||||
for k, v in sorted(ctx.substate.items()): | ||||
|
r43350 | ui.writenoi18n(b'path %s\n' % k) | ||
ui.writenoi18n(b' source %s\n' % v[0]) | ||||
ui.writenoi18n(b' revision %s\n' % v[1]) | ||||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugsuccessorssets', | ||
[(b'', b'closest', False, _(b'return closest successors sets only'))], | ||||
_(b'[REV]'), | ||||
|
r43346 | ) | ||
|
r33274 | def debugsuccessorssets(ui, repo, *revs, **opts): | ||
|
r30956 | """show set of successors for revision | ||
A successors set of changeset A is a consistent group of revisions that | ||||
|
r33274 | succeed A. It contains non-obsolete changesets only unless closests | ||
successors set is set. | ||||
|
r30956 | |||
In most cases a changeset A has a single successors set containing a single | ||||
successor (changeset A replaced by A'). | ||||
A changeset that is made obsolete with no successors are called "pruned". | ||||
Such changesets have no successors sets at all. | ||||
A changeset that has been "split" will have a successors set containing | ||||
more than one successor. | ||||
A changeset that has been rewritten in multiple different ways is called | ||||
"divergent". Such changesets have multiple successor sets (each of which | ||||
may also be split, i.e. have multiple successors). | ||||
Results are displayed as follows:: | ||||
<rev1> | ||||
<successors-1A> | ||||
<rev2> | ||||
<successors-2A> | ||||
<successors-2B1> <successors-2B2> <successors-2B3> | ||||
Here rev2 has two possible (i.e. divergent) successors sets. The first | ||||
holds one element, whereas the second holds three (i.e. the changeset has | ||||
been split). | ||||
""" | ||||
# passed to successorssets caching computation from one call to another | ||||
cache = {} | ||||
|
r36140 | ctx2str = bytes | ||
|
r30956 | node2str = short | ||
for rev in scmutil.revrange(repo, revs): | ||||
ctx = repo[rev] | ||||
|
r43347 | ui.write(b'%s\n' % ctx2str(ctx)) | ||
|
r43346 | for succsset in obsutil.successorssets( | ||
|
r43906 | repo, ctx.node(), closest=opts['closest'], cache=cache | ||
|
r43346 | ): | ||
|
r30956 | if succsset: | ||
|
r43347 | ui.write(b' ') | ||
|
r30956 | ui.write(node2str(succsset[0])) | ||
for node in succsset[1:]: | ||||
|
r43347 | ui.write(b' ') | ||
|
r30956 | ui.write(node2str(node)) | ||
|
r43347 | ui.write(b'\n') | ||
|
r30956 | |||
|
r44787 | |||
|
r44772 | @command(b'debugtagscache', []) | ||
def debugtagscache(ui, repo): | ||||
"""display the contents of .hg/cache/hgtagsfnodes1""" | ||||
cache = tagsmod.hgtagsfnodescache(repo.unfiltered()) | ||||
for r in repo: | ||||
node = repo[r].node() | ||||
tagsnode = cache.getfnode(node, computemissing=False) | ||||
|
r44824 | tagsnodedisplay = hex(tagsnode) if tagsnode else b'missing/invalid' | ||
ui.write(b'%d %s %s\n' % (r, hex(node), tagsnodedisplay)) | ||||
|
r43346 | |||
|
r44787 | |||
|
r43346 | @command( | ||
|
r43347 | b'debugtemplate', | ||
|
r43346 | [ | ||
|
r43347 | (b'r', b'rev', [], _(b'apply template on changesets'), _(b'REV')), | ||
(b'D', b'define', [], _(b'define template keyword'), _(b'KEY=VALUE')), | ||||
|
r43346 | ], | ||
|
r43347 | _(b'[-r REV]... [-D KEY=VALUE]... TEMPLATE'), | ||
|
r43346 | optionalrepo=True, | ||
) | ||||
|
r30957 | def debugtemplate(ui, repo, tmpl, **opts): | ||
"""parse and apply a template | ||||
If -r/--rev is given, the template is processed as a log template and | ||||
applied to the given changesets. Otherwise, it is processed as a generic | ||||
template. | ||||
Use --verbose to print the parsed tree. | ||||
""" | ||||
revs = None | ||||
|
r43906 | if opts['rev']: | ||
|
r30957 | if repo is None: | ||
|
r43346 | raise error.RepoError( | ||
|
r43387 | _(b'there is no Mercurial repository here (.hg not found)') | ||
|
r43346 | ) | ||
|
r43906 | revs = scmutil.revrange(repo, opts['rev']) | ||
|
r30957 | |||
props = {} | ||||
|
r43906 | for d in opts['define']: | ||
|
r30957 | try: | ||
|
r43347 | k, v = (e.strip() for e in d.split(b'=', 1)) | ||
if not k or k == b'ui': | ||||
|
r30957 | raise ValueError | ||
props[k] = v | ||||
except ValueError: | ||||
|
r43347 | raise error.Abort(_(b'malformed keyword definition: %s') % d) | ||
|
r30957 | |||
if ui.verbose: | ||||
|
r43347 | aliases = ui.configitems(b'templatealias') | ||
|
r30957 | tree = templater.parse(tmpl) | ||
|
r43347 | ui.note(templater.prettyformat(tree), b'\n') | ||
|
r30957 | newtree = templater.expandaliases(tree, aliases) | ||
if newtree != tree: | ||||
r43364 | ui.notenoi18n( | |||
b"* expanded:\n", templater.prettyformat(newtree), b'\n' | ||||
) | ||||
|
r30957 | |||
if revs is None: | ||||
|
r35485 | tres = formatter.templateresources(ui, repo) | ||
t = formatter.maketemplater(ui, tmpl, resources=tres) | ||||
|
r38374 | if ui.verbose: | ||
kwds, funcs = t.symbolsuseddefault() | ||||
|
r43350 | ui.writenoi18n(b"* keywords: %s\n" % b', '.join(sorted(kwds))) | ||
ui.writenoi18n(b"* functions: %s\n" % b', '.join(sorted(funcs))) | ||||
|
r37003 | ui.write(t.renderdefault(props)) | ||
|
r30957 | else: | ||
|
r35906 | displayer = logcmdutil.maketemplater(ui, repo, tmpl) | ||
|
r38374 | if ui.verbose: | ||
kwds, funcs = displayer.t.symbolsuseddefault() | ||||
|
r43350 | ui.writenoi18n(b"* keywords: %s\n" % b', '.join(sorted(kwds))) | ||
ui.writenoi18n(b"* functions: %s\n" % b', '.join(sorted(funcs))) | ||||
|
r30957 | for r in revs: | ||
|
r33102 | displayer.show(repo[r], **pycompat.strkwargs(props)) | ||
|
r30957 | displayer.close() | ||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debuguigetpass', | ||
|
r46554 | [ | ||
(b'p', b'prompt', b'', _(b'prompt text'), _(b'TEXT')), | ||||
], | ||||
|
r43347 | _(b'[-p TEXT]'), | ||
|
r43346 | norepo=True, | ||
) | ||||
|
r43347 | def debuguigetpass(ui, prompt=b''): | ||
|
r36810 | """show prompt to type password""" | ||
r = ui.getpass(prompt) | ||||
|
r46628 | if r is not None: | ||
r = encoding.strtolocal(r) | ||||
else: | ||||
r = b"<default response>" | ||||
|
r45148 | ui.writenoi18n(b'response: %s\n' % r) | ||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debuguiprompt', | ||
|
r46554 | [ | ||
(b'p', b'prompt', b'', _(b'prompt text'), _(b'TEXT')), | ||||
], | ||||
|
r43347 | _(b'[-p TEXT]'), | ||
|
r43346 | norepo=True, | ||
) | ||||
|
r43347 | def debuguiprompt(ui, prompt=b''): | ||
|
r36810 | """show plain prompt""" | ||
r = ui.prompt(prompt) | ||||
|
r43350 | ui.writenoi18n(b'response: %s\n' % r) | ||
|
r43347 | |||
@command(b'debugupdatecaches', []) | ||||
|
r32265 | def debugupdatecaches(ui, repo, *pats, **opts): | ||
"""warm all known caches in the repository""" | ||||
|
r33438 | with repo.wlock(), repo.lock(): | ||
|
r36970 | repo.updatecaches(full=True) | ||
|
r32265 | |||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugupgraderepo', | ||
|
r43346 | [ | ||
|
r43347 | ( | ||
b'o', | ||||
b'optimize', | ||||
[], | ||||
_(b'extra optimization to perform'), | ||||
_(b'NAME'), | ||||
), | ||||
(b'', b'run', False, _(b'performs an upgrade')), | ||||
(b'', b'backup', True, _(b'keep the old repository content around')), | ||||
(b'', b'changelog', None, _(b'select the changelog for upgrade')), | ||||
(b'', b'manifest', None, _(b'select the manifest for upgrade')), | ||||
r46612 | (b'', b'filelogs', None, _(b'select all filelogs for upgrade')), | |||
|
r43346 | ], | ||
) | ||||
r43098 | def debugupgraderepo(ui, repo, run=False, optimize=None, backup=True, **opts): | |||
|
r30774 | """upgrade a repository to use different features | ||
If no arguments are specified, the repository is evaluated for upgrade | ||||
and a list of problems and potential optimizations is printed. | ||||
With ``--run``, a repository upgrade is performed. Behavior of the upgrade | ||||
can be influenced via additional arguments. More details will be provided | ||||
by the command output when run without ``--run``. | ||||
During the upgrade, the repository will be locked and no writes will be | ||||
allowed. | ||||
At the end of the upgrade, the repository may not be readable while new | ||||
repository data is swapped in. This window will be as long as it takes to | ||||
rename some directories inside the ``.hg`` directory. On most machines, this | ||||
should complete almost instantaneously and the chances of a consumer being | ||||
unable to access the repository should be low. | ||||
r43098 | ||||
By default, all revlog will be upgraded. You can restrict this using flag | ||||
such as `--manifest`: | ||||
* `--manifest`: only optimize the manifest | ||||
* `--no-manifest`: optimize all revlog but the manifest | ||||
r43099 | * `--changelog`: optimize the changelog only | |||
* `--no-changelog --no-manifest`: optimize filelogs only | ||||
r46612 | * `--filelogs`: optimize the filelogs only | |||
* `--no-changelog --no-manifest --no-filelogs`: skip all filelog optimisation | ||||
|
r30774 | """ | ||
|
r43346 | return upgrade.upgraderepo( | ||
ui, repo, run=run, optimize=optimize, backup=backup, **opts | ||||
) | ||||
@command( | ||||
|
r43347 | b'debugwalk', cmdutil.walkopts, _(b'[OPTION]... [FILE]...'), inferrepo=True | ||
|
r43346 | ) | ||
|
r30958 | def debugwalk(ui, repo, *pats, **opts): | ||
"""show how files match on given patterns""" | ||||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r30958 | m = scmutil.match(repo[None], pats, opts) | ||
|
r38281 | if ui.verbose: | ||
|
r43350 | ui.writenoi18n(b'* matcher:\n', stringutil.prettyrepr(m), b'\n') | ||
|
r32363 | items = list(repo[None].walk(m)) | ||
|
r30958 | if not items: | ||
return | ||||
f = lambda fn: fn | ||||
|
r43347 | if ui.configbool(b'ui', b'slash') and pycompat.ossep != b'/': | ||
|
r30958 | f = lambda fn: util.normpath(fn) | ||
|
r43347 | fmt = b'f %%-%ds %%-%ds %%s' % ( | ||
|
r30958 | max([len(abs) for abs in items]), | ||
|
r43346 | max([len(repo.pathto(abs)) for abs in items]), | ||
) | ||||
|
r30958 | for abs in items: | ||
|
r43347 | line = fmt % ( | ||
abs, | ||||
f(repo.pathto(abs)), | ||||
m.exact(abs) and b'exact' or b'', | ||||
) | ||||
ui.write(b"%s\n" % line.rstrip()) | ||||
@command(b'debugwhyunstable', [], _(b'REV')) | ||||
r36972 | def debugwhyunstable(ui, repo, rev): | |||
"""explain instabilities of a changeset""" | ||||
|
r37414 | for entry in obsutil.whyunstable(repo, scmutil.revsingle(repo, rev)): | ||
|
r43347 | dnodes = b'' | ||
if entry.get(b'divergentnodes'): | ||||
|
r43346 | dnodes = ( | ||
|
r43347 | b' '.join( | ||
b'%s (%s)' % (ctx.hex(), ctx.phasestr()) | ||||
for ctx in entry[b'divergentnodes'] | ||||
|
r43346 | ) | ||
|
r43347 | + b' ' | ||
|
r43346 | ) | ||
ui.write( | ||||
|
r43347 | b'%s: %s%s %s\n' | ||
% (entry[b'instability'], dnodes, entry[b'reason'], entry[b'node']) | ||||
|
r43346 | ) | ||
@command( | ||||
|
r43347 | b'debugwireargs', | ||
|
r43346 | [ | ||
|
r43347 | (b'', b'three', b'', b'three'), | ||
(b'', b'four', b'', b'four'), | ||||
(b'', b'five', b'', b'five'), | ||||
|
r43346 | ] | ||
+ cmdutil.remoteopts, | ||||
|
r43347 | _(b'REPO [OPTIONS]... [ONE [TWO]]'), | ||
|
r43346 | norepo=True, | ||
) | ||||
|
r30959 | def debugwireargs(ui, repopath, *vals, **opts): | ||
|
r33100 | opts = pycompat.byteskwargs(opts) | ||
|
r30959 | repo = hg.peer(ui, opts, repopath) | ||
|
r32375 | for opt in cmdutil.remoteopts: | ||
|
r30959 | del opts[opt[1]] | ||
args = {} | ||||
|
r43376 | for k, v in pycompat.iteritems(opts): | ||
|
r30959 | if v: | ||
args[k] = v | ||||
|
r35402 | args = pycompat.strkwargs(args) | ||
|
r30959 | # run twice to check that we don't mess up the stream for the next command | ||
res1 = repo.debugwireargs(*vals, **args) | ||||
res2 = repo.debugwireargs(*vals, **args) | ||||
|
r43347 | ui.write(b"%s\n" % res1) | ||
|
r30959 | if res1 != res2: | ||
|
r43347 | ui.warn(b"%s\n" % res2) | ||
|
r36545 | |||
|
r43346 | |||
|
r36545 | def _parsewirelangblocks(fh): | ||
activeaction = None | ||||
blocklines = [] | ||||
|
r40210 | lastindent = 0 | ||
|
r36545 | |||
for line in fh: | ||||
line = line.rstrip() | ||||
if not line: | ||||
continue | ||||
if line.startswith(b'#'): | ||||
continue | ||||
|
r39097 | if not line.startswith(b' '): | ||
|
r36545 | # New block. Flush previous one. | ||
if activeaction: | ||||
yield activeaction, blocklines | ||||
activeaction = line | ||||
blocklines = [] | ||||
|
r40210 | lastindent = 0 | ||
|
r36545 | continue | ||
# Else we start with an indent. | ||||
if not activeaction: | ||||
|
r43347 | raise error.Abort(_(b'indented line outside of block')) | ||
|
r36545 | |||
|
r40210 | indent = len(line) - len(line.lstrip()) | ||
# If this line is indented more than the last line, concatenate it. | ||||
if indent > lastindent and blocklines: | ||||
blocklines[-1] += line.lstrip() | ||||
else: | ||||
blocklines.append(line) | ||||
lastindent = indent | ||||
|
r36545 | |||
# Flush last block. | ||||
if activeaction: | ||||
yield activeaction, blocklines | ||||
|
r43346 | |||
@command( | ||||
|
r43347 | b'debugwireproto', | ||
|
r36545 | [ | ||
|
r43347 | (b'', b'localssh', False, _(b'start an SSH server for this repo')), | ||
(b'', b'peer', b'', _(b'construct a specific version of the peer')), | ||||
|
r43346 | ( | ||
|
r43347 | b'', | ||
b'noreadstderr', | ||||
|
r43346 | False, | ||
|
r43347 | _(b'do not read from stderr of the remote'), | ||
), | ||||
( | ||||
b'', | ||||
b'nologhandshake', | ||||
False, | ||||
_(b'do not log I/O related to the peer handshake'), | ||||
|
r43346 | ), | ||
] | ||||
+ cmdutil.remoteopts, | ||||
|
r43347 | _(b'[PATH]'), | ||
|
r43346 | optionalrepo=True, | ||
) | ||||
|
r37030 | def debugwireproto(ui, repo, path=None, **opts): | ||
|
r36545 | """send wire protocol commands to a server | ||
This command can be used to issue wire protocol commands to remote | ||||
peers and to debug the raw data being exchanged. | ||||
``--localssh`` will start an SSH server against the current repository | ||||
and connect to that. By default, the connection will perform a handshake | ||||
and establish an appropriate peer instance. | ||||
``--peer`` can be used to bypass the handshake protocol and construct a | ||||
peer instance using the specified class type. Valid values are ``raw``, | ||||
|
r37501 | ``http2``, ``ssh1``, and ``ssh2``. ``raw`` instances only allow sending | ||
raw data payloads and don't support higher-level command actions. | ||||
|
r36545 | |||
|
r36551 | ``--noreadstderr`` can be used to disable automatic reading from stderr | ||
of the peer (for SSH connections only). Disabling automatic reading of | ||||
stderr is useful for making output more deterministic. | ||||
|
r36545 | Commands are issued via a mini language which is specified via stdin. | ||
The language consists of individual actions to perform. An action is | ||||
defined by a block. A block is defined as a line with no leading | ||||
space followed by 0 or more lines with leading space. Blocks are | ||||
effectively a high-level command with additional metadata. | ||||
Lines beginning with ``#`` are ignored. | ||||
The following sections denote available actions. | ||||
raw | ||||
--- | ||||
Send raw data to the server. | ||||
The block payload contains the raw data to send as one atomic send | ||||
operation. The data may not actually be delivered in a single system | ||||
call: it depends on the abilities of the transport being used. | ||||
Each line in the block is de-indented and concatenated. Then, that | ||||
value is evaluated as a Python b'' literal. This allows the use of | ||||
backslash escaping, etc. | ||||
raw+ | ||||
---- | ||||
Behaves like ``raw`` except flushes output afterwards. | ||||
|
r36547 | command <X> | ||
----------- | ||||
Send a request to run a named command, whose name follows the ``command`` | ||||
string. | ||||
Arguments to the command are defined as lines in this block. The format of | ||||
each line is ``<key> <value>``. e.g.:: | ||||
command listkeys | ||||
namespace bookmarks | ||||
|
r37501 | If the value begins with ``eval:``, it will be interpreted as a Python | ||
literal expression. Otherwise values are interpreted as Python b'' literals. | ||||
This allows sending complex types and encoding special byte sequences via | ||||
backslash escaping. | ||||
|
r36547 | |||
|
r36551 | The following arguments have special meaning: | ||
``PUSHFILE`` | ||||
When defined, the *push* mechanism of the peer will be used instead | ||||
of the static request-response mechanism and the content of the | ||||
file specified in the value of this argument will be sent as the | ||||
command payload. | ||||
This can be used to submit a local bundle file to the remote. | ||||
|
r36548 | batchbegin | ||
---------- | ||||
Instruct the peer to begin a batched send. | ||||
All ``command`` blocks are queued for execution until the next | ||||
``batchsubmit`` block. | ||||
batchsubmit | ||||
----------- | ||||
Submit previously queued ``command`` blocks as a batch request. | ||||
This action MUST be paired with a ``batchbegin`` action. | ||||
|
r37031 | httprequest <method> <path> | ||
--------------------------- | ||||
(HTTP peer only) | ||||
Send an HTTP request to the peer. | ||||
The HTTP request line follows the ``httprequest`` action. e.g. ``GET /foo``. | ||||
Arguments of the form ``<key>: <value>`` are interpreted as HTTP request | ||||
headers to add to the request. e.g. ``Accept: foo``. | ||||
The following arguments are special: | ||||
``BODYFILE`` | ||||
The content of the file defined as the value to this argument will be | ||||
transferred verbatim as the HTTP request body. | ||||
|
r37069 | ``frame <type> <flags> <payload>`` | ||
Send a unified protocol frame as part of the request body. | ||||
All frames will be collected and sent as the body to the HTTP | ||||
request. | ||||
|
r36545 | close | ||
----- | ||||
Close the connection to the server. | ||||
flush | ||||
----- | ||||
Flush data written to the server. | ||||
readavailable | ||||
------------- | ||||
|
r36861 | Close the write end of the connection and read all available data from | ||
the server. | ||||
|
r36545 | |||
If the connection to the server encompasses multiple pipes, we poll both | ||||
pipes and read available data. | ||||
readline | ||||
-------- | ||||
Read a line of output from the server. If there are multiple output | ||||
pipes, reads only the main pipe. | ||||
|
r37025 | |||
ereadline | ||||
--------- | ||||
Like ``readline``, but read from the stderr pipe, if available. | ||||
read <X> | ||||
-------- | ||||
``read()`` N bytes from the server's main output pipe. | ||||
eread <X> | ||||
--------- | ||||
``read()`` N bytes from the server's stderr pipe, if available. | ||||
|
r37069 | |||
Specifying Unified Frame-Based Protocol Frames | ||||
---------------------------------------------- | ||||
It is possible to emit a *Unified Frame-Based Protocol* by using special | ||||
syntax. | ||||
A frame is composed as a type, flags, and payload. These can be parsed | ||||
|
r37304 | from a string of the form: | ||
<request-id> <stream-id> <stream-flags> <type> <flags> <payload> | ||||
``request-id`` and ``stream-id`` are integers defining the request and | ||||
stream identifiers. | ||||
|
r37075 | |||
|
r37069 | ``type`` can be an integer value for the frame type or the string name | ||
of the type. The strings are defined in ``wireprotoframing.py``. e.g. | ||||
``command-name``. | ||||
|
r37304 | ``stream-flags`` and ``flags`` are a ``|`` delimited list of flag | ||
components. Each component (and there can be just one) can be an integer | ||||
or a flag name for stream flags or frame flags, respectively. Values are | ||||
resolved to integers and then bitwise OR'd together. | ||||
|
r37306 | ``payload`` represents the raw frame payload. If it begins with | ||
``cbor:``, the following string is evaluated as Python code and the | ||||
resulting object is fed into a CBOR encoder. Otherwise it is interpreted | ||||
as a Python byte string literal. | ||||
|
r36545 | """ | ||
opts = pycompat.byteskwargs(opts) | ||||
|
r43347 | if opts[b'localssh'] and not repo: | ||
raise error.Abort(_(b'--localssh requires a repository')) | ||||
if opts[b'peer'] and opts[b'peer'] not in ( | ||||
b'raw', | ||||
b'http2', | ||||
b'ssh1', | ||||
b'ssh2', | ||||
): | ||||
|
r43346 | raise error.Abort( | ||
|
r43347 | _(b'invalid value for --peer'), | ||
hint=_(b'valid values are "raw", "ssh1", and "ssh2"'), | ||||
|
r43346 | ) | ||
|
r36545 | |||
|
r43347 | if path and opts[b'localssh']: | ||
|
r43387 | raise error.Abort(_(b'cannot specify --localssh with an explicit path')) | ||
|
r37030 | |||
|
r36545 | if ui.interactive(): | ||
|
r43347 | ui.write(_(b'(waiting for commands on stdin)\n')) | ||
|
r36545 | |||
blocks = list(_parsewirelangblocks(ui.fin)) | ||||
proc = None | ||||
|
r37030 | stdin = None | ||
stdout = None | ||||
stderr = None | ||||
|
r37031 | opener = None | ||
|
r36545 | |||
|
r43347 | if opts[b'localssh']: | ||
|
r36545 | # We start the SSH server in its own process so there is process | ||
# separation. This prevents a whole class of potential bugs around | ||||
# shared state from interfering with server operation. | ||||
|
r37138 | args = procutil.hgcmd() + [ | ||
|
r43347 | b'-R', | ||
|
r43346 | repo.root, | ||
|
r43347 | b'debugserve', | ||
b'--sshstdio', | ||||
|
r36545 | ] | ||
|
r43346 | proc = subprocess.Popen( | ||
pycompat.rapply(procutil.tonativestr, args), | ||||
stdin=subprocess.PIPE, | ||||
stdout=subprocess.PIPE, | ||||
stderr=subprocess.PIPE, | ||||
bufsize=0, | ||||
) | ||||
|
r36545 | |||
stdin = proc.stdin | ||||
stdout = proc.stdout | ||||
stderr = proc.stderr | ||||
# We turn the pipes into observers so we can log I/O. | ||||
|
r43347 | if ui.verbose or opts[b'peer'] == b'raw': | ||
|
r43346 | stdin = util.makeloggingfileobject( | ||
ui, proc.stdin, b'i', logdata=True | ||||
) | ||||
stdout = util.makeloggingfileobject( | ||||
ui, proc.stdout, b'o', logdata=True | ||||
) | ||||
stderr = util.makeloggingfileobject( | ||||
ui, proc.stderr, b'e', logdata=True | ||||
) | ||||
|
r36545 | |||
# --localssh also implies the peer connection settings. | ||||
|
r43347 | url = b'ssh://localserver' | ||
autoreadstderr = not opts[b'noreadstderr'] | ||||
if opts[b'peer'] == b'ssh1': | ||||
ui.write(_(b'creating ssh peer for wire protocol version 1\n')) | ||||
|
r43346 | peer = sshpeer.sshv1peer( | ||
ui, | ||||
url, | ||||
proc, | ||||
stdin, | ||||
stdout, | ||||
stderr, | ||||
None, | ||||
autoreadstderr=autoreadstderr, | ||||
) | ||||
|
r43347 | elif opts[b'peer'] == b'ssh2': | ||
ui.write(_(b'creating ssh peer for wire protocol version 2\n')) | ||||
|
r43346 | peer = sshpeer.sshv2peer( | ||
ui, | ||||
url, | ||||
proc, | ||||
stdin, | ||||
stdout, | ||||
stderr, | ||||
None, | ||||
autoreadstderr=autoreadstderr, | ||||
) | ||||
|
r43347 | elif opts[b'peer'] == b'raw': | ||
ui.write(_(b'using raw connection to peer\n')) | ||||
|
r36545 | peer = None | ||
else: | ||||
|
r43347 | ui.write(_(b'creating ssh peer from handshake results\n')) | ||
|
r43346 | peer = sshpeer.makepeer( | ||
ui, | ||||
url, | ||||
proc, | ||||
stdin, | ||||
stdout, | ||||
stderr, | ||||
autoreadstderr=autoreadstderr, | ||||
) | ||||
|
r36545 | |||
|
r37030 | elif path: | ||
# We bypass hg.peer() so we can proxy the sockets. | ||||
# TODO consider not doing this because we skip | ||||
# ``hg.wirepeersetupfuncs`` and potentially other useful functionality. | ||||
u = util.url(path) | ||||
|
r43347 | if u.scheme != b'http': | ||
raise error.Abort(_(b'only http:// paths are currently supported')) | ||||
|
r37030 | |||
url, authinfo = u.authinfo() | ||||
|
r37501 | openerargs = { | ||
|
r43906 | 'useragent': b'Mercurial debugwireproto', | ||
|
r37501 | } | ||
|
r37030 | |||
# Turn pipes/sockets into observers so we can log I/O. | ||||
if ui.verbose: | ||||
|
r43346 | openerargs.update( | ||
{ | ||||
|
r43906 | 'loggingfh': ui, | ||
'loggingname': b's', | ||||
|
r46554 | 'loggingopts': { | ||
'logdata': True, | ||||
'logdataapis': False, | ||||
}, | ||||
|
r43346 | } | ||
) | ||||
|
r37030 | |||
|
r37062 | if ui.debugflag: | ||
|
r43906 | openerargs['loggingopts']['logdataapis'] = True | ||
|
r37062 | |||
|
r37063 | # Don't send default headers when in raw mode. This allows us to | ||
# bypass most of the behavior of our URL handling code so we can | ||||
# have near complete control over what's sent on the wire. | ||||
|
r43347 | if opts[b'peer'] == b'raw': | ||
|
r43906 | openerargs['sendaccept'] = False | ||
|
r37063 | |||
|
r37030 | opener = urlmod.opener(ui, authinfo, **openerargs) | ||
|
r43347 | if opts[b'peer'] == b'http2': | ||
ui.write(_(b'creating http peer for wire protocol version 2\n')) | ||||
|
r37663 | # We go through makepeer() because we need an API descriptor for | ||
# the peer instance to be useful. | ||||
|
r43346 | with ui.configoverride( | ||
|
r43347 | {(b'experimental', b'httppeer.advertise-v2'): True} | ||
|
r43346 | ): | ||
|
r43347 | if opts[b'nologhandshake']: | ||
|
r37736 | ui.pushbuffer() | ||
|
r37663 | peer = httppeer.makepeer(ui, path, opener=opener) | ||
|
r43347 | if opts[b'nologhandshake']: | ||
|
r37736 | ui.popbuffer() | ||
|
r37663 | if not isinstance(peer, httppeer.httpv2peer): | ||
|
r43346 | raise error.Abort( | ||
_( | ||||
|
r43347 | b'could not instantiate HTTP peer for ' | ||
b'wire protocol version 2' | ||||
|
r43346 | ), | ||
hint=_( | ||||
|
r43347 | b'the server may not have the feature ' | ||
b'enabled or is not allowing this ' | ||||
b'client version' | ||||
|
r43346 | ), | ||
) | ||||
|
r37663 | |||
|
r43347 | elif opts[b'peer'] == b'raw': | ||
ui.write(_(b'using raw connection to peer\n')) | ||||
|
r37030 | peer = None | ||
|
r43347 | elif opts[b'peer']: | ||
|
r43346 | raise error.Abort( | ||
|
r43347 | _(b'--peer %s not supported with HTTP peers') % opts[b'peer'] | ||
|
r43346 | ) | ||
|
r37030 | else: | ||
|
r37571 | peer = httppeer.makepeer(ui, path, opener=opener) | ||
|
r37030 | |||
# We /could/ populate stdin/stdout with sock.makefile()... | ||||
|
r36545 | else: | ||
|
r43347 | raise error.Abort(_(b'unsupported connection configuration')) | ||
|
r36545 | |||
|
r36548 | batchedcommands = None | ||
|
r36545 | # Now perform actions based on the parsed wire language instructions. | ||
for action, lines in blocks: | ||||
|
r43347 | if action in (b'raw', b'raw+'): | ||
|
r37030 | if not stdin: | ||
|
r43347 | raise error.Abort(_(b'cannot call raw/raw+ on this peer')) | ||
|
r37030 | |||
|
r36545 | # Concatenate the data together. | ||
|
r43347 | data = b''.join(l.lstrip() for l in lines) | ||
|
r37102 | data = stringutil.unescapestr(data) | ||
|
r36545 | stdin.write(data) | ||
|
r43347 | if action == b'raw+': | ||
|
r36545 | stdin.flush() | ||
|
r43347 | elif action == b'flush': | ||
|
r37030 | if not stdin: | ||
|
r43347 | raise error.Abort(_(b'cannot call flush on this peer')) | ||
|
r36545 | stdin.flush() | ||
|
r43347 | elif action.startswith(b'command'): | ||
|
r36547 | if not peer: | ||
|
r43346 | raise error.Abort( | ||
_( | ||||
|
r43347 | b'cannot send commands unless peer instance ' | ||
b'is available' | ||||
|
r43346 | ) | ||
) | ||||
|
r36547 | |||
|
r43347 | command = action.split(b' ', 1)[1] | ||
|
r36547 | |||
args = {} | ||||
for line in lines: | ||||
# We need to allow empty values. | ||||
|
r43347 | fields = line.lstrip().split(b' ', 1) | ||
|
r36547 | if len(fields) == 1: | ||
key = fields[0] | ||||
|
r43347 | value = b'' | ||
|
r36547 | else: | ||
key, value = fields | ||||
|
r43347 | if value.startswith(b'eval:'): | ||
|
r37501 | value = stringutil.evalpythonliteral(value[5:]) | ||
else: | ||||
value = stringutil.unescapestr(value) | ||||
args[key] = value | ||||
|
r36547 | |||
|
r36548 | if batchedcommands is not None: | ||
batchedcommands.append((command, args)) | ||||
continue | ||||
|
r43347 | ui.status(_(b'sending %s command\n') % command) | ||
if b'PUSHFILE' in args: | ||||
|
r43906 | with open(args[b'PUSHFILE'], 'rb') as fh: | ||
|
r43347 | del args[b'PUSHFILE'] | ||
|
r43346 | res, output = peer._callpush( | ||
command, fh, **pycompat.strkwargs(args) | ||||
) | ||||
|
r43347 | ui.status(_(b'result: %s\n') % stringutil.escapestr(res)) | ||
|
r43346 | ui.status( | ||
|
r43347 | _(b'remote output: %s\n') % stringutil.escapestr(output) | ||
|
r43346 | ) | ||
|
r36551 | else: | ||
|
r37670 | with peer.commandexecutor() as e: | ||
res = e.callcommand(command, args).result() | ||||
|
r37738 | if isinstance(res, wireprotov2peer.commandresponse): | ||
|
r39597 | val = res.objects() | ||
|
r43346 | ui.status( | ||
|
r43347 | _(b'response: %s\n') | ||
|
r43346 | % stringutil.pprint(val, bprefix=True, indent=2) | ||
) | ||||
|
r37738 | else: | ||
|
r43346 | ui.status( | ||
|
r43347 | _(b'response: %s\n') | ||
|
r43346 | % stringutil.pprint(res, bprefix=True, indent=2) | ||
) | ||||
|
r36547 | |||
|
r43347 | elif action == b'batchbegin': | ||
|
r36548 | if batchedcommands is not None: | ||
|
r43347 | raise error.Abort(_(b'nested batchbegin not allowed')) | ||
|
r36548 | |||
batchedcommands = [] | ||||
|
r43347 | elif action == b'batchsubmit': | ||
|
r36548 | # There is a batching API we could go through. But it would be | ||
# difficult to normalize requests into function calls. It is easier | ||||
# to bypass this layer and normalize to commands + args. | ||||
|
r43346 | ui.status( | ||
|
r43347 | _(b'sending batch with %d sub-commands\n') | ||
% len(batchedcommands) | ||||
|
r43346 | ) | ||
|
r44103 | assert peer is not None | ||
|
r36548 | for i, chunk in enumerate(peer._submitbatch(batchedcommands)): | ||
|
r43346 | ui.status( | ||
|
r43347 | _(b'response #%d: %s\n') % (i, stringutil.escapestr(chunk)) | ||
|
r43346 | ) | ||
|
r36548 | |||
batchedcommands = None | ||||
|
r37031 | |||
|
r43347 | elif action.startswith(b'httprequest '): | ||
|
r37031 | if not opener: | ||
|
r43346 | raise error.Abort( | ||
|
r43387 | _(b'cannot use httprequest without an HTTP peer') | ||
|
r43346 | ) | ||
|
r37031 | |||
|
r43347 | request = action.split(b' ', 2) | ||
|
r37031 | if len(request) != 3: | ||
|
r43346 | raise error.Abort( | ||
_( | ||||
|
r43347 | b'invalid httprequest: expected format is ' | ||
b'"httprequest <method> <path>' | ||||
|
r43346 | ) | ||
) | ||||
|
r37031 | |||
method, httppath = request[1:] | ||||
headers = {} | ||||
body = None | ||||
|
r37069 | frames = [] | ||
|
r37031 | for line in lines: | ||
line = line.lstrip() | ||||
m = re.match(b'^([a-zA-Z0-9_-]+): (.*)$', line) | ||||
if m: | ||||
|
r39991 | # Headers need to use native strings. | ||
key = pycompat.strurl(m.group(1)) | ||||
value = pycompat.strurl(m.group(2)) | ||||
headers[key] = value | ||||
|
r37031 | continue | ||
if line.startswith(b'BODYFILE '): | ||||
|
r43347 | with open(line.split(b' ', 1), b'rb') as fh: | ||
|
r37031 | body = fh.read() | ||
|
r37069 | elif line.startswith(b'frame '): | ||
frame = wireprotoframing.makeframefromhumanstring( | ||||
|
r43346 | line[len(b'frame ') :] | ||
) | ||||
|
r37069 | |||
frames.append(frame) | ||||
|
r37031 | else: | ||
|
r43346 | raise error.Abort( | ||
|
r43347 | _(b'unknown argument to httprequest: %s') % line | ||
|
r43346 | ) | ||
|
r37031 | |||
url = path + httppath | ||||
|
r37069 | |||
if frames: | ||||
body = b''.join(bytes(f) for f in frames) | ||||
|
r37031 | req = urlmod.urlreq.request(pycompat.strurl(url), body, headers) | ||
|
r37065 | # urllib.Request insists on using has_data() as a proxy for | ||
# determining the request method. Override that to use our | ||||
# explicitly requested method. | ||||
|
r39099 | req.get_method = lambda: pycompat.sysstr(method) | ||
|
r37065 | |||
|
r37031 | try: | ||
|
r37575 | res = opener.open(req) | ||
body = res.read() | ||||
|
r37031 | except util.urlerr.urlerror as e: | ||
|
r39100 | # read() method must be called, but only exists in Python 2 | ||
getattr(e, 'read', lambda: None)() | ||||
|
r37575 | continue | ||
|
r43906 | ct = res.headers.get('Content-Type') | ||
if ct == 'application/mercurial-cbor': | ||||
|
r43346 | ui.write( | ||
|
r43347 | _(b'cbor> %s\n') | ||
|
r43346 | % stringutil.pprint( | ||
cborutil.decodeall(body), bprefix=True, indent=2 | ||||
) | ||||
) | ||||
|
r37031 | |||
|
r43347 | elif action == b'close': | ||
|
r44103 | assert peer is not None | ||
|
r36545 | peer.close() | ||
|
r43347 | elif action == b'readavailable': | ||
|
r37030 | if not stdout or not stderr: | ||
|
r43347 | raise error.Abort( | ||
_(b'readavailable not available on this peer') | ||||
) | ||||
|
r37030 | |||
|
r36861 | stdin.close() | ||
stdout.read() | ||||
stderr.read() | ||||
|
r37030 | |||
|
r43347 | elif action == b'readline': | ||
|
r37030 | if not stdout: | ||
|
r43347 | raise error.Abort(_(b'readline not available on this peer')) | ||
|
r36545 | stdout.readline() | ||
|
r43347 | elif action == b'ereadline': | ||
|
r37030 | if not stderr: | ||
|
r43347 | raise error.Abort(_(b'ereadline not available on this peer')) | ||
|
r37025 | stderr.readline() | ||
|
r43347 | elif action.startswith(b'read '): | ||
count = int(action.split(b' ', 1)[1]) | ||||
|
r37030 | if not stdout: | ||
|
r43347 | raise error.Abort(_(b'read not available on this peer')) | ||
|
r37025 | stdout.read(count) | ||
|
r43347 | elif action.startswith(b'eread '): | ||
count = int(action.split(b' ', 1)[1]) | ||||
|
r37030 | if not stderr: | ||
|
r43347 | raise error.Abort(_(b'eread not available on this peer')) | ||
|
r37025 | stderr.read(count) | ||
|
r36545 | else: | ||
|
r43347 | raise error.Abort(_(b'unknown action: %s') % action) | ||
|
r36545 | |||
|
r36548 | if batchedcommands is not None: | ||
|
r43347 | raise error.Abort(_(b'unclosed "batchbegin" request')) | ||
|
r36548 | |||
|
r36545 | if peer: | ||
peer.close() | ||||
if proc: | ||||
proc.kill() | ||||