/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

merge bzr.dev r4164

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009 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
30
30
        lockable_files,
31
31
        repository,
32
32
        revision as _mod_revision,
 
33
        symbol_versioning,
33
34
        transport,
34
35
        tsort,
35
36
        ui,
44
45
""")
45
46
 
46
47
from bzrlib.decorators import needs_read_lock, needs_write_lock
47
 
from bzrlib.hooks import Hooks
 
48
from bzrlib.hooks import HookPoint, Hooks
48
49
from bzrlib.inter import InterObject
49
50
from bzrlib import registry
50
51
from bzrlib.symbol_versioning import (
478
479
        """
479
480
        if self.base == from_branch.base:
480
481
            return (0, [])
481
 
        if pb is None:
482
 
            nested_pb = ui.ui_factory.nested_progress_bar()
483
 
            pb = nested_pb
484
 
        else:
485
 
            nested_pb = None
486
 
 
 
482
        if pb is not None:
 
483
            symbol_versioning.warn(
 
484
                symbol_versioning.deprecated_in((1, 14, 0))
 
485
                % "pb parameter to fetch()")
487
486
        from_branch.lock_read()
488
487
        try:
489
488
            if last_revision is None:
490
 
                pb.update('get source history')
491
489
                last_revision = from_branch.last_revision()
492
490
                last_revision = _mod_revision.ensure_null(last_revision)
493
491
            return self.repository.fetch(from_branch.repository,
494
492
                                         revision_id=last_revision,
495
 
                                         pb=nested_pb)
 
493
                                         pb=pb)
496
494
        finally:
497
 
            if nested_pb is not None:
498
 
                nested_pb.finished()
499
495
            from_branch.unlock()
500
496
 
501
497
    def get_bound_location(self):
1372
1368
        notified.
1373
1369
        """
1374
1370
        Hooks.__init__(self)
1375
 
        # Introduced in 0.15:
1376
 
        # invoked whenever the revision history has been set
1377
 
        # with set_revision_history. The api signature is
1378
 
        # (branch, revision_history), and the branch will
1379
 
        # be write-locked.
1380
 
        self['set_rh'] = []
1381
 
        # Invoked after a branch is opened. The api signature is (branch).
1382
 
        self['open'] = []
1383
 
        # invoked after a push operation completes.
1384
 
        # the api signature is
1385
 
        # (push_result)
1386
 
        # containing the members
1387
 
        # (source, local, master, old_revno, old_revid, new_revno, new_revid)
1388
 
        # where local is the local target branch or None, master is the target
1389
 
        # master branch, and the rest should be self explanatory. The source
1390
 
        # is read locked and the target branches write locked. Source will
1391
 
        # be the local low-latency branch.
1392
 
        self['post_push'] = []
1393
 
        # invoked after a pull operation completes.
1394
 
        # the api signature is
1395
 
        # (pull_result)
1396
 
        # containing the members
1397
 
        # (source, local, master, old_revno, old_revid, new_revno, new_revid)
1398
 
        # where local is the local branch or None, master is the target
1399
 
        # master branch, and the rest should be self explanatory. The source
1400
 
        # is read locked and the target branches write locked. The local
1401
 
        # branch is the low-latency branch.
1402
 
        self['post_pull'] = []
1403
 
        # invoked before a commit operation takes place.
1404
 
        # the api signature is
1405
 
        # (local, master, old_revno, old_revid, future_revno, future_revid,
1406
 
        #  tree_delta, future_tree).
1407
 
        # old_revid is NULL_REVISION for the first commit to a branch
1408
 
        # tree_delta is a TreeDelta object describing changes from the basis
1409
 
        # revision, hooks MUST NOT modify this delta
1410
 
        # future_tree is an in-memory tree obtained from
1411
 
        # CommitBuilder.revision_tree() and hooks MUST NOT modify this tree
1412
 
        self['pre_commit'] = []
1413
 
        # invoked after a commit operation completes.
1414
 
        # the api signature is
1415
 
        # (local, master, old_revno, old_revid, new_revno, new_revid)
1416
 
        # old_revid is NULL_REVISION for the first commit to a branch.
1417
 
        self['post_commit'] = []
1418
 
        # invoked after a uncommit operation completes.
1419
 
        # the api signature is
1420
 
        # (local, master, old_revno, old_revid, new_revno, new_revid) where
1421
 
        # local is the local branch or None, master is the target branch,
1422
 
        # and an empty branch recieves new_revno of 0, new_revid of None.
1423
 
        self['post_uncommit'] = []
1424
 
        # Introduced in 1.6
1425
 
        # Invoked before the tip of a branch changes.
1426
 
        # the api signature is
1427
 
        # (params) where params is a ChangeBranchTipParams with the members
1428
 
        # (branch, old_revno, new_revno, old_revid, new_revid)
1429
 
        self['pre_change_branch_tip'] = []
1430
 
        # Introduced in 1.4
1431
 
        # Invoked after the tip of a branch changes.
1432
 
        # the api signature is
1433
 
        # (params) where params is a ChangeBranchTipParams with the members
1434
 
        # (branch, old_revno, new_revno, old_revid, new_revid)
1435
 
        self['post_change_branch_tip'] = []
1436
 
        # Introduced in 1.9
1437
 
        # Invoked when a stacked branch activates its fallback locations and
1438
 
        # allows the transformation of the url of said location.
1439
 
        # the api signature is
1440
 
        # (branch, url) where branch is the branch having its fallback
1441
 
        # location activated and url is the url for the fallback location.
1442
 
        # The hook should return a url.
1443
 
        self['transform_fallback_location'] = []
 
1371
        self.create_hook(HookPoint('set_rh',
 
1372
            "Invoked whenever the revision history has been set via "
 
1373
            "set_revision_history. The api signature is (branch, "
 
1374
            "revision_history), and the branch will be write-locked. "
 
1375
            "The set_rh hook can be expensive for bzr to trigger, a better "
 
1376
            "hook to use is Branch.post_change_branch_tip.", (0, 15), None))
 
1377
        self.create_hook(HookPoint('open',
 
1378
            "Called with the Branch object that has been opened after a "
 
1379
            "branch is opened.", (1, 8), None))
 
1380
        self.create_hook(HookPoint('post_push',
 
1381
            "Called after a push operation completes. post_push is called "
 
1382
            "with a bzrlib.branch.BranchPushResult object and only runs in the "
 
1383
            "bzr client.", (0, 15), None))
 
1384
        self.create_hook(HookPoint('post_pull',
 
1385
            "Called after a pull operation completes. post_pull is called "
 
1386
            "with a bzrlib.branch.PullResult object and only runs in the "
 
1387
            "bzr client.", (0, 15), None))
 
1388
        self.create_hook(HookPoint('pre_commit',
 
1389
            "Called after a commit is calculated but before it is is "
 
1390
            "completed. pre_commit is called with (local, master, old_revno, "
 
1391
            "old_revid, future_revno, future_revid, tree_delta, future_tree"
 
1392
            "). old_revid is NULL_REVISION for the first commit to a branch, "
 
1393
            "tree_delta is a TreeDelta object describing changes from the "
 
1394
            "basis revision. hooks MUST NOT modify this delta. "
 
1395
            " future_tree is an in-memory tree obtained from "
 
1396
            "CommitBuilder.revision_tree() and hooks MUST NOT modify this "
 
1397
            "tree.", (0,91), None))
 
1398
        self.create_hook(HookPoint('post_commit',
 
1399
            "Called in the bzr client after a commit has completed. "
 
1400
            "post_commit is called with (local, master, old_revno, old_revid, "
 
1401
            "new_revno, new_revid). old_revid is NULL_REVISION for the first "
 
1402
            "commit to a branch.", (0, 15), None))
 
1403
        self.create_hook(HookPoint('post_uncommit',
 
1404
            "Called in the bzr client after an uncommit completes. "
 
1405
            "post_uncommit is called with (local, master, old_revno, "
 
1406
            "old_revid, new_revno, new_revid) where local is the local branch "
 
1407
            "or None, master is the target branch, and an empty branch "
 
1408
            "recieves new_revno of 0, new_revid of None.", (0, 15), None))
 
1409
        self.create_hook(HookPoint('pre_change_branch_tip',
 
1410
            "Called in bzr client and server before a change to the tip of a "
 
1411
            "branch is made. pre_change_branch_tip is called with a "
 
1412
            "bzrlib.branch.ChangeBranchTipParams. Note that push, pull, "
 
1413
            "commit, uncommit will all trigger this hook.", (1, 6), None))
 
1414
        self.create_hook(HookPoint('post_change_branch_tip',
 
1415
            "Called in bzr client and server after a change to the tip of a "
 
1416
            "branch is made. post_change_branch_tip is called with a "
 
1417
            "bzrlib.branch.ChangeBranchTipParams. Note that push, pull, "
 
1418
            "commit, uncommit will all trigger this hook.", (1, 4), None))
 
1419
        self.create_hook(HookPoint('transform_fallback_location',
 
1420
            "Called when a stacked branch is activating its fallback "
 
1421
            "locations. transform_fallback_location is called with (branch, "
 
1422
            "url), and should return a new url. Returning the same url "
 
1423
            "allows it to be used as-is, returning a different one can be "
 
1424
            "used to cause the branch to stack on a closer copy of that "
 
1425
            "fallback_location. Note that the branch cannot have history "
 
1426
            "accessing methods called on it during this hook because the "
 
1427
            "fallback locations have not been activated. When there are "
 
1428
            "multiple hooks installed for transform_fallback_location, "
 
1429
            "all are called with the url returned from the previous hook."
 
1430
            "The order is however undefined.", (1, 9), None))
1444
1431
 
1445
1432
 
1446
1433
# install the default hooks into the Branch class.
2121
2108
 
2122
2109
        Must be called with self read locked and target write locked.
2123
2110
        """
2124
 
        result = PushResult()
 
2111
        result = BranchPushResult()
2125
2112
        result.source_branch = self
2126
2113
        result.target_branch = target
2127
2114
        result.old_revno, result.old_revid = target.last_revision_info()
2625
2612
    :ivar new_revno: Revision number after pull.
2626
2613
    :ivar old_revid: Tip revision id before pull.
2627
2614
    :ivar new_revid: Tip revision id after pull.
2628
 
    :ivar source_branch: Source (local) branch object.
 
2615
    :ivar source_branch: Source (local) branch object. (read locked)
2629
2616
    :ivar master_branch: Master branch of the target, or the target if no
2630
2617
        Master
2631
2618
    :ivar local_branch: target branch if there is a Master, else None
2632
 
    :ivar target_branch: Target/destination branch object.
 
2619
    :ivar target_branch: Target/destination branch object. (write locked)
2633
2620
    :ivar tag_conflicts: A list of tag conflicts, see BasicTags.merge_to
2634
2621
    """
2635
2622
 
2646
2633
        self._show_tag_conficts(to_file)
2647
2634
 
2648
2635
 
2649
 
class PushResult(_Result):
 
2636
class BranchPushResult(_Result):
2650
2637
    """Result of a Branch.push operation.
2651
2638
 
2652
 
    :ivar old_revno: Revision number before push.
2653
 
    :ivar new_revno: Revision number after push.
2654
 
    :ivar old_revid: Tip revision id before push.
2655
 
    :ivar new_revid: Tip revision id after push.
2656
 
    :ivar source_branch: Source branch object.
2657
 
    :ivar master_branch: Master branch of the target, or None.
2658
 
    :ivar target_branch: Target/destination branch object.
 
2639
    :ivar old_revno: Revision number (eg 10) of the target before push.
 
2640
    :ivar new_revno: Revision number (eg 12) of the target after push.
 
2641
    :ivar old_revid: Tip revision id (eg joe@foo.com-1234234-aoeua34) of target
 
2642
        before the push.
 
2643
    :ivar new_revid: Tip revision id (eg joe@foo.com-5676566-boa234a) of target
 
2644
        after the push.
 
2645
    :ivar source_branch: Source branch object that the push was from. This is
 
2646
        read locked, and generally is a local (and thus low latency) branch.
 
2647
    :ivar master_branch: If target is a bound branch, the master branch of
 
2648
        target, or target itself. Always write locked.
 
2649
    :ivar target_branch: The direct Branch where data is being sent (write
 
2650
        locked).
 
2651
    :ivar local_branch: If the target is a bound branch this will be the
 
2652
        target, otherwise it will be None.
2659
2653
    """
2660
2654
 
2661
2655
    def __int__(self):