Patchwork [1,of,7] obsstore: add a `parents` field

login
register
mail settings
Submitter Pierre-Yves David
Date Aug. 19, 2014, 12:49 a.m.
Message ID <d5fefc953f30affb41ce.1408409371@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5495/
State Superseded
Commit b8a0e8176693ec0845f3d23015dc09f5e1443420
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 1408403324 25200
#      Mon Aug 18 16:08:44 2014 -0700
# Node ID d5fefc953f30affb41ce59289d6791b116169708
# Parent  3d33baa4c4269c682254d871039d7df1175b1856
obsstore: add a `parents` field

This fields is intended to store the parent of the precursor. This is useful to
attache pruned changeset to a set of exchanged changesets. We currently just
add the fields with a None value. None stand for "no data recorded".
Augie Fackler - Aug. 19, 2014, 2:08 p.m.
On Mon, Aug 18, 2014 at 05:49:31PM -0700, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1408403324 25200
> #      Mon Aug 18 16:08:44 2014 -0700
> # Node ID d5fefc953f30affb41ce59289d6791b116169708
> # Parent  3d33baa4c4269c682254d871039d7df1175b1856
> obsstore: add a `parents` field
>
> This fields is intended to store the parent of the precursor. This is useful to
> attache pruned changeset to a set of exchanged changesets. We currently just
> add the fields with a None value. None stand for "no data recorded".
>
> diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
> --- a/mercurial/obsolete.py
> +++ b/mercurial/obsolete.py
> @@ -168,11 +168,11 @@ def _readmarkers(data):
>                                 'short, %d bytes expected, got %d')
>                               % (mdsize, len(metadata)))
>          off += mdsize
>          date = util.parsedate(decodemeta(metadata).pop('date', '0 0'))
>
> -        yield (pre, sucs, flags, metadata, date)
> +        yield (pre, sucs, flags, metadata, date, None)
>
>  def encodemeta(meta):
>      """Return encoded metadata string to string mapping.
>
>      Assume no ':' in key and no '\0' in both key and value."""
> @@ -237,11 +237,11 @@ class obsstore(object):
>      Markers can be accessed with two mappings:
>      - precursors[x] -> set(markers on precursors edges of x)
>      - successors[x] -> set(markers on successors edges of x)
>      """
>
> -    fields = ('prec', 'succs', 'flag', 'meta', 'date')
> +    fields = ('prec', 'succs', 'flag', 'meta', 'date', 'parents')

Now that there's a magic value for one of these fields, it's past time to
add a comment documenting what you expect in each field. Here's my guess:

prec: precursor nodes. List[nodeid]. Always present.
succs: successor nodes. List[nodeid]. Always present.
flag: ?
meta: ?
date: When the marker was created. Always present. Stored as seconds since the epoch.
parents: Parent(s) of precursor node(s). None if not recorded, otherwise a List[nodeid].

(I'm sure I could figure out what flag and meta are for again, but I'd
rather see this documented before I have to reverse engineer it.)

>
>      def __init__(self, sopener):
>          # caches for various obsolescence related cache
>          self.caches = {}
>          self._all = []
> @@ -290,11 +290,11 @@ class obsstore(object):
>              if len(succ) != 20:
>                  raise ValueError(succ)
>          if prec in succs:
>              raise ValueError(_('in-marker cycle with %s') % node.hex(prec))
>          marker = (str(prec), tuple(succs), int(flag), encodemeta(metadata),
> -                  date)
> +                  date, None)
>          return bool(self.add(transaction, [marker]))
>
>      def add(self, transaction, markers):
>          """Add new markers to the store
>
> @@ -354,11 +354,11 @@ def _encodemarkers(markers, addheader=Fa
>      for marker in markers:
>          yield _encodeonemarker(marker)
>
>
>  def _encodeonemarker(marker):
> -    pre, sucs, flags, metadata, date = marker
> +    pre, sucs, flags, metadata, date, parents = marker
>      metadata = decodemeta(metadata)
>      metadata['date'] = '%d %i' % date
>      metadata = encodemeta(metadata)
>      nbsuc = len(sucs)
>      format = _fmfixed + (_fmnode * nbsuc)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -168,11 +168,11 @@  def _readmarkers(data):
                                'short, %d bytes expected, got %d')
                              % (mdsize, len(metadata)))
         off += mdsize
         date = util.parsedate(decodemeta(metadata).pop('date', '0 0'))
 
-        yield (pre, sucs, flags, metadata, date)
+        yield (pre, sucs, flags, metadata, date, None)
 
 def encodemeta(meta):
     """Return encoded metadata string to string mapping.
 
     Assume no ':' in key and no '\0' in both key and value."""
@@ -237,11 +237,11 @@  class obsstore(object):
     Markers can be accessed with two mappings:
     - precursors[x] -> set(markers on precursors edges of x)
     - successors[x] -> set(markers on successors edges of x)
     """
 
-    fields = ('prec', 'succs', 'flag', 'meta', 'date')
+    fields = ('prec', 'succs', 'flag', 'meta', 'date', 'parents')
 
     def __init__(self, sopener):
         # caches for various obsolescence related cache
         self.caches = {}
         self._all = []
@@ -290,11 +290,11 @@  class obsstore(object):
             if len(succ) != 20:
                 raise ValueError(succ)
         if prec in succs:
             raise ValueError(_('in-marker cycle with %s') % node.hex(prec))
         marker = (str(prec), tuple(succs), int(flag), encodemeta(metadata),
-                  date)
+                  date, None)
         return bool(self.add(transaction, [marker]))
 
     def add(self, transaction, markers):
         """Add new markers to the store
 
@@ -354,11 +354,11 @@  def _encodemarkers(markers, addheader=Fa
     for marker in markers:
         yield _encodeonemarker(marker)
 
 
 def _encodeonemarker(marker):
-    pre, sucs, flags, metadata, date = marker
+    pre, sucs, flags, metadata, date, parents = marker
     metadata = decodemeta(metadata)
     metadata['date'] = '%d %i' % date
     metadata = encodemeta(metadata)
     nbsuc = len(sucs)
     format = _fmfixed + (_fmnode * nbsuc)