~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/breakin.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-09 21:42:24 UTC
  • mto: This revision was merged to the branch mainline in revision 3543.
  • Revision ID: john@arbash-meinel.com-20080709214224-r75k87r6a01pfc3h
Restore a real weave merge to 'bzr merge --weave'.

To do so efficiently, we only add the simple LCAs to the final weave
object, unless we run into complexities with the merge graph.
This gives the same effective result as adding all the texts,
with the advantage of not having to extract all of them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
 
from __future__ import absolute_import
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
16
 
19
17
import os
20
18
import signal
21
19
 
22
 
 
23
 
_breakin_signal_number = None
24
 
_breakin_signal_name = None
25
 
 
26
 
 
27
20
def _debug(signal_number, interrupted_frame):
28
21
    import pdb
29
22
    import sys
30
 
    sys.stderr.write("** %s received, entering debugger\n"
 
23
    sys.stderr.write("** SIGQUIT received, entering debugger\n"
31
24
            "** Type 'c' to continue or 'q' to stop the process\n"
32
 
            "** Or %s again to quit (and possibly dump core)\n"
33
 
            % (_breakin_signal_name, _breakin_signal_name))
34
 
    # It seems that on Windows, when sys.stderr is to a PIPE, then we need to
35
 
    # flush. Not sure why it is buffered, but that seems to be the case.
36
 
    sys.stderr.flush()
 
25
            "** Or SIGQUIT again to quit (and possibly dump core)\n"
 
26
            )
37
27
    # restore default meaning so that you can kill the process by hitting it
38
28
    # twice
39
 
    signal.signal(_breakin_signal_number, signal.SIG_DFL)
 
29
    signal.signal(signal.SIGQUIT, signal.SIG_DFL)
40
30
    try:
41
31
        pdb.set_trace()
42
32
    finally:
43
 
        signal.signal(_breakin_signal_number, _debug)
44
 
 
45
 
 
46
 
def determine_signal():
47
 
    global _breakin_signal_number
48
 
    global _breakin_signal_name
49
 
    if _breakin_signal_number is not None:
50
 
        return _breakin_signal_number
51
 
    # Note: As near as I can tell, Windows is the only one to define SIGBREAK,
52
 
    #       and other platforms defined SIGQUIT. There doesn't seem to be a
53
 
    #       platform that defines both.
54
 
    #       -- jam 2009-07-30
55
 
    sigquit = getattr(signal, 'SIGQUIT', None)
56
 
    sigbreak = getattr(signal, 'SIGBREAK', None)
57
 
    if sigquit is not None:
58
 
        _breakin_signal_number = sigquit
59
 
        _breakin_signal_name = 'SIGQUIT'
60
 
    elif sigbreak is not None:
61
 
        _breakin_signal_number = sigbreak
62
 
        _breakin_signal_name = 'SIGBREAK'
63
 
 
64
 
    return _breakin_signal_number
65
 
 
66
 
 
67
 
def hook_debugger_to_signal():
68
 
    """Add a signal handler so we drop into the debugger.
69
 
 
70
 
    On Unix, this is hooked into SIGQUIT (C-\\), and on Windows, this is
71
 
    hooked into SIGBREAK (C-Pause).
72
 
    """
73
 
 
74
 
    # when sigquit (C-\) or sigbreak (C-Pause) is received go into pdb
75
 
    if os.environ.get('BZR_SIGQUIT_PDB', '1') == '0':
76
 
        # User explicitly requested we don't support this
77
 
        return
78
 
    sig = determine_signal()
79
 
    if sig is None:
80
 
        return
81
 
    # print 'hooking into %s' % (_breakin_signal_name,)
82
 
    signal.signal(sig, _debug)
 
33
        signal.signal(signal.SIGQUIT, _debug)
 
34
 
 
35
 
 
36
def hook_sigquit():
 
37
    # when sigquit (C-\) is received go into pdb
 
38
    if (os.environ.get('BZR_SIGQUIT_PDB', '1') == '0'
 
39
        or getattr(signal, 'SIGQUIT', None) is None):
 
40
        return
 
41
    signal.signal(signal.SIGQUIT, _debug)