##// END OF EJS Templates
py3: use email.generator.BytesGenerator in patch.split()...
py3: use email.generator.BytesGenerator in patch.split() This fixes test-import.t on python3. We add Generator alias in mail module to handle python2/python3 compatibility.

File last commit:

r43406:ba5b062a default
r43426:0e6a7ce8 default
Show More
debugcommands.py
4265 lines | 135.0 KiB | text/x-python | PythonLexer
Gregory Szorc
debugcommands: introduce standalone module for debug commands...
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
Yuya Nishihara
debuginstall: use codecs.lookup() to detect invalid encoding...
r34131 import codecs
Augie Fackler
debugcommands: stabilize output of debugbundle by having a custom repr...
r34027 import collections
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 import difflib
Pierre-Yves David
debugcommands: move 'debuglocks' in the new module
r30938 import errno
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518 import operator
Gregory Szorc
debugcommands: move 'debugfsinfo' in the new module
r30525 import os
Gregory Szorc
debugcommands: move 'debugdiscovery' in the module...
r30517 import random
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031 import re
Pierre-Yves David
debugcommands: move 'debuglocks' in the new module
r30938 import socket
Matt Harbison
debug: add a method to check the state of, and built an SSL cert chain...
r33493 import ssl
Augie Fackler
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime...
r36799 import stat
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 import string
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 import subprocess
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 import sys
Pierre-Yves David
debugcommands: move 'debuglocks' in the new module
r30938 import time
Gregory Szorc
debugcommands: introduce standalone module for debug commands...
r30401
from .i18n import _
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 from .node import (
Gregory Szorc
debugcommands: move 'debuggetbundle' in the new module
r30526 bin,
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 hex,
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 nullhex,
Gregory Szorc
debugcommands: move 'debugindex' and 'debugindexdot' in the new module
r30528 nullid,
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 nullrev,
Gregory Szorc
debugcommands: move 'debugdiscovery' in the module...
r30517 short,
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 )
Gregory Szorc
py3: manually import getattr where it is needed...
r43359 from .pycompat import (
getattr,
open,
)
Gregory Szorc
debugcommands: introduce standalone module for debug commands...
r30401 from . import (
Gregory Szorc
debugcommands: move 'debugbundle' in the new module
r30501 bundle2,
changegroup,
Gregory Szorc
debugcommands: introduce standalone module for debug commands...
r30401 cmdutil,
Pierre-Yves David
color: move 'debugcolor' into the 'debugcommands' modules...
r31120 color,
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 context,
Martin von Zweigbergk
debugcommands: add a debugpathcopies command...
r41656 copies,
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 dagparser,
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 encoding,
Gregory Szorc
debugcommands: introduce standalone module for debug commands...
r30401 error,
Gregory Szorc
debugcommands: move 'debugbundle' in the new module
r30501 exchange,
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518 extensions,
FUJIWARA Katsunori
debugcommands: add debugpickmergetool to examine which merge tool is chosen...
r32256 filemerge,
Yuya Nishihara
fileset: extract language processing part to new module (API)...
r38841 filesetlang,
Pierre-Yves David
debugcommands: move 'debugtemplate' in the new module
r30957 formatter,
Gregory Szorc
debugcommands: move 'debugbundle' in the new module
r30501 hg,
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030 httppeer,
Gregory Szorc
debugcommands: move 'debugdiscovery' in the module...
r30517 localrepo,
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 lock as lockmod,
Yuya Nishihara
cmdutil: drop aliases for logcmdutil functions (API)...
r35906 logcmdutil,
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 merge as mergemod,
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 obsolete,
obsutil: move 'successorssets' to the new modules...
r33143 obsutil,
Gregory Szorc
debugcommands: issue warning when repo has secret changesets (issue5589)...
r32745 phases,
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 policy,
Pierre-Yves David
debugcommands: move 'debugpvec' in the new module
r30947 pvec,
Pulkit Goyal
py3: use pycompat.getcwd() instead of os.getcwd()...
r30519 pycompat,
Yuya Nishihara
registrar: move cmdutil.command to registrar module (API)...
r32337 registrar,
Gregory Szorc
repair: implement requirements checking for upgrades...
r30775 repair,
Gregory Szorc
debugcommands: introduce standalone module for debug commands...
r30401 revlog,
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 revset,
Yuya Nishihara
revset: split language services to revsetlang module (API)...
r31024 revsetlang,
Gregory Szorc
debugcommands: introduce standalone module for debug commands...
r30401 scmutil,
Gregory Szorc
debugcommands: move 'debugdiscovery' in the module...
r30517 setdiscovery,
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 simplemerge,
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 sshpeer,
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 sslutil,
Gregory Szorc
debugcommands: move debug{create,apply}streambundleclone to the new module
r30502 streamclone,
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 templater,
Gregory Szorc
debugcommands: move 'debugdiscovery' in the module...
r30517 treediscovery,
Pierre-Yves David
upgrade: extract code in its own module...
r31864 upgrade,
Boris Feld
debug: add a 'debugdownload' command...
r35578 url as urlmod,
Gregory Szorc
debugcommands: move 'debugdate' in the new module
r30516 util,
Pierre-Yves David
vfs: use 'vfs' module directly in 'mercurial.debugcommand'...
r31239 vfs as vfsmod,
Gregory Szorc
wireproto: define and implement protocol for issuing requests...
r37069 wireprotoframing,
Gregory Szorc
debugcommands: add debugserve command...
r36544 wireprotoserver,
Gregory Szorc
wireprotov2: establish a type for representing command response...
r37738 wireprotov2peer,
Gregory Szorc
debugcommands: introduce standalone module for debug commands...
r30401 )
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 from .utils import (
Gregory Szorc
debugcommands: use our CBOR decoder...
r39480 cborutil,
util: extract compression code in `mercurial.utils.compression`...
r42208 compression,
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 dateutil,
Yuya Nishihara
procutil: bulk-replace function calls to point to new module
r37138 procutil,
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 stringutil,
)
Gregory Szorc
debugcommands: introduce standalone module for debug commands...
r30401
Augie Fackler
formatting: blacken the codebase...
r43346 from .revlogutils import deltas as deltautil
Boris Feld
revlog: split functionality related to deltas computation in a new module...
r39366
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 release = lockmod.release
Yuya Nishihara
debugcommands: use temporary dict for its command table...
r32377 command = registrar.command()
Gregory Szorc
debugcommands: introduce standalone module for debug commands...
r30401
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @command(b'debugancestor', [], _(b'[INDEX] REV1 REV2'), optionalrepo=True)
Gregory Szorc
debugcommands: introduce standalone module for debug commands...
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
Matt Harbison
py3: rename pycompat.getcwd() to encoding.getcwd() (API)...
r39843 r = revlog.revlog(vfsmod.vfs(encoding.getcwd(), audit=False), index)
Gregory Szorc
debugcommands: introduce standalone module for debug commands...
r30401 lookup = r.lookup
elif len(args) == 2:
if not repo:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b'there is no Mercurial repository here (.hg not found)')
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: introduce standalone module for debug commands...
r30401 rev1, rev2 = args
r = repo.changelog
lookup = repo.lookup
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'either two or three arguments required'))
Gregory Szorc
debugcommands: introduce standalone module for debug commands...
r30401 a = r.ancestor(lookup(rev1), lookup(rev2))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'%d:%s\n' % (r.rev(a), hex(a)))
@command(b'debugapplystreamclonebundle', [], b'FILE')
Gregory Szorc
debugcommands: sort command order...
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)
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugbuilddag',
Augie Fackler
formatting: blacken the codebase...
r43346 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (
b'm',
b'mergeable-file',
None,
_(b'add single file mergeable changes'),
),
Augie Fackler
formatting: blacken the codebase...
r43346 (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'o',
b'overwritten-file',
Augie Fackler
formatting: blacken the codebase...
r43346 None,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'add single file all revs overwrite'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'n', b'new-file', None, _(b'add new file at each rev')),
Augie Fackler
formatting: blacken the codebase...
r43346 ],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'[OPTION]... [TEXT]'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
def debugbuilddag(
ui,
repo,
text=None,
mergeable_file=False,
overwritten_file=False,
new_file=False,
):
Gregory Szorc
debugcommands: move debugbuilddag...
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:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.status(_(b"reading DAG from stdin\n"))
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 text = ui.fin.read()
cl = repo.changelog
if len(cl) > 0:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'repository is not empty'))
Gregory Szorc
debugcommands: move debugbuilddag...
r30402
# determine number of revs in DAG
total = 0
for type, data in dagparser.parsedag(text):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if type == b'n':
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 total += 1
if mergeable_file:
linesperrev = 2
# make a file with k lines per rev
Augie Fackler
formatting: blacken the codebase...
r43346 initialmergedlines = [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'%d' % i for i in pycompat.xrange(0, total * linesperrev)
Augie Fackler
formatting: blacken the codebase...
r43346 ]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 initialmergedlines.append(b"")
Gregory Szorc
debugcommands: move debugbuilddag...
r30402
tags = []
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 progress = ui.makeprogress(
_(b'building'), unit=_(b'revisions'), total=total
)
with progress, repo.wlock(), repo.lock(), repo.transaction(b"builddag"):
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 at = -1
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 atbranch = b'default'
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 nodeids = []
id = 0
Martin von Zweigbergk
debugbuilddag: use progress helper...
r38394 progress.update(id)
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 for type, data in dagparser.parsedag(text):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if type == b'n':
ui.note((b'node %s\n' % pycompat.bytestr(data)))
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 id, ps = data
files = []
Martin von Zweigbergk
debugbuilddag: create filectx instance in 'filectxfn' callback...
r35400 filecontent = {}
Gregory Szorc
debugcommands: move debugbuilddag...
r30402
p2 = None
if mergeable_file:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fn = b"mf"
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 p1 = repo[ps[0]]
if len(ps) > 1:
p2 = repo[ps[1]]
pa = p1.ancestor(p2)
Augie Fackler
formatting: blacken the codebase...
r43346 base, local, other = [
x[fn].data() for x in (pa, p1, p2)
]
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 m3 = simplemerge.Merge3Text(base, local, other)
ml = [l.strip() for l in m3.merge_lines()]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ml.append(b"")
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 elif at > 0:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ml = p1[fn].data().split(b"\n")
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 else:
ml = initialmergedlines
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ml[id * linesperrev] += b" r%i" % id
mergedtext = b"\n".join(ml)
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 files.append(fn)
Martin von Zweigbergk
debugbuilddag: create filectx instance in 'filectxfn' callback...
r35400 filecontent[fn] = mergedtext
Gregory Szorc
debugcommands: move debugbuilddag...
r30402
if overwritten_file:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fn = b"of"
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 files.append(fn)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 filecontent[fn] = b"r%i\n" % id
Gregory Szorc
debugcommands: move debugbuilddag...
r30402
if new_file:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fn = b"nf%i" % id
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 files.append(fn)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 filecontent[fn] = b"r%i\n" % id
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 if len(ps) > 1:
if not p2:
p2 = repo[ps[1]]
for fn in p2:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if fn.startswith(b"nf"):
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 files.append(fn)
Martin von Zweigbergk
debugbuilddag: create filectx instance in 'filectxfn' callback...
r35400 filecontent[fn] = p2[fn].data()
Gregory Szorc
debugcommands: move debugbuilddag...
r30402
def fctxfn(repo, cx, path):
Martin von Zweigbergk
debugbuilddag: create filectx instance in 'filectxfn' callback...
r35400 if path in filecontent:
Augie Fackler
formatting: blacken the codebase...
r43346 return context.memfilectx(
repo, cx, path, filecontent[path]
)
Martin von Zweigbergk
debugbuilddag: create filectx instance in 'filectxfn' callback...
r35400 return None
Gregory Szorc
debugcommands: move debugbuilddag...
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]
Augie Fackler
formatting: blacken the codebase...
r43346 cx = context.memctx(
repo,
pars,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"r%i" % id,
Augie Fackler
formatting: blacken the codebase...
r43346 files,
fctxfn,
date=(id, 0),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 user=b"debugbuilddag",
extra={b'branch': atbranch},
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 nodeid = repo.commitctx(cx)
nodeids.append(nodeid)
at = id
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif type == b'l':
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 id, name = data
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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))
Gregory Szorc
debugcommands: move debugbuilddag...
r30402 atbranch = data
Martin von Zweigbergk
debugbuilddag: use progress helper...
r38394 progress.update(id)
Gregory Szorc
debugcommands: move debugbuilddag...
r30402
if tags:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo.vfs.write(b"localtags", b"".join(tags))
Gregory Szorc
debugcommands: move 'debugbundle' in the new module
r30501
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
debugcommands: move 'debugbundle' in the new module
r30501 def _debugchangegroup(ui, gen, all=None, indent=0, **opts):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 indent_string = b' ' * indent
Gregory Szorc
debugcommands: move 'debugbundle' in the new module
r30501 if all:
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"%sformat: id, p1, p2, cset, delta base, len(delta)\n"
Augie Fackler
formatting: blacken the codebase...
r43346 % indent_string
)
Gregory Szorc
debugcommands: move 'debugbundle' in the new module
r30501
def showchunks(named):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b"\n%s%s\n" % (indent_string, named))
Durham Goode
debug: update debugbundle to use new deltaiter api...
r34293 for deltadata in gen.deltaiter():
node, p1, p2, cs, deltabase, delta, flags = deltadata
Augie Fackler
formatting: blacken the codebase...
r43346 ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"%s%s %s %s %s %s %d\n"
Augie Fackler
formatting: blacken the codebase...
r43346 % (
indent_string,
hex(node),
hex(p1),
hex(p2),
hex(cs),
hex(deltabase),
len(delta),
)
)
Gregory Szorc
debugcommands: move 'debugbundle' in the new module
r30501
chunkdata = gen.changelogheader()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 showchunks(b"changelog")
Gregory Szorc
debugcommands: move 'debugbundle' in the new module
r30501 chunkdata = gen.manifestheader()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 showchunks(b"manifest")
Gregory Szorc
debugcommands: move 'debugbundle' in the new module
r30501 for chunkdata in iter(gen.filelogheader, {}):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fname = chunkdata[b'filename']
Gregory Szorc
debugcommands: move 'debugbundle' in the new module
r30501 showchunks(fname)
else:
if isinstance(gen, bundle2.unbundle20):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'use debugbundle2 for this file'))
Gregory Szorc
debugcommands: move 'debugbundle' in the new module
r30501 chunkdata = gen.changelogheader()
Durham Goode
debug: update debugbundle to use new deltaiter api...
r34293 for deltadata in gen.deltaiter():
node, p1, p2, cs, deltabase, delta, flags = deltadata
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b"%s%s\n" % (indent_string, hex(node)))
Gregory Szorc
debugcommands: move 'debugbundle' in the new module
r30501
Augie Fackler
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
debugcommands: pass part, not read data, into _debugobsmarker()...
r33029 def _debugobsmarkers(ui, part, indent=0, **opts):
debugbundle: display the content of obsmarkers parts...
r32517 """display version and markers contained in 'data'"""
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Martin von Zweigbergk
debugcommands: pass part, not read data, into _debugobsmarker()...
r33029 data = part.read()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 indent_string = b' ' * indent
debugbundle: display the content of obsmarkers parts...
r32517 try:
version, markers = obsolete._readmarkers(data)
except error.UnknownVersion as exc:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 msg = b"%sunsupported version: %s (%d bytes)\n"
debugbundle: display the content of obsmarkers parts...
r32517 msg %= indent_string, exc.version, len(data)
ui.write(msg)
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 msg = b"%sversion: %d (%d bytes)\n"
debugbundle: display the content of obsmarkers parts...
r32517 msg %= indent_string, version, len(data)
ui.write(msg)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm = ui.formatter(b'debugobsolete', opts)
debugbundle: display the content of obsmarkers parts...
r32517 for rawmarker in sorted(markers):
obsutil: move the 'marker' class to the new modules...
r33149 m = obsutil.marker(None, rawmarker)
debugbundle: display the content of obsmarkers parts...
r32517 fm.startitem()
fm.plain(indent_string)
cmdutil.showmarker(fm, m)
fm.end()
Augie Fackler
formatting: blacken the codebase...
r43346
Martin von Zweigbergk
bundle: add config option to include phases...
r33031 def _debugphaseheads(ui, data, indent=0):
"""display version and markers contained in 'data'"""
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 indent_string = b' ' * indent
Boris Feld
phases: move the binary decoding function in the phases module...
r34321 headsbyphase = phases.binarydecode(data)
Martin von Zweigbergk
bundle: add config option to include phases...
r33031 for phase in phases.allphases:
for head in headsbyphase[phase]:
ui.write(indent_string)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'%s %s\n' % (hex(head), phases.phasenames[phase]))
Martin von Zweigbergk
bundle: add config option to include phases...
r33031
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
debugcommands: stabilize output of debugbundle by having a custom repr...
r34027 def _quasirepr(thing):
if isinstance(thing, (dict, util.sortdict, collections.OrderedDict)):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'{%s}' % (
Augie Fackler
formatting: blacken the codebase...
r43346 b', '.join(b'%s: %s' % (k, thing[k]) for k in sorted(thing))
)
Augie Fackler
debugcommands: stabilize output of debugbundle by having a custom repr...
r34027 return pycompat.bytestr(repr(thing))
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
debugcommands: move 'debugbundle' in the new module
r30501 def _debugbundle2(ui, gen, all=None, **opts):
"""lists the contents of a bundle2"""
if not isinstance(gen, bundle2.unbundle20):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'not a bundle2 file'))
ui.write((b'Stream params: %s\n' % _quasirepr(gen.params)))
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 parttypes = opts.get(r'part_type', [])
Gregory Szorc
debugcommands: move 'debugbundle' in the new module
r30501 for part in gen.iterparts():
Danek Duvall
debugbundle: add --part-type flag to emit only named part types...
r32694 if parttypes and part.type not in parttypes:
continue
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 msg = b'%s -- %s (mandatory: %r)\n'
Boris Feld
debugbundle: also display if a part is mandatory or advisory...
r37919 ui.write((msg % (part.type, _quasirepr(part.params), part.mandatory)))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if part.type == b'changegroup':
version = part.params.get(b'version', b'01')
cg = changegroup.getunbundler(version, part, b'UN')
Boris Feld
debugbundle: do not display detailed part data in --quiet mode...
r36969 if not ui.quiet:
_debugchangegroup(ui, cg, all=all, indent=4, **opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if part.type == b'obsmarkers':
Boris Feld
debugbundle: do not display detailed part data in --quiet mode...
r36969 if not ui.quiet:
_debugobsmarkers(ui, part, indent=4, **opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if part.type == b'phase-heads':
Boris Feld
debugbundle: do not display detailed part data in --quiet mode...
r36969 if not ui.quiet:
_debugphaseheads(ui, part, indent=4)
Gregory Szorc
debugcommands: move debug{create,apply}streambundleclone to the new module
r30502
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugbundle',
Augie Fackler
formatting: blacken the codebase...
r43346 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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')),
Augie Fackler
formatting: blacken the codebase...
r43346 ],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'FILE'),
Augie Fackler
formatting: blacken the codebase...
r43346 norepo=True,
)
Gregory Szorc
debugcommands: sort command order...
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)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'%s\n' % spec)
Gregory Szorc
debugcommands: sort command order...
r30541 return
Gregory Szorc
debugcommands: move debug{create,apply}streambundleclone to the new module
r30502
Gregory Szorc
debugcommands: sort command order...
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)
Gregory Szorc
debugcommands: move 'debugcheckstate' in the new module
r30503
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @command(b'debugcapabilities', [], _(b'PATH'), norepo=True)
Boris Feld
debug: add a debugcapabilities commands...
r34960 def debugcapabilities(ui, path, **opts):
"""lists the capabilities of a remote peer"""
Pulkit Goyal
py3: handle keyword arguments correctly in debugcommands.py...
r35402 opts = pycompat.byteskwargs(opts)
Boris Feld
debug: add a debugcapabilities commands...
r34960 peer = hg.peer(ui, opts, path)
caps = peer.capabilities()
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'Main capabilities:\n')
Boris Feld
debug: add a debugcapabilities commands...
r34960 for c in sorted(caps):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b' %s\n' % c)
Boris Feld
debug: print parsed bundle2 capabilities with debugcapabilities...
r34961 b2caps = bundle2.bundle2caps(peer)
if b2caps:
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'Bundle2 capabilities:\n')
Gregory Szorc
py3: finish porting iteritems() to pycompat and remove source transformer...
r43376 for key, values in sorted(pycompat.iteritems(b2caps)):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b' %s\n' % key)
Boris Feld
debug: print parsed bundle2 capabilities with debugcapabilities...
r34961 for v in values:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b' %s\n' % v)
@command(b'debugcheckstate', [], b'')
Gregory Szorc
debugcommands: move 'debugcheckstate' in the new module
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]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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))
Gregory Szorc
debugcommands: move 'debugcheckstate' in the new module
r30503 errors += 1
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if state in b"a" and f in m1:
ui.warn(_(b"%s in state %s, but also in manifest1\n") % (f, state))
Gregory Szorc
debugcommands: move 'debugcheckstate' in the new module
r30503 errors += 1
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if state in b"m" and f not in m1 and f not in m2:
Augie Fackler
formatting: blacken the codebase...
r43346 ui.warn(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"%s in state %s, but not in either manifest\n") % (f, state)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: move 'debugcheckstate' in the new module
r30503 errors += 1
for f in m1:
state = repo.dirstate[f]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if state not in b"nrm":
ui.warn(_(b"%s in manifest1, but listed as state %s") % (f, state))
Gregory Szorc
debugcommands: move 'debugcheckstate' in the new module
r30503 errors += 1
if errors:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 error = _(b".hg/dirstate inconsistent with current parent's manifest")
Gregory Szorc
debugcommands: move 'debugcheckstate' in the new module
r30503 raise error.Abort(error)
Gregory Szorc
debugcommands: move 'debugcommands' in the new module...
r30504
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugcolor',
[(b'', b'style', None, _(b'show all configured styles'))],
b'hg debugcolor',
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
color: move 'debugcolor' into the 'debugcommands' modules...
r31120 def debugcolor(ui, repo, **opts):
"""show available color, effects or style"""
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'color mode: %s\n' % stringutil.pprint(ui._colormode))
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 if opts.get(r'style'):
Pierre-Yves David
color: move 'debugcolor' into the 'debugcommands' modules...
r31120 return _debugdisplaystyle(ui)
else:
return _debugdisplaycolor(ui)
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
color: move 'debugcolor' into the 'debugcommands' modules...
r31120 def _debugdisplaycolor(ui):
Pierre-Yves David
color: cleanup 'debugcolor' logic...
r31121 ui = ui.copy()
ui._styles.clear()
Matt Harbison
color: stop mutating the default effects map...
r31689 for effect in color._activeeffects(ui).keys():
Pierre-Yves David
color: cleanup 'debugcolor' logic...
r31121 ui._styles[effect] = effect
if ui._terminfoparams:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 for k, v in ui.configitems(b'color'):
if k.startswith(b'color.'):
Pierre-Yves David
color: cleanup 'debugcolor' logic...
r31121 ui._styles[k] = k[6:]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif k.startswith(b'terminfo.'):
Pierre-Yves David
color: cleanup 'debugcolor' logic...
r31121 ui._styles[k] = k[9:]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(_(b'available colors:\n'))
Pierre-Yves David
color: cleanup 'debugcolor' logic...
r31121 # sort label with a '_' after the other to group '_background' entry.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 items = sorted(ui._styles.items(), key=lambda i: (b'_' in i[0], i[0], i[1]))
Pierre-Yves David
color: cleanup 'debugcolor' logic...
r31121 for colorname, label in items:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'%s\n' % colorname, label=label)
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
color: move 'debugcolor' into the 'debugcommands' modules...
r31120
def _debugdisplaystyle(ui):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(_(b'available style:\n'))
Yuya Nishihara
debugcolor: fix crash by empty styles (issue5856)
r37841 if not ui._styles:
return
Pierre-Yves David
color: move 'debugcolor' into the 'debugcommands' modules...
r31120 width = max(len(s) for s in ui._styles)
for label, effects in sorted(ui._styles.items()):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'%s' % label, label=label)
Pierre-Yves David
color: move 'debugcolor' into the 'debugcommands' modules...
r31120 if effects:
# 50
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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')
Gregory Szorc
debugcommands: sort command order...
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.
"""
Gregory Szorc
debugcommands: issue warning when repo has secret changesets (issue5589)...
r32745 # TODO we may want to turn this into an abort when this functionality
# is moved into `hg bundle`.
if phases.hassecret(repo):
Augie Fackler
formatting: blacken the codebase...
r43346 ui.warn(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'(warning: stream clone bundle will contain secret '
b'revisions)\n'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Gregory Szorc
debugcommands: issue warning when repo has secret changesets (issue5589)...
r32745
Gregory Szorc
debugcommands: sort command order...
r30541 requirements, gen = streamclone.generatebundlev1(repo)
changegroup.writechunks(ui, gen, fname)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(_(b'bundle requirements: %s\n') % b', '.join(sorted(requirements)))
Gregory Szorc
debugcommands: sort command order...
r30541
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugdag',
Augie Fackler
formatting: blacken the codebase...
r43346 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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')),
Augie Fackler
formatting: blacken the codebase...
r43346 ],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'[OPTION]... [FILE [REV]...]'),
Augie Fackler
formatting: blacken the codebase...
r43346 optionalrepo=True,
)
Gregory Szorc
debugcommands: move 'debugdag' into the new module
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.
"""
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 spaces = opts.get(r'spaces')
dots = opts.get(r'dots')
Gregory Szorc
debugcommands: move 'debugdag' into the new module
r30514 if file_:
Augie Fackler
formatting: blacken the codebase...
r43346 rlog = revlog.revlog(vfsmod.vfs(encoding.getcwd(), audit=False), file_)
Gregory Szorc
debugcommands: move 'debugdag' into the new module
r30514 revs = set((int(r) for r in revs))
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
debugcommands: move 'debugdag' into the new module
r30514 def events():
for r in rlog:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 yield b'n', (r, list(p for p in rlog.parentrevs(r) if p != -1))
Gregory Szorc
debugcommands: move 'debugdag' into the new module
r30514 if r in revs:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 yield b'l', (r, b"r%i" % r)
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
debugcommands: move 'debugdag' into the new module
r30514 elif repo:
cl = repo.changelog
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 tags = opts.get(r'tags')
branches = opts.get(r'branches')
Gregory Szorc
debugcommands: move 'debugdag' into the new module
r30514 if tags:
labels = {}
for l, n in repo.tags().items():
labels.setdefault(cl.rev(n), []).append(l)
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
debugcommands: move 'debugdag' into the new module
r30514 def events():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b = b"default"
Gregory Szorc
debugcommands: move 'debugdag' into the new module
r30514 for r in cl:
if branches:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 newb = cl.read(cl.node(r))[5][b'branch']
Gregory Szorc
debugcommands: move 'debugdag' into the new module
r30514 if newb != b:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 yield b'a', newb
Gregory Szorc
debugcommands: move 'debugdag' into the new module
r30514 b = newb
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 yield b'n', (r, list(p for p in cl.parentrevs(r) if p != -1))
Gregory Szorc
debugcommands: move 'debugdag' into the new module
r30514 if tags:
ls = labels.get(r)
if ls:
for l in ls:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 yield b'l', (r, l)
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
debugcommands: move 'debugdag' into the new module
r30514 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'need repo for changelog dag'))
Gregory Szorc
debugcommands: move 'debugdag' into the new module
r30514
Augie Fackler
formatting: blacken the codebase...
r43346 for line in dagparser.dagtextlines(
events(),
addspaces=spaces,
wraplabels=True,
wrapannotations=True,
wrapnonlinear=dots,
usedots=dots,
maxlinewidth=70,
):
Gregory Szorc
debugcommands: move 'debugdag' into the new module
r30514 ui.write(line)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b"\n")
@command(b'debugdata', cmdutil.debugrevlogopts, _(b'-c|-m|FILE REV'))
Gregory Szorc
debugcommands: move 'debugrevlogopts' into the new module...
r30515 def debugdata(ui, repo, file_, rev=None, **opts):
"""dump the contents of a data file revision"""
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts.get(b'changelog') or opts.get(b'manifest') or opts.get(b'dir'):
Gregory Szorc
debugcommands: move 'debugrevlogopts' into the new module...
r30515 if rev is not None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.CommandError(b'debugdata', _(b'invalid arguments'))
Gregory Szorc
debugcommands: move 'debugrevlogopts' into the new module...
r30515 file_, rev = None, file_
elif rev is None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.CommandError(b'debugdata', _(b'invalid arguments'))
r = cmdutil.openstorage(repo, b'debugdata', file_, opts)
Gregory Szorc
debugcommands: move 'debugrevlogopts' into the new module...
r30515 try:
rawdata: update callers in debugcommands...
r43041 ui.write(r.rawdata(r.lookup(rev)))
Gregory Szorc
debugcommands: move 'debugrevlogopts' into the new module...
r30515 except KeyError:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'invalid revision identifier %s') % rev)
Gregory Szorc
debugcommands: move 'debugdate' in the new module
r30516
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugdate',
[(b'e', b'extended', None, _(b'try extended date formats'))],
_(b'[-e] DATE [RANGE]'),
Augie Fackler
formatting: blacken the codebase...
r43346 norepo=True,
optionalrepo=True,
)
Gregory Szorc
debugcommands: move 'debugdate' in the new module
r30516 def debugdate(ui, date, range=None, **opts):
"""parse and display a date"""
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 if opts[r"extended"]:
Boris Feld
util: extract all date-related utils in utils/dateutil module...
r36625 d = dateutil.parsedate(date, util.extendeddateformats)
Gregory Szorc
debugcommands: move 'debugdate' in the new module
r30516 else:
Boris Feld
util: extract all date-related utils in utils/dateutil module...
r36625 d = dateutil.parsedate(date)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b"internal: %d %d\n" % d)
ui.writenoi18n(b"standard: %s\n" % dateutil.datestr(d))
Gregory Szorc
debugcommands: move 'debugdate' in the new module
r30516 if range:
Boris Feld
util: extract all date-related utils in utils/dateutil module...
r36625 m = dateutil.matchdate(range)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b"match: %s\n" % m(d[0]))
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugdeltachain',
Yuya Nishihara
commands: move templates of common command options to cmdutil (API)...
r32375 cmdutil.debugrevlogopts + cmdutil.formatteropts,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'-c|-m|FILE'),
Augie Fackler
formatting: blacken the codebase...
r43346 optionalrepo=True,
)
Gregory Szorc
debugcommands: sort command order...
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
Paul Morelle
debugdeltachain: output information about sparse read if enabled
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
Paul Morelle
debugdeltachain: display how many chunks would be read in sparse-read mode
r35696 :``srchunks``: in how many data hunks the whole revision would be read
Paul Morelle
debugdeltachain: output information about sparse read if enabled
r35050
The sparse read can be enabled with experimental.sparse-read = True
Gregory Szorc
debugcommands: sort command order...
r30541 """
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 r = cmdutil.openrevlog(repo, b'debugdeltachain', file_, opts)
Gregory Szorc
debugcommands: sort command order...
r30541 index = r.index
Paul Morelle
debugdeltachain: r.start and r.length can be retrieved outside the loop
r38127 start = r.start
length = r.length
Gregory Szorc
revlog: rename constants (API)...
r32316 generaldelta = r.version & revlog.FLAG_GENERALDELTA
Paul Morelle
debugdeltachain: output information about sparse read if enabled
r35050 withsparseread = getattr(r, '_withsparseread', False)
Gregory Szorc
debugcommands: sort command order...
r30541
def revinfo(rev):
e = index[rev]
compsize = e[1]
uncompsize = e[2]
chainsize = 0
if generaldelta:
if e[3] == e[5]:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 deltatype = b'p1'
Gregory Szorc
debugcommands: sort command order...
r30541 elif e[3] == e[6]:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 deltatype = b'p2'
Gregory Szorc
debugcommands: sort command order...
r30541 elif e[3] == rev - 1:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 deltatype = b'prev'
Gregory Szorc
debugcommands: sort command order...
r30541 elif e[3] == rev:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 deltatype = b'base'
Gregory Szorc
debugcommands: sort command order...
r30541 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 deltatype = b'other'
Gregory Szorc
debugcommands: sort command order...
r30541 else:
if e[3] == rev:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 deltatype = b'base'
Gregory Szorc
debugcommands: sort command order...
r30541 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 deltatype = b'prev'
Gregory Szorc
debugcommands: sort command order...
r30541
chain = r._deltachain(rev)[0]
for iterrev in chain:
e = index[iterrev]
chainsize += e[1]
return compsize, uncompsize, deltatype, chain, chainsize
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm = ui.formatter(b'debugdeltachain', opts)
Gregory Szorc
debugcommands: sort command order...
r30541
Augie Fackler
formatting: blacken the codebase...
r43346 fm.plain(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b' rev chain# chainlen prev delta '
b'size rawsize chainsize ratio lindist extradist '
b'extraratio'
Augie Fackler
formatting: blacken the codebase...
r43346 )
Paul Morelle
debugdeltachain: output information about sparse read if enabled
r35050 if withsparseread:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.plain(b' readsize largestblk rddensity srchunks')
fm.plain(b'\n')
Gregory Szorc
debugcommands: sort command order...
r30541
chainbases = {}
for rev in r:
comp, uncomp, deltatype, chain, chainsize = revinfo(rev)
chainbase = chain[0]
chainid = chainbases.setdefault(chainbase, len(chainbases) + 1)
Paul Morelle
debugdeltachain: output information about sparse read if enabled
r35050 basestart = start(chainbase)
revstart = start(rev)
Gregory Szorc
debugcommands: sort command order...
r30541 lineardist = revstart + comp - basestart
extradist = lineardist - chainsize
try:
prevrev = chain[-2]
except IndexError:
prevrev = -1
Paul Morelle
debugdeltachain: avoid division by zero when a chain is empty...
r38668 if uncomp != 0:
chainratio = float(chainsize) / float(uncomp)
else:
chainratio = chainsize
if chainsize != 0:
extraratio = float(extradist) / float(chainsize)
else:
extraratio = extradist
Gregory Szorc
debugcommands: sort command order...
r30541
fm.startitem()
Augie Fackler
formatting: blacken the codebase...
r43346 fm.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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',
Augie Fackler
formatting: blacken the codebase...
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,
)
Paul Morelle
debugdeltachain: output information about sparse read if enabled
r35050 if withsparseread:
readsize = 0
largestblock = 0
Paul Morelle
debugdeltachain: cleanup the double call to _slicechunk...
r35746 srchunks = 0
Boris Feld
revlog: split functionality related to deltas computation in a new module...
r39366 for revschunk in deltautil.slicechunk(r, chain):
Paul Morelle
debugdeltachain: cleanup the double call to _slicechunk...
r35746 srchunks += 1
Paul Morelle
debugdeltachain: output information about sparse read if enabled
r35050 blkend = start(revschunk[-1]) + length(revschunk[-1])
blksize = blkend - start(revschunk[0])
readsize += blksize
if largestblock < blksize:
largestblock = blksize
Boris Feld
debugdeltachain: protect against 0 readsize...
r38669 if readsize:
readdensity = float(chainsize) / float(readsize)
else:
readdensity = 1
Paul Morelle
debugdeltachain: output information about sparse read if enabled
r35050
Augie Fackler
formatting: blacken the codebase...
r43346 fm.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'readsize largestblock readdensity srchunks',
b' %10d %10d %9.5f %8d',
Augie Fackler
formatting: blacken the codebase...
r43346 readsize,
largestblock,
readdensity,
srchunks,
readsize=readsize,
largestblock=largestblock,
readdensity=readdensity,
srchunks=srchunks,
)
Paul Morelle
debugdeltachain: output information about sparse read if enabled
r35050
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.plain(b'\n')
Gregory Szorc
debugcommands: sort command order...
r30541
fm.end()
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugdirstate|debugstate',
Augie Fackler
formatting: blacken the codebase...
r43346 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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')),
Augie Fackler
formatting: blacken the codebase...
r43346 ],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'[OPTION]...'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugstate' in the new module
r30954 def debugstate(ui, repo, **opts):
"""show the contents of the current dirstate"""
Martin von Zweigbergk
debugdirstate: deprecate --nodates in favor of --no-dates...
r39796 nodates = not opts[r'dates']
if opts.get(r'nodates') is not None:
nodates = True
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 datesort = opts.get(r'datesort')
Pierre-Yves David
debugcommands: move 'debugstate' in the new module
r30954
if datesort:
Augie Fackler
formatting: blacken the codebase...
r43346 keyfunc = lambda x: (x[1][3], x[0]) # sort by mtime, then by filename
Pierre-Yves David
debugcommands: move 'debugstate' in the new module
r30954 else:
Augie Fackler
formatting: blacken the codebase...
r43346 keyfunc = None # sort by filename
Gregory Szorc
py3: finish porting iteritems() to pycompat and remove source transformer...
r43376 for file_, ent in sorted(pycompat.iteritems(repo.dirstate), key=keyfunc):
Pierre-Yves David
debugcommands: move 'debugstate' in the new module
r30954 if ent[3] == -1:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 timestr = b'unset '
Pierre-Yves David
debugcommands: move 'debugstate' in the new module
r30954 elif nodates:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 timestr = b'set '
Pierre-Yves David
debugcommands: move 'debugstate' in the new module
r30954 else:
Augie Fackler
formatting: blacken the codebase...
r43346 timestr = time.strftime(
r"%Y-%m-%d %H:%M:%S ", time.localtime(ent[3])
)
Pulkit Goyal
py3: use encoding.strtolocal() to convert string to bytes...
r35205 timestr = encoding.strtolocal(timestr)
Pierre-Yves David
debugcommands: move 'debugstate' in the new module
r30954 if ent[1] & 0o20000:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 mode = b'lnk'
Pierre-Yves David
debugcommands: move 'debugstate' in the new module
r30954 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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_))
Pierre-Yves David
debugcommands: move 'debugstate' in the new module
r30954 for f in repo.dirstate.copies():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(_(b"copy: %s -> %s\n") % (repo.dirstate.copied(f), f))
Pierre-Yves David
debugcommands: move 'debugstate' in the new module
r30954
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugdiscovery',
Augie Fackler
formatting: blacken the codebase...
r43346 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'', b'old', None, _(b'use old-style discovery')),
Augie Fackler
formatting: blacken the codebase...
r43346 (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'',
b'nonheads',
Augie Fackler
formatting: blacken the codebase...
r43346 None,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'use old-style discovery with non-heads included'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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'),
Augie Fackler
formatting: blacken the codebase...
r43346 ]
+ cmdutil.remoteopts,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'[--rev REV] [OTHER]'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 def debugdiscovery(ui, repo, remoteurl=b"default", **opts):
Gregory Szorc
debugcommands: move 'debugdiscovery' in the module...
r30517 """runs the changeset discovery protocol in isolation"""
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Martin von Zweigbergk
debugdiscovery: drop reference to invalid --branch option...
r35418 remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl))
Gregory Szorc
debugcommands: move 'debugdiscovery' in the module...
r30517 remote = hg.peer(repo, opts, remoteurl)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.status(_(b'comparing with %s\n') % util.hidepassword(remoteurl))
Gregory Szorc
debugcommands: move 'debugdiscovery' in the module...
r30517
# make sure tests are repeatable
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 random.seed(int(opts[b'seed']))
if opts.get(b'old'):
Augie Fackler
formatting: blacken the codebase...
r43346
debugdiscovery: small internal refactoring...
r42198 def doit(pushedrevs, remoteheads, remote=remote):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if not util.safehasattr(remote, b'branches'):
Gregory Szorc
debugcommands: move 'debugdiscovery' in the module...
r30517 # enable in-client legacy support
remote = localrepo.locallegacypeer(remote.local())
Augie Fackler
formatting: blacken the codebase...
r43346 common, _in, hds = treediscovery.findcommonincoming(
repo, remote, force=True
)
Gregory Szorc
debugcommands: move 'debugdiscovery' in the module...
r30517 common = set(common)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if not opts.get(b'nonheads'):
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"unpruned common: %s\n"
% b" ".join(sorted(short(n) for n in common))
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: use a revset instead of dagutil...
r39199
clnode = repo.changelog.node
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 common = repo.revs(b'heads(::%ln)', common)
Gregory Szorc
debugcommands: use a revset instead of dagutil...
r39199 common = {clnode(r) for r in common}
debugdiscovery: small internal refactoring...
r42198 return common, hds
Augie Fackler
formatting: blacken the codebase...
r43346
debugdiscovery: small internal refactoring...
r42198 else:
Augie Fackler
formatting: blacken the codebase...
r43346
debugdiscovery: small internal refactoring...
r42198 def doit(pushedrevs, remoteheads, remote=remote):
Boris Feld
setdiscover: allow to ignore part of the local graph...
r35305 nodes = None
if pushedrevs:
revs = scmutil.revrange(repo, pushedrevs)
nodes = [repo[r].node() for r in revs]
Augie Fackler
formatting: blacken the codebase...
r43346 common, any, hds = setdiscovery.findcommonheads(
ui, repo, remote, ancestorsof=nodes
)
debugdiscovery: small internal refactoring...
r42198 return common, hds
Gregory Szorc
debugcommands: move 'debugdiscovery' in the module...
r30517
Martin von Zweigbergk
debugdiscovery: drop reference to non-existent --remote-head option...
r35420 remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, revs=None)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 localrevs = opts[b'rev']
with util.timedcm(b'debug-discovery') as t:
debugdiscovery: display time elapsed during the discovery step...
r42202 common, hds = doit(localrevs, remoterevs)
debugdiscovery: small internal refactoring...
r42198
debugdiscovery: display more statistic about the common set...
r42199 # compute all statistics
debugdiscovery: small internal refactoring...
r42198 common = set(common)
rheads = set(hds)
lheads = set(repo.heads())
debugdiscovery: display more statistic about the common set...
r42199
data = {}
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 data[b'elapsed'] = t.elapsed
data[b'nb-common'] = len(common)
data[b'nb-common-local'] = len(common & lheads)
data[b'nb-common-remote'] = len(common & rheads)
data[b'nb-common-both'] = len(common & rheads & lheads)
data[b'nb-local'] = len(lheads)
data[b'nb-local-missing'] = data[b'nb-local'] - data[b'nb-common-local']
data[b'nb-remote'] = len(rheads)
data[b'nb-remote-unknown'] = data[b'nb-remote'] - data[b'nb-common-remote']
data[b'nb-revs'] = len(repo.revs(b'all()'))
data[b'nb-revs-common'] = len(repo.revs(b'::%ln', common))
data[b'nb-revs-missing'] = data[b'nb-revs'] - data[b'nb-revs-common']
debugdiscovery: display more statistic about the common set...
r42199
# display discovery summary
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b"elapsed time: %(elapsed)f seconds\n" % data)
ui.writenoi18n(b"heads summary:\n")
ui.writenoi18n(b" total common heads: %(nb-common)9d\n" % data)
ui.writenoi18n(b" also local heads: %(nb-common-local)9d\n" % data)
ui.writenoi18n(b" also remote heads: %(nb-common-remote)9d\n" % data)
ui.writenoi18n(b" both: %(nb-common-both)9d\n" % data)
ui.writenoi18n(b" local heads: %(nb-local)9d\n" % data)
ui.writenoi18n(b" common: %(nb-common-local)9d\n" % data)
ui.writenoi18n(b" missing: %(nb-local-missing)9d\n" % data)
ui.writenoi18n(b" remote heads: %(nb-remote)9d\n" % data)
ui.writenoi18n(b" common: %(nb-common-remote)9d\n" % data)
ui.writenoi18n(b" unknown: %(nb-remote-unknown)9d\n" % data)
ui.writenoi18n(b"local changesets: %(nb-revs)9d\n" % data)
ui.writenoi18n(b" common: %(nb-revs-common)9d\n" % data)
ui.writenoi18n(b" missing: %(nb-revs-missing)9d\n" % data)
debugdiscovery: display more statistic about the common set...
r42199
debugdiscovery: only list common heads on verbose...
r42201 if ui.verbose:
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"common heads: %s\n" % b" ".join(sorted(short(n) for n in common))
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518
Boris Feld
debug: add a 'debugdownload' command...
r35578 _chunksize = 4 << 10
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @command(
b'debugdownload', [(b'o', b'output', b'', _(b'path')),], optionalrepo=True
)
Boris Feld
debugdownload: read repository hgrc if there is one...
r35748 def debugdownload(ui, repo, url, output=None, **opts):
Boris Feld
debug: add a 'debugdownload' command...
r35578 """download a resource using Mercurial logic and config
"""
fh = urlmod.open(ui, url, output)
dest = ui
if output:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 dest = open(output, b"wb", _chunksize)
Boris Feld
debug: add a 'debugdownload' command...
r35578 try:
data = fh.read(_chunksize)
while data:
dest.write(data)
data = fh.read(_chunksize)
finally:
if output:
dest.close()
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @command(b'debugextensions', cmdutil.formatteropts, [], optionalrepo=True)
Matt Harbison
debugextensions: process extensions loaded from the local repository too
r37998 def debugextensions(ui, repo, **opts):
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518 '''show information about active extensions'''
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518 exts = extensions.extensions(ui)
hgver = util.version()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm = ui.formatter(b'debugextensions', opts)
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518 for extname, extmod in sorted(exts, key=operator.itemgetter(0)):
isinternal = extensions.ismoduleinternal(extmod)
Pulkit Goyal
py3: use pycompat.fsencode() to convert __file__ to bytes...
r31074 extsource = pycompat.fsencode(extmod.__file__)
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518 if isinternal:
exttestedwith = [] # never expose magic string to users
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 exttestedwith = getattr(extmod, 'testedwith', b'').split()
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518 extbuglink = getattr(extmod, 'buglink', None)
fm.startitem()
if ui.quiet or ui.verbose:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.write(b'name', b'%s\n', extname)
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.write(b'name', b'%s', extname)
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518 if isinternal or hgver in exttestedwith:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.plain(b'\n')
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518 elif not exttestedwith:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.plain(_(b' (untested!)\n'))
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518 else:
lasttestedversion = exttestedwith[-1]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.plain(b' (%s!)\n' % lasttestedversion)
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518
Augie Fackler
formatting: blacken the codebase...
r43346 fm.condwrite(
ui.verbose and extsource,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'source',
_(b' location: %s\n'),
extsource or b"",
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518
if ui.verbose:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.plain(_(b' bundled: %s\n') % [b'no', b'yes'][isinternal])
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518 fm.data(bundled=isinternal)
Augie Fackler
formatting: blacken the codebase...
r43346 fm.condwrite(
ui.verbose and exttestedwith,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'testedwith',
_(b' tested with: %s\n'),
fm.formatlist(exttestedwith, name=b'ver'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
fm.condwrite(
ui.verbose and extbuglink,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'buglink',
_(b' bug reporting: %s\n'),
extbuglink or b"",
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: move 'debugextensions' to the new module
r30518
fm.end()
Gregory Szorc
debugcommands: move 'debugfileset' in the new module
r30524
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugfileset',
Augie Fackler
formatting: blacken the codebase...
r43346 [
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'r',
b'rev',
b'',
_(b'apply the filespec on this revision'),
_(b'REV'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'',
b'all-files',
False,
_(b'test files from all revisions and working directory'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b's',
b'show-matcher',
None,
_(b'print internal representation of matcher'),
),
(
b'p',
b'show-stage',
Augie Fackler
formatting: blacken the codebase...
r43346 [],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'print parsed tree at the given stage'),
_(b'NAME'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'[-r REV] [--all-files] [OPTION]... FILESPEC'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: move 'debugfileset' in the new module
r30524 def debugfileset(ui, repo, expr, **opts):
'''parse and apply a fileset specification'''
Augie Fackler
debugcommands: force import of fileset in debugfileset...
r39008 from . import fileset
Augie Fackler
formatting: blacken the codebase...
r43346
fileset.symbols # force import of fileset so we have predicates to optimize
Yuya Nishihara
fileset: make debugfileset filter repository files...
r38629 opts = pycompat.byteskwargs(opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = scmutil.revsingle(repo, opts.get(b'rev'), None)
Yuya Nishihara
debugfileset: backport --show-stage option from debugrevspec...
r38837
stages = [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'parsed', pycompat.identity),
(b'analyzed', filesetlang.analyze),
(b'optimized', filesetlang.optimize),
Yuya Nishihara
debugfileset: backport --show-stage option from debugrevspec...
r38837 ]
stagenames = set(n for n, f in stages)
showalways = set()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if ui.verbose and not opts[b'show_stage']:
Yuya Nishihara
debugfileset: backport --show-stage option from debugrevspec...
r38837 # show parsed tree by --verbose (deprecated)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 showalways.add(b'parsed')
if opts[b'show_stage'] == [b'all']:
Yuya Nishihara
debugfileset: backport --show-stage option from debugrevspec...
r38837 showalways.update(stagenames)
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 for n in opts[b'show_stage']:
Yuya Nishihara
debugfileset: backport --show-stage option from debugrevspec...
r38837 if n not in stagenames:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'invalid stage name: %s') % n)
showalways.update(opts[b'show_stage'])
Yuya Nishihara
debugfileset: backport --show-stage option from debugrevspec...
r38837
Yuya Nishihara
fileset: extract language processing part to new module (API)...
r38841 tree = filesetlang.parse(expr)
Yuya Nishihara
debugfileset: backport --show-stage option from debugrevspec...
r38837 for n, f in stages:
tree = f(tree)
if n in showalways:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'show_stage'] or n != b'parsed':
ui.write(b"* %s:\n" % n)
ui.write(filesetlang.prettyformat(tree), b"\n")
Gregory Szorc
debugcommands: move 'debugfileset' in the new module
r30524
Yuya Nishihara
fileset: make debugfileset filter repository files...
r38629 files = set()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'all_files']:
Yuya Nishihara
fileset: make debugfileset filter repository files...
r38629 for r in repo:
c = repo[r]
files.update(c.files())
files.update(c.substate)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'all_files'] or ctx.rev() is None:
Yuya Nishihara
fileset: make debugfileset filter repository files...
r38629 wctx = repo[None]
Augie Fackler
formatting: blacken the codebase...
r43346 files.update(
repo.dirstate.walk(
scmutil.matchall(repo),
subrepos=list(wctx.substate),
unknown=True,
ignored=True,
)
)
Yuya Nishihara
fileset: make debugfileset filter repository files...
r38629 files.update(wctx.substate)
else:
files.update(ctx.files())
files.update(ctx.substate)
Yuya Nishihara
fileset: restrict getfileset() to not return a computed set (API)...
r38631 m = ctx.matchfileset(expr)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'show_matcher'] or (opts[b'show_matcher'] is None and ui.verbose):
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'* matcher:\n', stringutil.prettyrepr(m), b'\n')
Yuya Nishihara
fileset: make debugfileset filter repository files...
r38629 for f in sorted(files):
if not m(f):
continue
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b"%s\n" % f)
@command(b'debugformat', [] + cmdutil.formatteropts)
Boris Feld
debugformat: add a 'debugformat' command...
r35337 def debugformat(ui, repo, **opts):
Boris Feld
debugformat: add data about the config when verbose...
r35338 """display format information about the current repository
Use --verbose to get extra information about current config value and
Mercurial default."""
Pulkit Goyal
py3: handle keyword arguments correctly in debugcommands.py...
r35402 opts = pycompat.byteskwargs(opts)
Boris Feld
debugformat: add a 'debugformat' command...
r35337 maxvariantlength = max(len(fv.name) for fv in upgrade.allformatvariant)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 maxvariantlength = max(len(b'format-variant'), maxvariantlength)
Boris Feld
debugformat: add a 'debugformat' command...
r35337
def makeformatname(name):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'%s:' + (b' ' * (maxvariantlength - len(name)))
fm = ui.formatter(b'debugformat', opts)
Yuya Nishihara
debugformat: embed raw values in JSON and template output
r35379 if fm.isplain():
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
debugformat: embed raw values in JSON and template output
r35379 def formatvalue(value):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if util.safehasattr(value, b'startswith'):
Yuya Nishihara
debugformat: embed raw values in JSON and template output
r35379 return value
if value:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'yes'
Yuya Nishihara
debugformat: embed raw values in JSON and template output
r35379 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'no'
Augie Fackler
formatting: blacken the codebase...
r43346
Yuya Nishihara
debugformat: embed raw values in JSON and template output
r35379 else:
formatvalue = pycompat.identity
Boris Feld
debugformat: add a 'debugformat' command...
r35337
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.plain(b'format-variant')
fm.plain(b' ' * (maxvariantlength - len(b'format-variant')))
fm.plain(b' repo')
Boris Feld
debugformat: add data about the config when verbose...
r35338 if ui.verbose:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.plain(b' config default')
fm.plain(b'\n')
Boris Feld
debugformat: add a 'debugformat' command...
r35337 for fv in upgrade.allformatvariant:
Yuya Nishihara
debugformat: flush formatter output per item
r35378 fm.startitem()
Boris Feld
debugformat: add a 'debugformat' command...
r35337 repovalue = fv.fromrepo(repo)
Boris Feld
debugformat: add data about the config when verbose...
r35338 configvalue = fv.fromconfig(repo)
Boris Feld
debugformat: add a 'debugformat' command...
r35337
Boris Feld
debugformat: update label depending on value difference...
r35339 if repovalue != configvalue:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 namelabel = b'formatvariant.name.mismatchconfig'
repolabel = b'formatvariant.repo.mismatchconfig'
Boris Feld
debugformat: update label depending on value difference...
r35339 elif repovalue != fv.default:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 namelabel = b'formatvariant.name.mismatchdefault'
repolabel = b'formatvariant.repo.mismatchdefault'
Boris Feld
debugformat: update label depending on value difference...
r35339 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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)
Boris Feld
debugformat: update label depending on value difference...
r35339 if fv.default != configvalue:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 configlabel = b'formatvariant.config.special'
Boris Feld
debugformat: update label depending on value difference...
r35339 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 configlabel = b'formatvariant.config.default'
Augie Fackler
formatting: blacken the codebase...
r43346 fm.condwrite(
ui.verbose,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'config',
b' %6s',
Augie Fackler
formatting: blacken the codebase...
r43346 formatvalue(configvalue),
label=configlabel,
)
fm.condwrite(
ui.verbose,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'default',
b' %7s',
Augie Fackler
formatting: blacken the codebase...
r43346 formatvalue(fv.default),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 label=b'formatvariant.default',
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.plain(b'\n')
Yuya Nishihara
debugformat: flush formatter output per item
r35378 fm.end()
Boris Feld
debugformat: add a 'debugformat' command...
r35337
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @command(b'debugfsinfo', [], _(b'[PATH]'), norepo=True)
def debugfsinfo(ui, path=b"."):
Gregory Szorc
debugcommands: move 'debugfsinfo' in the new module
r30525 """show information detected about current filesystem"""
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'path: %s\n' % path)
formatting: run black on all file again...
r43364 ui.writenoi18n(
b'mounted on: %s\n' % (util.getfsmountpoint(path) or b'(unknown)')
)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
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)'))
formatting: run black on all file again...
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')
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 casesensitive = b'(unknown)'
Jun Wu
debugfsinfo: improve case-sensitive testing...
r31634 try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 with pycompat.namedtempfile(prefix=b'.debugfsinfo', dir=path) as f:
casesensitive = util.fscasesensitive(f.name) and b'yes' or b'no'
Jun Wu
debugfsinfo: improve case-sensitive testing...
r31634 except OSError:
pass
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'case-sensitive: %s\n' % casesensitive)
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debuggetbundle',
Augie Fackler
formatting: blacken the codebase...
r43346 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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'),
),
Augie Fackler
formatting: blacken the codebase...
r43346 ],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'REPO FILE [-H|-C ID]...'),
Augie Fackler
formatting: blacken the codebase...
r43346 norepo=True,
)
Gregory Szorc
debugcommands: move 'debuggetbundle' in the new module
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.
"""
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Gregory Szorc
debugcommands: move 'debuggetbundle' in the new module
r30526 repo = hg.peer(ui, opts, repopath)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if not repo.capable(b'getbundle'):
raise error.Abort(b"getbundle() not supported by target repository")
Gregory Szorc
debugcommands: move 'debuggetbundle' in the new module
r30526 args = {}
if common:
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 args[r'common'] = [bin(s) for s in common]
Gregory Szorc
debugcommands: move 'debuggetbundle' in the new module
r30526 if head:
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 args[r'heads'] = [bin(s) for s in head]
Gregory Szorc
debugcommands: move 'debuggetbundle' in the new module
r30526 # TODO: get desired bundlecaps from command line.
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 args[r'bundlecaps'] = None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 bundle = repo.getbundle(b'debug', **args)
bundletype = opts.get(b'type', b'bzip2').lower()
Augie Fackler
formatting: blacken the codebase...
r43346 btypes = {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'none': b'HG10UN',
b'bzip2': b'HG10BZ',
b'gzip': b'HG10GZ',
b'bundle2': b'HG20',
Augie Fackler
formatting: blacken the codebase...
r43346 }
Gregory Szorc
debugcommands: move 'debuggetbundle' in the new module
r30526 bundletype = btypes.get(bundletype)
if bundletype not in bundle2.bundletypes:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'unknown bundle type specified with --type'))
Gregory Szorc
debugcommands: move 'debuggetbundle' in the new module
r30526 bundle2.writebundle(ui, bundle, bundlepath, bundletype)
Gregory Szorc
debugcommands: move 'debugignore' in the new module
r30527
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @command(b'debugignore', [], b'[FILE]')
Gregory Szorc
debugcommands: move 'debugignore' in the new module
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
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b"%s\n" % pycompat.byterepr(ignore))
Gregory Szorc
debugcommands: move 'debugignore' in the new module
r30527 else:
Matt Harbison
debugignore: eliminate inconsistencies with `hg status` (issue5222)...
r33507 m = scmutil.match(repo[None], pats=files)
Martin von Zweigbergk
debugignore: respect ui.relative-paths...
r41785 uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True)
Matt Harbison
debugignore: eliminate inconsistencies with `hg status` (issue5222)...
r33507 for f in m.files():
Gregory Szorc
debugcommands: move 'debugignore' in the new module
r30527 nf = util.normpath(f)
ignored = None
ignoredata = None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if nf != b'.':
Gregory Szorc
debugcommands: move 'debugignore' in the new module
r30527 if ignore(nf):
ignored = nf
ignoredata = repo.dirstate._ignorefileandline(nf)
else:
for p in util.finddirs(nf):
if ignore(p):
ignored = p
ignoredata = repo.dirstate._ignorefileandline(p)
break
if ignored:
if ignored == nf:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(_(b"%s is ignored\n") % uipathfn(f))
Gregory Szorc
debugcommands: move 'debugignore' in the new module
r30527 else:
Augie Fackler
formatting: blacken the codebase...
r43346 ui.write(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"%s is ignored because of "
b"containing directory %s\n"
Augie Fackler
formatting: blacken the codebase...
r43346 )
% (uipathfn(f), ignored)
)
Gregory Szorc
debugcommands: move 'debugignore' in the new module
r30527 ignorefile, lineno, line = ignoredata
Augie Fackler
formatting: blacken the codebase...
r43346 ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"(ignore rule in %s, line %d: '%s')\n")
Augie Fackler
formatting: blacken the codebase...
r43346 % (ignorefile, lineno, line)
)
Gregory Szorc
debugcommands: move 'debugignore' in the new module
r30527 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(_(b"%s is not ignored\n") % uipathfn(f))
Gregory Szorc
debugcommands: move 'debugindex' and 'debugindexdot' in the new module
r30528
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugindex',
Augie Fackler
formatting: blacken the codebase...
r43346 cmdutil.debugrevlogopts + cmdutil.formatteropts,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'-c|-m|FILE'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: move 'debugindex' and 'debugindexdot' in the new module
r30528 def debugindex(ui, repo, file_=None, **opts):
Gregory Szorc
debugcommands: introduce debugrevlogindex (BC)...
r39318 """dump index data for a storage primitive"""
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 store = cmdutil.openstorage(repo, b'debugindex', file_, opts)
Gregory Szorc
debugcommands: move 'debugindex' and 'debugindexdot' in the new module
r30528
if ui.debugflag:
shortfn = hex
else:
shortfn = short
idlen = 12
Gregory Szorc
debugcommands: introduce debugrevlogindex (BC)...
r39318 for i in store:
idlen = len(shortfn(store.node(i)))
Gregory Szorc
debugcommands: move 'debugindex' and 'debugindexdot' in the new module
r30528 break
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm = ui.formatter(b'debugindex', opts)
Augie Fackler
formatting: blacken the codebase...
r43346 fm.plain(
b' rev linkrev %s %s p2\n'
% (b'nodeid'.ljust(idlen), b'p1'.ljust(idlen))
)
Gregory Szorc
debugcommands: introduce debugrevlogindex (BC)...
r39318
for rev in store:
node = store.node(rev)
parents = store.parents(node)
fm.startitem()
fm.write(b'rev', b'%6d ', rev)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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]))
Gregory Szorc
debugcommands: introduce debugrevlogindex (BC)...
r39318 fm.plain(b'\n')
fm.end()
Gregory Szorc
debugcommands: move 'debugindex' and 'debugindexdot' in the new module
r30528
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugindexdot',
cmdutil.debugrevlogopts,
_(b'-c|-m|FILE'),
optionalrepo=True,
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: move 'debugindex' and 'debugindexdot' in the new module
r30528 def debugindexdot(ui, repo, file_=None, **opts):
"""dump an index DAG as a graphviz dot file"""
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 r = cmdutil.openstorage(repo, b'debugindexdot', file_, opts)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b"digraph G {\n")
Gregory Szorc
debugcommands: move 'debugindex' and 'debugindexdot' in the new module
r30528 for i in r:
node = r.node(i)
pp = r.parents(node)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b"\t%d -> %d\n" % (r.rev(pp[0]), i))
Gregory Szorc
debugcommands: move 'debugindex' and 'debugindexdot' in the new module
r30528 if pp[1] != nullid:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b"\t%d -> %d\n" % (r.rev(pp[1]), i))
ui.write(b"}\n")
@command(b'debugindexstats', [])
Martin von Zweigbergk
debugcommands: add a debugindexstats command...
r40016 def debugindexstats(ui, repo):
"""show stats related to the changelog index"""
repo.changelog.shortest(nullid, 1)
Martin von Zweigbergk
debugcommands: avoid stack trace from debugindexstats in pure mode...
r40401 index = repo.changelog.index
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if not util.safehasattr(index, b'stats'):
raise error.Abort(_(b'debugindexstats only works with native code'))
Martin von Zweigbergk
debugcommands: avoid stack trace from debugindexstats in pure mode...
r40401 for k, v in sorted(index.stats().items()):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'%s: %d\n' % (k, v))
@command(b'debuginstall', [] + cmdutil.formatteropts, b'', norepo=True)
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 def debuginstall(ui, **opts):
'''test Mercurial installation
Returns 0 on success.
'''
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918
problems = 0
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm = ui.formatter(b'debuginstall', opts)
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 fm.startitem()
# encoding
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.write(b'encoding', _(b"checking encoding (%s)...\n"), encoding.encoding)
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 err = None
try:
Yuya Nishihara
debuginstall: use codecs.lookup() to detect invalid encoding...
r34131 codecs.lookup(pycompat.sysstr(encoding.encoding))
except LookupError as inst:
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 err = stringutil.forcebytestr(inst)
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 problems += 1
Augie Fackler
formatting: blacken the codebase...
r43346 fm.condwrite(
err,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'encodingerror',
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b" %s\n (check that your locale is properly set)\n"),
Augie Fackler
formatting: blacken the codebase...
r43346 err,
)
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918
# Python
Augie Fackler
formatting: blacken the codebase...
r43346 fm.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'pythonexe',
_(b"checking Python executable (%s)\n"),
pycompat.sysexecutable or _(b"unknown"),
Augie Fackler
formatting: blacken the codebase...
r43346 )
fm.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'pythonver',
_(b"checking Python version (%s)\n"),
(b"%d.%d.%d" % sys.version_info[:3]),
Augie Fackler
formatting: blacken the codebase...
r43346 )
fm.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'pythonlib',
_(b"checking Python lib (%s)...\n"),
Augie Fackler
formatting: blacken the codebase...
r43346 os.path.dirname(pycompat.fsencode(os.__file__)),
)
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918
security = set(sslutil.supportedprotocols)
if sslutil.hassni:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 security.add(b'sni')
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918
Augie Fackler
formatting: blacken the codebase...
r43346 fm.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'pythonsecurity',
_(b"checking Python security support (%s)\n"),
fm.formatlist(sorted(security), name=b'protocol', fmt=b'%s', sep=b','),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918
# These are warnings, not errors. So don't increment problem count. This
# may change in the future.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'tls1.2' not in security:
Augie Fackler
formatting: blacken the codebase...
r43346 fm.plain(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b' TLS 1.2 not supported by Python install; '
b'network connections lack modern security\n'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'sni' not in security:
Augie Fackler
formatting: blacken the codebase...
r43346 fm.plain(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b' SNI not supported by Python install; may have '
b'connectivity issues with some servers\n'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918
# TODO print CA cert info
# hg version
hgver = util.version()
Augie Fackler
formatting: blacken the codebase...
r43346 fm.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'hgver', _(b"checking Mercurial version (%s)\n"), hgver.split(b'+')[0]
Augie Fackler
formatting: blacken the codebase...
r43346 )
fm.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'hgverextra',
_(b"checking Mercurial custom build (%s)\n"),
b'+'.join(hgver.split(b'+')[1:]),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918
# compiled modules
Augie Fackler
formatting: blacken the codebase...
r43346 fm.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'hgmodulepolicy', _(b"checking module policy (%s)\n"), policy.policy
Augie Fackler
formatting: blacken the codebase...
r43346 )
fm.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'hgmodules',
_(b"checking installed modules (%s)...\n"),
Augie Fackler
formatting: blacken the codebase...
r43346 os.path.dirname(pycompat.fsencode(__file__)),
)
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rustandc = policy.policy in (b'rust+c', b'rust+c-allow')
Georges Racinet
rust: module policy with importrust...
r42651 rustext = rustandc # for now, that's the only case
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 cext = policy.policy in (b'c', b'allow') or rustandc
Georges Racinet
rust: module policy with importrust...
r42651 nopure = cext or rustext
if nopure:
Yuya Nishihara
debuginstall: check C extensions only if they are loadable per policy...
r32204 err = None
try:
Georges Racinet
rust: module policy with importrust...
r42651 if cext:
from .cext import (
base85,
bdiff,
mpatch,
osutil,
)
Augie Fackler
formatting: blacken the codebase...
r43346
Georges Racinet
rust: module policy with importrust...
r42651 # quiet pyflakes
dir(bdiff), dir(mpatch), dir(base85), dir(osutil)
if rustext:
from .rustext import (
ancestor,
dirstate,
)
Augie Fackler
formatting: blacken the codebase...
r43346
dir(ancestor), dir(dirstate) # quiet pyflakes
Yuya Nishihara
debuginstall: check C extensions only if they are loadable per policy...
r32204 except Exception as inst:
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 err = stringutil.forcebytestr(inst)
Yuya Nishihara
debuginstall: check C extensions only if they are loadable per policy...
r32204 problems += 1
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.condwrite(err, b'extensionserror', b" %s\n", err)
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918
compengines = util.compengines._engines.values()
Augie Fackler
formatting: blacken the codebase...
r43346 fm.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'compengines',
_(b'checking registered compression engines (%s)\n'),
Augie Fackler
formatting: blacken the codebase...
r43346 fm.formatlist(
sorted(e.name() for e in compengines),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 name=b'compengine',
fmt=b'%s',
sep=b', ',
Augie Fackler
formatting: blacken the codebase...
r43346 ),
)
fm.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'compenginesavail',
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b'checking available compression engines (%s)\n'),
Augie Fackler
formatting: blacken the codebase...
r43346 fm.formatlist(
sorted(e.name() for e in compengines if e.available()),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 name=b'compengine',
fmt=b'%s',
sep=b', ',
Augie Fackler
formatting: blacken the codebase...
r43346 ),
)
util: extract compression code in `mercurial.utils.compression`...
r42208 wirecompengines = compression.compengines.supportedwireengines(
Augie Fackler
formatting: blacken the codebase...
r43346 compression.SERVERROLE
)
fm.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'compenginesserver',
_(
b'checking available compression engines '
b'for wire protocol (%s)\n'
),
Augie Fackler
formatting: blacken the codebase...
r43346 fm.formatlist(
[e.name() for e in wirecompengines if e.wireprotosupport()],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 name=b'compengine',
fmt=b'%s',
sep=b', ',
Augie Fackler
formatting: blacken the codebase...
r43346 ),
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 re2 = b'missing'
Boris Feld
debuginstall: add a line about re2 availability...
r35464 if util._re2:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 re2 = b'available'
fm.plain(_(b'checking "re2" regexp engine (%s)\n') % re2)
Boris Feld
debuginstall: add a line about re2 availability...
r35464 fm.data(re2=bool(util._re2))
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918
# templates
p = templater.templatepaths()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.write(b'templatedirs', b'checking templates (%s)...\n', b' '.join(p))
fm.condwrite(not p, b'', _(b" no template directories found\n"))
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 if p:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 m = templater.templatepath(b"map-cmdline.default")
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 if m:
# template found, check if it is working
err = None
try:
templater.templater.frommapfile(m)
except Exception as inst:
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 err = stringutil.forcebytestr(inst)
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 p = None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.condwrite(err, b'defaulttemplateerror', b" %s\n", err)
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 else:
p = None
Augie Fackler
formatting: blacken the codebase...
r43346 fm.condwrite(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 p, b'defaulttemplate', _(b"checking default template (%s)\n"), m
Augie Fackler
formatting: blacken the codebase...
r43346 )
fm.condwrite(
not m,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'defaulttemplatenotfound',
_(b" template '%s' not found\n"),
b"default",
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 if not p:
problems += 1
Augie Fackler
formatting: blacken the codebase...
r43346 fm.condwrite(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 not p, b'', _(b" (templates seem to have been installed incorrectly)\n")
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918
# editor
editor = ui.geteditor()
editor = util.expandpath(editor)
Yuya Nishihara
procutil: bulk-replace function calls to point to new module
r37138 editorbin = procutil.shellsplit(editor)[0]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.write(b'editor', _(b"checking commit editor... (%s)\n"), editorbin)
Yuya Nishihara
procutil: bulk-replace function calls to point to new module
r37138 cmdpath = procutil.findexe(editorbin)
Augie Fackler
formatting: blacken the codebase...
r43346 fm.condwrite(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 not cmdpath and editor == b'vi',
b'vinotfound',
Augie Fackler
formatting: blacken the codebase...
r43346 _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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"
Augie Fackler
formatting: blacken the codebase...
r43346 ),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 not cmdpath and editor == b'vi' and editorbin,
Augie Fackler
formatting: blacken the codebase...
r43346 )
fm.condwrite(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 not cmdpath and editor != b'vi',
b'editornotfound',
Augie Fackler
formatting: blacken the codebase...
r43346 _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b" Can't find editor '%s' in PATH\n"
b" (specify a commit editor in your configuration"
b" file)\n"
Augie Fackler
formatting: blacken the codebase...
r43346 ),
not cmdpath and editorbin,
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if not cmdpath and editor != b'vi':
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 problems += 1
# check username
username = None
err = None
try:
username = ui.username()
except error.Abort as e:
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 err = stringutil.forcebytestr(e)
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 problems += 1
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.condwrite(
username, b'username', _(b"checking username (%s)\n"), username
)
Augie Fackler
formatting: blacken the codebase...
r43346 fm.condwrite(
err,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'usernameerror',
Augie Fackler
formatting: blacken the codebase...
r43346 _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"checking username...\n %s\n"
b" (specify a username in your configuration file)\n"
Augie Fackler
formatting: blacken the codebase...
r43346 ),
err,
)
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918
Augie Fackler
debugcommands: add support for extensions adding their own debug info...
r42878 for name, mod in extensions.extensions():
handler = getattr(mod, 'debuginstall', None)
if handler is not None:
problems += handler(ui, fm)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm.condwrite(not problems, b'', _(b"no problems detected\n"))
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 if not problems:
fm.data(problems=problems)
Augie Fackler
formatting: blacken the codebase...
r43346 fm.condwrite(
problems,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'problems',
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b"%d problems detected, please check your install!\n"),
Augie Fackler
formatting: blacken the codebase...
r43346 problems,
)
Pierre-Yves David
debugcommands: extract debuginstall in the debugcommands module
r30918 fm.end()
return problems
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @command(b'debugknown', [], _(b'REPO ID...'), norepo=True)
Pierre-Yves David
debugcommands: move 'debugknown' in the new module
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.
"""
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Pierre-Yves David
debugcommands: move 'debugknown' in the new module
r30919 repo = hg.peer(ui, opts, repopath)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if not repo.capable(b'known'):
raise error.Abort(b"known() not supported by target repository")
Pierre-Yves David
debugcommands: move 'debugknown' in the new module
r30919 flags = repo.known([bin(s) for s in ids])
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b"%s\n" % (b"".join([f and b"1" or b"0" for f in flags])))
@command(b'debuglabelcomplete', [], _(b'LABEL...'))
Pierre-Yves David
debugcommands: move 'debuglabelcomplete' in the new module
r30935 def debuglabelcomplete(ui, repo, *args):
'''backwards compatibility with old bash completion scripts (DEPRECATED)'''
Kyle Lippincott
debuglabelcomplete: fix to call debugnamecomplete in new location...
r31402 debugnamecomplete(ui, repo, *args)
Pierre-Yves David
debugcommands: move 'debuglabelcomplete' in the new module
r30935
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debuglocks',
Augie Fackler
formatting: blacken the codebase...
r43346 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'L', b'force-lock', None, _(b'free the store lock (DANGEROUS)')),
Augie Fackler
formatting: blacken the codebase...
r43346 (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'W',
b'force-wlock',
Augie Fackler
formatting: blacken the codebase...
r43346 None,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'free the working state lock (DANGEROUS)'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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'),
),
Augie Fackler
formatting: blacken the codebase...
r43346 ],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'[OPTION]...'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debuglocks' in the new module
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.
Paul Morelle
debuglocks: allow setting a lock
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.
Pierre-Yves David
debugcommands: move 'debuglocks' in the new module
r30938 Returns 0 if no locks are held.
"""
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 if opts.get(r'force_lock'):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo.svfs.unlink(b'lock')
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 if opts.get(r'force_wlock'):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo.vfs.unlink(b'wlock')
Paul Morelle
debuglocks: add tests (and fix typo in early return)
r35395 if opts.get(r'force_lock') or opts.get(r'force_wlock'):
Pierre-Yves David
debugcommands: move 'debuglocks' in the new module
r30938 return 0
Paul Morelle
debuglocks: allow setting a lock
r35396 locks = []
try:
if opts.get(r'set_wlock'):
try:
locks.append(repo.wlock(False))
except error.LockHeld:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'wlock is already held'))
Paul Morelle
debuglocks: allow setting a lock
r35396 if opts.get(r'set_lock'):
try:
locks.append(repo.lock(False))
except error.LockHeld:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'lock is already held'))
Paul Morelle
debuglocks: allow setting a lock
r35396 if len(locks):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.promptchoice(_(b"ready to release the lock (y)? $$ &Yes"))
Paul Morelle
debuglocks: allow setting a lock
r35396 return 0
finally:
release(*locks)
Pierre-Yves David
debugcommands: move 'debuglocks' in the new module
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:
Augie Fackler
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime...
r36799 st = vfs.lstat(name)
age = now - st[stat.ST_MTIME]
user = util.username(st.st_uid)
Pierre-Yves David
debugcommands: move 'debuglocks' in the new module
r30938 locker = vfs.readlock(name)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b":" in locker:
host, pid = locker.split(b':')
Pierre-Yves David
debugcommands: move 'debuglocks' in the new module
r30938 if host == socket.gethostname():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 locker = b'user %s, process %s' % (user or b'None', pid)
Pierre-Yves David
debugcommands: move 'debuglocks' in the new module
r30938 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 locker = b'user %s, process %s, host %s' % (
Augie Fackler
formatting: blacken the codebase...
r43346 user or b'None',
pid,
host,
)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b"%-6s %s (%ds)\n" % (name + b":", locker, age))
Pierre-Yves David
debugcommands: move 'debuglocks' in the new module
r30938 return 1
except OSError as e:
if e.errno != errno.ENOENT:
raise
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b"%-6s free\n" % (name + b":"))
Pierre-Yves David
debugcommands: move 'debuglocks' in the new module
r30938 return 0
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 held += report(repo.svfs, b"lock", repo.lock)
held += report(repo.vfs, b"wlock", repo.wlock)
Pierre-Yves David
debugcommands: move 'debuglocks' in the new module
r30938
return held
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugmanifestfulltextcache',
Augie Fackler
formatting: blacken the codebase...
r43346 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'', b'clear', False, _(b'clear the cache')),
Augie Fackler
formatting: blacken the codebase...
r43346 (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'a',
b'add',
Augie Fackler
formatting: blacken the codebase...
r43346 [],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'add the given manifest nodes to the cache'),
_(b'NODE'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'',
Augie Fackler
formatting: blacken the codebase...
r43346 )
manifestcache: support multiple cache addition in one debug command run...
r42124 def debugmanifestfulltextcache(ui, repo, add=(), **opts):
Martijn Pieters
manifest: persist the manifestfulltext cache...
r38803 """show, clear or amend the contents of the manifest fulltext cache"""
manifestcache: only lock the repository if the debug command touch the cache...
r42108
def getcache():
Gregory Szorc
manifest: add getstorage() to manifestlog and use it globally...
r39280 r = repo.manifestlog.getstorage(b'')
Martijn Pieters
manifest: persist the manifestfulltext cache...
r38803 try:
manifestcache: only lock the repository if the debug command touch the cache...
r42108 return r._fulltextcache
Martijn Pieters
manifest: persist the manifestfulltext cache...
r38803 except AttributeError:
Augie Fackler
formatting: blacken the codebase...
r43346 msg = _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"Current revlog implementation doesn't appear to have a "
b"manifest fulltext cache\n"
Augie Fackler
formatting: blacken the codebase...
r43346 )
manifestcache: only lock the repository if the debug command touch the cache...
r42108 raise error.Abort(msg)
if opts.get(r'clear'):
manifestcache: protect write with `wlock` instead of `lock`...
r42130 with repo.wlock():
manifestcache: only lock the repository if the debug command touch the cache...
r42108 cache = getcache()
manifestcache: actually honor --clear...
r42113 cache.clear(clear_persisted_data=True)
return
Martijn Pieters
manifest: persist the manifestfulltext cache...
r38803
manifestcache: only lock the repository if the debug command touch the cache...
r42108 if add:
manifestcache: protect write with `wlock` instead of `lock`...
r42130 with repo.wlock():
manifestcache: support multiple cache addition in one debug command run...
r42124 m = repo.manifestlog
store = m.getstorage(b'')
for n in add:
try:
manifest = m[store.lookup(n)]
except error.LookupError as e:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(e, hint=b"Check your manifest node id")
manifestcache: support multiple cache addition in one debug command run...
r42124 manifest.read() # stores revisision in cache too
manifestcache: do not display data when using --add...
r42109 return
Martijn Pieters
manifest: persist the manifestfulltext cache...
r38803
manifestcache: only lock the repository if the debug command touch the cache...
r42108 cache = getcache()
if not len(cache):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(_(b'cache empty\n'))
manifestcache: only lock the repository if the debug command touch the cache...
r42108 else:
ui.write(
Augie Fackler
formatting: blacken the codebase...
r43346 _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'cache contains %d manifest entries, in order of most to '
b'least recent:\n'
Augie Fackler
formatting: blacken the codebase...
r43346 )
% (len(cache),)
)
manifestcache: only lock the repository if the debug command touch the cache...
r42108 totalsize = 0
for nodeid in cache:
# Use cache.get to not update the LRU order
manifestcache: stop altering the lru cache order while displaying it...
r42125 data = cache.peek(nodeid)
manifestcache: only lock the repository if the debug command touch the cache...
r42108 size = len(data)
Augie Fackler
formatting: blacken the codebase...
r43346 totalsize += size + 24 # 20 bytes nodeid, 4 bytes size
ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'id: %s, size %s\n') % (hex(nodeid), util.bytecount(size))
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ondisk = cache._opener.stat(b'manifestfulltextcache').st_size
manifestcache: only lock the repository if the debug command touch the cache...
r42108 ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'total cache data size %s, on-disk %s\n')
Augie Fackler
formatting: blacken the codebase...
r43346 % (util.bytecount(totalsize), util.bytecount(ondisk))
manifestcache: only lock the repository if the debug command touch the cache...
r42108 )
Martijn Pieters
manifest: persist the manifestfulltext cache...
r38803
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @command(b'debugmergestate', [], b'')
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 def debugmergestate(ui, repo, *args):
"""print merge state
Use --verbose to print out information about whether v1 or v2 merge state
was chosen."""
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 def _hashornull(h):
if h == nullhex:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'null'
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 else:
return h
def printrecords(version):
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'* version %d records\n' % version)
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 if version == 1:
records = v1records
else:
records = v2records
for rtype, record in records:
# pretty print some record types
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if rtype == b'L':
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'local: %s\n' % record)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif rtype == b'O':
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'other: %s\n' % record)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif rtype == b'm':
driver, mdstate = record.split(b'\0', 1)
formatting: run black on all file again...
r43364 ui.writenoi18n(
b'merge driver: %s (state "%s")\n' % (driver, mdstate)
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif rtype in b'FDC':
r = record.split(b'\0')
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 f, state, hash, lfile, afile, anode, ofile = r[0:7]
if version == 1:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 onode = b'not stored in v1 format'
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 flags = r[7]
else:
onode, flags = r[7:9]
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'file: %s (record type "%s", state "%s", hash %s)\n'
Augie Fackler
formatting: blacken the codebase...
r43346 % (f, rtype, state, _hashornull(hash))
)
formatting: run black on all file again...
r43364 ui.writenoi18n(
b' local path: %s (flags "%s")\n' % (lfile, flags)
)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b' ancestor path: %s (node %s)\n'
Augie Fackler
formatting: blacken the codebase...
r43346 % (afile, _hashornull(anode))
)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b' other path: %s (node %s)\n'
% (ofile, _hashornull(onode))
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif rtype == b'f':
filename, rawextras = record.split(b'\0', 1)
extras = rawextras.split(b'\0')
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 i = 0
extrastrings = []
while i < len(extras):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 extrastrings.append(b'%s = %s' % (extras[i], extras[i + 1]))
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 i += 2
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'file extras: %s (%s)\n'
% (filename, b', '.join(extrastrings))
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif rtype == b'l':
labels = record.split(b'\0', 2)
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 labels = [l for l in labels if len(l) > 0]
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'labels:\n')
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write((b' local: %s\n' % labels[0]))
ui.write((b' other: %s\n' % labels[1]))
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 if len(labels) > 2:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write((b' base: %s\n' % labels[2]))
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 else:
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'unrecognized entry: %s\t%s\n'
% (rtype, record.replace(b'\0', b'\t'))
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936
# Avoid mergestate.read() since it may raise an exception for unsupported
# merge state records. We shouldn't be doing this, but this is OK since this
# command is pretty low-level.
ms = mergemod.mergestate(repo)
# sort so that reasonable information is on top
v1records = ms._readrecordsv1()
v2records = ms._readrecordsv2()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 order = b'LOml'
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 def key(r):
idx = order.find(r[0])
if idx == -1:
return (1, r[1])
else:
return (0, idx)
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 v1records.sort(key=key)
v2records.sort(key=key)
if not v1records and not v2records:
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'no merge state found\n')
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 elif not v2records:
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.notenoi18n(b'no version 2 merge state\n')
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 printrecords(1)
elif ms._v1v2match(v1records, v2records):
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.notenoi18n(b'v1 and v2 states match: using v2\n')
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 printrecords(2)
else:
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.notenoi18n(b'v1 and v2 states mismatch: using v1\n')
Pierre-Yves David
debugcommands: move 'debugmergestate' in the new module
r30936 printrecords(1)
if ui.verbose:
printrecords(2)
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @command(b'debugnamecomplete', [], _(b'NAME...'))
Pierre-Yves David
debugcommands: move 'debugnamecomplete' in the new module
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)
Gregory Szorc
py3: finish porting iteritems() to pycompat and remove source transformer...
r43376 for name, ns in pycompat.iteritems(repo.names):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if name != b'branches':
Pierre-Yves David
debugcommands: move 'debugnamecomplete' in the new module
r30937 names.update(ns.listnames(repo))
Augie Fackler
formatting: blacken the codebase...
r43346 names.update(
tag
for (tag, heads, tip, closed) in repo.branchmap().iterbranches()
if not closed
)
Pierre-Yves David
debugcommands: move 'debugnamecomplete' in the new module
r30937 completions = set()
if not args:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 args = [b'']
Pierre-Yves David
debugcommands: move 'debugnamecomplete' in the new module
r30937 for a in args:
completions.update(n for n in names if n.startswith(a))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'\n'.join(sorted(completions)))
ui.write(b'\n')
Pierre-Yves David
debugcommands: move 'debugnamecomplete' in the new module
r30937
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugobsolete',
Augie Fackler
formatting: blacken the codebase...
r43346 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'', b'flags', 0, _(b'markers flag')),
Augie Fackler
formatting: blacken the codebase...
r43346 (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'',
b'record-parents',
Augie Fackler
formatting: blacken the codebase...
r43346 False,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'record parent information for the precursor'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'r', b'rev', [], _(b'display markers relevant to REV')),
Augie Fackler
formatting: blacken the codebase...
r43346 (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'',
b'exclusive',
Augie Fackler
formatting: blacken the codebase...
r43346 False,
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b'restrict display to markers only relevant to REV'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'', b'index', False, _(b'display index of the marker')),
(b'', b'delete', [], _(b'delete markers specified by indices')),
Augie Fackler
formatting: blacken the codebase...
r43346 ]
+ cmdutil.commitopts2
+ cmdutil.formatteropts,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'[OBSOLETED [REPLACEMENT ...]]'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 def debugobsolete(ui, repo, precursor=None, *successors, **opts):
"""create arbitrary obsolete marker
With no arguments, displays the list of obsolescence markers."""
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
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:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'changeset references must be full hexadecimal '
b'node identifiers'
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts.get(b'delete'):
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 indices = []
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 for v in opts.get(b'delete'):
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 try:
indices.append(int(v))
except ValueError:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'invalid index value: %r') % v,
hint=_(b'use integers for indices'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939
if repo.currenttransaction():
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b'cannot delete obsmarkers in the middle of transaction.')
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939
with repo.lock():
n = repair.deleteobsmarkers(repo.obsstore, indices)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(_(b'deleted %i obsolescence markers\n') % n)
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939
return
if precursor is not None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'rev']:
raise error.Abort(b'cannot select revision when creating marker')
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 metadata = {}
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 metadata[b'user'] = encoding.fromlocal(opts[b'user'] or ui.username())
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 succs = tuple(parsenodeid(succ) for succ in successors)
l = repo.lock()
try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 tr = repo.transaction(b'debugobsolete')
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 date = opts.get(b'date')
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 if date:
Boris Feld
util: extract all date-related utils in utils/dateutil module...
r36625 date = dateutil.parsedate(date)
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 else:
date = None
prec = parsenodeid(precursor)
parents = None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'record_parents']:
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 if prec not in repo.unfiltered():
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'cannot used --record-parents on '
b'unknown changesets'
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 parents = repo.unfiltered()[prec].parents()
parents = tuple(p.node() for p in parents)
Augie Fackler
formatting: blacken the codebase...
r43346 repo.obsstore.create(
tr,
prec,
succs,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 opts[b'flags'],
Augie Fackler
formatting: blacken the codebase...
r43346 parents=parents,
date=date,
metadata=metadata,
ui=ui,
)
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 tr.close()
except ValueError as exc:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'bad obsmarker input: %s') % pycompat.bytestr(exc)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 finally:
tr.release()
finally:
l.release()
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'rev']:
revs = scmutil.revrange(repo, opts[b'rev'])
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 nodes = [repo[r].node() for r in revs]
Augie Fackler
formatting: blacken the codebase...
r43346 markers = list(
obsutil.getmarkers(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 repo, nodes=nodes, exclusive=opts[b'exclusive']
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 markers.sort(key=lambda x: x._data)
else:
obsutil: move 'getmarkers' to the new modules...
r33150 markers = obsutil.getmarkers(repo)
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939
markerstoiter = markers
isrelevant = lambda m: True
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts.get(b'rev') and opts.get(b'index'):
obsutil: move 'getmarkers' to the new modules...
r33150 markerstoiter = obsutil.getmarkers(repo)
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 markerset = set(markers)
isrelevant = lambda m: m in markerset
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fm = ui.formatter(b'debugobsolete', opts)
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
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()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ind = i if opts.get(b'index') else None
Pierre-Yves David
debugcommands: move 'debugobsolete' in the new module
r30939 cmdutil.showmarker(fm, m, index=ind)
fm.end()
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugp1copies',
[(b'r', b'rev', b'', _(b'revision to debug'), _(b'REV'))],
_(b'[-r REV]'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Martin von Zweigbergk
context: introduce p[12]copies() methods and debugp[12]copies commands...
r41921 def debugp1copies(ui, repo, **opts):
"""dump copy information compared to p1"""
opts = pycompat.byteskwargs(opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = scmutil.revsingle(repo, opts.get(b'rev'), default=None)
Martin von Zweigbergk
context: introduce p[12]copies() methods and debugp[12]copies commands...
r41921 for dst, src in ctx.p1copies().items():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'%s -> %s\n' % (src, dst))
Martin von Zweigbergk
context: introduce p[12]copies() methods and debugp[12]copies commands...
r41921
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugp2copies',
[(b'r', b'rev', b'', _(b'revision to debug'), _(b'REV'))],
_(b'[-r REV]'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Martin von Zweigbergk
context: introduce p[12]copies() methods and debugp[12]copies commands...
r41921 def debugp1copies(ui, repo, **opts):
"""dump copy information compared to p2"""
opts = pycompat.byteskwargs(opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = scmutil.revsingle(repo, opts.get(b'rev'), default=None)
Martin von Zweigbergk
context: introduce p[12]copies() methods and debugp[12]copies commands...
r41921 for dst, src in ctx.p2copies().items():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'%s -> %s\n' % (src, dst))
Martin von Zweigbergk
context: introduce p[12]copies() methods and debugp[12]copies commands...
r41921
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugpathcomplete',
Augie Fackler
formatting: blacken the codebase...
r43346 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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')),
Augie Fackler
formatting: blacken the codebase...
r43346 ],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'FILESPEC...'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugpathcomplete' in the new module
r30940 def debugpathcomplete(ui, repo, *specs, **opts):
'''complete part or all of a tracked path
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
--full is specified, in which case entire paths are used.'''
def complete(path, acceptable):
dirstate = repo.dirstate
Matt Harbison
py3: rename pycompat.getcwd() to encoding.getcwd() (API)...
r39843 spec = os.path.normpath(os.path.join(encoding.getcwd(), path))
Pierre-Yves David
debugcommands: move 'debugpathcomplete' in the new module
r30940 rootdir = repo.root + pycompat.ossep
if spec != repo.root and not spec.startswith(rootdir):
return [], []
if os.path.isdir(spec):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 spec += b'/'
Augie Fackler
formatting: blacken the codebase...
r43346 spec = spec[len(rootdir) :]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fixpaths = pycompat.ossep != b'/'
Pierre-Yves David
debugcommands: move 'debugpathcomplete' in the new module
r30940 if fixpaths:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 spec = spec.replace(pycompat.ossep, b'/')
Pierre-Yves David
debugcommands: move 'debugpathcomplete' in the new module
r30940 speclen = len(spec)
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 fullpaths = opts[r'full']
Pierre-Yves David
debugcommands: move 'debugpathcomplete' in the new module
r30940 files, dirs = set(), set()
adddir, addfile = dirs.add, files.add
Gregory Szorc
py3: finish porting iteritems() to pycompat and remove source transformer...
r43376 for f, st in pycompat.iteritems(dirstate):
Pierre-Yves David
debugcommands: move 'debugpathcomplete' in the new module
r30940 if f.startswith(spec) and st[0] in acceptable:
if fixpaths:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 f = f.replace(b'/', pycompat.ossep)
Pierre-Yves David
debugcommands: move 'debugpathcomplete' in the new module
r30940 if fullpaths:
addfile(f)
continue
s = f.find(pycompat.ossep, speclen)
if s >= 0:
adddir(f[:s])
else:
addfile(f)
return files, dirs
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 acceptable = b''
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 if opts[r'normal']:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 acceptable += b'nm'
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 if opts[r'added']:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 acceptable += b'a'
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 if opts[r'removed']:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 acceptable += b'r'
Pierre-Yves David
debugcommands: move 'debugpathcomplete' in the new module
r30940 cwd = repo.getcwd()
if not specs:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 specs = [b'.']
Pierre-Yves David
debugcommands: move 'debugpathcomplete' in the new module
r30940
files, dirs = set(), set()
for spec in specs:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 f, d = complete(spec, acceptable or b'nmar')
Pierre-Yves David
debugcommands: move 'debugpathcomplete' in the new module
r30940 files.update(f)
dirs.update(d)
files.update(dirs)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'\n'.join(repo.pathto(p, cwd) for p in sorted(files)))
ui.write(b'\n')
Pierre-Yves David
debugcommands: move 'debugpathcomplete' in the new module
r30940
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugpathcopies',
Augie Fackler
formatting: blacken the codebase...
r43346 cmdutil.walkopts,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'hg debugpathcopies REV1 REV2 [FILE]',
Augie Fackler
formatting: blacken the codebase...
r43346 inferrepo=True,
)
Martin von Zweigbergk
debugcommands: add a debugpathcopies command...
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)
Martin von Zweigbergk
debugpathcopies: sort output so it's deterministic...
r41915 for dst, src in sorted(copies.pathcopies(ctx1, ctx2, m).items()):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'%s -> %s\n' % (src, dst))
@command(b'debugpeer', [], _(b'PATH'), norepo=True)
Gregory Szorc
debugcommands: introduce debugpeer command...
r35947 def debugpeer(ui, path):
"""establish a connection to a peer repository"""
# Always enable peer request logging. Requires --debug to display
# though.
overrides = {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'devel', b'debug.peer-request'): True,
Gregory Szorc
debugcommands: introduce debugpeer command...
r35947 }
with ui.configoverride(overrides):
peer = hg.peer(ui, {}, path)
local = peer.local() is not None
canpush = peer.canpush()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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')))
Gregory Szorc
debugcommands: introduce debugpeer command...
r35947
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugpickmergetool',
Augie Fackler
formatting: blacken the codebase...
r43346 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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')),
Augie Fackler
formatting: blacken the codebase...
r43346 ]
+ cmdutil.walkopts
+ cmdutil.mergetoolopts,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'[PATTERN]...'),
Augie Fackler
formatting: blacken the codebase...
r43346 inferrepo=True,
)
FUJIWARA Katsunori
debugcommands: add debugpickmergetool to examine which merge tool is chosen...
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.
"""
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
FUJIWARA Katsunori
debugcommands: add debugpickmergetool to examine which merge tool is chosen...
r32256 overrides = {}
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'tool']:
overrides[(b'ui', b'forcemerge')] = opts[b'tool']
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.notenoi18n(b'with --tool %r\n' % (pycompat.bytestr(opts[b'tool'])))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347
with ui.configoverride(overrides, b'debugmergepatterns'):
hgmerge = encoding.environ.get(b"HGMERGE")
FUJIWARA Katsunori
debugcommands: add debugpickmergetool to examine which merge tool is chosen...
r32256 if hgmerge is not None:
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.notenoi18n(b'with HGMERGE=%r\n' % (pycompat.bytestr(hgmerge)))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 uimerge = ui.config(b"ui", b"merge")
FUJIWARA Katsunori
debugcommands: add debugpickmergetool to examine which merge tool is chosen...
r32256 if uimerge:
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.notenoi18n(b'with ui.merge=%r\n' % (pycompat.bytestr(uimerge)))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347
ctx = scmutil.revsingle(repo, opts.get(b'rev'))
FUJIWARA Katsunori
debugcommands: add debugpickmergetool to examine which merge tool is chosen...
r32256 m = scmutil.match(ctx, pats, opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 changedelete = opts[b'changedelete']
FUJIWARA Katsunori
debugcommands: add debugpickmergetool to examine which merge tool is chosen...
r32256 for path in ctx.walk(m):
fctx = ctx[path]
try:
if not ui.debugflag:
ui.pushbuffer(error=True)
Augie Fackler
formatting: blacken the codebase...
r43346 tool, toolpath = filemerge._picktool(
repo,
ui,
path,
fctx.isbinary(),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'l' in fctx.flags(),
Augie Fackler
formatting: blacken the codebase...
r43346 changedelete,
)
FUJIWARA Katsunori
debugcommands: add debugpickmergetool to examine which merge tool is chosen...
r32256 finally:
if not ui.debugflag:
ui.popbuffer()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'%s = %s\n' % (path, tool))
@command(b'debugpushkey', [], _(b'REPO NAMESPACE [KEY OLD NEW]'), norepo=True)
Pierre-Yves David
debugcommands: move 'debugpushkey' in the new module
r30946 def debugpushkey(ui, repopath, namespace, *keyinfo, **opts):
'''access the pushkey key/value protocol
With two args, list the keys in the given namespace.
With five args, set a key to new if it currently is set to old.
Reports success or failure.
'''
target = hg.peer(ui, {}, repopath)
if keyinfo:
key, old, new = keyinfo
Gregory Szorc
exchange: use command executor for pushkey...
r37665 with target.commandexecutor() as e:
Augie Fackler
formatting: blacken the codebase...
r43346 r = e.callcommand(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'pushkey',
{
b'namespace': namespace,
b'key': key,
b'old': old,
b'new': new,
},
Augie Fackler
formatting: blacken the codebase...
r43346 ).result()
Gregory Szorc
exchange: use command executor for pushkey...
r37665
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.status(pycompat.bytestr(r) + b'\n')
Pierre-Yves David
debugcommands: move 'debugpushkey' in the new module
r30946 return not r
else:
Gregory Szorc
py3: finish porting iteritems() to pycompat and remove source transformer...
r43376 for k, v in sorted(pycompat.iteritems(target.listkeys(namespace))):
Augie Fackler
formatting: blacken the codebase...
r43346 ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"%s\t%s\n" % (stringutil.escapestr(k), stringutil.escapestr(v))
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugpushkey' in the new module
r30946
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @command(b'debugpvec', [], _(b'A B'))
Pierre-Yves David
debugcommands: move 'debugpvec' in the new module
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:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rel = b"="
Pierre-Yves David
debugcommands: move 'debugpvec' in the new module
r30947 elif pa > pb:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rel = b">"
Pierre-Yves David
debugcommands: move 'debugpvec' in the new module
r30947 elif pa < pb:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 rel = b"<"
Pierre-Yves David
debugcommands: move 'debugpvec' in the new module
r30947 elif pa | pb:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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))
Augie Fackler
formatting: blacken the codebase...
r43346 ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b"delta: %d hdist: %d distance: %d relation: %s\n")
Augie Fackler
formatting: blacken the codebase...
r43346 % (
abs(pa._depth - pb._depth),
pvec._hamming(pa._vec, pb._vec),
pa.distance(pb),
rel,
)
)
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugrebuilddirstate|debugrebuildstate',
Augie Fackler
formatting: blacken the codebase...
r43346 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'r', b'rev', b'', _(b'revision to rebuild to'), _(b'REV')),
Augie Fackler
formatting: blacken the codebase...
r43346 (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'',
b'minimal',
Augie Fackler
formatting: blacken the codebase...
r43346 None,
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'only rebuild files that are inconsistent with '
b'the working copy parent'
Augie Fackler
formatting: blacken the codebase...
r43346 ),
),
Pierre-Yves David
debugcommands: move 'debugrebuilddirstate' in the new module
r30948 ],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'[-r REV]'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugrebuilddirstate' in the new module
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.
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 if opts.get(r'minimal'):
Pierre-Yves David
debugcommands: move 'debugrebuilddirstate' in the new module
r30948 manifestfiles = set(ctx.manifest().keys())
dirstatefiles = set(dirstate)
manifestonly = manifestfiles - dirstatefiles
dsonly = dirstatefiles - manifestfiles
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 dsnotadded = set(f for f in dsonly if dirstate[f] != b'a')
Pierre-Yves David
debugcommands: move 'debugrebuilddirstate' in the new module
r30948 changedfiles = manifestonly | dsnotadded
dirstate.rebuild(ctx.node(), ctx.manifest(), changedfiles)
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @command(b'debugrebuildfncache', [], b'')
Pierre-Yves David
debugcommands: move 'debugrebuildfncache' in the new module
r30949 def debugrebuildfncache(ui, repo):
"""rebuild the fncache file"""
repair.rebuildfncache(ui, repo)
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugrename',
[(b'r', b'rev', b'', _(b'revision to debug'), _(b'REV'))],
_(b'[-r REV] [FILE]...'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Martin von Zweigbergk
debugrename: don't require at least one path...
r41839 def debugrename(ui, repo, *pats, **opts):
Pierre-Yves David
debugcommands: move 'debugrename' in the new module
r30950 """dump rename information"""
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ctx = scmutil.revsingle(repo, opts.get(b'rev'))
Martin von Zweigbergk
debugrename: don't require at least one path...
r41839 m = scmutil.match(ctx, pats, opts)
Pierre-Yves David
debugcommands: move 'debugrename' in the new module
r30950 for abs in ctx.walk(m):
fctx = ctx[abs]
o = fctx.filelog().renamed(fctx.filenode())
Martin von Zweigbergk
debugwalk: avoid match.rel() and use repo.pathto() instead...
r41808 rel = repo.pathto(abs)
Pierre-Yves David
debugcommands: move 'debugrename' in the new module
r30950 if o:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(_(b"%s renamed from %s:%s\n") % (rel, o[0], hex(o[1])))
Pierre-Yves David
debugcommands: move 'debugrename' in the new module
r30950 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(_(b"%s not renamed\n") % rel)
Pierre-Yves David
debugcommands: move 'debugrename' in the new module
r30950
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugrevlog',
cmdutil.debugrevlogopts + [(b'd', b'dump', False, _(b'dump index data'))],
_(b'-c|-m|FILE'),
Augie Fackler
formatting: blacken the codebase...
r43346 optionalrepo=True,
)
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 def debugrevlog(ui, repo, file_=None, **opts):
"""show data and statistics about a revlog"""
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 r = cmdutil.openrevlog(repo, b'debugrevlog', file_, opts)
if opts.get(b"dump"):
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 numrevs = len(r)
Augie Fackler
formatting: blacken the codebase...
r43346 ui.write(
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"# rev p1rev p2rev start end deltastart base p1 p2"
b" rawsize totalsize compression heads chainlen\n"
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 ts = 0
heads = set()
Gregory Szorc
global: use pycompat.xrange()...
r38806 for rev in pycompat.xrange(numrevs):
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
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
Augie Fackler
formatting: blacken the codebase...
r43346 ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"%5d %5d %5d %5d %5d %10d %4d %4d %4d %7d %9d "
b"%11d %5d %8d\n"
Augie Fackler
formatting: blacken the codebase...
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,
)
)
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 return 0
v = r.version
format = v & 0xFFFF
flags = []
gdelta = False
Gregory Szorc
revlog: rename constants (API)...
r32316 if v & revlog.FLAG_INLINE_DATA:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 flags.append(b'inline')
Gregory Szorc
revlog: rename constants (API)...
r32316 if v & revlog.FLAG_GENERALDELTA:
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 gdelta = True
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 flags.append(b'generaldelta')
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 if not flags:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 flags = [b'(none)']
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951
Boris Feld
debugrevlog: document some of the variable used...
r39115 ### tracks merge vs single parent
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 nummerges = 0
Boris Feld
debugrevlog: document some of the variable used...
r39115
### tracks ways the "delta" are build
Boris Feld
debugrevlog: track empty revlog entries...
r39116 # nodelta
numempty = 0
Boris Feld
debugrevlog: display details about empty revision...
r39117 numemptytext = 0
numemptydelta = 0
Boris Feld
debugrevlog: document some of the variable used...
r39115 # full file content
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 numfull = 0
Boris Feld
debugrevlog: include information about intermediate snapshots...
r39187 # intermediate snapshot against a prior snapshot
numsemi = 0
Boris Feld
debugrevlog: display snapshot details per depth...
r39189 # snapshot count per depth
numsnapdepth = collections.defaultdict(lambda: 0)
Boris Feld
debugrevlog: document some of the variable used...
r39115 # delta against previous revision
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 numprev = 0
Boris Feld
debugrevlog: document some of the variable used...
r39115 # delta against first or second parent (not prev)
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 nump1 = 0
nump2 = 0
Boris Feld
debugrevlog: document some of the variable used...
r39115 # delta against neither prev nor parents
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 numother = 0
Boris Feld
debugrevlog: document some of the variable used...
r39115 # delta against prev that are also first or second parent
# (details of `numprev`)
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 nump1prev = 0
nump2prev = 0
Boris Feld
debugrevlog: document some of the variable used...
r39115
# data about delta chain of each revs
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 chainlengths = []
debugrevlog: also display the largest delta chain span...
r33057 chainbases = []
chainspans = []
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951
Boris Feld
debugrevlog: document some of the variable used...
r39115 # data about each revision
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 datasize = [None, 0, 0]
fullsize = [None, 0, 0]
Boris Feld
debugrevlog: include information about intermediate snapshots...
r39187 semisize = [None, 0, 0]
Boris Feld
debugrevlog: display snapshot details per depth...
r39189 # snapshot count per depth
snapsizedepth = collections.defaultdict(lambda: [None, 0, 0])
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
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)
Gregory Szorc
global: use pycompat.xrange()...
r38806 for rev in pycompat.xrange(numrevs):
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
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)
debugrevlog: also display the largest delta chain span...
r33057 chainbases.append(r.start(rev))
chainspans.append(size)
Boris Feld
debugrevlog: track empty revlog entries...
r39116 if size == 0:
numempty += 1
Boris Feld
debugrevlog: display details about empty revision...
r39117 numemptytext += 1
Boris Feld
debugrevlog: track empty revlog entries...
r39116 else:
numfull += 1
Boris Feld
debugrevlog: display snapshot details per depth...
r39189 numsnapdepth[0] += 1
Boris Feld
debugrevlog: track empty revlog entries...
r39116 addsize(size, fullsize)
Boris Feld
debugrevlog: display snapshot details per depth...
r39189 addsize(size, snapsizedepth[0])
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 else:
chainlengths.append(chainlengths[delta] + 1)
debugrevlog: also display the largest delta chain span...
r33057 baseaddr = chainbases[delta]
revaddr = r.start(rev)
chainbases.append(baseaddr)
chainspans.append((revaddr - baseaddr) + size)
Boris Feld
debugrevlog: track empty revlog entries...
r39116 if size == 0:
numempty += 1
Boris Feld
debugrevlog: display details about empty revision...
r39117 numemptydelta += 1
Boris Feld
debugrevlog: include information about intermediate snapshots...
r39187 elif r.issnapshot(rev):
addsize(size, semisize)
numsemi += 1
Boris Feld
debugrevlog: display snapshot details per depth...
r39189 depth = r.snapshotdepth(rev)
numsnapdepth[depth] += 1
addsize(size, snapsizedepth[depth])
Boris Feld
debugrevlog: track empty revlog entries...
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
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 elif delta == p2:
Boris Feld
debugrevlog: track empty revlog entries...
r39116 nump2 += 1
elif delta != nullrev:
numother += 1
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951
# Obtain data on the raw chunks in the revlog.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if util.safehasattr(r, b'_getsegmentforrevs'):
Boris Feld
debugrevlog: fix for non-manifest object...
r39184 segment = r._getsegmentforrevs(rev, rev)[1]
else:
segment = r._revlog._getsegmentforrevs(rev, rev)[1]
Gregory Szorc
revlog: rename _chunkraw to _getsegmentforrevs()...
r32224 if segment:
Pulkit Goyal
py3: pass the memoryview object into bytes() to get the value
r33106 chunktype = bytes(segment[0:1])
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 chunktype = b'empty'
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
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
Boris Feld
debugrevlog: include information about intermediate snapshots...
r39187 for size in (datasize, fullsize, semisize, deltasize):
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 if size[0] is None:
size[0] = 0
Boris Feld
debugrevlog: include information about intermediate snapshots...
r39187 numdeltas = numrevs - numfull - numempty - numsemi
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 numoprev = numprev - nump1prev - nump2prev
totalrawsize = datasize[2]
datasize[2] /= numrevs
fulltotal = fullsize[2]
debugrevlog: fix average size computation for empty data (issue6167)...
r42757 if numfull == 0:
fullsize[2] = 0
else:
fullsize[2] /= numfull
Boris Feld
debugrevlog: include information about intermediate snapshots...
r39187 semitotal = semisize[2]
Boris Feld
debugrevlog: display snapshot details per depth...
r39189 snaptotal = {}
Martin von Zweigbergk
cleanup: some Yoda conditions, this patch removes...
r40065 if numsemi > 0:
Boris Feld
debugrevlog: include information about intermediate snapshots...
r39187 semisize[2] /= numsemi
Boris Feld
debugrevlog: display snapshot details per depth...
r39189 for depth in snapsizedepth:
snaptotal[depth] = snapsizedepth[depth][2]
snapsizedepth[depth][2] /= numsnapdepth[depth]
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 deltatotal = deltasize[2]
Boris Feld
debugrevlog: track empty revlog entries...
r39116 if numdeltas > 0:
deltasize[2] /= numdeltas
Boris Feld
debugrevlog: include information about intermediate snapshots...
r39187 totalsize = fulltotal + semitotal + deltatotal
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 avgchainlen = sum(chainlengths) / numrevs
maxchainlen = max(chainlengths)
debugrevlog: also display the largest delta chain span...
r33057 maxchainspan = max(chainspans)
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 compratio = 1
if totalsize:
compratio = totalrawsize / totalsize
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 basedfmtstr = b'%%%dd\n'
basepcfmtstr = b'%%%dd %s(%%5.2f%%%%)\n'
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951
def dfmtstr(max):
return basedfmtstr % len(str(max))
Augie Fackler
formatting: blacken the codebase...
r43346
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 def pcfmtstr(max, padding=0):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return basepcfmtstr % (len(str(max)), b' ' * padding)
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951
def pcfmt(value, total):
if total:
return (value, 100 * float(value) / total)
else:
return value, 100.0
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'format : %d\n' % format)
ui.writenoi18n(b'flags : %s\n' % b', '.join(flags))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347
ui.write(b'\n')
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 fmt = pcfmtstr(totalsize)
fmt2 = dfmtstr(totalsize)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'revisions : ' + fmt2 % numrevs)
ui.writenoi18n(b' merges : ' + fmt % pcfmt(nummerges, numrevs))
formatting: run black on all file again...
r43364 ui.writenoi18n(
b' normal : ' + fmt % pcfmt(numrevs - nummerges, numrevs)
)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'revisions : ' + fmt2 % numrevs)
ui.writenoi18n(b' empty : ' + fmt % pcfmt(numempty, numrevs))
ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b' text : '
Augie Fackler
formatting: blacken the codebase...
r43346 + fmt % pcfmt(numemptytext, numemptytext + numemptydelta)
)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b' delta : '
Augie Fackler
formatting: blacken the codebase...
r43346 + fmt % pcfmt(numemptydelta, numemptytext + numemptydelta)
)
formatting: run black on all file again...
r43364 ui.writenoi18n(
b' snapshot : ' + fmt % pcfmt(numfull + numsemi, numrevs)
)
Boris Feld
debugrevlog: display snapshot details per depth...
r39189 for depth in sorted(numsnapdepth):
Augie Fackler
formatting: blacken the codebase...
r43346 ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b' lvl-%-3d : ' % depth)
Augie Fackler
formatting: blacken the codebase...
r43346 + fmt % pcfmt(numsnapdepth[depth], numrevs)
)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b' deltas : ' + fmt % pcfmt(numdeltas, numrevs))
ui.writenoi18n(b'revision size : ' + fmt2 % totalsize)
ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b' snapshot : ' + fmt % pcfmt(fulltotal + semitotal, totalsize)
)
Boris Feld
debugrevlog: display snapshot details per depth...
r39189 for depth in sorted(numsnapdepth):
Augie Fackler
formatting: blacken the codebase...
r43346 ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b' lvl-%-3d : ' % depth)
Augie Fackler
formatting: blacken the codebase...
r43346 + fmt % pcfmt(snaptotal[depth], totalsize)
)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b' deltas : ' + fmt % pcfmt(deltatotal, totalsize))
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951
def fmtchunktype(chunktype):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if chunktype == b'empty':
return b' %s : ' % chunktype
Pulkit Goyal
py3: use pycompat.bytestr() to convert str to bytes
r33107 elif chunktype in pycompat.bytestr(string.ascii_letters):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b' 0x%s (%s) : ' % (hex(chunktype), chunktype)
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b' 0x%s : ' % hex(chunktype)
ui.write(b'\n')
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'chunks : ' + fmt2 % numrevs)
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 for chunktype in sorted(chunktypecounts):
ui.write(fmtchunktype(chunktype))
ui.write(fmt % pcfmt(chunktypecounts[chunktype], numrevs))
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'chunks size : ' + fmt2 % totalsize)
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 for chunktype in sorted(chunktypecounts):
ui.write(fmtchunktype(chunktype))
ui.write(fmt % pcfmt(chunktypesizes[chunktype], totalsize))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'\n')
Yuya Nishihara
debugrevlog: align chain length, reach, and compression ratio...
r33062 fmt = dfmtstr(max(avgchainlen, maxchainlen, maxchainspan, compratio))
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
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)
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951
if format > 0:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'\n')
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'uncompressed data size (min/max/avg) : %d / %d / %d\n'
Augie Fackler
formatting: blacken the codebase...
r43346 % tuple(datasize)
)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'full revision size (min/max/avg) : %d / %d / %d\n'
Augie Fackler
formatting: blacken the codebase...
r43346 % tuple(fullsize)
)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'inter-snapshot size (min/max/avg) : %d / %d / %d\n'
Augie Fackler
formatting: blacken the codebase...
r43346 % tuple(semisize)
)
Boris Feld
debugrevlog: display snapshot details per depth...
r39189 for depth in sorted(snapsizedepth):
if depth == 0:
continue
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b' level-%-3d (min/max/avg) : %d / %d / %d\n'
Augie Fackler
formatting: blacken the codebase...
r43346 % ((depth,) + tuple(snapsizedepth[depth]))
)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'delta size (min/max/avg) : %d / %d / %d\n'
Augie Fackler
formatting: blacken the codebase...
r43346 % tuple(deltasize)
)
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951
if numdeltas > 0:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'\n')
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 fmt = pcfmtstr(numdeltas)
fmt2 = pcfmtstr(numdeltas, 4)
formatting: run black on all file again...
r43364 ui.writenoi18n(
b'deltas against prev : ' + fmt % pcfmt(numprev, numdeltas)
)
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 if numprev > 0:
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b' where prev = p1 : ' + fmt2 % pcfmt(nump1prev, numprev)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b' where prev = p2 : ' + fmt2 % pcfmt(nump2prev, numprev)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b' other : ' + fmt2 % pcfmt(numoprev, numprev)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugrevlog' in the new module
r30951 if gdelta:
formatting: run black on all file again...
r43364 ui.writenoi18n(
b'deltas against p1 : ' + fmt % pcfmt(nump1, numdeltas)
)
ui.writenoi18n(
b'deltas against p2 : ' + fmt % pcfmt(nump2, numdeltas)
)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'deltas against other : ' + fmt % pcfmt(numother, numdeltas)
Augie Fackler
formatting: blacken the codebase...
r43346 )
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugrevlogindex',
Augie Fackler
formatting: blacken the codebase...
r43346 cmdutil.debugrevlogopts
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 + [(b'f', b'format', 0, _(b'revlog format'), _(b'FORMAT'))],
_(b'[-f FORMAT] -c|-m|FILE'),
Augie Fackler
formatting: blacken the codebase...
r43346 optionalrepo=True,
)
Gregory Szorc
debugcommands: introduce debugrevlogindex (BC)...
r39318 def debugrevlogindex(ui, repo, file_=None, **opts):
"""dump the contents of a revlog index"""
opts = pycompat.byteskwargs(opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 r = cmdutil.openrevlog(repo, b'debugrevlogindex', file_, opts)
format = opts.get(b'format', 0)
Gregory Szorc
debugcommands: introduce debugrevlogindex (BC)...
r39318 if format not in (0, 1):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b"unknown format %d") % format)
Gregory Szorc
debugcommands: introduce debugrevlogindex (BC)...
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:
Martin von Zweigbergk
debugcommands: add a few more writenoi18n()...
r43386 ui.writenoi18n(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 b" rev offset length linkrev %s %s p2\n"
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 % (b"nodeid".ljust(idlen), b"p1".ljust(idlen))
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: introduce debugrevlogindex (BC)...
r39318 else:
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b" rev linkrev %s %s p2\n"
% (b"nodeid".ljust(idlen), b"p1".ljust(idlen))
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: introduce debugrevlogindex (BC)...
r39318 elif format == 1:
if ui.verbose:
Martin von Zweigbergk
debugcommands: add a few more writenoi18n()...
r43386 ui.writenoi18n(
Augie Fackler
formatting: blacken the codebase...
r43346 (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b" rev flag offset length size link p1"
b" p2 %s\n"
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 % b"nodeid".rjust(idlen)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: introduce debugrevlogindex (BC)...
r39318 else:
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b" rev flag size link p1 p2 %s\n"
% b"nodeid".rjust(idlen)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: introduce debugrevlogindex (BC)...
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:
Augie Fackler
formatting: blacken the codebase...
r43346 ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"% 6d % 9d % 7d % 7d %s %s %s\n"
Augie Fackler
formatting: blacken the codebase...
r43346 % (
i,
r.start(i),
r.length(i),
r.linkrev(i),
shortfn(node),
shortfn(pp[0]),
shortfn(pp[1]),
)
)
Gregory Szorc
debugcommands: introduce debugrevlogindex (BC)...
r39318 else:
Augie Fackler
formatting: blacken the codebase...
r43346 ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"% 6d % 7d %s %s %s\n"
Augie Fackler
formatting: blacken the codebase...
r43346 % (
i,
r.linkrev(i),
shortfn(node),
shortfn(pp[0]),
shortfn(pp[1]),
)
)
Gregory Szorc
debugcommands: introduce debugrevlogindex (BC)...
r39318 elif format == 1:
pr = r.parentrevs(i)
if ui.verbose:
Augie Fackler
formatting: blacken the codebase...
r43346 ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d %s\n"
Augie Fackler
formatting: blacken the codebase...
r43346 % (
i,
r.flags(i),
r.start(i),
r.length(i),
r.rawsize(i),
r.linkrev(i),
pr[0],
pr[1],
shortfn(node),
)
)
Gregory Szorc
debugcommands: introduce debugrevlogindex (BC)...
r39318 else:
Augie Fackler
formatting: blacken the codebase...
r43346 ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"% 6d %04x % 8d % 6d % 6d % 6d %s\n"
Augie Fackler
formatting: blacken the codebase...
r43346 % (
i,
r.flags(i),
r.rawsize(i),
r.linkrev(i),
pr[0],
pr[1],
shortfn(node),
)
)
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugrevspec',
Augie Fackler
formatting: blacken the codebase...
r43346 [
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'',
b'optimize',
Augie Fackler
formatting: blacken the codebase...
r43346 None,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'print parsed tree after optimizing (DEPRECATED)'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'',
b'show-revs',
True,
_(b'print list of result revisions (default)'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b's',
b'show-set',
None,
_(b'print internal representation of result set'),
),
(
b'p',
b'show-stage',
Augie Fackler
formatting: blacken the codebase...
r43346 [],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'print parsed tree at the given stage'),
_(b'NAME'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'', b'no-optimized', False, _(b'evaluate tree without optimization')),
(b'', b'verify-optimized', False, _(b'verify optimized result')),
Augie Fackler
formatting: blacken the codebase...
r43346 ],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'REVSPEC',
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
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.
Yuya Nishihara
debugrevspec: add option to suppress list of computed revisions...
r32796 Use --no-show-revs option with -s or -p to print only the set
representation or the parsed tree respectively.
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 Use --verify-optimized to compare the optimized result with the unoptimized
one. Returns 1 if the optimized result differs.
"""
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 aliases = ui.configitems(b'revsetalias')
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 stages = [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'parsed', lambda tree: tree),
Augie Fackler
formatting: blacken the codebase...
r43346 (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'expanded',
Augie Fackler
formatting: blacken the codebase...
r43346 lambda tree: revsetlang.expandaliases(tree, aliases, ui.warn),
),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'concatenated', revsetlang.foldconcat),
(b'analyzed', revsetlang.analyze),
(b'optimized', revsetlang.optimize),
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 ]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'no_optimized']:
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 stages = stages[:-1]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'verify_optimized'] and opts[b'no_optimized']:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b'cannot use --verify-optimized with --no-optimized')
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 stagenames = set(n for n, f in stages)
showalways = set()
showchanged = set()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if ui.verbose and not opts[b'show_stage']:
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 # show parsed tree by --verbose (deprecated)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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']:
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 showalways.update(stagenames)
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 for n in opts[b'show_stage']:
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 if n not in stagenames:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'invalid stage name: %s') % n)
showalways.update(opts[b'show_stage'])
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952
treebystage = {}
printedtree = None
Martin von Zweigbergk
revset: use revsymbol() for checking if a symbol is valid...
r37368 tree = revsetlang.parse(expr, lookup=revset.lookupfn(repo))
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 for n, f in stages:
treebystage[n] = tree = f(tree)
if n in showalways or (n in showchanged and tree != printedtree):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'show_stage'] or n != b'parsed':
ui.write(b"* %s:\n" % n)
ui.write(revsetlang.prettyformat(tree), b"\n")
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 printedtree = tree
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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):
formatting: run black on all file again...
r43364 ui.writenoi18n(
b"* analyzed set:\n", stringutil.prettyrepr(arevs), b"\n"
)
ui.writenoi18n(
b"* optimized set:\n", stringutil.prettyrepr(brevs), b"\n"
)
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 arevs = list(arevs)
brevs = list(brevs)
if arevs == brevs:
return 0
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'--- analyzed\n', label=b'diff.file_a')
ui.writenoi18n(b'+++ optimized\n', label=b'diff.file_b')
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 sm = difflib.SequenceMatcher(None, arevs, brevs)
for tag, alo, ahi, blo, bhi in sm.get_opcodes():
Gregory Szorc
py3: use raw strings and %d for formatting...
r41820 if tag in (r'delete', r'replace'):
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 for c in arevs[alo:ahi]:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'-%d\n' % c, label=b'diff.deleted')
Gregory Szorc
py3: use raw strings and %d for formatting...
r41820 if tag in (r'insert', r'replace'):
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 for c in brevs[blo:bhi]:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'+%d\n' % c, label=b'diff.inserted')
Gregory Szorc
py3: use raw strings and %d for formatting...
r41820 if tag == r'equal':
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 for c in arevs[alo:ahi]:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b' %d\n' % c)
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 return 1
func = revset.makematcher(tree)
revs = func(repo)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'show_set'] or (opts[b'show_set'] is None and ui.verbose):
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b"* set:\n", stringutil.prettyrepr(revs), b"\n")
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if not opts[b'show_revs']:
Yuya Nishihara
debugrevspec: add option to suppress list of computed revisions...
r32796 return
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952 for c in revs:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b"%d\n" % c)
Pierre-Yves David
debugcommands: move 'debugrevspec' in the new module
r30952
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugserve',
Augie Fackler
formatting: blacken the codebase...
r43346 [
(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'',
b'sshstdio',
Augie Fackler
formatting: blacken the codebase...
r43346 False,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'run an SSH server bound to process handles'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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')),
Augie Fackler
formatting: blacken the codebase...
r43346 ],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'',
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: add debugserve command...
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)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if not opts[b'sshstdio']:
raise error.Abort(_(b'only --sshstdio is currently supported'))
Gregory Szorc
debugcommands: add debugserve command...
r36544
logfh = None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'logiofd'] and opts[b'logiofile']:
raise error.Abort(_(b'cannot use both --logiofd and --logiofile'))
if opts[b'logiofd']:
Gregory Szorc
debugcommands: add debugserve command...
r36544 # Line buffered because output is line based.
Augie Fackler
debugcommands: work around logiofd being a pipe and unseekable...
r38333 try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 logfh = os.fdopen(int(opts[b'logiofd']), r'ab', 1)
Augie Fackler
debugcommands: work around logiofd being a pipe and unseekable...
r38333 except OSError as e:
if e.errno != errno.ESPIPE:
raise
# can't seek a pipe, so `ab` mode fails on py3
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 logfh = os.fdopen(int(opts[b'logiofd']), r'wb', 1)
elif opts[b'logiofile']:
logfh = open(opts[b'logiofile'], b'ab', 1)
Gregory Szorc
debugcommands: add debugserve command...
r36544
s = wireprotoserver.sshserver(ui, repo, logfh=logfh)
s.serve_forever()
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @command(b'debugsetparents', [], _(b'REV1 [REV2]'))
Pierre-Yves David
debugcommands: move 'debugsetparents' in the new module
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.
"""
Martin von Zweigbergk
debugsetparents: avoid using "r1/r2" variable names for nodeids...
r37161 node1 = scmutil.revsingle(repo, rev1).node()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 node2 = scmutil.revsingle(repo, rev2, b'null').node()
Pierre-Yves David
debugcommands: move 'debugsetparents' in the new module
r30953
with repo.wlock():
Martin von Zweigbergk
debugsetparents: avoid using "r1/r2" variable names for nodeids...
r37161 repo.setparents(node1, node2)
Pierre-Yves David
debugcommands: move 'debugsetparents' in the new module
r30953
Augie Fackler
formatting: blacken the codebase...
r43346
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 @command(b'debugsidedata', cmdutil.debugrevlogopts, _(b'-c|-m|FILE REV'))
sidedata: add a debugsidedata command...
r43309 def debugsidedata(ui, repo, file_, rev=None, **opts):
debugsidedata: small doc improvement...
r43406 """dump the side data for a cl/manifest/file revision
Use --verbose to dump the sidedata content."""
sidedata: add a debugsidedata command...
r43309 opts = pycompat.byteskwargs(opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts.get(b'changelog') or opts.get(b'manifest') or opts.get(b'dir'):
sidedata: add a debugsidedata command...
r43309 if rev is not None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.CommandError(b'debugdata', _(b'invalid arguments'))
sidedata: add a debugsidedata command...
r43309 file_, rev = None, file_
elif rev is None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.CommandError(b'debugdata', _(b'invalid arguments'))
r = cmdutil.openstorage(repo, b'debugdata', file_, opts)
sidedata: add a debugsidedata command...
r43309 r = getattr(r, '_revlog', r)
try:
sidedata = r.sidedata(r.lookup(rev))
except KeyError:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'invalid revision identifier %s') % rev)
sidedata: add a debugsidedata command...
r43309 if sidedata:
sidedata = list(sidedata.items())
sidedata.sort()
Martin von Zweigbergk
debugcommands: add a few more writenoi18n()...
r43386 ui.writenoi18n(b'%d sidedata entries\n' % len(sidedata))
sidedata: add a debugsidedata command...
r43309 for key, value in sidedata:
Martin von Zweigbergk
debugcommands: add a few more writenoi18n()...
r43386 ui.writenoi18n(b' entry-%04o size %d\n' % (key, len(value)))
sidedata: add a debugsidedata command...
r43309 if ui.verbose:
Martin von Zweigbergk
debugcommands: add a few more writenoi18n()...
r43386 ui.writenoi18n(b' %s\n' % stringutil.pprint(value))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347
@command(b'debugssl', [], b'[SOURCE]', optionalrepo=True)
Matt Harbison
debug: add a method to check the state of, and built an SSL cert chain...
r33493 def debugssl(ui, repo, source=None, **opts):
'''test a secure connection to a server
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.
'''
Jun Wu
codemod: use pycompat.iswindows...
r34646 if not pycompat.iswindows:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b'certificate chain building is only possible on Windows')
Augie Fackler
formatting: blacken the codebase...
r43346 )
Matt Harbison
debug: add a method to check the state of, and built an SSL cert chain...
r33493
if not source:
Matt Harbison
debugssl: allow a URL to be specified without a local repository...
r34031 if not repo:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"there is no Mercurial repository here, and no "
b"server specified"
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 source = b"default"
Matt Harbison
debug: add a method to check the state of, and built an SSL cert chain...
r33493
source, branches = hg.parseurl(ui.expandpath(source))
url = util.url(source)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 defaultport = {b'https': 443, b'ssh': 22}
Yuya Nishihara
debugssl: convert port number to int (issue5757)...
r35444 if url.scheme in defaultport:
try:
addr = (url.host, int(url.port or defaultport[url.scheme]))
except ValueError:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b"malformed port number in URL"))
Matt Harbison
debug: add a method to check the state of, and built an SSL cert chain...
r33493 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b"only https and ssh connections are supported"))
Matt Harbison
debug: add a method to check the state of, and built an SSL cert chain...
r33493
from . import win32
Augie Fackler
formatting: blacken the codebase...
r43346 s = ssl.wrap_socket(
socket.socket(),
ssl_version=ssl.PROTOCOL_TLS,
cert_reqs=ssl.CERT_NONE,
ca_certs=None,
)
Matt Harbison
debug: add a method to check the state of, and built an SSL cert chain...
r33493
try:
s.connect(addr)
cert = s.getpeercert(True)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.status(_(b'checking the certificate chain for %s\n') % url.host)
Matt Harbison
debug: add a method to check the state of, and built an SSL cert chain...
r33493
complete = win32.checkcertificatechain(cert, build=False)
if not complete:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.status(_(b'certificate chain is incomplete, updating... '))
Matt Harbison
debug: add a method to check the state of, and built an SSL cert chain...
r33493
if not win32.checkcertificatechain(cert):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.status(_(b'failed.\n'))
Matt Harbison
debug: add a method to check the state of, and built an SSL cert chain...
r33493 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.status(_(b'done.\n'))
Matt Harbison
debug: add a method to check the state of, and built an SSL cert chain...
r33493 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.status(_(b'full certificate chain is available\n'))
Matt Harbison
debug: add a method to check the state of, and built an SSL cert chain...
r33493 finally:
s.close()
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugsub',
[(b'r', b'rev', b'', _(b'revision to check'), _(b'REV'))],
_(b'[-r REV] [REV]'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugsub' in the new module
r30955 def debugsub(ui, repo, rev=None):
ctx = scmutil.revsingle(repo, rev, None)
for k, v in sorted(ctx.substate.items()):
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'path %s\n' % k)
ui.writenoi18n(b' source %s\n' % v[0])
ui.writenoi18n(b' revision %s\n' % v[1])
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugsuccessorssets',
[(b'', b'closest', False, _(b'return closest successors sets only'))],
_(b'[REV]'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Boris Feld
obsolete: closest divergent support...
r33274 def debugsuccessorssets(ui, repo, *revs, **opts):
Pierre-Yves David
debugcommands: move 'debugsuccessorssets' in the new module
r30956 """show set of successors for revision
A successors set of changeset A is a consistent group of revisions that
Boris Feld
obsolete: closest divergent support...
r33274 succeed A. It contains non-obsolete changesets only unless closests
successors set is set.
Pierre-Yves David
debugcommands: move 'debugsuccessorssets' in the new module
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 = {}
Gregory Szorc
py3: convert context to bytes instead of str...
r36140 ctx2str = bytes
Pierre-Yves David
debugcommands: move 'debugsuccessorssets' in the new module
r30956 node2str = short
for rev in scmutil.revrange(repo, revs):
ctx = repo[rev]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'%s\n' % ctx2str(ctx))
Augie Fackler
formatting: blacken the codebase...
r43346 for succsset in obsutil.successorssets(
repo, ctx.node(), closest=opts[r'closest'], cache=cache
):
Pierre-Yves David
debugcommands: move 'debugsuccessorssets' in the new module
r30956 if succsset:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b' ')
Pierre-Yves David
debugcommands: move 'debugsuccessorssets' in the new module
r30956 ui.write(node2str(succsset[0]))
for node in succsset[1:]:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b' ')
Pierre-Yves David
debugcommands: move 'debugsuccessorssets' in the new module
r30956 ui.write(node2str(node))
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b'\n')
Pierre-Yves David
debugcommands: move 'debugsuccessorssets' in the new module
r30956
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugtemplate',
Augie Fackler
formatting: blacken the codebase...
r43346 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'r', b'rev', [], _(b'apply template on changesets'), _(b'REV')),
(b'D', b'define', [], _(b'define template keyword'), _(b'KEY=VALUE')),
Augie Fackler
formatting: blacken the codebase...
r43346 ],
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'[-r REV]... [-D KEY=VALUE]... TEMPLATE'),
Augie Fackler
formatting: blacken the codebase...
r43346 optionalrepo=True,
)
Pierre-Yves David
debugcommands: move 'debugtemplate' in the new module
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
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 if opts[r'rev']:
Pierre-Yves David
debugcommands: move 'debugtemplate' in the new module
r30957 if repo is None:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.RepoError(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b'there is no Mercurial repository here (.hg not found)')
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 revs = scmutil.revrange(repo, opts[r'rev'])
Pierre-Yves David
debugcommands: move 'debugtemplate' in the new module
r30957
props = {}
Pulkit Goyal
py3: use r'' to prevent the addition of b'' by transformer...
r33101 for d in opts[r'define']:
Pierre-Yves David
debugcommands: move 'debugtemplate' in the new module
r30957 try:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 k, v = (e.strip() for e in d.split(b'=', 1))
if not k or k == b'ui':
Pierre-Yves David
debugcommands: move 'debugtemplate' in the new module
r30957 raise ValueError
props[k] = v
except ValueError:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'malformed keyword definition: %s') % d)
Pierre-Yves David
debugcommands: move 'debugtemplate' in the new module
r30957
if ui.verbose:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 aliases = ui.configitems(b'templatealias')
Pierre-Yves David
debugcommands: move 'debugtemplate' in the new module
r30957 tree = templater.parse(tmpl)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.note(templater.prettyformat(tree), b'\n')
Pierre-Yves David
debugcommands: move 'debugtemplate' in the new module
r30957 newtree = templater.expandaliases(tree, aliases)
if newtree != tree:
formatting: run black on all file again...
r43364 ui.notenoi18n(
b"* expanded:\n", templater.prettyformat(newtree), b'\n'
)
Pierre-Yves David
debugcommands: move 'debugtemplate' in the new module
r30957
if revs is None:
Yuya Nishihara
templater: move repo, ui and cache to per-engine resources
r35485 tres = formatter.templateresources(ui, repo)
t = formatter.maketemplater(ui, tmpl, resources=tres)
Yuya Nishihara
templater: add function to look up symbols used in template...
r38374 if ui.verbose:
kwds, funcs = t.symbolsuseddefault()
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b"* keywords: %s\n" % b', '.join(sorted(kwds)))
ui.writenoi18n(b"* functions: %s\n" % b', '.join(sorted(funcs)))
Yuya Nishihara
templater: rename .render(mapping) to .renderdefault(mapping) (API)...
r37003 ui.write(t.renderdefault(props))
Pierre-Yves David
debugcommands: move 'debugtemplate' in the new module
r30957 else:
Yuya Nishihara
cmdutil: drop aliases for logcmdutil functions (API)...
r35906 displayer = logcmdutil.maketemplater(ui, repo, tmpl)
Yuya Nishihara
templater: add function to look up symbols used in template...
r38374 if ui.verbose:
kwds, funcs = displayer.t.symbolsuseddefault()
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b"* keywords: %s\n" % b', '.join(sorted(kwds)))
ui.writenoi18n(b"* functions: %s\n" % b', '.join(sorted(funcs)))
Pierre-Yves David
debugcommands: move 'debugtemplate' in the new module
r30957 for r in revs:
Pulkit Goyal
py3: use pycompat.strkwargs() to convert kwargs keys to str
r33102 displayer.show(repo[r], **pycompat.strkwargs(props))
Pierre-Yves David
debugcommands: move 'debugtemplate' in the new module
r30957 displayer.close()
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debuguigetpass',
[(b'p', b'prompt', b'', _(b'prompt text'), _(b'TEXT')),],
_(b'[-p TEXT]'),
Augie Fackler
formatting: blacken the codebase...
r43346 norepo=True,
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 def debuguigetpass(ui, prompt=b''):
Yuya Nishihara
ui: add debug commands to test interactive prompt...
r36810 """show prompt to type password"""
r = ui.getpass(prompt)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'respose: %s\n' % r)
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debuguiprompt',
[(b'p', b'prompt', b'', _(b'prompt text'), _(b'TEXT')),],
_(b'[-p TEXT]'),
Augie Fackler
formatting: blacken the codebase...
r43346 norepo=True,
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 def debuguiprompt(ui, prompt=b''):
Yuya Nishihara
ui: add debug commands to test interactive prompt...
r36810 """show plain prompt"""
r = ui.prompt(prompt)
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'response: %s\n' % r)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347
@command(b'debugupdatecaches', [])
Pierre-Yves David
caches: introduce a 'debugupdatecaches' command...
r32265 def debugupdatecaches(ui, repo, *pats, **opts):
"""warm all known caches in the repository"""
Jun Wu
codemod: simplify nested withs...
r33438 with repo.wlock(), repo.lock():
Boris Feld
debugupdatecache: also warm rev branch cache...
r36970 repo.updatecaches(full=True)
Pierre-Yves David
caches: introduce a 'debugupdatecaches' command...
r32265
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugupgraderepo',
Augie Fackler
formatting: blacken the codebase...
r43346 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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')),
Augie Fackler
formatting: blacken the codebase...
r43346 ],
)
upgrade: add an argument to control manifest upgrade...
r43098 def debugupgraderepo(ui, repo, run=False, optimize=None, backup=True, **opts):
Gregory Szorc
debugcommands: stub for debugupgraderepo command...
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.
upgrade: add an argument to control manifest upgrade...
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
upgrade: add an argument to control changelog upgrade...
r43099 * `--changelog`: optimize the changelog only
* `--no-changelog --no-manifest`: optimize filelogs only
Gregory Szorc
debugcommands: stub for debugupgraderepo command...
r30774 """
Augie Fackler
formatting: blacken the codebase...
r43346 return upgrade.upgraderepo(
ui, repo, run=run, optimize=optimize, backup=backup, **opts
)
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugwalk', cmdutil.walkopts, _(b'[OPTION]... [FILE]...'), inferrepo=True
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pierre-Yves David
debugcommands: move 'debugwalk' in the new module
r30958 def debugwalk(ui, repo, *pats, **opts):
"""show how files match on given patterns"""
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Pierre-Yves David
debugcommands: move 'debugwalk' in the new module
r30958 m = scmutil.match(repo[None], pats, opts)
Yuya Nishihara
debugwalk: show matcher output only if -v/--verbose...
r38281 if ui.verbose:
Augie Fackler
cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n...
r43350 ui.writenoi18n(b'* matcher:\n', stringutil.prettyrepr(m), b'\n')
Augie Fackler
debugcommands: use repo[None].walk instead of repo.walk
r32363 items = list(repo[None].walk(m))
Pierre-Yves David
debugcommands: move 'debugwalk' in the new module
r30958 if not items:
return
f = lambda fn: fn
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if ui.configbool(b'ui', b'slash') and pycompat.ossep != b'/':
Pierre-Yves David
debugcommands: move 'debugwalk' in the new module
r30958 f = lambda fn: util.normpath(fn)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fmt = b'f %%-%ds %%-%ds %%s' % (
Pierre-Yves David
debugcommands: move 'debugwalk' in the new module
r30958 max([len(abs) for abs in items]),
Augie Fackler
formatting: blacken the codebase...
r43346 max([len(repo.pathto(abs)) for abs in items]),
)
Pierre-Yves David
debugcommands: move 'debugwalk' in the new module
r30958 for abs in items:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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'))
av6
debug: add debugwhyunstable that explains instabilities...
r36972 def debugwhyunstable(ui, repo, rev):
"""explain instabilities of a changeset"""
Martin von Zweigbergk
debugwhyunstable: add support for revsets...
r37414 for entry in obsutil.whyunstable(repo, scmutil.revsingle(repo, rev)):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 dnodes = b''
if entry.get(b'divergentnodes'):
Augie Fackler
formatting: blacken the codebase...
r43346 dnodes = (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b' '.join(
b'%s (%s)' % (ctx.hex(), ctx.phasestr())
for ctx in entry[b'divergentnodes']
Augie Fackler
formatting: blacken the codebase...
r43346 )
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 + b' '
Augie Fackler
formatting: blacken the codebase...
r43346 )
ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'%s: %s%s %s\n'
% (entry[b'instability'], dnodes, entry[b'reason'], entry[b'node'])
Augie Fackler
formatting: blacken the codebase...
r43346 )
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugwireargs',
Augie Fackler
formatting: blacken the codebase...
r43346 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (b'', b'three', b'', b'three'),
(b'', b'four', b'', b'four'),
(b'', b'five', b'', b'five'),
Augie Fackler
formatting: blacken the codebase...
r43346 ]
+ cmdutil.remoteopts,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'REPO [OPTIONS]... [ONE [TWO]]'),
Augie Fackler
formatting: blacken the codebase...
r43346 norepo=True,
)
Pierre-Yves David
debugcommands: move 'debugwireargs' in the new module
r30959 def debugwireargs(ui, repopath, *vals, **opts):
Pulkit Goyal
py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes...
r33100 opts = pycompat.byteskwargs(opts)
Pierre-Yves David
debugcommands: move 'debugwireargs' in the new module
r30959 repo = hg.peer(ui, opts, repopath)
Yuya Nishihara
commands: move templates of common command options to cmdutil (API)...
r32375 for opt in cmdutil.remoteopts:
Pierre-Yves David
debugcommands: move 'debugwireargs' in the new module
r30959 del opts[opt[1]]
args = {}
Gregory Szorc
py3: finish porting iteritems() to pycompat and remove source transformer...
r43376 for k, v in pycompat.iteritems(opts):
Pierre-Yves David
debugcommands: move 'debugwireargs' in the new module
r30959 if v:
args[k] = v
Pulkit Goyal
py3: handle keyword arguments correctly in debugcommands.py...
r35402 args = pycompat.strkwargs(args)
Pierre-Yves David
debugcommands: move 'debugwireargs' in the new module
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)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(b"%s\n" % res1)
Pierre-Yves David
debugcommands: move 'debugwireargs' in the new module
r30959 if res1 != res2:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.warn(b"%s\n" % res2)
Gregory Szorc
debugcommands: add debugwireproto command...
r36545
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 def _parsewirelangblocks(fh):
activeaction = None
blocklines = []
Gregory Szorc
debugcommands: support wrapping long lines...
r40210 lastindent = 0
Gregory Szorc
debugcommands: add debugwireproto command...
r36545
for line in fh:
line = line.rstrip()
if not line:
continue
if line.startswith(b'#'):
continue
Augie Fackler
debugcommands: fix a missing b prefix...
r39097 if not line.startswith(b' '):
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 # New block. Flush previous one.
if activeaction:
yield activeaction, blocklines
activeaction = line
blocklines = []
Gregory Szorc
debugcommands: support wrapping long lines...
r40210 lastindent = 0
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 continue
# Else we start with an indent.
if not activeaction:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'indented line outside of block'))
Gregory Szorc
debugcommands: add debugwireproto command...
r36545
Gregory Szorc
debugcommands: support wrapping long lines...
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
Gregory Szorc
debugcommands: add debugwireproto command...
r36545
# Flush last block.
if activeaction:
yield activeaction, blocklines
Augie Fackler
formatting: blacken the codebase...
r43346
@command(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugwireproto',
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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')),
Augie Fackler
formatting: blacken the codebase...
r43346 (
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'',
b'noreadstderr',
Augie Fackler
formatting: blacken the codebase...
r43346 False,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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'),
Augie Fackler
formatting: blacken the codebase...
r43346 ),
]
+ cmdutil.remoteopts,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'[PATH]'),
Augie Fackler
formatting: blacken the codebase...
r43346 optionalrepo=True,
)
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030 def debugwireproto(ui, repo, path=None, **opts):
Gregory Szorc
debugcommands: add debugwireproto command...
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``,
Gregory Szorc
wireproto: crude support for version 2 HTTP peer...
r37501 ``http2``, ``ssh1``, and ``ssh2``. ``raw`` instances only allow sending
raw data payloads and don't support higher-level command actions.
Gregory Szorc
debugcommands: add debugwireproto command...
r36545
Gregory Szorc
debugcommands: support for triggering push protocol...
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.
Gregory Szorc
debugcommands: add debugwireproto command...
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.
Gregory Szorc
debugcommands: allow sending of simple commands with debugwireproto...
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
Gregory Szorc
wireproto: crude support for version 2 HTTP peer...
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.
Gregory Szorc
debugcommands: allow sending of simple commands with debugwireproto...
r36547
Gregory Szorc
debugcommands: support for triggering push protocol...
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.
Gregory Szorc
debugcommands: support for sending "batch" requests...
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.
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
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.
Gregory Szorc
wireproto: define and implement protocol for issuing requests...
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.
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 close
-----
Close the connection to the server.
flush
-----
Flush data written to the server.
readavailable
-------------
Yuya Nishihara
debugwireproto: close the write end before consuming all available data...
r36861 Close the write end of the connection and read all available data from
the server.
Gregory Szorc
debugcommands: add debugwireproto command...
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.
Gregory Szorc
debugcommands: introduce actions to perform deterministic reads...
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.
Gregory Szorc
wireproto: define and implement protocol for issuing requests...
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
Gregory Szorc
wireproto: add streams to frame-based protocol...
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.
Gregory Szorc
wireproto: add request IDs to frames...
r37075
Gregory Szorc
wireproto: define and implement protocol for issuing requests...
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``.
Gregory Szorc
wireproto: add streams to frame-based protocol...
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.
Gregory Szorc
wireproto: syntax for encoding CBOR into frames...
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.
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 """
opts = pycompat.byteskwargs(opts)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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',
):
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'invalid value for --peer'),
hint=_(b'valid values are "raw", "ssh1", and "ssh2"'),
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: add debugwireproto command...
r36545
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if path and opts[b'localssh']:
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 raise error.Abort(_(b'cannot specify --localssh with an explicit path'))
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 if ui.interactive():
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(_(b'(waiting for commands on stdin)\n'))
Gregory Szorc
debugcommands: add debugwireproto command...
r36545
blocks = list(_parsewirelangblocks(ui.fin))
proc = None
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030 stdin = None
stdout = None
stderr = None
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031 opener = None
Gregory Szorc
debugcommands: add debugwireproto command...
r36545
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'localssh']:
Gregory Szorc
debugcommands: add debugwireproto command...
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.
Yuya Nishihara
procutil: bulk-replace function calls to point to new module
r37138 args = procutil.hgcmd() + [
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'-R',
Augie Fackler
formatting: blacken the codebase...
r43346 repo.root,
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'debugserve',
b'--sshstdio',
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 ]
Augie Fackler
formatting: blacken the codebase...
r43346 proc = subprocess.Popen(
pycompat.rapply(procutil.tonativestr, args),
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
bufsize=0,
)
Gregory Szorc
debugcommands: add debugwireproto command...
r36545
stdin = proc.stdin
stdout = proc.stdout
stderr = proc.stderr
# We turn the pipes into observers so we can log I/O.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if ui.verbose or opts[b'peer'] == b'raw':
Augie Fackler
formatting: blacken the codebase...
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
)
Gregory Szorc
debugcommands: add debugwireproto command...
r36545
# --localssh also implies the peer connection settings.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
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'))
Augie Fackler
formatting: blacken the codebase...
r43346 peer = sshpeer.sshv1peer(
ui,
url,
proc,
stdin,
stdout,
stderr,
None,
autoreadstderr=autoreadstderr,
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif opts[b'peer'] == b'ssh2':
ui.write(_(b'creating ssh peer for wire protocol version 2\n'))
Augie Fackler
formatting: blacken the codebase...
r43346 peer = sshpeer.sshv2peer(
ui,
url,
proc,
stdin,
stdout,
stderr,
None,
autoreadstderr=autoreadstderr,
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif opts[b'peer'] == b'raw':
ui.write(_(b'using raw connection to peer\n'))
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 peer = None
else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.write(_(b'creating ssh peer from handshake results\n'))
Augie Fackler
formatting: blacken the codebase...
r43346 peer = sshpeer.makepeer(
ui,
url,
proc,
stdin,
stdout,
stderr,
autoreadstderr=autoreadstderr,
)
Gregory Szorc
debugcommands: add debugwireproto command...
r36545
Gregory Szorc
debugcommands: support connecting to HTTP peers...
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)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if u.scheme != b'http':
raise error.Abort(_(b'only http:// paths are currently supported'))
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030
url, authinfo = u.authinfo()
Gregory Szorc
wireproto: crude support for version 2 HTTP peer...
r37501 openerargs = {
r'useragent': b'Mercurial debugwireproto',
}
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030
# Turn pipes/sockets into observers so we can log I/O.
if ui.verbose:
Augie Fackler
formatting: blacken the codebase...
r43346 openerargs.update(
{
r'loggingfh': ui,
r'loggingname': b's',
r'loggingopts': {r'logdata': True, r'logdataapis': False,},
}
)
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030
Gregory Szorc
util: don't log low-level I/O calls for HTTP peer...
r37062 if ui.debugflag:
openerargs[r'loggingopts'][r'logdataapis'] = True
Gregory Szorc
url: support suppressing Accept header...
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.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'peer'] == b'raw':
Gregory Szorc
url: support suppressing Accept header...
r37063 openerargs[r'sendaccept'] = False
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030 opener = urlmod.opener(ui, authinfo, **openerargs)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'peer'] == b'http2':
ui.write(_(b'creating http peer for wire protocol version 2\n'))
Gregory Szorc
debugcommands: perform handshake when obtaining httpv2 peer...
r37663 # We go through makepeer() because we need an API descriptor for
# the peer instance to be useful.
Augie Fackler
formatting: blacken the codebase...
r43346 with ui.configoverride(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 {(b'experimental', b'httppeer.advertise-v2'): True}
Augie Fackler
formatting: blacken the codebase...
r43346 ):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'nologhandshake']:
Gregory Szorc
debugcommands: ability to suppress logging of handshake...
r37736 ui.pushbuffer()
Gregory Szorc
debugcommands: perform handshake when obtaining httpv2 peer...
r37663 peer = httppeer.makepeer(ui, path, opener=opener)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if opts[b'nologhandshake']:
Gregory Szorc
debugcommands: ability to suppress logging of handshake...
r37736 ui.popbuffer()
Gregory Szorc
debugcommands: perform handshake when obtaining httpv2 peer...
r37663 if not isinstance(peer, httppeer.httpv2peer):
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'could not instantiate HTTP peer for '
b'wire protocol version 2'
Augie Fackler
formatting: blacken the codebase...
r43346 ),
hint=_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'the server may not have the feature '
b'enabled or is not allowing this '
b'client version'
Augie Fackler
formatting: blacken the codebase...
r43346 ),
)
Gregory Szorc
debugcommands: perform handshake when obtaining httpv2 peer...
r37663
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif opts[b'peer'] == b'raw':
ui.write(_(b'using raw connection to peer\n'))
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030 peer = None
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif opts[b'peer']:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'--peer %s not supported with HTTP peers') % opts[b'peer']
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030 else:
Gregory Szorc
httppeer: allow opener to be passed to makepeer()...
r37571 peer = httppeer.makepeer(ui, path, opener=opener)
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030
# We /could/ populate stdin/stdout with sock.makefile()...
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'unsupported connection configuration'))
Gregory Szorc
debugcommands: add debugwireproto command...
r36545
Gregory Szorc
debugcommands: support for sending "batch" requests...
r36548 batchedcommands = None
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 # Now perform actions based on the parsed wire language instructions.
for action, lines in blocks:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if action in (b'raw', b'raw+'):
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030 if not stdin:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'cannot call raw/raw+ on this peer'))
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 # Concatenate the data together.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 data = b''.join(l.lstrip() for l in lines)
Yuya Nishihara
stringutil: bulk-replace call sites to point to new module...
r37102 data = stringutil.unescapestr(data)
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 stdin.write(data)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if action == b'raw+':
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 stdin.flush()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'flush':
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030 if not stdin:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'cannot call flush on this peer'))
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 stdin.flush()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action.startswith(b'command'):
Gregory Szorc
debugcommands: allow sending of simple commands with debugwireproto...
r36547 if not peer:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'cannot send commands unless peer instance '
b'is available'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Gregory Szorc
debugcommands: allow sending of simple commands with debugwireproto...
r36547
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 command = action.split(b' ', 1)[1]
Gregory Szorc
debugcommands: allow sending of simple commands with debugwireproto...
r36547
args = {}
for line in lines:
# We need to allow empty values.
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 fields = line.lstrip().split(b' ', 1)
Gregory Szorc
debugcommands: allow sending of simple commands with debugwireproto...
r36547 if len(fields) == 1:
key = fields[0]
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 value = b''
Gregory Szorc
debugcommands: allow sending of simple commands with debugwireproto...
r36547 else:
key, value = fields
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if value.startswith(b'eval:'):
Gregory Szorc
wireproto: crude support for version 2 HTTP peer...
r37501 value = stringutil.evalpythonliteral(value[5:])
else:
value = stringutil.unescapestr(value)
args[key] = value
Gregory Szorc
debugcommands: allow sending of simple commands with debugwireproto...
r36547
Gregory Szorc
debugcommands: support for sending "batch" requests...
r36548 if batchedcommands is not None:
batchedcommands.append((command, args))
continue
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.status(_(b'sending %s command\n') % command)
if b'PUSHFILE' in args:
with open(args[b'PUSHFILE'], r'rb') as fh:
del args[b'PUSHFILE']
Augie Fackler
formatting: blacken the codebase...
r43346 res, output = peer._callpush(
command, fh, **pycompat.strkwargs(args)
)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 ui.status(_(b'result: %s\n') % stringutil.escapestr(res))
Augie Fackler
formatting: blacken the codebase...
r43346 ui.status(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'remote output: %s\n') % stringutil.escapestr(output)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: support for triggering push protocol...
r36551 else:
Gregory Szorc
debugcommands: use command executor for invoking commands...
r37670 with peer.commandexecutor() as e:
res = e.callcommand(command, args).result()
Gregory Szorc
wireprotov2: establish a type for representing command response...
r37738 if isinstance(res, wireprotov2peer.commandresponse):
Gregory Szorc
wireprotov2peer: stream decoded responses...
r39597 val = res.objects()
Augie Fackler
formatting: blacken the codebase...
r43346 ui.status(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'response: %s\n')
Augie Fackler
formatting: blacken the codebase...
r43346 % stringutil.pprint(val, bprefix=True, indent=2)
)
Gregory Szorc
wireprotov2: establish a type for representing command response...
r37738 else:
Augie Fackler
formatting: blacken the codebase...
r43346 ui.status(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'response: %s\n')
Augie Fackler
formatting: blacken the codebase...
r43346 % stringutil.pprint(res, bprefix=True, indent=2)
)
Gregory Szorc
debugcommands: allow sending of simple commands with debugwireproto...
r36547
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'batchbegin':
Gregory Szorc
debugcommands: support for sending "batch" requests...
r36548 if batchedcommands is not None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'nested batchbegin not allowed'))
Gregory Szorc
debugcommands: support for sending "batch" requests...
r36548
batchedcommands = []
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'batchsubmit':
Gregory Szorc
debugcommands: support for sending "batch" requests...
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.
Augie Fackler
formatting: blacken the codebase...
r43346 ui.status(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'sending batch with %d sub-commands\n')
% len(batchedcommands)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: support for sending "batch" requests...
r36548 for i, chunk in enumerate(peer._submitbatch(batchedcommands)):
Augie Fackler
formatting: blacken the codebase...
r43346 ui.status(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'response #%d: %s\n') % (i, stringutil.escapestr(chunk))
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: support for sending "batch" requests...
r36548
batchedcommands = None
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action.startswith(b'httprequest '):
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031 if not opener:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Martin von Zweigbergk
cleanup: join string literals that are already on one line...
r43387 _(b'cannot use httprequest without an HTTP peer')
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 request = action.split(b' ', 2)
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031 if len(request) != 3:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
_(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'invalid httprequest: expected format is '
b'"httprequest <method> <path>'
Augie Fackler
formatting: blacken the codebase...
r43346 )
)
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031
method, httppath = request[1:]
headers = {}
body = None
Gregory Szorc
wireproto: define and implement protocol for issuing requests...
r37069 frames = []
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031 for line in lines:
line = line.lstrip()
m = re.match(b'^([a-zA-Z0-9_-]+): (.*)$', line)
if m:
Gregory Szorc
py3: convert HTTP request headers to str...
r39991 # Headers need to use native strings.
key = pycompat.strurl(m.group(1))
value = pycompat.strurl(m.group(2))
headers[key] = value
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031 continue
if line.startswith(b'BODYFILE '):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 with open(line.split(b' ', 1), b'rb') as fh:
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031 body = fh.read()
Gregory Szorc
wireproto: define and implement protocol for issuing requests...
r37069 elif line.startswith(b'frame '):
frame = wireprotoframing.makeframefromhumanstring(
Augie Fackler
formatting: blacken the codebase...
r43346 line[len(b'frame ') :]
)
Gregory Szorc
wireproto: define and implement protocol for issuing requests...
r37069
frames.append(frame)
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031 else:
Augie Fackler
formatting: blacken the codebase...
r43346 raise error.Abort(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'unknown argument to httprequest: %s') % line
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031
url = path + httppath
Gregory Szorc
wireproto: define and implement protocol for issuing requests...
r37069
if frames:
body = b''.join(bytes(f) for f in frames)
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031 req = urlmod.urlreq.request(pycompat.strurl(url), body, headers)
Gregory Szorc
wireproto: define permissions-based routing of HTTPv2 wire protocol...
r37065 # urllib.Request insists on using has_data() as a proxy for
# determining the request method. Override that to use our
# explicitly requested method.
Augie Fackler
debugcommands: get_method should always return a sysstr...
r39099 req.get_method = lambda: pycompat.sysstr(method)
Gregory Szorc
wireproto: define permissions-based routing of HTTPv2 wire protocol...
r37065
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031 try:
Gregory Szorc
wireproto: define and implement HTTP handshake to upgrade protocol...
r37575 res = opener.open(req)
body = res.read()
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031 except util.urlerr.urlerror as e:
Augie Fackler
debugcommands: urlerror only has a read() method in Python 2...
r39100 # read() method must be called, but only exists in Python 2
getattr(e, 'read', lambda: None)()
Gregory Szorc
wireproto: define and implement HTTP handshake to upgrade protocol...
r37575 continue
Gregory Szorc
py3: use system strings for HTTP response header comparison...
r39992 ct = res.headers.get(r'Content-Type')
if ct == r'application/mercurial-cbor':
Augie Fackler
formatting: blacken the codebase...
r43346 ui.write(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 _(b'cbor> %s\n')
Augie Fackler
formatting: blacken the codebase...
r43346 % stringutil.pprint(
cborutil.decodeall(body), bprefix=True, indent=2
)
)
Gregory Szorc
debugcommands: support sending HTTP requests with debugwireproto...
r37031
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'close':
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 peer.close()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'readavailable':
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030 if not stdout or not stderr:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(
_(b'readavailable not available on this peer')
)
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030
Yuya Nishihara
debugwireproto: close the write end before consuming all available data...
r36861 stdin.close()
stdout.read()
stderr.read()
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'readline':
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030 if not stdout:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'readline not available on this peer'))
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 stdout.readline()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action == b'ereadline':
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030 if not stderr:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'ereadline not available on this peer'))
Gregory Szorc
debugcommands: introduce actions to perform deterministic reads...
r37025 stderr.readline()
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action.startswith(b'read '):
count = int(action.split(b' ', 1)[1])
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030 if not stdout:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'read not available on this peer'))
Gregory Szorc
debugcommands: introduce actions to perform deterministic reads...
r37025 stdout.read(count)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 elif action.startswith(b'eread '):
count = int(action.split(b' ', 1)[1])
Gregory Szorc
debugcommands: support connecting to HTTP peers...
r37030 if not stderr:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'eread not available on this peer'))
Gregory Szorc
debugcommands: introduce actions to perform deterministic reads...
r37025 stderr.read(count)
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'unknown action: %s') % action)
Gregory Szorc
debugcommands: add debugwireproto command...
r36545
Gregory Szorc
debugcommands: support for sending "batch" requests...
r36548 if batchedcommands is not None:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 raise error.Abort(_(b'unclosed "batchbegin" request'))
Gregory Szorc
debugcommands: support for sending "batch" requests...
r36548
Gregory Szorc
debugcommands: add debugwireproto command...
r36545 if peer:
peer.close()
if proc:
proc.kill()