~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.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:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2012 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
1225
1225
        self._set_config_location('public_branch', location)
1226
1226
 
1227
1227
    def get_push_location(self):
1228
 
        """Return the None or the location to push this branch to."""
1229
 
        push_loc = self.get_config().get_user_option('push_location')
 
1228
        """Return None or the location to push this branch to."""
 
1229
        push_loc = self._get_config_location('push_location')
1230
1230
        return push_loc
1231
1231
 
1232
1232
    def set_push_location(self, location):
2464
2464
        self.control_files = _control_files
2465
2465
        self._transport = _control_files._transport
2466
2466
        self.repository = _repository
 
2467
        self.conf_store = None
2467
2468
        Branch.__init__(self, possible_transports)
2468
2469
 
2469
2470
    def __str__(self):
2485
2486
        return _mod_config.TransportConfig(self._transport, 'branch.conf')
2486
2487
 
2487
2488
    def _get_config_store(self):
2488
 
        return _mod_config.BranchStore(self)
 
2489
        if self.conf_store is None:
 
2490
            self.conf_store =  _mod_config.BranchStore(self)
 
2491
        return self.conf_store
2489
2492
 
2490
2493
    def is_locked(self):
2491
2494
        return self.control_files.is_locked()
2540
2543
 
2541
2544
    @only_raises(errors.LockNotHeld, errors.LockBroken)
2542
2545
    def unlock(self):
 
2546
        if self.conf_store is not None:
 
2547
            self.conf_store.save_changes()
2543
2548
        try:
2544
2549
            self.control_files.unlock()
2545
2550
        finally:
3218
3223
 
3219
3224
        # Copy source data into target
3220
3225
        new_branch._write_last_revision_info(*branch.last_revision_info())
3221
 
        new_branch.set_parent(branch.get_parent())
3222
 
        new_branch.set_bound_location(branch.get_bound_location())
3223
 
        new_branch.set_push_location(branch.get_push_location())
 
3226
        new_branch.lock_write()
 
3227
        try:
 
3228
            new_branch.set_parent(branch.get_parent())
 
3229
            new_branch.set_bound_location(branch.get_bound_location())
 
3230
            new_branch.set_push_location(branch.get_push_location())
 
3231
        finally:
 
3232
            new_branch.unlock()
3224
3233
 
3225
3234
        # New branch has no tags by default
3226
3235
        new_branch.tags._set_tag_dict({})
3232
3241
 
3233
3242
        # Clean up old files
3234
3243
        new_branch._transport.delete('revision-history')
 
3244
        branch.lock_write()
3235
3245
        try:
3236
 
            branch.set_parent(None)
3237
 
        except errors.NoSuchFile:
3238
 
            pass
3239
 
        branch.set_bound_location(None)
 
3246
            try:
 
3247
                branch.set_parent(None)
 
3248
            except errors.NoSuchFile:
 
3249
                pass
 
3250
            branch.set_bound_location(None)
 
3251
        finally:
 
3252
            branch.unlock()
3240
3253
 
3241
3254
 
3242
3255
class Converter6to7(object):
3244
3257
 
3245
3258
    def convert(self, branch):
3246
3259
        format = BzrBranchFormat7()
3247
 
        branch._set_config_location('stacked_on_location', '')
 
3260
        branch.lock_write()
 
3261
        try:
 
3262
            branch._set_config_location('stacked_on_location', '')
 
3263
        finally:
 
3264
            branch.unlock()
3248
3265
        # update target format
3249
3266
        branch._transport.put_bytes('format', format.as_string())
3250
3267