find_unique_abbrev: use 4-buffer ring
Some code paths want to format multiple abbreviated sha1s in the same output line. Because we use a single static buffer for our return value, they have to either break their output into several calls or allocate their own arrays and use find_unique_abbrev_r(). Intead, let's mimic sha1_to_hex() and use a ring of several buffers, so that the return value stays valid through multiple calls. This shortens some of the callers, and makes it harder to for them to make a silly mistake. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
4ce742fc9c
commit
ef2ed5013c
@ -1374,12 +1374,11 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
|
||||
struct commit *commit;
|
||||
|
||||
if (verbosity >= 0) {
|
||||
char from[GIT_SHA1_HEXSZ + 1], to[GIT_SHA1_HEXSZ + 1];
|
||||
find_unique_abbrev_r(from, head_commit->object.oid.hash,
|
||||
DEFAULT_ABBREV);
|
||||
find_unique_abbrev_r(to, remoteheads->item->object.oid.hash,
|
||||
DEFAULT_ABBREV);
|
||||
printf(_("Updating %s..%s\n"), from, to);
|
||||
printf(_("Updating %s..%s\n"),
|
||||
find_unique_abbrev(head_commit->object.oid.hash,
|
||||
DEFAULT_ABBREV),
|
||||
find_unique_abbrev(remoteheads->item->object.oid.hash,
|
||||
DEFAULT_ABBREV));
|
||||
}
|
||||
strbuf_addstr(&msg, "Fast-forward");
|
||||
if (have_message)
|
||||
|
Reference in New Issue
Block a user