Commit 15fe583fb97d7e91d4cd62435189c98018f5e145

Stefan Sperling 2018-11-05T17:57:30

search most recently opened pack index first, not last

diff --git a/lib/repository.c b/lib/repository.c
index d82e38e..42722b7 100644
--- a/lib/repository.c
+++ b/lib/repository.c
@@ -578,18 +578,21 @@ got_repo_cache_packidx(struct got_repository *repo, struct got_packidx *packidx)
 		if (repo->packidx_cache[i] == NULL)
 			break;
 	}
-
 	if (i == nitems(repo->packidx_cache)) {
 		err = got_packidx_close(repo->packidx_cache[i - 1]);
 		if (err)
 			return err;
-		memmove(&repo->packidx_cache[1], &repo->packidx_cache[0],
-		    sizeof(repo->packidx_cache) -
-		    sizeof(repo->packidx_cache[0]));
-		i = 0;
 	}
 
-	repo->packidx_cache[i] = packidx;
+	/*
+	 * Insert the new pack index at the front so it will
+	 * be searched first in the future.
+	 */
+	memmove(&repo->packidx_cache[1], &repo->packidx_cache[0],
+	    sizeof(repo->packidx_cache) -
+	    sizeof(repo->packidx_cache[0]));
+	repo->packidx_cache[0] = packidx;
+
 	return NULL;
 }