templater: move stylemap() to hgweb_mod, since that's its only user
authorMartin von Zweigbergk <martinvonz@google.com>
Tue, 04 Aug 2020 09:13:10 -0700
changeset 45328 ba50c8a95e2b
parent 45327 9a5c4875a88c
child 45329 dc10bcd5c08d
templater: move stylemap() to hgweb_mod, since that's its only user `stylemap()` even has an error message that mentions "hgweb templates", so it seems that it's meant specifically for hgweb. Differential Revision: https://phab.mercurial-scm.org/D8890
mercurial/hgweb/hgweb_mod.py
mercurial/templater.py
--- a/mercurial/hgweb/hgweb_mod.py	Mon Aug 03 22:15:45 2020 -0700
+++ b/mercurial/hgweb/hgweb_mod.py	Tue Aug 04 09:13:10 2020 -0700
@@ -53,7 +53,41 @@
         configfn(b'web', b'style'),
         b'paper',
     )
-    return styles, templater.stylemap(styles, templatepath)
+    return styles, _stylemap(styles, templatepath)
+
+
+def _stylemap(styles, path=None):
+    """Return path to mapfile for a given style.
+
+    Searches mapfile in the following locations:
+    1. templatepath/style/map
+    2. templatepath/map-style
+    3. templatepath/map
+    """
+
+    if path is None:
+        path = templater.templatedir()
+
+    if path is not None:
+        for style in styles:
+            # only plain name is allowed to honor template paths
+            if (
+                not style
+                or style in (pycompat.oscurdir, pycompat.ospardir)
+                or pycompat.ossep in style
+                or pycompat.osaltsep
+                and pycompat.osaltsep in style
+            ):
+                continue
+            locations = [os.path.join(style, b'map'), b'map-' + style]
+            locations.append(b'map')
+
+            for location in locations:
+                mapfile = os.path.join(path, location)
+                if os.path.isfile(mapfile):
+                    return style, mapfile
+
+    raise RuntimeError(b"No hgweb templates found in %r" % path)
 
 
 def makebreadcrumb(url, prefix=b''):
--- a/mercurial/templater.py	Mon Aug 03 22:15:45 2020 -0700
+++ b/mercurial/templater.py	Tue Aug 04 09:13:10 2020 -0700
@@ -1075,37 +1075,3 @@
     if f and os.path.isfile(f):
         return f
     return None
-
-
-def stylemap(styles, path=None):
-    """Return path to mapfile for a given style.
-
-    Searches mapfile in the following locations:
-    1. templatepath/style/map
-    2. templatepath/map-style
-    3. templatepath/map
-    """
-
-    if path is None:
-        path = templatedir()
-
-    if path is not None:
-        for style in styles:
-            # only plain name is allowed to honor template paths
-            if (
-                not style
-                or style in (pycompat.oscurdir, pycompat.ospardir)
-                or pycompat.ossep in style
-                or pycompat.osaltsep
-                and pycompat.osaltsep in style
-            ):
-                continue
-            locations = [os.path.join(style, b'map'), b'map-' + style]
-            locations.append(b'map')
-
-            for location in locations:
-                mapfile = os.path.join(path, location)
-                if os.path.isfile(mapfile):
-                    return style, mapfile
-
-    raise RuntimeError(b"No hgweb templates found in %r" % path)