OSDN Git Service

fetch-pack: simplify add_sought_entry
authorJeff King <peff@peff.net>
Mon, 22 Feb 2016 22:44:50 +0000 (17:44 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Feb 2016 22:51:09 +0000 (14:51 -0800)
commit5545f057d4684de99feca0ca480297e3d71fb812
treef585d64615a567adc297c4a530f4ace095e9d988
parenta78c188a32dd2ce02db2b966a70bffec52c98d20
fetch-pack: simplify add_sought_entry

We have two variants of this function, one that takes a
string and one that takes a ptr/len combo. But we only call
the latter with the length of a NUL-terminated string, so
our first simplification is to drop it in favor of the
string variant.

Since we know we have a string, we can also replace the
manual memory computation with a call to alloc_ref().

Furthermore, we can rely on get_oid_hex() to complain if it
hits the end of the string. That means we can simplify the
check for "<sha1> <ref>" versus just "<ref>". Rather than
manage the ptr/len pair, we can just bump the start of our
string forward. The original code over-allocated based on
the original "namelen" (which wasn't _wrong_, but was simply
wasteful and confusing).

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