Commit 8af4d074cc3bcc8ea63d75f147be892e4925075b

Vicent Marti 2011-09-29T15:34:17

odb: Let users decide compression level for the loose ODB

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;