[PATCH 5 of 7 V2 apply on date fix] obsstore: also store the 'parents' field on disk

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue Aug 19 12:53:41 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1408404524 25200
#      Mon Aug 18 16:28:44 2014 -0700
# Node ID d05b490f62be236c93859892715733a117c231ca
# Parent  ce953e0e9dea9001b2907efa015823475aa43696
obsstore: also store the 'parents' field on disk

We now store the `parents` field on disk. We use the same strategy as for
`date`: We stick it into the metadata. This is slow and dirty, but this is also
the only way we currently have.

At some point we'll have a new obsstore format to store this properly.

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -171,13 +171,32 @@ def _readmarkers(data):
         meta = decodemeta(metadata)
         try:
             date = util.parsedate(decodemeta(metadata).pop('date', '0 0'))
         except util.Abort:
             date = (0., 0)
+        parents = None
+        if 'p2' in meta:
+            parents = (meta.pop('p1', None), meta.pop('p2', None))
+        elif 'p1' in meta:
+            parents = (meta.pop('p1', None),)
+        elif 'p0' in meta:
+            parents = ()
+        if parents is not None:
+            try:
+                parents = tuple(node.bin(p) for p in parents)
+                # if parent conent is not nodeid drop the data
+                for p in parents:
+                    if len(p) != 20:
+                        parents = None
+                        break
+            except TypeError:
+                # if content cannot be translated to nodeid drop the data.
+                parents = None
+
         metadata = encodemeta(meta)
 
-        yield (pre, sucs, flags, metadata, date, None)
+        yield (pre, sucs, flags, metadata, date, parents)
 
 def encodemeta(meta):
     """Return encoded metadata string to string mapping.
 
     Assume no ':' in key and no '\0' in both key and value."""
@@ -362,10 +381,16 @@ def _encodemarkers(markers, addheader=Fa
 
 def _encodeonemarker(marker):
     pre, sucs, flags, metadata, date, parents = marker
     metadata = decodemeta(metadata)
     metadata['date'] = '%d %i' % date
+    if parents is not None:
+        if not parents:
+            # marks we explicitly recorded no parents.
+            metadata['p0'] = ''
+        for i, p in enumerate(parents, 1):
+            metadata['p%i' % i] = node.hex(p)
     metadata = encodemeta(metadata)
     nbsuc = len(sucs)
     format = _fmfixed + (_fmnode * nbsuc)
     data = [nbsuc, len(metadata), flags, pre]
     data.extend(sucs)


More information about the Mercurial-devel mailing list