diff options
| author | Ben Straub <bstraub@github.com> | 2012-07-26 12:58:44 -0700 |
|---|---|---|
| committer | Ben Straub <bstraub@github.com> | 2012-07-26 12:58:44 -0700 |
| commit | ef9905c9902a9ffad71c8acddec74dc0d8e866de (patch) | |
| tree | 430227357c229d559571d65a9d2d008252b4ae64 /src | |
| parent | dc03369c07c6222c763cca8a80452608c8cce435 (diff) | |
| download | libgit2-ef9905c9902a9ffad71c8acddec74dc0d8e866de.tar.gz | |
checkout: introduce git_checkout_opts
Refactor checkout into several more-sensible
entry points, which consolidates common options
into a single structure that may be passed around.
Diffstat (limited to 'src')
| -rw-r--r-- | src/checkout.c | 23 | ||||
| -rw-r--r-- | src/clone.c | 25 |
2 files changed, 29 insertions, 19 deletions
diff --git a/src/checkout.c b/src/checkout.c index c2e1c4994..d5f69c648 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -27,7 +27,7 @@ GIT_BEGIN_DECL typedef struct tree_walk_data { - git_indexer_stats *stats; + git_checkout_opts *opts; git_repository *repo; git_odb *odb; bool do_symlinks; @@ -120,21 +120,21 @@ static int checkout_walker(const char *path, const git_tree_entry *entry, void * } git_buf_free(&fnbuf); - data->stats->processed++; + data->opts->stats.processed++; return retcode; } -int git_checkout_force(git_repository *repo, git_indexer_stats *stats) +int git_checkout_index(git_repository *repo, git_checkout_opts *opts) { int retcode = GIT_ERROR; - git_indexer_stats dummy_stats; + git_checkout_opts default_opts = GIT_CHECKOUT_DEFAULT_OPTS; git_tree *tree; tree_walk_data payload; git_config *cfg; assert(repo); - if (!stats) stats = &dummy_stats; + if (!opts) opts = &default_opts; if (git_repository_is_bare(repo)) { giterr_set(GITERR_INVALID, "Checkout is not allowed for bare repositories"); @@ -150,12 +150,12 @@ int git_checkout_force(git_repository *repo, git_indexer_stats *stats) git_config_free(cfg); } - stats->total = stats->processed = 0; - payload.stats = stats; + opts->stats.total = opts->stats.processed = 0; + payload.opts = opts; payload.repo = repo; if (git_repository_odb(&payload.odb, repo) < 0) return GIT_ERROR; - /* TODO: stats->total is never calculated. */ + /* TODO: opts->stats.total is never calculated. */ if (!git_repository_head_tree(&tree, repo)) { /* Checkout the files */ @@ -170,4 +170,11 @@ int git_checkout_force(git_repository *repo, git_indexer_stats *stats) } +int git_checkout_head(git_repository *repo, git_checkout_opts *opts) +{ + /* TODO */ + return -1; +} + + GIT_END_DECL diff --git a/src/clone.c b/src/clone.c index 803338ebb..7ce391136 100644 --- a/src/clone.c +++ b/src/clone.c @@ -161,20 +161,20 @@ static int update_head_to_remote(git_repository *repo, git_remote *remote) static int setup_remotes_and_fetch(git_repository *repo, const char *origin_url, - git_indexer_stats *stats) + git_indexer_stats *fetch_stats) { int retcode = GIT_ERROR; git_remote *origin = NULL; git_off_t bytes = 0; git_indexer_stats dummy_stats; - if (!stats) stats = &dummy_stats; + if (!fetch_stats) fetch_stats = &dummy_stats; /* Create the "origin" remote */ if (!git_remote_add(&origin, repo, "origin", origin_url)) { /* Connect and download everything */ if (!git_remote_connect(origin, GIT_DIR_FETCH)) { - if (!git_remote_download(origin, &bytes, stats)) { + if (!git_remote_download(origin, &bytes, fetch_stats)) { /* Create "origin/foo" branches for all remote branches */ if (!git_remote_update_tips(origin, NULL)) { /* Point HEAD to the same ref as the remote's head */ @@ -209,18 +209,21 @@ static bool path_is_okay(const char *path) static int clone_internal(git_repository **out, const char *origin_url, const char *path, - git_indexer_stats *stats, + git_indexer_stats *fetch_stats, int is_bare) { int retcode = GIT_ERROR; git_repository *repo = NULL; + git_indexer_stats dummy_stats; + + if (!fetch_stats) fetch_stats = &dummy_stats; if (!path_is_okay(path)) { return GIT_ERROR; } if (!(retcode = git_repository_init(&repo, path, is_bare))) { - if ((retcode = setup_remotes_and_fetch(repo, origin_url, stats)) < 0) { + if ((retcode = setup_remotes_and_fetch(repo, origin_url, fetch_stats)) < 0) { /* Failed to fetch; clean up */ git_repository_free(repo); git_futils_rmdir_r(path, GIT_DIRREMOVAL_FILES_AND_DIRS); @@ -236,25 +239,25 @@ static int clone_internal(git_repository **out, int git_clone_bare(git_repository **out, const char *origin_url, const char *dest_path, - git_indexer_stats *stats) + git_indexer_stats *fetch_stats) { assert(out && origin_url && dest_path); - return clone_internal(out, origin_url, dest_path, stats, 1); + return clone_internal(out, origin_url, dest_path, fetch_stats, 1); } int git_clone(git_repository **out, const char *origin_url, const char *workdir_path, - git_indexer_stats *stats) + git_indexer_stats *fetch_stats, + git_checkout_opts *checkout_opts) { int retcode = GIT_ERROR; assert(out && origin_url && workdir_path); - if (!(retcode = clone_internal(out, origin_url, workdir_path, stats, 0))) { - git_indexer_stats checkout_stats; - retcode = git_checkout_force(*out, &checkout_stats); + if (!(retcode = clone_internal(out, origin_url, workdir_path, fetch_stats, 0))) { + retcode = git_checkout_head(*out, checkout_opts); } return retcode; |
