Patchwork [5,of,7] obsstore: also store the 'parents' field on disk

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 19, 2014, 12:49 a.m.
Message ID <bfa06f4858e3e088f84d.1408409375@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5499/
State Superseded
Commit cf414981978a53d2d9a38bbb971bddd3c9a2ba14
Headers show

Comments

Pierre-Yves David - Aug. 19, 2014, 12:49 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1408404524 25200
#      Mon Aug 18 16:28:44 2014 -0700
# Node ID bfa06f4858e3e088f84df0cda1ad78bbe9a01132
# Parent  793dd98326b070cb43804c3141e6053dc37c386e
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.
Pierre-Yves David - Aug. 19, 2014, 5:52 p.m.
On 08/18/2014 05:49 PM, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1408404524 25200
> #      Mon Aug 18 16:28:44 2014 -0700
> # Node ID bfa06f4858e3e088f84df0cda1ad78bbe9a01132
> # Parent  793dd98326b070cb43804c3141e6053dc37c386e
> obsstore: also store the 'parents' field on disk

This change need to be rebase atop the fix for date I just patchbomb.
(and it also need to gain similar armor against malformated markers)

I'll post a V2 in a second

Patch

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -168,13 +168,22 @@  def _readmarkers(data):
                                'short, %d bytes expected, got %d')
                              % (mdsize, len(metadata)))
         off += mdsize
         meta = decodemeta(metadata)
         date = util.parsedate(meta.pop('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:
+            parents = tuple(node.bin(p) for p in parents)
         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."""
@@ -359,10 +368,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)