use strbuf_add_unique_abbrev() for adding short hashes
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 and a bit more efficient. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Aug 6, 2016 at 17:41 UTC
1eb47f167d65d1d305b9c196a1bb40eb96117cb1
3 files changed
+11
-16
builtin/checkout.c
+1
-2
@@ -703,8 +703,7 @@ static int add_pending_uninteresting_ref(const char *refname,
703
static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
704
{
705
strbuf_addstr(sb, " ");
706
- strbuf_addstr(sb,
707
- find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));
706
+ strbuf_add_unique_abbrev(sb, commit->object.oid.hash, DEFAULT_ABBREV);
707
strbuf_addch(sb, ' ');
708
if (!parse_commit(commit))
709
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
pretty.c
+6
-7
@@ -1141,8 +1141,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1141
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
1142
return 1;
1143
}
1144
- strbuf_addstr(sb, find_unique_abbrev(commit->object.oid.hash,
1145
- c->pretty_ctx->abbrev));
1144
+ strbuf_add_unique_abbrev(sb, commit->object.oid.hash,
1145
+ c->pretty_ctx->abbrev);
1146
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
1147
c->abbrev_commit_hash.len = sb->len - c->abbrev_commit_hash.off;
1148
return 1;
@@ -1152,8 +1152,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1152
case 't': /* abbreviated tree hash */
1153
if (add_again(sb, &c->abbrev_tree_hash))
1154
return 1;
1155
- strbuf_addstr(sb, find_unique_abbrev(commit->tree->object.oid.hash,
1156
- c->pretty_ctx->abbrev));
1155
+ strbuf_add_unique_abbrev(sb, commit->tree->object.oid.hash,
1156
+ c->pretty_ctx->abbrev);
1157
c->abbrev_tree_hash.len = sb->len - c->abbrev_tree_hash.off;
1158
return 1;
1159
case 'P': /* parent hashes */
@@ -1169,9 +1169,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1169
for (p = commit->parents; p; p = p->next) {
1170
if (p != commit->parents)
1171
strbuf_addch(sb, ' ');
1172
- strbuf_addstr(sb, find_unique_abbrev(
1173
- p->item->object.oid.hash,
1174
- c->pretty_ctx->abbrev));
1172
+ strbuf_add_unique_abbrev(sb, p->item->object.oid.hash,
1173
+ c->pretty_ctx->abbrev);
1174
}
1175
c->abbrev_parent_hashes.len = sb->len -
1176
c->abbrev_parent_hashes.off;
transport.c
+4
-7
@@ -321,11 +321,6 @@ static void print_ref_status(char flag, const char *summary, struct ref *to, str
321
}
322
}
323
324
-static const char *status_abbrev(unsigned char sha1[20])
325
-{
326
- return find_unique_abbrev(sha1, DEFAULT_ABBREV);
327
-}
328
-
324
static void print_ok_ref_status(struct ref *ref, int porcelain)
325
{
326
if (ref->deletion)
@@ -340,7 +335,8 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
335
char type;
336
const char *msg;
337
343
- strbuf_addstr(&quickref, status_abbrev(ref->old_oid.hash));
338
+ strbuf_add_unique_abbrev(&quickref, ref->old_oid.hash,
339
+ DEFAULT_ABBREV);
340
if (ref->forced_update) {
341
strbuf_addstr(&quickref, "...");
342
type = '+';
@@ -350,7 +346,8 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
346
type = ' ';
347
msg = NULL;
348
}
353
- strbuf_addstr(&quickref, status_abbrev(ref->new_oid.hash));
349
+ strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash,
350
+ DEFAULT_ABBREV);
351
352
print_ref_status(type, quickref.buf, ref, ref->peer_ref, msg, porcelain);
353
strbuf_release(&quickref);