Patchwork templatekw: change joinfmt to a mandatory argument of _hybrid object

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 2, 2016, 1:02 p.m.
Message ID <b44d35446ec01aef03fa.1470142964@mimosa>
Download mbox | patch
Permalink /patch/16033/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 2, 2016, 1:02 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1469246923 -32400
#      Sat Jul 23 13:08:43 2016 +0900
# Node ID b44d35446ec01aef03fa978fe1bae6c568d1e327
# Parent  76f8aecf37ee6a7508a84394b0eb427df9806cd4
templatekw: change joinfmt to a mandatory argument of _hybrid object

We've fixed several bugs caused by the misuse of the default joinfmt. Make
it more explicit to prevent future bugs.

dict.values()[0] is replaced by dict[element] as showlist() knows what the
key is.
Pierre-Yves David - Aug. 2, 2016, 2:44 p.m.
On 08/02/2016 03:02 PM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1469246923 -32400
> #      Sat Jul 23 13:08:43 2016 +0900
> # Node ID b44d35446ec01aef03fa978fe1bae6c568d1e327
> # Parent  76f8aecf37ee6a7508a84394b0eb427df9806cd4
> templatekw: change joinfmt to a mandatory argument of _hybrid object

pushed, thanks

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -26,14 +26,11 @@  from . import (
 #  "{get(extras, key)}"
 
 class _hybrid(object):
-    def __init__(self, gen, values, makemap, joinfmt=None):
+    def __init__(self, gen, values, makemap, joinfmt):
         self.gen = gen
         self.values = values
         self._makemap = makemap
-        if joinfmt:
-            self.joinfmt = joinfmt
-        else:
-            self.joinfmt = lambda x: x.values()[0]
+        self.joinfmt = joinfmt
     def __iter__(self):
         return self.gen
     def itermaps(self):
@@ -53,7 +50,7 @@  def showlist(name, values, plural=None, 
     if not element:
         element = name
     f = _showlist(name, values, plural, separator, **args)
-    return _hybrid(f, values, lambda x: {element: x})
+    return _hybrid(f, values, lambda x: {element: x}, lambda d: d[element])
 
 def _showlist(name, values, plural=None, separator=' ', **args):
     '''expand set of values.