Patchwork [1,of,3] merge: add state extras merge state data

login
register
mail settings
Submitter Durham Goode
Date Feb. 5, 2016, 7:02 p.m.
Message ID <27579dd5295a4b41960c.1454698970@dev8486.prn1.facebook.com>
Download mbox | patch
Permalink /patch/13009/
State Superseded
Headers show

Comments

Durham Goode - Feb. 5, 2016, 7:02 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1454696128 28800
#      Fri Feb 05 10:15:28 2016 -0800
# Node ID 27579dd5295a4b41960c34e33287c2e9bdfc8113
# Parent  01a5143cd25f285f8c745a92986cd7186bb32c90
merge: add state extras merge state data

In future commits we will want to store more data related to each file in the
merge state. This patch adds an optional record for storing a dictionary of
extras for each file.
Durham Goode - Feb. 5, 2016, 7:04 p.m.
On 2/5/16 11:02 AM, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1454696128 28800
> #      Fri Feb 05 10:15:28 2016 -0800
> # Node ID 27579dd5295a4b41960c34e33287c2e9bdfc8113
> # Parent  01a5143cd25f285f8c745a92986cd7186bb32c90
> merge: add state extras merge state data
>
> In future commits we will want to store more data related to each file in the
> merge state. This patch adds an optional record for storing a dictionary of
> extras for each file.
>
This was meant to be a V2 series.  I've resent with the correct V2 flag.
Pierre-Yves David - Feb. 11, 2016, 9:35 p.m.
On 02/05/2016 07:02 PM, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1454696128 28800
> #      Fri Feb 05 10:15:28 2016 -0800
> # Node ID 27579dd5295a4b41960c34e33287c2e9bdfc8113
> # Parent  01a5143cd25f285f8c745a92986cd7186bb32c90
> merge: add state extras merge state data
>
> In future commits we will want to store more data related to each file in the
> merge state. This patch adds an optional record for storing a dictionary of
> extras for each file.

Small nits, it would be nice to have some more details on what you plan 
to store/what you are trying to solve a bit earlier in the series (like 
now). Please think about it for next time.

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -65,6 +65,7 @@  class mergestate(object):
        (experimental)
     m: the external merge driver defined for this merge plus its run state
        (experimental)
+    f: a (filename, dictonary) tuple of optional values for a given file
     X: unsupported mandatory record type (used in tests)
     x: unsupported advisory record type (used in tests)
 
@@ -102,6 +103,7 @@  class mergestate(object):
 
     def reset(self, node=None, other=None):
         self._state = {}
+        self._stateextras = {}
         self._local = None
         self._other = None
         for var in ('localctx', 'otherctx'):
@@ -126,6 +128,7 @@  class mergestate(object):
         of on disk file.
         """
         self._state = {}
+        self._stateextras = {}
         self._local = None
         self._other = None
         for var in ('localctx', 'otherctx'):
@@ -152,6 +155,16 @@  class mergestate(object):
             elif rtype in 'FDC':
                 bits = record.split('\0')
                 self._state[bits[0]] = bits[1:]
+            elif rtype == 'f':
+                filename, rawextras = record.split('\0', 1)
+                extraparts = rawextras.split('\0')
+                extras = {}
+                i = 0
+                while i < len(extraparts):
+                    extras[extraparts[i]] = extraparts[i + 1]
+                    i += 2
+
+                self._stateextras[filename] = extras
             elif not rtype.islower():
                 unsupported.add(rtype)
         self._results = {}
@@ -336,6 +349,10 @@  class mergestate(object):
                 records.append(('C', '\0'.join([d] + v)))
             else:
                 records.append(('F', '\0'.join([d] + v)))
+        for filename, extras in sorted(self._stateextras.iteritems()):
+            rawextras = '\0'.join('%s\0%s' % (k, v) for k, v in
+                                  extras.iteritems())
+            records.append(('f', '%s\0%s' % (filename, rawextras)))
         return records
 
     def _writerecords(self, records):
@@ -423,6 +440,9 @@  class mergestate(object):
             if entry[0] == 'd':
                 yield f
 
+    def extras(self, filename):
+        return self._stateextras.setdefault(filename, {})
+
     def _resolve(self, preresolve, dfile, wctx, labels=None):
         """rerun merge process for file path `dfile`"""
         if self[dfile] in 'rd':
@@ -462,6 +482,7 @@  class mergestate(object):
         if r is None:
             # no real conflict
             del self._state[dfile]
+            self._stateextras.pop(dfile, None)
             self._dirty = True
         elif not r:
             self.mark(dfile, 'r')