~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/builtins.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
1118
1118
            # Remembers if asked explicitly or no previous location is set
1119
1119
            if (remember
1120
1120
                or (remember is None and branch_to.get_parent() is None)):
1121
 
                branch_to.set_parent(branch_from.base)
 
1121
                branch_to.lock_write()
 
1122
                try:
 
1123
                    # FIXME: This shouldn't be done before the pull
 
1124
                    # succeeds... -- vila 2012-01-02
 
1125
                    branch_to.set_parent(branch_from.base)
 
1126
                finally:
 
1127
                    branch_to.unlock()
1122
1128
 
1123
1129
        if revision is not None:
1124
1130
            revision_id = revision.as_revision_id(branch_from)
2011
2017
                a_bzrdir.create_workingtree()
2012
2018
        if append_revisions_only:
2013
2019
            try:
2014
 
                branch.set_append_revisions_only(True)
 
2020
                branch.lock_write()
 
2021
                try:
 
2022
                    branch.set_append_revisions_only(True)
 
2023
                finally:
 
2024
                    branch.unlock()
2015
2025
            except errors.UpgradeRequired:
2016
2026
                raise errors.BzrCommandError(gettext('This branch format cannot be set'
2017
2027
                    ' to append-revisions-only.  Try --default.'))
3768
3778
            if directory is None:
3769
3779
                c = Branch.open_containing(u'.')[0].get_config_stack()
3770
3780
            else:
3771
 
                c = Branch.open(directory).get_config_stack()
 
3781
                b = Branch.open(directory)
 
3782
                self.add_cleanup(b.lock_write().unlock)
 
3783
                c = b.get_config_stack()
3772
3784
        else:
3773
3785
            c = _mod_config.GlobalStack()
3774
3786
        c.set('email', name)
5158
5170
            else:
5159
5171
                if location is None:
5160
5172
                    if b.get_bound_location() is not None:
5161
 
                        raise errors.BzrCommandError(gettext('Branch is already bound'))
 
5173
                        raise errors.BzrCommandError(
 
5174
                            gettext('Branch is already bound'))
5162
5175
                    else:
5163
 
                        raise errors.BzrCommandError(gettext('No location supplied '
5164
 
                            'and no previous location known'))
 
5176
                        raise errors.BzrCommandError(
 
5177
                            gettext('No location supplied'
 
5178
                                    ' and no previous location known'))
5165
5179
        b_other = Branch.open(location)
5166
5180
        try:
5167
5181
            b.bind(b_other)
5577
5591
        if public_branch is None:
5578
5592
            public_branch = stored_public_branch
5579
5593
        elif stored_public_branch is None:
5580
 
            branch.set_public_branch(public_branch)
 
5594
            # FIXME: Should be done only if we succeed ? -- vila 2012-01-03
 
5595
            branch.lock_write()
 
5596
            try:
 
5597
                branch.set_public_branch(public_branch)
 
5598
            finally:
 
5599
                branch.unlock()
5581
5600
        if not include_bundle and public_branch is None:
5582
5601
            raise errors.BzrCommandError(gettext('No public branch specified or'
5583
5602
                                         ' known'))