Patchwork [1,of,3,RFC] context: factor out commonancestorsheads calculation

login
register
mail settings
Submitter Sean Farley
Date May 27, 2018, 11:48 a.m.
Message ID <6a31ef919a2440e79a14.1527421696@1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa>
Download mbox | patch
Permalink /patch/31887/
State New
Headers show

Comments

Sean Farley - May 27, 2018, 11:48 a.m.
# HG changeset patch
# User Sean Farley <sean@farley.io>
# Date 1527357492 -7200
#      Sat May 26 19:58:12 2018 +0200
# Node ID 6a31ef919a2440e79a1477d428b46408bf3667ab
# Parent  cc9aa88792fe8daf041521710f52be59c69b79eb
# EXP-Topic gca-revset
context: factor out commonancestorsheads calculation

A future patch will make a new method that returns a list of all
changesets that are a common ancestor. In other words, this method will
return all the candidates for a consensus merge.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
index 90142e4..30d57e0 100644
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -543,21 +543,24 @@  class changectx(basectx):
         if fileid is None:
             fileid = self.filenode(path)
         return filectx(self._repo, path, fileid=fileid,
                        changectx=self, filelog=filelog)
 
+    def _commonancestors(self, c2):
+        # deal with workingctxs
+        n2 = c2._node
+        if n2 is None:
+            n2 = c2._parents[0]._node
+        return n2, self._repo.changelog.commonancestorsheads(self._node, n2)
+
     def ancestor(self, c2, warn=False):
         """return the "best" ancestor context of self and c2
 
         If there are multiple candidates, it will show a message and check
         merge.preferancestor configuration before falling back to the
         revlog ancestor."""
-        # deal with workingctxs
-        n2 = c2._node
-        if n2 is None:
-            n2 = c2._parents[0]._node
-        cahs = self._repo.changelog.commonancestorsheads(self._node, n2)
+        n2, cahs = self._commonancestors(c2)
         if not cahs:
             anc = nullid
         elif len(cahs) == 1:
             anc = cahs[0]
         else: