On Sun, Oct 1, 2017 at 3:08 PM, brian m. carlson <sandals@xxxxxxxxxxxxxxxxxxxx> wrote: > Convert check_connected and the callbacks it takes to use struct > object_id. > > diff --git a/connected.c b/connected.c > index f416b05051..4a47f33270 100644 > --- a/connected.c > +++ b/connected.c > @@ -16,13 +16,13 @@ > * > * Returns 0 if everything is connected, non-zero otherwise. > */ > -int check_connected(sha1_iterate_fn fn, void *cb_data, > +int check_connected(oid_iterate_fn fn, void *cb_data, > struct check_connected_options *opt) > { > struct child_process rev_list = CHILD_PROCESS_INIT; > struct check_connected_options defaults = CHECK_CONNECTED_INIT; > - char commit[41]; > - unsigned char sha1[20]; > + char commit[GIT_MAX_HEXSZ + 1]; > + struct object_id oid; > int err = 0; > struct packed_git *new_pack = NULL; > struct transport *transport; > @@ -77,7 +77,7 @@ int check_connected(sha1_iterate_fn fn, void *cb_data, > > sigchain_push(SIGPIPE, SIG_IGN); > > - commit[40] = '\n'; > + commit[GIT_SHA1_HEXSZ] = '\n'; While we are using SHA1, this and below is correctly using GIT_SHA1_HEXSZ, but the array is defined as GIT_MAX_HEXSZ. Upon switching the hash function, we would plug in the GIT_NEWHASH_HEXSZ here, or if we do it dynamically (using a vtable for hash functions, to switch at run time) we'd need to make the decision based on the hash function. Makes sense. > do { > /* > * If index-pack already checked that: > @@ -87,17 +87,17 @@ int check_connected(sha1_iterate_fn fn, void *cb_data, > * are sure the ref is good and not sending it to > * rev-list for verification. > */ > - if (new_pack && find_pack_entry_one(sha1, new_pack)) > + if (new_pack && find_pack_entry_one(oid.hash, new_pack)) > continue; > > - memcpy(commit, sha1_to_hex(sha1), 40); > - if (write_in_full(rev_list.in, commit, 41) < 0) { > + memcpy(commit, oid_to_hex(&oid), GIT_SHA1_HEXSZ); > + if (write_in_full(rev_list.in, commit, GIT_SHA1_HEXSZ + 1) < 0) { > if (errno != EPIPE && errno != EINVAL) > error_errno(_("failed write to rev-list")); > err = -1; > break; > }