changeset 26500:5bd7c4c07f6d

merge.mergestate: factor out code to validate v1/v2 records We're going to need this in another place in upcoming patches.
author Siddharth Agarwal <sid0@fb.com>
date Wed, 30 Sep 2015 21:22:31 -0700
parents e72b62b154b0
children 0748083f2898
files mercurial/merge.py
diffstat 1 files changed, 21 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/merge.py	Tue Oct 06 13:19:05 2015 -0700
+++ b/mercurial/merge.py	Wed Sep 30 21:22:31 2015 -0700
@@ -117,6 +117,25 @@
         returns list of record [(TYPE, data), ...]"""
         v1records = self._readrecordsv1()
         v2records = self._readrecordsv2()
+        if self._v1v2match(v1records, v2records):
+            return v2records
+        else:
+            # v1 file is newer than v2 file, use it
+            # we have to infer the "other" changeset of the merge
+            # we cannot do better than that with v1 of the format
+            mctx = self._repo[None].parents()[-1]
+            v1records.append(('O', mctx.hex()))
+            # add place holder "other" file node information
+            # nobody is using it yet so we do no need to fetch the data
+            # if mctx was wrong `mctx[bits[-2]]` may fails.
+            for idx, r in enumerate(v1records):
+                if r[0] == 'F':
+                    bits = r[1].split('\0')
+                    bits.insert(-2, '')
+                    v1records[idx] = (r[0], '\0'.join(bits))
+            return v1records
+
+    def _v1v2match(self, v1records, v2records):
         oldv2 = set() # old format version of v2 record
         for rec in v2records:
             if rec[0] == 'L':
@@ -126,22 +145,9 @@
                 oldv2.add(('F', _droponode(rec[1])))
         for rec in v1records:
             if rec not in oldv2:
-                # v1 file is newer than v2 file, use it
-                # we have to infer the "other" changeset of the merge
-                # we cannot do better than that with v1 of the format
-                mctx = self._repo[None].parents()[-1]
-                v1records.append(('O', mctx.hex()))
-                # add place holder "other" file node information
-                # nobody is using it yet so we do no need to fetch the data
-                # if mctx was wrong `mctx[bits[-2]]` may fails.
-                for idx, r in enumerate(v1records):
-                    if r[0] == 'F':
-                        bits = r[1].split('\0')
-                        bits.insert(-2, '')
-                        v1records[idx] = (r[0], '\0'.join(bits))
-                return v1records
+                return False
         else:
-            return v2records
+            return True
 
     def _readrecordsv1(self):
         """read on disk merge state for version 1 file