hgignore中的怪异的负面前瞻性处理 [英] Weird negative lookahead handling in hgignore

查看:98
本文介绍了hgignore中的怪异的负面前瞻性处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在巨大的源代码树中,我希望Mercurial仅跟踪一个子文件夹.

Out of a huge source tree, i want just one subfolder be tracked by Mercurial.

specific/component/subfolder

在任何体面的正则表达式工具(Regex Coach,regexpal.com)中,以下内容绝对足够(并且可以理解)

In any decent regex tool (Regex Coach, regexpal.com), the following is absolutely sufficient (and understandable)

^(?!specific/component/subfolder).+

同时.hgignore坚持拥有

meanwhile .hgignore insists on having

^(?!extras).+
^extras/(?!extensions).+
^extras/extensions/(?!sharing).+

我在前瞻组中添加斜线后,什么都没有通过.

as soon as i put slash inside the lookahead group, nothing gets through.

在将其称为错误之前(也许还有另一个本地正则表达式解析器?),我先问一下集体智慧:-)

Before calling this a bug (perhaps of yet another homegrown regex parser?) i ask the collective inteligence :-)

间接获得有关hgignore想要去什么的线索

Credits for indirect clue on what the heck hgignore wants go to

使用负前瞻珩磨.hgignore文件

推荐答案

请不要在.hgignore中使用否定的超前查询.真的.每当有人在Stack Overflow中在这里建议它时,我都会让他们知道它不是一个预期的功能,因此无法正常工作.如果假定Mercurial的.hgignore文件是白名单系统,则它将具有真正的白名单语法.这是一个黑名单,应按原样使用.

Just don't use negative lookahead in .hgignore. Really. Every time someone suggests it here in Stack Overflow I chime in letting them know that it doesn't work well because it's not an intended feature. If Mercurial's .hgignore file was supposed to be a whitelist system it would have a real whitelist syntax. It's a blacklist and should be used as such.

否定前瞻语法几乎可以正常工作,因为它不是本地的正则表达式解析器-它是内置在python中的一个语法,如果不使用它,则禁用否定前瞻似乎有点过头,但也许是更好的选择.

The negative lookahead syntax almost-works precisely because it's not a homegrown regex parser -- it's the one built into python and going out of the way do disable negative lookahead seems like overkill, but maybe was the better choice.

两个解决方案比使用永远无法满足您的否定的前瞻性处理要好:

Two solutions better than using the never-going-to-be-satisfying-to-you negative look ahead handling:

  • 只需将存储库下移一级-向下移至您实际要跟踪的文件夹中
  • -或-将所有内容列入黑名单,然后'hg add'您要跟踪的文件-添加覆盖忽略

严重.这不是预期的功能,它永远无法正常运行,但由于向后兼容的原因而无法删除.

Seriously. This wasn't an intended feature and it's never going to work well but can't be removed for backwards compatibility reasons.

这篇关于hgignore中的怪异的负面前瞻性处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆