~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

MergeĀ fromĀ remote-is-at-least.

Show diffs side-by-side

added added

removed removed

Lines of Context:
425
425
        else:
426
426
            return (0, _mod_revision.NULL_REVISION)
427
427
 
 
428
    @deprecated_method(deprecated_in((1, 6, 0)))
428
429
    def missing_revisions(self, other, stop_revision=None):
429
430
        """Return a list of new revisions that would perfectly fit.
430
431
        
447
448
                raise errors.NoSuchRevision(self, stop_revision)
448
449
        return other_history[self_len:stop_revision]
449
450
 
 
451
    @needs_write_lock
450
452
    def update_revisions(self, other, stop_revision=None, overwrite=False,
451
453
                         graph=None):
452
454
        """Pull in new perfect-fit revisions.
459
461
            information. This can be None.
460
462
        :return: None
461
463
        """
462
 
        raise NotImplementedError(self.update_revisions)
 
464
        other.lock_read()
 
465
        try:
 
466
            other_revno, other_last_revision = other.last_revision_info()
 
467
            stop_revno = None # unknown
 
468
            if stop_revision is None:
 
469
                stop_revision = other_last_revision
 
470
                if _mod_revision.is_null(stop_revision):
 
471
                    # if there are no commits, we're done.
 
472
                    return
 
473
                stop_revno = other_revno
 
474
 
 
475
            # what's the current last revision, before we fetch [and change it
 
476
            # possibly]
 
477
            last_rev = _mod_revision.ensure_null(self.last_revision())
 
478
            # we fetch here so that we don't process data twice in the common
 
479
            # case of having something to pull, and so that the check for 
 
480
            # already merged can operate on the just fetched graph, which will
 
481
            # be cached in memory.
 
482
            self.fetch(other, stop_revision)
 
483
            # Check to see if one is an ancestor of the other
 
484
            if not overwrite:
 
485
                if graph is None:
 
486
                    graph = self.repository.get_graph()
 
487
                heads = graph.heads([stop_revision, last_rev])
 
488
                if heads == set([last_rev]):
 
489
                    # The current revision is a decendent of the target,
 
490
                    # nothing to do
 
491
                    return
 
492
                elif heads == set([stop_revision, last_rev]):
 
493
                    # These branches have diverged
 
494
                    raise errors.DivergedBranches(self, other)
 
495
                elif heads != set([stop_revision]):
 
496
                    raise AssertionError("invalid heads: %r" % heads)
 
497
            if stop_revno is None:
 
498
                if graph is None:
 
499
                    graph = self.repository.get_graph()
 
500
                this_revno, this_last_revision = self.last_revision_info()
 
501
                stop_revno = graph.find_distance_to_null(stop_revision,
 
502
                                [(other_last_revision, other_revno),
 
503
                                 (this_last_revision, this_revno)])
 
504
            self.set_last_revision_info(stop_revno, stop_revision)
 
505
        finally:
 
506
            other.unlock()
 
507
 
 
508
 
463
509
 
464
510
    def revision_id_to_revno(self, revision_id):
465
511
        """Given a revision id, return its revno"""
918
964
            for (filename, content) in utf8_files:
919
965
                branch_transport.put_bytes(
920
966
                    filename, content,
921
 
                    mode=control_files._file_mode)
 
967
                    mode=a_bzrdir._get_file_mode())
922
968
        finally:
923
969
            control_files.unlock()
924
970
        return self.open(a_bzrdir, _found=True)
1412
1458
        It is intended to be called by BzrBranch5.set_revision_history."""
1413
1459
        self._transport.put_bytes(
1414
1460
            'revision-history', '\n'.join(history),
1415
 
            mode=self.control_files._file_mode)
 
1461
            mode=self.bzrdir._get_file_mode())
1416
1462
 
1417
1463
    @needs_write_lock
1418
1464
    def set_revision_history(self, rev_history):
1505
1551
        self.set_revision_history(self._lefthand_history(revision_id,
1506
1552
            last_rev, other_branch))
1507
1553
 
1508
 
    @needs_write_lock
1509
 
    def update_revisions(self, other, stop_revision=None, overwrite=False,
1510
 
                         graph=None):
1511
 
        """See Branch.update_revisions."""
1512
 
        other.lock_read()
1513
 
        try:
1514
 
            other_revno, other_last_revision = other.last_revision_info()
1515
 
            stop_revno = None # unknown
1516
 
            if stop_revision is None:
1517
 
                stop_revision = other_last_revision
1518
 
                if _mod_revision.is_null(stop_revision):
1519
 
                    # if there are no commits, we're done.
1520
 
                    return
1521
 
                stop_revno = other_revno
1522
 
 
1523
 
            # what's the current last revision, before we fetch [and change it
1524
 
            # possibly]
1525
 
            last_rev = _mod_revision.ensure_null(self.last_revision())
1526
 
            # we fetch here so that we don't process data twice in the common
1527
 
            # case of having something to pull, and so that the check for 
1528
 
            # already merged can operate on the just fetched graph, which will
1529
 
            # be cached in memory.
1530
 
            self.fetch(other, stop_revision)
1531
 
            # Check to see if one is an ancestor of the other
1532
 
            if not overwrite:
1533
 
                if graph is None:
1534
 
                    graph = self.repository.get_graph()
1535
 
                heads = graph.heads([stop_revision, last_rev])
1536
 
                if heads == set([last_rev]):
1537
 
                    # The current revision is a decendent of the target,
1538
 
                    # nothing to do
1539
 
                    return
1540
 
                elif heads == set([stop_revision, last_rev]):
1541
 
                    # These branches have diverged
1542
 
                    raise errors.DivergedBranches(self, other)
1543
 
                elif heads != set([stop_revision]):
1544
 
                    raise AssertionError("invalid heads: %r" % heads)
1545
 
            if stop_revno is None:
1546
 
                if graph is None:
1547
 
                    graph = self.repository.get_graph()
1548
 
                this_revno, this_last_revision = self.last_revision_info()
1549
 
                stop_revno = graph.find_distance_to_null(stop_revision,
1550
 
                                [(other_last_revision, other_revno),
1551
 
                                 (this_last_revision, this_revno)])
1552
 
            self.set_last_revision_info(stop_revno, stop_revision)
1553
 
        finally:
1554
 
            other.unlock()
1555
 
 
1556
1554
    def basis_tree(self):
1557
1555
        """See Branch.basis_tree."""
1558
1556
        return self.repository.revision_tree(self.last_revision())
1734
1732
            self._transport.delete('parent')
1735
1733
        else:
1736
1734
            self._transport.put_bytes('parent', url + '\n',
1737
 
                mode=self.control_files._file_mode)
 
1735
                mode=self.bzrdir._get_file_mode())
1738
1736
 
1739
1737
 
1740
1738
class BzrBranch5(BzrBranch):
1913
1911
        revision_id = _mod_revision.ensure_null(revision_id)
1914
1912
        out_string = '%d %s\n' % (revno, revision_id)
1915
1913
        self._transport.put_bytes('last-revision', out_string,
1916
 
            mode=self.control_files._file_mode)
 
1914
            mode=self.bzrdir._get_file_mode())
1917
1915
 
1918
1916
    @needs_write_lock
1919
1917
    def set_last_revision_info(self, revno, revision_id):
2224
2222
        # Copying done; now update target format
2225
2223
        new_branch._transport.put_bytes('format',
2226
2224
            format.get_format_string(),
2227
 
            mode=new_branch.control_files._file_mode)
 
2225
            mode=new_branch.bzrdir._get_file_mode())
2228
2226
 
2229
2227
        # Clean up old files
2230
2228
        new_branch._transport.delete('revision-history')