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:
688
from_branch.lock_read()
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)
685
return InterBranch.get(from_branch, self).fetch(last_revision,
699
688
def get_bound_location(self):
700
689
"""Return the URL of the branch we are bound to.
1818
1808
These are all empty initially, because by default nothing should get
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',
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.",
1888
self.create_hook(HookPoint('post_branch_init',
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))
2676
2665
"""Return the branch we are bound to.
2678
2667
:return: Either a Branch, or None
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.
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
2674
def _get_master_branch(self, possible_transports):
2685
2675
bound_loc = self.get_bound_location()
2686
2676
if not bound_loc:
3366
3367
self.source.tags.merge_to(self.target.tags)
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:
3376
self.source.lock_read()
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)
3384
self.source.unlock()
3369
3387
def update_revisions(self, stop_revision=None, overwrite=False,
3370
3388
graph=None, fetch_tags=True):
3371
3389
"""See InterBranch.update_revisions()."""