Patchwork [03,of,10] py3: fix join(), min(), and max() template functions over string

login
register
mail settings
Submitter Yuya Nishihara
Date March 2, 2018, 12:26 a.m.
Message ID <7f0a461c110f7d953dda.1519950382@mimosa>
Download mbox | patch
Permalink /patch/28627/
State Accepted
Headers show

Comments

Yuya Nishihara - March 2, 2018, 12:26 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1519940544 18000
#      Thu Mar 01 16:42:24 2018 -0500
# Node ID 7f0a461c110f7d953dda945dfe9c0912865f8e91
# Parent  d44f1bec9f60ebec416be5a7cd44aa386e04da64
py3: fix join(), min(), and max() template functions over string

It's silly to split a string into characters and concatenate them, but that
should work and test-command-template.t has one. min() and max() had the
same issue on Python 3, so fixed too.

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -908,7 +908,7 @@  def join(context, mapping, args):
         joiner = evalstring(context, mapping, args[1])
 
     first = True
-    for x in joinset:
+    for x in pycompat.maybebytestr(joinset):
         if first:
             first = False
         else:
@@ -991,7 +991,7 @@  def max_(context, mapping, args, **kwarg
 
     iterable = evalfuncarg(context, mapping, args[0])
     try:
-        x = max(iterable)
+        x = max(pycompat.maybebytestr(iterable))
     except (TypeError, ValueError):
         # i18n: "max" is a keyword
         raise error.ParseError(_("max first argument should be an iterable"))
@@ -1006,7 +1006,7 @@  def min_(context, mapping, args, **kwarg
 
     iterable = evalfuncarg(context, mapping, args[0])
     try:
-        x = min(iterable)
+        x = min(pycompat.maybebytestr(iterable))
     except (TypeError, ValueError):
         # i18n: "min" is a keyword
         raise error.ParseError(_("min first argument should be an iterable"))