~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/remote.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) 2006-2011 Canonical Ltd
 
1
# Copyright (C) 2006-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
3190
3190
        self.id = "branch"
3191
3191
        self._real_store = None
3192
3192
 
3193
 
    def lock_write(self, token=None):
3194
 
        return self.branch.lock_write(token)
3195
 
 
3196
 
    def unlock(self):
3197
 
        return self.branch.unlock()
3198
 
 
3199
 
    @needs_write_lock
3200
 
    def save(self):
3201
 
        # We need to be able to override the undecorated implementation
3202
 
        self.save_without_locking()
3203
 
 
3204
 
    def save_without_locking(self):
3205
 
        super(RemoteBranchStore, self).save()
3206
 
 
3207
3193
    def external_url(self):
3208
3194
        return self.branch.user_url
3209
3195
 
3293
3279
        self._repo_lock_token = None
3294
3280
        self._lock_count = 0
3295
3281
        self._leave_lock = False
 
3282
        self.conf_store = None
3296
3283
        # Setup a format: note that we cannot call _ensure_real until all the
3297
3284
        # attributes above are set: This code cannot be moved higher up in this
3298
3285
        # function.
3341
3328
        return RemoteBranchConfig(self)
3342
3329
 
3343
3330
    def _get_config_store(self):
3344
 
        return RemoteBranchStore(self)
 
3331
        if self.conf_store is None:
 
3332
            self.conf_store =  RemoteBranchStore(self)
 
3333
        return self.conf_store
3345
3334
 
3346
3335
    def _get_real_transport(self):
3347
3336
        # if we try vfs access, return the real branch's vfs transport
3367
3356
            self.bzrdir._ensure_real()
3368
3357
            self._real_branch = self.bzrdir._real_bzrdir.open_branch(
3369
3358
                ignore_fallbacks=self._real_ignore_fallbacks, name=self._name)
 
3359
            # The remote branch and the real branch shares the same store. If
 
3360
            # we don't, there will always be cases where one of the stores
 
3361
            # doesn't see an update made on the other.
 
3362
            self._real_branch.conf_store = self.conf_store
3370
3363
            if self.repository._real_repository is None:
3371
3364
                # Give the remote repository the matching real repo.
3372
3365
                real_repo = self._real_branch.repository
3450
3443
 
3451
3444
    def set_stacked_on_url(self, url):
3452
3445
        branch.Branch.set_stacked_on_url(self, url)
 
3446
        # We need the stacked_on_url to be visible both locally (to not query
 
3447
        # it repeatedly) and remotely (so smart verbs can get it server side)
 
3448
        # Without the following line,
 
3449
        # bzrlib.tests.per_branch.test_create_clone.TestCreateClone
 
3450
        # .test_create_clone_on_transport_stacked_hooks_get_stacked_branch
 
3451
        # fails for remote branches -- vila 2012-01-04
 
3452
        self.conf_store.save_changes()
3453
3453
        if not url:
3454
3454
            self._is_stacked = False
3455
3455
        else:
3583
3583
        try:
3584
3584
            self._lock_count -= 1
3585
3585
            if not self._lock_count:
 
3586
                if self.conf_store is not None:
 
3587
                    self.conf_store.save_changes()
3586
3588
                self._clear_cached_state()
3587
3589
                mode = self._lock_mode
3588
3590
                self._lock_mode = None
3878
3880
            last_rev=last_rev,other_branch=other_branch))
3879
3881
 
3880
3882
    def set_push_location(self, location):
3881
 
        self._ensure_real()
3882
 
        return self._real_branch.set_push_location(location)
 
3883
        self._set_config_location('push_location', location)
3883
3884
 
3884
3885
    def heads_to_fetch(self):
3885
3886
        if self._format._use_default_local_heads_to_fetch():