Patchwork [5,of,9] highlight: use matcher API to test if file should be pygmentized

login
register
mail settings
Submitter Yuya Nishihara
Date July 10, 2018, 3:07 p.m.
Message ID <8106467635e240a6af6d.1531235263@mimosa>
Download mbox | patch
Permalink /patch/32763/
State Accepted
Headers show

Comments

Yuya Nishihara - July 10, 2018, 3:07 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1531234188 -32400
#      Tue Jul 10 23:49:48 2018 +0900
# Node ID 8106467635e240a6af6d27b4848385af2218bb93
# Parent  5a3ee7bdeca33fc599967aab894f5219eb6ecaa4
highlight: use matcher API to test if file should be pygmentized

Prepares for the upcoming API change. We'll no longer have to call the
fileset function directly since the cost of the matcher-based fileset will
become O(number of tests) from O(number of files in subset).

Patch

diff --git a/hgext/highlight/__init__.py b/hgext/highlight/__init__.py
--- a/hgext/highlight/__init__.py
+++ b/hgext/highlight/__init__.py
@@ -36,7 +36,6 @@  from mercurial.hgweb import (
 
 from mercurial import (
     extensions,
-    fileset,
 )
 
 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
@@ -51,9 +50,8 @@  def pygmentize(web, field, fctx, tmpl):
     filenameonly = web.configbool('web', 'highlightonlymatchfilename', False)
 
     ctx = fctx.changectx()
-    tree = fileset.parse(expr)
-    mctx = fileset.matchctx(ctx, subset=[fctx.path()], status=None)
-    if fctx.path() in fileset.getset(mctx, tree):
+    m = ctx.matchfileset(expr)
+    if m(fctx.path()):
         highlight.pygmentize(field, fctx, style, tmpl,
                 guessfilenameonly=filenameonly)