diff options
author | Ben Straub <bstraub@github.com> | 2012-07-26 13:12:21 -0700 |
---|---|---|
committer | Ben Straub <bstraub@github.com> | 2012-07-26 13:12:21 -0700 |
commit | b401bace1b28ac23990382605791eddbeda09d9b (patch) | |
tree | c6611b78a99a3fdcbac9084deac2ab397b6fe639 | |
parent | ef9905c9902a9ffad71c8acddec74dc0d8e866de (diff) | |
download | libgit2-b401bace1b28ac23990382605791eddbeda09d9b.tar.gz |
Restructure for better checkout options
* Removed the #define for defaults
* Promoted progress structure to top-level API call
argument
-rw-r--r-- | include/git2/checkout.h | 29 | ||||
-rw-r--r-- | include/git2/clone.h | 18 | ||||
-rw-r--r-- | src/checkout.c | 16 | ||||
-rw-r--r-- | src/clone.c | 3 | ||||
-rw-r--r-- | tests-clar/checkout/checkout.c | 10 | ||||
-rw-r--r-- | tests-clar/clone/clone.c | 12 |
6 files changed, 49 insertions, 39 deletions
diff --git a/include/git2/checkout.h b/include/git2/checkout.h index ff1c4132a..6e0a05f7c 100644 --- a/include/git2/checkout.h +++ b/include/git2/checkout.h @@ -22,26 +22,17 @@ GIT_BEGIN_DECL -#define GIT_CHECKOUT_OVERWRITE_EXISTING 0 +#define GIT_CHECKOUT_OVERWRITE_EXISTING 0 /* default */ #define GIT_CHECKOUT_SKIP_EXISTING 1 - +/* Use zeros to indicate default settings */ typedef struct git_checkout_opts { - git_indexer_stats stats; - int existing_file_action; - int apply_filters; - int dir_mode; - int file_open_mode; + int existing_file_action; /* default: GIT_CHECKOUT_OVERWRITE_EXISTING */ + int disable_filters; + int dir_mode; /* default is 0755 */ + int file_open_mode; /* default is O_CREAT | O_TRUNC | O_WRONLY */ } git_checkout_opts; -#define GIT_CHECKOUT_DEFAULT_OPTS { \ - {0}, \ - GIT_CHECKOUT_OVERWRITE_EXISTING, \ - true, \ - GIT_DIR_MODE, \ - O_CREAT|O_TRUNC|O_WRONLY \ -} - /** * Updates files in the working tree to match the index. * @@ -49,7 +40,9 @@ typedef struct git_checkout_opts { * @param opts specifies checkout options (may be NULL) * @return 0 on success, GIT_ERROR otherwise (use git_error_last for information about the error) */ -GIT_EXTERN(int) git_checkout_index(git_repository *repo, git_checkout_opts *opts); +GIT_EXTERN(int) git_checkout_index(git_repository *repo, + git_checkout_opts *opts, + git_indexer_stats *stats); /** * Updates files in the working tree to match the commit pointed to by HEAD. @@ -58,7 +51,9 @@ GIT_EXTERN(int) git_checkout_index(git_repository *repo, git_checkout_opts *opts * @param opts specifies checkout options (may be NULL) * @return 0 on success, GIT_ERROR otherwise (use git_error_last for information about the error) */ -GIT_EXTERN(int) git_checkout_head(git_repository *repo, git_checkout_opts *opts); +GIT_EXTERN(int) git_checkout_head(git_repository *repo, + git_checkout_opts *opts, + git_indexer_stats *stats); /** @} */ GIT_END_DECL diff --git a/include/git2/clone.h b/include/git2/clone.h index 5468f09be..73b6ea54c 100644 --- a/include/git2/clone.h +++ b/include/git2/clone.h @@ -10,6 +10,7 @@ #include "common.h" #include "types.h" #include "indexer.h" +#include "checkout.h" /** @@ -27,10 +28,16 @@ GIT_BEGIN_DECL * @param out pointer that will receive the resulting repository object * @param origin_url repository to clone from * @param workdir_path local directory to clone to - * @param stats pointer to structure that receives progress information (may be NULL) + * @param fetch_stats pointer to structure that receives fetch progress information (may be NULL) + * @param checkout_opts options for the checkout step (may be NULL) * @return 0 on success, GIT_ERROR otherwise (use git_error_last for information about the error) */ -GIT_EXTERN(int) git_clone(git_repository **out, const char *origin_url, const char *workdir_path, git_indexer_stats *stats); +GIT_EXTERN(int) git_clone(git_repository **out, + const char *origin_url, + const char *workdir_path, + git_indexer_stats *fetch_stats, + git_indexer_stats *checkout_stats, + git_checkout_opts *checkout_opts); /** * TODO @@ -38,10 +45,13 @@ GIT_EXTERN(int) git_clone(git_repository **out, const char *origin_url, const ch * @param out pointer that will receive the resulting repository object * @param origin_url repository to clone from * @param dest_path local directory to clone to - * @param stats pointer to structure that receives progress information (may be NULL) + * @param fetch_stats pointer to structure that receives fetch progress information (may be NULL) * @return 0 on success, GIT_ERROR otherwise (use git_error_last for information about the error) */ -GIT_EXTERN(int) git_clone_bare(git_repository **out, const char *origin_url, const char *dest_path, git_indexer_stats *stats); +GIT_EXTERN(int) git_clone_bare(git_repository **out, + const char *origin_url, + const char *dest_path, + git_indexer_stats *fetch_stats); /** @} */ GIT_END_DECL diff --git a/src/checkout.c b/src/checkout.c index d5f69c648..342a1ba8d 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -27,6 +27,7 @@ GIT_BEGIN_DECL typedef struct tree_walk_data { + git_indexer_stats *stats; git_checkout_opts *opts; git_repository *repo; git_odb *odb; @@ -120,21 +121,23 @@ static int checkout_walker(const char *path, const git_tree_entry *entry, void * } git_buf_free(&fnbuf); - data->opts->stats.processed++; + data->stats->processed++; return retcode; } -int git_checkout_index(git_repository *repo, git_checkout_opts *opts) +int git_checkout_index(git_repository *repo, git_checkout_opts *opts, git_indexer_stats *stats) { int retcode = GIT_ERROR; - git_checkout_opts default_opts = GIT_CHECKOUT_DEFAULT_OPTS; + git_indexer_stats dummy_stats; + git_checkout_opts default_opts = {0}; git_tree *tree; tree_walk_data payload; git_config *cfg; assert(repo); if (!opts) opts = &default_opts; + if (!stats) stats = &dummy_stats; if (git_repository_is_bare(repo)) { giterr_set(GITERR_INVALID, "Checkout is not allowed for bare repositories"); @@ -150,12 +153,13 @@ int git_checkout_index(git_repository *repo, git_checkout_opts *opts) git_config_free(cfg); } - opts->stats.total = opts->stats.processed = 0; + stats->total = stats->processed = 0; + payload.stats = stats; payload.opts = opts; payload.repo = repo; if (git_repository_odb(&payload.odb, repo) < 0) return GIT_ERROR; - /* TODO: opts->stats.total is never calculated. */ + /* TODO: stats.total is never calculated. */ if (!git_repository_head_tree(&tree, repo)) { /* Checkout the files */ @@ -170,7 +174,7 @@ int git_checkout_index(git_repository *repo, git_checkout_opts *opts) } -int git_checkout_head(git_repository *repo, git_checkout_opts *opts) +int git_checkout_head(git_repository *repo, git_checkout_opts *opts, git_indexer_stats *stats) { /* TODO */ return -1; diff --git a/src/clone.c b/src/clone.c index 7ce391136..47bd16d84 100644 --- a/src/clone.c +++ b/src/clone.c @@ -250,6 +250,7 @@ int git_clone(git_repository **out, const char *origin_url, const char *workdir_path, git_indexer_stats *fetch_stats, + git_indexer_stats *checkout_stats, git_checkout_opts *checkout_opts) { int retcode = GIT_ERROR; @@ -257,7 +258,7 @@ int git_clone(git_repository **out, assert(out && origin_url && workdir_path); if (!(retcode = clone_internal(out, origin_url, workdir_path, fetch_stats, 0))) { - retcode = git_checkout_head(*out, checkout_opts); + retcode = git_checkout_head(*out, checkout_opts, checkout_stats); } return retcode; diff --git a/tests-clar/checkout/checkout.c b/tests-clar/checkout/checkout.c index 71f8f0201..53d95c410 100644 --- a/tests-clar/checkout/checkout.c +++ b/tests-clar/checkout/checkout.c @@ -38,12 +38,12 @@ void test_checkout_checkout__bare(void) { cl_git_sandbox_cleanup(); g_repo = cl_git_sandbox_init("testrepo.git"); - cl_git_fail(git_checkout_index(g_repo, NULL)); + cl_git_fail(git_checkout_index(g_repo, NULL, NULL)); } void test_checkout_checkout__default(void) { - cl_git_pass(git_checkout_index(g_repo, NULL)); + cl_git_pass(git_checkout_index(g_repo, NULL, NULL)); test_file_contents("./testrepo/README", "hey there\n"); test_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n"); test_file_contents("./testrepo/new.txt", "my new file\n"); @@ -57,7 +57,7 @@ void test_checkout_checkout__crlf(void) "README text eol=cr\n" "new.txt text eol=lf\n"; cl_git_mkfile("./testrepo/.gitattributes", attributes); - cl_git_pass(git_checkout_index(g_repo, NULL)); + cl_git_pass(git_checkout_index(g_repo, NULL, NULL)); /* test_file_contents("./testrepo/README", "hey there\n"); */ /* test_file_contents("./testrepo/new.txt", "my new file\n"); */ /* test_file_contents("./testrepo/branch_file.txt", "hi\r\nbye!\r\n"); */ @@ -80,7 +80,7 @@ void test_checkout_checkout__symlinks(void) { /* First try with symlinks forced on */ enable_symlinks(true); - cl_git_pass(git_checkout_index(g_repo, NULL)); + cl_git_pass(git_checkout_index(g_repo, NULL, NULL)); #ifdef GIT_WIN32 test_file_contents("./testrepo/link_to_new.txt", "new.txt"); @@ -101,7 +101,7 @@ void test_checkout_checkout__symlinks(void) cl_git_sandbox_cleanup(); g_repo = cl_git_sandbox_init("testrepo"); enable_symlinks(false); - cl_git_pass(git_checkout_index(g_repo, NULL)); + cl_git_pass(git_checkout_index(g_repo, NULL, NULL)); test_file_contents("./testrepo/link_to_new.txt", "new.txt"); } diff --git a/tests-clar/clone/clone.c b/tests-clar/clone/clone.c index a64d5e836..d10b79c91 100644 --- a/tests-clar/clone/clone.c +++ b/tests-clar/clone/clone.c @@ -67,7 +67,7 @@ static void build_local_file_url(git_buf *out, const char *fixture) void test_clone_clone__bad_url(void) { /* Clone should clean up the mess if the URL isn't a git repository */ - cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", NULL, NULL)); + cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", NULL, NULL, NULL)); cl_assert(!git_path_exists("./foo")); cl_git_fail(git_clone_bare(&g_repo, "not_a_repo", "./foo.git", NULL)); cl_assert(!git_path_exists("./foo.git")); @@ -80,7 +80,7 @@ void test_clone_clone__local(void) build_local_file_url(&src, cl_fixture("testrepo.git")); #if DO_LOCAL_TEST - cl_git_pass(git_clone(&g_repo, git_buf_cstr(&src), "./local", NULL, NULL)); + cl_git_pass(git_clone(&g_repo, git_buf_cstr(&src), "./local", NULL, NULL, NULL)); git_repository_free(g_repo); git_futils_rmdir_r("./local", GIT_DIRREMOVAL_FILES_AND_DIRS); cl_git_pass(git_clone_bare(&g_repo, git_buf_cstr(&src), "./local.git", NULL)); @@ -96,7 +96,7 @@ void test_clone_clone__network_full(void) #if DO_LIVE_NETWORK_TESTS git_remote *origin; - cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./test2", NULL, NULL)); + cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./test2", NULL, NULL, NULL)); cl_assert(!git_repository_is_bare(g_repo)); cl_git_pass(git_remote_load(&origin, g_repo, "origin")); git_futils_rmdir_r("./test2", GIT_DIRREMOVAL_FILES_AND_DIRS); @@ -121,19 +121,19 @@ void test_clone_clone__already_exists(void) #if DO_LIVE_NETWORK_TESTS /* Should pass with existing-but-empty dir */ p_mkdir("./foo", GIT_DIR_MODE); - cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL)); + cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL)); git_repository_free(g_repo); g_repo = NULL; git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS); #endif /* Should fail with a file */ cl_git_mkfile("./foo", "Bar!"); - cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL)); + cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL)); git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS); /* Should fail with existing-and-nonempty dir */ p_mkdir("./foo", GIT_DIR_MODE); cl_git_mkfile("./foo/bar", "Baz!"); - cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL)); + cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL)); git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS); } |