Mercurial > public > mercurial-scm > hg
comparison mercurial/revlog.py @ 20557:514d32de6646
revlog: introduce commonancestors method for getting all common ancestor heads
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Mon, 24 Feb 2014 22:42:14 +0100 |
parents | 33394f2e331e |
children | 774ff56cbe34 |
comparison
equal
deleted
inserted
replaced
20556:db0740a487ab | 20557:514d32de6646 |
---|---|
732 return True | 732 return True |
733 elif i > end: | 733 elif i > end: |
734 break | 734 break |
735 return False | 735 return False |
736 | 736 |
737 def ancestor(self, a, b): | 737 def commonancestors(self, a, b): |
738 """calculate the least common ancestor of nodes a and b""" | 738 """calculate the least common ancestors of nodes a and b""" |
739 | |
740 a, b = self.rev(a), self.rev(b) | 739 a, b = self.rev(a), self.rev(b) |
741 try: | 740 try: |
742 ancs = self.index.ancestors(a, b) | 741 ancs = self.index.ancestors(a, b) |
743 except (AttributeError, OverflowError): | 742 except (AttributeError, OverflowError): # C implementation failed |
744 ancs = ancestor.ancestors(self.parentrevs, a, b) | 743 ancs = ancestor.ancestors(self.parentrevs, a, b) |
744 return map(self.node, ancs) | |
745 | |
746 def ancestor(self, a, b): | |
747 """calculate a least common ancestor of nodes a and b""" | |
748 ancs = self.commonancestors(a, b) | |
745 if ancs: | 749 if ancs: |
746 # choose a consistent winner when there's a tie | 750 # choose a consistent winner when there's a tie |
747 return min(map(self.node, ancs)) | 751 return min(ancs) |
748 return nullid | 752 return nullid |
749 | 753 |
750 def _match(self, id): | 754 def _match(self, id): |
751 if isinstance(id, int): | 755 if isinstance(id, int): |
752 # rev | 756 # rev |