Weird negative lookahead handling in hgignore

大兔子大兔子 提交于 2019-12-11 08:24:58

问题


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

specific/component/subfolder

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

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

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 :-)

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

Honing the .hgignore file using a negative lookahead


回答1:


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.

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:

  • just move the repository one level lower -- down into the folder you actually want to track
  • -or- blacklist everything and then 'hg add' the files you want track -- add overrides ignore

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



来源:https://stackoverflow.com/questions/10433342/weird-negative-lookahead-handling-in-hgignore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!