commit 160bbe2e336908947c078a78e3ae58100a38e9fc from: Stefan Sperling date: Wed Mar 18 16:13:46 2020 UTC jump right to the index of the first delta commit - e6c1173dcf57c322cbb74af339c615c983c190f3 commit + 160bbe2e336908947c078a78e3ae58100a38e9fc blob - 058e5043c887bbd0abf19e56bf3c6d7dfe952f16 blob + b4e4dc21f9308f616d81790239027df7bcacdb7b --- libexec/got-index-pack/got-index-pack.c +++ libexec/got-index-pack/got-index-pack.c @@ -560,7 +560,7 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmp SHA1_CTX ctx; uint8_t packidx_hash[SHA1_DIGEST_LENGTH]; ssize_t r, w; - int pass, have_ref_deltas = 0; + int pass, have_ref_deltas = 0, first_delta_idx = -1; size_t mapoff = 0; /* Check pack file header. */ @@ -688,11 +688,18 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmp obj->type == GOT_OBJ_TYPE_TAG) { obj->valid = 1; nloose++; - } else if (obj->type == GOT_OBJ_TYPE_REF_DELTA) - have_ref_deltas = 1; + } else { + if (first_delta_idx == -1) + first_delta_idx = i; + if (obj->type == GOT_OBJ_TYPE_REF_DELTA) + have_ref_deltas = 1; + } } nvalid = nloose; + if (first_delta_idx == -1) + first_delta_idx = 0; + /* In order to resolve ref deltas we need an in-progress pack index. */ if (have_ref_deltas) make_packidx(&packidx, nobj, objects); @@ -713,7 +720,7 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmp * Offset deltas can always be resolved in one pass * unless the packfile is corrupt. */ - for (i = 0; i < nobj; i++) { + for (i = first_delta_idx; i < nobj; i++) { obj = &objects[i]; if (obj->type != GOT_OBJ_TYPE_REF_DELTA && obj->type != GOT_OBJ_TYPE_OFFSET_DELTA)