match: avoid translating glob to matcher multiple times for large sets
For hgignore with many globs, the resulting regexp might not fit under the 20K
length limit. So the patterns need to be broken up in smaller pieces.
Before this change, the logic was re-starting the full process from scratch
for each smaller pieces, including the translation of globs into regexp.
Effectively doing the work over and over.
If the 20K limit is reached, we are likely in a case where there is many such
glob, so exporting them is especially expensive and we should be careful not
to do that work more than once.
To work around this, we now translate glob to regexp once and for all. Then,
we assemble the resulting individual regexp into valid blocks.
This raises a very significant performance win for large `.hgignore file`:
Before: ! wall 0.153153 comb 0.150000 user 0.150000 sys 0.000000 (median of 66)
After: ! wall 0.059793 comb 0.060000 user 0.060000 sys 0.000000 (median of 100)
Test encode/decode filters
$ hg init
$ cat > .hg/hgrc <<EOF
> [encode]
> not.gz = tr [:lower:] [:upper:]
> *.gz = gzip -d
> [decode]
> not.gz = tr [:upper:] [:lower:]
> *.gz = gzip
> EOF
$ echo "this is a test" | gzip > a.gz
$ echo "this is a test" > not.gz
$ hg add *
$ hg ci -m "test"
no changes
$ hg status
$ touch *
no changes
$ hg status
check contents in repo are encoded
$ hg debugdata a.gz 0
this is a test
$ hg debugdata not.gz 0
THIS IS A TEST
check committed content was decoded
$ gunzip < a.gz
this is a test
$ cat not.gz
this is a test
$ rm *
$ hg co -C
2 files updated, 0 files merged, 0 files removed, 0 files unresolved
check decoding of our new working dir copy
$ gunzip < a.gz
this is a test
$ cat not.gz
this is a test
check hg cat operation
$ hg cat a.gz
this is a test
$ hg cat --decode a.gz | gunzip
this is a test
$ mkdir subdir
$ cd subdir
$ hg -R .. cat ../a.gz
this is a test
$ hg -R .. cat --decode ../a.gz | gunzip
this is a test
$ cd ..
check tempfile filter
$ hg cat a.gz --decode --config 'decode.*.gz=tempfile:gzip -c INFILE > OUTFILE' | gunzip
this is a test
$ hg cat a.gz --decode --config 'decode.*.gz=tempfile:sh -c "exit 1"'
abort: command '*' failed: exited with status 1 (glob)
[255]
$ cd ..