Skip to content

Commit

Permalink
Convert find_unique_abbrev* to struct object_id
Browse files Browse the repository at this point in the history
Convert find_unique_abbrev and find_unique_abbrev_r to each take a
pointer to struct object_id.

Signed-off-by: brian m. carlson <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
bk2204 authored and gitster committed Mar 14, 2018
1 parent 40f5555 commit aab9583
Show file tree
Hide file tree
Showing 28 changed files with 61 additions and 59 deletions.
2 changes: 1 addition & 1 deletion builtin/blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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));
}

/*
Expand Down
4 changes: 2 additions & 2 deletions builtin/describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions builtin/ls-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions builtin/ls-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions builtin/merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion builtin/name-rev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions builtin/receive-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion builtin/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion builtin/rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion builtin/rev-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion builtin/show-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions builtin/show-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
Expand Down
6 changes: 4 additions & 2 deletions builtin/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions builtin/worktree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions combine-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions log-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ 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));
}
}

static void show_children(struct rev_info *opt, struct commit *commit, int abbrev)
{
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));
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -620,16 +620,16 @@ 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);
if (opt->children.name)
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) {
Expand Down
4 changes: 2 additions & 2 deletions ref-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion sequencer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit aab9583

Please sign in to comment.