Patchwork [09,of,22] obsstore: move header encoding to a separate function

login
register
mail settings
Submitter Jun Wu
Date June 4, 2017, 11:59 p.m.
Message ID <5b83ced66577dc862594.1496620761@x1c>
Download mbox | patch
Permalink /patch/21187/
State Accepted
Headers show

Comments

Jun Wu - June 4, 2017, 11:59 p.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1496561891 25200
#      Sun Jun 04 00:38:11 2017 -0700
# Node ID 5b83ced66577dc862594f85bcef2726a0d3fcfaf
# Parent  e42031df2e3a0a3805c13ade577a083117d745aa
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 5b83ced66577
obsstore: move header encoding to a separate function

This patch moves encodeheader from encodemarkers. So markers and header
could be encoded separately.
Gregory Szorc - June 6, 2017, 6:09 a.m.
On Sun, Jun 4, 2017 at 4:59 PM, Jun Wu <quark@fb.com> wrote:

> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1496561891 25200
> #      Sun Jun 04 00:38:11 2017 -0700
> # Node ID 5b83ced66577dc862594f85bcef2726a0d3fcfaf
> # Parent  e42031df2e3a0a3805c13ade577a083117d745aa
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r
> 5b83ced66577
> obsstore: move header encoding to a separate function
>

Queued this one.


>
> This patch moves encodeheader from encodemarkers. So markers and header
> could be encoded separately.
>
> diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
> --- a/mercurial/obsolete.py
> +++ b/mercurial/obsolete.py
> @@ -453,4 +453,7 @@ def _readmarkers(data):
>      return diskversion, formats[diskversion][0](data, off)
>
> +def encodeheader(version=_fm0version):
> +    return _pack('>B', version)
> +
>  def encodemarkers(markers, addheader=False, version=_fm0version):
>      # Kept separate from flushmarkers(), it will be reused for
> @@ -458,5 +461,5 @@ def encodemarkers(markers, addheader=Fal
>      encodeone = formats[version][1]
>      if addheader:
> -        yield _pack('>B', version)
> +        yield encodeheader(version)
>      for marker in markers:
>          yield encodeone(marker)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>
Yuya Nishihara - June 6, 2017, 12:51 p.m.
On Sun, 4 Jun 2017 16:59:21 -0700, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1496561891 25200
> #      Sun Jun 04 00:38:11 2017 -0700
> # Node ID 5b83ced66577dc862594f85bcef2726a0d3fcfaf
> # Parent  e42031df2e3a0a3805c13ade577a083117d745aa
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 5b83ced66577
> obsstore: move header encoding to a separate function
> 
> This patch moves encodeheader from encodemarkers. So markers and header
> could be encoded separately.
> 
> diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
> --- a/mercurial/obsolete.py
> +++ b/mercurial/obsolete.py
> @@ -453,4 +453,7 @@ def _readmarkers(data):
>      return diskversion, formats[diskversion][0](data, off)
>  
> +def encodeheader(version=_fm0version):
> +    return _pack('>B', version)

Nit: this default value seems useless since the caller should know which
version it is processing.

Patch

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -453,4 +453,7 @@  def _readmarkers(data):
     return diskversion, formats[diskversion][0](data, off)
 
+def encodeheader(version=_fm0version):
+    return _pack('>B', version)
+
 def encodemarkers(markers, addheader=False, version=_fm0version):
     # Kept separate from flushmarkers(), it will be reused for
@@ -458,5 +461,5 @@  def encodemarkers(markers, addheader=Fal
     encodeone = formats[version][1]
     if addheader:
-        yield _pack('>B', version)
+        yield encodeheader(version)
     for marker in markers:
         yield encodeone(marker)