226
226
if last_revision is None:
227
227
pb.update('get source history')
228
from_history = from_branch.revision_history()
230
last_revision = from_history[-1]
232
# no history in the source branch
233
last_revision = _mod_revision.NULL_REVISION
228
last_revision = from_branch.last_revision_info()[1]
234
229
return self.repository.fetch(from_branch.repository,
235
230
revision_id=last_revision,
264
259
if config is None:
265
260
config = self.get_config()
267
return self.repository.get_commit_builder(self, parents, config,
262
return self.repository.get_commit_builder(self, parents, config,
268
263
timestamp, timezone, committer, revprops, revision_id)
270
265
def get_master_branch(self):
322
def last_revision_info(self):
323
"""Return information about the last revision.
325
:return: A tuple (revno, last_revision_id).
327
rh = self.revision_history()
330
return (revno, rh[-1])
332
return (0, _mod_revision.NULL_REVISION)
327
334
def missing_revisions(self, other, stop_revision=None):
328
335
"""Return a list of new revisions that would perfectly fit.
378
385
return history[revno - 1]
380
387
def pull(self, source, overwrite=False, stop_revision=None):
388
"""Mirror source into this branch.
390
This branch is considered to be 'local', having low latency.
381
392
raise NotImplementedError(self.pull)
394
def push(self, target, overwrite=False, stop_revision=None):
395
"""Mirror this branch into target.
397
This branch is considered to be 'local', having low latency.
399
raise NotImplementedError(self.push)
383
401
def basis_tree(self):
384
402
"""Return `Tree` object for last revision."""
385
403
return self.repository.revision_tree(self.last_revision())
596
614
Weaves are used if this branch's repostory uses weaves.
598
616
if isinstance(self.bzrdir, bzrdir.BzrDirPreSplitOut):
599
from bzrlib import repository
617
from bzrlib.repofmt import weaverepo
600
618
format = bzrdir.BzrDirMetaFormat1()
601
format.repository_format = repository.RepositoryFormat7()
619
format.repository_format = weaverepo.RepositoryFormat7()
603
621
format = self.repository.bzrdir.cloning_metadir()
606
def create_checkout(self, to_location, revision_id=None,
624
def create_checkout(self, to_location, revision_id=None,
607
625
lightweight=False):
608
626
"""Create a checkout of a branch.
681
699
def get_format_description(self):
682
700
"""Return the short format description for this format."""
683
raise NotImplementedError(self.get_format_string)
701
raise NotImplementedError(self.get_format_description)
685
703
def initialize(self, a_bzrdir):
686
704
"""Create a branch of this format in a_bzrdir."""
736
754
dict.__init__(self)
755
# Introduced in 0.15:
737
756
# invoked whenever the revision history has been set
738
757
# with set_revision_history. The api signature is
739
758
# (branch, revision_history), and the branch will
740
# be write-locked. Introduced in 0.15.
741
760
self['set_rh'] = []
761
# invoked after a push operation completes.
762
# the api signature is
763
# (source, local, master, old_revno, old_revid, new_revno, new_revid)
764
# where local is the local branch or None, master is the target
765
# master branch, and the rest should be self explanatory. The source
766
# is read locked and the target branches write locked. Source will
767
# be the local low-latency branch.
768
self['post_push'] = []
769
# invoked after a pull operation completes.
770
# the api signature is
771
# (source, local, master, old_revno, old_revid, new_revno, new_revid)
772
# where local is the local branch or None, master is the target
773
# master branch, and the rest should be self explanatory. The source
774
# is read locked and the target branches write locked. The local
775
# branch is the low-latency branch.
776
self['post_pull'] = []
777
# invoked after a commit operation completes.
778
# the api signature is
779
# (local, master, old_revno, old_revid, new_revno, new_revid)
780
# old_revid is NULL_REVISION for the first commit to a branch.
781
self['post_commit'] = []
782
# invoked after a uncommit operation completes.
783
# the api signature is
784
# (local, master, old_revno, old_revid, new_revno, new_revid) where
785
# local is the local branch or None, master is the target branch,
786
# and an empty branch recieves new_revno of 0, new_revid of None.
787
self['post_uncommit'] = []
743
789
def install_hook(self, hook_name, a_callable):
744
790
"""Install a_callable in to the hook hook_name.
1237
1283
return self.bzrdir.open_workingtree()
1239
1285
@needs_write_lock
1240
def pull(self, source, overwrite=False, stop_revision=None):
1241
"""See Branch.pull."""
1286
def pull(self, source, overwrite=False, stop_revision=None,
1287
_hook_master=None, _run_hooks=True):
1290
:param _hook_master: Private parameter - set the branch to
1291
be supplied as the master to push hooks.
1292
:param _run_hooks: Private parameter - allow disabling of
1293
hooks, used when pushing to a master branch.
1242
1295
source.lock_read()
1244
old_count = len(self.revision_history())
1297
old_count, old_tip = self.last_revision_info()
1246
1299
self.update_revisions(source, stop_revision)
1247
1300
except DivergedBranches:
1251
1304
self.set_revision_history(source.revision_history())
1252
new_count = len(self.revision_history())
1305
new_count, new_tip = self.last_revision_info()
1312
for hook in Branch.hooks['post_pull']:
1313
hook(source, _hook_local, _hook_master, old_count, old_tip,
1253
1315
return new_count - old_count
1255
1317
source.unlock()
1320
def push(self, target, overwrite=False, stop_revision=None,
1321
_hook_master=None, _run_hooks=True):
1324
:param _hook_master: Private parameter - set the branch to
1325
be supplied as the master to push hooks.
1326
:param _run_hooks: Private parameter - allow disabling of
1327
hooks, used when pushing to a master branch.
1331
old_count, old_tip = target.last_revision_info()
1333
target.update_revisions(self, stop_revision)
1334
except DivergedBranches:
1338
target.set_revision_history(self.revision_history())
1339
new_count, new_tip = target.last_revision_info()
1342
_hook_local = target
1344
_hook_master = target
1346
for hook in Branch.hooks['post_push']:
1347
hook(self, _hook_local, _hook_master, old_count, old_tip,
1349
return new_count - old_count
1257
1353
def get_parent(self):
1258
1354
"""See Branch.get_parent."""
1331
1427
_repository=_repository)
1333
1429
@needs_write_lock
1334
def pull(self, source, overwrite=False, stop_revision=None):
1335
"""Updates branch.pull to be bound branch aware."""
1430
def pull(self, source, overwrite=False, stop_revision=None,
1432
"""Extends branch.pull to be bound branch aware.
1434
:param _run_hooks: Private parameter used to force hook running
1435
off during bound branch double-pushing.
1336
1437
bound_location = self.get_bound_location()
1337
if source.base != bound_location:
1438
master_branch = None
1439
if bound_location and source.base != bound_location:
1338
1440
# not pulling from master, so we need to update master.
1339
1441
master_branch = self.get_master_branch()
1341
master_branch.pull(source)
1342
source = master_branch
1343
return super(BzrBranch5, self).pull(source, overwrite, stop_revision)
1442
master_branch.lock_write()
1445
# pull from source into master.
1446
master_branch.pull(source, overwrite, stop_revision,
1448
return super(BzrBranch5, self).pull(source, overwrite,
1449
stop_revision, _hook_master=master_branch,
1450
_run_hooks=_run_hooks)
1453
master_branch.unlock()
1456
def push(self, target, overwrite=False, stop_revision=None):
1457
"""Updates branch.push to be bound branch aware."""
1458
bound_location = target.get_bound_location()
1459
master_branch = None
1460
if bound_location and target.base != bound_location:
1461
# not pushing to master, so we need to update master.
1462
master_branch = target.get_master_branch()
1463
master_branch.lock_write()
1466
# push into the master from this branch.
1467
super(BzrBranch5, self).push(master_branch, overwrite,
1468
stop_revision, _run_hooks=False)
1469
# and push into the target branch from this. Note that we push from
1470
# this branch again, because its considered the highest bandwidth
1472
return super(BzrBranch5, self).push(target, overwrite,
1473
stop_revision, _hook_master=master_branch)
1476
master_branch.unlock()
1345
1478
def get_bound_location(self):