mercurial/debugcommands.py
author Martin von Zweigbergk <martinvonz@google.com>
Tue, 08 Oct 2019 15:06:18 -0700
changeset 43117 8ff1ecfadcd1
parent 43116 defabf63e969
child 43136 ba5b062a1388
permissions -rw-r--r--
cleanup: join string literals that are already on one line Thanks to Kyle for noticing this and for providing the regular expression to run on the codebase. This patch has been reviewed by the test suite and they approved of it. # skip-blame: fallout from mass reformatting Differential Revision: https://phab.mercurial-scm.org/D7028
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30401
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     1
# debugcommands.py - command processing for debug* commands
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     2
#
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     3
# Copyright 2005-2016 Matt Mackall <mpm@selenic.com>
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     4
#
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     6
# GNU General Public License version 2 or any later version.
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     7
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     8
from __future__ import absolute_import
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
     9
34129
902219a99901 debuginstall: use codecs.lookup() to detect invalid encoding
Yuya Nishihara <yuya@tcha.org>
parents: 34120
diff changeset
    10
import codecs
34025
626a28f30dbd debugcommands: stabilize output of debugbundle by having a custom repr
Augie Fackler <raf@durin42.com>
parents: 33553
diff changeset
    11
import collections
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
    12
import difflib
30938
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
    13
import errno
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
    14
import operator
30525
86ebd2f61c31 debugcommands: move 'debugfsinfo' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30524
diff changeset
    15
import os
30517
a3ec6db36315 debugcommands: move 'debugdiscovery' in the module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30516
diff changeset
    16
import random
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
    17
import re
30938
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
    18
import socket
33493
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
    19
import ssl
36781
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36778
diff changeset
    20
import stat
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
    21
import string
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
    22
import subprocess
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
    23
import sys
30938
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
    24
import time
30401
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    25
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    26
from .i18n import _
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
    27
from .node import (
30526
9c10905f4b48 debugcommands: move 'debuggetbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30525
diff changeset
    28
    bin,
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
    29
    hex,
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
    30
    nullhex,
30528
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
    31
    nullid,
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
    32
    nullrev,
30517
a3ec6db36315 debugcommands: move 'debugdiscovery' in the module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30516
diff changeset
    33
    short,
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
    34
)
43089
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
    35
from .pycompat import (
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
    36
    getattr,
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
    37
    open,
c59eb1560c44 py3: manually import getattr where it is needed
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43085
diff changeset
    38
)
30401
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    39
from . import (
30501
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
    40
    bundle2,
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
    41
    changegroup,
30401
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    42
    cmdutil,
31120
c4e8fa2b1c40 color: move 'debugcolor' into the 'debugcommands' modules
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31074
diff changeset
    43
    color,
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
    44
    context,
41515
7dc160a57025 debugcommands: add a debugpathcopies command
Martin von Zweigbergk <martinvonz@google.com>
parents: 41365
diff changeset
    45
    copies,
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
    46
    dagparser,
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
    47
    encoding,
30401
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    48
    error,
30501
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
    49
    exchange,
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
    50
    extensions,
32256
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
    51
    filemerge,
38805
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38802
diff changeset
    52
    filesetlang,
30957
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
    53
    formatter,
30501
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
    54
    hg,
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
    55
    httppeer,
30517
a3ec6db36315 debugcommands: move 'debugdiscovery' in the module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30516
diff changeset
    56
    localrepo,
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
    57
    lock as lockmod,
35888
c8e2d6ed1f9e cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35730
diff changeset
    58
    logcmdutil,
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
    59
    merge as mergemod,
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
    60
    obsolete,
33142
4f49810a1011 obsutil: move 'successorssets' to the new modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33107
diff changeset
    61
    obsutil,
32745
23734c0e361f debugcommands: issue warning when repo has secret changesets (issue5589)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32694
diff changeset
    62
    phases,
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
    63
    policy,
30947
3c766ca89377 debugcommands: move 'debugpvec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30946
diff changeset
    64
    pvec,
30519
20a42325fdef py3: use pycompat.getcwd() instead of os.getcwd()
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30518
diff changeset
    65
    pycompat,
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32315
diff changeset
    66
    registrar,
30775
513d68a90398 repair: implement requirements checking for upgrades
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30774
diff changeset
    67
    repair,
30401
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    68
    revlog,
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
    69
    revset,
31024
0b8356705de6 revset: split language services to revsetlang module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 30988
diff changeset
    70
    revsetlang,
30401
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    71
    scmutil,
30517
a3ec6db36315 debugcommands: move 'debugdiscovery' in the module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30516
diff changeset
    72
    setdiscovery,
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
    73
    simplemerge,
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
    74
    sshpeer,
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
    75
    sslutil,
30502
6da030496667 debugcommands: move debug{create,apply}streambundleclone to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30501
diff changeset
    76
    streamclone,
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
    77
    templater,
30517
a3ec6db36315 debugcommands: move 'debugdiscovery' in the module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30516
diff changeset
    78
    treediscovery,
31864
70d163b86316 upgrade: extract code in its own module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31689
diff changeset
    79
    upgrade,
35562
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
    80
    url as urlmod,
30516
ef1353c283e3 debugcommands: move 'debugdate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30515
diff changeset
    81
    util,
31239
9cdba6072b97 vfs: use 'vfs' module directly in 'mercurial.debugcommand'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31216
diff changeset
    82
    vfs as vfsmod,
37051
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
    83
    wireprotoframing,
36527
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
    84
    wireprotoserver,
37720
d715a85003c8 wireprotov2: establish a type for representing command response
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37718
diff changeset
    85
    wireprotov2peer,
30401
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    86
)
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37057
diff changeset
    87
from .utils import (
39449
e5eb67dea6e8 debugcommands: use our CBOR decoder
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39378
diff changeset
    88
    cborutil,
42041
3e47d1ec9da5 util: extract compression code in `mercurial.utils.compression`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42035
diff changeset
    89
    compression,
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37057
diff changeset
    90
    dateutil,
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37084
diff changeset
    91
    procutil,
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37057
diff changeset
    92
    stringutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37057
diff changeset
    93
)
30401
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
    94
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
    95
from .revlogutils import deltas as deltautil
39330
655b5b465953 revlog: split functionality related to deltas computation in a new module
Boris Feld <boris.feld@octobus.net>
parents: 39282
diff changeset
    96
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
    97
release = lockmod.release
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
    98
32377
c942c83ac2ec debugcommands: use temporary dict for its command table
Yuya Nishihara <yuya@tcha.org>
parents: 32376
diff changeset
    99
command = registrar.command()
30401
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   100
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   101
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   102
@command(b'debugancestor', [], _(b'[INDEX] REV1 REV2'), optionalrepo=True)
30401
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   103
def debugancestor(ui, repo, *args):
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   104
    """find the ancestor revision of two revisions in a given index"""
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   105
    if len(args) == 3:
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   106
        index, rev1, rev2 = args
39818
24e493ec2229 py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 39760
diff changeset
   107
        r = revlog.revlog(vfsmod.vfs(encoding.getcwd(), audit=False), index)
30401
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   108
        lookup = r.lookup
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   109
    elif len(args) == 2:
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   110
        if not repo:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   111
            raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43116
diff changeset
   112
                _(b'there is no Mercurial repository here (.hg not found)')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   113
            )
30401
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   114
        rev1, rev2 = args
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   115
        r = repo.changelog
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   116
        lookup = repo.lookup
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   117
    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   118
        raise error.Abort(_(b'either two or three arguments required'))
30401
869d660b8669 debugcommands: introduce standalone module for debug commands
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff changeset
   119
    a = r.ancestor(lookup(rev1), lookup(rev2))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   120
    ui.write(b'%d:%s\n' % (r.rev(a), hex(a)))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   121
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   122
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   123
@command(b'debugapplystreamclonebundle', [], b'FILE')
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   124
def debugapplystreamclonebundle(ui, repo, fname):
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   125
    """apply a stream clone bundle file"""
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   126
    f = hg.openpath(ui, fname)
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   127
    gen = exchange.readbundle(ui, f, fname)
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   128
    gen.apply(repo)
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   129
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   130
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   131
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   132
    b'debugbuilddag',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   133
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   134
        (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   135
            b'm',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   136
            b'mergeable-file',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   137
            None,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   138
            _(b'add single file mergeable changes'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   139
        ),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   140
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   141
            b'o',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   142
            b'overwritten-file',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   143
            None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   144
            _(b'add single file all revs overwrite'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   145
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   146
        (b'n', b'new-file', None, _(b'add new file at each rev')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   147
    ],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   148
    _(b'[OPTION]... [TEXT]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   149
)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   150
def debugbuilddag(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   151
    ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   152
    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   153
    text=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   154
    mergeable_file=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   155
    overwritten_file=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   156
    new_file=False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   157
):
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   158
    """builds a repo with a given DAG from scratch in the current empty repo
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   159
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   160
    The description of the DAG is read from stdin if not given on the
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   161
    command line.
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   162
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   163
    Elements:
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   164
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   165
     - "+n" is a linear run of n nodes based on the current default parent
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   166
     - "." is a single node based on the current default parent
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   167
     - "$" resets the default parent to null (implied at the start);
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   168
           otherwise the default parent is always the last node created
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   169
     - "<p" sets the default parent to the backref p
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   170
     - "*p" is a fork at parent p, which is a backref
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   171
     - "*p1/p2" is a merge of parents p1 and p2, which are backrefs
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   172
     - "/p2" is a merge of the preceding node and p2
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   173
     - ":tag" defines a local tag for the preceding node
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   174
     - "@branch" sets the named branch for subsequent nodes
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   175
     - "#...\\n" is a comment up to the end of the line
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   176
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   177
    Whitespace between the above elements is ignored.
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   178
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   179
    A backref is either
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   180
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   181
     - a number n, which references the node curr-n, where curr is the current
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   182
       node, or
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   183
     - the name of a local tag you placed earlier using ":tag", or
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   184
     - empty to denote the default parent.
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   185
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   186
    All string valued-elements are either strictly alphanumeric, or must
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   187
    be enclosed in double quotes ("..."), with "\\" as escape character.
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   188
    """
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   189
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   190
    if text is None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   191
        ui.status(_(b"reading DAG from stdin\n"))
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   192
        text = ui.fin.read()
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   193
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   194
    cl = repo.changelog
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   195
    if len(cl) > 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   196
        raise error.Abort(_(b'repository is not empty'))
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   197
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   198
    # determine number of revs in DAG
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   199
    total = 0
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   200
    for type, data in dagparser.parsedag(text):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   201
        if type == b'n':
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   202
            total += 1
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   203
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   204
    if mergeable_file:
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   205
        linesperrev = 2
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   206
        # make a file with k lines per rev
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   207
        initialmergedlines = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   208
            b'%d' % i for i in pycompat.xrange(0, total * linesperrev)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   209
        ]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   210
        initialmergedlines.append(b"")
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   211
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   212
    tags = []
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   213
    progress = ui.makeprogress(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   214
        _(b'building'), unit=_(b'revisions'), total=total
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   215
    )
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   216
    with progress, repo.wlock(), repo.lock(), repo.transaction(b"builddag"):
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   217
        at = -1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   218
        atbranch = b'default'
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   219
        nodeids = []
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   220
        id = 0
38375
fce1c17493db debugbuilddag: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38355
diff changeset
   221
        progress.update(id)
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   222
        for type, data in dagparser.parsedag(text):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   223
            if type == b'n':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   224
                ui.note((b'node %s\n' % pycompat.bytestr(data)))
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   225
                id, ps = data
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   226
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   227
                files = []
35399
dffc35a5be9f debugbuilddag: create filectx instance in 'filectxfn' callback
Martin von Zweigbergk <martinvonz@google.com>
parents: 35395
diff changeset
   228
                filecontent = {}
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   229
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   230
                p2 = None
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   231
                if mergeable_file:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   232
                    fn = b"mf"
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   233
                    p1 = repo[ps[0]]
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   234
                    if len(ps) > 1:
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   235
                        p2 = repo[ps[1]]
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   236
                        pa = p1.ancestor(p2)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   237
                        base, local, other = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   238
                            x[fn].data() for x in (pa, p1, p2)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   239
                        ]
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   240
                        m3 = simplemerge.Merge3Text(base, local, other)
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   241
                        ml = [l.strip() for l in m3.merge_lines()]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   242
                        ml.append(b"")
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   243
                    elif at > 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   244
                        ml = p1[fn].data().split(b"\n")
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   245
                    else:
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   246
                        ml = initialmergedlines
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   247
                    ml[id * linesperrev] += b" r%i" % id
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   248
                    mergedtext = b"\n".join(ml)
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   249
                    files.append(fn)
35399
dffc35a5be9f debugbuilddag: create filectx instance in 'filectxfn' callback
Martin von Zweigbergk <martinvonz@google.com>
parents: 35395
diff changeset
   250
                    filecontent[fn] = mergedtext
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   251
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   252
                if overwritten_file:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   253
                    fn = b"of"
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   254
                    files.append(fn)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   255
                    filecontent[fn] = b"r%i\n" % id
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   256
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   257
                if new_file:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   258
                    fn = b"nf%i" % id
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   259
                    files.append(fn)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   260
                    filecontent[fn] = b"r%i\n" % id
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   261
                    if len(ps) > 1:
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   262
                        if not p2:
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   263
                            p2 = repo[ps[1]]
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   264
                        for fn in p2:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   265
                            if fn.startswith(b"nf"):
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   266
                                files.append(fn)
35399
dffc35a5be9f debugbuilddag: create filectx instance in 'filectxfn' callback
Martin von Zweigbergk <martinvonz@google.com>
parents: 35395
diff changeset
   267
                                filecontent[fn] = p2[fn].data()
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   268
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   269
                def fctxfn(repo, cx, path):
35399
dffc35a5be9f debugbuilddag: create filectx instance in 'filectxfn' callback
Martin von Zweigbergk <martinvonz@google.com>
parents: 35395
diff changeset
   270
                    if path in filecontent:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   271
                        return context.memfilectx(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   272
                            repo, cx, path, filecontent[path]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   273
                        )
35399
dffc35a5be9f debugbuilddag: create filectx instance in 'filectxfn' callback
Martin von Zweigbergk <martinvonz@google.com>
parents: 35395
diff changeset
   274
                    return None
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   275
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   276
                if len(ps) == 0 or ps[0] < 0:
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   277
                    pars = [None, None]
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   278
                elif len(ps) == 1:
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   279
                    pars = [nodeids[ps[0]], None]
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   280
                else:
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   281
                    pars = [nodeids[p] for p in ps]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   282
                cx = context.memctx(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   283
                    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   284
                    pars,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   285
                    b"r%i" % id,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   286
                    files,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   287
                    fctxfn,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   288
                    date=(id, 0),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   289
                    user=b"debugbuilddag",
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   290
                    extra={b'branch': atbranch},
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   291
                )
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   292
                nodeid = repo.commitctx(cx)
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   293
                nodeids.append(nodeid)
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   294
                at = id
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   295
            elif type == b'l':
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   296
                id, name = data
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   297
                ui.note((b'tag %s\n' % name))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   298
                tags.append(b"%s %s\n" % (hex(repo.changelog.node(id)), name))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   299
            elif type == b'a':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   300
                ui.note((b'branch %s\n' % data))
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   301
                atbranch = data
38375
fce1c17493db debugbuilddag: use progress helper
Martin von Zweigbergk <martinvonz@google.com>
parents: 38355
diff changeset
   302
            progress.update(id)
30402
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   303
945f8229b30d debugcommands: move debugbuilddag
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30401
diff changeset
   304
        if tags:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   305
            repo.vfs.write(b"localtags", b"".join(tags))
30501
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   306
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   307
30501
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   308
def _debugchangegroup(ui, gen, all=None, indent=0, **opts):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   309
    indent_string = b' ' * indent
30501
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   310
    if all:
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   311
        ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   312
            b"%sformat: id, p1, p2, cset, delta base, len(delta)\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   313
            % indent_string
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   314
        )
30501
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   315
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   316
        def showchunks(named):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   317
            ui.write(b"\n%s%s\n" % (indent_string, named))
34292
311f6ccf8f23 debug: update debugbundle to use new deltaiter api
Durham Goode <durham@fb.com>
parents: 34130
diff changeset
   318
            for deltadata in gen.deltaiter():
311f6ccf8f23 debug: update debugbundle to use new deltaiter api
Durham Goode <durham@fb.com>
parents: 34130
diff changeset
   319
                node, p1, p2, cs, deltabase, delta, flags = deltadata
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   320
                ui.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   321
                    b"%s%s %s %s %s %s %d\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   322
                    % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   323
                        indent_string,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   324
                        hex(node),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   325
                        hex(p1),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   326
                        hex(p2),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   327
                        hex(cs),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   328
                        hex(deltabase),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   329
                        len(delta),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   330
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   331
                )
30501
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   332
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   333
        chunkdata = gen.changelogheader()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   334
        showchunks(b"changelog")
30501
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   335
        chunkdata = gen.manifestheader()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   336
        showchunks(b"manifest")
30501
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   337
        for chunkdata in iter(gen.filelogheader, {}):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   338
            fname = chunkdata[b'filename']
30501
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   339
            showchunks(fname)
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   340
    else:
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   341
        if isinstance(gen, bundle2.unbundle20):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   342
            raise error.Abort(_(b'use debugbundle2 for this file'))
30501
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   343
        chunkdata = gen.changelogheader()
34292
311f6ccf8f23 debug: update debugbundle to use new deltaiter api
Durham Goode <durham@fb.com>
parents: 34130
diff changeset
   344
        for deltadata in gen.deltaiter():
311f6ccf8f23 debug: update debugbundle to use new deltaiter api
Durham Goode <durham@fb.com>
parents: 34130
diff changeset
   345
            node, p1, p2, cs, deltabase, delta, flags = deltadata
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   346
            ui.write(b"%s%s\n" % (indent_string, hex(node)))
30501
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   347
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   348
33029
b482d80e041b debugcommands: pass part, not read data, into _debugobsmarker()
Martin von Zweigbergk <martinvonz@google.com>
parents: 33028
diff changeset
   349
def _debugobsmarkers(ui, part, indent=0, **opts):
32517
b62b2b373bce debugbundle: display the content of obsmarkers parts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32457
diff changeset
   350
    """display version and markers contained in 'data'"""
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
   351
    opts = pycompat.byteskwargs(opts)
33029
b482d80e041b debugcommands: pass part, not read data, into _debugobsmarker()
Martin von Zweigbergk <martinvonz@google.com>
parents: 33028
diff changeset
   352
    data = part.read()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   353
    indent_string = b' ' * indent
32517
b62b2b373bce debugbundle: display the content of obsmarkers parts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32457
diff changeset
   354
    try:
b62b2b373bce debugbundle: display the content of obsmarkers parts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32457
diff changeset
   355
        version, markers = obsolete._readmarkers(data)
b62b2b373bce debugbundle: display the content of obsmarkers parts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32457
diff changeset
   356
    except error.UnknownVersion as exc:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   357
        msg = b"%sunsupported version: %s (%d bytes)\n"
32517
b62b2b373bce debugbundle: display the content of obsmarkers parts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32457
diff changeset
   358
        msg %= indent_string, exc.version, len(data)
b62b2b373bce debugbundle: display the content of obsmarkers parts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32457
diff changeset
   359
        ui.write(msg)
b62b2b373bce debugbundle: display the content of obsmarkers parts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32457
diff changeset
   360
    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   361
        msg = b"%sversion: %d (%d bytes)\n"
32517
b62b2b373bce debugbundle: display the content of obsmarkers parts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32457
diff changeset
   362
        msg %= indent_string, version, len(data)
b62b2b373bce debugbundle: display the content of obsmarkers parts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32457
diff changeset
   363
        ui.write(msg)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   364
        fm = ui.formatter(b'debugobsolete', opts)
32517
b62b2b373bce debugbundle: display the content of obsmarkers parts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32457
diff changeset
   365
        for rawmarker in sorted(markers):
33148
4e30168d7939 obsutil: move the 'marker' class to the new modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33142
diff changeset
   366
            m = obsutil.marker(None, rawmarker)
32517
b62b2b373bce debugbundle: display the content of obsmarkers parts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32457
diff changeset
   367
            fm.startitem()
b62b2b373bce debugbundle: display the content of obsmarkers parts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32457
diff changeset
   368
            fm.plain(indent_string)
b62b2b373bce debugbundle: display the content of obsmarkers parts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32457
diff changeset
   369
            cmdutil.showmarker(fm, m)
b62b2b373bce debugbundle: display the content of obsmarkers parts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32457
diff changeset
   370
        fm.end()
b62b2b373bce debugbundle: display the content of obsmarkers parts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 32457
diff changeset
   371
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   372
33031
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 33029
diff changeset
   373
def _debugphaseheads(ui, data, indent=0):
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 33029
diff changeset
   374
    """display version and markers contained in 'data'"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   375
    indent_string = b' ' * indent
34320
12c42bcd4133 phases: move the binary decoding function in the phases module
Boris Feld <boris.feld@octobus.net>
parents: 34292
diff changeset
   376
    headsbyphase = phases.binarydecode(data)
33031
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 33029
diff changeset
   377
    for phase in phases.allphases:
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 33029
diff changeset
   378
        for head in headsbyphase[phase]:
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 33029
diff changeset
   379
            ui.write(indent_string)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   380
            ui.write(b'%s %s\n' % (hex(head), phases.phasenames[phase]))
33031
e8c8d81eb864 bundle: add config option to include phases
Martin von Zweigbergk <martinvonz@google.com>
parents: 33029
diff changeset
   381
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   382
34025
626a28f30dbd debugcommands: stabilize output of debugbundle by having a custom repr
Augie Fackler <raf@durin42.com>
parents: 33553
diff changeset
   383
def _quasirepr(thing):
626a28f30dbd debugcommands: stabilize output of debugbundle by having a custom repr
Augie Fackler <raf@durin42.com>
parents: 33553
diff changeset
   384
    if isinstance(thing, (dict, util.sortdict, collections.OrderedDict)):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   385
        return b'{%s}' % (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   386
            b', '.join(b'%s: %s' % (k, thing[k]) for k in sorted(thing))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   387
        )
34025
626a28f30dbd debugcommands: stabilize output of debugbundle by having a custom repr
Augie Fackler <raf@durin42.com>
parents: 33553
diff changeset
   388
    return pycompat.bytestr(repr(thing))
626a28f30dbd debugcommands: stabilize output of debugbundle by having a custom repr
Augie Fackler <raf@durin42.com>
parents: 33553
diff changeset
   389
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   390
30501
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   391
def _debugbundle2(ui, gen, all=None, **opts):
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   392
    """lists the contents of a bundle2"""
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   393
    if not isinstance(gen, bundle2.unbundle20):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   394
        raise error.Abort(_(b'not a bundle2 file'))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   395
    ui.write((b'Stream params: %s\n' % _quasirepr(gen.params)))
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
   396
    parttypes = opts.get(r'part_type', [])
30501
a87e469201f9 debugcommands: move 'debugbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30402
diff changeset
   397
    for part in gen.iterparts():
32694
3ef319e9505f debugbundle: add --part-type flag to emit only named part types
Danek Duvall <danek.duvall@oracle.com>
parents: 32626
diff changeset
   398
        if parttypes and part.type not in parttypes:
3ef319e9505f debugbundle: add --part-type flag to emit only named part types
Danek Duvall <danek.duvall@oracle.com>
parents: 32626
diff changeset
   399
            continue
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   400
        msg = b'%s -- %s (mandatory: %r)\n'
37841
d618558e4e8b debugbundle: also display if a part is mandatory or advisory
Boris Feld <boris.feld@octobus.net>
parents: 37823
diff changeset
   401
        ui.write((msg % (part.type, _quasirepr(part.params), part.mandatory)))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   402
        if part.type == b'changegroup':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   403
            version = part.params.get(b'version', b'01')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   404
            cg = changegroup.getunbundler(version, part, b'UN')
36951
c92d1d3c58ee debugbundle: do not display detailed part data in --quiet mode
Boris Feld <boris.feld@octobus.net>
parents: 36843
diff changeset
   405
            if not ui.quiet:
c92d1d3c58ee debugbundle: do not display detailed part data in --quiet mode
Boris Feld <boris.feld@octobus.net>
parents: 36843
diff changeset
   406
                _debugchangegroup(ui, cg, all=all, indent=4, **opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   407
        if part.type == b'obsmarkers':
36951
c92d1d3c58ee debugbundle: do not display detailed part data in --quiet mode
Boris Feld <boris.feld@octobus.net>
parents: 36843
diff changeset
   408
            if not ui.quiet:
c92d1d3c58ee debugbundle: do not display detailed part data in --quiet mode
Boris Feld <boris.feld@octobus.net>
parents: 36843
diff changeset
   409
                _debugobsmarkers(ui, part, indent=4, **opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   410
        if part.type == b'phase-heads':
36951
c92d1d3c58ee debugbundle: do not display detailed part data in --quiet mode
Boris Feld <boris.feld@octobus.net>
parents: 36843
diff changeset
   411
            if not ui.quiet:
c92d1d3c58ee debugbundle: do not display detailed part data in --quiet mode
Boris Feld <boris.feld@octobus.net>
parents: 36843
diff changeset
   412
                _debugphaseheads(ui, part, indent=4)
30502
6da030496667 debugcommands: move debug{create,apply}streambundleclone to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30501
diff changeset
   413
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   414
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   415
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   416
    b'debugbundle',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   417
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   418
        (b'a', b'all', None, _(b'show all details')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   419
        (b'', b'part-type', [], _(b'show only the named part type')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   420
        (b'', b'spec', None, _(b'print the bundlespec of the bundle')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   421
    ],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   422
    _(b'FILE'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   423
    norepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   424
)
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   425
def debugbundle(ui, bundlepath, all=None, spec=None, **opts):
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   426
    """lists the contents of a bundle"""
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   427
    with hg.openpath(ui, bundlepath) as f:
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   428
        if spec:
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   429
            spec = exchange.getbundlespec(ui, f)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   430
            ui.write(b'%s\n' % spec)
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   431
            return
30502
6da030496667 debugcommands: move debug{create,apply}streambundleclone to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30501
diff changeset
   432
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   433
        gen = exchange.readbundle(ui, f, bundlepath)
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   434
        if isinstance(gen, bundle2.unbundle20):
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   435
            return _debugbundle2(ui, gen, all=all, **opts)
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   436
        _debugchangegroup(ui, gen, all=all, **opts)
30503
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   437
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   438
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   439
@command(b'debugcapabilities', [], _(b'PATH'), norepo=True)
34959
7ee2d859f720 debug: add a debugcapabilities commands
Boris Feld <boris.feld@octobus.net>
parents: 34645
diff changeset
   440
def debugcapabilities(ui, path, **opts):
7ee2d859f720 debug: add a debugcapabilities commands
Boris Feld <boris.feld@octobus.net>
parents: 34645
diff changeset
   441
    """lists the capabilities of a remote peer"""
35401
cd3392cb5818 py3: handle keyword arguments correctly in debugcommands.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35400
diff changeset
   442
    opts = pycompat.byteskwargs(opts)
34959
7ee2d859f720 debug: add a debugcapabilities commands
Boris Feld <boris.feld@octobus.net>
parents: 34645
diff changeset
   443
    peer = hg.peer(ui, opts, path)
7ee2d859f720 debug: add a debugcapabilities commands
Boris Feld <boris.feld@octobus.net>
parents: 34645
diff changeset
   444
    caps = peer.capabilities()
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   445
    ui.writenoi18n(b'Main capabilities:\n')
34959
7ee2d859f720 debug: add a debugcapabilities commands
Boris Feld <boris.feld@octobus.net>
parents: 34645
diff changeset
   446
    for c in sorted(caps):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   447
        ui.write(b'  %s\n' % c)
34960
762ea8a1f5e7 debug: print parsed bundle2 capabilities with debugcapabilities
Boris Feld <boris.feld@octobus.net>
parents: 34959
diff changeset
   448
    b2caps = bundle2.bundle2caps(peer)
762ea8a1f5e7 debug: print parsed bundle2 capabilities with debugcapabilities
Boris Feld <boris.feld@octobus.net>
parents: 34959
diff changeset
   449
    if b2caps:
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   450
        ui.writenoi18n(b'Bundle2 capabilities:\n')
43106
d783f945a701 py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43094
diff changeset
   451
        for key, values in sorted(pycompat.iteritems(b2caps)):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   452
            ui.write(b'  %s\n' % key)
34960
762ea8a1f5e7 debug: print parsed bundle2 capabilities with debugcapabilities
Boris Feld <boris.feld@octobus.net>
parents: 34959
diff changeset
   453
            for v in values:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   454
                ui.write(b'    %s\n' % v)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   455
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   456
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   457
@command(b'debugcheckstate', [], b'')
30503
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   458
def debugcheckstate(ui, repo):
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   459
    """validate the correctness of the current dirstate"""
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   460
    parent1, parent2 = repo.dirstate.parents()
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   461
    m1 = repo[parent1].manifest()
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   462
    m2 = repo[parent2].manifest()
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   463
    errors = 0
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   464
    for f in repo.dirstate:
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   465
        state = repo.dirstate[f]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   466
        if state in b"nr" and f not in m1:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   467
            ui.warn(_(b"%s in state %s, but not in manifest1\n") % (f, state))
30503
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   468
            errors += 1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   469
        if state in b"a" and f in m1:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   470
            ui.warn(_(b"%s in state %s, but also in manifest1\n") % (f, state))
30503
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   471
            errors += 1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   472
        if state in b"m" and f not in m1 and f not in m2:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   473
            ui.warn(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   474
                _(b"%s in state %s, but not in either manifest\n") % (f, state)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   475
            )
30503
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   476
            errors += 1
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   477
    for f in m1:
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   478
        state = repo.dirstate[f]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   479
        if state not in b"nrm":
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   480
            ui.warn(_(b"%s in manifest1, but listed as state %s") % (f, state))
30503
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   481
            errors += 1
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   482
    if errors:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   483
        error = _(b".hg/dirstate inconsistent with current parent's manifest")
30503
6bfb333a6f2f debugcommands: move 'debugcheckstate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30502
diff changeset
   484
        raise error.Abort(error)
30504
c3bdc27121d1 debugcommands: move 'debugcommands' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30503
diff changeset
   485
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   486
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   487
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   488
    b'debugcolor',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   489
    [(b'', b'style', None, _(b'show all configured styles'))],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   490
    b'hg debugcolor',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   491
)
31120
c4e8fa2b1c40 color: move 'debugcolor' into the 'debugcommands' modules
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31074
diff changeset
   492
def debugcolor(ui, repo, **opts):
c4e8fa2b1c40 color: move 'debugcolor' into the 'debugcommands' modules
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31074
diff changeset
   493
    """show available color, effects or style"""
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   494
    ui.writenoi18n(b'color mode: %s\n' % stringutil.pprint(ui._colormode))
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
   495
    if opts.get(r'style'):
31120
c4e8fa2b1c40 color: move 'debugcolor' into the 'debugcommands' modules
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31074
diff changeset
   496
        return _debugdisplaystyle(ui)
c4e8fa2b1c40 color: move 'debugcolor' into the 'debugcommands' modules
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31074
diff changeset
   497
    else:
c4e8fa2b1c40 color: move 'debugcolor' into the 'debugcommands' modules
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31074
diff changeset
   498
        return _debugdisplaycolor(ui)
c4e8fa2b1c40 color: move 'debugcolor' into the 'debugcommands' modules
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31074
diff changeset
   499
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   500
31120
c4e8fa2b1c40 color: move 'debugcolor' into the 'debugcommands' modules
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31074
diff changeset
   501
def _debugdisplaycolor(ui):
31121
8fc55bbd2235 color: cleanup 'debugcolor' logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31120
diff changeset
   502
    ui = ui.copy()
8fc55bbd2235 color: cleanup 'debugcolor' logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31120
diff changeset
   503
    ui._styles.clear()
31689
57a22f699179 color: stop mutating the default effects map
Matt Harbison <matt_harbison@yahoo.com>
parents: 31634
diff changeset
   504
    for effect in color._activeeffects(ui).keys():
31121
8fc55bbd2235 color: cleanup 'debugcolor' logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31120
diff changeset
   505
        ui._styles[effect] = effect
8fc55bbd2235 color: cleanup 'debugcolor' logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31120
diff changeset
   506
    if ui._terminfoparams:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   507
        for k, v in ui.configitems(b'color'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   508
            if k.startswith(b'color.'):
31121
8fc55bbd2235 color: cleanup 'debugcolor' logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31120
diff changeset
   509
                ui._styles[k] = k[6:]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   510
            elif k.startswith(b'terminfo.'):
31121
8fc55bbd2235 color: cleanup 'debugcolor' logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31120
diff changeset
   511
                ui._styles[k] = k[9:]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   512
    ui.write(_(b'available colors:\n'))
31121
8fc55bbd2235 color: cleanup 'debugcolor' logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31120
diff changeset
   513
    # sort label with a '_' after the other to group '_background' entry.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   514
    items = sorted(ui._styles.items(), key=lambda i: (b'_' in i[0], i[0], i[1]))
31121
8fc55bbd2235 color: cleanup 'debugcolor' logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31120
diff changeset
   515
    for colorname, label in items:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   516
        ui.write(b'%s\n' % colorname, label=label)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   517
31120
c4e8fa2b1c40 color: move 'debugcolor' into the 'debugcommands' modules
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31074
diff changeset
   518
c4e8fa2b1c40 color: move 'debugcolor' into the 'debugcommands' modules
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31074
diff changeset
   519
def _debugdisplaystyle(ui):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   520
    ui.write(_(b'available style:\n'))
37823
0e9ddab2bac2 debugcolor: fix crash by empty styles (issue5856)
Yuya Nishihara <yuya@tcha.org>
parents: 37722
diff changeset
   521
    if not ui._styles:
0e9ddab2bac2 debugcolor: fix crash by empty styles (issue5856)
Yuya Nishihara <yuya@tcha.org>
parents: 37722
diff changeset
   522
        return
31120
c4e8fa2b1c40 color: move 'debugcolor' into the 'debugcommands' modules
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31074
diff changeset
   523
    width = max(len(s) for s in ui._styles)
c4e8fa2b1c40 color: move 'debugcolor' into the 'debugcommands' modules
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31074
diff changeset
   524
    for label, effects in sorted(ui._styles.items()):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   525
        ui.write(b'%s' % label, label=label)
31120
c4e8fa2b1c40 color: move 'debugcolor' into the 'debugcommands' modules
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31074
diff changeset
   526
        if effects:
c4e8fa2b1c40 color: move 'debugcolor' into the 'debugcommands' modules
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31074
diff changeset
   527
            # 50
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   528
            ui.write(b': ')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   529
            ui.write(b' ' * (max(0, width - len(label))))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   530
            ui.write(b', '.join(ui.label(e, e) for e in effects.split()))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   531
        ui.write(b'\n')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   532
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   533
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   534
@command(b'debugcreatestreamclonebundle', [], b'FILE')
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   535
def debugcreatestreamclonebundle(ui, repo, fname):
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   536
    """create a stream clone bundle file
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   537
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   538
    Stream bundles are special bundles that are essentially archives of
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   539
    revlog files. They are commonly used for cloning very quickly.
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   540
    """
32745
23734c0e361f debugcommands: issue warning when repo has secret changesets (issue5589)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32694
diff changeset
   541
    # TODO we may want to turn this into an abort when this functionality
23734c0e361f debugcommands: issue warning when repo has secret changesets (issue5589)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32694
diff changeset
   542
    # is moved into `hg bundle`.
23734c0e361f debugcommands: issue warning when repo has secret changesets (issue5589)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32694
diff changeset
   543
    if phases.hassecret(repo):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   544
        ui.warn(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   545
            _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   546
                b'(warning: stream clone bundle will contain secret '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   547
                b'revisions)\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   548
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   549
        )
32745
23734c0e361f debugcommands: issue warning when repo has secret changesets (issue5589)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32694
diff changeset
   550
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   551
    requirements, gen = streamclone.generatebundlev1(repo)
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   552
    changegroup.writechunks(ui, gen, fname)
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   553
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   554
    ui.write(_(b'bundle requirements: %s\n') % b', '.join(sorted(requirements)))
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   555
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   556
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   557
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   558
    b'debugdag',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   559
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   560
        (b't', b'tags', None, _(b'use tags as labels')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   561
        (b'b', b'branches', None, _(b'annotate with branch names')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   562
        (b'', b'dots', None, _(b'use dots for runs')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   563
        (b's', b'spaces', None, _(b'separate elements by spaces')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   564
    ],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   565
    _(b'[OPTION]... [FILE [REV]...]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   566
    optionalrepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   567
)
30514
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   568
def debugdag(ui, repo, file_=None, *revs, **opts):
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   569
    """format the changelog or an index DAG as a concise textual description
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   570
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   571
    If you pass a revlog index, the revlog's DAG is emitted. If you list
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   572
    revision numbers, they get labeled in the output as rN.
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   573
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   574
    Otherwise, the changelog DAG of the current repo is emitted.
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   575
    """
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
   576
    spaces = opts.get(r'spaces')
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
   577
    dots = opts.get(r'dots')
30514
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   578
    if file_:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   579
        rlog = revlog.revlog(vfsmod.vfs(encoding.getcwd(), audit=False), file_)
30514
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   580
        revs = set((int(r) for r in revs))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   581
30514
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   582
        def events():
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   583
            for r in rlog:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   584
                yield b'n', (r, list(p for p in rlog.parentrevs(r) if p != -1))
30514
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   585
                if r in revs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   586
                    yield b'l', (r, b"r%i" % r)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   587
30514
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   588
    elif repo:
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   589
        cl = repo.changelog
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
   590
        tags = opts.get(r'tags')
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
   591
        branches = opts.get(r'branches')
30514
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   592
        if tags:
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   593
            labels = {}
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   594
            for l, n in repo.tags().items():
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   595
                labels.setdefault(cl.rev(n), []).append(l)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   596
30514
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   597
        def events():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   598
            b = b"default"
30514
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   599
            for r in cl:
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   600
                if branches:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   601
                    newb = cl.read(cl.node(r))[5][b'branch']
30514
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   602
                    if newb != b:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   603
                        yield b'a', newb
30514
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   604
                        b = newb
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   605
                yield b'n', (r, list(p for p in cl.parentrevs(r) if p != -1))
30514
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   606
                if tags:
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   607
                    ls = labels.get(r)
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   608
                    if ls:
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   609
                        for l in ls:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   610
                            yield b'l', (r, l)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   611
30514
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   612
    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   613
        raise error.Abort(_(b'need repo for changelog dag'))
30514
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   614
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   615
    for line in dagparser.dagtextlines(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   616
        events(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   617
        addspaces=spaces,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   618
        wraplabels=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   619
        wrapannotations=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   620
        wrapnonlinear=dots,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   621
        usedots=dots,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   622
        maxlinewidth=70,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   623
    ):
30514
625ccc95fa96 debugcommands: move 'debugdag' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30505
diff changeset
   624
        ui.write(line)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   625
        ui.write(b"\n")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   626
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   627
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   628
@command(b'debugdata', cmdutil.debugrevlogopts, _(b'-c|-m|FILE REV'))
30515
cdd1885d0f2f debugcommands: move 'debugrevlogopts' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30514
diff changeset
   629
def debugdata(ui, repo, file_, rev=None, **opts):
cdd1885d0f2f debugcommands: move 'debugrevlogopts' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30514
diff changeset
   630
    """dump the contents of a data file revision"""
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
   631
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   632
    if opts.get(b'changelog') or opts.get(b'manifest') or opts.get(b'dir'):
30515
cdd1885d0f2f debugcommands: move 'debugrevlogopts' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30514
diff changeset
   633
        if rev is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   634
            raise error.CommandError(b'debugdata', _(b'invalid arguments'))
30515
cdd1885d0f2f debugcommands: move 'debugrevlogopts' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30514
diff changeset
   635
        file_, rev = None, file_
cdd1885d0f2f debugcommands: move 'debugrevlogopts' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30514
diff changeset
   636
    elif rev is None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   637
        raise error.CommandError(b'debugdata', _(b'invalid arguments'))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   638
    r = cmdutil.openstorage(repo, b'debugdata', file_, opts)
30515
cdd1885d0f2f debugcommands: move 'debugrevlogopts' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30514
diff changeset
   639
    try:
42773
127d57e950e0 rawdata: update callers in debugcommands
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42651
diff changeset
   640
        ui.write(r.rawdata(r.lookup(rev)))
30515
cdd1885d0f2f debugcommands: move 'debugrevlogopts' into the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30514
diff changeset
   641
    except KeyError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   642
        raise error.Abort(_(b'invalid revision identifier %s') % rev)
30516
ef1353c283e3 debugcommands: move 'debugdate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30515
diff changeset
   643
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   644
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   645
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   646
    b'debugdate',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   647
    [(b'e', b'extended', None, _(b'try extended date formats'))],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   648
    _(b'[-e] DATE [RANGE]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   649
    norepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   650
    optionalrepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   651
)
30516
ef1353c283e3 debugcommands: move 'debugdate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30515
diff changeset
   652
def debugdate(ui, date, range=None, **opts):
ef1353c283e3 debugcommands: move 'debugdate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30515
diff changeset
   653
    """parse and display a date"""
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
   654
    if opts[r"extended"]:
36607
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36587
diff changeset
   655
        d = dateutil.parsedate(date, util.extendeddateformats)
30516
ef1353c283e3 debugcommands: move 'debugdate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30515
diff changeset
   656
    else:
36607
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36587
diff changeset
   657
        d = dateutil.parsedate(date)
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   658
    ui.writenoi18n(b"internal: %d %d\n" % d)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   659
    ui.writenoi18n(b"standard: %s\n" % dateutil.datestr(d))
30516
ef1353c283e3 debugcommands: move 'debugdate' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30515
diff changeset
   660
    if range:
36607
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36587
diff changeset
   661
        m = dateutil.matchdate(range)
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   662
        ui.writenoi18n(b"match: %s\n" % m(d[0]))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   663
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   664
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   665
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   666
    b'debugdeltachain',
32375
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32371
diff changeset
   667
    cmdutil.debugrevlogopts + cmdutil.formatteropts,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   668
    _(b'-c|-m|FILE'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   669
    optionalrepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   670
)
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   671
def debugdeltachain(ui, repo, file_=None, **opts):
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   672
    """dump information about delta chains in a revlog
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   673
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   674
    Output can be templatized. Available template keywords are:
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   675
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   676
    :``rev``:       revision number
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   677
    :``chainid``:   delta chain identifier (numbered by unique base)
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   678
    :``chainlen``:  delta chain length to this revision
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   679
    :``prevrev``:   previous revision in delta chain
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   680
    :``deltatype``: role of delta / how it was computed
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   681
    :``compsize``:  compressed size of revision
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   682
    :``uncompsize``: uncompressed size of revision
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   683
    :``chainsize``: total size of compressed revisions in chain
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   684
    :``chainratio``: total chain size divided by uncompressed revision size
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   685
                    (new delta chains typically start at ratio 2.00)
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   686
    :``lindist``:   linear distance from base revision in delta chain to end
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   687
                    of this revision
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   688
    :``extradist``: total size of revisions not part of this delta chain from
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   689
                    base of delta chain to end of this revision; a measurement
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   690
                    of how much extra data we need to read/seek across to read
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   691
                    the delta chain for this revision
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   692
    :``extraratio``: extradist divided by chainsize; another representation of
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   693
                    how much unrelated data is needed to load this delta chain
35059
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   694
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   695
    If the repository is configured to use the sparse read, additional keywords
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   696
    are available:
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   697
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   698
    :``readsize``:     total size of data read from the disk for a revision
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   699
                       (sum of the sizes of all the blocks)
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   700
    :``largestblock``: size of the largest block of data read from the disk
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   701
    :``readdensity``:  density of useful bytes in the data read from the disk
35678
43154a76f392 debugdeltachain: display how many chunks would be read in sparse-read mode
Paul Morelle <paul.morelle@octobus.net>
parents: 35585
diff changeset
   702
    :``srchunks``:  in how many data hunks the whole revision would be read
35059
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   703
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   704
    The sparse read can be enabled with experimental.sparse-read = True
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   705
    """
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
   706
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   707
    r = cmdutil.openrevlog(repo, b'debugdeltachain', file_, opts)
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   708
    index = r.index
38115
b17fa9041695 debugdeltachain: r.start and r.length can be retrieved outside the loop
Paul Morelle <paul.morelle@octobus.net>
parents: 37977
diff changeset
   709
    start = r.start
b17fa9041695 debugdeltachain: r.start and r.length can be retrieved outside the loop
Paul Morelle <paul.morelle@octobus.net>
parents: 37977
diff changeset
   710
    length = r.length
32315
67026d65a4fc revlog: rename constants (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32265
diff changeset
   711
    generaldelta = r.version & revlog.FLAG_GENERALDELTA
35059
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   712
    withsparseread = getattr(r, '_withsparseread', False)
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   713
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   714
    def revinfo(rev):
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   715
        e = index[rev]
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   716
        compsize = e[1]
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   717
        uncompsize = e[2]
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   718
        chainsize = 0
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   719
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   720
        if generaldelta:
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   721
            if e[3] == e[5]:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   722
                deltatype = b'p1'
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   723
            elif e[3] == e[6]:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   724
                deltatype = b'p2'
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   725
            elif e[3] == rev - 1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   726
                deltatype = b'prev'
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   727
            elif e[3] == rev:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   728
                deltatype = b'base'
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   729
            else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   730
                deltatype = b'other'
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   731
        else:
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   732
            if e[3] == rev:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   733
                deltatype = b'base'
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   734
            else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   735
                deltatype = b'prev'
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   736
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   737
        chain = r._deltachain(rev)[0]
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   738
        for iterrev in chain:
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   739
            e = index[iterrev]
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   740
            chainsize += e[1]
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   741
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   742
        return compsize, uncompsize, deltatype, chain, chainsize
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   743
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   744
    fm = ui.formatter(b'debugdeltachain', opts)
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   745
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   746
    fm.plain(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   747
        b'    rev  chain# chainlen     prev   delta       '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   748
        b'size    rawsize  chainsize     ratio   lindist extradist '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   749
        b'extraratio'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   750
    )
35059
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   751
    if withsparseread:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   752
        fm.plain(b'   readsize largestblk rddensity srchunks')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   753
    fm.plain(b'\n')
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   754
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   755
    chainbases = {}
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   756
    for rev in r:
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   757
        comp, uncomp, deltatype, chain, chainsize = revinfo(rev)
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   758
        chainbase = chain[0]
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   759
        chainid = chainbases.setdefault(chainbase, len(chainbases) + 1)
35059
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   760
        basestart = start(chainbase)
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   761
        revstart = start(rev)
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   762
        lineardist = revstart + comp - basestart
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   763
        extradist = lineardist - chainsize
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   764
        try:
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   765
            prevrev = chain[-2]
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   766
        except IndexError:
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   767
            prevrev = -1
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   768
38646
93313f66b69b debugdeltachain: avoid division by zero when a chain is empty
Paul Morelle <paul.morelle@octobus.net>
parents: 38612
diff changeset
   769
        if uncomp != 0:
93313f66b69b debugdeltachain: avoid division by zero when a chain is empty
Paul Morelle <paul.morelle@octobus.net>
parents: 38612
diff changeset
   770
            chainratio = float(chainsize) / float(uncomp)
93313f66b69b debugdeltachain: avoid division by zero when a chain is empty
Paul Morelle <paul.morelle@octobus.net>
parents: 38612
diff changeset
   771
        else:
93313f66b69b debugdeltachain: avoid division by zero when a chain is empty
Paul Morelle <paul.morelle@octobus.net>
parents: 38612
diff changeset
   772
            chainratio = chainsize
93313f66b69b debugdeltachain: avoid division by zero when a chain is empty
Paul Morelle <paul.morelle@octobus.net>
parents: 38612
diff changeset
   773
93313f66b69b debugdeltachain: avoid division by zero when a chain is empty
Paul Morelle <paul.morelle@octobus.net>
parents: 38612
diff changeset
   774
        if chainsize != 0:
93313f66b69b debugdeltachain: avoid division by zero when a chain is empty
Paul Morelle <paul.morelle@octobus.net>
parents: 38612
diff changeset
   775
            extraratio = float(extradist) / float(chainsize)
93313f66b69b debugdeltachain: avoid division by zero when a chain is empty
Paul Morelle <paul.morelle@octobus.net>
parents: 38612
diff changeset
   776
        else:
93313f66b69b debugdeltachain: avoid division by zero when a chain is empty
Paul Morelle <paul.morelle@octobus.net>
parents: 38612
diff changeset
   777
            extraratio = extradist
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   778
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   779
        fm.startitem()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   780
        fm.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   781
            b'rev chainid chainlen prevrev deltatype compsize '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   782
            b'uncompsize chainsize chainratio lindist extradist '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   783
            b'extraratio',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   784
            b'%7d %7d %8d %8d %7s %10d %10d %10d %9.5f %9d %9d %10.5f',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   785
            rev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   786
            chainid,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   787
            len(chain),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   788
            prevrev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   789
            deltatype,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   790
            comp,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   791
            uncomp,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   792
            chainsize,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   793
            chainratio,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   794
            lineardist,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   795
            extradist,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   796
            extraratio,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   797
            rev=rev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   798
            chainid=chainid,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   799
            chainlen=len(chain),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   800
            prevrev=prevrev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   801
            deltatype=deltatype,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   802
            compsize=comp,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   803
            uncompsize=uncomp,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   804
            chainsize=chainsize,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   805
            chainratio=chainratio,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   806
            lindist=lineardist,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   807
            extradist=extradist,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   808
            extraratio=extraratio,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   809
        )
35059
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   810
        if withsparseread:
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   811
            readsize = 0
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   812
            largestblock = 0
35728
22a877215ea1 debugdeltachain: cleanup the double call to _slicechunk
Paul Morelle <paul.morelle@octobus.net>
parents: 35678
diff changeset
   813
            srchunks = 0
22a877215ea1 debugdeltachain: cleanup the double call to _slicechunk
Paul Morelle <paul.morelle@octobus.net>
parents: 35678
diff changeset
   814
39330
655b5b465953 revlog: split functionality related to deltas computation in a new module
Boris Feld <boris.feld@octobus.net>
parents: 39282
diff changeset
   815
            for revschunk in deltautil.slicechunk(r, chain):
35728
22a877215ea1 debugdeltachain: cleanup the double call to _slicechunk
Paul Morelle <paul.morelle@octobus.net>
parents: 35678
diff changeset
   816
                srchunks += 1
35059
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   817
                blkend = start(revschunk[-1]) + length(revschunk[-1])
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   818
                blksize = blkend - start(revschunk[0])
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   819
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   820
                readsize += blksize
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   821
                if largestblock < blksize:
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   822
                    largestblock = blksize
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   823
38647
0f4c2c70e26e debugdeltachain: protect against 0 readsize
Boris Feld <boris.feld@octobus.net>
parents: 38646
diff changeset
   824
            if readsize:
0f4c2c70e26e debugdeltachain: protect against 0 readsize
Boris Feld <boris.feld@octobus.net>
parents: 38646
diff changeset
   825
                readdensity = float(chainsize) / float(readsize)
0f4c2c70e26e debugdeltachain: protect against 0 readsize
Boris Feld <boris.feld@octobus.net>
parents: 38646
diff changeset
   826
            else:
0f4c2c70e26e debugdeltachain: protect against 0 readsize
Boris Feld <boris.feld@octobus.net>
parents: 38646
diff changeset
   827
                readdensity = 1
35059
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   828
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   829
            fm.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   830
                b'readsize largestblock readdensity srchunks',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   831
                b' %10d %10d %9.5f %8d',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   832
                readsize,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   833
                largestblock,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   834
                readdensity,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   835
                srchunks,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   836
                readsize=readsize,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   837
                largestblock=largestblock,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   838
                readdensity=readdensity,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   839
                srchunks=srchunks,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   840
            )
35059
5cbbef8d2a57 debugdeltachain: output information about sparse read if enabled
Paul Morelle <paul.morelle@octobus.net>
parents: 34960
diff changeset
   841
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   842
        fm.plain(b'\n')
30541
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   843
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   844
    fm.end()
342d0cb4f446 debugcommands: sort command order
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30529
diff changeset
   845
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   846
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   847
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   848
    b'debugdirstate|debugstate',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   849
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   850
        (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   851
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   852
            b'nodates',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   853
            None,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   854
            _(b'do not display the saved mtime (DEPRECATED)'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   855
        ),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   856
        (b'', b'dates', True, _(b'display the saved mtime')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   857
        (b'', b'datesort', None, _(b'sort by saved mtime')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   858
    ],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   859
    _(b'[OPTION]...'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   860
)
30954
dad968920130 debugcommands: move 'debugstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30953
diff changeset
   861
def debugstate(ui, repo, **opts):
dad968920130 debugcommands: move 'debugstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30953
diff changeset
   862
    """show the contents of the current dirstate"""
dad968920130 debugcommands: move 'debugstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30953
diff changeset
   863
39760
7e99b02768ef debugdirstate: deprecate --nodates in favor of --no-dates
Martin von Zweigbergk <martinvonz@google.com>
parents: 39561
diff changeset
   864
    nodates = not opts[r'dates']
7e99b02768ef debugdirstate: deprecate --nodates in favor of --no-dates
Martin von Zweigbergk <martinvonz@google.com>
parents: 39561
diff changeset
   865
    if opts.get(r'nodates') is not None:
7e99b02768ef debugdirstate: deprecate --nodates in favor of --no-dates
Martin von Zweigbergk <martinvonz@google.com>
parents: 39561
diff changeset
   866
        nodates = True
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
   867
    datesort = opts.get(r'datesort')
30954
dad968920130 debugcommands: move 'debugstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30953
diff changeset
   868
dad968920130 debugcommands: move 'debugstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30953
diff changeset
   869
    if datesort:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   870
        keyfunc = lambda x: (x[1][3], x[0])  # sort by mtime, then by filename
30954
dad968920130 debugcommands: move 'debugstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30953
diff changeset
   871
    else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   872
        keyfunc = None  # sort by filename
43106
d783f945a701 py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43094
diff changeset
   873
    for file_, ent in sorted(pycompat.iteritems(repo.dirstate), key=keyfunc):
30954
dad968920130 debugcommands: move 'debugstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30953
diff changeset
   874
        if ent[3] == -1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   875
            timestr = b'unset               '
30954
dad968920130 debugcommands: move 'debugstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30953
diff changeset
   876
        elif nodates:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   877
            timestr = b'set                 '
30954
dad968920130 debugcommands: move 'debugstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30953
diff changeset
   878
        else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   879
            timestr = time.strftime(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   880
                r"%Y-%m-%d %H:%M:%S ", time.localtime(ent[3])
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   881
            )
35204
d4b108fdf423 py3: use encoding.strtolocal() to convert string to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35151
diff changeset
   882
            timestr = encoding.strtolocal(timestr)
30954
dad968920130 debugcommands: move 'debugstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30953
diff changeset
   883
        if ent[1] & 0o20000:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   884
            mode = b'lnk'
30954
dad968920130 debugcommands: move 'debugstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30953
diff changeset
   885
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   886
            mode = b'%3o' % (ent[1] & 0o777 & ~util.umask)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   887
        ui.write(b"%c %s %10d %s%s\n" % (ent[0], mode, ent[2], timestr, file_))
30954
dad968920130 debugcommands: move 'debugstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30953
diff changeset
   888
    for f in repo.dirstate.copies():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   889
        ui.write(_(b"copy: %s -> %s\n") % (repo.dirstate.copied(f), f))
30954
dad968920130 debugcommands: move 'debugstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30953
diff changeset
   890
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   891
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   892
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   893
    b'debugdiscovery',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   894
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   895
        (b'', b'old', None, _(b'use old-style discovery')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   896
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   897
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   898
            b'nonheads',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   899
            None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   900
            _(b'use old-style discovery with non-heads included'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   901
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   902
        (b'', b'rev', [], b'restrict discovery to this set of revs'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   903
        (b'', b'seed', b'12323', b'specify the random seed use for discovery'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   904
    ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   905
    + cmdutil.remoteopts,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   906
    _(b'[--rev REV] [OTHER]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   907
)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   908
def debugdiscovery(ui, repo, remoteurl=b"default", **opts):
30517
a3ec6db36315 debugcommands: move 'debugdiscovery' in the module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30516
diff changeset
   909
    """runs the changeset discovery protocol in isolation"""
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
   910
    opts = pycompat.byteskwargs(opts)
35417
2105bdd9462a debugdiscovery: drop reference to invalid --branch option
Martin von Zweigbergk <martinvonz@google.com>
parents: 35401
diff changeset
   911
    remoteurl, branches = hg.parseurl(ui.expandpath(remoteurl))
30517
a3ec6db36315 debugcommands: move 'debugdiscovery' in the module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30516
diff changeset
   912
    remote = hg.peer(repo, opts, remoteurl)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   913
    ui.status(_(b'comparing with %s\n') % util.hidepassword(remoteurl))
30517
a3ec6db36315 debugcommands: move 'debugdiscovery' in the module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30516
diff changeset
   914
a3ec6db36315 debugcommands: move 'debugdiscovery' in the module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30516
diff changeset
   915
    # make sure tests are repeatable
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   916
    random.seed(int(opts[b'seed']))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   917
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   918
    if opts.get(b'old'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   919
42031
d31d8c5279c6 debugdiscovery: small internal refactoring
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42030
diff changeset
   920
        def doit(pushedrevs, remoteheads, remote=remote):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   921
            if not util.safehasattr(remote, b'branches'):
30517
a3ec6db36315 debugcommands: move 'debugdiscovery' in the module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30516
diff changeset
   922
                # enable in-client legacy support
a3ec6db36315 debugcommands: move 'debugdiscovery' in the module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30516
diff changeset
   923
                remote = localrepo.locallegacypeer(remote.local())
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   924
            common, _in, hds = treediscovery.findcommonincoming(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   925
                repo, remote, force=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   926
            )
30517
a3ec6db36315 debugcommands: move 'debugdiscovery' in the module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30516
diff changeset
   927
            common = set(common)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   928
            if not opts.get(b'nonheads'):
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   929
                ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   930
                    b"unpruned common: %s\n"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   931
                    % b" ".join(sorted(short(n) for n in common))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   932
                )
39163
26f3d075f36e debugcommands: use a revset instead of dagutil
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39161
diff changeset
   933
26f3d075f36e debugcommands: use a revset instead of dagutil
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39161
diff changeset
   934
                clnode = repo.changelog.node
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   935
                common = repo.revs(b'heads(::%ln)', common)
39163
26f3d075f36e debugcommands: use a revset instead of dagutil
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39161
diff changeset
   936
                common = {clnode(r) for r in common}
42031
d31d8c5279c6 debugdiscovery: small internal refactoring
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42030
diff changeset
   937
            return common, hds
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   938
42031
d31d8c5279c6 debugdiscovery: small internal refactoring
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42030
diff changeset
   939
    else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   940
42031
d31d8c5279c6 debugdiscovery: small internal refactoring
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42030
diff changeset
   941
        def doit(pushedrevs, remoteheads, remote=remote):
35304
f77121b6bf1b setdiscover: allow to ignore part of the local graph
Boris Feld <boris.feld@octobus.net>
parents: 35204
diff changeset
   942
            nodes = None
f77121b6bf1b setdiscover: allow to ignore part of the local graph
Boris Feld <boris.feld@octobus.net>
parents: 35204
diff changeset
   943
            if pushedrevs:
f77121b6bf1b setdiscover: allow to ignore part of the local graph
Boris Feld <boris.feld@octobus.net>
parents: 35204
diff changeset
   944
                revs = scmutil.revrange(repo, pushedrevs)
f77121b6bf1b setdiscover: allow to ignore part of the local graph
Boris Feld <boris.feld@octobus.net>
parents: 35204
diff changeset
   945
                nodes = [repo[r].node() for r in revs]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   946
            common, any, hds = setdiscovery.findcommonheads(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   947
                ui, repo, remote, ancestorsof=nodes
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   948
            )
42031
d31d8c5279c6 debugdiscovery: small internal refactoring
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42030
diff changeset
   949
            return common, hds
30517
a3ec6db36315 debugcommands: move 'debugdiscovery' in the module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30516
diff changeset
   950
35419
fed2c040764e debugdiscovery: drop reference to non-existent --remote-head option
Martin von Zweigbergk <martinvonz@google.com>
parents: 35418
diff changeset
   951
    remoterevs, _checkout = hg.addbranchrevs(repo, remote, branches, revs=None)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   952
    localrevs = opts[b'rev']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   953
    with util.timedcm(b'debug-discovery') as t:
42035
eec20025ada3 debugdiscovery: display time elapsed during the discovery step
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42034
diff changeset
   954
        common, hds = doit(localrevs, remoterevs)
42031
d31d8c5279c6 debugdiscovery: small internal refactoring
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42030
diff changeset
   955
42032
63165e4a76da debugdiscovery: display more statistic about the common set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42031
diff changeset
   956
    # compute all statistics
42031
d31d8c5279c6 debugdiscovery: small internal refactoring
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42030
diff changeset
   957
    common = set(common)
d31d8c5279c6 debugdiscovery: small internal refactoring
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42030
diff changeset
   958
    rheads = set(hds)
d31d8c5279c6 debugdiscovery: small internal refactoring
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42030
diff changeset
   959
    lheads = set(repo.heads())
42032
63165e4a76da debugdiscovery: display more statistic about the common set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42031
diff changeset
   960
63165e4a76da debugdiscovery: display more statistic about the common set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42031
diff changeset
   961
    data = {}
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   962
    data[b'elapsed'] = t.elapsed
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   963
    data[b'nb-common'] = len(common)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   964
    data[b'nb-common-local'] = len(common & lheads)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   965
    data[b'nb-common-remote'] = len(common & rheads)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   966
    data[b'nb-common-both'] = len(common & rheads & lheads)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   967
    data[b'nb-local'] = len(lheads)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   968
    data[b'nb-local-missing'] = data[b'nb-local'] - data[b'nb-common-local']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   969
    data[b'nb-remote'] = len(rheads)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   970
    data[b'nb-remote-unknown'] = data[b'nb-remote'] - data[b'nb-common-remote']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   971
    data[b'nb-revs'] = len(repo.revs(b'all()'))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   972
    data[b'nb-revs-common'] = len(repo.revs(b'::%ln', common))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   973
    data[b'nb-revs-missing'] = data[b'nb-revs'] - data[b'nb-revs-common']
42032
63165e4a76da debugdiscovery: display more statistic about the common set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42031
diff changeset
   974
63165e4a76da debugdiscovery: display more statistic about the common set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42031
diff changeset
   975
    # display discovery summary
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   976
    ui.writenoi18n(b"elapsed time:  %(elapsed)f seconds\n" % data)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   977
    ui.writenoi18n(b"heads summary:\n")
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   978
    ui.writenoi18n(b"  total common heads:  %(nb-common)9d\n" % data)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   979
    ui.writenoi18n(b"    also local heads:  %(nb-common-local)9d\n" % data)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   980
    ui.writenoi18n(b"    also remote heads: %(nb-common-remote)9d\n" % data)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   981
    ui.writenoi18n(b"    both:              %(nb-common-both)9d\n" % data)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   982
    ui.writenoi18n(b"  local heads:         %(nb-local)9d\n" % data)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   983
    ui.writenoi18n(b"    common:            %(nb-common-local)9d\n" % data)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   984
    ui.writenoi18n(b"    missing:           %(nb-local-missing)9d\n" % data)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   985
    ui.writenoi18n(b"  remote heads:        %(nb-remote)9d\n" % data)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   986
    ui.writenoi18n(b"    common:            %(nb-common-remote)9d\n" % data)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   987
    ui.writenoi18n(b"    unknown:           %(nb-remote-unknown)9d\n" % data)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   988
    ui.writenoi18n(b"local changesets:      %(nb-revs)9d\n" % data)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   989
    ui.writenoi18n(b"  common:              %(nb-revs-common)9d\n" % data)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   990
    ui.writenoi18n(b"  missing:             %(nb-revs-missing)9d\n" % data)
42032
63165e4a76da debugdiscovery: display more statistic about the common set
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42031
diff changeset
   991
42034
fd8d13ea1bcc debugdiscovery: only list common heads on verbose
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42033
diff changeset
   992
    if ui.verbose:
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
   993
        ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   994
            b"common heads: %s\n" % b" ".join(sorted(short(n) for n in common))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   995
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
   996
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
   997
35562
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
   998
_chunksize = 4 << 10
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
   999
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1000
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1001
@command(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1002
    b'debugdownload', [(b'o', b'output', b'', _(b'path')),], optionalrepo=True
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1003
)
35730
05d415790761 debugdownload: read repository hgrc if there is one
Boris Feld <boris.feld@octobus.net>
parents: 35728
diff changeset
  1004
def debugdownload(ui, repo, url, output=None, **opts):
35562
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
  1005
    """download a resource using Mercurial logic and config
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
  1006
    """
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
  1007
    fh = urlmod.open(ui, url, output)
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
  1008
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
  1009
    dest = ui
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
  1010
    if output:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1011
        dest = open(output, b"wb", _chunksize)
35562
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
  1012
    try:
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
  1013
        data = fh.read(_chunksize)
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
  1014
        while data:
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
  1015
            dest.write(data)
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
  1016
            data = fh.read(_chunksize)
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
  1017
    finally:
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
  1018
        if output:
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
  1019
            dest.close()
6580cf751418 debug: add a 'debugdownload' command
Boris Feld <boris.feld@octobus.net>
parents: 35514
diff changeset
  1020
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1021
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1022
@command(b'debugextensions', cmdutil.formatteropts, [], optionalrepo=True)
37977
8ba0344f9fb1 debugextensions: process extensions loaded from the local repository too
Matt Harbison <matt_harbison@yahoo.com>
parents: 37942
diff changeset
  1023
def debugextensions(ui, repo, **opts):
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1024
    '''show information about active extensions'''
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
  1025
    opts = pycompat.byteskwargs(opts)
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1026
    exts = extensions.extensions(ui)
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1027
    hgver = util.version()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1028
    fm = ui.formatter(b'debugextensions', opts)
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1029
    for extname, extmod in sorted(exts, key=operator.itemgetter(0)):
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1030
        isinternal = extensions.ismoduleinternal(extmod)
31074
2912b06905dc py3: use pycompat.fsencode() to convert __file__ to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 31024
diff changeset
  1031
        extsource = pycompat.fsencode(extmod.__file__)
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1032
        if isinternal:
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1033
            exttestedwith = []  # never expose magic string to users
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1034
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1035
            exttestedwith = getattr(extmod, 'testedwith', b'').split()
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1036
        extbuglink = getattr(extmod, 'buglink', None)
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1037
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1038
        fm.startitem()
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1039
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1040
        if ui.quiet or ui.verbose:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1041
            fm.write(b'name', b'%s\n', extname)
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1042
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1043
            fm.write(b'name', b'%s', extname)
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1044
            if isinternal or hgver in exttestedwith:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1045
                fm.plain(b'\n')
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1046
            elif not exttestedwith:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1047
                fm.plain(_(b' (untested!)\n'))
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1048
            else:
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1049
                lasttestedversion = exttestedwith[-1]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1050
                fm.plain(b' (%s!)\n' % lasttestedversion)
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1051
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1052
        fm.condwrite(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1053
            ui.verbose and extsource,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1054
            b'source',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1055
            _(b'  location: %s\n'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1056
            extsource or b"",
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1057
        )
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1058
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1059
        if ui.verbose:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1060
            fm.plain(_(b'  bundled: %s\n') % [b'no', b'yes'][isinternal])
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1061
        fm.data(bundled=isinternal)
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1062
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1063
        fm.condwrite(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1064
            ui.verbose and exttestedwith,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1065
            b'testedwith',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1066
            _(b'  tested with: %s\n'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1067
            fm.formatlist(exttestedwith, name=b'ver'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1068
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1069
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1070
        fm.condwrite(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1071
            ui.verbose and extbuglink,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1072
            b'buglink',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1073
            _(b'  bug reporting: %s\n'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1074
            extbuglink or b"",
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1075
        )
30518
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1076
a8b17859684a debugcommands: move 'debugextensions' to the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30517
diff changeset
  1077
    fm.end()
30524
1ee358c3ed26 debugcommands: move 'debugfileset' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30519
diff changeset
  1078
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1079
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1080
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1081
    b'debugfileset',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1082
    [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1083
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1084
            b'r',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1085
            b'rev',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1086
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1087
            _(b'apply the filespec on this revision'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1088
            _(b'REV'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1089
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1090
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1091
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1092
            b'all-files',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1093
            False,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1094
            _(b'test files from all revisions and working directory'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1095
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1096
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1097
            b's',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1098
            b'show-matcher',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1099
            None,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1100
            _(b'print internal representation of matcher'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1101
        ),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1102
        (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1103
            b'p',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1104
            b'show-stage',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1105
            [],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1106
            _(b'print parsed tree at the given stage'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1107
            _(b'NAME'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1108
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1109
    ],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1110
    _(b'[-r REV] [--all-files] [OPTION]... FILESPEC'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1111
)
30524
1ee358c3ed26 debugcommands: move 'debugfileset' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30519
diff changeset
  1112
def debugfileset(ui, repo, expr, **opts):
1ee358c3ed26 debugcommands: move 'debugfileset' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30519
diff changeset
  1113
    '''parse and apply a fileset specification'''
38972
4d992e3f10ba debugcommands: force import of fileset in debugfileset
Augie Fackler <augie@google.com>
parents: 38829
diff changeset
  1114
    from . import fileset
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1115
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1116
    fileset.symbols  # force import of fileset so we have predicates to optimize
38610
3d8ef60569d8 fileset: make debugfileset filter repository files
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
  1117
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1118
    ctx = scmutil.revsingle(repo, opts.get(b'rev'), None)
38801
1d1c1645d7b9 debugfileset: backport --show-stage option from debugrevspec
Yuya Nishihara <yuya@tcha.org>
parents: 38783
diff changeset
  1119
1d1c1645d7b9 debugfileset: backport --show-stage option from debugrevspec
Yuya Nishihara <yuya@tcha.org>
parents: 38783
diff changeset
  1120
    stages = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1121
        (b'parsed', pycompat.identity),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1122
        (b'analyzed', filesetlang.analyze),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1123
        (b'optimized', filesetlang.optimize),
38801
1d1c1645d7b9 debugfileset: backport --show-stage option from debugrevspec
Yuya Nishihara <yuya@tcha.org>
parents: 38783
diff changeset
  1124
    ]
1d1c1645d7b9 debugfileset: backport --show-stage option from debugrevspec
Yuya Nishihara <yuya@tcha.org>
parents: 38783
diff changeset
  1125
    stagenames = set(n for n, f in stages)
1d1c1645d7b9 debugfileset: backport --show-stage option from debugrevspec
Yuya Nishihara <yuya@tcha.org>
parents: 38783
diff changeset
  1126
1d1c1645d7b9 debugfileset: backport --show-stage option from debugrevspec
Yuya Nishihara <yuya@tcha.org>
parents: 38783
diff changeset
  1127
    showalways = set()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1128
    if ui.verbose and not opts[b'show_stage']:
38801
1d1c1645d7b9 debugfileset: backport --show-stage option from debugrevspec
Yuya Nishihara <yuya@tcha.org>
parents: 38783
diff changeset
  1129
        # show parsed tree by --verbose (deprecated)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1130
        showalways.add(b'parsed')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1131
    if opts[b'show_stage'] == [b'all']:
38801
1d1c1645d7b9 debugfileset: backport --show-stage option from debugrevspec
Yuya Nishihara <yuya@tcha.org>
parents: 38783
diff changeset
  1132
        showalways.update(stagenames)
1d1c1645d7b9 debugfileset: backport --show-stage option from debugrevspec
Yuya Nishihara <yuya@tcha.org>
parents: 38783
diff changeset
  1133
    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1134
        for n in opts[b'show_stage']:
38801
1d1c1645d7b9 debugfileset: backport --show-stage option from debugrevspec
Yuya Nishihara <yuya@tcha.org>
parents: 38783
diff changeset
  1135
            if n not in stagenames:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1136
                raise error.Abort(_(b'invalid stage name: %s') % n)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1137
        showalways.update(opts[b'show_stage'])
38801
1d1c1645d7b9 debugfileset: backport --show-stage option from debugrevspec
Yuya Nishihara <yuya@tcha.org>
parents: 38783
diff changeset
  1138
38805
b9162ea1b815 fileset: extract language processing part to new module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38802
diff changeset
  1139
    tree = filesetlang.parse(expr)
38801
1d1c1645d7b9 debugfileset: backport --show-stage option from debugrevspec
Yuya Nishihara <yuya@tcha.org>
parents: 38783
diff changeset
  1140
    for n, f in stages:
1d1c1645d7b9 debugfileset: backport --show-stage option from debugrevspec
Yuya Nishihara <yuya@tcha.org>
parents: 38783
diff changeset
  1141
        tree = f(tree)
1d1c1645d7b9 debugfileset: backport --show-stage option from debugrevspec
Yuya Nishihara <yuya@tcha.org>
parents: 38783
diff changeset
  1142
        if n in showalways:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1143
            if opts[b'show_stage'] or n != b'parsed':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1144
                ui.write(b"* %s:\n" % n)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1145
            ui.write(filesetlang.prettyformat(tree), b"\n")
30524
1ee358c3ed26 debugcommands: move 'debugfileset' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30519
diff changeset
  1146
38610
3d8ef60569d8 fileset: make debugfileset filter repository files
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
  1147
    files = set()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1148
    if opts[b'all_files']:
38610
3d8ef60569d8 fileset: make debugfileset filter repository files
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
  1149
        for r in repo:
3d8ef60569d8 fileset: make debugfileset filter repository files
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
  1150
            c = repo[r]
3d8ef60569d8 fileset: make debugfileset filter repository files
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
  1151
            files.update(c.files())
3d8ef60569d8 fileset: make debugfileset filter repository files
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
  1152
            files.update(c.substate)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1153
    if opts[b'all_files'] or ctx.rev() is None:
38610
3d8ef60569d8 fileset: make debugfileset filter repository files
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
  1154
        wctx = repo[None]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1155
        files.update(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1156
            repo.dirstate.walk(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1157
                scmutil.matchall(repo),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1158
                subrepos=list(wctx.substate),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1159
                unknown=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1160
                ignored=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1161
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1162
        )
38610
3d8ef60569d8 fileset: make debugfileset filter repository files
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
  1163
        files.update(wctx.substate)
3d8ef60569d8 fileset: make debugfileset filter repository files
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
  1164
    else:
3d8ef60569d8 fileset: make debugfileset filter repository files
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
  1165
        files.update(ctx.files())
3d8ef60569d8 fileset: make debugfileset filter repository files
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
  1166
        files.update(ctx.substate)
3d8ef60569d8 fileset: make debugfileset filter repository files
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
  1167
38612
760cc5dc01e8 fileset: restrict getfileset() to not return a computed set (API)
Yuya Nishihara <yuya@tcha.org>
parents: 38610
diff changeset
  1168
    m = ctx.matchfileset(expr)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1169
    if opts[b'show_matcher'] or (opts[b'show_matcher'] is None and ui.verbose):
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1170
        ui.writenoi18n(b'* matcher:\n', stringutil.prettyrepr(m), b'\n')
38610
3d8ef60569d8 fileset: make debugfileset filter repository files
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
  1171
    for f in sorted(files):
3d8ef60569d8 fileset: make debugfileset filter repository files
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
  1172
        if not m(f):
3d8ef60569d8 fileset: make debugfileset filter repository files
Yuya Nishihara <yuya@tcha.org>
parents: 38599
diff changeset
  1173
            continue
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1174
        ui.write(b"%s\n" % f)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1175
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1176
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1177
@command(b'debugformat', [] + cmdutil.formatteropts)
35336
c3e4f196b6e0 debugformat: add a 'debugformat' command
Boris Feld <boris.feld@octobus.net>
parents: 35304
diff changeset
  1178
def debugformat(ui, repo, **opts):
35337
cfb403b92f43 debugformat: add data about the config when verbose
Boris Feld <boris.feld@octobus.net>
parents: 35336
diff changeset
  1179
    """display format information about the current repository
cfb403b92f43 debugformat: add data about the config when verbose
Boris Feld <boris.feld@octobus.net>
parents: 35336
diff changeset
  1180
cfb403b92f43 debugformat: add data about the config when verbose
Boris Feld <boris.feld@octobus.net>
parents: 35336
diff changeset
  1181
    Use --verbose to get extra information about current config value and
cfb403b92f43 debugformat: add data about the config when verbose
Boris Feld <boris.feld@octobus.net>
parents: 35336
diff changeset
  1182
    Mercurial default."""
35401
cd3392cb5818 py3: handle keyword arguments correctly in debugcommands.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35400
diff changeset
  1183
    opts = pycompat.byteskwargs(opts)
35336
c3e4f196b6e0 debugformat: add a 'debugformat' command
Boris Feld <boris.feld@octobus.net>
parents: 35304
diff changeset
  1184
    maxvariantlength = max(len(fv.name) for fv in upgrade.allformatvariant)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1185
    maxvariantlength = max(len(b'format-variant'), maxvariantlength)
35336
c3e4f196b6e0 debugformat: add a 'debugformat' command
Boris Feld <boris.feld@octobus.net>
parents: 35304
diff changeset
  1186
c3e4f196b6e0 debugformat: add a 'debugformat' command
Boris Feld <boris.feld@octobus.net>
parents: 35304
diff changeset
  1187
    def makeformatname(name):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1188
        return b'%s:' + (b' ' * (maxvariantlength - len(name)))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1189
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1190
    fm = ui.formatter(b'debugformat', opts)
35378
9144e898cad5 debugformat: embed raw values in JSON and template output
Yuya Nishihara <yuya@tcha.org>
parents: 35377
diff changeset
  1191
    if fm.isplain():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1192
35378
9144e898cad5 debugformat: embed raw values in JSON and template output
Yuya Nishihara <yuya@tcha.org>
parents: 35377
diff changeset
  1193
        def formatvalue(value):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1194
            if util.safehasattr(value, b'startswith'):
35378
9144e898cad5 debugformat: embed raw values in JSON and template output
Yuya Nishihara <yuya@tcha.org>
parents: 35377
diff changeset
  1195
                return value
9144e898cad5 debugformat: embed raw values in JSON and template output
Yuya Nishihara <yuya@tcha.org>
parents: 35377
diff changeset
  1196
            if value:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1197
                return b'yes'
35378
9144e898cad5 debugformat: embed raw values in JSON and template output
Yuya Nishihara <yuya@tcha.org>
parents: 35377
diff changeset
  1198
            else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1199
                return b'no'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1200
35378
9144e898cad5 debugformat: embed raw values in JSON and template output
Yuya Nishihara <yuya@tcha.org>
parents: 35377
diff changeset
  1201
    else:
9144e898cad5 debugformat: embed raw values in JSON and template output
Yuya Nishihara <yuya@tcha.org>
parents: 35377
diff changeset
  1202
        formatvalue = pycompat.identity
35336
c3e4f196b6e0 debugformat: add a 'debugformat' command
Boris Feld <boris.feld@octobus.net>
parents: 35304
diff changeset
  1203
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1204
    fm.plain(b'format-variant')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1205
    fm.plain(b' ' * (maxvariantlength - len(b'format-variant')))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1206
    fm.plain(b' repo')
35337
cfb403b92f43 debugformat: add data about the config when verbose
Boris Feld <boris.feld@octobus.net>
parents: 35336
diff changeset
  1207
    if ui.verbose:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1208
        fm.plain(b' config default')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1209
    fm.plain(b'\n')
35336
c3e4f196b6e0 debugformat: add a 'debugformat' command
Boris Feld <boris.feld@octobus.net>
parents: 35304
diff changeset
  1210
    for fv in upgrade.allformatvariant:
35377
c0b6fa74e007 debugformat: flush formatter output per item
Yuya Nishihara <yuya@tcha.org>
parents: 35339
diff changeset
  1211
        fm.startitem()
35336
c3e4f196b6e0 debugformat: add a 'debugformat' command
Boris Feld <boris.feld@octobus.net>
parents: 35304
diff changeset
  1212
        repovalue = fv.fromrepo(repo)
35337
cfb403b92f43 debugformat: add data about the config when verbose
Boris Feld <boris.feld@octobus.net>
parents: 35336
diff changeset
  1213
        configvalue = fv.fromconfig(repo)
35336
c3e4f196b6e0 debugformat: add a 'debugformat' command
Boris Feld <boris.feld@octobus.net>
parents: 35304
diff changeset
  1214
35338
bd326f3e0e14 debugformat: update label depending on value difference
Boris Feld <boris.feld@octobus.net>
parents: 35337
diff changeset
  1215
        if repovalue != configvalue:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1216
            namelabel = b'formatvariant.name.mismatchconfig'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1217
            repolabel = b'formatvariant.repo.mismatchconfig'
35338
bd326f3e0e14 debugformat: update label depending on value difference
Boris Feld <boris.feld@octobus.net>
parents: 35337
diff changeset
  1218
        elif repovalue != fv.default:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1219
            namelabel = b'formatvariant.name.mismatchdefault'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1220
            repolabel = b'formatvariant.repo.mismatchdefault'
35338
bd326f3e0e14 debugformat: update label depending on value difference
Boris Feld <boris.feld@octobus.net>
parents: 35337
diff changeset
  1221
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1222
            namelabel = b'formatvariant.name.uptodate'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1223
            repolabel = b'formatvariant.repo.uptodate'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1224
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1225
        fm.write(b'name', makeformatname(fv.name), fv.name, label=namelabel)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1226
        fm.write(b'repo', b' %3s', formatvalue(repovalue), label=repolabel)
35338
bd326f3e0e14 debugformat: update label depending on value difference
Boris Feld <boris.feld@octobus.net>
parents: 35337
diff changeset
  1227
        if fv.default != configvalue:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1228
            configlabel = b'formatvariant.config.special'
35338
bd326f3e0e14 debugformat: update label depending on value difference
Boris Feld <boris.feld@octobus.net>
parents: 35337
diff changeset
  1229
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1230
            configlabel = b'formatvariant.config.default'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1231
        fm.condwrite(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1232
            ui.verbose,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1233
            b'config',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1234
            b' %6s',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1235
            formatvalue(configvalue),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1236
            label=configlabel,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1237
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1238
        fm.condwrite(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1239
            ui.verbose,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1240
            b'default',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1241
            b' %7s',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1242
            formatvalue(fv.default),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1243
            label=b'formatvariant.default',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1244
        )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1245
        fm.plain(b'\n')
35377
c0b6fa74e007 debugformat: flush formatter output per item
Yuya Nishihara <yuya@tcha.org>
parents: 35339
diff changeset
  1246
    fm.end()
35336
c3e4f196b6e0 debugformat: add a 'debugformat' command
Boris Feld <boris.feld@octobus.net>
parents: 35304
diff changeset
  1247
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1248
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1249
@command(b'debugfsinfo', [], _(b'[PATH]'), norepo=True)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1250
def debugfsinfo(ui, path=b"."):
30525
86ebd2f61c31 debugcommands: move 'debugfsinfo' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30524
diff changeset
  1251
    """show information detected about current filesystem"""
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1252
    ui.writenoi18n(b'path: %s\n' % path)
43094
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  1253
    ui.writenoi18n(
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  1254
        b'mounted on: %s\n' % (util.getfsmountpoint(path) or b'(unknown)')
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  1255
    )
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1256
    ui.writenoi18n(b'exec: %s\n' % (util.checkexec(path) and b'yes' or b'no'))
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1257
    ui.writenoi18n(b'fstype: %s\n' % (util.getfstype(path) or b'(unknown)'))
43094
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  1258
    ui.writenoi18n(
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  1259
        b'symlink: %s\n' % (util.checklink(path) and b'yes' or b'no')
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  1260
    )
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  1261
    ui.writenoi18n(
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  1262
        b'hardlink: %s\n' % (util.checknlink(path) and b'yes' or b'no')
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  1263
    )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1264
    casesensitive = b'(unknown)'
31634
35738db2037a debugfsinfo: improve case-sensitive testing
Jun Wu <quark@fb.com>
parents: 31633
diff changeset
  1265
    try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1266
        with pycompat.namedtempfile(prefix=b'.debugfsinfo', dir=path) as f:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1267
            casesensitive = util.fscasesensitive(f.name) and b'yes' or b'no'
31634
35738db2037a debugfsinfo: improve case-sensitive testing
Jun Wu <quark@fb.com>
parents: 31633
diff changeset
  1268
    except OSError:
35738db2037a debugfsinfo: improve case-sensitive testing
Jun Wu <quark@fb.com>
parents: 31633
diff changeset
  1269
        pass
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1270
    ui.writenoi18n(b'case-sensitive: %s\n' % casesensitive)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1271
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1272
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1273
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1274
    b'debuggetbundle',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1275
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1276
        (b'H', b'head', [], _(b'id of head node'), _(b'ID')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1277
        (b'C', b'common', [], _(b'id of common node'), _(b'ID')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1278
        (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1279
            b't',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1280
            b'type',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1281
            b'bzip2',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1282
            _(b'bundle compression type to use'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1283
            _(b'TYPE'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1284
        ),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1285
    ],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1286
    _(b'REPO FILE [-H|-C ID]...'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1287
    norepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1288
)
30526
9c10905f4b48 debugcommands: move 'debuggetbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30525
diff changeset
  1289
def debuggetbundle(ui, repopath, bundlepath, head=None, common=None, **opts):
9c10905f4b48 debugcommands: move 'debuggetbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30525
diff changeset
  1290
    """retrieves a bundle from a repo
9c10905f4b48 debugcommands: move 'debuggetbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30525
diff changeset
  1291
9c10905f4b48 debugcommands: move 'debuggetbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30525
diff changeset
  1292
    Every ID must be a full-length hex node id string. Saves the bundle to the
9c10905f4b48 debugcommands: move 'debuggetbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30525
diff changeset
  1293
    given file.
9c10905f4b48 debugcommands: move 'debuggetbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30525
diff changeset
  1294
    """
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
  1295
    opts = pycompat.byteskwargs(opts)
30526
9c10905f4b48 debugcommands: move 'debuggetbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30525
diff changeset
  1296
    repo = hg.peer(ui, opts, repopath)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1297
    if not repo.capable(b'getbundle'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1298
        raise error.Abort(b"getbundle() not supported by target repository")
30526
9c10905f4b48 debugcommands: move 'debuggetbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30525
diff changeset
  1299
    args = {}
9c10905f4b48 debugcommands: move 'debuggetbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30525
diff changeset
  1300
    if common:
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
  1301
        args[r'common'] = [bin(s) for s in common]
30526
9c10905f4b48 debugcommands: move 'debuggetbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30525
diff changeset
  1302
    if head:
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
  1303
        args[r'heads'] = [bin(s) for s in head]
30526
9c10905f4b48 debugcommands: move 'debuggetbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30525
diff changeset
  1304
    # TODO: get desired bundlecaps from command line.
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
  1305
    args[r'bundlecaps'] = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1306
    bundle = repo.getbundle(b'debug', **args)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1307
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1308
    bundletype = opts.get(b'type', b'bzip2').lower()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1309
    btypes = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1310
        b'none': b'HG10UN',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1311
        b'bzip2': b'HG10BZ',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1312
        b'gzip': b'HG10GZ',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1313
        b'bundle2': b'HG20',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1314
    }
30526
9c10905f4b48 debugcommands: move 'debuggetbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30525
diff changeset
  1315
    bundletype = btypes.get(bundletype)
9c10905f4b48 debugcommands: move 'debuggetbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30525
diff changeset
  1316
    if bundletype not in bundle2.bundletypes:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1317
        raise error.Abort(_(b'unknown bundle type specified with --type'))
30526
9c10905f4b48 debugcommands: move 'debuggetbundle' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30525
diff changeset
  1318
    bundle2.writebundle(ui, bundle, bundlepath, bundletype)
30527
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1319
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1320
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1321
@command(b'debugignore', [], b'[FILE]')
30527
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1322
def debugignore(ui, repo, *files, **opts):
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1323
    """display the combined ignore pattern and information about ignored files
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1324
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1325
    With no argument display the combined ignore pattern.
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1326
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1327
    Given space separated file names, shows if the given file is ignored and
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1328
    if so, show the ignore rule (file and line number) that matched it.
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1329
    """
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1330
    ignore = repo.dirstate._ignore
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1331
    if not files:
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1332
        # Show all the patterns
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1333
        ui.write(b"%s\n" % pycompat.byterepr(ignore))
30527
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1334
    else:
33507
e9672de52a23 debugignore: eliminate inconsistencies with `hg status` (issue5222)
Matt Harbison <matt_harbison@yahoo.com>
parents: 33493
diff changeset
  1335
        m = scmutil.match(repo[None], pats=files)
41636
be8741d42836 debugignore: respect ui.relative-paths
Martin von Zweigbergk <martinvonz@google.com>
parents: 41515
diff changeset
  1336
        uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True)
33507
e9672de52a23 debugignore: eliminate inconsistencies with `hg status` (issue5222)
Matt Harbison <matt_harbison@yahoo.com>
parents: 33493
diff changeset
  1337
        for f in m.files():
30527
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1338
            nf = util.normpath(f)
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1339
            ignored = None
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1340
            ignoredata = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1341
            if nf != b'.':
30527
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1342
                if ignore(nf):
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1343
                    ignored = nf
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1344
                    ignoredata = repo.dirstate._ignorefileandline(nf)
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1345
                else:
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1346
                    for p in util.finddirs(nf):
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1347
                        if ignore(p):
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1348
                            ignored = p
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1349
                            ignoredata = repo.dirstate._ignorefileandline(p)
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1350
                            break
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1351
            if ignored:
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1352
                if ignored == nf:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1353
                    ui.write(_(b"%s is ignored\n") % uipathfn(f))
30527
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1354
                else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1355
                    ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1356
                        _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1357
                            b"%s is ignored because of "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1358
                            b"containing directory %s\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1359
                        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1360
                        % (uipathfn(f), ignored)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1361
                    )
30527
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1362
                ignorefile, lineno, line = ignoredata
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1363
                ui.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1364
                    _(b"(ignore rule in %s, line %d: '%s')\n")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1365
                    % (ignorefile, lineno, line)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1366
                )
30527
243ecbd4f5c9 debugcommands: move 'debugignore' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30526
diff changeset
  1367
            else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1368
                ui.write(_(b"%s is not ignored\n") % uipathfn(f))
30528
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1369
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1370
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1371
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1372
    b'debugindex',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1373
    cmdutil.debugrevlogopts + cmdutil.formatteropts,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1374
    _(b'-c|-m|FILE'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1375
)
30528
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1376
def debugindex(ui, repo, file_=None, **opts):
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  1377
    """dump index data for a storage primitive"""
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
  1378
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1379
    store = cmdutil.openstorage(repo, b'debugindex', file_, opts)
30528
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1380
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1381
    if ui.debugflag:
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1382
        shortfn = hex
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1383
    else:
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1384
        shortfn = short
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1385
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1386
    idlen = 12
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  1387
    for i in store:
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  1388
        idlen = len(shortfn(store.node(i)))
30528
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1389
        break
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1390
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1391
    fm = ui.formatter(b'debugindex', opts)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1392
    fm.plain(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1393
        b'   rev linkrev %s %s p2\n'
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1394
        % (b'nodeid'.ljust(idlen), b'p1'.ljust(idlen))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1395
    )
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  1396
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  1397
    for rev in store:
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  1398
        node = store.node(rev)
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  1399
        parents = store.parents(node)
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  1400
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  1401
        fm.startitem()
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  1402
        fm.write(b'rev', b'%6d ', rev)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1403
        fm.write(b'linkrev', b'%7d ', store.linkrev(rev))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1404
        fm.write(b'node', b'%s ', shortfn(node))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1405
        fm.write(b'p1', b'%s ', shortfn(parents[0]))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1406
        fm.write(b'p2', b'%s', shortfn(parents[1]))
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  1407
        fm.plain(b'\n')
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  1408
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  1409
    fm.end()
30528
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1410
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1411
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1412
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1413
    b'debugindexdot',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1414
    cmdutil.debugrevlogopts,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1415
    _(b'-c|-m|FILE'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1416
    optionalrepo=True,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1417
)
30528
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1418
def debugindexdot(ui, repo, file_=None, **opts):
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1419
    """dump an index DAG as a graphviz dot file"""
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
  1420
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1421
    r = cmdutil.openstorage(repo, b'debugindexdot', file_, opts)
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1422
    ui.writenoi18n(b"digraph G {\n")
30528
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1423
    for i in r:
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1424
        node = r.node(i)
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1425
        pp = r.parents(node)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1426
        ui.write(b"\t%d -> %d\n" % (r.rev(pp[0]), i))
30528
22683f2f8100 debugcommands: move 'debugindex' and 'debugindexdot' in the new module
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30527
diff changeset
  1427
        if pp[1] != nullid:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1428
            ui.write(b"\t%d -> %d\n" % (r.rev(pp[1]), i))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1429
    ui.write(b"}\n")
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1430
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1431
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1432
@command(b'debugindexstats', [])
39980
d71e0ba34d9b debugcommands: add a debugindexstats command
Martin von Zweigbergk <martinvonz@google.com>
parents: 39956
diff changeset
  1433
def debugindexstats(ui, repo):
d71e0ba34d9b debugcommands: add a debugindexstats command
Martin von Zweigbergk <martinvonz@google.com>
parents: 39956
diff changeset
  1434
    """show stats related to the changelog index"""
d71e0ba34d9b debugcommands: add a debugindexstats command
Martin von Zweigbergk <martinvonz@google.com>
parents: 39956
diff changeset
  1435
    repo.changelog.shortest(nullid, 1)
40365
4f37af86d5d5 debugcommands: avoid stack trace from debugindexstats in pure mode
Martin von Zweigbergk <martinvonz@google.com>
parents: 40174
diff changeset
  1436
    index = repo.changelog.index
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1437
    if not util.safehasattr(index, b'stats'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1438
        raise error.Abort(_(b'debugindexstats only works with native code'))
40365
4f37af86d5d5 debugcommands: avoid stack trace from debugindexstats in pure mode
Martin von Zweigbergk <martinvonz@google.com>
parents: 40174
diff changeset
  1439
    for k, v in sorted(index.stats().items()):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1440
        ui.write(b'%s: %d\n' % (k, v))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1441
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1442
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1443
@command(b'debuginstall', [] + cmdutil.formatteropts, b'', norepo=True)
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1444
def debuginstall(ui, **opts):
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1445
    '''test Mercurial installation
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1446
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1447
    Returns 0 on success.
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1448
    '''
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
  1449
    opts = pycompat.byteskwargs(opts)
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1450
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1451
    problems = 0
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1452
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1453
    fm = ui.formatter(b'debuginstall', opts)
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1454
    fm.startitem()
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1455
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1456
    # encoding
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1457
    fm.write(b'encoding', _(b"checking encoding (%s)...\n"), encoding.encoding)
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1458
    err = None
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1459
    try:
34129
902219a99901 debuginstall: use codecs.lookup() to detect invalid encoding
Yuya Nishihara <yuya@tcha.org>
parents: 34120
diff changeset
  1460
        codecs.lookup(pycompat.sysstr(encoding.encoding))
902219a99901 debuginstall: use codecs.lookup() to detect invalid encoding
Yuya Nishihara <yuya@tcha.org>
parents: 34120
diff changeset
  1461
    except LookupError as inst:
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37057
diff changeset
  1462
        err = stringutil.forcebytestr(inst)
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1463
        problems += 1
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1464
    fm.condwrite(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1465
        err,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1466
        b'encodingerror',
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43116
diff changeset
  1467
        _(b" %s\n (check that your locale is properly set)\n"),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1468
        err,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1469
    )
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1470
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1471
    # Python
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1472
    fm.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1473
        b'pythonexe',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1474
        _(b"checking Python executable (%s)\n"),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1475
        pycompat.sysexecutable or _(b"unknown"),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1476
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1477
    fm.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1478
        b'pythonver',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1479
        _(b"checking Python version (%s)\n"),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1480
        (b"%d.%d.%d" % sys.version_info[:3]),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1481
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1482
    fm.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1483
        b'pythonlib',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1484
        _(b"checking Python lib (%s)...\n"),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1485
        os.path.dirname(pycompat.fsencode(os.__file__)),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1486
    )
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1487
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1488
    security = set(sslutil.supportedprotocols)
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1489
    if sslutil.hassni:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1490
        security.add(b'sni')
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1491
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1492
    fm.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1493
        b'pythonsecurity',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1494
        _(b"checking Python security support (%s)\n"),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1495
        fm.formatlist(sorted(security), name=b'protocol', fmt=b'%s', sep=b','),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1496
    )
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1497
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1498
    # These are warnings, not errors. So don't increment problem count. This
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1499
    # may change in the future.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1500
    if b'tls1.2' not in security:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1501
        fm.plain(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1502
            _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1503
                b'  TLS 1.2 not supported by Python install; '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1504
                b'network connections lack modern security\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1505
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1506
        )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1507
    if b'sni' not in security:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1508
        fm.plain(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1509
            _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1510
                b'  SNI not supported by Python install; may have '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1511
                b'connectivity issues with some servers\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1512
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1513
        )
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1514
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1515
    # TODO print CA cert info
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1516
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1517
    # hg version
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1518
    hgver = util.version()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1519
    fm.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1520
        b'hgver', _(b"checking Mercurial version (%s)\n"), hgver.split(b'+')[0]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1521
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1522
    fm.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1523
        b'hgverextra',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1524
        _(b"checking Mercurial custom build (%s)\n"),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1525
        b'+'.join(hgver.split(b'+')[1:]),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1526
    )
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1527
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1528
    # compiled modules
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1529
    fm.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1530
        b'hgmodulepolicy', _(b"checking module policy (%s)\n"), policy.policy
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1531
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1532
    fm.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1533
        b'hgmodules',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1534
        _(b"checking installed modules (%s)...\n"),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1535
        os.path.dirname(pycompat.fsencode(__file__)),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1536
    )
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1537
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1538
    rustandc = policy.policy in (b'rust+c', b'rust+c-allow')
42451
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1539
    rustext = rustandc  # for now, that's the only case
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1540
    cext = policy.policy in (b'c', b'allow') or rustandc
42451
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1541
    nopure = cext or rustext
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1542
    if nopure:
32209
85dc5a25f1fc debuginstall: check C extensions only if they are loadable per policy
Yuya Nishihara <yuya@tcha.org>
parents: 31864
diff changeset
  1543
        err = None
85dc5a25f1fc debuginstall: check C extensions only if they are loadable per policy
Yuya Nishihara <yuya@tcha.org>
parents: 31864
diff changeset
  1544
        try:
42451
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1545
            if cext:
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1546
                from .cext import (
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1547
                    base85,
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1548
                    bdiff,
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1549
                    mpatch,
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1550
                    osutil,
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1551
                )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1552
42451
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1553
                # quiet pyflakes
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1554
                dir(bdiff), dir(mpatch), dir(base85), dir(osutil)
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1555
            if rustext:
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1556
                from .rustext import (
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1557
                    ancestor,
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1558
                    dirstate,
810f66b468cd rust: module policy with importrust
Georges Racinet <georges.racinet@octobus.net>
parents: 42145
diff changeset
  1559
                )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1560
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1561
                dir(ancestor), dir(dirstate)  # quiet pyflakes
32209
85dc5a25f1fc debuginstall: check C extensions only if they are loadable per policy
Yuya Nishihara <yuya@tcha.org>
parents: 31864
diff changeset
  1562
        except Exception as inst:
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37057
diff changeset
  1563
            err = stringutil.forcebytestr(inst)
32209
85dc5a25f1fc debuginstall: check C extensions only if they are loadable per policy
Yuya Nishihara <yuya@tcha.org>
parents: 31864
diff changeset
  1564
            problems += 1
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1565
        fm.condwrite(err, b'extensionserror', b" %s\n", err)
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1566
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1567
    compengines = util.compengines._engines.values()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1568
    fm.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1569
        b'compengines',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1570
        _(b'checking registered compression engines (%s)\n'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1571
        fm.formatlist(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1572
            sorted(e.name() for e in compengines),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1573
            name=b'compengine',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1574
            fmt=b'%s',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1575
            sep=b', ',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1576
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1577
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1578
    fm.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1579
        b'compenginesavail',
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43116
diff changeset
  1580
        _(b'checking available compression engines (%s)\n'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1581
        fm.formatlist(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1582
            sorted(e.name() for e in compengines if e.available()),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1583
            name=b'compengine',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1584
            fmt=b'%s',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1585
            sep=b', ',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1586
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1587
    )
42041
3e47d1ec9da5 util: extract compression code in `mercurial.utils.compression`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42035
diff changeset
  1588
    wirecompengines = compression.compengines.supportedwireengines(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1589
        compression.SERVERROLE
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1590
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1591
    fm.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1592
        b'compenginesserver',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1593
        _(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1594
            b'checking available compression engines '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1595
            b'for wire protocol (%s)\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1596
        ),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1597
        fm.formatlist(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1598
            [e.name() for e in wirecompengines if e.wireprotosupport()],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1599
            name=b'compengine',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1600
            fmt=b'%s',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1601
            sep=b', ',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1602
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1603
    )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1604
    re2 = b'missing'
35448
8251c4c4abdc debuginstall: add a line about re2 availability
Boris Feld <boris.feld@octobus.net>
parents: 35424
diff changeset
  1605
    if util._re2:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1606
        re2 = b'available'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1607
    fm.plain(_(b'checking "re2" regexp engine (%s)\n') % re2)
35448
8251c4c4abdc debuginstall: add a line about re2 availability
Boris Feld <boris.feld@octobus.net>
parents: 35424
diff changeset
  1608
    fm.data(re2=bool(util._re2))
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1609
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1610
    # templates
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1611
    p = templater.templatepaths()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1612
    fm.write(b'templatedirs', b'checking templates (%s)...\n', b' '.join(p))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1613
    fm.condwrite(not p, b'', _(b" no template directories found\n"))
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1614
    if p:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1615
        m = templater.templatepath(b"map-cmdline.default")
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1616
        if m:
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1617
            # template found, check if it is working
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1618
            err = None
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1619
            try:
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1620
                templater.templater.frommapfile(m)
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1621
            except Exception as inst:
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37057
diff changeset
  1622
                err = stringutil.forcebytestr(inst)
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1623
                p = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1624
            fm.condwrite(err, b'defaulttemplateerror', b" %s\n", err)
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1625
        else:
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1626
            p = None
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1627
        fm.condwrite(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1628
            p, b'defaulttemplate', _(b"checking default template (%s)\n"), m
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1629
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1630
        fm.condwrite(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1631
            not m,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1632
            b'defaulttemplatenotfound',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1633
            _(b" template '%s' not found\n"),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1634
            b"default",
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1635
        )
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1636
    if not p:
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1637
        problems += 1
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1638
    fm.condwrite(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1639
        not p, b'', _(b" (templates seem to have been installed incorrectly)\n")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1640
    )
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1641
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1642
    # editor
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1643
    editor = ui.geteditor()
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1644
    editor = util.expandpath(editor)
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37084
diff changeset
  1645
    editorbin = procutil.shellsplit(editor)[0]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1646
    fm.write(b'editor', _(b"checking commit editor... (%s)\n"), editorbin)
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37084
diff changeset
  1647
    cmdpath = procutil.findexe(editorbin)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1648
    fm.condwrite(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1649
        not cmdpath and editor == b'vi',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1650
        b'vinotfound',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1651
        _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1652
            b" No commit editor set and can't find %s in PATH\n"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1653
            b" (specify a commit editor in your configuration"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1654
            b" file)\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1655
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1656
        not cmdpath and editor == b'vi' and editorbin,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1657
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1658
    fm.condwrite(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1659
        not cmdpath and editor != b'vi',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1660
        b'editornotfound',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1661
        _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1662
            b" Can't find editor '%s' in PATH\n"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1663
            b" (specify a commit editor in your configuration"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1664
            b" file)\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1665
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1666
        not cmdpath and editorbin,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1667
    )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1668
    if not cmdpath and editor != b'vi':
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1669
        problems += 1
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1670
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1671
    # check username
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1672
    username = None
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1673
    err = None
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1674
    try:
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1675
        username = ui.username()
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1676
    except error.Abort as e:
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37057
diff changeset
  1677
        err = stringutil.forcebytestr(e)
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1678
        problems += 1
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1679
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1680
    fm.condwrite(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1681
        username, b'username', _(b"checking username (%s)\n"), username
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1682
    )
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1683
    fm.condwrite(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1684
        err,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1685
        b'usernameerror',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1686
        _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1687
            b"checking username...\n %s\n"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1688
            b" (specify a username in your configuration file)\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1689
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1690
        err,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1691
    )
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1692
42651
7f1df7019497 debugcommands: add support for extensions adding their own debug info
Augie Fackler <augie@google.com>
parents: 42580
diff changeset
  1693
    for name, mod in extensions.extensions():
7f1df7019497 debugcommands: add support for extensions adding their own debug info
Augie Fackler <augie@google.com>
parents: 42580
diff changeset
  1694
        handler = getattr(mod, 'debuginstall', None)
7f1df7019497 debugcommands: add support for extensions adding their own debug info
Augie Fackler <augie@google.com>
parents: 42580
diff changeset
  1695
        if handler is not None:
7f1df7019497 debugcommands: add support for extensions adding their own debug info
Augie Fackler <augie@google.com>
parents: 42580
diff changeset
  1696
            problems += handler(ui, fm)
7f1df7019497 debugcommands: add support for extensions adding their own debug info
Augie Fackler <augie@google.com>
parents: 42580
diff changeset
  1697
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1698
    fm.condwrite(not problems, b'', _(b"no problems detected\n"))
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1699
    if not problems:
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1700
        fm.data(problems=problems)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1701
    fm.condwrite(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1702
        problems,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1703
        b'problems',
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43116
diff changeset
  1704
        _(b"%d problems detected, please check your install!\n"),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1705
        problems,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1706
    )
30918
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1707
    fm.end()
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1708
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1709
    return problems
fec3dbaa7f83 debugcommands: extract debuginstall in the debugcommands module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30775
diff changeset
  1710
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1711
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1712
@command(b'debugknown', [], _(b'REPO ID...'), norepo=True)
30919
e1fa5fe9f9d4 debugcommands: move 'debugknown' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30918
diff changeset
  1713
def debugknown(ui, repopath, *ids, **opts):
e1fa5fe9f9d4 debugcommands: move 'debugknown' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30918
diff changeset
  1714
    """test whether node ids are known to a repo
e1fa5fe9f9d4 debugcommands: move 'debugknown' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30918
diff changeset
  1715
e1fa5fe9f9d4 debugcommands: move 'debugknown' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30918
diff changeset
  1716
    Every ID must be a full-length hex node id string. Returns a list of 0s
e1fa5fe9f9d4 debugcommands: move 'debugknown' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30918
diff changeset
  1717
    and 1s indicating unknown/known.
e1fa5fe9f9d4 debugcommands: move 'debugknown' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30918
diff changeset
  1718
    """
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
  1719
    opts = pycompat.byteskwargs(opts)
30919
e1fa5fe9f9d4 debugcommands: move 'debugknown' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30918
diff changeset
  1720
    repo = hg.peer(ui, opts, repopath)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1721
    if not repo.capable(b'known'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1722
        raise error.Abort(b"known() not supported by target repository")
30919
e1fa5fe9f9d4 debugcommands: move 'debugknown' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30918
diff changeset
  1723
    flags = repo.known([bin(s) for s in ids])
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1724
    ui.write(b"%s\n" % (b"".join([f and b"1" or b"0" for f in flags])))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1725
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1726
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1727
@command(b'debuglabelcomplete', [], _(b'LABEL...'))
30935
e46533c3201e debugcommands: move 'debuglabelcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30919
diff changeset
  1728
def debuglabelcomplete(ui, repo, *args):
e46533c3201e debugcommands: move 'debuglabelcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30919
diff changeset
  1729
    '''backwards compatibility with old bash completion scripts (DEPRECATED)'''
31402
ea0395eec67b debuglabelcomplete: fix to call debugnamecomplete in new location
Kyle Lippincott <spectral@google.com>
parents: 31239
diff changeset
  1730
    debugnamecomplete(ui, repo, *args)
30935
e46533c3201e debugcommands: move 'debuglabelcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30919
diff changeset
  1731
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1732
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1733
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1734
    b'debuglocks',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1735
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1736
        (b'L', b'force-lock', None, _(b'free the store lock (DANGEROUS)')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1737
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1738
            b'W',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1739
            b'force-wlock',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1740
            None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1741
            _(b'free the working state lock (DANGEROUS)'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1742
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1743
        (b's', b'set-lock', None, _(b'set the store lock until stopped')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1744
        (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1745
            b'S',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1746
            b'set-wlock',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1747
            None,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1748
            _(b'set the working state lock until stopped'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1749
        ),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1750
    ],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1751
    _(b'[OPTION]...'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1752
)
30938
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1753
def debuglocks(ui, repo, **opts):
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1754
    """show or modify state of locks
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1755
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1756
    By default, this command will show which locks are held. This
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1757
    includes the user and process holding the lock, the amount of time
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1758
    the lock has been held, and the machine name where the process is
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1759
    running if it's not local.
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1760
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1761
    Locks protect the integrity of Mercurial's data, so should be
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1762
    treated with care. System crashes or other interruptions may cause
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1763
    locks to not be properly released, though Mercurial will usually
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1764
    detect and remove such stale locks automatically.
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1765
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1766
    However, detecting stale locks may not always be possible (for
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1767
    instance, on a shared filesystem). Removing locks may also be
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1768
    blocked by filesystem permissions.
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1769
35395
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1770
    Setting a lock will prevent other commands from changing the data.
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1771
    The command will wait until an interruption (SIGINT, SIGTERM, ...) occurs.
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1772
    The set locks are removed when the command exits.
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1773
30938
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1774
    Returns 0 if no locks are held.
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1775
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1776
    """
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1777
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
  1778
    if opts.get(r'force_lock'):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1779
        repo.svfs.unlink(b'lock')
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
  1780
    if opts.get(r'force_wlock'):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1781
        repo.vfs.unlink(b'wlock')
35394
a43b2dd95e4f debuglocks: add tests (and fix typo in early return)
Paul Morelle <paul.morelle@octobus.net>
parents: 35378
diff changeset
  1782
    if opts.get(r'force_lock') or opts.get(r'force_wlock'):
30938
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1783
        return 0
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1784
35395
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1785
    locks = []
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1786
    try:
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1787
        if opts.get(r'set_wlock'):
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1788
            try:
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1789
                locks.append(repo.wlock(False))
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1790
            except error.LockHeld:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1791
                raise error.Abort(_(b'wlock is already held'))
35395
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1792
        if opts.get(r'set_lock'):
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1793
            try:
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1794
                locks.append(repo.lock(False))
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1795
            except error.LockHeld:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1796
                raise error.Abort(_(b'lock is already held'))
35395
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1797
        if len(locks):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1798
            ui.promptchoice(_(b"ready to release the lock (y)? $$ &Yes"))
35395
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1799
            return 0
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1800
    finally:
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1801
        release(*locks)
12055fb3ba30 debuglocks: allow setting a lock
Paul Morelle <paul.morelle@octobus.net>
parents: 35394
diff changeset
  1802
30938
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1803
    now = time.time()
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1804
    held = 0
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1805
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1806
    def report(vfs, name, method):
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1807
        # this causes stale locks to get reaped for more accurate reporting
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1808
        try:
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1809
            l = method(False)
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1810
        except error.LockHeld:
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1811
            l = None
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1812
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1813
        if l:
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1814
            l.release()
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1815
        else:
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1816
            try:
36781
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36778
diff changeset
  1817
                st = vfs.lstat(name)
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36778
diff changeset
  1818
                age = now - st[stat.ST_MTIME]
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36778
diff changeset
  1819
                user = util.username(st.st_uid)
30938
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1820
                locker = vfs.readlock(name)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1821
                if b":" in locker:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1822
                    host, pid = locker.split(b':')
30938
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1823
                    if host == socket.gethostname():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1824
                        locker = b'user %s, process %s' % (user or b'None', pid)
30938
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1825
                    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1826
                        locker = b'user %s, process %s, host %s' % (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1827
                            user or b'None',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1828
                            pid,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1829
                            host,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1830
                        )
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1831
                ui.writenoi18n(b"%-6s %s (%ds)\n" % (name + b":", locker, age))
30938
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1832
                return 1
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1833
            except OSError as e:
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1834
                if e.errno != errno.ENOENT:
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1835
                    raise
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1836
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1837
        ui.writenoi18n(b"%-6s free\n" % (name + b":"))
30938
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1838
        return 0
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1839
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1840
    held += report(repo.svfs, b"lock", repo.lock)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1841
    held += report(repo.vfs, b"wlock", repo.wlock)
30938
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1842
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1843
    return held
23c801570449 debugcommands: move 'debuglocks' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30937
diff changeset
  1844
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1845
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1846
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1847
    b'debugmanifestfulltextcache',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1848
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1849
        (b'', b'clear', False, _(b'clear the cache')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1850
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1851
            b'a',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1852
            b'add',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1853
            [],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1854
            _(b'add the given manifest nodes to the cache'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1855
            _(b'NODE'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1856
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1857
    ],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1858
    b'',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1859
)
41958
1fe278aa4ad5 manifestcache: support multiple cache addition in one debug command run
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41947
diff changeset
  1860
def debugmanifestfulltextcache(ui, repo, add=(), **opts):
38781
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38707
diff changeset
  1861
    """show, clear or amend the contents of the manifest fulltext cache"""
41942
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1862
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1863
    def getcache():
39244
73cf21b2e8a6 manifest: add getstorage() to manifestlog and use it globally
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39163
diff changeset
  1864
        r = repo.manifestlog.getstorage(b'')
38781
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38707
diff changeset
  1865
        try:
41942
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1866
            return r._fulltextcache
38781
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38707
diff changeset
  1867
        except AttributeError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1868
            msg = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1869
                b"Current revlog implementation doesn't appear to have a "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1870
                b"manifest fulltext cache\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1871
            )
41942
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1872
            raise error.Abort(msg)
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1873
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1874
    if opts.get(r'clear'):
41964
d121823072b8 manifestcache: protect write with `wlock` instead of `lock`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41959
diff changeset
  1875
        with repo.wlock():
41942
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1876
            cache = getcache()
41947
b74ef67573e5 manifestcache: actually honor --clear
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41943
diff changeset
  1877
            cache.clear(clear_persisted_data=True)
b74ef67573e5 manifestcache: actually honor --clear
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41943
diff changeset
  1878
            return
38781
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38707
diff changeset
  1879
41942
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1880
    if add:
41964
d121823072b8 manifestcache: protect write with `wlock` instead of `lock`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41959
diff changeset
  1881
        with repo.wlock():
41958
1fe278aa4ad5 manifestcache: support multiple cache addition in one debug command run
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41947
diff changeset
  1882
            m = repo.manifestlog
1fe278aa4ad5 manifestcache: support multiple cache addition in one debug command run
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41947
diff changeset
  1883
            store = m.getstorage(b'')
1fe278aa4ad5 manifestcache: support multiple cache addition in one debug command run
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41947
diff changeset
  1884
            for n in add:
1fe278aa4ad5 manifestcache: support multiple cache addition in one debug command run
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41947
diff changeset
  1885
                try:
1fe278aa4ad5 manifestcache: support multiple cache addition in one debug command run
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41947
diff changeset
  1886
                    manifest = m[store.lookup(n)]
1fe278aa4ad5 manifestcache: support multiple cache addition in one debug command run
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41947
diff changeset
  1887
                except error.LookupError as e:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1888
                    raise error.Abort(e, hint=b"Check your manifest node id")
41958
1fe278aa4ad5 manifestcache: support multiple cache addition in one debug command run
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41947
diff changeset
  1889
                manifest.read()  # stores revisision in cache too
41943
1e75311d78f7 manifestcache: do not display data when using --add
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41942
diff changeset
  1890
            return
38781
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38707
diff changeset
  1891
41942
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1892
    cache = getcache()
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1893
    if not len(cache):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1894
        ui.write(_(b'cache empty\n'))
41942
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1895
    else:
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1896
        ui.write(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1897
            _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1898
                b'cache contains %d manifest entries, in order of most to '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1899
                b'least recent:\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1900
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1901
            % (len(cache),)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1902
        )
41942
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1903
        totalsize = 0
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1904
        for nodeid in cache:
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1905
            # Use cache.get to not update the LRU order
41959
e3307243d188 manifestcache: stop altering the lru cache order while displaying it
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41958
diff changeset
  1906
            data = cache.peek(nodeid)
41942
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1907
            size = len(data)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1908
            totalsize += size + 24  # 20 bytes nodeid, 4 bytes size
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1909
            ui.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1910
                _(b'id: %s, size %s\n') % (hex(nodeid), util.bytecount(size))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1911
            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1912
        ondisk = cache._opener.stat(b'manifestfulltextcache').st_size
41942
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1913
        ui.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1914
            _(b'total cache data size %s, on-disk %s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1915
            % (util.bytecount(totalsize), util.bytecount(ondisk))
41942
fbee66c90cef manifestcache: only lock the repository if the debug command touch the cache
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 41941
diff changeset
  1916
        )
38781
0a57945aaf7f manifest: persist the manifestfulltext cache
Martijn Pieters <mj@zopatista.com>
parents: 38707
diff changeset
  1917
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1918
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1919
@command(b'debugmergestate', [], b'')
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1920
def debugmergestate(ui, repo, *args):
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1921
    """print merge state
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1922
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1923
    Use --verbose to print out information about whether v1 or v2 merge state
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1924
    was chosen."""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1925
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1926
    def _hashornull(h):
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1927
        if h == nullhex:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1928
            return b'null'
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1929
        else:
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1930
            return h
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1931
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1932
    def printrecords(version):
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1933
        ui.writenoi18n(b'* version %d records\n' % version)
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1934
        if version == 1:
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1935
            records = v1records
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1936
        else:
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1937
            records = v2records
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1938
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1939
        for rtype, record in records:
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1940
            # pretty print some record types
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1941
            if rtype == b'L':
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1942
                ui.writenoi18n(b'local: %s\n' % record)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1943
            elif rtype == b'O':
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1944
                ui.writenoi18n(b'other: %s\n' % record)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1945
            elif rtype == b'm':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1946
                driver, mdstate = record.split(b'\0', 1)
43094
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  1947
                ui.writenoi18n(
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  1948
                    b'merge driver: %s (state "%s")\n' % (driver, mdstate)
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  1949
                )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1950
            elif rtype in b'FDC':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1951
                r = record.split(b'\0')
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1952
                f, state, hash, lfile, afile, anode, ofile = r[0:7]
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1953
                if version == 1:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1954
                    onode = b'not stored in v1 format'
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1955
                    flags = r[7]
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1956
                else:
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1957
                    onode, flags = r[7:9]
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1958
                ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1959
                    b'file: %s (record type "%s", state "%s", hash %s)\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1960
                    % (f, rtype, state, _hashornull(hash))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1961
                )
43094
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  1962
                ui.writenoi18n(
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  1963
                    b'  local path: %s (flags "%s")\n' % (lfile, flags)
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  1964
                )
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1965
                ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1966
                    b'  ancestor path: %s (node %s)\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1967
                    % (afile, _hashornull(anode))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1968
                )
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1969
                ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1970
                    b'  other path: %s (node %s)\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1971
                    % (ofile, _hashornull(onode))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1972
                )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1973
            elif rtype == b'f':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1974
                filename, rawextras = record.split(b'\0', 1)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1975
                extras = rawextras.split(b'\0')
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1976
                i = 0
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1977
                extrastrings = []
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1978
                while i < len(extras):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1979
                    extrastrings.append(b'%s = %s' % (extras[i], extras[i + 1]))
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1980
                    i += 2
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1981
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1982
                ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1983
                    b'file extras: %s (%s)\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1984
                    % (filename, b', '.join(extrastrings))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1985
                )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1986
            elif rtype == b'l':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1987
                labels = record.split(b'\0', 2)
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1988
                labels = [l for l in labels if len(l) > 0]
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1989
                ui.writenoi18n(b'labels:\n')
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1990
                ui.write((b'  local: %s\n' % labels[0]))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1991
                ui.write((b'  other: %s\n' % labels[1]))
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1992
                if len(labels) > 2:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1993
                    ui.write((b'  base:  %s\n' % labels[2]))
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1994
            else:
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  1995
                ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1996
                    b'unrecognized entry: %s\t%s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1997
                    % (rtype, record.replace(b'\0', b'\t'))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  1998
                )
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  1999
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2000
    # Avoid mergestate.read() since it may raise an exception for unsupported
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2001
    # merge state records. We shouldn't be doing this, but this is OK since this
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2002
    # command is pretty low-level.
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2003
    ms = mergemod.mergestate(repo)
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2004
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2005
    # sort so that reasonable information is on top
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2006
    v1records = ms._readrecordsv1()
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2007
    v2records = ms._readrecordsv2()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2008
    order = b'LOml'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2009
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2010
    def key(r):
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2011
        idx = order.find(r[0])
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2012
        if idx == -1:
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2013
            return (1, r[1])
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2014
        else:
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2015
            return (0, idx)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2016
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2017
    v1records.sort(key=key)
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2018
    v2records.sort(key=key)
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2019
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2020
    if not v1records and not v2records:
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2021
        ui.writenoi18n(b'no merge state found\n')
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2022
    elif not v2records:
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2023
        ui.notenoi18n(b'no version 2 merge state\n')
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2024
        printrecords(1)
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2025
    elif ms._v1v2match(v1records, v2records):
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2026
        ui.notenoi18n(b'v1 and v2 states match: using v2\n')
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2027
        printrecords(2)
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2028
    else:
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2029
        ui.notenoi18n(b'v1 and v2 states mismatch: using v1\n')
30936
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2030
        printrecords(1)
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2031
        if ui.verbose:
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2032
            printrecords(2)
8de38479d60b debugcommands: move 'debugmergestate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30935
diff changeset
  2033
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2034
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2035
@command(b'debugnamecomplete', [], _(b'NAME...'))
30937
a9aa67ba3f96 debugcommands: move 'debugnamecomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30936
diff changeset
  2036
def debugnamecomplete(ui, repo, *args):
a9aa67ba3f96 debugcommands: move 'debugnamecomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30936
diff changeset
  2037
    '''complete "names" - tags, open branch names, bookmark names'''
a9aa67ba3f96 debugcommands: move 'debugnamecomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30936
diff changeset
  2038
a9aa67ba3f96 debugcommands: move 'debugnamecomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30936
diff changeset
  2039
    names = set()
a9aa67ba3f96 debugcommands: move 'debugnamecomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30936
diff changeset
  2040
    # since we previously only listed open branches, we will handle that
a9aa67ba3f96 debugcommands: move 'debugnamecomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30936
diff changeset
  2041
    # specially (after this for loop)
43106
d783f945a701 py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43094
diff changeset
  2042
    for name, ns in pycompat.iteritems(repo.names):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2043
        if name != b'branches':
30937
a9aa67ba3f96 debugcommands: move 'debugnamecomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30936
diff changeset
  2044
            names.update(ns.listnames(repo))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2045
    names.update(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2046
        tag
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2047
        for (tag, heads, tip, closed) in repo.branchmap().iterbranches()
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2048
        if not closed
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2049
    )
30937
a9aa67ba3f96 debugcommands: move 'debugnamecomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30936
diff changeset
  2050
    completions = set()
a9aa67ba3f96 debugcommands: move 'debugnamecomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30936
diff changeset
  2051
    if not args:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2052
        args = [b'']
30937
a9aa67ba3f96 debugcommands: move 'debugnamecomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30936
diff changeset
  2053
    for a in args:
a9aa67ba3f96 debugcommands: move 'debugnamecomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30936
diff changeset
  2054
        completions.update(n for n in names if n.startswith(a))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2055
    ui.write(b'\n'.join(sorted(completions)))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2056
    ui.write(b'\n')
30937
a9aa67ba3f96 debugcommands: move 'debugnamecomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30936
diff changeset
  2057
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2058
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2059
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2060
    b'debugobsolete',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2061
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2062
        (b'', b'flags', 0, _(b'markers flag')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2063
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2064
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2065
            b'record-parents',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2066
            False,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2067
            _(b'record parent information for the precursor'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2068
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2069
        (b'r', b'rev', [], _(b'display markers relevant to REV')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2070
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2071
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2072
            b'exclusive',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2073
            False,
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43116
diff changeset
  2074
            _(b'restrict display to markers only relevant to REV'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2075
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2076
        (b'', b'index', False, _(b'display index of the marker')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2077
        (b'', b'delete', [], _(b'delete markers specified by indices')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2078
    ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2079
    + cmdutil.commitopts2
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2080
    + cmdutil.formatteropts,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2081
    _(b'[OBSOLETED [REPLACEMENT ...]]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2082
)
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2083
def debugobsolete(ui, repo, precursor=None, *successors, **opts):
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2084
    """create arbitrary obsolete marker
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2085
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2086
    With no arguments, displays the list of obsolescence markers."""
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2087
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
  2088
    opts = pycompat.byteskwargs(opts)
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
  2089
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2090
    def parsenodeid(s):
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2091
        try:
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2092
            # We do not use revsingle/revrange functions here to accept
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2093
            # arbitrary node identifiers, possibly not present in the
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2094
            # local repository.
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2095
            n = bin(s)
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2096
            if len(n) != len(nullid):
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2097
                raise TypeError()
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2098
            return n
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2099
        except TypeError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2100
            raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2101
                b'changeset references must be full hexadecimal '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2102
                b'node identifiers'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2103
            )
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2104
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2105
    if opts.get(b'delete'):
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2106
        indices = []
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2107
        for v in opts.get(b'delete'):
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2108
            try:
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2109
                indices.append(int(v))
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2110
            except ValueError:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2111
                raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2112
                    _(b'invalid index value: %r') % v,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2113
                    hint=_(b'use integers for indices'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2114
                )
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2115
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2116
        if repo.currenttransaction():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2117
            raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43116
diff changeset
  2118
                _(b'cannot delete obsmarkers in the middle of transaction.')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2119
            )
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2120
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2121
        with repo.lock():
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2122
            n = repair.deleteobsmarkers(repo.obsstore, indices)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2123
            ui.write(_(b'deleted %i obsolescence markers\n') % n)
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2124
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2125
        return
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2126
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2127
    if precursor is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2128
        if opts[b'rev']:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2129
            raise error.Abort(b'cannot select revision when creating marker')
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2130
        metadata = {}
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2131
        metadata[b'user'] = encoding.fromlocal(opts[b'user'] or ui.username())
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2132
        succs = tuple(parsenodeid(succ) for succ in successors)
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2133
        l = repo.lock()
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2134
        try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2135
            tr = repo.transaction(b'debugobsolete')
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2136
            try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2137
                date = opts.get(b'date')
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2138
                if date:
36607
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36587
diff changeset
  2139
                    date = dateutil.parsedate(date)
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2140
                else:
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2141
                    date = None
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2142
                prec = parsenodeid(precursor)
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2143
                parents = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2144
                if opts[b'record_parents']:
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2145
                    if prec not in repo.unfiltered():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2146
                        raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2147
                            b'cannot used --record-parents on '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2148
                            b'unknown changesets'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2149
                        )
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2150
                    parents = repo.unfiltered()[prec].parents()
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2151
                    parents = tuple(p.node() for p in parents)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2152
                repo.obsstore.create(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2153
                    tr,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2154
                    prec,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2155
                    succs,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2156
                    opts[b'flags'],
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2157
                    parents=parents,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2158
                    date=date,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2159
                    metadata=metadata,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2160
                    ui=ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2161
                )
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2162
                tr.close()
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2163
            except ValueError as exc:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2164
                raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2165
                    _(b'bad obsmarker input: %s') % pycompat.bytestr(exc)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2166
                )
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2167
            finally:
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2168
                tr.release()
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2169
        finally:
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2170
            l.release()
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2171
    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2172
        if opts[b'rev']:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2173
            revs = scmutil.revrange(repo, opts[b'rev'])
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2174
            nodes = [repo[r].node() for r in revs]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2175
            markers = list(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2176
                obsutil.getmarkers(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2177
                    repo, nodes=nodes, exclusive=opts[b'exclusive']
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2178
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2179
            )
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2180
            markers.sort(key=lambda x: x._data)
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2181
        else:
33149
a14e2e7f7d1f obsutil: move 'getmarkers' to the new modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33148
diff changeset
  2182
            markers = obsutil.getmarkers(repo)
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2183
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2184
        markerstoiter = markers
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2185
        isrelevant = lambda m: True
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2186
        if opts.get(b'rev') and opts.get(b'index'):
33149
a14e2e7f7d1f obsutil: move 'getmarkers' to the new modules
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33148
diff changeset
  2187
            markerstoiter = obsutil.getmarkers(repo)
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2188
            markerset = set(markers)
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2189
            isrelevant = lambda m: m in markerset
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2190
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2191
        fm = ui.formatter(b'debugobsolete', opts)
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2192
        for i, m in enumerate(markerstoiter):
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2193
            if not isrelevant(m):
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2194
                # marker can be irrelevant when we're iterating over a set
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2195
                # of markers (markerstoiter) which is bigger than the set
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2196
                # of markers we want to display (markers)
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2197
                # this can happen if both --index and --rev options are
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2198
                # provided and thus we need to iterate over all of the markers
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2199
                # to get the correct indices, but only display the ones that
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2200
                # are relevant to --rev value
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2201
                continue
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2202
            fm.startitem()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2203
            ind = i if opts.get(b'index') else None
30939
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2204
            cmdutil.showmarker(fm, m, index=ind)
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2205
        fm.end()
9e39d196cdf5 debugcommands: move 'debugobsolete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30938
diff changeset
  2206
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2207
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2208
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2209
    b'debugp1copies',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2210
    [(b'r', b'rev', b'', _(b'revision to debug'), _(b'REV'))],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2211
    _(b'[-r REV]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2212
)
41755
a4358f7345b4 context: introduce p[12]copies() methods and debugp[12]copies commands
Martin von Zweigbergk <martinvonz@google.com>
parents: 41749
diff changeset
  2213
def debugp1copies(ui, repo, **opts):
a4358f7345b4 context: introduce p[12]copies() methods and debugp[12]copies commands
Martin von Zweigbergk <martinvonz@google.com>
parents: 41749
diff changeset
  2214
    """dump copy information compared to p1"""
a4358f7345b4 context: introduce p[12]copies() methods and debugp[12]copies commands
Martin von Zweigbergk <martinvonz@google.com>
parents: 41749
diff changeset
  2215
a4358f7345b4 context: introduce p[12]copies() methods and debugp[12]copies commands
Martin von Zweigbergk <martinvonz@google.com>
parents: 41749
diff changeset
  2216
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2217
    ctx = scmutil.revsingle(repo, opts.get(b'rev'), default=None)
41755
a4358f7345b4 context: introduce p[12]copies() methods and debugp[12]copies commands
Martin von Zweigbergk <martinvonz@google.com>
parents: 41749
diff changeset
  2218
    for dst, src in ctx.p1copies().items():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2219
        ui.write(b'%s -> %s\n' % (src, dst))
41755
a4358f7345b4 context: introduce p[12]copies() methods and debugp[12]copies commands
Martin von Zweigbergk <martinvonz@google.com>
parents: 41749
diff changeset
  2220
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2221
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2222
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2223
    b'debugp2copies',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2224
    [(b'r', b'rev', b'', _(b'revision to debug'), _(b'REV'))],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2225
    _(b'[-r REV]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2226
)
41755
a4358f7345b4 context: introduce p[12]copies() methods and debugp[12]copies commands
Martin von Zweigbergk <martinvonz@google.com>
parents: 41749
diff changeset
  2227
def debugp1copies(ui, repo, **opts):
a4358f7345b4 context: introduce p[12]copies() methods and debugp[12]copies commands
Martin von Zweigbergk <martinvonz@google.com>
parents: 41749
diff changeset
  2228
    """dump copy information compared to p2"""
a4358f7345b4 context: introduce p[12]copies() methods and debugp[12]copies commands
Martin von Zweigbergk <martinvonz@google.com>
parents: 41749
diff changeset
  2229
a4358f7345b4 context: introduce p[12]copies() methods and debugp[12]copies commands
Martin von Zweigbergk <martinvonz@google.com>
parents: 41749
diff changeset
  2230
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2231
    ctx = scmutil.revsingle(repo, opts.get(b'rev'), default=None)
41755
a4358f7345b4 context: introduce p[12]copies() methods and debugp[12]copies commands
Martin von Zweigbergk <martinvonz@google.com>
parents: 41749
diff changeset
  2232
    for dst, src in ctx.p2copies().items():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2233
        ui.write(b'%s -> %s\n' % (src, dst))
41755
a4358f7345b4 context: introduce p[12]copies() methods and debugp[12]copies commands
Martin von Zweigbergk <martinvonz@google.com>
parents: 41749
diff changeset
  2234
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2235
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2236
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2237
    b'debugpathcomplete',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2238
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2239
        (b'f', b'full', None, _(b'complete an entire path')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2240
        (b'n', b'normal', None, _(b'show only normal files')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2241
        (b'a', b'added', None, _(b'show only added files')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2242
        (b'r', b'removed', None, _(b'show only removed files')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2243
    ],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2244
    _(b'FILESPEC...'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2245
)
30940
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2246
def debugpathcomplete(ui, repo, *specs, **opts):
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2247
    '''complete part or all of a tracked path
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2248
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2249
    This command supports shells that offer path name completion. It
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2250
    currently completes only files already known to the dirstate.
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2251
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2252
    Completion extends only to the next path segment unless
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2253
    --full is specified, in which case entire paths are used.'''
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2254
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2255
    def complete(path, acceptable):
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2256
        dirstate = repo.dirstate
39818
24e493ec2229 py3: rename pycompat.getcwd() to encoding.getcwd() (API)
Matt Harbison <matt_harbison@yahoo.com>
parents: 39760
diff changeset
  2257
        spec = os.path.normpath(os.path.join(encoding.getcwd(), path))
30940
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2258
        rootdir = repo.root + pycompat.ossep
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2259
        if spec != repo.root and not spec.startswith(rootdir):
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2260
            return [], []
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2261
        if os.path.isdir(spec):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2262
            spec += b'/'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2263
        spec = spec[len(rootdir) :]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2264
        fixpaths = pycompat.ossep != b'/'
30940
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2265
        if fixpaths:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2266
            spec = spec.replace(pycompat.ossep, b'/')
30940
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2267
        speclen = len(spec)
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
  2268
        fullpaths = opts[r'full']
30940
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2269
        files, dirs = set(), set()
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2270
        adddir, addfile = dirs.add, files.add
43106
d783f945a701 py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43094
diff changeset
  2271
        for f, st in pycompat.iteritems(dirstate):
30940
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2272
            if f.startswith(spec) and st[0] in acceptable:
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2273
                if fixpaths:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2274
                    f = f.replace(b'/', pycompat.ossep)
30940
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2275
                if fullpaths:
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2276
                    addfile(f)
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2277
                    continue
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2278
                s = f.find(pycompat.ossep, speclen)
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2279
                if s >= 0:
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2280
                    adddir(f[:s])
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2281
                else:
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2282
                    addfile(f)
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2283
        return files, dirs
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2284
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2285
    acceptable = b''
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
  2286
    if opts[r'normal']:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2287
        acceptable += b'nm'
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
  2288
    if opts[r'added']:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2289
        acceptable += b'a'
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
  2290
    if opts[r'removed']:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2291
        acceptable += b'r'
30940
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2292
    cwd = repo.getcwd()
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2293
    if not specs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2294
        specs = [b'.']
30940
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2295
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2296
    files, dirs = set(), set()
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2297
    for spec in specs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2298
        f, d = complete(spec, acceptable or b'nmar')
30940
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2299
        files.update(f)
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2300
        dirs.update(d)
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2301
    files.update(dirs)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2302
    ui.write(b'\n'.join(repo.pathto(p, cwd) for p in sorted(files)))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2303
    ui.write(b'\n')
30940
c8081ea63591 debugcommands: move 'debugpathcomplete' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30939
diff changeset
  2304
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2305
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2306
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2307
    b'debugpathcopies',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2308
    cmdutil.walkopts,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2309
    b'hg debugpathcopies REV1 REV2 [FILE]',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2310
    inferrepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2311
)
41515
7dc160a57025 debugcommands: add a debugpathcopies command
Martin von Zweigbergk <martinvonz@google.com>
parents: 41365
diff changeset
  2312
def debugpathcopies(ui, repo, rev1, rev2, *pats, **opts):
7dc160a57025 debugcommands: add a debugpathcopies command
Martin von Zweigbergk <martinvonz@google.com>
parents: 41365
diff changeset
  2313
    """show copies between two revisions"""
7dc160a57025 debugcommands: add a debugpathcopies command
Martin von Zweigbergk <martinvonz@google.com>
parents: 41365
diff changeset
  2314
    ctx1 = scmutil.revsingle(repo, rev1)
7dc160a57025 debugcommands: add a debugpathcopies command
Martin von Zweigbergk <martinvonz@google.com>
parents: 41365
diff changeset
  2315
    ctx2 = scmutil.revsingle(repo, rev2)
7dc160a57025 debugcommands: add a debugpathcopies command
Martin von Zweigbergk <martinvonz@google.com>
parents: 41365
diff changeset
  2316
    m = scmutil.match(ctx1, pats, opts)
41749
f96988680afe debugpathcopies: sort output so it's deterministic
Martin von Zweigbergk <martinvonz@google.com>
parents: 41691
diff changeset
  2317
    for dst, src in sorted(copies.pathcopies(ctx1, ctx2, m).items()):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2318
        ui.write(b'%s -> %s\n' % (src, dst))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2319
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2320
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2321
@command(b'debugpeer', [], _(b'PATH'), norepo=True)
35929
5f029d03cf71 debugcommands: introduce debugpeer command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35902
diff changeset
  2322
def debugpeer(ui, path):
5f029d03cf71 debugcommands: introduce debugpeer command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35902
diff changeset
  2323
    """establish a connection to a peer repository"""
5f029d03cf71 debugcommands: introduce debugpeer command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35902
diff changeset
  2324
    # Always enable peer request logging. Requires --debug to display
5f029d03cf71 debugcommands: introduce debugpeer command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35902
diff changeset
  2325
    # though.
5f029d03cf71 debugcommands: introduce debugpeer command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35902
diff changeset
  2326
    overrides = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2327
        (b'devel', b'debug.peer-request'): True,
35929
5f029d03cf71 debugcommands: introduce debugpeer command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35902
diff changeset
  2328
    }
5f029d03cf71 debugcommands: introduce debugpeer command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35902
diff changeset
  2329
5f029d03cf71 debugcommands: introduce debugpeer command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35902
diff changeset
  2330
    with ui.configoverride(overrides):
5f029d03cf71 debugcommands: introduce debugpeer command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35902
diff changeset
  2331
        peer = hg.peer(ui, {}, path)
5f029d03cf71 debugcommands: introduce debugpeer command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35902
diff changeset
  2332
5f029d03cf71 debugcommands: introduce debugpeer command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35902
diff changeset
  2333
        local = peer.local() is not None
5f029d03cf71 debugcommands: introduce debugpeer command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35902
diff changeset
  2334
        canpush = peer.canpush()
5f029d03cf71 debugcommands: introduce debugpeer command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35902
diff changeset
  2335
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2336
        ui.write(_(b'url: %s\n') % peer.url())
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2337
        ui.write(_(b'local: %s\n') % (_(b'yes') if local else _(b'no')))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2338
        ui.write(_(b'pushable: %s\n') % (_(b'yes') if canpush else _(b'no')))
35929
5f029d03cf71 debugcommands: introduce debugpeer command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35902
diff changeset
  2339
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2340
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2341
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2342
    b'debugpickmergetool',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2343
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2344
        (b'r', b'rev', b'', _(b'check for files in this revision'), _(b'REV')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2345
        (b'', b'changedelete', None, _(b'emulate merging change and delete')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2346
    ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2347
    + cmdutil.walkopts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2348
    + cmdutil.mergetoolopts,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2349
    _(b'[PATTERN]...'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2350
    inferrepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2351
)
32256
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2352
def debugpickmergetool(ui, repo, *pats, **opts):
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2353
    """examine which merge tool is chosen for specified file
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2354
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2355
    As described in :hg:`help merge-tools`, Mercurial examines
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2356
    configurations below in this order to decide which merge tool is
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2357
    chosen for specified file.
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2358
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2359
    1. ``--tool`` option
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2360
    2. ``HGMERGE`` environment variable
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2361
    3. configurations in ``merge-patterns`` section
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2362
    4. configuration of ``ui.merge``
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2363
    5. configurations in ``merge-tools`` section
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2364
    6. ``hgmerge`` tool (for historical reason only)
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2365
    7. default tool for fallback (``:merge`` or ``:prompt``)
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2366
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2367
    This command writes out examination result in the style below::
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2368
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2369
        FILE = MERGETOOL
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2370
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2371
    By default, all files known in the first parent context of the
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2372
    working directory are examined. Use file patterns and/or -I/-X
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2373
    options to limit target files. -r/--rev is also useful to examine
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2374
    files in another context without actual updating to it.
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2375
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2376
    With --debug, this command shows warning messages while matching
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2377
    against ``merge-patterns`` and so on, too. It is recommended to
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2378
    use this option with explicit file patterns and/or -I/-X options,
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2379
    because this option increases amount of output per file according
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2380
    to configurations in hgrc.
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2381
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2382
    With -v/--verbose, this command shows configurations below at
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2383
    first (only if specified).
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2384
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2385
    - ``--tool`` option
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2386
    - ``HGMERGE`` environment variable
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2387
    - configuration of ``ui.merge``
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2388
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2389
    If merge tool is chosen before matching against
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2390
    ``merge-patterns``, this command can't show any helpful
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2391
    information, even with --debug. In such case, information above is
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2392
    useful to know why a merge tool is chosen.
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2393
    """
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
  2394
    opts = pycompat.byteskwargs(opts)
32256
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2395
    overrides = {}
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2396
    if opts[b'tool']:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2397
        overrides[(b'ui', b'forcemerge')] = opts[b'tool']
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2398
        ui.notenoi18n(b'with --tool %r\n' % (pycompat.bytestr(opts[b'tool'])))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2399
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2400
    with ui.configoverride(overrides, b'debugmergepatterns'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2401
        hgmerge = encoding.environ.get(b"HGMERGE")
32256
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2402
        if hgmerge is not None:
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2403
            ui.notenoi18n(b'with HGMERGE=%r\n' % (pycompat.bytestr(hgmerge)))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2404
        uimerge = ui.config(b"ui", b"merge")
32256
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2405
        if uimerge:
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2406
            ui.notenoi18n(b'with ui.merge=%r\n' % (pycompat.bytestr(uimerge)))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2407
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2408
        ctx = scmutil.revsingle(repo, opts.get(b'rev'))
32256
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2409
        m = scmutil.match(ctx, pats, opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2410
        changedelete = opts[b'changedelete']
32256
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2411
        for path in ctx.walk(m):
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2412
            fctx = ctx[path]
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2413
            try:
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2414
                if not ui.debugflag:
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2415
                    ui.pushbuffer(error=True)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2416
                tool, toolpath = filemerge._picktool(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2417
                    repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2418
                    ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2419
                    path,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2420
                    fctx.isbinary(),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2421
                    b'l' in fctx.flags(),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2422
                    changedelete,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2423
                )
32256
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2424
            finally:
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2425
                if not ui.debugflag:
9bc36198338e debugcommands: add debugpickmergetool to examine which merge tool is chosen
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 32229
diff changeset
  2426
                    ui.popbuffer()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2427
            ui.write(b'%s = %s\n' % (path, tool))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2428
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2429
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2430
@command(b'debugpushkey', [], _(b'REPO NAMESPACE [KEY OLD NEW]'), norepo=True)
30946
7103122495e2 debugcommands: move 'debugpushkey' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30940
diff changeset
  2431
def debugpushkey(ui, repopath, namespace, *keyinfo, **opts):
7103122495e2 debugcommands: move 'debugpushkey' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30940
diff changeset
  2432
    '''access the pushkey key/value protocol
7103122495e2 debugcommands: move 'debugpushkey' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30940
diff changeset
  2433
7103122495e2 debugcommands: move 'debugpushkey' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30940
diff changeset
  2434
    With two args, list the keys in the given namespace.
7103122495e2 debugcommands: move 'debugpushkey' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30940
diff changeset
  2435
7103122495e2 debugcommands: move 'debugpushkey' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30940
diff changeset
  2436
    With five args, set a key to new if it currently is set to old.
7103122495e2 debugcommands: move 'debugpushkey' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30940
diff changeset
  2437
    Reports success or failure.
7103122495e2 debugcommands: move 'debugpushkey' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30940
diff changeset
  2438
    '''
7103122495e2 debugcommands: move 'debugpushkey' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30940
diff changeset
  2439
7103122495e2 debugcommands: move 'debugpushkey' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30940
diff changeset
  2440
    target = hg.peer(ui, {}, repopath)
7103122495e2 debugcommands: move 'debugpushkey' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30940
diff changeset
  2441
    if keyinfo:
7103122495e2 debugcommands: move 'debugpushkey' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30940
diff changeset
  2442
        key, old, new = keyinfo
37647
516b5a5edae3 exchange: use command executor for pushkey
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37645
diff changeset
  2443
        with target.commandexecutor() as e:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2444
            r = e.callcommand(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2445
                b'pushkey',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2446
                {
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2447
                    b'namespace': namespace,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2448
                    b'key': key,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2449
                    b'old': old,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2450
                    b'new': new,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2451
                },
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2452
            ).result()
37647
516b5a5edae3 exchange: use command executor for pushkey
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37645
diff changeset
  2453
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2454
        ui.status(pycompat.bytestr(r) + b'\n')
30946
7103122495e2 debugcommands: move 'debugpushkey' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30940
diff changeset
  2455
        return not r
7103122495e2 debugcommands: move 'debugpushkey' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30940
diff changeset
  2456
    else:
43106
d783f945a701 py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43094
diff changeset
  2457
        for k, v in sorted(pycompat.iteritems(target.listkeys(namespace))):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2458
            ui.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2459
                b"%s\t%s\n" % (stringutil.escapestr(k), stringutil.escapestr(v))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2460
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2461
30946
7103122495e2 debugcommands: move 'debugpushkey' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30940
diff changeset
  2462
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2463
@command(b'debugpvec', [], _(b'A B'))
30947
3c766ca89377 debugcommands: move 'debugpvec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30946
diff changeset
  2464
def debugpvec(ui, repo, a, b=None):
3c766ca89377 debugcommands: move 'debugpvec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30946
diff changeset
  2465
    ca = scmutil.revsingle(repo, a)
3c766ca89377 debugcommands: move 'debugpvec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30946
diff changeset
  2466
    cb = scmutil.revsingle(repo, b)
3c766ca89377 debugcommands: move 'debugpvec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30946
diff changeset
  2467
    pa = pvec.ctxpvec(ca)
3c766ca89377 debugcommands: move 'debugpvec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30946
diff changeset
  2468
    pb = pvec.ctxpvec(cb)
3c766ca89377 debugcommands: move 'debugpvec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30946
diff changeset
  2469
    if pa == pb:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2470
        rel = b"="
30947
3c766ca89377 debugcommands: move 'debugpvec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30946
diff changeset
  2471
    elif pa > pb:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2472
        rel = b">"
30947
3c766ca89377 debugcommands: move 'debugpvec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30946
diff changeset
  2473
    elif pa < pb:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2474
        rel = b"<"
30947
3c766ca89377 debugcommands: move 'debugpvec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30946
diff changeset
  2475
    elif pa | pb:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2476
        rel = b"|"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2477
    ui.write(_(b"a: %s\n") % pa)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2478
    ui.write(_(b"b: %s\n") % pb)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2479
    ui.write(_(b"depth(a): %d depth(b): %d\n") % (pa._depth, pb._depth))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2480
    ui.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2481
        _(b"delta: %d hdist: %d distance: %d relation: %s\n")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2482
        % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2483
            abs(pa._depth - pb._depth),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2484
            pvec._hamming(pa._vec, pb._vec),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2485
            pa.distance(pb),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2486
            rel,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2487
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2488
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2489
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2490
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2491
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2492
    b'debugrebuilddirstate|debugrebuildstate',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2493
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2494
        (b'r', b'rev', b'', _(b'revision to rebuild to'), _(b'REV')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2495
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2496
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2497
            b'minimal',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2498
            None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2499
            _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2500
                b'only rebuild files that are inconsistent with '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2501
                b'the working copy parent'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2502
            ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2503
        ),
30948
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2504
    ],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2505
    _(b'[-r REV]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2506
)
30948
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2507
def debugrebuilddirstate(ui, repo, rev, **opts):
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2508
    """rebuild the dirstate as it would look like for the given revision
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2509
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2510
    If no revision is specified the first current parent will be used.
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2511
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2512
    The dirstate will be set to the files of the given revision.
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2513
    The actual working directory content or existing dirstate
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2514
    information such as adds or removes is not considered.
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2515
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2516
    ``minimal`` will only rebuild the dirstate status for files that claim to be
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2517
    tracked but are not in the parent manifest, or that exist in the parent
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2518
    manifest but are not in the dirstate. It will not change adds, removes, or
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2519
    modified files that are in the working copy parent.
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2520
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2521
    One use of this command is to make the next :hg:`status` invocation
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2522
    check the actual file content.
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2523
    """
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2524
    ctx = scmutil.revsingle(repo, rev)
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2525
    with repo.wlock():
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2526
        dirstate = repo.dirstate
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2527
        changedfiles = None
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2528
        # See command doc for what minimal does.
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
  2529
        if opts.get(r'minimal'):
30948
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2530
            manifestfiles = set(ctx.manifest().keys())
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2531
            dirstatefiles = set(dirstate)
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2532
            manifestonly = manifestfiles - dirstatefiles
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2533
            dsonly = dirstatefiles - manifestfiles
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2534
            dsnotadded = set(f for f in dsonly if dirstate[f] != b'a')
30948
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2535
            changedfiles = manifestonly | dsnotadded
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2536
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2537
        dirstate.rebuild(ctx.node(), ctx.manifest(), changedfiles)
cc2b537b1966 debugcommands: move 'debugrebuilddirstate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30947
diff changeset
  2538
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2539
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2540
@command(b'debugrebuildfncache', [], b'')
30949
e7d7335819f4 debugcommands: move 'debugrebuildfncache' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30948
diff changeset
  2541
def debugrebuildfncache(ui, repo):
e7d7335819f4 debugcommands: move 'debugrebuildfncache' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30948
diff changeset
  2542
    """rebuild the fncache file"""
e7d7335819f4 debugcommands: move 'debugrebuildfncache' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30948
diff changeset
  2543
    repair.rebuildfncache(ui, repo)
e7d7335819f4 debugcommands: move 'debugrebuildfncache' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30948
diff changeset
  2544
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2545
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2546
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2547
    b'debugrename',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2548
    [(b'r', b'rev', b'', _(b'revision to debug'), _(b'REV'))],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2549
    _(b'[-r REV] [FILE]...'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2550
)
41690
ea72da71ad69 debugrename: don't require at least one path
Martin von Zweigbergk <martinvonz@google.com>
parents: 41671
diff changeset
  2551
def debugrename(ui, repo, *pats, **opts):
30950
7236f949ce3f debugcommands: move 'debugrename' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30949
diff changeset
  2552
    """dump rename information"""
7236f949ce3f debugcommands: move 'debugrename' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30949
diff changeset
  2553
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
  2554
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2555
    ctx = scmutil.revsingle(repo, opts.get(b'rev'))
41690
ea72da71ad69 debugrename: don't require at least one path
Martin von Zweigbergk <martinvonz@google.com>
parents: 41671
diff changeset
  2556
    m = scmutil.match(ctx, pats, opts)
30950
7236f949ce3f debugcommands: move 'debugrename' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30949
diff changeset
  2557
    for abs in ctx.walk(m):
7236f949ce3f debugcommands: move 'debugrename' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30949
diff changeset
  2558
        fctx = ctx[abs]
7236f949ce3f debugcommands: move 'debugrename' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30949
diff changeset
  2559
        o = fctx.filelog().renamed(fctx.filenode())
41659
ecf7f4ef52fb debugwalk: avoid match.rel() and use repo.pathto() instead
Martin von Zweigbergk <martinvonz@google.com>
parents: 41636
diff changeset
  2560
        rel = repo.pathto(abs)
30950
7236f949ce3f debugcommands: move 'debugrename' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30949
diff changeset
  2561
        if o:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2562
            ui.write(_(b"%s renamed from %s:%s\n") % (rel, o[0], hex(o[1])))
30950
7236f949ce3f debugcommands: move 'debugrename' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30949
diff changeset
  2563
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2564
            ui.write(_(b"%s not renamed\n") % rel)
30950
7236f949ce3f debugcommands: move 'debugrename' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30949
diff changeset
  2565
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2566
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2567
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2568
    b'debugrevlog',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2569
    cmdutil.debugrevlogopts + [(b'd', b'dump', False, _(b'dump index data'))],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2570
    _(b'-c|-m|FILE'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2571
    optionalrepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2572
)
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2573
def debugrevlog(ui, repo, file_=None, **opts):
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2574
    """show data and statistics about a revlog"""
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
  2575
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2576
    r = cmdutil.openrevlog(repo, b'debugrevlog', file_, opts)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2577
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2578
    if opts.get(b"dump"):
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2579
        numrevs = len(r)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2580
        ui.write(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2581
            (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2582
                b"# rev p1rev p2rev start   end deltastart base   p1   p2"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2583
                b" rawsize totalsize compression heads chainlen\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2584
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2585
        )
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2586
        ts = 0
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2587
        heads = set()
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2588
38783
e7aa113b14f7 global: use pycompat.xrange()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38781
diff changeset
  2589
        for rev in pycompat.xrange(numrevs):
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2590
            dbase = r.deltaparent(rev)
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2591
            if dbase == -1:
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2592
                dbase = rev
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2593
            cbase = r.chainbase(rev)
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2594
            clen = r.chainlen(rev)
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2595
            p1, p2 = r.parentrevs(rev)
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2596
            rs = r.rawsize(rev)
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2597
            ts = ts + rs
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2598
            heads -= set(r.parentrevs(rev))
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2599
            heads.add(rev)
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2600
            try:
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2601
                compression = ts / r.end(rev)
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2602
            except ZeroDivisionError:
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2603
                compression = 0
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2604
            ui.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2605
                b"%5d %5d %5d %5d %5d %10d %4d %4d %4d %7d %9d "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2606
                b"%11d %5d %8d\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2607
                % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2608
                    rev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2609
                    p1,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2610
                    p2,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2611
                    r.start(rev),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2612
                    r.end(rev),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2613
                    r.start(dbase),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2614
                    r.start(cbase),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2615
                    r.start(p1),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2616
                    r.start(p2),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2617
                    rs,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2618
                    ts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2619
                    compression,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2620
                    len(heads),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2621
                    clen,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2622
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2623
            )
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2624
        return 0
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2625
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2626
    v = r.version
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2627
    format = v & 0xFFFF
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2628
    flags = []
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2629
    gdelta = False
32315
67026d65a4fc revlog: rename constants (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32265
diff changeset
  2630
    if v & revlog.FLAG_INLINE_DATA:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2631
        flags.append(b'inline')
32315
67026d65a4fc revlog: rename constants (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32265
diff changeset
  2632
    if v & revlog.FLAG_GENERALDELTA:
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2633
        gdelta = True
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2634
        flags.append(b'generaldelta')
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2635
    if not flags:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2636
        flags = [b'(none)']
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2637
39080
5c99486fcfe1 debugrevlog: document some of the variable used
Boris Feld <boris.feld@octobus.net>
parents: 39065
diff changeset
  2638
    ### tracks merge vs single parent
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2639
    nummerges = 0
39080
5c99486fcfe1 debugrevlog: document some of the variable used
Boris Feld <boris.feld@octobus.net>
parents: 39065
diff changeset
  2640
5c99486fcfe1 debugrevlog: document some of the variable used
Boris Feld <boris.feld@octobus.net>
parents: 39065
diff changeset
  2641
    ### tracks ways the "delta" are build
39081
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2642
    # nodelta
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2643
    numempty = 0
39082
a456c603a83d debugrevlog: display details about empty revision
Boris Feld <boris.feld@octobus.net>
parents: 39081
diff changeset
  2644
    numemptytext = 0
a456c603a83d debugrevlog: display details about empty revision
Boris Feld <boris.feld@octobus.net>
parents: 39081
diff changeset
  2645
    numemptydelta = 0
39080
5c99486fcfe1 debugrevlog: document some of the variable used
Boris Feld <boris.feld@octobus.net>
parents: 39065
diff changeset
  2646
    # full file content
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2647
    numfull = 0
39151
07b82f55f351 debugrevlog: include information about intermediate snapshots
Boris Feld <boris.feld@octobus.net>
parents: 39148
diff changeset
  2648
    # intermediate snapshot against a prior snapshot
07b82f55f351 debugrevlog: include information about intermediate snapshots
Boris Feld <boris.feld@octobus.net>
parents: 39148
diff changeset
  2649
    numsemi = 0
39153
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2650
    # snapshot count per depth
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2651
    numsnapdepth = collections.defaultdict(lambda: 0)
39080
5c99486fcfe1 debugrevlog: document some of the variable used
Boris Feld <boris.feld@octobus.net>
parents: 39065
diff changeset
  2652
    # delta against previous revision
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2653
    numprev = 0
39080
5c99486fcfe1 debugrevlog: document some of the variable used
Boris Feld <boris.feld@octobus.net>
parents: 39065
diff changeset
  2654
    # delta against first or second parent (not prev)
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2655
    nump1 = 0
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2656
    nump2 = 0
39080
5c99486fcfe1 debugrevlog: document some of the variable used
Boris Feld <boris.feld@octobus.net>
parents: 39065
diff changeset
  2657
    # delta against neither prev nor parents
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2658
    numother = 0
39080
5c99486fcfe1 debugrevlog: document some of the variable used
Boris Feld <boris.feld@octobus.net>
parents: 39065
diff changeset
  2659
    # delta against prev that are also first or second parent
5c99486fcfe1 debugrevlog: document some of the variable used
Boris Feld <boris.feld@octobus.net>
parents: 39065
diff changeset
  2660
    # (details of `numprev`)
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2661
    nump1prev = 0
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2662
    nump2prev = 0
39080
5c99486fcfe1 debugrevlog: document some of the variable used
Boris Feld <boris.feld@octobus.net>
parents: 39065
diff changeset
  2663
5c99486fcfe1 debugrevlog: document some of the variable used
Boris Feld <boris.feld@octobus.net>
parents: 39065
diff changeset
  2664
    # data about delta chain of each revs
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2665
    chainlengths = []
33057
03eefca3ed33 debugrevlog: also display the largest delta chain span
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33031
diff changeset
  2666
    chainbases = []
03eefca3ed33 debugrevlog: also display the largest delta chain span
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33031
diff changeset
  2667
    chainspans = []
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2668
39080
5c99486fcfe1 debugrevlog: document some of the variable used
Boris Feld <boris.feld@octobus.net>
parents: 39065
diff changeset
  2669
    # data about each revision
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2670
    datasize = [None, 0, 0]
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2671
    fullsize = [None, 0, 0]
39151
07b82f55f351 debugrevlog: include information about intermediate snapshots
Boris Feld <boris.feld@octobus.net>
parents: 39148
diff changeset
  2672
    semisize = [None, 0, 0]
39153
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2673
    # snapshot count per depth
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2674
    snapsizedepth = collections.defaultdict(lambda: [None, 0, 0])
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2675
    deltasize = [None, 0, 0]
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2676
    chunktypecounts = {}
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2677
    chunktypesizes = {}
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2678
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2679
    def addsize(size, l):
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2680
        if l[0] is None or size < l[0]:
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2681
            l[0] = size
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2682
        if size > l[1]:
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2683
            l[1] = size
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2684
        l[2] += size
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2685
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2686
    numrevs = len(r)
38783
e7aa113b14f7 global: use pycompat.xrange()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 38781
diff changeset
  2687
    for rev in pycompat.xrange(numrevs):
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2688
        p1, p2 = r.parentrevs(rev)
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2689
        delta = r.deltaparent(rev)
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2690
        if format > 0:
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2691
            addsize(r.rawsize(rev), datasize)
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2692
        if p2 != nullrev:
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2693
            nummerges += 1
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2694
        size = r.length(rev)
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2695
        if delta == nullrev:
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2696
            chainlengths.append(0)
33057
03eefca3ed33 debugrevlog: also display the largest delta chain span
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33031
diff changeset
  2697
            chainbases.append(r.start(rev))
03eefca3ed33 debugrevlog: also display the largest delta chain span
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33031
diff changeset
  2698
            chainspans.append(size)
39081
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2699
            if size == 0:
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2700
                numempty += 1
39082
a456c603a83d debugrevlog: display details about empty revision
Boris Feld <boris.feld@octobus.net>
parents: 39081
diff changeset
  2701
                numemptytext += 1
39081
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2702
            else:
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2703
                numfull += 1
39153
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2704
                numsnapdepth[0] += 1
39081
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2705
                addsize(size, fullsize)
39153
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2706
                addsize(size, snapsizedepth[0])
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2707
        else:
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2708
            chainlengths.append(chainlengths[delta] + 1)
33057
03eefca3ed33 debugrevlog: also display the largest delta chain span
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33031
diff changeset
  2709
            baseaddr = chainbases[delta]
03eefca3ed33 debugrevlog: also display the largest delta chain span
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33031
diff changeset
  2710
            revaddr = r.start(rev)
03eefca3ed33 debugrevlog: also display the largest delta chain span
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33031
diff changeset
  2711
            chainbases.append(baseaddr)
03eefca3ed33 debugrevlog: also display the largest delta chain span
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33031
diff changeset
  2712
            chainspans.append((revaddr - baseaddr) + size)
39081
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2713
            if size == 0:
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2714
                numempty += 1
39082
a456c603a83d debugrevlog: display details about empty revision
Boris Feld <boris.feld@octobus.net>
parents: 39081
diff changeset
  2715
                numemptydelta += 1
39151
07b82f55f351 debugrevlog: include information about intermediate snapshots
Boris Feld <boris.feld@octobus.net>
parents: 39148
diff changeset
  2716
            elif r.issnapshot(rev):
07b82f55f351 debugrevlog: include information about intermediate snapshots
Boris Feld <boris.feld@octobus.net>
parents: 39148
diff changeset
  2717
                addsize(size, semisize)
07b82f55f351 debugrevlog: include information about intermediate snapshots
Boris Feld <boris.feld@octobus.net>
parents: 39148
diff changeset
  2718
                numsemi += 1
39153
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2719
                depth = r.snapshotdepth(rev)
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2720
                numsnapdepth[depth] += 1
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2721
                addsize(size, snapsizedepth[depth])
39081
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2722
            else:
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2723
                addsize(size, deltasize)
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2724
                if delta == rev - 1:
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2725
                    numprev += 1
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2726
                    if delta == p1:
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2727
                        nump1prev += 1
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2728
                    elif delta == p2:
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2729
                        nump2prev += 1
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2730
                elif delta == p1:
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2731
                    nump1 += 1
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2732
                elif delta == p2:
39081
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2733
                    nump2 += 1
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2734
                elif delta != nullrev:
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2735
                    numother += 1
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2736
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2737
        # Obtain data on the raw chunks in the revlog.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2738
        if util.safehasattr(r, b'_getsegmentforrevs'):
39148
1464183343b3 debugrevlog: fix for non-manifest object
Boris Feld <boris.feld@octobus.net>
parents: 39082
diff changeset
  2739
            segment = r._getsegmentforrevs(rev, rev)[1]
1464183343b3 debugrevlog: fix for non-manifest object
Boris Feld <boris.feld@octobus.net>
parents: 39082
diff changeset
  2740
        else:
1464183343b3 debugrevlog: fix for non-manifest object
Boris Feld <boris.feld@octobus.net>
parents: 39082
diff changeset
  2741
            segment = r._revlog._getsegmentforrevs(rev, rev)[1]
32229
75e93d95aae6 revlog: rename _chunkraw to _getsegmentforrevs()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 32209
diff changeset
  2742
        if segment:
33106
2f812b0d1936 py3: pass the memoryview object into bytes() to get the value
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33102
diff changeset
  2743
            chunktype = bytes(segment[0:1])
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2744
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2745
            chunktype = b'empty'
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2746
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2747
        if chunktype not in chunktypecounts:
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2748
            chunktypecounts[chunktype] = 0
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2749
            chunktypesizes[chunktype] = 0
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2750
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2751
        chunktypecounts[chunktype] += 1
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2752
        chunktypesizes[chunktype] += size
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2753
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2754
    # Adjust size min value for empty cases
39151
07b82f55f351 debugrevlog: include information about intermediate snapshots
Boris Feld <boris.feld@octobus.net>
parents: 39148
diff changeset
  2755
    for size in (datasize, fullsize, semisize, deltasize):
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2756
        if size[0] is None:
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2757
            size[0] = 0
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2758
39151
07b82f55f351 debugrevlog: include information about intermediate snapshots
Boris Feld <boris.feld@octobus.net>
parents: 39148
diff changeset
  2759
    numdeltas = numrevs - numfull - numempty - numsemi
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2760
    numoprev = numprev - nump1prev - nump2prev
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2761
    totalrawsize = datasize[2]
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2762
    datasize[2] /= numrevs
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2763
    fulltotal = fullsize[2]
42554
30033d56758f debugrevlog: fix average size computation for empty data (issue6167)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42145
diff changeset
  2764
    if numfull == 0:
30033d56758f debugrevlog: fix average size computation for empty data (issue6167)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42145
diff changeset
  2765
        fullsize[2] = 0
30033d56758f debugrevlog: fix average size computation for empty data (issue6167)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42145
diff changeset
  2766
    else:
30033d56758f debugrevlog: fix average size computation for empty data (issue6167)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42145
diff changeset
  2767
        fullsize[2] /= numfull
39151
07b82f55f351 debugrevlog: include information about intermediate snapshots
Boris Feld <boris.feld@octobus.net>
parents: 39148
diff changeset
  2768
    semitotal = semisize[2]
39153
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2769
    snaptotal = {}
40029
e2697acd9381 cleanup: some Yoda conditions, this patch removes
Martin von Zweigbergk <martinvonz@google.com>
parents: 40017
diff changeset
  2770
    if numsemi > 0:
39151
07b82f55f351 debugrevlog: include information about intermediate snapshots
Boris Feld <boris.feld@octobus.net>
parents: 39148
diff changeset
  2771
        semisize[2] /= numsemi
39153
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2772
    for depth in snapsizedepth:
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2773
        snaptotal[depth] = snapsizedepth[depth][2]
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2774
        snapsizedepth[depth][2] /= numsnapdepth[depth]
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2775
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2776
    deltatotal = deltasize[2]
39081
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2777
    if numdeltas > 0:
195ed920653e debugrevlog: track empty revlog entries
Boris Feld <boris.feld@octobus.net>
parents: 39080
diff changeset
  2778
        deltasize[2] /= numdeltas
39151
07b82f55f351 debugrevlog: include information about intermediate snapshots
Boris Feld <boris.feld@octobus.net>
parents: 39148
diff changeset
  2779
    totalsize = fulltotal + semitotal + deltatotal
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2780
    avgchainlen = sum(chainlengths) / numrevs
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2781
    maxchainlen = max(chainlengths)
33057
03eefca3ed33 debugrevlog: also display the largest delta chain span
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 33031
diff changeset
  2782
    maxchainspan = max(chainspans)
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2783
    compratio = 1
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2784
    if totalsize:
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2785
        compratio = totalrawsize / totalsize
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2786
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2787
    basedfmtstr = b'%%%dd\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2788
    basepcfmtstr = b'%%%dd %s(%%5.2f%%%%)\n'
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2789
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2790
    def dfmtstr(max):
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2791
        return basedfmtstr % len(str(max))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2792
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2793
    def pcfmtstr(max, padding=0):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2794
        return basepcfmtstr % (len(str(max)), b' ' * padding)
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2795
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2796
    def pcfmt(value, total):
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2797
        if total:
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2798
            return (value, 100 * float(value) / total)
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2799
        else:
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2800
            return value, 100.0
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2801
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2802
    ui.writenoi18n(b'format : %d\n' % format)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2803
    ui.writenoi18n(b'flags  : %s\n' % b', '.join(flags))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2804
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2805
    ui.write(b'\n')
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2806
    fmt = pcfmtstr(totalsize)
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2807
    fmt2 = dfmtstr(totalsize)
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2808
    ui.writenoi18n(b'revisions     : ' + fmt2 % numrevs)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2809
    ui.writenoi18n(b'    merges    : ' + fmt % pcfmt(nummerges, numrevs))
43094
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  2810
    ui.writenoi18n(
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  2811
        b'    normal    : ' + fmt % pcfmt(numrevs - nummerges, numrevs)
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  2812
    )
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2813
    ui.writenoi18n(b'revisions     : ' + fmt2 % numrevs)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2814
    ui.writenoi18n(b'    empty     : ' + fmt % pcfmt(numempty, numrevs))
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2815
    ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2816
        b'                   text  : '
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2817
        + fmt % pcfmt(numemptytext, numemptytext + numemptydelta)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2818
    )
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2819
    ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2820
        b'                   delta : '
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2821
        + fmt % pcfmt(numemptydelta, numemptytext + numemptydelta)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2822
    )
43094
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  2823
    ui.writenoi18n(
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  2824
        b'    snapshot  : ' + fmt % pcfmt(numfull + numsemi, numrevs)
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  2825
    )
39153
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2826
    for depth in sorted(numsnapdepth):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2827
        ui.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2828
            (b'      lvl-%-3d :       ' % depth)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2829
            + fmt % pcfmt(numsnapdepth[depth], numrevs)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2830
        )
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2831
    ui.writenoi18n(b'    deltas    : ' + fmt % pcfmt(numdeltas, numrevs))
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2832
    ui.writenoi18n(b'revision size : ' + fmt2 % totalsize)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2833
    ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2834
        b'    snapshot  : ' + fmt % pcfmt(fulltotal + semitotal, totalsize)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2835
    )
39153
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2836
    for depth in sorted(numsnapdepth):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2837
        ui.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2838
            (b'      lvl-%-3d :       ' % depth)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2839
            + fmt % pcfmt(snaptotal[depth], totalsize)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2840
        )
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2841
    ui.writenoi18n(b'    deltas    : ' + fmt % pcfmt(deltatotal, totalsize))
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2842
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2843
    def fmtchunktype(chunktype):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2844
        if chunktype == b'empty':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2845
            return b'    %s     : ' % chunktype
33107
e88fdec9cb9e py3: use pycompat.bytestr() to convert str to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33106
diff changeset
  2846
        elif chunktype in pycompat.bytestr(string.ascii_letters):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2847
            return b'    0x%s (%s)  : ' % (hex(chunktype), chunktype)
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2848
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2849
            return b'    0x%s      : ' % hex(chunktype)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2850
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2851
    ui.write(b'\n')
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2852
    ui.writenoi18n(b'chunks        : ' + fmt2 % numrevs)
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2853
    for chunktype in sorted(chunktypecounts):
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2854
        ui.write(fmtchunktype(chunktype))
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2855
        ui.write(fmt % pcfmt(chunktypecounts[chunktype], numrevs))
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2856
    ui.writenoi18n(b'chunks size   : ' + fmt2 % totalsize)
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2857
    for chunktype in sorted(chunktypecounts):
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2858
        ui.write(fmtchunktype(chunktype))
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2859
        ui.write(fmt % pcfmt(chunktypesizes[chunktype], totalsize))
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2860
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2861
    ui.write(b'\n')
33062
e21b750c9b9e debugrevlog: align chain length, reach, and compression ratio
Yuya Nishihara <yuya@tcha.org>
parents: 33057
diff changeset
  2862
    fmt = dfmtstr(max(avgchainlen, maxchainlen, maxchainspan, compratio))
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2863
    ui.writenoi18n(b'avg chain length  : ' + fmt % avgchainlen)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2864
    ui.writenoi18n(b'max chain length  : ' + fmt % maxchainlen)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2865
    ui.writenoi18n(b'max chain reach   : ' + fmt % maxchainspan)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2866
    ui.writenoi18n(b'compression ratio : ' + fmt % compratio)
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2867
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2868
    if format > 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2869
        ui.write(b'\n')
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2870
        ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2871
            b'uncompressed data size (min/max/avg) : %d / %d / %d\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2872
            % tuple(datasize)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2873
        )
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2874
    ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2875
        b'full revision size (min/max/avg)     : %d / %d / %d\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2876
        % tuple(fullsize)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2877
    )
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2878
    ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2879
        b'inter-snapshot size (min/max/avg)    : %d / %d / %d\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2880
        % tuple(semisize)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2881
    )
39153
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2882
    for depth in sorted(snapsizedepth):
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2883
        if depth == 0:
9d6fab487c13 debugrevlog: display snapshot details per depth
Boris Feld <boris.feld@octobus.net>
parents: 39151
diff changeset
  2884
            continue
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2885
        ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2886
            b'    level-%-3d (min/max/avg)          : %d / %d / %d\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2887
            % ((depth,) + tuple(snapsizedepth[depth]))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2888
        )
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2889
    ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2890
        b'delta size (min/max/avg)             : %d / %d / %d\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2891
        % tuple(deltasize)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2892
    )
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2893
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2894
    if numdeltas > 0:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2895
        ui.write(b'\n')
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2896
        fmt = pcfmtstr(numdeltas)
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2897
        fmt2 = pcfmtstr(numdeltas, 4)
43094
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  2898
        ui.writenoi18n(
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  2899
            b'deltas against prev  : ' + fmt % pcfmt(numprev, numdeltas)
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  2900
        )
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2901
        if numprev > 0:
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2902
            ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2903
                b'    where prev = p1  : ' + fmt2 % pcfmt(nump1prev, numprev)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2904
            )
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2905
            ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2906
                b'    where prev = p2  : ' + fmt2 % pcfmt(nump2prev, numprev)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2907
            )
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2908
            ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2909
                b'    other            : ' + fmt2 % pcfmt(numoprev, numprev)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2910
            )
30951
f44b96aef81b debugcommands: move 'debugrevlog' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30950
diff changeset
  2911
        if gdelta:
43094
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  2912
            ui.writenoi18n(
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  2913
                b'deltas against p1    : ' + fmt % pcfmt(nump1, numdeltas)
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  2914
            )
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  2915
            ui.writenoi18n(
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  2916
                b'deltas against p2    : ' + fmt % pcfmt(nump2, numdeltas)
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  2917
            )
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2918
            ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2919
                b'deltas against other : ' + fmt % pcfmt(numother, numdeltas)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2920
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2921
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2922
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2923
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2924
    b'debugrevlogindex',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2925
    cmdutil.debugrevlogopts
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2926
    + [(b'f', b'format', 0, _(b'revlog format'), _(b'FORMAT'))],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2927
    _(b'[-f FORMAT] -c|-m|FILE'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2928
    optionalrepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2929
)
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2930
def debugrevlogindex(ui, repo, file_=None, **opts):
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2931
    """dump the contents of a revlog index"""
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2932
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2933
    r = cmdutil.openrevlog(repo, b'debugrevlogindex', file_, opts)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2934
    format = opts.get(b'format', 0)
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2935
    if format not in (0, 1):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2936
        raise error.Abort(_(b"unknown format %d") % format)
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2937
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2938
    if ui.debugflag:
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2939
        shortfn = hex
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2940
    else:
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2941
        shortfn = short
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2942
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2943
    # There might not be anything in r, so have a sane default
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2944
    idlen = 12
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2945
    for i in r:
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2946
        idlen = len(shortfn(r.node(i)))
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2947
        break
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2948
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2949
    if format == 0:
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2950
        if ui.verbose:
43116
defabf63e969 debugcommands: add a few more writenoi18n()
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
  2951
            ui.writenoi18n(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43116
diff changeset
  2952
                b"   rev    offset  length linkrev %s %s p2\n"
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2953
                % (b"nodeid".ljust(idlen), b"p1".ljust(idlen))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2954
            )
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2955
        else:
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2956
            ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2957
                b"   rev linkrev %s %s p2\n"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2958
                % (b"nodeid".ljust(idlen), b"p1".ljust(idlen))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2959
            )
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2960
    elif format == 1:
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2961
        if ui.verbose:
43116
defabf63e969 debugcommands: add a few more writenoi18n()
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
  2962
            ui.writenoi18n(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2963
                (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2964
                    b"   rev flag   offset   length     size   link     p1"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2965
                    b"     p2 %s\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2966
                )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2967
                % b"nodeid".rjust(idlen)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2968
            )
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2969
        else:
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  2970
            ui.writenoi18n(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2971
                b"   rev flag     size   link     p1     p2 %s\n"
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2972
                % b"nodeid".rjust(idlen)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2973
            )
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2974
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2975
    for i in r:
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2976
        node = r.node(i)
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2977
        if format == 0:
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2978
            try:
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2979
                pp = r.parents(node)
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2980
            except Exception:
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2981
                pp = [nullid, nullid]
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2982
            if ui.verbose:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2983
                ui.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2984
                    b"% 6d % 9d % 7d % 7d %s %s %s\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2985
                    % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2986
                        i,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2987
                        r.start(i),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2988
                        r.length(i),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2989
                        r.linkrev(i),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2990
                        shortfn(node),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2991
                        shortfn(pp[0]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2992
                        shortfn(pp[1]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2993
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2994
                )
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  2995
            else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2996
                ui.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  2997
                    b"% 6d % 7d %s %s %s\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2998
                    % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  2999
                        i,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3000
                        r.linkrev(i),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3001
                        shortfn(node),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3002
                        shortfn(pp[0]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3003
                        shortfn(pp[1]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3004
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3005
                )
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  3006
        elif format == 1:
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  3007
            pr = r.parentrevs(i)
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  3008
            if ui.verbose:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3009
                ui.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3010
                    b"% 6d %04x % 8d % 8d % 8d % 6d % 6d % 6d %s\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3011
                    % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3012
                        i,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3013
                        r.flags(i),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3014
                        r.start(i),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3015
                        r.length(i),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3016
                        r.rawsize(i),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3017
                        r.linkrev(i),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3018
                        pr[0],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3019
                        pr[1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3020
                        shortfn(node),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3021
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3022
                )
39282
828a45233036 debugcommands: introduce debugrevlogindex (BC)
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39281
diff changeset
  3023
            else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3024
                ui.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3025
                    b"% 6d %04x % 8d % 6d % 6d % 6d %s\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3026
                    % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3027
                        i,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3028
                        r.flags(i),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3029
                        r.rawsize(i),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3030
                        r.linkrev(i),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3031
                        pr[0],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3032
                        pr[1],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3033
                        shortfn(node),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3034
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3035
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3036
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3037
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3038
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3039
    b'debugrevspec',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3040
    [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3041
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3042
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3043
            b'optimize',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3044
            None,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3045
            _(b'print parsed tree after optimizing (DEPRECATED)'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3046
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3047
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3048
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3049
            b'show-revs',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3050
            True,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3051
            _(b'print list of result revisions (default)'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3052
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3053
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3054
            b's',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3055
            b'show-set',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3056
            None,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3057
            _(b'print internal representation of result set'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3058
        ),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3059
        (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3060
            b'p',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3061
            b'show-stage',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3062
            [],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3063
            _(b'print parsed tree at the given stage'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3064
            _(b'NAME'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3065
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3066
        (b'', b'no-optimized', False, _(b'evaluate tree without optimization')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3067
        (b'', b'verify-optimized', False, _(b'verify optimized result')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3068
    ],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3069
    b'REVSPEC',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3070
)
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3071
def debugrevspec(ui, repo, expr, **opts):
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3072
    """parse and apply a revision specification
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3073
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3074
    Use -p/--show-stage option to print the parsed tree at the given stages.
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3075
    Use -p all to print tree at every stage.
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3076
32797
bcca357bb792 debugrevspec: add option to suppress list of computed revisions
Yuya Nishihara <yuya@tcha.org>
parents: 32796
diff changeset
  3077
    Use --no-show-revs option with -s or -p to print only the set
bcca357bb792 debugrevspec: add option to suppress list of computed revisions
Yuya Nishihara <yuya@tcha.org>
parents: 32796
diff changeset
  3078
    representation or the parsed tree respectively.
bcca357bb792 debugrevspec: add option to suppress list of computed revisions
Yuya Nishihara <yuya@tcha.org>
parents: 32796
diff changeset
  3079
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3080
    Use --verify-optimized to compare the optimized result with the unoptimized
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3081
    one. Returns 1 if the optimized result differs.
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3082
    """
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
  3083
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3084
    aliases = ui.configitems(b'revsetalias')
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3085
    stages = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3086
        (b'parsed', lambda tree: tree),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3087
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3088
            b'expanded',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3089
            lambda tree: revsetlang.expandaliases(tree, aliases, ui.warn),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3090
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3091
        (b'concatenated', revsetlang.foldconcat),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3092
        (b'analyzed', revsetlang.analyze),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3093
        (b'optimized', revsetlang.optimize),
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3094
    ]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3095
    if opts[b'no_optimized']:
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3096
        stages = stages[:-1]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3097
    if opts[b'verify_optimized'] and opts[b'no_optimized']:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3098
        raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43116
diff changeset
  3099
            _(b'cannot use --verify-optimized with --no-optimized')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3100
        )
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3101
    stagenames = set(n for n, f in stages)
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3102
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3103
    showalways = set()
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3104
    showchanged = set()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3105
    if ui.verbose and not opts[b'show_stage']:
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3106
        # show parsed tree by --verbose (deprecated)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3107
        showalways.add(b'parsed')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3108
        showchanged.update([b'expanded', b'concatenated'])
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3109
        if opts[b'optimize']:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3110
            showalways.add(b'optimized')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3111
    if opts[b'show_stage'] and opts[b'optimize']:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3112
        raise error.Abort(_(b'cannot use --optimize with --show-stage'))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3113
    if opts[b'show_stage'] == [b'all']:
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3114
        showalways.update(stagenames)
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3115
    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3116
        for n in opts[b'show_stage']:
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3117
            if n not in stagenames:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3118
                raise error.Abort(_(b'invalid stage name: %s') % n)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3119
        showalways.update(opts[b'show_stage'])
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3120
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3121
    treebystage = {}
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3122
    printedtree = None
37350
e32dfff71529 revset: use revsymbol() for checking if a symbol is valid
Martin von Zweigbergk <martinvonz@google.com>
parents: 37322
diff changeset
  3123
    tree = revsetlang.parse(expr, lookup=revset.lookupfn(repo))
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3124
    for n, f in stages:
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3125
        treebystage[n] = tree = f(tree)
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3126
        if n in showalways or (n in showchanged and tree != printedtree):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3127
            if opts[b'show_stage'] or n != b'parsed':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3128
                ui.write(b"* %s:\n" % n)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3129
            ui.write(revsetlang.prettyformat(tree), b"\n")
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3130
            printedtree = tree
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3131
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3132
    if opts[b'verify_optimized']:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3133
        arevs = revset.makematcher(treebystage[b'analyzed'])(repo)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3134
        brevs = revset.makematcher(treebystage[b'optimized'])(repo)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3135
        if opts[b'show_set'] or (opts[b'show_set'] is None and ui.verbose):
43094
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  3136
            ui.writenoi18n(
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  3137
                b"* analyzed set:\n", stringutil.prettyrepr(arevs), b"\n"
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  3138
            )
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  3139
            ui.writenoi18n(
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  3140
                b"* optimized set:\n", stringutil.prettyrepr(brevs), b"\n"
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  3141
            )
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3142
        arevs = list(arevs)
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3143
        brevs = list(brevs)
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3144
        if arevs == brevs:
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3145
            return 0
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  3146
        ui.writenoi18n(b'--- analyzed\n', label=b'diff.file_a')
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  3147
        ui.writenoi18n(b'+++ optimized\n', label=b'diff.file_b')
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3148
        sm = difflib.SequenceMatcher(None, arevs, brevs)
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3149
        for tag, alo, ahi, blo, bhi in sm.get_opcodes():
41671
34ae00a14783 py3: use raw strings and %d for formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41659
diff changeset
  3150
            if tag in (r'delete', r'replace'):
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3151
                for c in arevs[alo:ahi]:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3152
                    ui.write(b'-%d\n' % c, label=b'diff.deleted')
41671
34ae00a14783 py3: use raw strings and %d for formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41659
diff changeset
  3153
            if tag in (r'insert', r'replace'):
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3154
                for c in brevs[blo:bhi]:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3155
                    ui.write(b'+%d\n' % c, label=b'diff.inserted')
41671
34ae00a14783 py3: use raw strings and %d for formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents: 41659
diff changeset
  3156
            if tag == r'equal':
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3157
                for c in arevs[alo:ahi]:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3158
                    ui.write(b' %d\n' % c)
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3159
        return 1
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3160
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3161
    func = revset.makematcher(tree)
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3162
    revs = func(repo)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3163
    if opts[b'show_set'] or (opts[b'show_set'] is None and ui.verbose):
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  3164
        ui.writenoi18n(b"* set:\n", stringutil.prettyrepr(revs), b"\n")
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3165
    if not opts[b'show_revs']:
32797
bcca357bb792 debugrevspec: add option to suppress list of computed revisions
Yuya Nishihara <yuya@tcha.org>
parents: 32796
diff changeset
  3166
        return
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3167
    for c in revs:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3168
        ui.write(b"%d\n" % c)
30952
85c3c879c43a debugcommands: move 'debugrevspec' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30951
diff changeset
  3169
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3170
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3171
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3172
    b'debugserve',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3173
    [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3174
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3175
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3176
            b'sshstdio',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3177
            False,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3178
            _(b'run an SSH server bound to process handles'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3179
        ),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3180
        (b'', b'logiofd', b'', _(b'file descriptor to log server I/O to')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3181
        (b'', b'logiofile', b'', _(b'file to log server I/O to')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3182
    ],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3183
    b'',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3184
)
36527
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3185
def debugserve(ui, repo, **opts):
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3186
    """run a server with advanced settings
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3187
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3188
    This command is similar to :hg:`serve`. It exists partially as a
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3189
    workaround to the fact that ``hg serve --stdio`` must have specific
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3190
    arguments for security reasons.
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3191
    """
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3192
    opts = pycompat.byteskwargs(opts)
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3193
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3194
    if not opts[b'sshstdio']:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3195
        raise error.Abort(_(b'only --sshstdio is currently supported'))
36527
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3196
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3197
    logfh = None
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3198
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3199
    if opts[b'logiofd'] and opts[b'logiofile']:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3200
        raise error.Abort(_(b'cannot use both --logiofd and --logiofile'))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3201
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3202
    if opts[b'logiofd']:
36527
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3203
        # Line buffered because output is line based.
38313
275cc461b854 debugcommands: work around logiofd being a pipe and unseekable
Augie Fackler <augie@google.com>
parents: 38263
diff changeset
  3204
        try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3205
            logfh = os.fdopen(int(opts[b'logiofd']), r'ab', 1)
38313
275cc461b854 debugcommands: work around logiofd being a pipe and unseekable
Augie Fackler <augie@google.com>
parents: 38263
diff changeset
  3206
        except OSError as e:
275cc461b854 debugcommands: work around logiofd being a pipe and unseekable
Augie Fackler <augie@google.com>
parents: 38263
diff changeset
  3207
            if e.errno != errno.ESPIPE:
275cc461b854 debugcommands: work around logiofd being a pipe and unseekable
Augie Fackler <augie@google.com>
parents: 38263
diff changeset
  3208
                raise
275cc461b854 debugcommands: work around logiofd being a pipe and unseekable
Augie Fackler <augie@google.com>
parents: 38263
diff changeset
  3209
            # can't seek a pipe, so `ab` mode fails on py3
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3210
            logfh = os.fdopen(int(opts[b'logiofd']), r'wb', 1)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3211
    elif opts[b'logiofile']:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3212
        logfh = open(opts[b'logiofile'], b'ab', 1)
36527
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3213
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3214
    s = wireprotoserver.sshserver(ui, repo, logfh=logfh)
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3215
    s.serve_forever()
44dc34b8d17b debugcommands: add debugserve command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36492
diff changeset
  3216
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3217
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3218
@command(b'debugsetparents', [], _(b'REV1 [REV2]'))
30953
5b09e9bc0902 debugcommands: move 'debugsetparents' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30952
diff changeset
  3219
def debugsetparents(ui, repo, rev1, rev2=None):
5b09e9bc0902 debugcommands: move 'debugsetparents' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30952
diff changeset
  3220
    """manually set the parents of the current working directory
5b09e9bc0902 debugcommands: move 'debugsetparents' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30952
diff changeset
  3221
5b09e9bc0902 debugcommands: move 'debugsetparents' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30952
diff changeset
  3222
    This is useful for writing repository conversion tools, but should
5b09e9bc0902 debugcommands: move 'debugsetparents' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30952
diff changeset
  3223
    be used with care. For example, neither the working directory nor the
5b09e9bc0902 debugcommands: move 'debugsetparents' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30952
diff changeset
  3224
    dirstate is updated, so file status may be incorrect after running this
5b09e9bc0902 debugcommands: move 'debugsetparents' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30952
diff changeset
  3225
    command.
5b09e9bc0902 debugcommands: move 'debugsetparents' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30952
diff changeset
  3226
5b09e9bc0902 debugcommands: move 'debugsetparents' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30952
diff changeset
  3227
    Returns 0 on success.
5b09e9bc0902 debugcommands: move 'debugsetparents' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30952
diff changeset
  3228
    """
5b09e9bc0902 debugcommands: move 'debugsetparents' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30952
diff changeset
  3229
37143
8bac14ce5778 debugsetparents: avoid using "r1/r2" variable names for nodeids
Martin von Zweigbergk <martinvonz@google.com>
parents: 37120
diff changeset
  3230
    node1 = scmutil.revsingle(repo, rev1).node()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3231
    node2 = scmutil.revsingle(repo, rev2, b'null').node()
30953
5b09e9bc0902 debugcommands: move 'debugsetparents' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30952
diff changeset
  3232
5b09e9bc0902 debugcommands: move 'debugsetparents' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30952
diff changeset
  3233
    with repo.wlock():
37143
8bac14ce5778 debugsetparents: avoid using "r1/r2" variable names for nodeids
Martin von Zweigbergk <martinvonz@google.com>
parents: 37120
diff changeset
  3234
        repo.setparents(node1, node2)
30953
5b09e9bc0902 debugcommands: move 'debugsetparents' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30952
diff changeset
  3235
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3236
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3237
@command(b'debugsidedata', cmdutil.debugrevlogopts, _(b'-c|-m|FILE REV'))
43041
559ac8411f12 sidedata: add a debugsidedata command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42926
diff changeset
  3238
def debugsidedata(ui, repo, file_, rev=None, **opts):
559ac8411f12 sidedata: add a debugsidedata command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42926
diff changeset
  3239
    """dump the side data for a cl/manifest/file revision"""
559ac8411f12 sidedata: add a debugsidedata command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42926
diff changeset
  3240
    opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3241
    if opts.get(b'changelog') or opts.get(b'manifest') or opts.get(b'dir'):
43041
559ac8411f12 sidedata: add a debugsidedata command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42926
diff changeset
  3242
        if rev is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3243
            raise error.CommandError(b'debugdata', _(b'invalid arguments'))
43041
559ac8411f12 sidedata: add a debugsidedata command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42926
diff changeset
  3244
        file_, rev = None, file_
559ac8411f12 sidedata: add a debugsidedata command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42926
diff changeset
  3245
    elif rev is None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3246
        raise error.CommandError(b'debugdata', _(b'invalid arguments'))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3247
    r = cmdutil.openstorage(repo, b'debugdata', file_, opts)
43041
559ac8411f12 sidedata: add a debugsidedata command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42926
diff changeset
  3248
    r = getattr(r, '_revlog', r)
559ac8411f12 sidedata: add a debugsidedata command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42926
diff changeset
  3249
    try:
559ac8411f12 sidedata: add a debugsidedata command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42926
diff changeset
  3250
        sidedata = r.sidedata(r.lookup(rev))
559ac8411f12 sidedata: add a debugsidedata command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42926
diff changeset
  3251
    except KeyError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3252
        raise error.Abort(_(b'invalid revision identifier %s') % rev)
43041
559ac8411f12 sidedata: add a debugsidedata command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42926
diff changeset
  3253
    if sidedata:
559ac8411f12 sidedata: add a debugsidedata command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42926
diff changeset
  3254
        sidedata = list(sidedata.items())
559ac8411f12 sidedata: add a debugsidedata command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42926
diff changeset
  3255
        sidedata.sort()
43116
defabf63e969 debugcommands: add a few more writenoi18n()
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
  3256
        ui.writenoi18n(b'%d sidedata entries\n' % len(sidedata))
43041
559ac8411f12 sidedata: add a debugsidedata command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42926
diff changeset
  3257
        for key, value in sidedata:
43116
defabf63e969 debugcommands: add a few more writenoi18n()
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
  3258
            ui.writenoi18n(b' entry-%04o size %d\n' % (key, len(value)))
43041
559ac8411f12 sidedata: add a debugsidedata command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42926
diff changeset
  3259
            if ui.verbose:
43116
defabf63e969 debugcommands: add a few more writenoi18n()
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
  3260
                ui.writenoi18n(b'  %s\n' % stringutil.pprint(value))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3261
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3262
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3263
@command(b'debugssl', [], b'[SOURCE]', optionalrepo=True)
33493
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3264
def debugssl(ui, repo, source=None, **opts):
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3265
    '''test a secure connection to a server
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3266
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3267
    This builds the certificate chain for the server on Windows, installing the
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3268
    missing intermediates and trusted root via Windows Update if necessary.  It
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3269
    does nothing on other platforms.
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3270
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3271
    If SOURCE is omitted, the 'default' path will be used.  If a URL is given,
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3272
    that server is used. See :hg:`help urls` for more information.
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3273
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3274
    If the update succeeds, retry the original operation.  Otherwise, the cause
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3275
    of the SSL error is likely another issue.
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3276
    '''
34645
75979c8d4572 codemod: use pycompat.iswindows
Jun Wu <quark@fb.com>
parents: 34320
diff changeset
  3277
    if not pycompat.iswindows:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3278
        raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43116
diff changeset
  3279
            _(b'certificate chain building is only possible on Windows')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3280
        )
33493
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3281
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3282
    if not source:
34027
3c3066367d72 debugssl: allow a URL to be specified without a local repository
Matt Harbison <matt_harbison@yahoo.com>
parents: 33553
diff changeset
  3283
        if not repo:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3284
            raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3285
                _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3286
                    b"there is no Mercurial repository here, and no "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3287
                    b"server specified"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3288
                )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3289
            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3290
        source = b"default"
33493
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3291
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3292
    source, branches = hg.parseurl(ui.expandpath(source))
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3293
    url = util.url(source)
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3294
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3295
    defaultport = {b'https': 443, b'ssh': 22}
35425
88572b7e50fd debugssl: convert port number to int (issue5757)
Yuya Nishihara <yuya@tcha.org>
parents: 34645
diff changeset
  3296
    if url.scheme in defaultport:
88572b7e50fd debugssl: convert port number to int (issue5757)
Yuya Nishihara <yuya@tcha.org>
parents: 34645
diff changeset
  3297
        try:
88572b7e50fd debugssl: convert port number to int (issue5757)
Yuya Nishihara <yuya@tcha.org>
parents: 34645
diff changeset
  3298
            addr = (url.host, int(url.port or defaultport[url.scheme]))
88572b7e50fd debugssl: convert port number to int (issue5757)
Yuya Nishihara <yuya@tcha.org>
parents: 34645
diff changeset
  3299
        except ValueError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3300
            raise error.Abort(_(b"malformed port number in URL"))
33493
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3301
    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3302
        raise error.Abort(_(b"only https and ssh connections are supported"))
33493
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3303
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3304
    from . import win32
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3305
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3306
    s = ssl.wrap_socket(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3307
        socket.socket(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3308
        ssl_version=ssl.PROTOCOL_TLS,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3309
        cert_reqs=ssl.CERT_NONE,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3310
        ca_certs=None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3311
    )
33493
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3312
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3313
    try:
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3314
        s.connect(addr)
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3315
        cert = s.getpeercert(True)
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3316
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3317
        ui.status(_(b'checking the certificate chain for %s\n') % url.host)
33493
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3318
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3319
        complete = win32.checkcertificatechain(cert, build=False)
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3320
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3321
        if not complete:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3322
            ui.status(_(b'certificate chain is incomplete, updating... '))
33493
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3323
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3324
            if not win32.checkcertificatechain(cert):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3325
                ui.status(_(b'failed.\n'))
33493
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3326
            else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3327
                ui.status(_(b'done.\n'))
33493
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3328
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3329
            ui.status(_(b'full certificate chain is available\n'))
33493
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3330
    finally:
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3331
        s.close()
9a9f95214f46 debug: add a method to check the state of, and built an SSL cert chain
Matt Harbison <matt_harbison@yahoo.com>
parents: 33438
diff changeset
  3332
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3333
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3334
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3335
    b'debugsub',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3336
    [(b'r', b'rev', b'', _(b'revision to check'), _(b'REV'))],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3337
    _(b'[-r REV] [REV]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3338
)
30955
8e38fa360a12 debugcommands: move 'debugsub' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30954
diff changeset
  3339
def debugsub(ui, repo, rev=None):
8e38fa360a12 debugcommands: move 'debugsub' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30954
diff changeset
  3340
    ctx = scmutil.revsingle(repo, rev, None)
8e38fa360a12 debugcommands: move 'debugsub' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30954
diff changeset
  3341
    for k, v in sorted(ctx.substate.items()):
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  3342
        ui.writenoi18n(b'path %s\n' % k)
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  3343
        ui.writenoi18n(b' source   %s\n' % v[0])
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  3344
        ui.writenoi18n(b' revision %s\n' % v[1])
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3345
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3346
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3347
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3348
    b'debugsuccessorssets',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3349
    [(b'', b'closest', False, _(b'return closest successors sets only'))],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3350
    _(b'[REV]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3351
)
33274
68f3e819d41d obsolete: closest divergent support
Boris Feld <boris.feld@octobus.net>
parents: 33273
diff changeset
  3352
def debugsuccessorssets(ui, repo, *revs, **opts):
30956
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3353
    """show set of successors for revision
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3354
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3355
    A successors set of changeset A is a consistent group of revisions that
33274
68f3e819d41d obsolete: closest divergent support
Boris Feld <boris.feld@octobus.net>
parents: 33273
diff changeset
  3356
    succeed A. It contains non-obsolete changesets only unless closests
68f3e819d41d obsolete: closest divergent support
Boris Feld <boris.feld@octobus.net>
parents: 33273
diff changeset
  3357
    successors set is set.
30956
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3358
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3359
    In most cases a changeset A has a single successors set containing a single
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3360
    successor (changeset A replaced by A').
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3361
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3362
    A changeset that is made obsolete with no successors are called "pruned".
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3363
    Such changesets have no successors sets at all.
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3364
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3365
    A changeset that has been "split" will have a successors set containing
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3366
    more than one successor.
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3367
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3368
    A changeset that has been rewritten in multiple different ways is called
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3369
    "divergent". Such changesets have multiple successor sets (each of which
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3370
    may also be split, i.e. have multiple successors).
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3371
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3372
    Results are displayed as follows::
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3373
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3374
        <rev1>
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3375
            <successors-1A>
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3376
        <rev2>
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3377
            <successors-2A>
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3378
            <successors-2B1> <successors-2B2> <successors-2B3>
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3379
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3380
    Here rev2 has two possible (i.e. divergent) successors sets. The first
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3381
    holds one element, whereas the second holds three (i.e. the changeset has
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3382
    been split).
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3383
    """
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3384
    # passed to successorssets caching computation from one call to another
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3385
    cache = {}
36123
8eb13f5d5d3f py3: convert context to bytes instead of str
Gregory Szorc <gregory.szorc@gmail.com>
parents: 35929
diff changeset
  3386
    ctx2str = bytes
30956
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3387
    node2str = short
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3388
    for rev in scmutil.revrange(repo, revs):
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3389
        ctx = repo[rev]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3390
        ui.write(b'%s\n' % ctx2str(ctx))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3391
        for succsset in obsutil.successorssets(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3392
            repo, ctx.node(), closest=opts[r'closest'], cache=cache
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3393
        ):
30956
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3394
            if succsset:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3395
                ui.write(b'    ')
30956
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3396
                ui.write(node2str(succsset[0]))
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3397
                for node in succsset[1:]:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3398
                    ui.write(b' ')
30956
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3399
                    ui.write(node2str(node))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3400
            ui.write(b'\n')
30956
db30c6bfeb70 debugcommands: move 'debugsuccessorssets' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30955
diff changeset
  3401
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3402
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3403
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3404
    b'debugtemplate',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3405
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3406
        (b'r', b'rev', [], _(b'apply template on changesets'), _(b'REV')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3407
        (b'D', b'define', [], _(b'define template keyword'), _(b'KEY=VALUE')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3408
    ],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3409
    _(b'[-r REV]... [-D KEY=VALUE]... TEMPLATE'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3410
    optionalrepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3411
)
30957
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3412
def debugtemplate(ui, repo, tmpl, **opts):
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3413
    """parse and apply a template
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3414
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3415
    If -r/--rev is given, the template is processed as a log template and
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3416
    applied to the given changesets. Otherwise, it is processed as a generic
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3417
    template.
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3418
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3419
    Use --verbose to print the parsed tree.
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3420
    """
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3421
    revs = None
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
  3422
    if opts[r'rev']:
30957
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3423
        if repo is None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3424
            raise error.RepoError(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43116
diff changeset
  3425
                _(b'there is no Mercurial repository here (.hg not found)')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3426
            )
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
  3427
        revs = scmutil.revrange(repo, opts[r'rev'])
30957
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3428
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3429
    props = {}
33101
b257aaa0743a py3: use r'' to prevent the addition of b'' by transformer
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33100
diff changeset
  3430
    for d in opts[r'define']:
30957
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3431
        try:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3432
            k, v = (e.strip() for e in d.split(b'=', 1))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3433
            if not k or k == b'ui':
30957
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3434
                raise ValueError
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3435
            props[k] = v
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3436
        except ValueError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3437
            raise error.Abort(_(b'malformed keyword definition: %s') % d)
30957
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3438
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3439
    if ui.verbose:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3440
        aliases = ui.configitems(b'templatealias')
30957
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3441
        tree = templater.parse(tmpl)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3442
        ui.note(templater.prettyformat(tree), b'\n')
30957
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3443
        newtree = templater.expandaliases(tree, aliases)
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3444
        if newtree != tree:
43094
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  3445
            ui.notenoi18n(
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  3446
                b"* expanded:\n", templater.prettyformat(newtree), b'\n'
e8cf9ad52a78 formatting: run black on all file again
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43089
diff changeset
  3447
            )
30957
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3448
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3449
    if revs is None:
35469
f1c54d003327 templater: move repo, ui and cache to per-engine resources
Yuya Nishihara <yuya@tcha.org>
parents: 35465
diff changeset
  3450
        tres = formatter.templateresources(ui, repo)
f1c54d003327 templater: move repo, ui and cache to per-engine resources
Yuya Nishihara <yuya@tcha.org>
parents: 35465
diff changeset
  3451
        t = formatter.maketemplater(ui, tmpl, resources=tres)
38355
d4fae9a0ab1f templater: add function to look up symbols used in template
Yuya Nishihara <yuya@tcha.org>
parents: 38313
diff changeset
  3452
        if ui.verbose:
d4fae9a0ab1f templater: add function to look up symbols used in template
Yuya Nishihara <yuya@tcha.org>
parents: 38313
diff changeset
  3453
            kwds, funcs = t.symbolsuseddefault()
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  3454
            ui.writenoi18n(b"* keywords: %s\n" % b', '.join(sorted(kwds)))
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  3455
            ui.writenoi18n(b"* functions: %s\n" % b', '.join(sorted(funcs)))
36988
317382151ac3 templater: rename .render(mapping) to .renderdefault(mapping) (API)
Yuya Nishihara <yuya@tcha.org>
parents: 36954
diff changeset
  3456
        ui.write(t.renderdefault(props))
30957
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3457
    else:
35888
c8e2d6ed1f9e cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35730
diff changeset
  3458
        displayer = logcmdutil.maketemplater(ui, repo, tmpl)
38355
d4fae9a0ab1f templater: add function to look up symbols used in template
Yuya Nishihara <yuya@tcha.org>
parents: 38313
diff changeset
  3459
        if ui.verbose:
d4fae9a0ab1f templater: add function to look up symbols used in template
Yuya Nishihara <yuya@tcha.org>
parents: 38313
diff changeset
  3460
            kwds, funcs = displayer.t.symbolsuseddefault()
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  3461
            ui.writenoi18n(b"* keywords: %s\n" % b', '.join(sorted(kwds)))
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  3462
            ui.writenoi18n(b"* functions: %s\n" % b', '.join(sorted(funcs)))
30957
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3463
        for r in revs:
33102
1b6946f87c50 py3: use pycompat.strkwargs() to convert kwargs keys to str
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33101
diff changeset
  3464
            displayer.show(repo[r], **pycompat.strkwargs(props))
30957
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3465
        displayer.close()
14794735faa8 debugcommands: move 'debugtemplate' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30956
diff changeset
  3466
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3467
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3468
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3469
    b'debuguigetpass',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3470
    [(b'p', b'prompt', b'', _(b'prompt text'), _(b'TEXT')),],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3471
    _(b'[-p TEXT]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3472
    norepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3473
)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3474
def debuguigetpass(ui, prompt=b''):
36792
15c050b5d599 ui: add debug commands to test interactive prompt
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
  3475
    """show prompt to type password"""
15c050b5d599 ui: add debug commands to test interactive prompt
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
  3476
    r = ui.getpass(prompt)
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  3477
    ui.writenoi18n(b'respose: %s\n' % r)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3478
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3479
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3480
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3481
    b'debuguiprompt',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3482
    [(b'p', b'prompt', b'', _(b'prompt text'), _(b'TEXT')),],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3483
    _(b'[-p TEXT]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3484
    norepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3485
)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3486
def debuguiprompt(ui, prompt=b''):
36792
15c050b5d599 ui: add debug commands to test interactive prompt
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
  3487
    """show plain prompt"""
15c050b5d599 ui: add debug commands to test interactive prompt
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
  3488
    r = ui.prompt(prompt)
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  3489
    ui.writenoi18n(b'response: %s\n' % r)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3490
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3491
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3492
@command(b'debugupdatecaches', [])
32265
ccef71de7d41 caches: introduce a 'debugupdatecaches' command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32256
diff changeset
  3493
def debugupdatecaches(ui, repo, *pats, **opts):
ccef71de7d41 caches: introduce a 'debugupdatecaches' command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32256
diff changeset
  3494
    """warm all known caches in the repository"""
33438
8056481caa81 codemod: simplify nested withs
Jun Wu <quark@fb.com>
parents: 33336
diff changeset
  3495
    with repo.wlock(), repo.lock():
36952
b24cde12061b debugupdatecache: also warm rev branch cache
Boris Feld <boris.feld@octobus.net>
parents: 36951
diff changeset
  3496
        repo.updatecaches(full=True)
32265
ccef71de7d41 caches: introduce a 'debugupdatecaches' command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 32256
diff changeset
  3497
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3498
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3499
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3500
    b'debugupgraderepo',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3501
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3502
        (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3503
            b'o',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3504
            b'optimize',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3505
            [],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3506
            _(b'extra optimization to perform'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3507
            _(b'NAME'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3508
        ),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3509
        (b'', b'run', False, _(b'performs an upgrade')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3510
        (b'', b'backup', True, _(b'keep the old repository content around')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3511
        (b'', b'changelog', None, _(b'select the changelog for upgrade')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3512
        (b'', b'manifest', None, _(b'select the manifest for upgrade')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3513
    ],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3514
)
42830
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42773
diff changeset
  3515
def debugupgraderepo(ui, repo, run=False, optimize=None, backup=True, **opts):
30774
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3516
    """upgrade a repository to use different features
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3517
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3518
    If no arguments are specified, the repository is evaluated for upgrade
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3519
    and a list of problems and potential optimizations is printed.
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3520
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3521
    With ``--run``, a repository upgrade is performed. Behavior of the upgrade
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3522
    can be influenced via additional arguments. More details will be provided
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3523
    by the command output when run without ``--run``.
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3524
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3525
    During the upgrade, the repository will be locked and no writes will be
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3526
    allowed.
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3527
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3528
    At the end of the upgrade, the repository may not be readable while new
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3529
    repository data is swapped in. This window will be as long as it takes to
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3530
    rename some directories inside the ``.hg`` directory. On most machines, this
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3531
    should complete almost instantaneously and the chances of a consumer being
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3532
    unable to access the repository should be low.
42830
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42773
diff changeset
  3533
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42773
diff changeset
  3534
    By default, all revlog will be upgraded. You can restrict this using flag
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42773
diff changeset
  3535
    such as `--manifest`:
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42773
diff changeset
  3536
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42773
diff changeset
  3537
      * `--manifest`: only optimize the manifest
cf2b765cecd7 upgrade: add an argument to control manifest upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42773
diff changeset
  3538
      * `--no-manifest`: optimize all revlog but the manifest
42831
908ff446590e upgrade: add an argument to control changelog upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42830
diff changeset
  3539
      * `--changelog`: optimize the changelog only
908ff446590e upgrade: add an argument to control changelog upgrade
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 42830
diff changeset
  3540
      * `--no-changelog --no-manifest`: optimize filelogs only
30774
eaa5607132a2 debugcommands: stub for debugupgraderepo command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 30743
diff changeset
  3541
    """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3542
    return upgrade.upgraderepo(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3543
        ui, repo, run=run, optimize=optimize, backup=backup, **opts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3544
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3545
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3546
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3547
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3548
    b'debugwalk', cmdutil.walkopts, _(b'[OPTION]... [FILE]...'), inferrepo=True
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3549
)
30958
df73368c87c3 debugcommands: move 'debugwalk' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30957
diff changeset
  3550
def debugwalk(ui, repo, *pats, **opts):
df73368c87c3 debugcommands: move 'debugwalk' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30957
diff changeset
  3551
    """show how files match on given patterns"""
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
  3552
    opts = pycompat.byteskwargs(opts)
30958
df73368c87c3 debugcommands: move 'debugwalk' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30957
diff changeset
  3553
    m = scmutil.match(repo[None], pats, opts)
38262
7c3a59e2971b debugwalk: show matcher output only if -v/--verbose
Yuya Nishihara <yuya@tcha.org>
parents: 38261
diff changeset
  3554
    if ui.verbose:
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43077
diff changeset
  3555
        ui.writenoi18n(b'* matcher:\n', stringutil.prettyrepr(m), b'\n')
32363
a275186b989a debugcommands: use repo[None].walk instead of repo.walk
Augie Fackler <augie@google.com>
parents: 32337
diff changeset
  3556
    items = list(repo[None].walk(m))
30958
df73368c87c3 debugcommands: move 'debugwalk' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30957
diff changeset
  3557
    if not items:
df73368c87c3 debugcommands: move 'debugwalk' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30957
diff changeset
  3558
        return
df73368c87c3 debugcommands: move 'debugwalk' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30957
diff changeset
  3559
    f = lambda fn: fn
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3560
    if ui.configbool(b'ui', b'slash') and pycompat.ossep != b'/':
30958
df73368c87c3 debugcommands: move 'debugwalk' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30957
diff changeset
  3561
        f = lambda fn: util.normpath(fn)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3562
    fmt = b'f  %%-%ds  %%-%ds  %%s' % (
30958
df73368c87c3 debugcommands: move 'debugwalk' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30957
diff changeset
  3563
        max([len(abs) for abs in items]),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3564
        max([len(repo.pathto(abs)) for abs in items]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3565
    )
30958
df73368c87c3 debugcommands: move 'debugwalk' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30957
diff changeset
  3566
    for abs in items:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3567
        line = fmt % (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3568
            abs,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3569
            f(repo.pathto(abs)),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3570
            m.exact(abs) and b'exact' or b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3571
        )
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3572
        ui.write(b"%s\n" % line.rstrip())
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3573
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3574
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3575
@command(b'debugwhyunstable', [], _(b'REV'))
36954
efc4fb344c05 debug: add debugwhyunstable that explains instabilities
Anton Shestakov <av6@dwimlabs.net>
parents: 36952
diff changeset
  3576
def debugwhyunstable(ui, repo, rev):
efc4fb344c05 debug: add debugwhyunstable that explains instabilities
Anton Shestakov <av6@dwimlabs.net>
parents: 36952
diff changeset
  3577
    """explain instabilities of a changeset"""
37396
9966f44ecab4 debugwhyunstable: add support for revsets
Martin von Zweigbergk <martinvonz@google.com>
parents: 37350
diff changeset
  3578
    for entry in obsutil.whyunstable(repo, scmutil.revsingle(repo, rev)):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3579
        dnodes = b''
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3580
        if entry.get(b'divergentnodes'):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3581
            dnodes = (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3582
                b' '.join(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3583
                    b'%s (%s)' % (ctx.hex(), ctx.phasestr())
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3584
                    for ctx in entry[b'divergentnodes']
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3585
                )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3586
                + b' '
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3587
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3588
        ui.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3589
            b'%s: %s%s %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3590
            % (entry[b'instability'], dnodes, entry[b'reason'], entry[b'node'])
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3591
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3592
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3593
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3594
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3595
    b'debugwireargs',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3596
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3597
        (b'', b'three', b'', b'three'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3598
        (b'', b'four', b'', b'four'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3599
        (b'', b'five', b'', b'five'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3600
    ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3601
    + cmdutil.remoteopts,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3602
    _(b'REPO [OPTIONS]... [ONE [TWO]]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3603
    norepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3604
)
30959
bd5694ce8beb debugcommands: move 'debugwireargs' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30958
diff changeset
  3605
def debugwireargs(ui, repopath, *vals, **opts):
33100
05906b8e1d23 py3: use pycompat.byteskwargs() to convert kwargs' keys to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 33062
diff changeset
  3606
    opts = pycompat.byteskwargs(opts)
30959
bd5694ce8beb debugcommands: move 'debugwireargs' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30958
diff changeset
  3607
    repo = hg.peer(ui, opts, repopath)
32375
04baab18d60a commands: move templates of common command options to cmdutil (API)
Yuya Nishihara <yuya@tcha.org>
parents: 32371
diff changeset
  3608
    for opt in cmdutil.remoteopts:
30959
bd5694ce8beb debugcommands: move 'debugwireargs' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30958
diff changeset
  3609
        del opts[opt[1]]
bd5694ce8beb debugcommands: move 'debugwireargs' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30958
diff changeset
  3610
    args = {}
43106
d783f945a701 py3: finish porting iteritems() to pycompat and remove source transformer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 43094
diff changeset
  3611
    for k, v in pycompat.iteritems(opts):
30959
bd5694ce8beb debugcommands: move 'debugwireargs' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30958
diff changeset
  3612
        if v:
bd5694ce8beb debugcommands: move 'debugwireargs' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30958
diff changeset
  3613
            args[k] = v
35401
cd3392cb5818 py3: handle keyword arguments correctly in debugcommands.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 35400
diff changeset
  3614
    args = pycompat.strkwargs(args)
30959
bd5694ce8beb debugcommands: move 'debugwireargs' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30958
diff changeset
  3615
    # run twice to check that we don't mess up the stream for the next command
bd5694ce8beb debugcommands: move 'debugwireargs' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30958
diff changeset
  3616
    res1 = repo.debugwireargs(*vals, **args)
bd5694ce8beb debugcommands: move 'debugwireargs' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30958
diff changeset
  3617
    res2 = repo.debugwireargs(*vals, **args)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3618
    ui.write(b"%s\n" % res1)
30959
bd5694ce8beb debugcommands: move 'debugwireargs' in the new module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30958
diff changeset
  3619
    if res1 != res2:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3620
        ui.warn(b"%s\n" % res2)
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3621
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3622
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3623
def _parsewirelangblocks(fh):
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3624
    activeaction = None
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3625
    blocklines = []
40174
64360202d5b2 debugcommands: support wrapping long lines
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40029
diff changeset
  3626
    lastindent = 0
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3627
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3628
    for line in fh:
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3629
        line = line.rstrip()
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3630
        if not line:
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3631
            continue
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3632
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3633
        if line.startswith(b'#'):
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3634
            continue
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3635
39062
efeeb73f54c3 debugcommands: fix a missing b prefix
Augie Fackler <augie@google.com>
parents: 38972
diff changeset
  3636
        if not line.startswith(b' '):
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3637
            # New block. Flush previous one.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3638
            if activeaction:
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3639
                yield activeaction, blocklines
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3640
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3641
            activeaction = line
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3642
            blocklines = []
40174
64360202d5b2 debugcommands: support wrapping long lines
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40029
diff changeset
  3643
            lastindent = 0
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3644
            continue
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3645
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3646
        # Else we start with an indent.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3647
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3648
        if not activeaction:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3649
            raise error.Abort(_(b'indented line outside of block'))
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3650
40174
64360202d5b2 debugcommands: support wrapping long lines
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40029
diff changeset
  3651
        indent = len(line) - len(line.lstrip())
64360202d5b2 debugcommands: support wrapping long lines
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40029
diff changeset
  3652
64360202d5b2 debugcommands: support wrapping long lines
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40029
diff changeset
  3653
        # If this line is indented more than the last line, concatenate it.
64360202d5b2 debugcommands: support wrapping long lines
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40029
diff changeset
  3654
        if indent > lastindent and blocklines:
64360202d5b2 debugcommands: support wrapping long lines
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40029
diff changeset
  3655
            blocklines[-1] += line.lstrip()
64360202d5b2 debugcommands: support wrapping long lines
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40029
diff changeset
  3656
        else:
64360202d5b2 debugcommands: support wrapping long lines
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40029
diff changeset
  3657
            blocklines.append(line)
64360202d5b2 debugcommands: support wrapping long lines
Gregory Szorc <gregory.szorc@gmail.com>
parents: 40029
diff changeset
  3658
            lastindent = indent
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3659
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3660
    # Flush last block.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3661
    if activeaction:
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3662
        yield activeaction, blocklines
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3663
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3664
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3665
@command(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3666
    b'debugwireproto',
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3667
    [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3668
        (b'', b'localssh', False, _(b'start an SSH server for this repo')),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3669
        (b'', b'peer', b'', _(b'construct a specific version of the peer')),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3670
        (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3671
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3672
            b'noreadstderr',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3673
            False,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3674
            _(b'do not read from stderr of the remote'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3675
        ),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3676
        (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3677
            b'',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3678
            b'nologhandshake',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3679
            False,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3680
            _(b'do not log I/O related to the peer handshake'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3681
        ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3682
    ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3683
    + cmdutil.remoteopts,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3684
    _(b'[PATH]'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3685
    optionalrepo=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3686
)
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3687
def debugwireproto(ui, repo, path=None, **opts):
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3688
    """send wire protocol commands to a server
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3689
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3690
    This command can be used to issue wire protocol commands to remote
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3691
    peers and to debug the raw data being exchanged.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3692
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3693
    ``--localssh`` will start an SSH server against the current repository
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3694
    and connect to that. By default, the connection will perform a handshake
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3695
    and establish an appropriate peer instance.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3696
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3697
    ``--peer`` can be used to bypass the handshake protocol and construct a
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3698
    peer instance using the specified class type. Valid values are ``raw``,
37483
61e405fb6372 wireproto: crude support for version 2 HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37396
diff changeset
  3699
    ``http2``, ``ssh1``, and ``ssh2``. ``raw`` instances only allow sending
61e405fb6372 wireproto: crude support for version 2 HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37396
diff changeset
  3700
    raw data payloads and don't support higher-level command actions.
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3701
36534
5faeabb07cf5 debugcommands: support for triggering push protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36531
diff changeset
  3702
    ``--noreadstderr`` can be used to disable automatic reading from stderr
5faeabb07cf5 debugcommands: support for triggering push protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36531
diff changeset
  3703
    of the peer (for SSH connections only). Disabling automatic reading of
5faeabb07cf5 debugcommands: support for triggering push protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36531
diff changeset
  3704
    stderr is useful for making output more deterministic.
5faeabb07cf5 debugcommands: support for triggering push protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36531
diff changeset
  3705
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3706
    Commands are issued via a mini language which is specified via stdin.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3707
    The language consists of individual actions to perform. An action is
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3708
    defined by a block. A block is defined as a line with no leading
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3709
    space followed by 0 or more lines with leading space. Blocks are
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3710
    effectively a high-level command with additional metadata.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3711
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3712
    Lines beginning with ``#`` are ignored.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3713
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3714
    The following sections denote available actions.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3715
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3716
    raw
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3717
    ---
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3718
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3719
    Send raw data to the server.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3720
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3721
    The block payload contains the raw data to send as one atomic send
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3722
    operation. The data may not actually be delivered in a single system
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3723
    call: it depends on the abilities of the transport being used.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3724
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3725
    Each line in the block is de-indented and concatenated. Then, that
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3726
    value is evaluated as a Python b'' literal. This allows the use of
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3727
    backslash escaping, etc.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3728
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3729
    raw+
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3730
    ----
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3731
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3732
    Behaves like ``raw`` except flushes output afterwards.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3733
36530
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  3734
    command <X>
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  3735
    -----------
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  3736
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  3737
    Send a request to run a named command, whose name follows the ``command``
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  3738
    string.
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  3739
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  3740
    Arguments to the command are defined as lines in this block. The format of
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  3741
    each line is ``<key> <value>``. e.g.::
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  3742
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  3743
       command listkeys
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  3744
           namespace bookmarks
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  3745
37483
61e405fb6372 wireproto: crude support for version 2 HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37396
diff changeset
  3746
    If the value begins with ``eval:``, it will be interpreted as a Python
61e405fb6372 wireproto: crude support for version 2 HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37396
diff changeset
  3747
    literal expression. Otherwise values are interpreted as Python b'' literals.
61e405fb6372 wireproto: crude support for version 2 HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37396
diff changeset
  3748
    This allows sending complex types and encoding special byte sequences via
61e405fb6372 wireproto: crude support for version 2 HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37396
diff changeset
  3749
    backslash escaping.
36530
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  3750
36534
5faeabb07cf5 debugcommands: support for triggering push protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36531
diff changeset
  3751
    The following arguments have special meaning:
5faeabb07cf5 debugcommands: support for triggering push protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36531
diff changeset
  3752
5faeabb07cf5 debugcommands: support for triggering push protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36531
diff changeset
  3753
    ``PUSHFILE``
5faeabb07cf5 debugcommands: support for triggering push protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36531
diff changeset
  3754
        When defined, the *push* mechanism of the peer will be used instead
5faeabb07cf5 debugcommands: support for triggering push protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36531
diff changeset
  3755
        of the static request-response mechanism and the content of the
5faeabb07cf5 debugcommands: support for triggering push protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36531
diff changeset
  3756
        file specified in the value of this argument will be sent as the
5faeabb07cf5 debugcommands: support for triggering push protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36531
diff changeset
  3757
        command payload.
5faeabb07cf5 debugcommands: support for triggering push protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36531
diff changeset
  3758
5faeabb07cf5 debugcommands: support for triggering push protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36531
diff changeset
  3759
        This can be used to submit a local bundle file to the remote.
5faeabb07cf5 debugcommands: support for triggering push protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36531
diff changeset
  3760
36531
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  3761
    batchbegin
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  3762
    ----------
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  3763
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  3764
    Instruct the peer to begin a batched send.
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  3765
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  3766
    All ``command`` blocks are queued for execution until the next
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  3767
    ``batchsubmit`` block.
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  3768
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  3769
    batchsubmit
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  3770
    -----------
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  3771
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  3772
    Submit previously queued ``command`` blocks as a batch request.
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  3773
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  3774
    This action MUST be paired with a ``batchbegin`` action.
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  3775
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3776
    httprequest <method> <path>
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3777
    ---------------------------
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3778
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3779
    (HTTP peer only)
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3780
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3781
    Send an HTTP request to the peer.
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3782
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3783
    The HTTP request line follows the ``httprequest`` action. e.g. ``GET /foo``.
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3784
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3785
    Arguments of the form ``<key>: <value>`` are interpreted as HTTP request
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3786
    headers to add to the request. e.g. ``Accept: foo``.
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3787
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3788
    The following arguments are special:
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3789
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3790
    ``BODYFILE``
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3791
        The content of the file defined as the value to this argument will be
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3792
        transferred verbatim as the HTTP request body.
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3793
37051
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3794
    ``frame <type> <flags> <payload>``
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3795
        Send a unified protocol frame as part of the request body.
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3796
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3797
        All frames will be collected and sent as the body to the HTTP
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3798
        request.
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3799
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3800
    close
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3801
    -----
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3802
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3803
    Close the connection to the server.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3804
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3805
    flush
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3806
    -----
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3807
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3808
    Flush data written to the server.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3809
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3810
    readavailable
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3811
    -------------
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3812
36843
31581528f242 debugwireproto: close the write end before consuming all available data
Yuya Nishihara <yuya@tcha.org>
parents: 36835
diff changeset
  3813
    Close the write end of the connection and read all available data from
31581528f242 debugwireproto: close the write end before consuming all available data
Yuya Nishihara <yuya@tcha.org>
parents: 36835
diff changeset
  3814
    the server.
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3815
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3816
    If the connection to the server encompasses multiple pipes, we poll both
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3817
    pipes and read available data.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3818
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3819
    readline
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3820
    --------
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3821
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3822
    Read a line of output from the server. If there are multiple output
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3823
    pipes, reads only the main pipe.
37007
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  3824
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  3825
    ereadline
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  3826
    ---------
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  3827
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  3828
    Like ``readline``, but read from the stderr pipe, if available.
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  3829
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  3830
    read <X>
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  3831
    --------
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  3832
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  3833
    ``read()`` N bytes from the server's main output pipe.
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  3834
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  3835
    eread <X>
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  3836
    ---------
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  3837
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  3838
    ``read()`` N bytes from the server's stderr pipe, if available.
37051
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3839
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3840
    Specifying Unified Frame-Based Protocol Frames
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3841
    ----------------------------------------------
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3842
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3843
    It is possible to emit a *Unified Frame-Based Protocol* by using special
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3844
    syntax.
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3845
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3846
    A frame is composed as a type, flags, and payload. These can be parsed
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37283
diff changeset
  3847
    from a string of the form:
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37283
diff changeset
  3848
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37283
diff changeset
  3849
       <request-id> <stream-id> <stream-flags> <type> <flags> <payload>
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37283
diff changeset
  3850
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37283
diff changeset
  3851
    ``request-id`` and ``stream-id`` are integers defining the request and
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37283
diff changeset
  3852
    stream identifiers.
37057
2ec1fb9de638 wireproto: add request IDs to frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37051
diff changeset
  3853
37051
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3854
    ``type`` can be an integer value for the frame type or the string name
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3855
    of the type. The strings are defined in ``wireprotoframing.py``. e.g.
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3856
    ``command-name``.
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  3857
37288
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37283
diff changeset
  3858
    ``stream-flags`` and ``flags`` are a ``|`` delimited list of flag
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37283
diff changeset
  3859
    components. Each component (and there can be just one) can be an integer
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37283
diff changeset
  3860
    or a flag name for stream flags or frame flags, respectively. Values are
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37283
diff changeset
  3861
    resolved to integers and then bitwise OR'd together.
9bfcbe4f4745 wireproto: add streams to frame-based protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37283
diff changeset
  3862
37290
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37288
diff changeset
  3863
    ``payload`` represents the raw frame payload. If it begins with
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37288
diff changeset
  3864
    ``cbor:``, the following string is evaluated as Python code and the
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37288
diff changeset
  3865
    resulting object is fed into a CBOR encoder. Otherwise it is interpreted
cc5a040fe150 wireproto: syntax for encoding CBOR into frames
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37288
diff changeset
  3866
    as a Python byte string literal.
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3867
    """
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3868
    opts = pycompat.byteskwargs(opts)
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3869
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3870
    if opts[b'localssh'] and not repo:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3871
        raise error.Abort(_(b'--localssh requires a repository'))
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3872
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3873
    if opts[b'peer'] and opts[b'peer'] not in (
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3874
        b'raw',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3875
        b'http2',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3876
        b'ssh1',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3877
        b'ssh2',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3878
    ):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3879
        raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3880
            _(b'invalid value for --peer'),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3881
            hint=_(b'valid values are "raw", "ssh1", and "ssh2"'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3882
        )
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3883
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3884
    if path and opts[b'localssh']:
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43116
diff changeset
  3885
        raise error.Abort(_(b'cannot specify --localssh with an explicit path'))
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3886
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3887
    if ui.interactive():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3888
        ui.write(_(b'(waiting for commands on stdin)\n'))
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3889
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3890
    blocks = list(_parsewirelangblocks(ui.fin))
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3891
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3892
    proc = None
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3893
    stdin = None
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3894
    stdout = None
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3895
    stderr = None
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  3896
    opener = None
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3897
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3898
    if opts[b'localssh']:
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3899
        # We start the SSH server in its own process so there is process
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3900
        # separation. This prevents a whole class of potential bugs around
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3901
        # shared state from interfering with server operation.
37120
a8a902d7176e procutil: bulk-replace function calls to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37084
diff changeset
  3902
        args = procutil.hgcmd() + [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3903
            b'-R',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3904
            repo.root,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3905
            b'debugserve',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3906
            b'--sshstdio',
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3907
        ]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3908
        proc = subprocess.Popen(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3909
            pycompat.rapply(procutil.tonativestr, args),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3910
            stdin=subprocess.PIPE,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3911
            stdout=subprocess.PIPE,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3912
            stderr=subprocess.PIPE,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3913
            bufsize=0,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3914
        )
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3915
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3916
        stdin = proc.stdin
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3917
        stdout = proc.stdout
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3918
        stderr = proc.stderr
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3919
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3920
        # We turn the pipes into observers so we can log I/O.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3921
        if ui.verbose or opts[b'peer'] == b'raw':
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3922
            stdin = util.makeloggingfileobject(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3923
                ui, proc.stdin, b'i', logdata=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3924
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3925
            stdout = util.makeloggingfileobject(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3926
                ui, proc.stdout, b'o', logdata=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3927
            )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3928
            stderr = util.makeloggingfileobject(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3929
                ui, proc.stderr, b'e', logdata=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3930
            )
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3931
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3932
        # --localssh also implies the peer connection settings.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3933
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3934
        url = b'ssh://localserver'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3935
        autoreadstderr = not opts[b'noreadstderr']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3936
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3937
        if opts[b'peer'] == b'ssh1':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3938
            ui.write(_(b'creating ssh peer for wire protocol version 1\n'))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3939
            peer = sshpeer.sshv1peer(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3940
                ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3941
                url,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3942
                proc,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3943
                stdin,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3944
                stdout,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3945
                stderr,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3946
                None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3947
                autoreadstderr=autoreadstderr,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3948
            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3949
        elif opts[b'peer'] == b'ssh2':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3950
            ui.write(_(b'creating ssh peer for wire protocol version 2\n'))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3951
            peer = sshpeer.sshv2peer(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3952
                ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3953
                url,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3954
                proc,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3955
                stdin,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3956
                stdout,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3957
                stderr,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3958
                None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3959
                autoreadstderr=autoreadstderr,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3960
            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3961
        elif opts[b'peer'] == b'raw':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3962
            ui.write(_(b'using raw connection to peer\n'))
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3963
            peer = None
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3964
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3965
            ui.write(_(b'creating ssh peer from handshake results\n'))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3966
            peer = sshpeer.makepeer(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3967
                ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3968
                url,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3969
                proc,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3970
                stdin,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3971
                stdout,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3972
                stderr,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3973
                autoreadstderr=autoreadstderr,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3974
            )
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  3975
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3976
    elif path:
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3977
        # We bypass hg.peer() so we can proxy the sockets.
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3978
        # TODO consider not doing this because we skip
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3979
        # ``hg.wirepeersetupfuncs`` and potentially other useful functionality.
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3980
        u = util.url(path)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3981
        if u.scheme != b'http':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  3982
            raise error.Abort(_(b'only http:// paths are currently supported'))
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3983
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3984
        url, authinfo = u.authinfo()
37483
61e405fb6372 wireproto: crude support for version 2 HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37396
diff changeset
  3985
        openerargs = {
61e405fb6372 wireproto: crude support for version 2 HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37396
diff changeset
  3986
            r'useragent': b'Mercurial debugwireproto',
61e405fb6372 wireproto: crude support for version 2 HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37396
diff changeset
  3987
        }
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3988
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3989
        # Turn pipes/sockets into observers so we can log I/O.
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3990
        if ui.verbose:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3991
            openerargs.update(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3992
                {
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3993
                    r'loggingfh': ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3994
                    r'loggingname': b's',
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3995
                    r'loggingopts': {r'logdata': True, r'logdataapis': False,},
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3996
                }
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  3997
            )
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  3998
37044
d3a9036d9ae9 util: don't log low-level I/O calls for HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37013
diff changeset
  3999
        if ui.debugflag:
d3a9036d9ae9 util: don't log low-level I/O calls for HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37013
diff changeset
  4000
            openerargs[r'loggingopts'][r'logdataapis'] = True
d3a9036d9ae9 util: don't log low-level I/O calls for HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37013
diff changeset
  4001
37045
a708e1e4d7a8 url: support suppressing Accept header
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37044
diff changeset
  4002
        # Don't send default headers when in raw mode. This allows us to
a708e1e4d7a8 url: support suppressing Accept header
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37044
diff changeset
  4003
        # bypass most of the behavior of our URL handling code so we can
a708e1e4d7a8 url: support suppressing Accept header
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37044
diff changeset
  4004
        # have near complete control over what's sent on the wire.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4005
        if opts[b'peer'] == b'raw':
37045
a708e1e4d7a8 url: support suppressing Accept header
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37044
diff changeset
  4006
            openerargs[r'sendaccept'] = False
a708e1e4d7a8 url: support suppressing Accept header
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37044
diff changeset
  4007
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4008
        opener = urlmod.opener(ui, authinfo, **openerargs)
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4009
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4010
        if opts[b'peer'] == b'http2':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4011
            ui.write(_(b'creating http peer for wire protocol version 2\n'))
37645
72b0982cd509 debugcommands: perform handshake when obtaining httpv2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37644
diff changeset
  4012
            # We go through makepeer() because we need an API descriptor for
72b0982cd509 debugcommands: perform handshake when obtaining httpv2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37644
diff changeset
  4013
            # the peer instance to be useful.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4014
            with ui.configoverride(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4015
                {(b'experimental', b'httppeer.advertise-v2'): True}
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4016
            ):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4017
                if opts[b'nologhandshake']:
37718
ad1c07008e0b debugcommands: ability to suppress logging of handshake
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37652
diff changeset
  4018
                    ui.pushbuffer()
ad1c07008e0b debugcommands: ability to suppress logging of handshake
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37652
diff changeset
  4019
37645
72b0982cd509 debugcommands: perform handshake when obtaining httpv2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37644
diff changeset
  4020
                peer = httppeer.makepeer(ui, path, opener=opener)
72b0982cd509 debugcommands: perform handshake when obtaining httpv2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37644
diff changeset
  4021
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4022
                if opts[b'nologhandshake']:
37718
ad1c07008e0b debugcommands: ability to suppress logging of handshake
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37652
diff changeset
  4023
                    ui.popbuffer()
ad1c07008e0b debugcommands: ability to suppress logging of handshake
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37652
diff changeset
  4024
37645
72b0982cd509 debugcommands: perform handshake when obtaining httpv2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37644
diff changeset
  4025
            if not isinstance(peer, httppeer.httpv2peer):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4026
                raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4027
                    _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4028
                        b'could not instantiate HTTP peer for '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4029
                        b'wire protocol version 2'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4030
                    ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4031
                    hint=_(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4032
                        b'the server may not have the feature '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4033
                        b'enabled or is not allowing this '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4034
                        b'client version'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4035
                    ),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4036
                )
37645
72b0982cd509 debugcommands: perform handshake when obtaining httpv2 peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37644
diff changeset
  4037
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4038
        elif opts[b'peer'] == b'raw':
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4039
            ui.write(_(b'using raw connection to peer\n'))
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4040
            peer = None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4041
        elif opts[b'peer']:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4042
            raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4043
                _(b'--peer %s not supported with HTTP peers') % opts[b'peer']
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4044
            )
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4045
        else:
37553
6b08cf6b900f httppeer: allow opener to be passed to makepeer()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37552
diff changeset
  4046
            peer = httppeer.makepeer(ui, path, opener=opener)
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4047
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4048
        # We /could/ populate stdin/stdout with sock.makefile()...
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4049
    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4050
        raise error.Abort(_(b'unsupported connection configuration'))
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4051
36531
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4052
    batchedcommands = None
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4053
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4054
    # Now perform actions based on the parsed wire language instructions.
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4055
    for action, lines in blocks:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4056
        if action in (b'raw', b'raw+'):
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4057
            if not stdin:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4058
                raise error.Abort(_(b'cannot call raw/raw+ on this peer'))
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4059
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4060
            # Concatenate the data together.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4061
            data = b''.join(l.lstrip() for l in lines)
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37057
diff changeset
  4062
            data = stringutil.unescapestr(data)
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4063
            stdin.write(data)
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4064
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4065
            if action == b'raw+':
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4066
                stdin.flush()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4067
        elif action == b'flush':
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4068
            if not stdin:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4069
                raise error.Abort(_(b'cannot call flush on this peer'))
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4070
            stdin.flush()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4071
        elif action.startswith(b'command'):
36530
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  4072
            if not peer:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4073
                raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4074
                    _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4075
                        b'cannot send commands unless peer instance '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4076
                        b'is available'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4077
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4078
                )
36530
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  4079
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4080
            command = action.split(b' ', 1)[1]
36530
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  4081
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  4082
            args = {}
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  4083
            for line in lines:
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  4084
                # We need to allow empty values.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4085
                fields = line.lstrip().split(b' ', 1)
36530
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  4086
                if len(fields) == 1:
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  4087
                    key = fields[0]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4088
                    value = b''
36530
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  4089
                else:
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  4090
                    key, value = fields
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  4091
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4092
                if value.startswith(b'eval:'):
37483
61e405fb6372 wireproto: crude support for version 2 HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37396
diff changeset
  4093
                    value = stringutil.evalpythonliteral(value[5:])
61e405fb6372 wireproto: crude support for version 2 HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37396
diff changeset
  4094
                else:
61e405fb6372 wireproto: crude support for version 2 HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37396
diff changeset
  4095
                    value = stringutil.unescapestr(value)
61e405fb6372 wireproto: crude support for version 2 HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37396
diff changeset
  4096
61e405fb6372 wireproto: crude support for version 2 HTTP peer
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37396
diff changeset
  4097
                args[key] = value
36530
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  4098
36531
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4099
            if batchedcommands is not None:
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4100
                batchedcommands.append((command, args))
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4101
                continue
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4102
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4103
            ui.status(_(b'sending %s command\n') % command)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4104
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4105
            if b'PUSHFILE' in args:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4106
                with open(args[b'PUSHFILE'], r'rb') as fh:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4107
                    del args[b'PUSHFILE']
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4108
                    res, output = peer._callpush(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4109
                        command, fh, **pycompat.strkwargs(args)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4110
                    )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4111
                    ui.status(_(b'result: %s\n') % stringutil.escapestr(res))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4112
                    ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4113
                        _(b'remote output: %s\n') % stringutil.escapestr(output)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4114
                    )
36534
5faeabb07cf5 debugcommands: support for triggering push protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36531
diff changeset
  4115
            else:
37652
fe8c6f9f2914 debugcommands: use command executor for invoking commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37647
diff changeset
  4116
                with peer.commandexecutor() as e:
fe8c6f9f2914 debugcommands: use command executor for invoking commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37647
diff changeset
  4117
                    res = e.callcommand(command, args).result()
fe8c6f9f2914 debugcommands: use command executor for invoking commands
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37647
diff changeset
  4118
37720
d715a85003c8 wireprotov2: establish a type for representing command response
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37718
diff changeset
  4119
                if isinstance(res, wireprotov2peer.commandresponse):
39561
d06834e0f48e wireprotov2peer: stream decoded responses
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39449
diff changeset
  4120
                    val = res.objects()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4121
                    ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4122
                        _(b'response: %s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4123
                        % stringutil.pprint(val, bprefix=True, indent=2)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4124
                    )
37720
d715a85003c8 wireprotov2: establish a type for representing command response
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37718
diff changeset
  4125
                else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4126
                    ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4127
                        _(b'response: %s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4128
                        % stringutil.pprint(res, bprefix=True, indent=2)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4129
                    )
36530
bde0bd50f368 debugcommands: allow sending of simple commands with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36528
diff changeset
  4130
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4131
        elif action == b'batchbegin':
36531
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4132
            if batchedcommands is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4133
                raise error.Abort(_(b'nested batchbegin not allowed'))
36531
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4134
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4135
            batchedcommands = []
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4136
        elif action == b'batchsubmit':
36531
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4137
            # There is a batching API we could go through. But it would be
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4138
            # difficult to normalize requests into function calls. It is easier
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4139
            # to bypass this layer and normalize to commands + args.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4140
            ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4141
                _(b'sending batch with %d sub-commands\n')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4142
                % len(batchedcommands)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4143
            )
36531
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4144
            for i, chunk in enumerate(peer._submitbatch(batchedcommands)):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4145
                ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4146
                    _(b'response #%d: %s\n') % (i, stringutil.escapestr(chunk))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4147
                )
36531
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4148
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4149
            batchedcommands = None
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4150
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4151
        elif action.startswith(b'httprequest '):
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4152
            if not opener:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4153
                raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43116
diff changeset
  4154
                    _(b'cannot use httprequest without an HTTP peer')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4155
                )
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4156
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4157
            request = action.split(b' ', 2)
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4158
            if len(request) != 3:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4159
                raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4160
                    _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4161
                        b'invalid httprequest: expected format is '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4162
                        b'"httprequest <method> <path>'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4163
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4164
                )
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4165
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4166
            method, httppath = request[1:]
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4167
            headers = {}
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4168
            body = None
37051
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  4169
            frames = []
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4170
            for line in lines:
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4171
                line = line.lstrip()
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4172
                m = re.match(b'^([a-zA-Z0-9_-]+): (.*)$', line)
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4173
                if m:
39955
c421c22d3ad2 py3: convert HTTP request headers to str
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39884
diff changeset
  4174
                    # Headers need to use native strings.
c421c22d3ad2 py3: convert HTTP request headers to str
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39884
diff changeset
  4175
                    key = pycompat.strurl(m.group(1))
c421c22d3ad2 py3: convert HTTP request headers to str
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39884
diff changeset
  4176
                    value = pycompat.strurl(m.group(2))
c421c22d3ad2 py3: convert HTTP request headers to str
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39884
diff changeset
  4177
                    headers[key] = value
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4178
                    continue
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4179
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4180
                if line.startswith(b'BODYFILE '):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4181
                    with open(line.split(b' ', 1), b'rb') as fh:
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4182
                        body = fh.read()
37051
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  4183
                elif line.startswith(b'frame '):
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  4184
                    frame = wireprotoframing.makeframefromhumanstring(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4185
                        line[len(b'frame ') :]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4186
                    )
37051
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  4187
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  4188
                    frames.append(frame)
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4189
                else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4190
                    raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4191
                        _(b'unknown argument to httprequest: %s') % line
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4192
                    )
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4193
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4194
            url = path + httppath
37051
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  4195
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  4196
            if frames:
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  4197
                body = b''.join(bytes(f) for f in frames)
40206e227412 wireproto: define and implement protocol for issuing requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37047
diff changeset
  4198
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4199
            req = urlmod.urlreq.request(pycompat.strurl(url), body, headers)
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4200
37047
fddcb51b5084 wireproto: define permissions-based routing of HTTPv2 wire protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37045
diff changeset
  4201
            # urllib.Request insists on using has_data() as a proxy for
fddcb51b5084 wireproto: define permissions-based routing of HTTPv2 wire protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37045
diff changeset
  4202
            # determining the request method. Override that to use our
fddcb51b5084 wireproto: define permissions-based routing of HTTPv2 wire protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37045
diff changeset
  4203
            # explicitly requested method.
39064
a2fa7247ca70 debugcommands: get_method should always return a sysstr
Augie Fackler <augie@google.com>
parents: 39062
diff changeset
  4204
            req.get_method = lambda: pycompat.sysstr(method)
37047
fddcb51b5084 wireproto: define permissions-based routing of HTTPv2 wire protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37045
diff changeset
  4205
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4206
            try:
37557
734515aca84d wireproto: define and implement HTTP handshake to upgrade protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37553
diff changeset
  4207
                res = opener.open(req)
734515aca84d wireproto: define and implement HTTP handshake to upgrade protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37553
diff changeset
  4208
                body = res.read()
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4209
            except util.urlerr.urlerror as e:
39065
730e7d92a023 debugcommands: urlerror only has a read() method in Python 2
Augie Fackler <augie@google.com>
parents: 39064
diff changeset
  4210
                # read() method must be called, but only exists in Python 2
730e7d92a023 debugcommands: urlerror only has a read() method in Python 2
Augie Fackler <augie@google.com>
parents: 39064
diff changeset
  4211
                getattr(e, 'read', lambda: None)()
37557
734515aca84d wireproto: define and implement HTTP handshake to upgrade protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37553
diff changeset
  4212
                continue
734515aca84d wireproto: define and implement HTTP handshake to upgrade protocol
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37553
diff changeset
  4213
39956
36e9d2c60837 py3: use system strings for HTTP response header comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39955
diff changeset
  4214
            ct = res.headers.get(r'Content-Type')
36e9d2c60837 py3: use system strings for HTTP response header comparison
Gregory Szorc <gregory.szorc@gmail.com>
parents: 39955
diff changeset
  4215
            if ct == r'application/mercurial-cbor':
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4216
                ui.write(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4217
                    _(b'cbor> %s\n')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4218
                    % stringutil.pprint(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4219
                        cborutil.decodeall(body), bprefix=True, indent=2
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4220
                    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 43067
diff changeset
  4221
                )
37013
b6a7070e7663 debugcommands: support sending HTTP requests with debugwireproto
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37012
diff changeset
  4222
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4223
        elif action == b'close':
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4224
            peer.close()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4225
        elif action == b'readavailable':
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4226
            if not stdout or not stderr:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4227
                raise error.Abort(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4228
                    _(b'readavailable not available on this peer')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4229
                )
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4230
36843
31581528f242 debugwireproto: close the write end before consuming all available data
Yuya Nishihara <yuya@tcha.org>
parents: 36835
diff changeset
  4231
            stdin.close()
31581528f242 debugwireproto: close the write end before consuming all available data
Yuya Nishihara <yuya@tcha.org>
parents: 36835
diff changeset
  4232
            stdout.read()
31581528f242 debugwireproto: close the write end before consuming all available data
Yuya Nishihara <yuya@tcha.org>
parents: 36835
diff changeset
  4233
            stderr.read()
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4234
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4235
        elif action == b'readline':
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4236
            if not stdout:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4237
                raise error.Abort(_(b'readline not available on this peer'))
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4238
            stdout.readline()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4239
        elif action == b'ereadline':
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4240
            if not stderr:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4241
                raise error.Abort(_(b'ereadline not available on this peer'))
37007
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  4242
            stderr.readline()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4243
        elif action.startswith(b'read '):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4244
            count = int(action.split(b' ', 1)[1])
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4245
            if not stdout:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4246
                raise error.Abort(_(b'read not available on this peer'))
37007
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  4247
            stdout.read(count)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4248
        elif action.startswith(b'eread '):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4249
            count = int(action.split(b' ', 1)[1])
37012
fc8939825632 debugcommands: support connecting to HTTP peers
Gregory Szorc <gregory.szorc@gmail.com>
parents: 37007
diff changeset
  4250
            if not stderr:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4251
                raise error.Abort(_(b'eread not available on this peer'))
37007
143219fc2620 debugcommands: introduce actions to perform deterministic reads
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36988
diff changeset
  4252
            stderr.read(count)
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4253
        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4254
            raise error.Abort(_(b'unknown action: %s') % action)
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4255
36531
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4256
    if batchedcommands is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  4257
        raise error.Abort(_(b'unclosed "batchbegin" request'))
36531
097ad1079192 debugcommands: support for sending "batch" requests
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36530
diff changeset
  4258
36528
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4259
    if peer:
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4260
        peer.close()
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4261
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4262
    if proc:
72e487851a53 debugcommands: add debugwireproto command
Gregory Szorc <gregory.szorc@gmail.com>
parents: 36527
diff changeset
  4263
        proc.kill()