Convert check_connected to use struct object_id

Convert check_connected and the callbacks it takes to use struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Oct 15, 2017 at 22:06 UTC 6ccac9eed56280f035d84605b4451ae1721a3100
5 files changed +20 -20
builtin/clone.c
+2 -2
@@ -615,7 +615,7 @@ static void write_followtags(const struct ref *refs, const char *msg)
615 }
616 }
617
618 -static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
618 +static int iterate_ref_map(void *cb_data, struct object_id *oid)
619 {
620 struct ref **rm = cb_data;
621 struct ref *ref = *rm;
@@ -630,7 +630,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
630 if (!ref)
631 return -1;
632
633 - hashcpy(sha1, ref->old_oid.hash);
633 + oidcpy(oid, &ref->old_oid);
634 *rm = ref->next;
635 return 0;
636 }
builtin/fetch.c
+2 -2
@@ -727,7 +727,7 @@ static int update_local_ref(struct ref *ref,
727 }
728 }
729
730 -static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
730 +static int iterate_ref_map(void *cb_data, struct object_id *oid)
731 {
732 struct ref **rm = cb_data;
733 struct ref *ref = *rm;
@@ -737,7 +737,7 @@ static int iterate_ref_map(void *cb_data, unsigned char sha1[20])
737 if (!ref)
738 return -1; /* end of the list */
739 *rm = ref->next;
740 - hashcpy(sha1, ref->old_oid.hash);
740 + oidcpy(oid, &ref->old_oid);
741 return 0;
742 }
743
builtin/receive-pack.c
+5 -5
@@ -870,7 +870,7 @@ static void refuse_unconfigured_deny_delete_current(void)
870 rp_error("%s", _(refuse_unconfigured_deny_delete_current_msg));
871 }
872
873 -static int command_singleton_iterator(void *cb_data, unsigned char sha1[20]);
873 +static int command_singleton_iterator(void *cb_data, struct object_id *oid);
874 static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
875 {
876 static struct lock_file shallow_lock;
@@ -1270,7 +1270,7 @@ static void check_aliased_updates(struct command *commands)
1270 string_list_clear(&ref_list, 0);
1271 }
1272
1273 -static int command_singleton_iterator(void *cb_data, unsigned char sha1[20])
1273 +static int command_singleton_iterator(void *cb_data, struct object_id *oid)
1274 {
1275 struct command **cmd_list = cb_data;
1276 struct command *cmd = *cmd_list;
@@ -1278,7 +1278,7 @@ static int command_singleton_iterator(void *cb_data, unsigned char sha1[20])
1278 if (!cmd || is_null_oid(&cmd->new_oid))
1279 return -1; /* end of list */
1280 *cmd_list = NULL; /* this returns only one */
1281 - hashcpy(sha1, cmd->new_oid.hash);
1281 + oidcpy(oid, &cmd->new_oid);
1282 return 0;
1283 }
1284
@@ -1309,7 +1309,7 @@ struct iterate_data {
1309 struct shallow_info *si;
1310 };
1311
1312 -static int iterate_receive_command_list(void *cb_data, unsigned char sha1[20])
1312 +static int iterate_receive_command_list(void *cb_data, struct object_id *oid)
1313 {
1314 struct iterate_data *data = cb_data;
1315 struct command **cmd_list = &data->cmds;
@@ -1320,7 +1320,7 @@ static int iterate_receive_command_list(void *cb_data, unsigned char sha1[20])
1320 /* to be checked in update_shallow_ref() */
1321 continue;
1322 if (!is_null_oid(&cmd->new_oid) && !cmd->skip_update) {
1323 - hashcpy(sha1, cmd->new_oid.hash);
1323 + oidcpy(oid, &cmd->new_oid);
1324 *cmd_list = cmd->next;
1325 return 0;
1326 }
connected.c
+9 -9
@@ -16,13 +16,13 @@
16 *
17 * Returns 0 if everything is connected, non-zero otherwise.
18 */
19 -int check_connected(sha1_iterate_fn fn, void *cb_data,
19 +int check_connected(oid_iterate_fn fn, void *cb_data,
20 struct check_connected_options *opt)
21 {
22 struct child_process rev_list = CHILD_PROCESS_INIT;
23 struct check_connected_options defaults = CHECK_CONNECTED_INIT;
24 - char commit[41];
25 - unsigned char sha1[20];
24 + char commit[GIT_MAX_HEXSZ + 1];
25 + struct object_id oid;
26 int err = 0;
27 struct packed_git *new_pack = NULL;
28 struct transport *transport;
@@ -32,7 +32,7 @@ int check_connected(sha1_iterate_fn fn, void *cb_data,
32 opt = &defaults;
33 transport = opt->transport;
34
35 - if (fn(cb_data, sha1)) {
35 + if (fn(cb_data, &oid)) {
36 if (opt->err_fd)
37 close(opt->err_fd);
38 return err;
@@ -77,7 +77,7 @@ int check_connected(sha1_iterate_fn fn, void *cb_data,
77
78 sigchain_push(SIGPIPE, SIG_IGN);
79
80 - commit[40] = '\n';
80 + commit[GIT_SHA1_HEXSZ] = '\n';
81 do {
82 /*
83 * If index-pack already checked that:
@@ -87,17 +87,17 @@ int check_connected(sha1_iterate_fn fn, void *cb_data,
87 * are sure the ref is good and not sending it to
88 * rev-list for verification.
89 */
90 - if (new_pack && find_pack_entry_one(sha1, new_pack))
90 + if (new_pack && find_pack_entry_one(oid.hash, new_pack))
91 continue;
92
93 - memcpy(commit, sha1_to_hex(sha1), 40);
94 - if (write_in_full(rev_list.in, commit, 41) < 0) {
93 + memcpy(commit, oid_to_hex(&oid), GIT_SHA1_HEXSZ);
94 + if (write_in_full(rev_list.in, commit, GIT_SHA1_HEXSZ + 1) < 0) {
95 if (errno != EPIPE && errno != EINVAL)
96 error_errno(_("failed write to rev-list"));
97 err = -1;
98 break;
99 }
100 - } while (!fn(cb_data, sha1));
100 + } while (!fn(cb_data, &oid));
101
102 if (close(rev_list.in))
103 err = error_errno(_("failed to close rev-list's stdin"));
connected.h
+2 -2
@@ -8,7 +8,7 @@ struct transport;
8 * When called after returning the name for the last object, return -1
9 * to signal EOF, otherwise return 0.
10 */
11 -typedef int (*sha1_iterate_fn)(void *, unsigned char [20]);
11 +typedef int (*oid_iterate_fn)(void *, struct object_id *oid);
12
13 /*
14 * Named-arguments struct for check_connected. All arguments are
@@ -51,7 +51,7 @@ struct check_connected_options {
51 *
52 * If "opt" is NULL, behaves as if CHECK_CONNECTED_INIT was passed.
53 */
54 -int check_connected(sha1_iterate_fn fn, void *cb_data,
54 +int check_connected(oid_iterate_fn fn, void *cb_data,
55 struct check_connected_options *opt);
56
57 #endif /* CONNECTED_H */