tree_entry_interesting: do basedir compare on wildcard patterns when possible
commitc904cd89e4328c0b5041b6ee0bb2df32459a33a2
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 24 Nov 2012 04:33:51 +0000 (24 11:33 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Nov 2012 19:16:34 +0000 (26 11:16 -0800)
tree7ffe77166543e60ce97327090b3907ef820c3c19
parent8c6abbcd2720dd80b1c9b6db8104c4dcc7cba6c7
tree_entry_interesting: do basedir compare on wildcard patterns when possible

Currently we treat "*.c" and "path/to/*.c" the same way. Which means
we check all possible paths in repo against "path/to/*.c". One could
see that "path/elsewhere/foo.c" obviously cannot match "path/to/*.c"
and we only need to check all paths _inside_ "path/to/" against that
pattern.

This patch checks the leading fixed part of a pathspec against base
directory and exit early if possible. We could even optimize further
in "path/to/something*.c" case (i.e. check the fixed part against
name_entry as well) but that's more complicated and probably does not
gain us much.

-O2 build on linux-2.6, without and with this patch respectively:

$ time git rev-list --quiet HEAD -- 'drivers/*.c'

real    1m9.484s
user    1m9.128s
sys     0m0.181s

$ time ~/w/git/git rev-list --quiet HEAD -- 'drivers/*.c'

real    0m15.710s
user    0m15.564s
sys     0m0.107s

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
tree-walk.c