~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: John Arbash Meinel
  • Date: 2008-05-22 22:56:34 UTC
  • mto: This revision was merged to the branch mainline in revision 3460.
  • Revision ID: john@arbash-meinel.com-20080522225634-bl5qfq1caf119hr2
allow passing a 'graph' object into Branch.update_revisions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1500
1500
            last_rev, other_branch))
1501
1501
 
1502
1502
    @needs_write_lock
1503
 
    def update_revisions(self, other, stop_revision=None, overwrite=False):
 
1503
    def update_revisions(self, other, stop_revision=None, overwrite=False,
 
1504
                         graph=None):
1504
1505
        """See Branch.update_revisions."""
1505
1506
        other.lock_read()
1506
1507
        try:
1507
 
            other_last_revno, other_last_revision = other.last_revision_info()
 
1508
            other_revno, other_last_revision = other.last_revision_info()
 
1509
            stop_revno = None # unknown
1508
1510
            if stop_revision is None:
1509
1511
                stop_revision = other_last_revision
1510
1512
                if _mod_revision.is_null(stop_revision):
1511
1513
                    # if there are no commits, we're done.
1512
1514
                    return
 
1515
                stop_revno = other_revno
 
1516
 
1513
1517
            # whats the current last revision, before we fetch [and change it
1514
1518
            # possibly]
1515
1519
            last_rev = _mod_revision.ensure_null(self.last_revision())
1520
1524
            self.fetch(other, stop_revision)
1521
1525
            # Check to see if one is an ancestor of the other
1522
1526
            if not overwrite:
1523
 
                heads = self.repository.get_graph().heads([stop_revision,
1524
 
                                                           last_rev])
 
1527
                if graph is None:
 
1528
                    graph = self.repository.get_graph()
 
1529
                heads = graph.heads([stop_revision, last_rev])
1525
1530
                if heads == set([last_rev]):
1526
1531
                    # The current revision is a decendent of the target,
1527
1532
                    # nothing to do
1531
1536
                    raise errors.DivergedBranches(self, other)
1532
1537
                elif heads != set([stop_revision]):
1533
1538
                    raise AssertionError("invalid heads: %r" % heads)
1534
 
            if other_last_revision == stop_revision:
1535
 
                self.set_last_revision_info(other_last_revno,
1536
 
                                            other_last_revision)
1537
 
            else:
1538
 
                # TODO: jam 2007-11-29 Is there a way to determine the
1539
 
                #       revno without searching all of history??
1540
 
                if overwrite:
1541
 
                    self.generate_revision_history(stop_revision)
1542
 
                else:
1543
 
                    self.generate_revision_history(stop_revision,
1544
 
                        last_rev=last_rev, other_branch=other)
 
1539
            if stop_revno is None:
 
1540
                if graph is None:
 
1541
                    graph = self.repository.get_graph()
 
1542
                this_revno, this_last_revision = self.last_revision_info()
 
1543
                stop_revno = graph.find_distance_to_null(stop_revision,
 
1544
                                [(other_last_revision, other_revno),
 
1545
                                 (this_last_revision, this_revno)])
 
1546
            self.set_last_revision_info(stop_revno, stop_revision)
1545
1547
        finally:
1546
1548
            other.unlock()
1547
1549