use strbuf_add_unique_abbrev() for adding short hashes, part 3
Call strbuf_add_unique_abbrev() to add abbreviated hashes to strbufs instead of taking detours through find_unique_abbrev() and its static buffer. This is shorter in most cases and a bit more efficient. The changes here are not easily handled by a semantic patch because they involve removing temporary variables and deconstructing format strings for strbuf_addf(). Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
39ea59a257
commit
a94bb68397
10
wt-status.c
10
wt-status.c
@ -1053,7 +1053,6 @@ static void abbrev_sha1_in_line(struct strbuf *line)
|
||||
split = strbuf_split_max(line, ' ', 3);
|
||||
if (split[0] && split[1]) {
|
||||
unsigned char sha1[20];
|
||||
const char *abbrev;
|
||||
|
||||
/*
|
||||
* strbuf_split_max left a space. Trim it and re-add
|
||||
@ -1061,9 +1060,10 @@ static void abbrev_sha1_in_line(struct strbuf *line)
|
||||
*/
|
||||
strbuf_trim(split[1]);
|
||||
if (!get_sha1(split[1]->buf, sha1)) {
|
||||
abbrev = find_unique_abbrev(sha1, DEFAULT_ABBREV);
|
||||
strbuf_reset(split[1]);
|
||||
strbuf_addf(split[1], "%s ", abbrev);
|
||||
strbuf_add_unique_abbrev(split[1], sha1,
|
||||
DEFAULT_ABBREV);
|
||||
strbuf_addch(split[1], ' ');
|
||||
strbuf_reset(line);
|
||||
for (i = 0; split[i]; i++)
|
||||
strbuf_addbuf(line, split[i]);
|
||||
@ -1286,10 +1286,8 @@ static char *get_branch(const struct worktree *wt, const char *path)
|
||||
else if (starts_with(sb.buf, "refs/"))
|
||||
;
|
||||
else if (!get_sha1_hex(sb.buf, sha1)) {
|
||||
const char *abbrev;
|
||||
abbrev = find_unique_abbrev(sha1, DEFAULT_ABBREV);
|
||||
strbuf_reset(&sb);
|
||||
strbuf_addstr(&sb, abbrev);
|
||||
strbuf_add_unique_abbrev(&sb, sha1, DEFAULT_ABBREV);
|
||||
} else if (!strcmp(sb.buf, "detached HEAD")) /* rebase */
|
||||
goto got_nothing;
|
||||
else /* bisect */
|
||||
|
Reference in New Issue
Block a user