commit dd088d9503d8e7cebbb30c535d8e4d11556c8d30 from: Stefan Sperling date: Wed Oct 06 19:49:06 2021 UTC let 'got fetch' send all references to the server to avoid redundant downloads Problem reported by naddy. ok naddy commit - 0c079dbc7e6ed9857d4a13d908cc6858d57c81ec commit + dd088d9503d8e7cebbb30c535d8e4d11556c8d30 blob - 3b8efe373216c218b36b32818d61e5a06d485b73 blob + 06d450cdb8bfabc4d5e9452f3df3200f0c05e6d5 --- lib/fetch.c +++ lib/fetch.c @@ -298,6 +298,9 @@ got_fetch_pack(struct got_object_id **pack_hash, struc &packfile_size_cur, (*pack_hash)->sha1, &fetchibuf); if (err != NULL) goto done; + /* Don't report size progress for an empty pack file. */ + if (packfile_size_cur <= ssizeof(pack_hdr) + SHA1_DIGEST_LENGTH) + packfile_size_cur = 0; if (!done && refname && id) { err = got_pathlist_insert(NULL, refs, refname, id); if (err) @@ -404,8 +407,11 @@ got_fetch_pack(struct got_object_id **pack_hash, struc * If the pack file contains no objects, we may only need to update * references in our repository. The caller will take care of that. */ - if (nobj == 0) + if (nobj == 0) { + free(*pack_hash); + *pack_hash = NULL; goto done; + } if (lseek(packfd, 0, SEEK_SET) == -1) { err = got_error_from_errno("lseek"); blob - 96308310d28fd9186f083ce3c0028cceb9cd61b5 blob + 171700f1fa26666e69adceb379ea1e594e5513d7 --- libexec/got-fetch-pack/got-fetch-pack.c +++ libexec/got-fetch-pack/got-fetch-pack.c @@ -57,7 +57,6 @@ struct got_object *indexed; static int chattygot; -static struct got_object_id zhash = {.sha1={0}}; static const struct got_capability got_capabilities[] = { { GOT_CAPA_AGENT, "got/" GOT_VERSION_STR }, @@ -516,10 +515,9 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1, if (nwant == 0) goto done; - for (i = 0; i < nref; i++) { - if (got_object_id_cmp(&have[i], &zhash) == 0) - continue; - got_sha1_digest_to_str(have[i].sha1, hashstr, sizeof(hashstr)); + TAILQ_FOREACH(pe, have_refs, entry) { + struct got_object_id *id = pe->data; + got_sha1_digest_to_str(id->sha1, hashstr, sizeof(hashstr)); n = snprintf(buf, sizeof(buf), "have %s\n", hashstr); if (n >= sizeof(buf)) { err = got_error(GOT_ERR_NO_SPACE);