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 коммит произвёл Junio C Hamano
Родитель 40f5555ca3
Коммит aab9583f7b
28 изменённых файлов: 61 добавлений и 59 удалений

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

@ -499,7 +499,7 @@ static int read_ancestry(const char *graft_file)
static int update_auto_abbrev(int auto_abbrev, struct blame_origin *suspect) 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); auto_abbrev);
int len = strlen(uniq); int len = strlen(uniq);
if (auto_abbrev < len) if (auto_abbrev < len)

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

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

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

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

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

@ -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) 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) 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) { if (!match_cnt) {
struct object_id *cmit_oid = &cmit->object.oid; struct object_id *cmit_oid = &cmit->object.oid;
if (always) { if (always) {
strbuf_add_unique_abbrev(dst, cmit_oid->hash, abbrev); strbuf_add_unique_abbrev(dst, cmit_oid, abbrev);
if (suffix) if (suffix)
strbuf_addstr(dst, suffix); strbuf_addstr(dst, suffix);
return; return;

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

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

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

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

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

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

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

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

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

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

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

@ -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" rp_error("refusing inconsistent update between symref '%s' (%s..%s) and"
" its target '%s' (%s..%s)", " its target '%s' (%s..%s)",
cmd->ref_name, cmd->ref_name,
find_unique_abbrev(cmd->old_oid.hash, DEFAULT_ABBREV), find_unique_abbrev(&cmd->old_oid, DEFAULT_ABBREV),
find_unique_abbrev(cmd->new_oid.hash, DEFAULT_ABBREV), find_unique_abbrev(&cmd->new_oid, DEFAULT_ABBREV),
dst_cmd->ref_name, dst_cmd->ref_name,
find_unique_abbrev(dst_cmd->old_oid.hash, DEFAULT_ABBREV), find_unique_abbrev(&dst_cmd->old_oid, DEFAULT_ABBREV),
find_unique_abbrev(dst_cmd->new_oid.hash, DEFAULT_ABBREV)); find_unique_abbrev(&dst_cmd->new_oid, DEFAULT_ABBREV));
cmd->error_string = dst_cmd->error_string = cmd->error_string = dst_cmd->error_string =
"inconsistent aliased update"; "inconsistent aliased update";

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

@ -109,7 +109,7 @@ static void print_new_head_line(struct commit *commit)
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
printf(_("HEAD is now at %s"), 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); pp_commit_easy(CMIT_FMT_ONELINE, commit, &buf);
if (buf.len > 0) if (buf.len > 0)

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

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

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

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

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

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

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

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

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

@ -99,7 +99,8 @@ static int delete_tag(const char *name, const char *ref,
{ {
if (delete_ref(NULL, ref, oid, 0)) if (delete_ref(NULL, ref, oid, 0))
return 1; 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; return 0;
} }
@ -558,7 +559,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
die("%s", err.buf); die("%s", err.buf);
ref_transaction_free(transaction); ref_transaction_free(transaction);
if (force && !is_null_oid(&prev) && oidcmp(&prev, &object)) 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(buf);
UNLEAK(ref); UNLEAK(ref);

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

@ -498,7 +498,7 @@ static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len)
strbuf_addstr(&sb, "(bare)"); strbuf_addstr(&sb, "(bare)");
else { else {
strbuf_addf(&sb, "%-*s ", abbrev_len, 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) if (wt->is_detached)
strbuf_addstr(&sb, "(detached HEAD)"); strbuf_addstr(&sb, "(detached HEAD)");
else if (wt->head_ref) { else if (wt->head_ref) {
@ -523,7 +523,7 @@ static void measure_widths(struct worktree **wt, int *abbrev, int *maxlen)
if (path_len > *maxlen) if (path_len > *maxlen)
*maxlen = path_len; *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) if (sha1_len > *abbrev)
*abbrev = sha1_len; *abbrev = sha1_len;
} }

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

@ -951,14 +951,14 @@ extern void sha1_file_name(struct strbuf *buf, const unsigned char *sha1);
* more calls to find_unique_abbrev are made. * more calls to find_unique_abbrev are made.
* *
* The `_r` variant writes to a buffer supplied by the caller, which must be at * 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). * written (excluding the NUL terminator).
* *
* Note that while this version avoids the static buffer, it is not fully * Note that while this version avoids the static buffer, it is not fully
* reentrant, as it calls into other non-reentrant git code. * reentrant, as it calls into other non-reentrant git code.
*/ */
extern const char *find_unique_abbrev(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 unsigned char *sha1, 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 unsigned char null_sha1[GIT_MAX_RAWSZ];
extern const struct object_id null_oid; extern const struct object_id null_oid;

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

@ -915,11 +915,11 @@ static void show_combined_header(struct combine_diff_path *elem,
"", elem->path, line_prefix, c_meta, c_reset); "", elem->path, line_prefix, c_meta, c_reset);
printf("%s%sindex ", line_prefix, c_meta); printf("%s%sindex ", line_prefix, c_meta);
for (i = 0; i < num_parent; i++) { 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); abbrev);
printf("%s%s", i ? "," : "", abb); 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); printf("..%s%s\n", abb, c_reset);
if (mode_differs) { if (mode_differs) {

2
diff.c
Просмотреть файл

@ -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) static const char *diff_abbrev_oid(const struct object_id *oid, int abbrev)
{ {
if (startup_info->have_repository) if (startup_info->have_repository)
return find_unique_abbrev(oid->hash, abbrev); return find_unique_abbrev(oid, abbrev);
else { else {
char *hex = oid_to_hex(oid); char *hex = oid_to_hex(oid);
if (abbrev < 0) if (abbrev < 0)

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

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

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

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

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

@ -282,7 +282,7 @@ struct commit_message {
static const char *short_commit_name(struct commit *commit) 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) static int get_message(struct commit *commit, struct commit_message *out)

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

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

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

@ -878,7 +878,7 @@ void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
{ {
int r; int r;
strbuf_grow(sb, GIT_SHA1_HEXSZ + 1); 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); strbuf_setlen(sb, sb->len + r);
} }

4
tag.c
Просмотреть файл

@ -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.", return error("%s: cannot verify a non-tag object of type %s.",
name_to_report ? name_to_report ?
name_to_report : name_to_report :
find_unique_abbrev(oid->hash, DEFAULT_ABBREV), find_unique_abbrev(oid, DEFAULT_ABBREV),
type_name(type)); type_name(type));
buf = read_sha1_file(oid->hash, &type, &size); 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.", return error("%s: unable to read file.",
name_to_report ? name_to_report ?
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); ret = run_gpg_verify(buf, size, flags);

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

@ -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) static int measure_abbrev(const struct object_id *oid, int sofar)
{ {
char hex[GIT_MAX_HEXSZ + 1]; 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; return (w < sofar) ? sofar : w;
} }

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

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