How to imitate a language complementary to an operator in .hgignore?

I have a Python regex that matches a set of file names. How to change it so that I can use it in the Mercurial.hgignore file to ignore files that do not match the expression?

Full story: I have a large source tree with *.mlfiles scattered throughout. I want to put them in a new repository. There are other, less important files that are too heavy to include in the repository. I am trying to find the appropriate expression for a file .hgignore.

1st observation: Python does not have a regular language complement operator (AFAIK, it can only complement a character set). (By the way, why?)

Second observation: The following regular expression in Python:

re.compile("^.*(?<!\.ml)$")

works as expected:

abcabc - match  
abc.ml - no match  
x/abcabc - match  
x/abc.ml - no match

, .hgignore, :

$ hg st --all  
?  abc.ml  
I .hgignore  
I abcabc  
I x/xabc  
I x/xabc.ml  

.hgignore manpage, Mercurial Python. ? , Mercurial x/xabc.ml?

- ?

+3
3

, , . , /b/c/d , a, a/b, a/b/c, a/b/c/d. - , . ( , , ^bar$ bar/foo - , bar/foo .)

^.*(?<!\.ml)$ x/xabc.ml, x (.. .)

, , , .

+1

, , , . , , -, . - , . Windows XP ( unixy) Mercurial 1.2.1.

( # message.)

$ hg --version
Mercurial Distributed SCM (version 1.2.1)

$ cat .hgignore
syntax: regexp
^x/.+(?<!\.ml)$       # rooted to x/ subdir
#^.+[^.][^m][^l]$

$ hg status --all
? .hgignore           # not affected by x/ regex
? abc.ml              # not affected by x/ regex
? abcabc              # not affected by x/ regex
? x\saveme.ml         # versioned, is *.ml
I x\abcabc            # ignored, is not *.ml
I x\ignoreme.txt      # ignored, is not *.ml

:

$ cat .hgignore
syntax: regexp
#^x/.+(?<!\.ml)$
^.+[^.][^m][^l]$      # brittle, can only use one suffix

$ hg status --all
? abc.ml              # versioned, is *.ml
? x\saveme.ml         # versioned, is *.ml
I .hgignore           # ignored, is not *.ml
I abcabc              # ignored, is not *.ml
I x\abcabc            # ignored, is not *.ml
I x\ignoreme.txt      # ignored, is not *.ml

, . , .

0

, . :

$ hg --version
Mercurial Distributed SCM (version 1.1.2)

, . :

$ find . -name 'abc*' -print
./x/abcabc
./x/abc.ml
./abcabc
./abc.ml

.hgignore:

$ cat .hgignore
^.*(?<!\.ml)$

, stat:

$ hg stat
? abc.ml

, hg x/abc.ml. ? , :

$ python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mercurial.ignore
>>> import os
>>> root = os.getcwd()
>>> ignorefunc = mercurial.ignore.ignore(root, ['.hgignore'], lambda msg: None)
>>> 
>>> ignorefunc("abc.ml") # No match - this is correct
>>> ignorefunc("abcabc") # Match - this is correct, we want to ignore this
<_sre.SRE_Match object at 0xb7c765d0>
>>> ignorefunc("abcabc").span() 
(0, 6)
>>> ignorefunc("x/abcabc").span() # Match - this is correct, we want to ignore this
(0, 8)
>>> ignorefunc("x/abc.ml") # No match - this is correct!
>>> 

Please note that the ignorefuncprocessed abcabcand x/abcabcthe same (agreed - ie ignored), while abc.mland x/abc.mlalso handled the same way (no matches - that is not ignored).

So, maybe a logical error elsewhere in Mercurial, or maybe I'm looking at the wrong bit of Mercurial (although I would be surprised if that were the case). If I missed something, perhaps Mercurial should have an error (not the RFE that Martin Geisler points to).

0
source

Source: https://habr.com/ru/post/1711814/


All Articles