Patchwork [1,of,4,V2] obsolete: gather all contents related to format version 0 in a single place

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 30, 2014, 6:01 p.m.
Message ID <10778745265788c0a40c.1412100082@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6038/
State Accepted
Headers show

Comments

Pierre-Yves David - Sept. 30, 2014, 6:01 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1410525703 -7200
#      Fri Sep 12 14:41:43 2014 +0200
# Node ID 10778745265788c0a40cb9feef97bfb952bd5031
# Parent  4109cc16279ef0e04dc70e7f4c9ab7415e6a22d3
obsolete: gather all contents related to format version 0 in a single place


All contents includes documentation, constants, and functions, so we
gather all of those things into a single location. The diff is confusing
because it cannot understand what code is semantically moved around in this
grand migration.

Patch

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -61,29 +61,12 @@  Markers are stored in an append-only fil
 
 The file starts with a version header:
 
 - 1 unsigned byte: version number, starting at zero.
 
-
-The header is followed by the markers. Each marker is made of:
-
-- 1 unsigned byte: number of new changesets "N", can be zero.
-
-- 1 unsigned 32-bits integer: metadata size "M" in bytes.
-
-- 1 byte: a bit field. It is reserved for flags used in common
-  obsolete marker operations, to avoid repeated decoding of metadata
-  entries.
-
-- 20 bytes: obsoleted changeset identifier.
-
-- N*20 bytes: new changesets identifiers.
-
-- M bytes: metadata as a sequence of nul-terminated strings. Each
-  string contains a key and a value, separated by a colon ':', without
-  additional encoding. Keys cannot contain '\0' or ':' and values
-  cannot contain '\0'.
+The header is followed by the markers. Marker format depend of the version. See
+comment associated with each format for details.
 
 """
 import struct
 import util, base85, node
 import phases
@@ -96,17 +79,10 @@  from i18n import _
 
 # the obsolete feature is not mature enough to be enabled by default.
 # you have to rely on third party extension extension to enable this.
 _enabled = False
 
-# data used for parsing and writing
-_fm0version = 0
-_fm0fixed   = '>BIB20s'
-_fm0node = '20s'
-_fm0fsize = struct.calcsize(_fm0fixed)
-_fm0fnodesize = struct.calcsize(_fm0node)
-
 ### obsolescence marker flag
 
 ## bumpedfix flag
 #
 # When a changeset A' succeed to a changeset A which became public, we call A'
@@ -135,28 +111,35 @@  from i18n import _
 # This flag mean that the successors express the changes between the public and
 # bumped version and fix the situation, breaking the transitivity of
 # "bumped" here.
 bumpedfix = 1
 
-def _readmarkers(data):
-    """Read and enumerate markers from raw data"""
-    off = 0
-    diskversion = _unpack('>B', data[off:off + 1])[0]
-    off += 1
-    if diskversion not in formats:
-        raise util.Abort(_('parsing obsolete marker: unknown version %r')
-                         % diskversion)
-    return diskversion, formats[diskversion][0](data, off)
-
-def encodemarkers(markers, addheader=False, version=_fm0version):
-    # Kept separate from flushmarkers(), it will be reused for
-    # markers exchange.
-    encodeone = formats[version][1]
-    if addheader:
-        yield _pack('>B', _fm0version)
-    for marker in markers:
-        yield encodeone(marker)
+## Parsing and writing of version "0"
+#
+# The header is followed by the markers. Each marker is made of:
+#
+# - 1 unsigned byte: number of new changesets "N", can be zero.
+#
+# - 1 unsigned 32-bits integer: metadata size "M" in bytes.
+#
+# - 1 byte: a bit field. It is reserved for flags used in common
+#   obsolete marker operations, to avoid repeated decoding of metadata
+#   entries.
+#
+# - 20 bytes: obsoleted changeset identifier.
+#
+# - N*20 bytes: new changesets identifiers.
+#
+# - M bytes: metadata as a sequence of nul-terminated strings. Each
+#   string contains a key and a value, separated by a colon ':', without
+#   additional encoding. Keys cannot contain '\0' or ':' and values
+#   cannot contain '\0'.
+_fm0version = 0
+_fm0fixed   = '>BIB20s'
+_fm0node = '20s'
+_fm0fsize = struct.calcsize(_fm0fixed)
+_fm0fnodesize = struct.calcsize(_fm0node)
 
 def _fm0readmarkers(data, off=0):
     # Loop on markers
     l = len(data)
     while off + _fm0fsize <= l:
@@ -227,10 +210,30 @@  def _fm0encodeonemarker(marker):
 
 # mapping to read/write various marker formats
 # <version> -> (decoder, encoder)
 formats = {0: (_fm0readmarkers, _fm0encodeonemarker)}
 
+def _readmarkers(data):
+    """Read and enumerate markers from raw data"""
+    off = 0
+    diskversion = _unpack('>B', data[off:off + 1])[0]
+    off += 1
+    if diskversion not in formats:
+        raise util.Abort(_('parsing obsolete marker: unknown version %r')
+                         % diskversion)
+    return diskversion, formats[diskversion][0](data, off)
+
+def encodemarkers(markers, addheader=False, version=_fm0version):
+    # Kept separate from flushmarkers(), it will be reused for
+    # markers exchange.
+    encodeone = formats[version][1]
+    if addheader:
+        yield _pack('>B', _fm0version)
+    for marker in markers:
+        yield encodeone(marker)
+
+
 def encodemeta(meta):
     """Return encoded metadata string to string mapping.
 
     Assume no ':' in key and no '\0' in both key and value."""
     for key, value in meta.iteritems():