changeset 24987:fd7287f0b43c

templater: remove noop calls of parsestring(s, quoted=False) (API) Since db7463aa080f, parsestring(s, quoted=False) just returns s.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 04 May 2015 10:01:03 +0900
parents fb9b7b937b3e
children e8ff0b09acac
files hgext/bugzilla.py hgext/churn.py hgext/hgcia.py hgext/keyword.py hgext/notify.py mercurial/cmdutil.py mercurial/filemerge.py mercurial/templater.py
diffstat 8 files changed, 27 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/bugzilla.py	Tue Apr 14 12:45:15 2015 -0700
+++ b/hgext/bugzilla.py	Mon May 04 10:01:03 2015 +0900
@@ -279,7 +279,7 @@
 
 from mercurial.i18n import _
 from mercurial.node import short
-from mercurial import cmdutil, mail, templater, util
+from mercurial import cmdutil, mail, util
 import re, time, urlparse, xmlrpclib
 
 testedwith = 'internal'
@@ -876,8 +876,6 @@
         if not mapfile and not tmpl:
             tmpl = _('changeset {node|short} in repo {root} refers '
                      'to bug {bug}.\ndetails:\n\t{desc|tabindent}')
-        if tmpl:
-            tmpl = templater.parsestring(tmpl, quoted=False)
         t = cmdutil.changeset_templater(self.ui, self.repo,
                                         False, None, tmpl, mapfile, False)
         self.ui.pushbuffer()
--- a/hgext/churn.py	Tue Apr 14 12:45:15 2015 -0700
+++ b/hgext/churn.py	Mon May 04 10:01:03 2015 +0900
@@ -9,7 +9,7 @@
 '''command to display statistics about repository history'''
 
 from mercurial.i18n import _
-from mercurial import patch, cmdutil, scmutil, util, templater, commands
+from mercurial import patch, cmdutil, scmutil, util, commands
 from mercurial import encoding
 import os
 import time, datetime
@@ -19,7 +19,6 @@
 testedwith = 'internal'
 
 def maketemplater(ui, repo, tmpl):
-    tmpl = templater.parsestring(tmpl, quoted=False)
     try:
         t = cmdutil.changeset_templater(ui, repo, False, None, tmpl,
                                         None, False)
--- a/hgext/hgcia.py	Tue Apr 14 12:45:15 2015 -0700
+++ b/hgext/hgcia.py	Mon May 04 10:01:03 2015 +0900
@@ -43,7 +43,7 @@
 
 from mercurial.i18n import _
 from mercurial.node import bin, short
-from mercurial import cmdutil, patch, templater, util, mail
+from mercurial import cmdutil, patch, util, mail
 import email.Parser
 
 import socket, xmlrpclib
@@ -206,7 +206,6 @@
                 template = self.dstemplate
             else:
                 template = self.deftemplate
-        template = templater.parsestring(template, quoted=False)
         t = cmdutil.changeset_templater(self.ui, self.repo, False, None,
                                         template, style, False)
         self.templater = t
--- a/hgext/keyword.py	Tue Apr 14 12:45:15 2015 -0700
+++ b/hgext/keyword.py	Mon May 04 10:01:03 2015 +0900
@@ -83,7 +83,7 @@
 '''
 
 from mercurial import commands, context, cmdutil, dispatch, filelog, extensions
-from mercurial import localrepo, match, patch, templatefilters, templater, util
+from mercurial import localrepo, match, patch, templatefilters, util
 from mercurial import scmutil, pathutil
 from mercurial.hgweb import webcommands
 from mercurial.i18n import _
@@ -191,8 +191,7 @@
 
         kwmaps = self.ui.configitems('keywordmaps')
         if kwmaps: # override default templates
-            self.templates = dict((k, templater.parsestring(v, False))
-                                  for k, v in kwmaps)
+            self.templates = dict(kwmaps)
         else:
             self.templates = _defaultkwmaps(self.ui)
 
--- a/hgext/notify.py	Tue Apr 14 12:45:15 2015 -0700
+++ b/hgext/notify.py	Mon May 04 10:01:03 2015 +0900
@@ -138,7 +138,7 @@
 # load. This was not a problem on Python 2.7.
 import email.Parser
 from mercurial.i18n import _
-from mercurial import patch, cmdutil, templater, util, mail
+from mercurial import patch, cmdutil, util, mail
 import fnmatch
 
 testedwith = 'internal'
@@ -190,8 +190,6 @@
                     self.ui.config('notify', 'template'))
         if not mapfile and not template:
             template = deftemplates.get(hooktype) or single_template
-        if template:
-            template = templater.parsestring(template, quoted=False)
         self.t = cmdutil.changeset_templater(self.ui, self.repo, False, None,
                                              template, mapfile, False)
 
--- a/mercurial/cmdutil.py	Tue Apr 14 12:45:15 2015 -0700
+++ b/mercurial/cmdutil.py	Mon May 04 10:01:03 2015 +0900
@@ -1445,7 +1445,7 @@
             try:
                 tmpl = templater.parsestring(tmpl)
             except SyntaxError:
-                tmpl = templater.parsestring(tmpl, quoted=False)
+                pass
             return tmpl, None
         else:
             style = util.expandpath(ui.config('ui', 'style', ''))
@@ -1479,7 +1479,7 @@
         try:
             tmpl = templater.parsestring(t)
         except SyntaxError:
-            tmpl = templater.parsestring(t, quoted=False)
+            tmpl = t
         return tmpl, None
 
     if tmpl == 'list':
--- a/mercurial/filemerge.py	Tue Apr 14 12:45:15 2015 -0700
+++ b/mercurial/filemerge.py	Mon May 04 10:01:03 2015 +0900
@@ -354,7 +354,6 @@
 
     ui = repo.ui
     template = ui.config('ui', 'mergemarkertemplate', _defaultconflictmarker)
-    template = templater.parsestring(template, quoted=False)
     tmpl = templater.templater(None, cache={'conflictmarker': template})
 
     pad = max(len(l) for l in labels)
--- a/mercurial/templater.py	Tue Apr 14 12:45:15 2015 -0700
+++ b/mercurial/templater.py	Mon May 04 10:01:03 2015 +0900
@@ -618,28 +618,25 @@
                 for j in _flatten(i):
                     yield j
 
-def parsestring(s, quoted=True):
-    '''unwrap quotes if quoted is True'''
-    if quoted:
-        if len(s) < 2 or s[0] != s[-1]:
-            raise SyntaxError(_('unmatched quotes'))
-        # de-backslash-ify only <\">. it is invalid syntax in non-string part of
-        # template, but we are likely to escape <"> in quoted string and it was
-        # accepted before, thanks to issue4290. <\\"> is unmodified because it
-        # is ambiguous and it was processed as such before 2.8.1.
-        #
-        #  template  result
-        #  --------- ------------------------
-        #  {\"\"}    parse error
-        #  "{""}"    {""} -> <>
-        #  "{\"\"}"  {""} -> <>
-        #  {"\""}    {"\""} -> <">
-        #  '{"\""}'  {"\""} -> <">
-        #  "{"\""}"  parse error (don't care)
-        q = s[0]
-        return s[1:-1].replace('\\\\' + q, '\\\\\\' + q).replace('\\' + q, q)
-
-    return s
+def parsestring(s):
+    '''unwrap quotes'''
+    if len(s) < 2 or s[0] != s[-1]:
+        raise SyntaxError(_('unmatched quotes'))
+    # de-backslash-ify only <\">. it is invalid syntax in non-string part of
+    # template, but we are likely to escape <"> in quoted string and it was
+    # accepted before, thanks to issue4290. <\\"> is unmodified because it
+    # is ambiguous and it was processed as such before 2.8.1.
+    #
+    #  template  result
+    #  --------- ------------------------
+    #  {\"\"}    parse error
+    #  "{""}"    {""} -> <>
+    #  "{\"\"}"  {""} -> <>
+    #  {"\""}    {"\""} -> <">
+    #  '{"\""}'  {"\""} -> <">
+    #  "{"\""}"  parse error (don't care)
+    q = s[0]
+    return s[1:-1].replace('\\\\' + q, '\\\\\\' + q).replace('\\' + q, q)
 
 class engine(object):
     '''template expansion engine.