Patchwork [4,of,5] merge.mergestate: factor out code to validate v1/v2 records

login
register
mail settings
Submitter Siddharth Agarwal
Date Oct. 6, 2015, 11:40 p.m.
Message ID <7d7fd02dd571bd6e1a74.1444174806@dev6666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/10841/
State Accepted
Headers show

Comments

Siddharth Agarwal - Oct. 6, 2015, 11:40 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1443673351 25200
#      Wed Sep 30 21:22:31 2015 -0700
# Node ID 7d7fd02dd571bd6e1a74bc87097aa2338cfdba2b
# Parent  2d3f081900f9e0eb5d583211f5db699f2f5b000b
merge.mergestate: factor out code to validate v1/v2 records

We're going to need this in another place in upcoming patches.

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -117,6 +117,25 @@  class mergestate(object):
         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 @@  class mergestate(object):
                 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