odb: Let users decide compression level for the loose ODB
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57
diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h
index 9d0bfdd..eb8830f 100644
--- a/include/git2/odb_backend.h
+++ b/include/git2/odb_backend.h
@@ -93,7 +93,7 @@ typedef enum {
} git_odb_streammode;
GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir);
-GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir);
+GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir, int compression_level, int do_fsync);
GIT_END_DECL
diff --git a/src/odb.c b/src/odb.c
index 02809be..60789cf 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -321,7 +321,7 @@ static int add_default_backends(git_odb *db, const char *objects_dir, int as_alt
int error;
/* add the loose object backend */
- error = git_odb_backend_loose(&loose, objects_dir);
+ error = git_odb_backend_loose(&loose, objects_dir, -1, 0);
if (error < GIT_SUCCESS)
return error;
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 3ca46d1..4b2216b 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -807,7 +807,11 @@ static void loose_backend__free(git_odb_backend *_backend)
free(backend);
}
-int git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir)
+int git_odb_backend_loose(
+ git_odb_backend **backend_out,
+ const char *objects_dir,
+ int compression_level,
+ int do_fsync)
{
loose_backend *backend;
@@ -821,8 +825,11 @@ int git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir
return GIT_ENOMEM;
}
- backend->object_zlib_level = Z_BEST_SPEED;
- backend->fsync_object_files = 0;
+ if (compression_level < 0)
+ compression_level = Z_BEST_SPEED;
+
+ backend->object_zlib_level = compression_level;
+ backend->fsync_object_files = do_fsync;
backend->parent.read = &loose_backend__read;
backend->parent.write = &loose_backend__write;