diff options
author | Jeff King <peff@peff.net> | 2015-04-16 05:03:26 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-04-16 08:15:05 -0700 |
commit | 03afcbee9b9246f5ec9b013f2a699b151f0ba7ab (patch) | |
tree | 1ae0af79c0b59ba0c8b9fe2d897a9ed58cc104a3 /t/t1430-bad-ref-name.sh | |
parent | strbuf_getwholeline: use getdelim if it is available (diff) | |
download | tgif-03afcbee9b9246f5ec9b013f2a699b151f0ba7ab.tar.xz |
read_packed_refs: avoid double-checking sane refs
Prior to d0f810f (refs.c: allow listing and deleting badly
named refs, 2014-09-03), read_packed_refs would barf on any
malformed refnames by virtue of calling create_ref_entry
with the "check" parameter set to 1. That commit loosened
our reading so that we call check_refname_format ourselves
and just set a REF_BAD_NAME flag.
We then call create_ref_entry with the check parameter set
to 0. That function learned to do an extra safety check even
when the check parameter is 0, so that we don't load any
dangerous refnames (like "../../../etc/passwd"). This is
implemented by calling refname_is_safe() in
create_ref_entry().
However, we can observe that refname_is_safe() can only be
true if check_refname_format() also failed. So in the common
case of a sanely named ref, we perform _both_ checks, even
though we know that the latter will never trigger. This has
a noticeable performance impact when the packed-refs file is
large.
Let's drop the refname_is_safe check from create_ref_entry(),
and make it the responsibility of the caller. Of the three
callers that pass a check parameter of "0", two will have
just called check_refname_format(), and can check the
refname-safety only when it fails. The third case,
pack_if_possible_fn, is copying from an existing ref entry,
which must have previously passed our safety check.
With this patch, running "git rev-parse refs/heads/does-not-exist"
on a repo with a large (1.6GB) packed-refs file went from:
real 0m6.768s
user 0m6.340s
sys 0m0.432s
to:
real 0m5.703s
user 0m5.276s
sys 0m0.432s
for a wall-clock speedup of 15%.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t1430-bad-ref-name.sh')
0 files changed, 0 insertions, 0 deletions