Merge branch 'rs/use-strbuf-add-unique-abbrev'

A small code clean-up.

* rs/use-strbuf-add-unique-abbrev:
  use strbuf_add_unique_abbrev() for adding short hashes
This commit is contained in:
Junio C Hamano 2016-08-12 09:47:37 -07:00
Родитель 57734b4e88 1eb47f167d
Коммит 0a315befa7
3 изменённых файлов: 11 добавлений и 16 удалений

Просмотреть файл

@ -706,8 +706,7 @@ static int add_pending_uninteresting_ref(const char *refname,
static void describe_one_orphan(struct strbuf *sb, struct commit *commit) static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
{ {
strbuf_addstr(sb, " "); strbuf_addstr(sb, " ");
strbuf_addstr(sb, strbuf_add_unique_abbrev(sb, commit->object.oid.hash, DEFAULT_ABBREV);
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));
strbuf_addch(sb, ' '); strbuf_addch(sb, ' ');
if (!parse_commit(commit)) if (!parse_commit(commit))
pp_commit_easy(CMIT_FMT_ONELINE, commit, sb); pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);

Просмотреть файл

@ -1143,8 +1143,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET)); strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
return 1; return 1;
} }
strbuf_addstr(sb, find_unique_abbrev(commit->object.oid.hash, strbuf_add_unique_abbrev(sb, commit->object.oid.hash,
c->pretty_ctx->abbrev)); c->pretty_ctx->abbrev);
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET)); strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
c->abbrev_commit_hash.len = sb->len - c->abbrev_commit_hash.off; c->abbrev_commit_hash.len = sb->len - c->abbrev_commit_hash.off;
return 1; return 1;
@ -1154,8 +1154,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
case 't': /* abbreviated tree hash */ case 't': /* abbreviated tree hash */
if (add_again(sb, &c->abbrev_tree_hash)) if (add_again(sb, &c->abbrev_tree_hash))
return 1; return 1;
strbuf_addstr(sb, find_unique_abbrev(commit->tree->object.oid.hash, strbuf_add_unique_abbrev(sb, commit->tree->object.oid.hash,
c->pretty_ctx->abbrev)); c->pretty_ctx->abbrev);
c->abbrev_tree_hash.len = sb->len - c->abbrev_tree_hash.off; c->abbrev_tree_hash.len = sb->len - c->abbrev_tree_hash.off;
return 1; return 1;
case 'P': /* parent hashes */ case 'P': /* parent hashes */
@ -1171,9 +1171,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
for (p = commit->parents; p; p = p->next) { for (p = commit->parents; p; p = p->next) {
if (p != commit->parents) if (p != commit->parents)
strbuf_addch(sb, ' '); strbuf_addch(sb, ' ');
strbuf_addstr(sb, find_unique_abbrev( strbuf_add_unique_abbrev(sb, p->item->object.oid.hash,
p->item->object.oid.hash, c->pretty_ctx->abbrev);
c->pretty_ctx->abbrev));
} }
c->abbrev_parent_hashes.len = sb->len - c->abbrev_parent_hashes.len = sb->len -
c->abbrev_parent_hashes.off; c->abbrev_parent_hashes.off;

Просмотреть файл

@ -321,11 +321,6 @@ static void print_ref_status(char flag, const char *summary, struct ref *to, str
} }
} }
static const char *status_abbrev(unsigned char sha1[20])
{
return find_unique_abbrev(sha1, DEFAULT_ABBREV);
}
static void print_ok_ref_status(struct ref *ref, int porcelain) static void print_ok_ref_status(struct ref *ref, int porcelain)
{ {
if (ref->deletion) if (ref->deletion)
@ -340,7 +335,8 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
char type; char type;
const char *msg; const char *msg;
strbuf_addstr(&quickref, status_abbrev(ref->old_oid.hash)); strbuf_add_unique_abbrev(&quickref, ref->old_oid.hash,
DEFAULT_ABBREV);
if (ref->forced_update) { if (ref->forced_update) {
strbuf_addstr(&quickref, "..."); strbuf_addstr(&quickref, "...");
type = '+'; type = '+';
@ -350,7 +346,8 @@ static void print_ok_ref_status(struct ref *ref, int porcelain)
type = ' '; type = ' ';
msg = NULL; msg = NULL;
} }
strbuf_addstr(&quickref, status_abbrev(ref->new_oid.hash)); strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash,
DEFAULT_ABBREV);
print_ref_status(type, quickref.buf, ref, ref->peer_ref, msg, porcelain); print_ref_status(type, quickref.buf, ref, ref->peer_ref, msg, porcelain);
strbuf_release(&quickref); strbuf_release(&quickref);