templater: try to read %include in mapfiles from resources
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 30 Jul 2020 21:36:29 -0700
changeset 45334 fef64d7a4a84
parent 45333 d9a502a0a9ca
child 45335 d12fba074cc6
templater: try to read %include in mapfiles from resources The "show" style is an example of a style that uses an "%include" statement in its definition. This patch makes `hg log --style show` work. This takes the number of failing tests with PyOxidizer from 72 to 62. Differential Revision: https://phab.mercurial-scm.org/D8896
mercurial/templater.py
--- a/mercurial/templater.py	Thu Jul 30 15:29:06 2020 -0700
+++ b/mercurial/templater.py	Thu Jul 30 21:36:29 2020 -0700
@@ -835,11 +835,17 @@
             if os.path.isfile(abs):
                 subresource = util.posixfile(abs, b'rb')
         if not subresource:
-            dir = templatedir()
-            if dir:
-                abs = os.path.normpath(os.path.join(dir, rel))
-                if os.path.isfile(abs):
-                    subresource = util.posixfile(abs, b'rb')
+            if pycompat.ossep not in rel:
+                abs = rel
+                subresource = resourceutil.open_resource(
+                    b'mercurial.templates', rel
+                )
+            else:
+                dir = templatedir()
+                if dir:
+                    abs = os.path.normpath(os.path.join(dir, rel))
+                    if os.path.isfile(abs):
+                        subresource = util.posixfile(abs, b'rb')
         if subresource:
             data = subresource.read()
             conf.parse(