equal
deleted
inserted
replaced
13 from mercurial.i18n import _ |
13 from mercurial.i18n import _ |
14 from mercurial import ( |
14 from mercurial import ( |
15 ancestor, |
15 ancestor, |
16 error, |
16 error, |
17 mdiff, |
17 mdiff, |
18 pycompat, |
|
19 revlog, |
18 revlog, |
20 ) |
19 ) |
21 from mercurial.utils import storageutil |
20 from mercurial.utils import storageutil |
22 from mercurial.revlogutils import flagutil |
21 from mercurial.revlogutils import flagutil |
23 |
22 |
421 def ancestor(self, a, b): |
420 def ancestor(self, a, b): |
422 if a == self.repo.nullid or b == self.repo.nullid: |
421 if a == self.repo.nullid or b == self.repo.nullid: |
423 return self.repo.nullid |
422 return self.repo.nullid |
424 |
423 |
425 revmap, parentfunc = self._buildrevgraph(a, b) |
424 revmap, parentfunc = self._buildrevgraph(a, b) |
426 nodemap = {v: k for (k, v) in pycompat.iteritems(revmap)} |
425 nodemap = {v: k for (k, v) in revmap.items()} |
427 |
426 |
428 ancs = ancestor.ancestors(parentfunc, revmap[a], revmap[b]) |
427 ancs = ancestor.ancestors(parentfunc, revmap[a], revmap[b]) |
429 if ancs: |
428 if ancs: |
430 # choose a consistent winner when there's a tie |
429 # choose a consistent winner when there's a tie |
431 return min(map(nodemap.__getitem__, ancs)) |
430 return min(map(nodemap.__getitem__, ancs)) |
436 |
435 |
437 if a == self.repo.nullid or b == self.repo.nullid: |
436 if a == self.repo.nullid or b == self.repo.nullid: |
438 return self.repo.nullid |
437 return self.repo.nullid |
439 |
438 |
440 revmap, parentfunc = self._buildrevgraph(a, b) |
439 revmap, parentfunc = self._buildrevgraph(a, b) |
441 nodemap = {v: k for (k, v) in pycompat.iteritems(revmap)} |
440 nodemap = {v: k for (k, v) in revmap.items()} |
442 |
441 |
443 ancs = ancestor.commonancestorsheads(parentfunc, revmap[a], revmap[b]) |
442 ancs = ancestor.commonancestorsheads(parentfunc, revmap[a], revmap[b]) |
444 return map(nodemap.__getitem__, ancs) |
443 return map(nodemap.__getitem__, ancs) |
445 |
444 |
446 def _buildrevgraph(self, a, b): |
445 def _buildrevgraph(self, a, b): |
452 |
451 |
453 # Union the two maps |
452 # Union the two maps |
454 parentsmap = collections.defaultdict(list) |
453 parentsmap = collections.defaultdict(list) |
455 allparents = set() |
454 allparents = set() |
456 for mapping in (amap, bmap): |
455 for mapping in (amap, bmap): |
457 for node, pdata in pycompat.iteritems(mapping): |
456 for node, pdata in mapping.items(): |
458 parents = parentsmap[node] |
457 parents = parentsmap[node] |
459 p1, p2, linknode, copyfrom = pdata |
458 p1, p2, linknode, copyfrom = pdata |
460 # Don't follow renames (copyfrom). |
459 # Don't follow renames (copyfrom). |
461 # remotefilectx.ancestor does that. |
460 # remotefilectx.ancestor does that. |
462 if p1 != self.repo.nullid and not copyfrom: |
461 if p1 != self.repo.nullid and not copyfrom: |