Convert find_unique_abbrev* to struct object_id

Convert find_unique_abbrev and find_unique_abbrev_r to each take a
pointer to struct object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
brian m. carlson 2018-03-12 02:27:30 +00:00 committed by Junio C Hamano
parent 40f5555ca3
commit aab9583f7b
28 changed files with 61 additions and 59 deletions

View File

@ -499,7 +499,7 @@ static int read_ancestry(const char *graft_file)
static int update_auto_abbrev(int auto_abbrev, struct blame_origin *suspect)
{
const char *uniq = find_unique_abbrev(suspect->commit->object.oid.hash,
const char *uniq = find_unique_abbrev(&suspect->commit->object.oid,
auto_abbrev);
int len = strlen(uniq);
if (auto_abbrev < len)

View File

@ -273,7 +273,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
bname.buf,
(flags & REF_ISBROKEN) ? "broken"
: (flags & REF_ISSYMREF) ? target
: find_unique_abbrev(oid.hash, DEFAULT_ABBREV));
: find_unique_abbrev(&oid, DEFAULT_ABBREV));
}
delete_branch_config(bname.buf);

View File

@ -405,10 +405,10 @@ static void describe_detached_head(const char *msg, struct commit *commit)
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
if (print_sha1_ellipsis()) {
fprintf(stderr, "%s %s... %s\n", msg,
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf);
find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV), sb.buf);
} else {
fprintf(stderr, "%s %s %s\n", msg,
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf);
find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV), sb.buf);
}
strbuf_release(&sb);
}
@ -778,7 +778,7 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
" git branch <new-branch-name> %s\n\n",
/* Give ngettext() the count */
lost),
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));
find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV));
}
/*

View File

@ -285,7 +285,7 @@ static void append_name(struct commit_name *n, struct strbuf *dst)
static void append_suffix(int depth, const struct object_id *oid, struct strbuf *dst)
{
strbuf_addf(dst, "-%d-g%s", depth, find_unique_abbrev(oid->hash, abbrev));
strbuf_addf(dst, "-%d-g%s", depth, find_unique_abbrev(oid, abbrev));
}
static void describe_commit(struct object_id *oid, struct strbuf *dst)
@ -383,7 +383,7 @@ static void describe_commit(struct object_id *oid, struct strbuf *dst)
if (!match_cnt) {
struct object_id *cmit_oid = &cmit->object.oid;
if (always) {
strbuf_add_unique_abbrev(dst, cmit_oid->hash, abbrev);
strbuf_add_unique_abbrev(dst, cmit_oid, abbrev);
if (suffix)
strbuf_addstr(dst, suffix);
return;

View File

@ -1873,12 +1873,12 @@ static void print_commit(char sign, struct commit *commit, int verbose,
{
if (!verbose) {
fprintf(file, "%c %s\n", sign,
find_unique_abbrev(commit->object.oid.hash, abbrev));
find_unique_abbrev(&commit->object.oid, abbrev));
} else {
struct strbuf buf = STRBUF_INIT;
pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
fprintf(file, "%c %s %s\n", sign,
find_unique_abbrev(commit->object.oid.hash, abbrev),
find_unique_abbrev(&commit->object.oid, abbrev),
buf.buf);
strbuf_release(&buf);
}

View File

@ -240,7 +240,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,
printf("%s%06o %s %d\t",
tag,
ce->ce_mode,
find_unique_abbrev(ce->oid.hash, abbrev),
find_unique_abbrev(&ce->oid, abbrev),
ce_stage(ce));
}
write_eolinfo(repo->index, ce, fullname);
@ -271,7 +271,7 @@ static void show_ru_info(const struct index_state *istate)
if (!ui->mode[i])
continue;
printf("%s%06o %s %d\t", tag_resolve_undo, ui->mode[i],
find_unique_abbrev(ui->oid[i].hash, abbrev),
find_unique_abbrev(&ui->oid[i], abbrev),
i + 1);
write_name(path);
}

View File

@ -103,11 +103,11 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
} else
xsnprintf(size_text, sizeof(size_text), "-");
printf("%06o %s %s %7s\t", mode, type,
find_unique_abbrev(oid->hash, abbrev),
find_unique_abbrev(oid, abbrev),
size_text);
} else
printf("%06o %s %s\t", mode, type,
find_unique_abbrev(oid->hash, abbrev));
find_unique_abbrev(oid, abbrev));
}
baselen = base->len;
strbuf_addstr(base, pathname);

View File

@ -1327,7 +1327,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
check_commit_signature(commit, &signature_check);
find_unique_abbrev_r(hex, commit->object.oid.hash, DEFAULT_ABBREV);
find_unique_abbrev_r(hex, &commit->object.oid, DEFAULT_ABBREV);
switch (signature_check.result) {
case 'G':
break;
@ -1420,9 +1420,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (verbosity >= 0) {
printf(_("Updating %s..%s\n"),
find_unique_abbrev(head_commit->object.oid.hash,
find_unique_abbrev(&head_commit->object.oid,
DEFAULT_ABBREV),
find_unique_abbrev(remoteheads->item->object.oid.hash,
find_unique_abbrev(&remoteheads->item->object.oid,
DEFAULT_ABBREV));
}
strbuf_addstr(&msg, "Fast-forward");

View File

@ -328,7 +328,7 @@ static void show_name(const struct object *obj,
else if (allow_undefined)
printf("undefined\n");
else if (always)
printf("%s\n", find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
printf("%s\n", find_unique_abbrev(oid, DEFAULT_ABBREV));
else
die("cannot describe '%s'", oid_to_hex(oid));
strbuf_release(&buf);

View File

@ -1242,11 +1242,11 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
rp_error("refusing inconsistent update between symref '%s' (%s..%s) and"
" its target '%s' (%s..%s)",
cmd->ref_name,
find_unique_abbrev(cmd->old_oid.hash, DEFAULT_ABBREV),
find_unique_abbrev(cmd->new_oid.hash, DEFAULT_ABBREV),
find_unique_abbrev(&cmd->old_oid, DEFAULT_ABBREV),
find_unique_abbrev(&cmd->new_oid, DEFAULT_ABBREV),
dst_cmd->ref_name,
find_unique_abbrev(dst_cmd->old_oid.hash, DEFAULT_ABBREV),
find_unique_abbrev(dst_cmd->new_oid.hash, DEFAULT_ABBREV));
find_unique_abbrev(&dst_cmd->old_oid, DEFAULT_ABBREV),
find_unique_abbrev(&dst_cmd->new_oid, DEFAULT_ABBREV));
cmd->error_string = dst_cmd->error_string =
"inconsistent aliased update";

View File

@ -109,7 +109,7 @@ static void print_new_head_line(struct commit *commit)
struct strbuf buf = STRBUF_INIT;
printf(_("HEAD is now at %s"),
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));
find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV));
pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
if (buf.len > 0)

View File

@ -108,7 +108,7 @@ static void show_commit(struct commit *commit, void *data)
if (!revs->graph)
fputs(get_revision_mark(revs, commit), stdout);
if (revs->abbrev_commit && revs->abbrev)
fputs(find_unique_abbrev(commit->object.oid.hash, revs->abbrev),
fputs(find_unique_abbrev(&commit->object.oid, revs->abbrev),
stdout);
else
fputs(oid_to_hex(&commit->object.oid), stdout);

View File

@ -159,7 +159,7 @@ static void show_rev(int type, const struct object_id *oid, const char *name)
}
}
else if (abbrev)
show_with_type(type, find_unique_abbrev(oid->hash, abbrev));
show_with_type(type, find_unique_abbrev(oid, abbrev));
else
show_with_type(type, oid_to_hex(oid));
}

View File

@ -292,7 +292,7 @@ static void show_one_commit(struct commit *commit, int no_name)
}
else
printf("[%s] ",
find_unique_abbrev(commit->object.oid.hash,
find_unique_abbrev(&commit->object.oid,
DEFAULT_ABBREV));
}
puts(pretty_str);

View File

@ -29,7 +29,7 @@ static void show_one(const char *refname, const struct object_id *oid)
if (quiet)
return;
hex = find_unique_abbrev(oid->hash, abbrev);
hex = find_unique_abbrev(oid, abbrev);
if (hash_only)
printf("%s\n", hex);
else
@ -39,7 +39,7 @@ static void show_one(const char *refname, const struct object_id *oid)
return;
if (!peel_ref(refname, &peeled)) {
hex = find_unique_abbrev(peeled.hash, abbrev);
hex = find_unique_abbrev(&peeled, abbrev);
printf("%s %s^{}\n", hex, refname);
}
}

View File

@ -99,7 +99,8 @@ static int delete_tag(const char *name, const char *ref,
{
if (delete_ref(NULL, ref, oid, 0))
return 1;
printf(_("Deleted tag '%s' (was %s)\n"), name, find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
printf(_("Deleted tag '%s' (was %s)\n"), name,
find_unique_abbrev(oid, DEFAULT_ABBREV));
return 0;
}
@ -558,7 +559,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
die("%s", err.buf);
ref_transaction_free(transaction);
if (force && !is_null_oid(&prev) && oidcmp(&prev, &object))
printf(_("Updated tag '%s' (was %s)\n"), tag, find_unique_abbrev(prev.hash, DEFAULT_ABBREV));
printf(_("Updated tag '%s' (was %s)\n"), tag,
find_unique_abbrev(&prev, DEFAULT_ABBREV));
UNLEAK(buf);
UNLEAK(ref);

View File

@ -498,7 +498,7 @@ static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len)
strbuf_addstr(&sb, "(bare)");
else {
strbuf_addf(&sb, "%-*s ", abbrev_len,
find_unique_abbrev(wt->head_oid.hash, DEFAULT_ABBREV));
find_unique_abbrev(&wt->head_oid, DEFAULT_ABBREV));
if (wt->is_detached)
strbuf_addstr(&sb, "(detached HEAD)");
else if (wt->head_ref) {
@ -523,7 +523,7 @@ static void measure_widths(struct worktree **wt, int *abbrev, int *maxlen)
if (path_len > *maxlen)
*maxlen = path_len;
sha1_len = strlen(find_unique_abbrev(wt[i]->head_oid.hash, *abbrev));
sha1_len = strlen(find_unique_abbrev(&wt[i]->head_oid, *abbrev));
if (sha1_len > *abbrev)
*abbrev = sha1_len;
}

View File

@ -951,14 +951,14 @@ extern void sha1_file_name(struct strbuf *buf, const unsigned char *sha1);
* more calls to find_unique_abbrev are made.
*
* The `_r` variant writes to a buffer supplied by the caller, which must be at
* least `GIT_SHA1_HEXSZ + 1` bytes. The return value is the number of bytes
* least `GIT_MAX_HEXSZ + 1` bytes. The return value is the number of bytes
* written (excluding the NUL terminator).
*
* Note that while this version avoids the static buffer, it is not fully
* reentrant, as it calls into other non-reentrant git code.
*/
extern const char *find_unique_abbrev(const unsigned char *sha1, int len);
extern int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len);
extern const char *find_unique_abbrev(const struct object_id *oid, int len);
extern int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len);
extern const unsigned char null_sha1[GIT_MAX_RAWSZ];
extern const struct object_id null_oid;

View File

@ -915,11 +915,11 @@ static void show_combined_header(struct combine_diff_path *elem,
"", elem->path, line_prefix, c_meta, c_reset);
printf("%s%sindex ", line_prefix, c_meta);
for (i = 0; i < num_parent; i++) {
abb = find_unique_abbrev(elem->parent[i].oid.hash,
abb = find_unique_abbrev(&elem->parent[i].oid,
abbrev);
printf("%s%s", i ? "," : "", abb);
}
abb = find_unique_abbrev(elem->oid.hash, abbrev);
abb = find_unique_abbrev(&elem->oid, abbrev);
printf("..%s%s\n", abb, c_reset);
if (mode_differs) {

2
diff.c
View File

@ -3811,7 +3811,7 @@ static int similarity_index(struct diff_filepair *p)
static const char *diff_abbrev_oid(const struct object_id *oid, int abbrev)
{
if (startup_info->have_repository)
return find_unique_abbrev(oid->hash, abbrev);
return find_unique_abbrev(oid, abbrev);
else {
char *hex = oid_to_hex(oid);
if (abbrev < 0)

View File

@ -177,7 +177,7 @@ static void show_parents(struct commit *commit, int abbrev, FILE *file)
struct commit_list *p;
for (p = commit->parents; p ; p = p->next) {
struct commit *parent = p->item;
fprintf(file, " %s", find_unique_abbrev(parent->object.oid.hash, abbrev));
fprintf(file, " %s", find_unique_abbrev(&parent->object.oid, abbrev));
}
}
@ -185,7 +185,7 @@ static void show_children(struct rev_info *opt, struct commit *commit, int abbre
{
struct commit_list *p = lookup_decoration(&opt->children, &commit->object);
for ( ; p; p = p->next) {
fprintf(opt->diffopt.file, " %s", find_unique_abbrev(p->item->object.oid.hash, abbrev));
fprintf(opt->diffopt.file, " %s", find_unique_abbrev(&p->item->object.oid, abbrev));
}
}
@ -558,7 +558,7 @@ void show_log(struct rev_info *opt)
if (!opt->graph)
put_revision_mark(opt, commit);
fputs(find_unique_abbrev(commit->object.oid.hash, abbrev_commit), opt->diffopt.file);
fputs(find_unique_abbrev(&commit->object.oid, abbrev_commit), opt->diffopt.file);
if (opt->print_parents)
show_parents(commit, abbrev_commit, opt->diffopt.file);
if (opt->children.name)
@ -620,7 +620,8 @@ void show_log(struct rev_info *opt)
if (!opt->graph)
put_revision_mark(opt, commit);
fputs(find_unique_abbrev(commit->object.oid.hash, abbrev_commit),
fputs(find_unique_abbrev(&commit->object.oid,
abbrev_commit),
opt->diffopt.file);
if (opt->print_parents)
show_parents(commit, abbrev_commit, opt->diffopt.file);
@ -628,8 +629,7 @@ void show_log(struct rev_info *opt)
show_children(opt, commit, abbrev_commit);
if (parent)
fprintf(opt->diffopt.file, " (from %s)",
find_unique_abbrev(parent->object.oid.hash,
abbrev_commit));
find_unique_abbrev(&parent->object.oid, abbrev_commit));
fputs(diff_get_color_opt(&opt->diffopt, DIFF_RESET), opt->diffopt.file);
show_decorations(opt, commit);
if (opt->commit_format == CMIT_FMT_ONELINE) {

View File

@ -742,13 +742,13 @@ static int grab_objectname(const char *name, const struct object_id *oid,
{
if (starts_with(name, "objectname")) {
if (atom->u.objectname.option == O_SHORT) {
v->s = xstrdup(find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
v->s = xstrdup(find_unique_abbrev(oid, DEFAULT_ABBREV));
return 1;
} else if (atom->u.objectname.option == O_FULL) {
v->s = xstrdup(oid_to_hex(oid));
return 1;
} else if (atom->u.objectname.option == O_LENGTH) {
v->s = xstrdup(find_unique_abbrev(oid->hash, atom->u.objectname.length));
v->s = xstrdup(find_unique_abbrev(oid, atom->u.objectname.length));
return 1;
} else
die("BUG: unknown %%(objectname) option");

View File

@ -282,7 +282,7 @@ struct commit_message {
static const char *short_commit_name(struct commit *commit)
{
return find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV);
return find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV);
}
static int get_message(struct commit *commit, struct commit_message *out)

View File

@ -380,7 +380,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
}
advise(" %s %s%s",
find_unique_abbrev(oid->hash, DEFAULT_ABBREV),
find_unique_abbrev(oid, DEFAULT_ABBREV),
type_name(type) ? type_name(type) : "unknown type",
desc.buf);
@ -569,7 +569,7 @@ static void find_abbrev_len_packed(struct min_abbrev_data *mad)
find_abbrev_len_for_pack(p, mad);
}
int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
int find_unique_abbrev_r(char *hex, const struct object_id *oid, int len)
{
struct disambiguate_state ds;
struct min_abbrev_data mad;
@ -596,14 +596,14 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
len = FALLBACK_DEFAULT_ABBREV;
}
sha1_to_hex_r(hex, sha1);
oid_to_hex_r(hex, oid);
if (len == GIT_SHA1_HEXSZ || !len)
return GIT_SHA1_HEXSZ;
mad.init_len = len;
mad.cur_len = len;
mad.hex = hex;
mad.hash = sha1;
mad.hash = oid->hash;
find_abbrev_len_packed(&mad);
@ -621,13 +621,13 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
return mad.cur_len;
}
const char *find_unique_abbrev(const unsigned char *sha1, int len)
const char *find_unique_abbrev(const struct object_id *oid, int len)
{
static int bufno;
static char hexbuffer[4][GIT_MAX_HEXSZ + 1];
char *hex = hexbuffer[bufno];
bufno = (bufno + 1) % ARRAY_SIZE(hexbuffer);
find_unique_abbrev_r(hex, sha1, len);
find_unique_abbrev_r(hex, oid, len);
return hex;
}

View File

@ -878,7 +878,7 @@ void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
{
int r;
strbuf_grow(sb, GIT_SHA1_HEXSZ + 1);
r = find_unique_abbrev_r(sb->buf + sb->len, oid->hash, abbrev_len);
r = find_unique_abbrev_r(sb->buf + sb->len, oid, abbrev_len);
strbuf_setlen(sb, sb->len + r);
}

4
tag.c
View File

@ -46,7 +46,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
return error("%s: cannot verify a non-tag object of type %s.",
name_to_report ?
name_to_report :
find_unique_abbrev(oid->hash, DEFAULT_ABBREV),
find_unique_abbrev(oid, DEFAULT_ABBREV),
type_name(type));
buf = read_sha1_file(oid->hash, &type, &size);
@ -54,7 +54,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
return error("%s: unable to read file.",
name_to_report ?
name_to_report :
find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
find_unique_abbrev(oid, DEFAULT_ABBREV));
ret = run_gpg_verify(buf, size, flags);

View File

@ -461,7 +461,7 @@ static int print_one_push_status(struct ref *ref, const char *dest, int count,
static int measure_abbrev(const struct object_id *oid, int sofar)
{
char hex[GIT_MAX_HEXSZ + 1];
int w = find_unique_abbrev_r(hex, oid->hash, DEFAULT_ABBREV);
int w = find_unique_abbrev_r(hex, oid, DEFAULT_ABBREV);
return (w < sofar) ? sofar : w;
}

View File

@ -1350,7 +1350,7 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
const char *color)
{
status_printf_ln(s, color, _("You are currently cherry-picking commit %s."),
find_unique_abbrev(state->cherry_pick_head_oid.hash, DEFAULT_ABBREV));
find_unique_abbrev(&state->cherry_pick_head_oid, DEFAULT_ABBREV));
if (s->hints) {
if (has_unmerged(s))
status_printf_ln(s, color,
@ -1369,7 +1369,7 @@ static void show_revert_in_progress(struct wt_status *s,
const char *color)
{
status_printf_ln(s, color, _("You are currently reverting commit %s."),
find_unique_abbrev(state->revert_head_oid.hash, DEFAULT_ABBREV));
find_unique_abbrev(&state->revert_head_oid, DEFAULT_ABBREV));
if (s->hints) {
if (has_unmerged(s))
status_printf_ln(s, color,
@ -1489,7 +1489,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
state->detached_from = xstrdup(from);
} else
state->detached_from =
xstrdup(find_unique_abbrev(cb.noid.hash, DEFAULT_ABBREV));
xstrdup(find_unique_abbrev(&cb.noid, DEFAULT_ABBREV));
oidcpy(&state->detached_oid, &cb.noid);
state->detached_at = !get_oid("HEAD", &oid) &&
!oidcmp(&oid, &state->detached_oid);