martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  We had two callers of `templatepath()` that did the same test for both
  "map-cmdline.<name>" and "<name>", so let's move that into
  `templatepath()` so we can reuse it. It should be harmless for the `hg
  debuginstall` (it just means an extra file-system check in the case of
  broken installs).

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8809

AFFECTED FILES
  mercurial/debugcommands.py
  mercurial/formatter.py
  mercurial/logcmdutil.py
  mercurial/templater.py

CHANGE DETAILS

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -1064,9 +1064,10 @@
 
 def templatepath(name):
     '''return location of template file. returns None if not found.'''
-    f = os.path.join(templatedir(), name)
-    if f and os.path.isfile(f):
-        return f
+    for filename in (b'map-cmdline.' + name, name):
+        f = os.path.join(templatedir(), filename)
+        if f and os.path.isfile(f):
+            return f
     return None
 
 
diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -628,9 +628,7 @@
     if not tmpl and style:
         mapfile = style
         if not os.path.split(mapfile)[0]:
-            mapname = templater.templatepath(
-                b'map-cmdline.' + mapfile
-            ) or templater.templatepath(mapfile)
+            mapname = templater.templatepath(mapfile)
             if mapname:
                 mapfile = mapname
         return templatespec(None, mapfile)
diff --git a/mercurial/formatter.py b/mercurial/formatter.py
--- a/mercurial/formatter.py
+++ b/mercurial/formatter.py
@@ -581,9 +581,7 @@
 
     # perhaps a stock style?
     if not os.path.split(tmpl)[0]:
-        mapname = templater.templatepath(
-            b'map-cmdline.' + tmpl
-        ) or templater.templatepath(tmpl)
+        mapname = templater.templatepath(tmpl)
         if mapname:
             return templatespec(topic, None, mapname)
 
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -1672,7 +1672,7 @@
     fm.write(b'templatedirs', b'checking templates (%s)...\n', p)
     fm.condwrite(not p, b'', _(b" no template directories found\n"))
     if p:
-        m = templater.templatepath(b"map-cmdline.default")
+        m = templater.templatepath(b"default")
         if m:
             # template found, check if it is working
             err = None



To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to