/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: Andrew Bennetts
  • Date: 2011-04-08 03:31:54 UTC
  • mfrom: (5766 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5767.
  • Revision ID: andrew.bennetts@canonical.com-20110408033154-la08nghd4391sw5m
Merge latest lp:bzr, move our new release notes entries to the current release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
    needs_write_lock,
58
58
    only_raises,
59
59
    )
60
 
from bzrlib.hooks import HookPoint, Hooks
 
60
from bzrlib.hooks import Hooks
61
61
from bzrlib.inter import InterObject
62
62
from bzrlib.lock import _RelockDebugMixin, LogicalLockResult
63
63
from bzrlib import registry
79
79
    :ivar base:
80
80
        Base directory/url of the branch; using control_url and
81
81
        control_transport is more standardized.
82
 
 
83
 
    hooks: An instance of BranchHooks.
 
82
    :ivar hooks: An instance of BranchHooks.
 
83
    :ivar _master_branch_cache: cached result of get_master_branch, see
 
84
        _clear_cached_state.
84
85
    """
85
86
    # this is really an instance variable - FIXME move it there
86
87
    # - RBC 20060112
102
103
        self._partial_revision_history_cache = []
103
104
        self._tags_bytes = None
104
105
        self._last_revision_info_cache = None
 
106
        self._master_branch_cache = None
105
107
        self._merge_sorted_revisions_cache = None
106
108
        self._open_hook()
107
109
        hooks = Branch.hooks['open']
680
682
            last_revision.
681
683
        :return: None
682
684
        """
683
 
        if fetch_spec is not None and last_revision is not None:
684
 
            raise AssertionError(
685
 
                "fetch_spec and last_revision are mutually exclusive.")
686
 
        if self.base == from_branch.base:
687
 
            return (0, [])
688
 
        from_branch.lock_read()
689
 
        try:
690
 
            if last_revision is None and fetch_spec is None:
691
 
                last_revision = from_branch.last_revision()
692
 
                last_revision = _mod_revision.ensure_null(last_revision)
693
 
            return self.repository.fetch(from_branch.repository,
694
 
                                         revision_id=last_revision,
695
 
                                         fetch_spec=fetch_spec)
696
 
        finally:
697
 
            from_branch.unlock()
 
685
        return InterBranch.get(from_branch, self).fetch(last_revision,
 
686
            fetch_spec)
698
687
 
699
688
    def get_bound_location(self):
700
689
        """Return the URL of the branch we are bound to.
937
926
        self._revision_history_cache = None
938
927
        self._revision_id_to_revno_cache = None
939
928
        self._last_revision_info_cache = None
 
929
        self._master_branch_cache = None
940
930
        self._merge_sorted_revisions_cache = None
941
931
        self._partial_revision_history_cache = []
942
932
        self._partial_revision_id_to_revno_cache = {}
1818
1808
        These are all empty initially, because by default nothing should get
1819
1809
        notified.
1820
1810
        """
1821
 
        Hooks.__init__(self)
1822
 
        self.create_hook(HookPoint('set_rh',
 
1811
        Hooks.__init__(self, "bzrlib.branch", "Branch.hooks")
 
1812
        self.add_hook('set_rh',
1823
1813
            "Invoked whenever the revision history has been set via "
1824
1814
            "set_revision_history. The api signature is (branch, "
1825
1815
            "revision_history), and the branch will be write-locked. "
1826
1816
            "The set_rh hook can be expensive for bzr to trigger, a better "
1827
 
            "hook to use is Branch.post_change_branch_tip.", (0, 15), None))
1828
 
        self.create_hook(HookPoint('open',
 
1817
            "hook to use is Branch.post_change_branch_tip.", (0, 15))
 
1818
        self.add_hook('open',
1829
1819
            "Called with the Branch object that has been opened after a "
1830
 
            "branch is opened.", (1, 8), None))
1831
 
        self.create_hook(HookPoint('post_push',
 
1820
            "branch is opened.", (1, 8))
 
1821
        self.add_hook('post_push',
1832
1822
            "Called after a push operation completes. post_push is called "
1833
1823
            "with a bzrlib.branch.BranchPushResult object and only runs in the "
1834
 
            "bzr client.", (0, 15), None))
1835
 
        self.create_hook(HookPoint('post_pull',
 
1824
            "bzr client.", (0, 15))
 
1825
        self.add_hook('post_pull',
1836
1826
            "Called after a pull operation completes. post_pull is called "
1837
1827
            "with a bzrlib.branch.PullResult object and only runs in the "
1838
 
            "bzr client.", (0, 15), None))
1839
 
        self.create_hook(HookPoint('pre_commit',
 
1828
            "bzr client.", (0, 15))
 
1829
        self.add_hook('pre_commit',
1840
1830
            "Called after a commit is calculated but before it is "
1841
1831
            "completed. pre_commit is called with (local, master, old_revno, "
1842
1832
            "old_revid, future_revno, future_revid, tree_delta, future_tree"
1845
1835
            "basis revision. hooks MUST NOT modify this delta. "
1846
1836
            " future_tree is an in-memory tree obtained from "
1847
1837
            "CommitBuilder.revision_tree() and hooks MUST NOT modify this "
1848
 
            "tree.", (0,91), None))
1849
 
        self.create_hook(HookPoint('post_commit',
 
1838
            "tree.", (0,91))
 
1839
        self.add_hook('post_commit',
1850
1840
            "Called in the bzr client after a commit has completed. "
1851
1841
            "post_commit is called with (local, master, old_revno, old_revid, "
1852
1842
            "new_revno, new_revid). old_revid is NULL_REVISION for the first "
1853
 
            "commit to a branch.", (0, 15), None))
1854
 
        self.create_hook(HookPoint('post_uncommit',
 
1843
            "commit to a branch.", (0, 15))
 
1844
        self.add_hook('post_uncommit',
1855
1845
            "Called in the bzr client after an uncommit completes. "
1856
1846
            "post_uncommit is called with (local, master, old_revno, "
1857
1847
            "old_revid, new_revno, new_revid) where local is the local branch "
1858
1848
            "or None, master is the target branch, and an empty branch "
1859
 
            "receives new_revno of 0, new_revid of None.", (0, 15), None))
1860
 
        self.create_hook(HookPoint('pre_change_branch_tip',
 
1849
            "receives new_revno of 0, new_revid of None.", (0, 15))
 
1850
        self.add_hook('pre_change_branch_tip',
1861
1851
            "Called in bzr client and server before a change to the tip of a "
1862
1852
            "branch is made. pre_change_branch_tip is called with a "
1863
1853
            "bzrlib.branch.ChangeBranchTipParams. Note that push, pull, "
1864
 
            "commit, uncommit will all trigger this hook.", (1, 6), None))
1865
 
        self.create_hook(HookPoint('post_change_branch_tip',
 
1854
            "commit, uncommit will all trigger this hook.", (1, 6))
 
1855
        self.add_hook('post_change_branch_tip',
1866
1856
            "Called in bzr client and server after a change to the tip of a "
1867
1857
            "branch is made. post_change_branch_tip is called with a "
1868
1858
            "bzrlib.branch.ChangeBranchTipParams. Note that push, pull, "
1869
 
            "commit, uncommit will all trigger this hook.", (1, 4), None))
1870
 
        self.create_hook(HookPoint('transform_fallback_location',
 
1859
            "commit, uncommit will all trigger this hook.", (1, 4))
 
1860
        self.add_hook('transform_fallback_location',
1871
1861
            "Called when a stacked branch is activating its fallback "
1872
1862
            "locations. transform_fallback_location is called with (branch, "
1873
1863
            "url), and should return a new url. Returning the same url "
1878
1868
            "fallback locations have not been activated. When there are "
1879
1869
            "multiple hooks installed for transform_fallback_location, "
1880
1870
            "all are called with the url returned from the previous hook."
1881
 
            "The order is however undefined.", (1, 9), None))
1882
 
        self.create_hook(HookPoint('automatic_tag_name',
 
1871
            "The order is however undefined.", (1, 9))
 
1872
        self.add_hook('automatic_tag_name',
1883
1873
            "Called to determine an automatic tag name for a revision. "
1884
1874
            "automatic_tag_name is called with (branch, revision_id) and "
1885
1875
            "should return a tag name or None if no tag name could be "
1886
1876
            "determined. The first non-None tag name returned will be used.",
1887
 
            (2, 2), None))
1888
 
        self.create_hook(HookPoint('post_branch_init',
 
1877
            (2, 2))
 
1878
        self.add_hook('post_branch_init',
1889
1879
            "Called after new branch initialization completes. "
1890
1880
            "post_branch_init is called with a "
1891
1881
            "bzrlib.branch.BranchInitHookParams. "
1892
1882
            "Note that init, branch and checkout (both heavyweight and "
1893
 
            "lightweight) will all trigger this hook.", (2, 2), None))
1894
 
        self.create_hook(HookPoint('post_switch',
 
1883
            "lightweight) will all trigger this hook.", (2, 2))
 
1884
        self.add_hook('post_switch',
1895
1885
            "Called after a checkout switches branch. "
1896
1886
            "post_switch is called with a "
1897
 
            "bzrlib.branch.SwitchHookParams.", (2, 2), None))
 
1887
            "bzrlib.branch.SwitchHookParams.", (2, 2))
1898
1888
 
1899
1889
 
1900
1890
 
2637
2627
            target.update_revisions(self, stop_revision,
2638
2628
                overwrite=overwrite, graph=graph)
2639
2629
        if self._push_should_merge_tags():
2640
 
            result.tag_conflicts = self.tags.merge_to(target.tags,
2641
 
                overwrite)
 
2630
            result.tag_conflicts = self.tags.merge_to(target.tags, overwrite)
2642
2631
        result.new_revno, result.new_revid = target.last_revision_info()
2643
2632
        return result
2644
2633
 
2676
2665
        """Return the branch we are bound to.
2677
2666
 
2678
2667
        :return: Either a Branch, or None
2679
 
 
2680
 
        This could memoise the branch, but if thats done
2681
 
        it must be revalidated on each new lock.
2682
 
        So for now we just don't memoise it.
2683
 
        # RBC 20060304 review this decision.
2684
2668
        """
 
2669
        if self._master_branch_cache is None:
 
2670
            self._master_branch_cache = self._get_master_branch(
 
2671
                possible_transports)
 
2672
        return self._master_branch_cache
 
2673
 
 
2674
    def _get_master_branch(self, possible_transports):
2685
2675
        bound_loc = self.get_bound_location()
2686
2676
        if not bound_loc:
2687
2677
            return None
2698
2688
 
2699
2689
        :param location: URL to the target branch
2700
2690
        """
 
2691
        self._master_branch_cache = None
2701
2692
        if location:
2702
2693
            self._transport.put_bytes('bound', location+'\n',
2703
2694
                mode=self.bzrdir._get_file_mode())
2955
2946
 
2956
2947
    def set_bound_location(self, location):
2957
2948
        """See Branch.set_push_location."""
 
2949
        self._master_branch_cache = None
2958
2950
        result = None
2959
2951
        config = self.get_config()
2960
2952
        if location is None:
3326
3318
        """
3327
3319
        raise NotImplementedError(self.copy_content_into)
3328
3320
 
 
3321
    @needs_write_lock
 
3322
    def fetch(self, stop_revision=None, fetch_spec=None):
 
3323
        """Fetch revisions.
 
3324
 
 
3325
        :param stop_revision: Last revision to fetch
 
3326
        :param fetch_spec: Fetch spec.
 
3327
        """
 
3328
        raise NotImplementedError(self.fetch)
 
3329
 
3329
3330
 
3330
3331
class GenericInterBranch(InterBranch):
3331
3332
    """InterBranch implementation that uses public Branch functions."""
3366
3367
            self.source.tags.merge_to(self.target.tags)
3367
3368
 
3368
3369
    @needs_write_lock
 
3370
    def fetch(self, stop_revision=None, fetch_spec=None):
 
3371
        if fetch_spec is not None and stop_revision is not None:
 
3372
            raise AssertionError(
 
3373
                "fetch_spec and last_revision are mutually exclusive.")
 
3374
        if self.target.base == self.source.base:
 
3375
            return (0, [])
 
3376
        self.source.lock_read()
 
3377
        try:
 
3378
            if stop_revision is None and fetch_spec is None:
 
3379
                stop_revision = self.source.last_revision()
 
3380
                stop_revision = _mod_revision.ensure_null(stop_revision)
 
3381
            return self.target.repository.fetch(self.source.repository,
 
3382
                revision_id=stop_revision, fetch_spec=fetch_spec)
 
3383
        finally:
 
3384
            self.source.unlock()
 
3385
 
 
3386
    @needs_write_lock
3369
3387
    def update_revisions(self, stop_revision=None, overwrite=False,
3370
3388
        graph=None, fetch_tags=True):
3371
3389
        """See InterBranch.update_revisions()."""