Convert sha1_array_for_each_unique and for_each_abbrev to object_id

Make sha1_array_for_each_unique take a callback using struct object_id.
Since one of these callbacks is an argument to for_each_abbrev, convert
those as well.  Rename various functions, replacing "sha1" with "oid".

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 2017-03-31 01:39:59 +00:00 committed by Junio C Hamano
parent 5d3206d501
commit 1b7ba794d2
9 changed files with 35 additions and 37 deletions

View File

@ -401,10 +401,10 @@ struct object_cb_data {
struct expand_data *expand; struct expand_data *expand;
}; };
static int batch_object_cb(const unsigned char sha1[20], void *vdata) static int batch_object_cb(const struct object_id *oid, void *vdata)
{ {
struct object_cb_data *data = vdata; struct object_cb_data *data = vdata;
hashcpy(data->expand->oid.hash, sha1); oidcpy(&data->expand->oid, oid);
batch_object_write(NULL, data->opt, data->expand); batch_object_write(NULL, data->opt, data->expand);
return 0; return 0;
} }

View File

@ -225,10 +225,10 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
return git_default_config(var, value, cb); return git_default_config(var, value, cb);
} }
static void show_ref(const char *path, const unsigned char *sha1) static void show_ref(const char *path, const struct object_id *oid)
{ {
if (sent_capabilities) { if (sent_capabilities) {
packet_write_fmt(1, "%s %s\n", sha1_to_hex(sha1), path); packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), path);
} else { } else {
struct strbuf cap = STRBUF_INIT; struct strbuf cap = STRBUF_INIT;
@ -244,7 +244,7 @@ static void show_ref(const char *path, const unsigned char *sha1)
strbuf_addstr(&cap, " push-options"); strbuf_addstr(&cap, " push-options");
strbuf_addf(&cap, " agent=%s", git_user_agent_sanitized()); strbuf_addf(&cap, " agent=%s", git_user_agent_sanitized());
packet_write_fmt(1, "%s %s%c%s\n", packet_write_fmt(1, "%s %s%c%s\n",
sha1_to_hex(sha1), path, 0, cap.buf); oid_to_hex(oid), path, 0, cap.buf);
strbuf_release(&cap); strbuf_release(&cap);
sent_capabilities = 1; sent_capabilities = 1;
} }
@ -271,7 +271,7 @@ static int show_ref_cb(const char *path_full, const struct object_id *oid,
} else { } else {
oidset_insert(seen, oid); oidset_insert(seen, oid);
} }
show_ref(path, oid->hash); show_ref(path, oid);
return 0; return 0;
} }
@ -284,7 +284,7 @@ static void show_one_alternate_ref(const char *refname,
if (oidset_insert(seen, oid)) if (oidset_insert(seen, oid))
return; return;
show_ref(".have", oid->hash); show_ref(".have", oid);
} }
static void write_head_info(void) static void write_head_info(void)
@ -295,7 +295,7 @@ static void write_head_info(void)
for_each_alternate_ref(show_one_alternate_ref, &seen); for_each_alternate_ref(show_one_alternate_ref, &seen);
oidset_clear(&seen); oidset_clear(&seen);
if (!sent_capabilities) if (!sent_capabilities)
show_ref("capabilities^{}", null_sha1); show_ref("capabilities^{}", &null_oid);
advertise_shallow_grafts(1); advertise_shallow_grafts(1);

View File

@ -205,9 +205,9 @@ static int anti_reference(const char *refname, const struct object_id *oid, int
return 0; return 0;
} }
static int show_abbrev(const unsigned char *sha1, void *cb_data) static int show_abbrev(const struct object_id *oid, void *cb_data)
{ {
show_rev(NORMAL, sha1, NULL); show_rev(NORMAL, oid->hash, NULL);
return 0; return 0;
} }

View File

@ -1350,7 +1350,7 @@ extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char
extern int get_oid(const char *str, struct object_id *oid); extern int get_oid(const char *str, struct object_id *oid);
typedef int each_abbrev_fn(const unsigned char *sha1, void *); typedef int each_abbrev_fn(const struct object_id *oid, void *);
extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *); extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
extern int set_disambiguate_hint_config(const char *var, const char *value); extern int set_disambiguate_hint_config(const char *var, const char *value);

View File

@ -43,7 +43,7 @@ void sha1_array_clear(struct sha1_array *array)
} }
int sha1_array_for_each_unique(struct sha1_array *array, int sha1_array_for_each_unique(struct sha1_array *array,
for_each_sha1_fn fn, for_each_oid_fn fn,
void *data) void *data)
{ {
int i; int i;
@ -55,7 +55,7 @@ int sha1_array_for_each_unique(struct sha1_array *array,
int ret; int ret;
if (i > 0 && !oidcmp(array->oid + i, array->oid + i - 1)) if (i > 0 && !oidcmp(array->oid + i, array->oid + i - 1))
continue; continue;
ret = fn(array->oid[i].hash, data); ret = fn(array->oid + i, data);
if (ret) if (ret)
return ret; return ret;
} }

View File

@ -14,10 +14,10 @@ void sha1_array_append(struct sha1_array *array, const struct object_id *oid);
int sha1_array_lookup(struct sha1_array *array, const struct object_id *oid); int sha1_array_lookup(struct sha1_array *array, const struct object_id *oid);
void sha1_array_clear(struct sha1_array *array); void sha1_array_clear(struct sha1_array *array);
typedef int (*for_each_sha1_fn)(const unsigned char sha1[20], typedef int (*for_each_oid_fn)(const struct object_id *oid,
void *data); void *data);
int sha1_array_for_each_unique(struct sha1_array *array, int sha1_array_for_each_unique(struct sha1_array *array,
for_each_sha1_fn fn, for_each_oid_fn fn,
void *data); void *data);
#endif /* SHA1_ARRAY_H */ #endif /* SHA1_ARRAY_H */

View File

@ -342,34 +342,32 @@ static int init_object_disambiguation(const char *name, int len,
return 0; return 0;
} }
static int show_ambiguous_object(const unsigned char *sha1, void *data) static int show_ambiguous_object(const struct object_id *oid, void *data)
{ {
const struct disambiguate_state *ds = data; const struct disambiguate_state *ds = data;
struct object_id oid;
struct strbuf desc = STRBUF_INIT; struct strbuf desc = STRBUF_INIT;
int type; int type;
hashcpy(oid.hash, sha1); if (ds->fn && !ds->fn(oid, ds->cb_data))
if (ds->fn && !ds->fn(&oid, ds->cb_data))
return 0; return 0;
type = sha1_object_info(sha1, NULL); type = sha1_object_info(oid->hash, NULL);
if (type == OBJ_COMMIT) { if (type == OBJ_COMMIT) {
struct commit *commit = lookup_commit(sha1); struct commit *commit = lookup_commit(oid->hash);
if (commit) { if (commit) {
struct pretty_print_context pp = {0}; struct pretty_print_context pp = {0};
pp.date_mode.type = DATE_SHORT; pp.date_mode.type = DATE_SHORT;
format_commit_message(commit, " %ad - %s", &desc, &pp); format_commit_message(commit, " %ad - %s", &desc, &pp);
} }
} else if (type == OBJ_TAG) { } else if (type == OBJ_TAG) {
struct tag *tag = lookup_tag(sha1); struct tag *tag = lookup_tag(oid->hash);
if (!parse_tag(tag) && tag->tag) if (!parse_tag(tag) && tag->tag)
strbuf_addf(&desc, " %s", tag->tag); strbuf_addf(&desc, " %s", tag->tag);
} }
advise(" %s %s%s", advise(" %s %s%s",
find_unique_abbrev(sha1, DEFAULT_ABBREV), find_unique_abbrev(oid->hash, DEFAULT_ABBREV),
typename(type) ? typename(type) : "unknown type", typename(type) ? typename(type) : "unknown type",
desc.buf); desc.buf);

View File

@ -551,18 +551,18 @@ static int has_remote(const char *refname, const struct object_id *oid,
return 1; return 1;
} }
static int append_sha1_to_argv(const unsigned char sha1[20], void *data) static int append_oid_to_argv(const struct object_id *oid, void *data)
{ {
struct argv_array *argv = data; struct argv_array *argv = data;
argv_array_push(argv, sha1_to_hex(sha1)); argv_array_push(argv, oid_to_hex(oid));
return 0; return 0;
} }
static int check_has_commit(const unsigned char sha1[20], void *data) static int check_has_commit(const struct object_id *oid, void *data)
{ {
int *has_commit = data; int *has_commit = data;
if (!lookup_commit_reference(sha1)) if (!lookup_commit_reference(oid->hash))
*has_commit = 0; *has_commit = 0;
return 0; return 0;
@ -601,7 +601,7 @@ static int submodule_needs_pushing(const char *path, struct sha1_array *commits)
int needs_pushing = 0; int needs_pushing = 0;
argv_array_push(&cp.args, "rev-list"); argv_array_push(&cp.args, "rev-list");
sha1_array_for_each_unique(commits, append_sha1_to_argv, &cp.args); sha1_array_for_each_unique(commits, append_oid_to_argv, &cp.args);
argv_array_pushl(&cp.args, "--not", "--remotes", "-n", "1" , NULL); argv_array_pushl(&cp.args, "--not", "--remotes", "-n", "1" , NULL);
prepare_submodule_repo_env(&cp.env_array); prepare_submodule_repo_env(&cp.env_array);
@ -687,7 +687,7 @@ int find_unpushed_submodules(struct sha1_array *commits,
/* argv.argv[0] will be ignored by setup_revisions */ /* argv.argv[0] will be ignored by setup_revisions */
argv_array_push(&argv, "find_unpushed_submodules"); argv_array_push(&argv, "find_unpushed_submodules");
sha1_array_for_each_unique(commits, append_sha1_to_argv, &argv); sha1_array_for_each_unique(commits, append_oid_to_argv, &argv);
argv_array_push(&argv, "--not"); argv_array_push(&argv, "--not");
argv_array_pushf(&argv, "--remotes=%s", remotes_name); argv_array_pushf(&argv, "--remotes=%s", remotes_name);
@ -831,9 +831,9 @@ void check_for_new_submodule_commits(struct object_id *oid)
sha1_array_append(&ref_tips_after_fetch, oid); sha1_array_append(&ref_tips_after_fetch, oid);
} }
static int add_sha1_to_argv(const unsigned char sha1[20], void *data) static int add_oid_to_argv(const struct object_id *oid, void *data)
{ {
argv_array_push(data, sha1_to_hex(sha1)); argv_array_push(data, oid_to_hex(oid));
return 0; return 0;
} }
@ -850,10 +850,10 @@ static void calculate_changed_submodule_paths(void)
init_revisions(&rev, NULL); init_revisions(&rev, NULL);
argv_array_push(&argv, "--"); /* argv[0] program name */ argv_array_push(&argv, "--"); /* argv[0] program name */
sha1_array_for_each_unique(&ref_tips_after_fetch, sha1_array_for_each_unique(&ref_tips_after_fetch,
add_sha1_to_argv, &argv); add_oid_to_argv, &argv);
argv_array_push(&argv, "--not"); argv_array_push(&argv, "--not");
sha1_array_for_each_unique(&ref_tips_before_fetch, sha1_array_for_each_unique(&ref_tips_before_fetch,
add_sha1_to_argv, &argv); add_oid_to_argv, &argv);
setup_revisions(argv.argc, argv.argv, &rev, NULL); setup_revisions(argv.argc, argv.argv, &rev, NULL);
if (prepare_revision_walk(&rev)) if (prepare_revision_walk(&rev))
die("revision walk setup failed"); die("revision walk setup failed");

View File

@ -1,9 +1,9 @@
#include "cache.h" #include "cache.h"
#include "sha1-array.h" #include "sha1-array.h"
static int print_sha1(const unsigned char sha1[20], void *data) static int print_oid(const struct object_id *oid, void *data)
{ {
puts(sha1_to_hex(sha1)); puts(oid_to_hex(oid));
return 0; return 0;
} }
@ -27,7 +27,7 @@ int cmd_main(int argc, const char **argv)
} else if (!strcmp(line.buf, "clear")) } else if (!strcmp(line.buf, "clear"))
sha1_array_clear(&array); sha1_array_clear(&array);
else if (!strcmp(line.buf, "for_each_unique")) else if (!strcmp(line.buf, "for_each_unique"))
sha1_array_for_each_unique(&array, print_sha1, NULL); sha1_array_for_each_unique(&array, print_oid, NULL);
else else
die("unknown command: %s", line.buf); die("unknown command: %s", line.buf);
} }