Skip to content

Commit 5ec4aee

Browse files
committed
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.
1 parent c16556a commit 5ec4aee

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

include/git2/indexer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ typedef struct git_indexer_options {
2222
git_transfer_progress_cb progress_cb;
2323
/** progress_cb_payload payload for the progress callback */
2424
void *progress_cb_payload;
25+
26+
/** Do connectivity checks for the received pack */
27+
unsigned char verify;
2528
} git_indexer_options;
2629

2730
#define GIT_INDEXER_OPTIONS_VERSION 1

src/indexer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ int git_indexer_new(
148148
idx->expected_oids = git_oidmap_alloc();
149149
GITERR_CHECK_ALLOC(idx->expected_oids);
150150

151-
idx->do_verify = !!idx->odb;
151+
idx->do_verify = opts.verify;
152152

153153
if (git_repository__fsync_gitdir)
154154
idx->do_fsync = 1;
@@ -315,7 +315,7 @@ static void add_expected_oid(git_indexer *idx, const git_oid *oid)
315315
* because we have already processed it as part of our pack file, we do
316316
* not have to expect it.
317317
*/
318-
if (!git_odb_exists(idx->odb, oid) &&
318+
if ((!idx->odb || !git_odb_exists(idx->odb, oid)) &&
319319
!git_oidmap_exists(idx->pack->idx_cache, oid) &&
320320
!git_oidmap_exists(idx->expected_oids, oid)) {
321321
git_oid *dup = git__malloc(sizeof(*oid));
@@ -350,7 +350,7 @@ static int check_object_connectivity(git_indexer *idx, const git_rawobj *obj)
350350
* Check whether this is a known object. If so, we can just continue as
351351
* we assume that the ODB has a complete graph.
352352
*/
353-
if (git_odb_exists(idx->odb, &object->cached.oid))
353+
if (idx->odb && git_odb_exists(idx->odb, &object->cached.oid))
354354
return 0;
355355

356356
switch (obj->type) {

0 commit comments

Comments
 (0)