Skip to content

Commit 5e469ab

Browse files
committed
Merge branch 'rs/use-strbuf-add-unique-abbrev' into maint
A small code clean-up. * rs/use-strbuf-add-unique-abbrev: use strbuf_add_unique_abbrev() for adding short hashes
2 parents f14883b + 1eb47f1 commit 5e469ab

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

builtin/checkout.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,8 +704,7 @@ static int add_pending_uninteresting_ref(const char *refname,
704704
static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
705705
{
706706
strbuf_addstr(sb, " ");
707-
strbuf_addstr(sb,
708-
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));
707+
strbuf_add_unique_abbrev(sb, commit->object.oid.hash, DEFAULT_ABBREV);
709708
strbuf_addch(sb, ' ');
710709
if (!parse_commit(commit))
711710
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);

pretty.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,8 +1141,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
11411141
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
11421142
return 1;
11431143
}
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);
11461146
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
11471147
c->abbrev_commit_hash.len = sb->len - c->abbrev_commit_hash.off;
11481148
return 1;
@@ -1152,8 +1152,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
11521152
case 't': /* abbreviated tree hash */
11531153
if (add_again(sb, &c->abbrev_tree_hash))
11541154
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);
11571157
c->abbrev_tree_hash.len = sb->len - c->abbrev_tree_hash.off;
11581158
return 1;
11591159
case 'P': /* parent hashes */
@@ -1169,9 +1169,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
11691169
for (p = commit->parents; p; p = p->next) {
11701170
if (p != commit->parents)
11711171
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);
11751174
}
11761175
c->abbrev_parent_hashes.len = sb->len -
11771176
c->abbrev_parent_hashes.off;

transport.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,6 @@ static void print_ref_status(char flag, const char *summary, struct ref *to, str
321321
}
322322
}
323323

324-
static const char *status_abbrev(unsigned char sha1[20])
325-
{
326-
return find_unique_abbrev(sha1, DEFAULT_ABBREV);
327-
}
328-
329324
static void print_ok_ref_status(struct ref *ref, int porcelain)
330325
{
331326
if (ref->deletion)
@@ -340,7 +335,8 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
340335
char type;
341336
const char *msg;
342337

343-
strbuf_addstr(&quickref, status_abbrev(ref->old_oid.hash));
338+
strbuf_add_unique_abbrev(&quickref, ref->old_oid.hash,
339+
DEFAULT_ABBREV);
344340
if (ref->forced_update) {
345341
strbuf_addstr(&quickref, "...");
346342
type = '+';
@@ -350,7 +346,8 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
350346
type = ' ';
351347
msg = NULL;
352348
}
353-
strbuf_addstr(&quickref, status_abbrev(ref->new_oid.hash));
349+
strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash,
350+
DEFAULT_ABBREV);
354351

355352
print_ref_status(type, quickref.buf, ref, ref->peer_ref, msg, porcelain);
356353
strbuf_release(&quickref);

0 commit comments

Comments
 (0)