Commit 5ec4aee952ed0db040277c16d1ac015c6e4bee3b

Patrick Steinhardt 2017-11-12T10:35:18

indexer: add ability to select connectivity checks Right now, we simply turn on connectivity checks in the indexer as soon as we have access to an object database. But seeing that the connectivity checks may incur additional overhead, we do want the user to decide for himself whether he wants to allow those checks. Furthermore, it might also be desirable to check connectivity in case where no object database is given at all, e.g. in case where a fully connected pack file is expected. Add a flag `verify` to `git_indexer_options` to enable additional verification checks. Also avoid to query the ODB in case none is given to allow users to enable checks when they do not have an ODB.

diff --git a/include/git2/indexer.h b/include/git2/indexer.h
index 53a59fc..94d8785 100644
--- a/include/git2/indexer.h
+++ b/include/git2/indexer.h
@@ -22,6 +22,9 @@ typedef struct git_indexer_options {
 	git_transfer_progress_cb progress_cb;
 	/** progress_cb_payload payload for the progress callback */
 	void *progress_cb_payload;
+
+	/** Do connectivity checks for the received pack */
+	unsigned char verify;
 } git_indexer_options;
 
 #define GIT_INDEXER_OPTIONS_VERSION 1
diff --git a/src/indexer.c b/src/indexer.c
index fc9a3bb..019682c 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -148,7 +148,7 @@ int git_indexer_new(
 	idx->expected_oids = git_oidmap_alloc();
 	GITERR_CHECK_ALLOC(idx->expected_oids);
 
-	idx->do_verify = !!idx->odb;
+	idx->do_verify = opts.verify;
 
 	if (git_repository__fsync_gitdir)
 		idx->do_fsync = 1;
@@ -315,7 +315,7 @@ static void add_expected_oid(git_indexer *idx, const git_oid *oid)
 	 * because we have already processed it as part of our pack file, we do
 	 * not have to expect it.
 	 */
-	if (!git_odb_exists(idx->odb, oid) &&
+	if ((!idx->odb || !git_odb_exists(idx->odb, oid)) &&
 	    !git_oidmap_exists(idx->pack->idx_cache, oid) &&
 	    !git_oidmap_exists(idx->expected_oids, oid)) {
 		    git_oid *dup = git__malloc(sizeof(*oid));
@@ -350,7 +350,7 @@ static int check_object_connectivity(git_indexer *idx, const git_rawobj *obj)
 	 * Check whether this is a known object. If so, we can just continue as
 	 * we assume that the ODB has a complete graph.
 	 */
-	if (git_odb_exists(idx->odb, &object->cached.oid))
+	if (idx->odb && git_odb_exists(idx->odb, &object->cached.oid))
 		return 0;
 
 	switch (obj->type) {