简体   繁体   中英

hg .ignore regex - how to allow a new/mod'ed test_<filename>.c to be displayed but not the binary test_<filename>?

I have a set of unit tests in C. Their form is: test_<filename>.c and when compiled they are test_<filename> .

I am trying to have new *.C file show up when a hg status is displayed, but any binary files ( test_<filename> ) to be suppressed.

What I have now is:

src/project/test/.+/test_.+[^\.][^c]$

this works fine except for one case: where the <filename> ends with a c (ie, test_func , from test_func.c )

Then test_func is displayed with a status of '? test_func'

I am a moderate regex guy, but have searched for a couple of weeks, but haven't found a solution - which I assume to be easy, once I see it.

This is a bit hairy, but it seems to work, using a negative lookbehind (that's the (?<!a)b part):

src/project/test/.+/test.+([^c]|(?<!\.)c)$

To expand the part I changed — that is, ([^c]|(?<.\.)c) :

(
    [^c]             // the last character can be anything other than c
    |                // or, if it is c
    (?<!\.)c         // it cannot be preceded by .
)

The extra \ in the negative lookbehind (" c not preceded by . ") is needed to escape the . , which otherwise means "any character".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM