Patchwork [4,of,5,postargs] httppeer: compute header names only once

login
register
mail settings
Submitter Augie Fackler
Date March 11, 2016, 4:55 p.m.
Message ID <efcc8e438753cddf5af2.1457715315@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/13796/
State Accepted
Delegated to: Martin von Zweigbergk
Headers show

Comments

Augie Fackler - March 11, 2016, 4:55 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1457715082 18000
#      Fri Mar 11 11:51:22 2016 -0500
# Node ID efcc8e438753cddf5af209ae812f77c2affead07
# Parent  5355f92bff4a5527d7fdde189bc6d6a0c720095f
# EXP-Topic batch
httppeer: compute header names only once

This also helps make the code a little more readable.
Martin von Zweigbergk - March 11, 2016, 5:53 p.m.
For now, I've pushed up to here to the clowncopter, thanks.

On Fri, Mar 11, 2016 at 8:55 AM, Augie Fackler <raf@durin42.com> wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1457715082 18000
> #      Fri Mar 11 11:51:22 2016 -0500
> # Node ID efcc8e438753cddf5af209ae812f77c2affead07
> # Parent  5355f92bff4a5527d7fdde189bc6d6a0c720095f
> # EXP-Topic batch
> httppeer: compute header names only once
>
> This also helps make the code a little more readable.
>
> diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
> --- a/mercurial/httppeer.py
> +++ b/mercurial/httppeer.py
> @@ -108,12 +108,12 @@ class httppeer(wireproto.wirepeer):
>                  headerfmt = 'X-HgArg-%s'
>                  contentlen = headersize - len(headerfmt % '000' + ': \r\n')
>                  headernum = 0
> +                varyheaders = []
>                  for i in xrange(0, len(encargs), contentlen):
>                      headernum += 1
>                      header = headerfmt % str(headernum)
>                      headers[header] = encargs[i:i + contentlen]
> -                varyheaders = [
> -                    headerfmt % str(h) for h in range(1, headernum + 1)]
> +                    varyheaders.append(header)
>                  headers['Vary'] = ','.join(varyheaders)
>              else:
>                  q += sorted(args.items())
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py
--- a/mercurial/httppeer.py
+++ b/mercurial/httppeer.py
@@ -108,12 +108,12 @@  class httppeer(wireproto.wirepeer):
                 headerfmt = 'X-HgArg-%s'
                 contentlen = headersize - len(headerfmt % '000' + ': \r\n')
                 headernum = 0
+                varyheaders = []
                 for i in xrange(0, len(encargs), contentlen):
                     headernum += 1
                     header = headerfmt % str(headernum)
                     headers[header] = encargs[i:i + contentlen]
-                varyheaders = [
-                    headerfmt % str(h) for h in range(1, headernum + 1)]
+                    varyheaders.append(header)
                 headers['Vary'] = ','.join(varyheaders)
             else:
                 q += sorted(args.items())