contrib/debugshell.py
author C. Masloch <pushbx@ulukai.org>
Wed, 20 Apr 2022 19:24:39 +0200
changeset 49449 cfff73cab721
parent 48875 6000f5b25c9b
permissions -rw-r--r--
rebase: add boolean config item rebase.store-source This allows to use rebase without recording a rebase_source extra field. This is useful for example to build a mirror converted from another SCM (such as svn) by converting only new revisions, and then incrementally add them to the destination by pulling from the newly converted (unrelated) repo and rebasing the new revisions onto the last old already stored changeset. Without this patch the rebased changesets would always receive some rebase_source that would depend on the particular history of the conversion process, instead of only depending on the original source revisions. This is used to implement a hg mirror repo of SvarDOS (a partially nonfree but completely redistributable DOS distribution) in the scripts at https://hg.pushbx.org/ecm/svardos.scr/ In particular, cre.sh creates an svn mirror, upd.sh recreates an entire hg repo from the svn mirror (which takes too long to do in a regular job), and akt.sh uses hg convert with the config item convert.svn.startrev to incrementally convert only the two most recent revisions already found in the mirror destination plus any possible new revisions. If any are found, the temporary repo's changesets are pulled into the destination (as changesets from an unrelated repository). Then the changesets corresponding to the new revisions are rebased onto the prior final changeset. (Finally, the two remaining duplicates of the prior head and its parent are stripped from the destination repository.) Without this patch, the particular rebase_source extra field would depend on the order and times at which akt.sh was used, instead of only depending on the source repository. In other words, whatever sequence of upd.sh and akt.sh is used at whatever times, it is desired that the final output repositories always match each other exactly.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11633
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
     1
# debugshell extension
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
     2
"""a python shell with repo, changelog & manifest objects"""
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
     3
28476
e28dc6de38e7 debugshell: use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27721
diff changeset
     4
import code
11633
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
     5
import mercurial
28476
e28dc6de38e7 debugshell: use absolute_import
Pulkit Goyal <7895pulkit@gmail.com>
parents: 27721
diff changeset
     6
import sys
27721
e4b512bb6386 debugshell: disable demand importer when importing debugger
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21243
diff changeset
     7
from mercurial import (
e4b512bb6386 debugshell: disable demand importer when importing debugger
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21243
diff changeset
     8
    demandimport,
41814
b10bbbe995eb py3: make contrib/debugshell.py work with Python 3
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41759
diff changeset
     9
    pycompat,
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 30375
diff changeset
    10
    registrar,
27721
e4b512bb6386 debugshell: disable demand importer when importing debugger
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21243
diff changeset
    11
)
21243
8b5c039f2b4f debugshell: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19794
diff changeset
    12
8b5c039f2b4f debugshell: declare command using decorator
Gregory Szorc <gregory.szorc@gmail.com>
parents: 19794
diff changeset
    13
cmdtable = {}
32337
46ba2cdda476 registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents: 30375
diff changeset
    14
command = registrar.command(cmdtable)
11633
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    15
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41814
diff changeset
    16
19771
3bc675361206 debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents: 11633
diff changeset
    17
def pdb(ui, repo, msg, **opts):
11633
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    18
    objects = {
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    19
        'mercurial': mercurial,
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    20
        'repo': repo,
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    21
        'cl': repo.changelog,
30375
11b8b740d54a manifest: remove last uses of repo.manifest
Durham Goode <durham@fb.com>
parents: 29397
diff changeset
    22
        'mf': repo.manifestlog,
11633
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    23
    }
19771
3bc675361206 debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents: 11633
diff changeset
    24
3bc675361206 debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents: 11633
diff changeset
    25
    code.interact(msg, local=objects)
3bc675361206 debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents: 11633
diff changeset
    26
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41814
diff changeset
    27
19772
6ccec36a1fd9 debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents: 19771
diff changeset
    28
def ipdb(ui, repo, msg, **opts):
6ccec36a1fd9 debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents: 19771
diff changeset
    29
    import IPython
6ccec36a1fd9 debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents: 19771
diff changeset
    30
6ccec36a1fd9 debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents: 19771
diff changeset
    31
    cl = repo.changelog
30375
11b8b740d54a manifest: remove last uses of repo.manifest
Durham Goode <durham@fb.com>
parents: 29397
diff changeset
    32
    mf = repo.manifestlog
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41814
diff changeset
    33
    cl, mf  # use variables to appease pyflakes
19772
6ccec36a1fd9 debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents: 19771
diff changeset
    34
6ccec36a1fd9 debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents: 19771
diff changeset
    35
    IPython.embed()
6ccec36a1fd9 debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents: 19771
diff changeset
    36
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41814
diff changeset
    37
41814
b10bbbe995eb py3: make contrib/debugshell.py work with Python 3
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41759
diff changeset
    38
@command(b'debugshell|dbsh', [])
19771
3bc675361206 debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents: 11633
diff changeset
    39
def debugshell(ui, repo, **opts):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41814
diff changeset
    40
    bannermsg = "loaded repo : %s\n" "using source: %s" % (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41814
diff changeset
    41
        pycompat.sysstr(repo.root),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41814
diff changeset
    42
        mercurial.__path__[0],
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41814
diff changeset
    43
    )
19771
3bc675361206 debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents: 11633
diff changeset
    44
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41814
diff changeset
    45
    pdbmap = {'pdb': 'code', 'ipdb': 'IPython'}
19773
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    46
41814
b10bbbe995eb py3: make contrib/debugshell.py work with Python 3
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41759
diff changeset
    47
    debugger = ui.config(b"ui", b"debugger")
19773
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    48
    if not debugger:
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    49
        debugger = 'pdb'
41814
b10bbbe995eb py3: make contrib/debugshell.py work with Python 3
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41759
diff changeset
    50
    else:
b10bbbe995eb py3: make contrib/debugshell.py work with Python 3
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41759
diff changeset
    51
        debugger = pycompat.sysstr(debugger)
19773
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    52
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    53
    # if IPython doesn't exist, fallback to code.interact
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    54
    try:
27721
e4b512bb6386 debugshell: disable demand importer when importing debugger
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21243
diff changeset
    55
        with demandimport.deactivated():
e4b512bb6386 debugshell: disable demand importer when importing debugger
Gregory Szorc <gregory.szorc@gmail.com>
parents: 21243
diff changeset
    56
            __import__(pdbmap[debugger])
19773
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    57
    except ImportError:
43080
86e4daa2d54c cleanup: mark some ui.(status|note|warn|write) calls as not needing i18n
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    58
        ui.warnnoi18n(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41814
diff changeset
    59
            b"%s debugger specified but %s module was not found\n"
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41814
diff changeset
    60
            % (debugger, pdbmap[debugger])
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 41814
diff changeset
    61
        )
41814
b10bbbe995eb py3: make contrib/debugshell.py work with Python 3
Pulkit Goyal <pulkit@yandex-team.ru>
parents: 41759
diff changeset
    62
        debugger = b'pdb'
19773
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    63
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    64
    getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts)