contrib/debugshell.py
author Simon Heimberg <simohe@besonet.ch>
Sat, 08 Feb 2014 14:35:07 +0100
changeset 20425 ca6aa8362f33
parent 19794 cccc44304b2c
child 21243 8b5c039f2b4f
permissions -rw-r--r--
win32: spawndetached returns pid of detached process and not of cmd.exe win32.spawndetached starts the detached process by `cmd.exe` (or COMSPEC). The pid it returned was the one of cmd.exe and not the one of the detached process. When this pid is used to kill the process, the detached process is not killed, but only cmd.exe. With this patch the pid of the detached process is written to the pid file. Killing the process works as expected. The pid is only evaluated on writing the pid file. It is unnecessary to search the pid when it is not needed. And more important, it probably does not yet exist right after the cmd.exe process was started. When the pid is written to the file, waiting for the start of the detached process has already happened. Use this functionality instead of writing a 2nd wait function. Many tests on windows will not fail anymore, all those with the first failing line "abort: child process failed to start". (The processes still hanging around from previous test runs have to be killed first. They still block a tcp port.) A good test for the functionality of this patch is test-treediscovery.t, because it starts and kills `hg serve -d` several times.
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
19773
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
     4
import sys
11633
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
     5
import mercurial
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
     6
import code
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
     7
19771
3bc675361206 debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents: 11633
diff changeset
     8
def pdb(ui, repo, msg, **opts):
11633
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
     9
    objects = {
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    10
        'mercurial': mercurial,
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    11
        'repo': repo,
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    12
        'cl': repo.changelog,
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    13
        'mf': repo.manifest,
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    14
    }
19771
3bc675361206 debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents: 11633
diff changeset
    15
3bc675361206 debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents: 11633
diff changeset
    16
    code.interact(msg, local=objects)
3bc675361206 debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents: 11633
diff changeset
    17
19772
6ccec36a1fd9 debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents: 19771
diff changeset
    18
def ipdb(ui, repo, msg, **opts):
6ccec36a1fd9 debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents: 19771
diff changeset
    19
    import IPython
6ccec36a1fd9 debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents: 19771
diff changeset
    20
6ccec36a1fd9 debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents: 19771
diff changeset
    21
    cl = repo.changelog
6ccec36a1fd9 debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents: 19771
diff changeset
    22
    mf = repo.manifest
19794
cccc44304b2c debugshell: appease pyflakes
Matt Mackall <mpm@selenic.com>
parents: 19773
diff changeset
    23
    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
    24
6ccec36a1fd9 debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents: 19771
diff changeset
    25
    IPython.embed()
6ccec36a1fd9 debugshell: add function to embed ipython
Sean Farley <sean.michael.farley@gmail.com>
parents: 19771
diff changeset
    26
19771
3bc675361206 debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents: 11633
diff changeset
    27
def debugshell(ui, repo, **opts):
11633
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    28
    bannermsg = "loaded repo : %s\n" \
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    29
                "using source: %s" % (repo.root,
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    30
                                      mercurial.__path__[0])
19771
3bc675361206 debugshell: abstract out pdb code.interact
Sean Farley <sean.michael.farley@gmail.com>
parents: 11633
diff changeset
    31
19773
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    32
    pdbmap = {
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    33
        'pdb'  : 'code',
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    34
        'ipdb' : 'IPython'
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    35
    }
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    36
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    37
    debugger = ui.config("ui", "debugger")
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    38
    if not debugger:
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    39
        debugger = 'pdb'
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    40
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    41
    # 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
    42
    try:
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    43
        __import__(pdbmap[debugger])
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    44
    except ImportError:
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    45
        ui.warn("%s debugger specified but %s module was not found\n"
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    46
                % (debugger, pdbmap[debugger]))
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    47
        debugger = 'pdb'
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    48
51799a965446 debugshell: check ui.debugger for which debugger to use
Sean Farley <sean.michael.farley@gmail.com>
parents: 19772
diff changeset
    49
    getattr(sys.modules[__name__], debugger)(ui, repo, bannermsg, **opts)
11633
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    50
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    51
cmdtable = {
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    52
    "debugshell|dbsh": (debugshell, [])
6b7b99867ada contrib: add debugshell extension
Vishakh H <vsh426@gmail.com>
parents:
diff changeset
    53
}