comparison mercurial/context.py @ 21126:99b5eaf372a7

context: introduce merge.preferancestor for controlling which ancestor to pick Multiple revisions can be specified in merge.preferancestor, separated by whitespace. First match wins. This makes it possible to overrule the default of picking the common ancestor with the lowest hash value among the "best" (introduced in 3605d4e7e618). This can for instance help with some merges where the 'wrong' ancestor is used. There will thus be some overlap between this and the problems that can be solved with a future 'consensus merge'. Mercurial will show a note like note: using 40663881a6dd as ancestor of 3b08d01b0ab5 and adfe50279922 alternatively, use --config merge.preferancestor=0f6b37dbe527 when the option is available, listing all the alternative ancestors.
author Mads Kiilerich <madski@unity3d.com>
date Mon, 24 Feb 2014 22:42:14 +0100
parents e94e90a4526e
children 9f12d8665c7b
comparison
equal deleted inserted replaced
21125:e94e90a4526e 21126:99b5eaf372a7
394 return filectx(self._repo, path, fileid=fileid, 394 return filectx(self._repo, path, fileid=fileid,
395 changectx=self, filelog=filelog) 395 changectx=self, filelog=filelog)
396 396
397 def ancestor(self, c2): 397 def ancestor(self, c2):
398 """ 398 """
399 return the ancestor context of self and c2 399 return the "best" ancestor context of self and c2
400 """ 400 """
401 # deal with workingctxs 401 # deal with workingctxs
402 n2 = c2._node 402 n2 = c2._node
403 if n2 is None: 403 if n2 is None:
404 n2 = c2._parents[0]._node 404 n2 = c2._parents[0]._node
406 if not cahs: 406 if not cahs:
407 anc = nullid 407 anc = nullid
408 elif len(cahs) == 1: 408 elif len(cahs) == 1:
409 anc = cahs[0] 409 anc = cahs[0]
410 else: 410 else:
411 anc = self._repo.changelog.ancestor(self._node, n2) 411 for r in self._repo.ui.configlist('merge', 'preferancestor'):
412 ctx = changectx(self._repo, r)
413 anc = ctx.node()
414 if anc in cahs:
415 break
416 else:
417 anc = self._repo.changelog.ancestor(self._node, n2)
412 self._repo.ui.status( 418 self._repo.ui.status(
413 (_("note: using %s as ancestor of %s and %s\n") % 419 (_("note: using %s as ancestor of %s and %s\n") %
414 (short(anc), short(self._node), short(n2)))) 420 (short(anc), short(self._node), short(n2))) +
421 ''.join(_(" alternatively, use --config "
422 "merge.preferancestor=%s\n") %
423 short(n) for n in sorted(cahs) if n != anc))
415 return changectx(self._repo, anc) 424 return changectx(self._repo, anc)
416 425
417 def descendant(self, other): 426 def descendant(self, other):
418 """True if other is descendant of this changeset""" 427 """True if other is descendant of this changeset"""
419 return self._repo.changelog.descendant(self._rev, other._rev) 428 return self._repo.changelog.descendant(self._rev, other._rev)