~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

Rework test_script a little bit.


Don't allow someone to request a stdin request to echo.
Echo never reads from stdin, it just echos its arguments.
You use 'cat' if you want to read from stdin.

A few other fixes because the tests were using filenames
that are actually illegal on Windows, rather than just
nonexistant.


Change the exception handling for commands so that
unknown errors don't get silently squashed and then
turn into hard-to-debug errors later.

test_script now passes on Windows.

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
 
49
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
50
50
from bzrlib.hooks import HookPoint, Hooks
51
51
from bzrlib.inter import InterObject
 
52
from bzrlib.lock import _RelockDebugMixin
52
53
from bzrlib import registry
53
54
from bzrlib.symbol_versioning import (
54
55
    deprecated_in,
1284
1285
        # clone call. Or something. 20090224 RBC/spiv.
1285
1286
        if revision_id is None:
1286
1287
            revision_id = self.last_revision()
1287
 
        dir_to = self.bzrdir.clone_on_transport(to_transport,
1288
 
            revision_id=revision_id, stacked_on=stacked_on,
1289
 
            create_prefix=create_prefix, use_existing_dir=use_existing_dir)
 
1288
        try:
 
1289
            dir_to = self.bzrdir.clone_on_transport(to_transport,
 
1290
                revision_id=revision_id, stacked_on=stacked_on,
 
1291
                create_prefix=create_prefix, use_existing_dir=use_existing_dir)
 
1292
        except errors.FileExists:
 
1293
            if not use_existing_dir:
 
1294
                raise
 
1295
        except errors.NoSuchFile:
 
1296
            if not create_prefix:
 
1297
                raise
1290
1298
        return dir_to.open_branch()
1291
1299
 
1292
1300
    def create_checkout(self, to_location, revision_id=None,
2072
2080
    _legacy_formats[0].network_name(), _legacy_formats[0].__class__)
2073
2081
 
2074
2082
 
2075
 
class BzrBranch(Branch):
 
2083
class BzrBranch(Branch, _RelockDebugMixin):
2076
2084
    """A branch stored in the actual filesystem.
2077
2085
 
2078
2086
    Note that it's "local" in the context of the filesystem; it doesn't
2124
2132
        return self.control_files.is_locked()
2125
2133
 
2126
2134
    def lock_write(self, token=None):
 
2135
        if not self.is_locked():
 
2136
            self._note_lock('w')
2127
2137
        # All-in-one needs to always unlock/lock.
2128
2138
        repo_control = getattr(self.repository, 'control_files', None)
2129
2139
        if self.control_files == repo_control or not self.is_locked():
2139
2149
            raise
2140
2150
 
2141
2151
    def lock_read(self):
 
2152
        if not self.is_locked():
 
2153
            self._note_lock('r')
2142
2154
        # All-in-one needs to always unlock/lock.
2143
2155
        repo_control = getattr(self.repository, 'control_files', None)
2144
2156
        if self.control_files == repo_control or not self.is_locked():
2153
2165
                self.repository.unlock()
2154
2166
            raise
2155
2167
 
 
2168
    @only_raises(errors.LockNotHeld, errors.LockBroken)
2156
2169
    def unlock(self):
2157
2170
        try:
2158
2171
            self.control_files.unlock()