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>

brian m. carlson committed Mar 31, 2017 at 01:39 UTC 1b7ba794d21836f72e5888db63ab790077c04e1b
9 files changed +35 -37
builtin/cat-file.c
+2 -2
@@ -401,10 +401,10 @@ struct object_cb_data {
401 struct expand_data *expand;
402 };
403
404 -static int batch_object_cb(const unsigned char sha1[20], void *vdata)
404 +static int batch_object_cb(const struct object_id *oid, void *vdata)
405 {
406 struct object_cb_data *data = vdata;
407 - hashcpy(data->expand->oid.hash, sha1);
407 + oidcpy(&data->expand->oid, oid);
408 batch_object_write(NULL, data->opt, data->expand);
409 return 0;
410 }
builtin/receive-pack.c
+6 -6
@@ -225,10 +225,10 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
225 return git_default_config(var, value, cb);
226 }
227
228 -static void show_ref(const char *path, const unsigned char *sha1)
228 +static void show_ref(const char *path, const struct object_id *oid)
229 {
230 if (sent_capabilities) {
231 - packet_write_fmt(1, "%s %s\n", sha1_to_hex(sha1), path);
231 + packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), path);
232 } else {
233 struct strbuf cap = STRBUF_INIT;
234
@@ -244,7 +244,7 @@ static void show_ref(const char *path, const unsigned char *sha1)
244 strbuf_addstr(&cap, " push-options");
245 strbuf_addf(&cap, " agent=%s", git_user_agent_sanitized());
246 packet_write_fmt(1, "%s %s%c%s\n",
247 - sha1_to_hex(sha1), path, 0, cap.buf);
247 + oid_to_hex(oid), path, 0, cap.buf);
248 strbuf_release(&cap);
249 sent_capabilities = 1;
250 }
@@ -271,7 +271,7 @@ static int show_ref_cb(const char *path_full, const struct object_id *oid,
271 } else {
272 oidset_insert(seen, oid);
273 }
274 - show_ref(path, oid->hash);
274 + show_ref(path, oid);
275 return 0;
276 }
277
@@ -284,7 +284,7 @@ static void show_one_alternate_ref(const char *refname,
284 if (oidset_insert(seen, oid))
285 return;
286
287 - show_ref(".have", oid->hash);
287 + show_ref(".have", oid);
288 }
289
290 static void write_head_info(void)
@@ -295,7 +295,7 @@ static void write_head_info(void)
295 for_each_alternate_ref(show_one_alternate_ref, &seen);
296 oidset_clear(&seen);
297 if (!sent_capabilities)
298 - show_ref("capabilities^{}", null_sha1);
298 + show_ref("capabilities^{}", &null_oid);
299
300 advertise_shallow_grafts(1);
301
builtin/rev-parse.c
+2 -2
@@ -205,9 +205,9 @@ static int anti_reference(const char *refname, const struct object_id *oid, int
205 return 0;
206 }
207
208 -static int show_abbrev(const unsigned char *sha1, void *cb_data)
208 +static int show_abbrev(const struct object_id *oid, void *cb_data)
209 {
210 - show_rev(NORMAL, sha1, NULL);
210 + show_rev(NORMAL, oid->hash, NULL);
211 return 0;
212 }
213
cache.h
+1 -1
@@ -1350,7 +1350,7 @@ extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char
1350
1351 extern int get_oid(const char *str, struct object_id *oid);
1352
1353 -typedef int each_abbrev_fn(const unsigned char *sha1, void *);
1353 +typedef int each_abbrev_fn(const struct object_id *oid, void *);
1354 extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
1355
1356 extern int set_disambiguate_hint_config(const char *var, const char *value);
sha1-array.c
+2 -2
@@ -43,7 +43,7 @@ void sha1_array_clear(struct sha1_array *array)
43 }
44
45 int sha1_array_for_each_unique(struct sha1_array *array,
46 - for_each_sha1_fn fn,
46 + for_each_oid_fn fn,
47 void *data)
48 {
49 int i;
@@ -55,7 +55,7 @@ int sha1_array_for_each_unique(struct sha1_array *array,
55 int ret;
56 if (i > 0 && !oidcmp(array->oid + i, array->oid + i - 1))
57 continue;
58 - ret = fn(array->oid[i].hash, data);
58 + ret = fn(array->oid + i, data);
59 if (ret)
60 return ret;
61 }
sha1-array.h
+3 -3
@@ -14,10 +14,10 @@ void sha1_array_append(struct sha1_array *array, const struct object_id *oid);
14 int sha1_array_lookup(struct sha1_array *array, const struct object_id *oid);
15 void sha1_array_clear(struct sha1_array *array);
16
17 -typedef int (*for_each_sha1_fn)(const unsigned char sha1[20],
18 - void *data);
17 +typedef int (*for_each_oid_fn)(const struct object_id *oid,
18 + void *data);
19 int sha1_array_for_each_unique(struct sha1_array *array,
20 - for_each_sha1_fn fn,
20 + for_each_oid_fn fn,
21 void *data);
22
23 #endif /* SHA1_ARRAY_H */
sha1_name.c
+6 -8
@@ -342,34 +342,32 @@ static int init_object_disambiguation(const char *name, int len,
342 return 0;
343 }
344
345 -static int show_ambiguous_object(const unsigned char *sha1, void *data)
345 +static int show_ambiguous_object(const struct object_id *oid, void *data)
346 {
347 const struct disambiguate_state *ds = data;
348 - struct object_id oid;
348 struct strbuf desc = STRBUF_INIT;
349 int type;
350
351
353 - hashcpy(oid.hash, sha1);
354 - if (ds->fn && !ds->fn(&oid, ds->cb_data))
352 + if (ds->fn && !ds->fn(oid, ds->cb_data))
353 return 0;
354
357 - type = sha1_object_info(sha1, NULL);
355 + type = sha1_object_info(oid->hash, NULL);
356 if (type == OBJ_COMMIT) {
359 - struct commit *commit = lookup_commit(sha1);
357 + struct commit *commit = lookup_commit(oid->hash);
358 if (commit) {
359 struct pretty_print_context pp = {0};
360 pp.date_mode.type = DATE_SHORT;
361 format_commit_message(commit, " %ad - %s", &desc, &pp);
362 }
363 } else if (type == OBJ_TAG) {
366 - struct tag *tag = lookup_tag(sha1);
364 + struct tag *tag = lookup_tag(oid->hash);
365 if (!parse_tag(tag) && tag->tag)
366 strbuf_addf(&desc, " %s", tag->tag);
367 }
368
369 advise(" %s %s%s",
372 - find_unique_abbrev(sha1, DEFAULT_ABBREV),
370 + find_unique_abbrev(oid->hash, DEFAULT_ABBREV),
371 typename(type) ? typename(type) : "unknown type",
372 desc.buf);
373
submodule.c
+10 -10
@@ -551,18 +551,18 @@ static int has_remote(const char *refname, const struct object_id *oid,
551 return 1;
552 }
553
554 -static int append_sha1_to_argv(const unsigned char sha1[20], void *data)
554 +static int append_oid_to_argv(const struct object_id *oid, void *data)
555 {
556 struct argv_array *argv = data;
557 - argv_array_push(argv, sha1_to_hex(sha1));
557 + argv_array_push(argv, oid_to_hex(oid));
558 return 0;
559 }
560
561 -static int check_has_commit(const unsigned char sha1[20], void *data)
561 +static int check_has_commit(const struct object_id *oid, void *data)
562 {
563 int *has_commit = data;
564
565 - if (!lookup_commit_reference(sha1))
565 + if (!lookup_commit_reference(oid->hash))
566 *has_commit = 0;
567
568 return 0;
@@ -601,7 +601,7 @@ static int submodule_needs_pushing(const char *path, struct sha1_array *commits)
601 int needs_pushing = 0;
602
603 argv_array_push(&cp.args, "rev-list");
604 - sha1_array_for_each_unique(commits, append_sha1_to_argv, &cp.args);
604 + sha1_array_for_each_unique(commits, append_oid_to_argv, &cp.args);
605 argv_array_pushl(&cp.args, "--not", "--remotes", "-n", "1" , NULL);
606
607 prepare_submodule_repo_env(&cp.env_array);
@@ -687,7 +687,7 @@ int find_unpushed_submodules(struct sha1_array *commits,
687
688 /* argv.argv[0] will be ignored by setup_revisions */
689 argv_array_push(&argv, "find_unpushed_submodules");
690 - sha1_array_for_each_unique(commits, append_sha1_to_argv, &argv);
690 + sha1_array_for_each_unique(commits, append_oid_to_argv, &argv);
691 argv_array_push(&argv, "--not");
692 argv_array_pushf(&argv, "--remotes=%s", remotes_name);
693
@@ -831,9 +831,9 @@ void check_for_new_submodule_commits(struct object_id *oid)
831 sha1_array_append(&ref_tips_after_fetch, oid);
832 }
833
834 -static int add_sha1_to_argv(const unsigned char sha1[20], void *data)
834 +static int add_oid_to_argv(const struct object_id *oid, void *data)
835 {
836 - argv_array_push(data, sha1_to_hex(sha1));
836 + argv_array_push(data, oid_to_hex(oid));
837 return 0;
838 }
839
@@ -850,10 +850,10 @@ static void calculate_changed_submodule_paths(void)
850 init_revisions(&rev, NULL);
851 argv_array_push(&argv, "--"); /* argv[0] program name */
852 sha1_array_for_each_unique(&ref_tips_after_fetch,
853 - add_sha1_to_argv, &argv);
853 + add_oid_to_argv, &argv);
854 argv_array_push(&argv, "--not");
855 sha1_array_for_each_unique(&ref_tips_before_fetch,
856 - add_sha1_to_argv, &argv);
856 + add_oid_to_argv, &argv);
857 setup_revisions(argv.argc, argv.argv, &rev, NULL);
858 if (prepare_revision_walk(&rev))
859 die("revision walk setup failed");
t/helper/test-sha1-array.c
+3 -3
@@ -1,9 +1,9 @@
1 #include "cache.h"
2 #include "sha1-array.h"
3
4 -static int print_sha1(const unsigned char sha1[20], void *data)
4 +static int print_oid(const struct object_id *oid, void *data)
5 {
6 - puts(sha1_to_hex(sha1));
6 + puts(oid_to_hex(oid));
7 return 0;
8 }
9
@@ -27,7 +27,7 @@ int cmd_main(int argc, const char **argv)
27 } else if (!strcmp(line.buf, "clear"))
28 sha1_array_clear(&array);
29 else if (!strcmp(line.buf, "for_each_unique"))
30 - sha1_array_for_each_unique(&array, print_sha1, NULL);
30 + sha1_array_for_each_unique(&array, print_oid, NULL);
31 else
32 die("unknown command: %s", line.buf);
33 }