]> git.ipfire.org Git - thirdparty/git.git/commit - refs.c
avoid using mksnpath for refs
authorJeff King <peff@peff.net>
Tue, 28 Mar 2017 19:46:33 +0000 (15:46 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 30 Mar 2017 21:59:50 +0000 (14:59 -0700)
commit6cd4a8982dbde0b6fee26faba2873c475af50a28
tree3006f26c267aabee175f0d4342e424bbccdd4644
parent7f897b6f176319ec0f490d286c3fee11187d7095
avoid using mksnpath for refs

Like the previous commit, we'd like to avoid the assumption
that refs fit into PATH_MAX-sized buffers. These callsites
have an extra twist, though: they write the refnames using
mksnpath. This does two things beyond a regular snprintf:

  1. It quietly writes "/bad-path/" when truncation occurs.
     This saves the caller having to check the error code,
     but if you aren't actually feeding the result to a
     system call (and we aren't here), it's questionable.

  2. It calls cleanup_path(), which removes leading
     instances of "./".  That's questionable when dealing
     with refnames, as we could silently canonicalize a
     syntactically bogus refname into a valid one.

Let's convert each case to use a strbuf. This is preferable
to xstrfmt() because we can reuse the same buffer as we
loop.

Signed-off-by: Jeff King <peff@peff.net>
refs.c