~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-09-19 00:32:14 UTC
  • mfrom: (4685.2.1 bzr.dev)
  • Revision ID: pqm@pqm.ubuntu.com-20090919003214-2dli9jc4y5xhjj3n
(mbp for garyvdm) Revert rename of
        test_merge_uncommitted_otherbasis_ancestor_of_thisbasis.

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
    )
47
47
""")
48
48
 
49
 
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
 
49
from bzrlib.decorators import needs_read_lock, needs_write_lock
50
50
from bzrlib.hooks import HookPoint, Hooks
51
51
from bzrlib.inter import InterObject
52
 
from bzrlib.lock import _RelockDebugMixin
53
52
from bzrlib import registry
54
53
from bzrlib.symbol_versioning import (
55
54
    deprecated_in,
503
502
                left_parent = stop_rev.parent_ids[0]
504
503
            else:
505
504
                left_parent = _mod_revision.NULL_REVISION
506
 
            # left_parent is the actual revision we want to stop logging at,
507
 
            # since we want to show the merged revisions after the stop_rev too
508
 
            reached_stop_revision_id = False
509
 
            revision_id_whitelist = []
510
505
            for node in rev_iter:
511
506
                rev_id = node.key[-1]
512
507
                if rev_id == left_parent:
513
 
                    # reached the left parent after the stop_revision
514
508
                    return
515
 
                if (not reached_stop_revision_id or
516
 
                        rev_id in revision_id_whitelist):
517
 
                    yield (rev_id, node.merge_depth, node.revno,
 
509
                yield (rev_id, node.merge_depth, node.revno,
518
510
                       node.end_of_merge)
519
 
                    if reached_stop_revision_id or rev_id == stop_revision_id:
520
 
                        # only do the merged revs of rev_id from now on
521
 
                        rev = self.repository.get_revision(rev_id)
522
 
                        if rev.parent_ids:
523
 
                            reached_stop_revision_id = True
524
 
                            revision_id_whitelist.extend(rev.parent_ids)
525
511
        else:
526
512
            raise ValueError('invalid stop_rule %r' % stop_rule)
527
513
 
1103
1089
        params = ChangeBranchTipParams(
1104
1090
            self, old_revno, new_revno, old_revid, new_revid)
1105
1091
        for hook in hooks:
1106
 
            hook(params)
 
1092
            try:
 
1093
                hook(params)
 
1094
            except errors.TipChangeRejected:
 
1095
                raise
 
1096
            except Exception:
 
1097
                exc_info = sys.exc_info()
 
1098
                hook_name = Branch.hooks.get_hook_name(hook)
 
1099
                raise errors.HookFailed(
 
1100
                    'pre_change_branch_tip', hook_name, exc_info)
1107
1101
 
1108
1102
    @needs_write_lock
1109
1103
    def update(self):
1290
1284
        # clone call. Or something. 20090224 RBC/spiv.
1291
1285
        if revision_id is None:
1292
1286
            revision_id = self.last_revision()
1293
 
        dir_to = self.bzrdir.clone_on_transport(to_transport,
1294
 
            revision_id=revision_id, stacked_on=stacked_on,
1295
 
            create_prefix=create_prefix, use_existing_dir=use_existing_dir)
 
1287
        try:
 
1288
            dir_to = self.bzrdir.clone_on_transport(to_transport,
 
1289
                revision_id=revision_id, stacked_on=stacked_on,
 
1290
                create_prefix=create_prefix, use_existing_dir=use_existing_dir)
 
1291
        except errors.FileExists:
 
1292
            if not use_existing_dir:
 
1293
                raise
 
1294
        except errors.NoSuchFile:
 
1295
            if not create_prefix:
 
1296
                raise
1296
1297
        return dir_to.open_branch()
1297
1298
 
1298
1299
    def create_checkout(self, to_location, revision_id=None,
1438
1439
        """Return the format for the branch object in a_bzrdir."""
1439
1440
        try:
1440
1441
            transport = a_bzrdir.get_branch_transport(None)
1441
 
            format_string = transport.get_bytes("format")
 
1442
            format_string = transport.get("format").read()
1442
1443
            return klass._formats[format_string]
1443
1444
        except errors.NoSuchFile:
1444
1445
            raise errors.NotBranchError(path=transport.base)
1977
1978
    def get_reference(self, a_bzrdir):
1978
1979
        """See BranchFormat.get_reference()."""
1979
1980
        transport = a_bzrdir.get_branch_transport(None)
1980
 
        return transport.get_bytes('location')
 
1981
        return transport.get('location').read()
1981
1982
 
1982
1983
    def set_reference(self, a_bzrdir, to_branch):
1983
1984
        """See BranchFormat.set_reference()."""
2078
2079
    _legacy_formats[0].network_name(), _legacy_formats[0].__class__)
2079
2080
 
2080
2081
 
2081
 
class BzrBranch(Branch, _RelockDebugMixin):
 
2082
class BzrBranch(Branch):
2082
2083
    """A branch stored in the actual filesystem.
2083
2084
 
2084
2085
    Note that it's "local" in the context of the filesystem; it doesn't
2130
2131
        return self.control_files.is_locked()
2131
2132
 
2132
2133
    def lock_write(self, token=None):
2133
 
        if not self.is_locked():
2134
 
            self._note_lock('w')
2135
2134
        # All-in-one needs to always unlock/lock.
2136
2135
        repo_control = getattr(self.repository, 'control_files', None)
2137
2136
        if self.control_files == repo_control or not self.is_locked():
2138
 
            self.repository._warn_if_deprecated(self)
2139
2137
            self.repository.lock_write()
2140
2138
            took_lock = True
2141
2139
        else:
2148
2146
            raise
2149
2147
 
2150
2148
    def lock_read(self):
2151
 
        if not self.is_locked():
2152
 
            self._note_lock('r')
2153
2149
        # All-in-one needs to always unlock/lock.
2154
2150
        repo_control = getattr(self.repository, 'control_files', None)
2155
2151
        if self.control_files == repo_control or not self.is_locked():
2156
 
            self.repository._warn_if_deprecated(self)
2157
2152
            self.repository.lock_read()
2158
2153
            took_lock = True
2159
2154
        else:
2165
2160
                self.repository.unlock()
2166
2161
            raise
2167
2162
 
2168
 
    @only_raises(errors.LockNotHeld, errors.LockBroken)
2169
2163
    def unlock(self):
2170
2164
        try:
2171
2165
            self.control_files.unlock()