Commit 5278a006 by Josh Triplett

git_packbuilder_write: Allow setting path to NULL to use the default path

If given a NULL path, write to the object path of the repository.

Add tests for the new behavior.
parent 0bc091dd
......@@ -155,7 +155,7 @@ GIT_EXTERN(int) git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb);
* Write the new pack and corresponding index file to path.
*
* @param pb The packbuilder
* @param path to the directory where the packfile and index should be stored
* @param path Path to the directory where the packfile and index should be stored, or NULL for default location
* @param mode permissions to use creating a packfile or 0 for defaults
* @param progress_cb function to call with progress information from the indexer (optional)
* @param progress_cb_payload payload for the progress callback (optional)
......
......@@ -1385,6 +1385,7 @@ int git_packbuilder_write(
void *progress_cb_payload)
{
int error = -1;
git_buf object_path = GIT_BUF_INIT;
git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT;
git_indexer *indexer = NULL;
git_indexer_progress stats;
......@@ -1393,6 +1394,14 @@ int git_packbuilder_write(
PREPARE_PACK;
if (path == NULL) {
if ((error = git_repository_item_path(&object_path, pb->repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0)
goto cleanup;
if ((error = git_buf_joinpath(&object_path, git_buf_cstr(&object_path), "pack")) < 0)
goto cleanup;
path = git_buf_cstr(&object_path);
}
opts.progress_cb = progress_cb;
opts.progress_cb_payload = progress_cb_payload;
......@@ -1415,6 +1424,7 @@ int git_packbuilder_write(
cleanup:
git_indexer_free(indexer);
git_buf_dispose(&object_path);
return error;
}
......
......@@ -151,6 +151,15 @@ void test_pack_packbuilder__get_hash(void)
cl_assert_equal_s(hex, "7f5fa362c664d68ba7221259be1cbd187434b2f0");
}
void test_pack_packbuilder__write_default_path(void)
{
seed_packbuilder();
cl_git_pass(git_packbuilder_write(_packbuilder, NULL, 0, NULL, NULL));
cl_assert(git_path_exists("objects/pack/pack-7f5fa362c664d68ba7221259be1cbd187434b2f0.idx"));
cl_assert(git_path_exists("objects/pack/pack-7f5fa362c664d68ba7221259be1cbd187434b2f0.pack"));
}
static void test_write_pack_permission(mode_t given, mode_t expected)
{
struct stat statbuf;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment