[PATCH RFC] highlight: add highlightfiles config option, which takes a fileset (issue3005)

Matt Mackall mpm at selenic.com
Thu Sep 17 19:47:03 CDT 2015


On Thu, 2015-09-17 at 22:28 +0900, Yuya Nishihara wrote:
> On Wed, 16 Sep 2015 22:36:57 +0800, Anton Shestakov wrote:
> > # HG changeset patch
> > # User Anton Shestakov <av6 at dwimlabs.net>
> > # Date 1442413836 -28800
> > #      Wed Sep 16 22:30:36 2015 +0800
> > # Node ID ee1b85c5616ece49f53095adfe85e90c3efeb48b
> > # Parent  7df5d476087392e217699a41c11fbe8cd48713b2
> > highlight: add highlightfiles config option, which takes a fileset (issue3005)
> > 
> > Highlight extension lacked a way to limit files by size, by extension, and/or
> > by any other part of file path. A good solution would be to use a fileset,
> > since it can check file path, extension and size (and more) in one expression.
> > So this change introduces such an option, highlighfiles, which takes a fileset
> > and on each request decides if the requested file should be highlighted.
> > 
> > The default "size('<5M')" is, in a way, suggested in issue3005.
> > 
> > checkfctx() limits the amount of work to just one file (subset kwarg in
> > fileset.matchctx()).
> > 
> > Monkey-patching works around issue4568, otherwise using filesets here while
> > running hgweb in directory mode would say, for example, "Abort: **.py not under
> > root", but this fix is very local and probably far from ideal. I suspect there
> > to be a way to fix this for the whole hgweb and resolve the issue, but I don't
> > know how to do it.
> 
> > +def checkfctx(fctx, expr):
> > +    ctx = fctx.changectx()
> > +    tree = fileset.parse(expr)
> > +    mctx = fileset.matchctx(ctx, subset=[fctx.path()], status=None)
> > +    repo = ctx.repo()
> > +    # To allow matching file names in the fileset in hgweb directory mode.
> > +    # See issue4568.
> > +    object.__setattr__(repo, 'getcwd', lambda: repo.root)
> 
> It monkey-patches a repo object which lives long in the current thread. So
> once you've visited a highlighted page, repo.getcwd() is faked after that.
> I'm not sure if it can cause a real problem, but it smells bad.

It does indeed. On the other hand, hgweb should probably be doing
something like this itself because we never want the matcher to care
about what directory the webserver is running in.

-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial-devel mailing list