mergestate: use _stateextras instead of merge records for commit related info
authorPulkit Goyal <7895pulkit@gmail.com>
Mon, 10 Aug 2020 15:29:02 +0530
changeset 45382 0652a533fe3c
parent 45381 ede4c121239e
child 45383 f970cca30989
mergestate: use _stateextras instead of merge records for commit related info There is a set of information related to a merge which is needed on commit. We want to store such information in the mergestate so that we can read it while committing. For this purpose, we are using merge records and introduced a merge entry state for that. However this won't scale and is not clean way to implement this. This patch reworks the existing logic related to this to use _stateextras and read from it. Right now the information stored is not very descriptive but it will be in next patch. Using _stateextras also makes MERGE_RECORD_MERGED_OTHER useless and only to be kept for BC. Differential Revision: https://phab.mercurial-scm.org/D8920
mercurial/commands.py
mercurial/commit.py
mercurial/mergestate.py
--- a/mercurial/commands.py	Mon Aug 10 15:09:44 2020 +0530
+++ b/mercurial/commands.py	Mon Aug 10 15:29:02 2020 +0530
@@ -5969,8 +5969,6 @@
             if not m(f):
                 continue
 
-            if ms[f] == mergestatemod.MERGE_RECORD_MERGED_OTHER:
-                continue
             label, key = mergestateinfo[ms[f]]
             fm.startitem()
             fm.context(ctx=wctx)
@@ -6018,9 +6016,6 @@
 
             didwork = True
 
-            if ms[f] == mergestatemod.MERGE_RECORD_MERGED_OTHER:
-                continue
-
             # don't let driver-resolved files be marked, and run the conclude
             # step if asked to resolve
             if ms[f] == mergestatemod.MERGE_RECORD_DRIVER_RESOLVED:
--- a/mercurial/commit.py	Mon Aug 10 15:09:44 2020 +0530
+++ b/mercurial/commit.py	Mon Aug 10 15:29:02 2020 +0530
@@ -325,10 +325,7 @@
         elif not fparentancestors:
             # TODO: this whole if-else might be simplified much more
             ms = mergestate.mergestate.read(repo)
-            if (
-                fname in ms
-                and ms[fname] == mergestate.MERGE_RECORD_MERGED_OTHER
-            ):
+            if ms.extras(fname).get(b'filenode-source') == b'other':
                 fparent1, fparent2 = fparent2, nullid
 
     # is the file changed?
--- a/mercurial/mergestate.py	Mon Aug 10 15:09:44 2020 +0530
+++ b/mercurial/mergestate.py	Mon Aug 10 15:29:02 2020 +0530
@@ -81,6 +81,8 @@
 MERGE_RECORD_DRIVER_RESOLVED = b'd'
 # represents that the file was automatically merged in favor
 # of other version. This info is used on commit.
+# This is now deprecated and commit related information is now
+# stored in RECORD_FILE_VALUES
 MERGE_RECORD_MERGED_OTHER = b'o'
 
 #####
@@ -257,7 +259,13 @@
                 LEGACY_RECORD_RESOLVED_OTHER,
             ):
                 bits = record.split(b'\0')
-                self._state[bits[0]] = bits[1:]
+                # merge entry type MERGE_RECORD_MERGED_OTHER is deprecated
+                # and we now store related information in _stateextras, so
+                # lets write to _stateextras directly
+                if bits[1] == MERGE_RECORD_MERGED_OTHER:
+                    self._stateextras[bits[0]][b'filenode-source'] = b'other'
+                else:
+                    self._state[bits[0]] = bits[1:]
             elif rtype == RECORD_FILE_VALUES:
                 filename, rawextras = record.split(b'\0', 1)
                 extraparts = rawextras.split(b'\0')
@@ -486,8 +494,6 @@
                 records.append(
                     (RECORD_PATH_CONFLICT, b'\0'.join([filename] + v))
                 )
-            elif v[0] == MERGE_RECORD_MERGED_OTHER:
-                records.append((RECORD_MERGED, b'\0'.join([filename] + v)))
             elif v[1] == nullhex or v[6] == nullhex:
                 # Change/Delete or Delete/Change conflicts. These are stored in
                 # 'C' records. v[1] is the local file, and is nullhex when the
@@ -587,7 +593,7 @@
         self._dirty = True
 
     def addmergedother(self, path):
-        self._state[path] = [MERGE_RECORD_MERGED_OTHER, nullhex, nullhex]
+        self._stateextras[path] = {b'filenode-source': b'other'}
         self._dirty = True
 
     def __contains__(self, dfile):
@@ -636,8 +642,6 @@
         """
         if self[dfile] in (MERGE_RECORD_RESOLVED, MERGE_RECORD_DRIVER_RESOLVED):
             return True, 0
-        if self._state[dfile][0] == MERGE_RECORD_MERGED_OTHER:
-            return True, 0
         stateentry = self._state[dfile]
         state, localkey, lfile, afile, anode, ofile, onode, flags = stateentry
         octx = self._repo[self._other]