summaryrefslogtreecommitdiff
path: root/src/odb.c
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2021-11-08 14:48:45 +0100
committerJosh Triplett <josh@joshtriplett.org>2021-11-08 14:59:01 +0100
commit81662d432c585df651a9f733670ac577f6b555a5 (patch)
treee01d3383073dfba7abd28b565b6ce62aebc7aa66 /src/odb.c
parent3993e9aebc7d293e9aec420800c581f7f234def7 (diff)
downloadlibgit2-81662d432c585df651a9f733670ac577f6b555a5.tar.gz
Support checking for object existence without refresh
Looking up a non-existent object currently always invokes `git_odb_refresh`. If looking up a large batch of objects, many of which may legitimately not exist, this will repeatedly refresh the ODB to no avail. Add a `git_odb_exists_ext` that accepts flags controlling the ODB lookup, and add a flag to suppress the refresh. This allows the user to control if and when they refresh (for instance, refreshing once before starting the batch).
Diffstat (limited to 'src/odb.c')
-rw-r--r--src/odb.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/odb.c b/src/odb.c
index 7bf575474..79328672b 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -883,6 +883,11 @@ int git_odb__freshen(git_odb *db, const git_oid *id)
int git_odb_exists(git_odb *db, const git_oid *id)
{
+ return git_odb_exists_ext(db, id, 0);
+}
+
+int git_odb_exists_ext(git_odb *db, const git_oid *id, unsigned int flags)
+{
git_odb_object *object;
GIT_ASSERT_ARG(db);
@@ -899,7 +904,7 @@ int git_odb_exists(git_odb *db, const git_oid *id)
if (odb_exists_1(db, id, false))
return 1;
- if (!git_odb_refresh(db))
+ if (!(flags & GIT_ODB_LOOKUP_NO_REFRESH) && !git_odb_refresh(db))
return odb_exists_1(db, id, true);
/* Failed to refresh, hence not found */