aboutsummaryrefslogtreecommitdiff
path: root/test-wildmatch.c
Commit message (Collapse)AuthorAge
* add an extra level of indirection to main()Jeff King2016-07-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are certain startup tasks that we expect every git process to do. In some cases this is just to improve the quality of the program (e.g., setting up gettext()). In others it is a requirement for using certain functions in libgit.a (e.g., system_path() expects that you have called git_extract_argv0_path()). Most commands are builtins and are covered by the git.c version of main(). However, there are still a few external commands that use their own main(). Each of these has to remember to include the correct startup sequence, and we are not always consistent. Rather than just fix the inconsistencies, let's make this harder to get wrong by providing a common main() that can run this standard startup. We basically have two options to do this: - the compat/mingw.h file already does something like this by adding a #define that replaces the definition of main with a wrapper that calls mingw_startup(). The upside is that the code in each program doesn't need to be changed at all; it's rewritten on the fly by the preprocessor. The downside is that it may make debugging of the startup sequence a bit more confusing, as the preprocessor is quietly inserting new code. - the builtin functions are all of the form cmd_foo(), and git.c's main() calls them. This is much more explicit, which may make things more obvious to somebody reading the code. It's also more flexible (because of course we have to figure out _which_ cmd_foo() to call). The downside is that each of the builtins must define cmd_foo(), instead of just main(). This patch chooses the latter option, preferring the more explicit approach, even though it is more invasive. We introduce a new file common-main.c, with the "real" main. It expects to call cmd_main() from whatever other objects it is linked against. We link common-main.o against anything that links against libgit.a, since we know that such programs will need to do this setup. Note that common-main.o can't actually go inside libgit.a, as the linker would not pick up its main() function automatically (it has no callers). The rest of the patch is just adjusting all of the various external programs (mostly in t/helper) to use cmd_main(). I've provided a global declaration for cmd_main(), which means that all of the programs also need to match its signature. In particular, many functions need to switch to "const char **" instead of "char **" for argv. This effect ripples out to a few other variables and functions, as well. This makes the patch even more invasive, but the end result is much better. We should be treating argv strings as const anyway, and now all programs conform to the same signature (which also matches the way builtins are defined). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* stop using fnmatch (either native or compat)Nguyễn Thái Ngọc Duy2014-02-20
| | | | | | | | | | Since v1.8.4 (about six months ago) wildmatch is used as default replacement for fnmatch. We have seen only one fix since so wildmatch probably has done a good job as fnmatch replacement. This concludes the fnmatch->wildmatch transition by no longer relying on fnmatch. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Revert "test-wildmatch: add "perf" command to compare wildmatch and fnmatch"Nguyễn Thái Ngọc Duy2014-02-20
| | | | | | | | | This reverts commit 1b25892636d2f250eb2163301440ee8c8c1ac944. compat fnmatch will be removed soon and we can't rely on fnmatch() available everywhere. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Makefile: add USE_WILDMATCH to use wildmatch as fnmatchNguyễn Thái Ngọc Duy2013-01-01
| | | | | | | | | | | | | | This is similar to NO_FNMATCH but it uses wildmatch instead of compat/fnmatch. This is an intermediate step to let wildmatch be used as fnmatch replacement for wider audience before it replaces fnmatch completely and compat/fnmatch is removed. fnmatch in test-wildmatch is not impacted by this and is the only place that NO_FNMATCH or NO_FNMATCH_CASEFOLD remain active when USE_WILDMATCH is set. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* test-wildmatch: add "perf" command to compare wildmatch and fnmatchNguyễn Thái Ngọc Duy2013-01-01
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It takes a text file, a pattern, a number <n> and pathname flag. Each line in the text file is matched against the pattern <n> times. If "pathname" is given, FNM_PATHNAME is used. test-wildmatch is built with -O2 and tested against glibc 2.14.1 (also -O2) and compat/fnmatch. The input file is linux-2.6.git file list. <n> is 2000. The complete command list is at the end. wildmatch is beaten in the following cases. Apparently it needs some improvement in FNM_PATHNAME case: glibc, '*/*/*' with FNM_PATHNAME: wildmatch 8s 1559us fnmatch 1s 11877us or 12.65% faster compat, '*/*/*' with FNM_PATHNAME: wildmatch 7s 922458us fnmatch 2s 905111us or 36.67% faster compat, '*/*/*' without FNM_PATHNAME: wildmatch 7s 264201us fnmatch 2s 1897us or 27.56% faster compat, '[a-z]*/[a-z]*/[a-z]*' with FNM_PATHNAME: wildmatch 8s 742827us fnmatch 0s 922943us or 10.56% faster compat, '[a-z]*/[a-z]*/[a-z]*' without FNM_PATHNAME: wildmatch 8s 284520us fnmatch 0s 6936us or 0.08% faster The rest of glibc numbers ------------------------- 'Documentation/*' wildmatch 1s 529479us fnmatch 1s 98263us or 71.81% slower 'drivers/*' wildmatch 1s 988288us fnmatch 1s 192049us or 59.95% slower 'Documentation/*' pathname wildmatch 1s 557507us fnmatch 1s 93696us or 70.22% slower 'drivers/*' pathname wildmatch 2s 161626us fnmatch 1s 230372us or 56.92% slower '[Dd]ocu[Mn]entation/*' wildmatch 1s 776581us fnmatch 1s 471693us or 82.84% slower '[Dd]o?u[Mn]en?ati?n/*' wildmatch 1s 770770us fnmatch 1s 555727us or 87.86% slower '[Dd]o?u[Mn]en?ati?n/*' pathname wildmatch 1s 783507us fnmatch 1s 537029us or 86.18% slower '[A-Za-z][A-Za-z]??*' wildmatch 4s 110386us fnmatch 4s 926306us or 119.85% slower '[A-Za-z][A-Za-z]??' wildmatch 3s 918114us fnmatch 3s 686175us or 94.08% slower '[A-Za-z][A-Za-z]??*' pathname wildmatch 4s 453746us fnmatch 4s 955856us or 111.27% slower '[A-Za-z][A-Za-z]??' pathname wildmatch 3s 896646us fnmatch 3s 733828us or 95.82% slower '*/*/*' wildmatch 7s 287985us fnmatch 1s 74083us or 14.74% slower '[a-z]*/[a-z]*/[a-z]*' pathname wildmatch 8s 796659us fnmatch 1s 568409us or 17.83% slower '[a-z]*/[a-z]*/[a-z]*' wildmatch 8s 316559us fnmatch 3s 430652us or 41.25% slower The rest of compat numbers -------------------------- 'Documentation/*' wildmatch 1s 520389us fnmatch 0s 62579us or 4.12% slower 'drivers/*' wildmatch 1s 955354us fnmatch 0s 190109us or 9.72% slower 'Documentation/*' pathname wildmatch 1s 561675us fnmatch 0s 55336us or 3.54% slower 'drivers/*' pathname wildmatch 2s 106100us fnmatch 0s 219680us or 10.43% slower '[Dd]ocu[Mn]entation/*' wildmatch 1s 750810us fnmatch 0s 542721us or 31.00% slower '[Dd]o?u[Mn]en?ati?n/*' wildmatch 1s 724791us fnmatch 0s 538948us or 31.25% slower '[Dd]o?u[Mn]en?ati?n/*' pathname wildmatch 1s 731403us fnmatch 0s 537474us or 31.04% slower '[A-Za-z][A-Za-z]??*' wildmatch 4s 28555us fnmatch 1s 67297us or 26.49% slower '[A-Za-z][A-Za-z]??' wildmatch 3s 838279us fnmatch 0s 880005us or 22.93% slower '[A-Za-z][A-Za-z]??*' pathname wildmatch 4s 379476us fnmatch 1s 55643us or 24.10% slower '[A-Za-z][A-Za-z]??' pathname wildmatch 3s 830910us fnmatch 0s 849699us or 22.18% slower The following commands are used: LANG=C ./test-wildmatch perf /tmp/filelist.txt 'Documentation/*' 2000 LANG=C ./test-wildmatch perf /tmp/filelist.txt 'drivers/*' 2000 LANG=C ./test-wildmatch perf /tmp/filelist.txt 'Documentation/*' 2000 pathname LANG=C ./test-wildmatch perf /tmp/filelist.txt 'drivers/*' 2000 pathname LANG=C ./test-wildmatch perf /tmp/filelist.txt '[Dd]ocu[Mn]entation/*' 2000 LANG=C ./test-wildmatch perf /tmp/filelist.txt '[Dd]o?u[Mn]en?ati?n/*' 2000 LANG=C ./test-wildmatch perf /tmp/filelist.txt '[Dd]o?u[Mn]en?ati?n/*' 2000 pathname LANG=C ./test-wildmatch perf /tmp/filelist.txt '[A-Za-z][A-Za-z]??*' 2000 LANG=C ./test-wildmatch perf /tmp/filelist.txt '[A-Za-z][A-Za-z]??' 2000 LANG=C ./test-wildmatch perf /tmp/filelist.txt '[A-Za-z][A-Za-z]??*' 2000 pathname LANG=C ./test-wildmatch perf /tmp/filelist.txt '[A-Za-z][A-Za-z]??' 2000 pathname LANG=C ./test-wildmatch perf /tmp/filelist.txt '*/*/*' 2000 LANG=C ./test-wildmatch perf /tmp/filelist.txt '*/*/*' 2000 pathname LANG=C ./test-wildmatch perf /tmp/filelist.txt '[a-z]*/[a-z]*/[a-z]*' 2000 pathname LANG=C ./test-wildmatch perf /tmp/filelist.txt '[a-z]*/[a-z]*/[a-z]*' 2000 Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* wildmatch: support "no FNM_PATHNAME" modeNguyễn Thái Ngọc Duy2013-01-01
| | | | | | | | | | | | So far, wildmatch() has always honoured directory boundary and there was no way to turn it off. Make it behave more like fnmatch() by requiring all callers that want the FNM_PATHNAME behaviour to pass that in the equivalent flag WM_PATHNAME. Callers that do not specify WM_PATHNAME will get wildcards like ? and * in their patterns matched against '/', just like not passing FNM_PATHNAME to fnmatch(). Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* wildmatch: rename constants and update prototypeNguyễn Thái Ngọc Duy2013-01-01
| | | | | | | | | | | | | - All exported constants now have a prefix WM_ - Do not rely on FNM_* constants, use the WM_ counterparts - Remove TRUE and FALSE to follow Git's coding style - While at it, turn flags type from int to unsigned int - Add an (unused yet) argument to carry extra information so that we don't have to change the prototype again later when we need to pass other stuff to wildmatch Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* test-wildmatch: avoid Windows path manglingNguyễn Thái Ngọc Duy2012-11-20
| | | | | | | | | | | | | The MSYS bash mangles arguments that begin with a forward slash when they are passed to test-wildmatch. This causes tests to fail. Avoid mangling by prepending "XXX", which is removed by test-wildmatch before further processing. [J6t: reworded commit message] Reported-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
* wildmatch: remove static variable force_lower_caseNguyễn Thái Ngọc Duy2012-10-15
| | | | | | | | One place less to worry about thread safety. Also combine wildmatch and iwildmatch into one. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* wildmatch: make wildmatch's return value compatible with fnmatchNguyễn Thái Ngọc Duy2012-10-15
| | | | | | | | wildmatch returns non-zero if matched, zero otherwise. This patch makes it return zero if matches, non-zero otherwise, like fnmatch(). Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Integrate wildmatch to gitNguyễn Thái Ngọc Duy2012-10-15
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>