/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/debug.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-05 14:26:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105142658-vek3v6pzlxb751s2
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. 

@only_raises is evil and gave a hard time since any exception during
save_changes() was swallowed.

Possible improvements: 

- add some needs_write_lock decorators to crucial
  methods (_set_config_location ?) but keep locking the branch at higher levels

- decorate branch.unlock to call stack.save if last_lock() it True
  outside of @only_raises scope (evil decorator)

- add @needs_write_lock to stack.set and stack.remove (will probably get
  rid of most testing issues) we probably need a specialized decorator
  that can relay to the store and from there to the branch or whatever is
  needed. This will also helps bzr config to get it right. The
  get_mutable_section trick should not be needed anymore either.

- decorate branch.unlock to call stack.save if last_lock() it True outside
  of @only_raises scope (evil decorator)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
 
18
17
"""Set of flags that enable different debug behaviour.
19
18
 
20
19
These are set with eg ``-Dlock`` on the bzr command line or in
24
23
for a list of the available options.
25
24
"""
26
25
 
 
26
from __future__ import absolute_import
27
27
 
28
28
debug_flags = set()
29
29
 
31
31
def set_debug_flags_from_config():
32
32
    """Turn on debug flags based on the global configuration"""
33
33
 
34
 
    from bzrlib.config import GlobalConfig
35
 
 
36
 
    c = GlobalConfig()
37
 
    value = c.get_user_option("debug_flags")
38
 
    if value is not None:
39
 
        # configobject gives us either a string if there's just one or a list
40
 
        # if there's multiple
41
 
        if isinstance(value, basestring):
42
 
            value = [value]
43
 
        for w in value:
44
 
            w = w.strip()
45
 
            debug_flags.add(w)
 
34
    from bzrlib import config
 
35
 
 
36
    c = config.GlobalStack()
 
37
    for f in c.get('debug_flags'):
 
38
        debug_flags.add(f)
 
39
 
 
40
 
 
41
def set_trace():
 
42
    """Pdb using original stdin and stdout.
 
43
 
 
44
    When debugging blackbox tests, sys.stdin and sys.stdout are captured for
 
45
    test purposes and cannot be used for interactive debugging. This class uses
 
46
    the origianl stdin/stdout to allow such use.
 
47
 
 
48
    Instead of doing:
 
49
 
 
50
       import pdb; pdb.set_trace()
 
51
 
 
52
    you can do:
 
53
 
 
54
       from bzrlib import debug; debug.set_trace()
 
55
    """
 
56
    import pdb
 
57
    import sys
 
58
    pdb.Pdb(stdin=sys.__stdin__, stdout=sys.__stdout__
 
59
            ).set_trace(sys._getframe().f_back)