jump right to the index of the first delta
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
diff --git a/libexec/got-index-pack/got-index-pack.c b/libexec/got-index-pack/got-index-pack.c
index 058e504..b4e4dc2 100644
--- a/libexec/got-index-pack/got-index-pack.c
+++ b/libexec/got-index-pack/got-index-pack.c
@@ -560,7 +560,7 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmpfile,
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 *tmpfile,
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 *tmpfile,
* 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)