/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Martin Pool
  • Date: 2010-04-28 07:03:38 UTC
  • mfrom: (5188 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5189.
  • Revision ID: mbp@sourcefrog.net-20100428070338-2af8y3takgfkrkyp
merge news

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
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, LogicalLockResult
 
52
from bzrlib.lock import _RelockDebugMixin
53
53
from bzrlib import registry
54
54
from bzrlib.symbol_versioning import (
55
55
    deprecated_in,
283
283
        new_history.reverse()
284
284
        return new_history
285
285
 
286
 
    def lock_write(self, token=None):
287
 
        """Lock the branch for write operations.
288
 
 
289
 
        :param token: A token to permit reacquiring a previously held and
290
 
            preserved lock.
291
 
        :return: A BranchWriteLockResult.
292
 
        """
 
286
    def lock_write(self):
293
287
        raise NotImplementedError(self.lock_write)
294
288
 
295
289
    def lock_read(self):
296
 
        """Lock the branch for read operations.
297
 
 
298
 
        :return: A bzrlib.lock.LogicalLockResult.
299
 
        """
300
290
        raise NotImplementedError(self.lock_read)
301
291
 
302
292
    def unlock(self):
427
417
            * 'include' - the stop revision is the last item in the result
428
418
            * 'with-merges' - include the stop revision and all of its
429
419
              merged revisions in the result
430
 
            * 'with-merges-without-common-ancestry' - filter out revisions 
431
 
              that are in both ancestries
432
420
        :param direction: either 'reverse' or 'forward':
433
421
            * reverse means return the start_revision_id first, i.e.
434
422
              start at the most recent revision and go backwards in history
465
453
            stop_revision_id, stop_rule)
466
454
        # Make sure we don't return revisions that are not part of the
467
455
        # start_revision_id ancestry.
468
 
        filtered = self._filter_start_non_ancestors(filtered)
 
456
        filtered = self._filter_non_ancestors(filtered)
469
457
        if direction == 'reverse':
470
458
            return filtered
471
459
        if direction == 'forward':
508
496
                       node.end_of_merge)
509
497
                if rev_id == stop_revision_id:
510
498
                    return
511
 
        elif stop_rule == 'with-merges-without-common-ancestry':
512
 
            # We want to exclude all revisions that are already part of the
513
 
            # stop_revision_id ancestry.
514
 
            graph = self.repository.get_graph()
515
 
            ancestors = graph.find_unique_ancestors(start_revision_id,
516
 
                                                    [stop_revision_id])
517
 
            for node in rev_iter:
518
 
                rev_id = node.key[-1]
519
 
                if rev_id not in ancestors:
520
 
                    continue
521
 
                yield (rev_id, node.merge_depth, node.revno,
522
 
                       node.end_of_merge)
523
499
        elif stop_rule == 'with-merges':
524
500
            stop_rev = self.repository.get_revision(stop_revision_id)
525
501
            if stop_rev.parent_ids:
548
524
        else:
549
525
            raise ValueError('invalid stop_rule %r' % stop_rule)
550
526
 
551
 
    def _filter_start_non_ancestors(self, rev_iter):
 
527
    def _filter_non_ancestors(self, rev_iter):
552
528
        # If we started from a dotted revno, we want to consider it as a tip
553
529
        # and don't want to yield revisions that are not part of its
554
530
        # ancestry. Given the order guaranteed by the merge sort, we will see
1356
1332
        """
1357
1333
        # XXX: Fix the bzrdir API to allow getting the branch back from the
1358
1334
        # clone call. Or something. 20090224 RBC/spiv.
1359
 
        # XXX: Should this perhaps clone colocated branches as well, 
1360
 
        # rather than just the default branch? 20100319 JRV
1361
1335
        if revision_id is None:
1362
1336
            revision_id = self.last_revision()
1363
1337
        dir_to = self.bzrdir.clone_on_transport(to_transport,
1533
1507
        """Return the current default format."""
1534
1508
        return klass._default_format
1535
1509
 
1536
 
    def get_reference(self, a_bzrdir, name=None):
 
1510
    def get_reference(self, a_bzrdir):
1537
1511
        """Get the target reference of the branch in a_bzrdir.
1538
1512
 
1539
1513
        format probing must have been completed before calling
1541
1515
        in a_bzrdir is correct.
1542
1516
 
1543
1517
        :param a_bzrdir: The bzrdir to get the branch data from.
1544
 
        :param name: Name of the colocated branch to fetch
1545
1518
        :return: None if the branch is not a reference branch.
1546
1519
        """
1547
1520
        return None
1548
1521
 
1549
1522
    @classmethod
1550
 
    def set_reference(self, a_bzrdir, name, to_branch):
 
1523
    def set_reference(self, a_bzrdir, to_branch):
1551
1524
        """Set the target reference of the branch in a_bzrdir.
1552
1525
 
1553
1526
        format probing must have been completed before calling
1555
1528
        in a_bzrdir is correct.
1556
1529
 
1557
1530
        :param a_bzrdir: The bzrdir to set the branch reference for.
1558
 
        :param name: Name of colocated branch to set, None for default
1559
1531
        :param to_branch: branch that the checkout is to reference
1560
1532
        """
1561
1533
        raise NotImplementedError(self.set_reference)
2171
2143
        """See BranchFormat.get_format_description()."""
2172
2144
        return "Checkout reference format 1"
2173
2145
 
2174
 
    def get_reference(self, a_bzrdir, name=None):
 
2146
    def get_reference(self, a_bzrdir):
2175
2147
        """See BranchFormat.get_reference()."""
2176
 
        transport = a_bzrdir.get_branch_transport(None, name=name)
 
2148
        transport = a_bzrdir.get_branch_transport(None)
2177
2149
        return transport.get_bytes('location')
2178
2150
 
2179
 
    def set_reference(self, a_bzrdir, name, to_branch):
 
2151
    def set_reference(self, a_bzrdir, to_branch):
2180
2152
        """See BranchFormat.set_reference()."""
2181
 
        transport = a_bzrdir.get_branch_transport(None, name=name)
 
2153
        transport = a_bzrdir.get_branch_transport(None)
2182
2154
        location = transport.put_bytes('location', to_branch.base)
2183
2155
 
2184
2156
    def initialize(self, a_bzrdir, name=None, target_branch=None):
2235
2207
                raise AssertionError("wrong format %r found for %r" %
2236
2208
                    (format, self))
2237
2209
        if location is None:
2238
 
            location = self.get_reference(a_bzrdir, name)
 
2210
            location = self.get_reference(a_bzrdir)
2239
2211
        real_bzrdir = bzrdir.BzrDir.open(
2240
2212
            location, possible_transports=possible_transports)
2241
2213
        result = real_bzrdir.open_branch(name=name, 
2279
2251
    _legacy_formats[0].network_name(), _legacy_formats[0].__class__)
2280
2252
 
2281
2253
 
2282
 
class BranchWriteLockResult(LogicalLockResult):
2283
 
    """The result of write locking a branch.
2284
 
 
2285
 
    :ivar branch_token: The token obtained from the underlying branch lock, or
2286
 
        None.
2287
 
    :ivar unlock: A callable which will unlock the lock.
2288
 
    """
2289
 
 
2290
 
    def __init__(self, unlock, branch_token):
2291
 
        LogicalLockResult.__init__(self, unlock)
2292
 
        self.branch_token = branch_token
2293
 
 
2294
 
    def __repr__(self):
2295
 
        return "BranchWriteLockResult(%s, %s)" % (self.branch_token,
2296
 
            self.unlock)
2297
 
 
2298
 
 
2299
2254
class BzrBranch(Branch, _RelockDebugMixin):
2300
2255
    """A branch stored in the actual filesystem.
2301
2256
 
2355
2310
        return self.control_files.is_locked()
2356
2311
 
2357
2312
    def lock_write(self, token=None):
2358
 
        """Lock the branch for write operations.
2359
 
 
2360
 
        :param token: A token to permit reacquiring a previously held and
2361
 
            preserved lock.
2362
 
        :return: A BranchWriteLockResult.
2363
 
        """
2364
2313
        if not self.is_locked():
2365
2314
            self._note_lock('w')
2366
2315
        # All-in-one needs to always unlock/lock.
2372
2321
        else:
2373
2322
            took_lock = False
2374
2323
        try:
2375
 
            return BranchWriteLockResult(self.unlock,
2376
 
                self.control_files.lock_write(token=token))
 
2324
            return self.control_files.lock_write(token=token)
2377
2325
        except:
2378
2326
            if took_lock:
2379
2327
                self.repository.unlock()
2380
2328
            raise
2381
2329
 
2382
2330
    def lock_read(self):
2383
 
        """Lock the branch for read operations.
2384
 
 
2385
 
        :return: A bzrlib.lock.LogicalLockResult.
2386
 
        """
2387
2331
        if not self.is_locked():
2388
2332
            self._note_lock('r')
2389
2333
        # All-in-one needs to always unlock/lock.
2396
2340
            took_lock = False
2397
2341
        try:
2398
2342
            self.control_files.lock_read()
2399
 
            return LogicalLockResult(self.unlock)
2400
2343
        except:
2401
2344
            if took_lock:
2402
2345
                self.repository.unlock()