Patchwork D8890: templater: move stylemap() to hgweb_mod, since that's its only user

login
register
mail settings
Submitter phabricator
Date Aug. 5, 2020, 4:26 p.m.
Message ID <differential-rev-PHID-DREV-674eolf3hnvwzb6vgvki-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46989/
State Superseded
Headers show

Comments

phabricator - Aug. 5, 2020, 4:26 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  `stylemap()` even has an error message that mentions "hgweb
  templates", so it seems that it's meant specifically for hgweb.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/hgweb/hgweb_mod.py
  mercurial/templater.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -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)
diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -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''):