~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-05-24 11:41:24 UTC
  • mfrom: (3449.1.2 unbreak-push-overwrite)
  • Revision ID: pqm@pqm.ubuntu.com-20080524114124-ubdyd5iqf7zxl2pn
Fix "bzr push --overwrite -r NNN". (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
447
447
                raise errors.NoSuchRevision(self, stop_revision)
448
448
        return other_history[self_len:stop_revision]
449
449
 
450
 
    def update_revisions(self, other, stop_revision=None, overwrite=False,
451
 
                         graph=None):
 
450
    def update_revisions(self, other, stop_revision=None):
452
451
        """Pull in new perfect-fit revisions.
453
452
 
454
453
        :param other: Another Branch to pull from
455
454
        :param stop_revision: Updated until the given revision
456
 
        :param overwrite: Always set the branch pointer, rather than checking
457
 
            to see if it is a proper descendant.
458
 
        :param graph: A Graph object that can be used to query history
459
 
            information. This can be None.
460
455
        :return: None
461
456
        """
462
457
        raise NotImplementedError(self.update_revisions)
1506
1501
            last_rev, other_branch))
1507
1502
 
1508
1503
    @needs_write_lock
1509
 
    def update_revisions(self, other, stop_revision=None, overwrite=False,
1510
 
                         graph=None):
 
1504
    def update_revisions(self, other, stop_revision=None, overwrite=False):
1511
1505
        """See Branch.update_revisions."""
1512
1506
        other.lock_read()
1513
1507
        try:
1514
 
            other_revno, other_last_revision = other.last_revision_info()
1515
 
            stop_revno = None # unknown
 
1508
            other_last_revno, other_last_revision = other.last_revision_info()
1516
1509
            if stop_revision is None:
1517
1510
                stop_revision = other_last_revision
1518
1511
                if _mod_revision.is_null(stop_revision):
1519
1512
                    # if there are no commits, we're done.
1520
1513
                    return
1521
 
                stop_revno = other_revno
1522
 
 
1523
 
            # what's the current last revision, before we fetch [and change it
 
1514
            # whats the current last revision, before we fetch [and change it
1524
1515
            # possibly]
1525
1516
            last_rev = _mod_revision.ensure_null(self.last_revision())
1526
1517
            # we fetch here so that we don't process data twice in the common
1530
1521
            self.fetch(other, stop_revision)
1531
1522
            # Check to see if one is an ancestor of the other
1532
1523
            if not overwrite:
1533
 
                if graph is None:
1534
 
                    graph = self.repository.get_graph()
1535
 
                heads = graph.heads([stop_revision, last_rev])
 
1524
                heads = self.repository.get_graph().heads([stop_revision,
 
1525
                                                           last_rev])
1536
1526
                if heads == set([last_rev]):
1537
1527
                    # The current revision is a decendent of the target,
1538
1528
                    # nothing to do
1542
1532
                    raise errors.DivergedBranches(self, other)
1543
1533
                elif heads != set([stop_revision]):
1544
1534
                    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)
 
1535
            if other_last_revision == stop_revision:
 
1536
                self.set_last_revision_info(other_last_revno,
 
1537
                                            other_last_revision)
 
1538
            else:
 
1539
                # TODO: jam 2007-11-29 Is there a way to determine the
 
1540
                #       revno without searching all of history??
 
1541
                if overwrite:
 
1542
                    self.generate_revision_history(stop_revision)
 
1543
                else:
 
1544
                    self.generate_revision_history(stop_revision,
 
1545
                        last_rev=last_rev, other_branch=other)
1553
1546
        finally:
1554
1547
            other.unlock()
1555
1548
 
1573
1566
        result.target_branch = self
1574
1567
        source.lock_read()
1575
1568
        try:
1576
 
            # We assume that during 'pull' the local repository is closer than
1577
 
            # the remote one.
1578
 
            graph = self.repository.get_graph(source.repository)
1579
1569
            result.old_revno, result.old_revid = self.last_revision_info()
1580
 
            self.update_revisions(source, stop_revision, overwrite=overwrite,
1581
 
                                  graph=graph)
 
1570
            self.update_revisions(source, stop_revision, overwrite=overwrite)
1582
1571
            result.tag_conflicts = source.tags.merge_to(self.tags, overwrite)
1583
1572
            result.new_revno, result.new_revid = self.last_revision_info()
1584
1573
            if _hook_master:
1681
1670
        result.source_branch = self
1682
1671
        result.target_branch = target
1683
1672
        result.old_revno, result.old_revid = target.last_revision_info()
1684
 
 
1685
 
        # We assume that during 'push' this repository is closer than
1686
 
        # the target.
1687
 
        graph = self.repository.get_graph(target.repository)
1688
 
        target.update_revisions(self, stop_revision, overwrite=overwrite,
1689
 
                                graph=graph)
 
1673
        target.update_revisions(self, stop_revision, overwrite)
1690
1674
        result.tag_conflicts = self.tags.merge_to(target.tags, overwrite)
1691
1675
        result.new_revno, result.new_revid = target.last_revision_info()
1692
1676
        return result