/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: John Arbash Meinel
  • Date: 2007-02-13 20:33:57 UTC
  • mfrom: (2283 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2294.
  • Revision ID: john@arbash-meinel.com-20070213203357-b7yg41mi9sk6cqd0
[merge] bzr.dev 2283
resolve conflicts in moved repository formats
small issue with osutils.contains_whitespace()

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 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
225
225
        try:
226
226
            if last_revision is None:
227
227
                pb.update('get source history')
228
 
                from_history = from_branch.revision_history()
229
 
                if from_history:
230
 
                    last_revision = from_history[-1]
231
 
                else:
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,
236
231
                                         pb=nested_pb)
264
259
        if config is None:
265
260
            config = self.get_config()
266
261
        
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)
269
264
 
270
265
    def get_master_branch(self):
324
319
        else:
325
320
            return None
326
321
 
 
322
    def last_revision_info(self):
 
323
        """Return information about the last revision.
 
324
 
 
325
        :return: A tuple (revno, last_revision_id).
 
326
        """
 
327
        rh = self.revision_history()
 
328
        revno = len(rh)
 
329
        if revno:
 
330
            return (revno, rh[-1])
 
331
        else:
 
332
            return (0, _mod_revision.NULL_REVISION)
 
333
 
327
334
    def missing_revisions(self, other, stop_revision=None):
328
335
        """Return a list of new revisions that would perfectly fit.
329
336
        
378
385
        return history[revno - 1]
379
386
 
380
387
    def pull(self, source, overwrite=False, stop_revision=None):
 
388
        """Mirror source into this branch.
 
389
 
 
390
        This branch is considered to be 'local', having low latency.
 
391
        """
381
392
        raise NotImplementedError(self.pull)
382
393
 
 
394
    def push(self, target, overwrite=False, stop_revision=None):
 
395
        """Mirror this branch into target.
 
396
 
 
397
        This branch is considered to be 'local', having low latency.
 
398
        """
 
399
        raise NotImplementedError(self.push)
 
400
 
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.
597
615
        """
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()
602
620
        else:
603
621
            format = self.repository.bzrdir.cloning_metadir()
604
622
        return format
605
623
 
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.
609
627
        
680
698
 
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)
684
702
 
685
703
    def initialize(self, a_bzrdir):
686
704
        """Create a branch of this format in a_bzrdir."""
734
752
        notified.
735
753
        """
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.
 
759
        # be write-locked.
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'] = []
742
788
 
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()
1238
1284
 
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):
 
1288
        """See Branch.pull.
 
1289
 
 
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.
 
1294
        """
1242
1295
        source.lock_read()
1243
1296
        try:
1244
 
            old_count = len(self.revision_history())
 
1297
            old_count, old_tip = self.last_revision_info()
1245
1298
            try:
1246
1299
                self.update_revisions(source, stop_revision)
1247
1300
            except DivergedBranches:
1249
1302
                    raise
1250
1303
            if overwrite:
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()
 
1306
            if _run_hooks:
 
1307
                if _hook_master:
 
1308
                    _hook_local = self
 
1309
                else:
 
1310
                    _hook_master = self
 
1311
                    _hook_local = None
 
1312
                for hook in Branch.hooks['post_pull']:
 
1313
                    hook(source, _hook_local, _hook_master, old_count, old_tip,
 
1314
                        new_count, new_tip)
1253
1315
            return new_count - old_count
1254
1316
        finally:
1255
1317
            source.unlock()
1256
1318
 
 
1319
    @needs_read_lock
 
1320
    def push(self, target, overwrite=False, stop_revision=None,
 
1321
        _hook_master=None, _run_hooks=True):
 
1322
        """See Branch.push.
 
1323
        
 
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.
 
1328
        """
 
1329
        target.lock_write()
 
1330
        try:
 
1331
            old_count, old_tip = target.last_revision_info()
 
1332
            try:
 
1333
                target.update_revisions(self, stop_revision)
 
1334
            except DivergedBranches:
 
1335
                if not overwrite:
 
1336
                    raise
 
1337
            if overwrite:
 
1338
                target.set_revision_history(self.revision_history())
 
1339
            new_count, new_tip = target.last_revision_info()
 
1340
            if _run_hooks:
 
1341
                if _hook_master:
 
1342
                    _hook_local = target
 
1343
                else:
 
1344
                    _hook_master = target
 
1345
                    _hook_local = None
 
1346
                for hook in Branch.hooks['post_push']:
 
1347
                    hook(self, _hook_local, _hook_master, old_count, old_tip,
 
1348
                        new_count, new_tip)
 
1349
            return new_count - old_count
 
1350
        finally:
 
1351
            target.unlock()
 
1352
 
1257
1353
    def get_parent(self):
1258
1354
        """See Branch.get_parent."""
1259
1355
 
1331
1427
                                         _repository=_repository)
1332
1428
        
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,
 
1431
        _run_hooks=True):
 
1432
        """Extends branch.pull to be bound branch aware.
 
1433
        
 
1434
        :param _run_hooks: Private parameter used to force hook running
 
1435
            off during bound branch double-pushing.
 
1436
        """
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()
1340
 
            if 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()
 
1443
        try:
 
1444
            if master_branch:
 
1445
                # pull from source into master.
 
1446
                master_branch.pull(source, overwrite, stop_revision,
 
1447
                    _run_hooks=False)
 
1448
            return super(BzrBranch5, self).pull(source, overwrite,
 
1449
                stop_revision, _hook_master=master_branch,
 
1450
                _run_hooks=_run_hooks)
 
1451
        finally:
 
1452
            if master_branch:
 
1453
                master_branch.unlock()
 
1454
 
 
1455
    @needs_read_lock
 
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()
 
1464
        try:
 
1465
            if master_branch:
 
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
 
1471
            # repository.
 
1472
            return super(BzrBranch5, self).push(target, overwrite,
 
1473
                stop_revision, _hook_master=master_branch)
 
1474
        finally:
 
1475
            if master_branch:
 
1476
                master_branch.unlock()
1344
1477
 
1345
1478
    def get_bound_location(self):
1346
1479
        try: