]> git.ipfire.org Git - thirdparty/git.git/commit - sha1-name.c
get_short_sha1: NUL-terminate hex prefix
authorJeff King <peff@peff.net>
Mon, 26 Sep 2016 12:00:07 +0000 (08:00 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Sep 2016 18:46:41 +0000 (11:46 -0700)
commit59e4e34f6977f83c3a3842178da6358a5d130eb6
treeb7a0219bfc313daefa6b023c8ba7d95a83cf0204
parent0016043bf46f4b85054c61f9000ccc58d0ef4ad7
get_short_sha1: NUL-terminate hex prefix

We store the hex prefix in a 40-byte buffer with the prefix
itself followed by 40-minus-len "x" characters. These x's
serve no purpose, and the lack of NUL termination makes the
prefix string annoying to use. Let's just terminate it.

Note that this is in contrast to the binary prefix, which
_must_ be zero-padded, because we look at the whole thing
during a binary search to find the first potential match in
each pack index. The loose-object hex search cannot use the
same trick because it has to do a linear walk through the
unsorted results of readdir() (and even if it could, you'd
want zeroes instead of x's).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
sha1_name.c