685
if fetch_spec is not None and last_revision is not None:
686
raise AssertionError(
687
"fetch_spec and last_revision are mutually exclusive.")
688
if self.base == from_branch.base:
690
from_branch.lock_read()
692
if last_revision is None and fetch_spec is None:
693
last_revision = from_branch.last_revision()
694
last_revision = _mod_revision.ensure_null(last_revision)
695
return self.repository.fetch(from_branch.repository,
696
revision_id=last_revision,
697
fetch_spec=fetch_spec)
684
return InterBranch.get(from_branch, self).fetch(last_revision,
701
687
def get_bound_location(self):
702
688
"""Return the URL of the branch we are bound to.
1658
1644
for hook in hooks:
1661
def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1663
"""Initialize a branch in a bzrdir, with specified files
1665
:param a_bzrdir: The bzrdir to initialize the branch in
1666
:param utf8_files: The files to create as a list of
1667
(filename, content) tuples
1668
:param name: Name of colocated branch to create, if any
1669
:return: a branch in this format
1671
mutter('creating branch %r in %s', self, a_bzrdir.user_url)
1672
branch_transport = a_bzrdir.get_branch_transport(self, name=name)
1673
control_files = lockable_files.LockableFiles(branch_transport,
1674
'lock', lockdir.LockDir)
1675
control_files.create_lock()
1676
control_files.lock_write()
1678
utf8_files += [('format', self.get_format_string())]
1679
for (filename, content) in utf8_files:
1680
branch_transport.put_bytes(
1682
mode=a_bzrdir._get_file_mode())
1684
control_files.unlock()
1685
branch = self.open(a_bzrdir, name, _found=True,
1686
found_repository=repository)
1687
self._run_post_branch_init_hooks(a_bzrdir, name, branch)
1690
1647
def initialize(self, a_bzrdir, name=None, repository=None):
1691
1648
"""Create a branch of this format in a_bzrdir.
1821
1778
These are all empty initially, because by default nothing should get
1824
Hooks.__init__(self)
1825
self.create_hook(HookPoint('set_rh',
1781
Hooks.__init__(self, "bzrlib.branch", "Branch.hooks")
1782
self.add_hook('set_rh',
1826
1783
"Invoked whenever the revision history has been set via "
1827
1784
"set_revision_history. The api signature is (branch, "
1828
1785
"revision_history), and the branch will be write-locked. "
1829
1786
"The set_rh hook can be expensive for bzr to trigger, a better "
1830
"hook to use is Branch.post_change_branch_tip.", (0, 15), None))
1831
self.create_hook(HookPoint('open',
1787
"hook to use is Branch.post_change_branch_tip.", (0, 15))
1788
self.add_hook('open',
1832
1789
"Called with the Branch object that has been opened after a "
1833
"branch is opened.", (1, 8), None))
1834
self.create_hook(HookPoint('post_push',
1790
"branch is opened.", (1, 8))
1791
self.add_hook('post_push',
1835
1792
"Called after a push operation completes. post_push is called "
1836
1793
"with a bzrlib.branch.BranchPushResult object and only runs in the "
1837
"bzr client.", (0, 15), None))
1838
self.create_hook(HookPoint('post_pull',
1794
"bzr client.", (0, 15))
1795
self.add_hook('post_pull',
1839
1796
"Called after a pull operation completes. post_pull is called "
1840
1797
"with a bzrlib.branch.PullResult object and only runs in the "
1841
"bzr client.", (0, 15), None))
1842
self.create_hook(HookPoint('pre_commit',
1798
"bzr client.", (0, 15))
1799
self.add_hook('pre_commit',
1843
1800
"Called after a commit is calculated but before it is "
1844
1801
"completed. pre_commit is called with (local, master, old_revno, "
1845
1802
"old_revid, future_revno, future_revid, tree_delta, future_tree"
1848
1805
"basis revision. hooks MUST NOT modify this delta. "
1849
1806
" future_tree is an in-memory tree obtained from "
1850
1807
"CommitBuilder.revision_tree() and hooks MUST NOT modify this "
1851
"tree.", (0,91), None))
1852
self.create_hook(HookPoint('post_commit',
1809
self.add_hook('post_commit',
1853
1810
"Called in the bzr client after a commit has completed. "
1854
1811
"post_commit is called with (local, master, old_revno, old_revid, "
1855
1812
"new_revno, new_revid). old_revid is NULL_REVISION for the first "
1856
"commit to a branch.", (0, 15), None))
1857
self.create_hook(HookPoint('post_uncommit',
1813
"commit to a branch.", (0, 15))
1814
self.add_hook('post_uncommit',
1858
1815
"Called in the bzr client after an uncommit completes. "
1859
1816
"post_uncommit is called with (local, master, old_revno, "
1860
1817
"old_revid, new_revno, new_revid) where local is the local branch "
1861
1818
"or None, master is the target branch, and an empty branch "
1862
"receives new_revno of 0, new_revid of None.", (0, 15), None))
1863
self.create_hook(HookPoint('pre_change_branch_tip',
1819
"receives new_revno of 0, new_revid of None.", (0, 15))
1820
self.add_hook('pre_change_branch_tip',
1864
1821
"Called in bzr client and server before a change to the tip of a "
1865
1822
"branch is made. pre_change_branch_tip is called with a "
1866
1823
"bzrlib.branch.ChangeBranchTipParams. Note that push, pull, "
1867
"commit, uncommit will all trigger this hook.", (1, 6), None))
1868
self.create_hook(HookPoint('post_change_branch_tip',
1824
"commit, uncommit will all trigger this hook.", (1, 6))
1825
self.add_hook('post_change_branch_tip',
1869
1826
"Called in bzr client and server after a change to the tip of a "
1870
1827
"branch is made. post_change_branch_tip is called with a "
1871
1828
"bzrlib.branch.ChangeBranchTipParams. Note that push, pull, "
1872
"commit, uncommit will all trigger this hook.", (1, 4), None))
1873
self.create_hook(HookPoint('transform_fallback_location',
1829
"commit, uncommit will all trigger this hook.", (1, 4))
1830
self.add_hook('transform_fallback_location',
1874
1831
"Called when a stacked branch is activating its fallback "
1875
1832
"locations. transform_fallback_location is called with (branch, "
1876
1833
"url), and should return a new url. Returning the same url "
1881
1838
"fallback locations have not been activated. When there are "
1882
1839
"multiple hooks installed for transform_fallback_location, "
1883
1840
"all are called with the url returned from the previous hook."
1884
"The order is however undefined.", (1, 9), None))
1885
self.create_hook(HookPoint('automatic_tag_name',
1841
"The order is however undefined.", (1, 9))
1842
self.add_hook('automatic_tag_name',
1886
1843
"Called to determine an automatic tag name for a revision. "
1887
1844
"automatic_tag_name is called with (branch, revision_id) and "
1888
1845
"should return a tag name or None if no tag name could be "
1889
1846
"determined. The first non-None tag name returned will be used.",
1891
self.create_hook(HookPoint('post_branch_init',
1848
self.add_hook('post_branch_init',
1892
1849
"Called after new branch initialization completes. "
1893
1850
"post_branch_init is called with a "
1894
1851
"bzrlib.branch.BranchInitHookParams. "
1895
1852
"Note that init, branch and checkout (both heavyweight and "
1896
"lightweight) will all trigger this hook.", (2, 2), None))
1897
self.create_hook(HookPoint('post_switch',
1853
"lightweight) will all trigger this hook.", (2, 2))
1854
self.add_hook('post_switch',
1898
1855
"Called after a checkout switches branch. "
1899
1856
"post_switch is called with a "
1900
"bzrlib.branch.SwitchHookParams.", (2, 2), None))
1857
"bzrlib.branch.SwitchHookParams.", (2, 2))
2023
1980
"""What class to instantiate on open calls."""
2024
1981
raise NotImplementedError(self._branch_class)
1983
def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1985
"""Initialize a branch in a bzrdir, with specified files
1987
:param a_bzrdir: The bzrdir to initialize the branch in
1988
:param utf8_files: The files to create as a list of
1989
(filename, content) tuples
1990
:param name: Name of colocated branch to create, if any
1991
:return: a branch in this format
1993
mutter('creating branch %r in %s', self, a_bzrdir.user_url)
1994
branch_transport = a_bzrdir.get_branch_transport(self, name=name)
1995
control_files = lockable_files.LockableFiles(branch_transport,
1996
'lock', lockdir.LockDir)
1997
control_files.create_lock()
1998
control_files.lock_write()
2000
utf8_files += [('format', self.get_format_string())]
2001
for (filename, content) in utf8_files:
2002
branch_transport.put_bytes(
2004
mode=a_bzrdir._get_file_mode())
2006
control_files.unlock()
2007
branch = self.open(a_bzrdir, name, _found=True,
2008
found_repository=repository)
2009
self._run_post_branch_init_hooks(a_bzrdir, name, branch)
2026
2012
def network_name(self):
2027
2013
"""A simple byte string uniquely identifying this format for RPC calls.
3371
3368
self.source.tags.merge_to(self.target.tags)
3373
3370
@needs_write_lock
3371
def fetch(self, stop_revision=None, fetch_spec=None):
3372
if fetch_spec is not None and stop_revision is not None:
3373
raise AssertionError(
3374
"fetch_spec and last_revision are mutually exclusive.")
3375
if self.target.base == self.source.base:
3377
self.source.lock_read()
3379
if stop_revision is None and fetch_spec is None:
3380
stop_revision = self.source.last_revision()
3381
stop_revision = _mod_revision.ensure_null(stop_revision)
3382
return self.target.repository.fetch(self.source.repository,
3383
revision_id=stop_revision, fetch_spec=fetch_spec)
3385
self.source.unlock()
3374
3388
def update_revisions(self, stop_revision=None, overwrite=False,
3375
3389
graph=None, fetch_tags=True):
3376
3390
"""See InterBranch.update_revisions()."""