From 764df57e82c337a70f55e320bf31acb50c6ffacd Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Fri, 15 Jun 2012 13:14:43 -0700 Subject: Add git_clone and git_clone_bare. So far they only create a repo, setup the "origin" remote, and fetch. The API probably needs work as well; there's no way to get progress information at this point. Also uncovered a shortcoming; git_remote_download doesn't fetch over local transport. --- include/git2.h | 1 + include/git2/clone.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 include/git2/clone.h (limited to 'include') diff --git a/include/git2.h b/include/git2.h index f260cfac..cab517d9 100644 --- a/include/git2.h +++ b/include/git2.h @@ -37,6 +37,7 @@ #include "git2/index.h" #include "git2/config.h" #include "git2/remote.h" +#include "git2/clone.h" #include "git2/refspec.h" #include "git2/net.h" diff --git a/include/git2/clone.h b/include/git2/clone.h new file mode 100644 index 00000000..7936282f --- /dev/null +++ b/include/git2/clone.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2012 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ +#ifndef INCLUDE_git_clone_h__ +#define INCLUDE_git_clone_h__ + +#include "common.h" +#include "types.h" + + +/** + * @file git2/clone.h + * @brief Git cloning routines + * @defgroup git_clone Git cloning routines + * @ingroup Git + * @{ + */ +GIT_BEGIN_DECL + +/** + * TODO + * + * @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 + * @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 *dest_path); + +/** + * TODO + * + * @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 + * @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_END_DECL +#endif -- cgit v1.2.1 From bb1f6087e44272371d25df9cc5610124f6cd5a01 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Tue, 19 Jun 2012 09:15:39 -0700 Subject: Add progress reporting to clone. --- include/git2/clone.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/git2/clone.h b/include/git2/clone.h index 7936282f..5468f09b 100644 --- a/include/git2/clone.h +++ b/include/git2/clone.h @@ -9,6 +9,7 @@ #include "common.h" #include "types.h" +#include "indexer.h" /** @@ -25,10 +26,11 @@ GIT_BEGIN_DECL * * @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 workdir_path local directory to clone to + * @param stats pointer to structure that receives 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(git_repository **out, const char *origin_url, const char *dest_path); +GIT_EXTERN(int) git_clone(git_repository **out, const char *origin_url, const char *workdir_path, git_indexer_stats *stats); /** * TODO @@ -36,9 +38,10 @@ 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) * @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_EXTERN(int) git_clone_bare(git_repository **out, const char *origin_url, const char *dest_path, git_indexer_stats *stats); /** @} */ GIT_END_DECL -- cgit v1.2.1 From 14741d62d9a8ae79774cf891a7ed665d8d650188 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Thu, 21 Jun 2012 11:13:19 -0700 Subject: Clone: new home for git_checkout_force. --- include/git2/checkout.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 include/git2/checkout.h (limited to 'include') diff --git a/include/git2/checkout.h b/include/git2/checkout.h new file mode 100644 index 00000000..9dec5b93 --- /dev/null +++ b/include/git2/checkout.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2012 the libgit2 contributors + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ +#ifndef INCLUDE_git_checkout_h__ +#define INCLUDE_git_checkout_h__ + +#include "common.h" +#include "types.h" +#include "indexer.h" + + +/** + * @file git2/checkout.h + * @brief Git checkout routines + * @defgroup git_checkout Git checkout routines + * @ingroup Git + * @{ + */ +GIT_BEGIN_DECL + +/** + * Updates files in the working tree to match the version in the index + * or HEAD. + * + * @param repo repository to check out (must be non-bare) + * @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) + * @return 0 on success, GIT_ERROR otherwise (use git_error_last for information about the error) + */ +GIT_EXTERN(int) git_checkout_force(git_repository *repo, git_indexer_stats *stats); + +/** @} */ +GIT_END_DECL +#endif -- cgit v1.2.1 From deac801de98be4974cfe806eb4bc072f34f81cc5 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Fri, 13 Jul 2012 15:50:23 -0700 Subject: Fix documentation comment to match actual params. --- include/git2/checkout.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'include') diff --git a/include/git2/checkout.h b/include/git2/checkout.h index 9dec5b93..313d52f7 100644 --- a/include/git2/checkout.h +++ b/include/git2/checkout.h @@ -22,12 +22,9 @@ GIT_BEGIN_DECL /** - * Updates files in the working tree to match the version in the index - * or HEAD. + * Updates files in the working tree to match the version in the index. * * @param repo repository to check out (must be non-bare) - * @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) * @return 0 on success, GIT_ERROR otherwise (use git_error_last for information about the error) */ -- cgit v1.2.1 From ef9905c9902a9ffad71c8acddec74dc0d8e866de Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Thu, 26 Jul 2012 12:58:44 -0700 Subject: 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. --- include/git2/checkout.h | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/git2/checkout.h b/include/git2/checkout.h index 313d52f7..ff1c4132 100644 --- a/include/git2/checkout.h +++ b/include/git2/checkout.h @@ -21,14 +21,44 @@ */ GIT_BEGIN_DECL + +#define GIT_CHECKOUT_OVERWRITE_EXISTING 0 +#define GIT_CHECKOUT_SKIP_EXISTING 1 + + +typedef struct git_checkout_opts { + git_indexer_stats stats; + int existing_file_action; + int apply_filters; + int dir_mode; + int file_open_mode; +} 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. + * + * @param repo repository to check out (must be non-bare) + * @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); + /** - * Updates files in the working tree to match the version in the index. + * Updates files in the working tree to match the commit pointed to by HEAD. * * @param repo repository to check out (must be non-bare) - * @param stats pointer to structure that receives progress information (may be NULL) + * @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_force(git_repository *repo, git_indexer_stats *stats); +GIT_EXTERN(int) git_checkout_head(git_repository *repo, git_checkout_opts *opts); /** @} */ GIT_END_DECL -- cgit v1.2.1 From b401bace1b28ac23990382605791eddbeda09d9b Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Thu, 26 Jul 2012 13:12:21 -0700 Subject: Restructure for better checkout options * Removed the #define for defaults * Promoted progress structure to top-level API call argument --- include/git2/checkout.h | 29 ++++++++++++----------------- include/git2/clone.h | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 21 deletions(-) (limited to 'include') diff --git a/include/git2/checkout.h b/include/git2/checkout.h index ff1c4132..6e0a05f7 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 5468f09b..73b6ea54 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 -- cgit v1.2.1 From 095ccc013f04398369d4063ff802d4c2928e367d Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Thu, 26 Jul 2012 16:31:49 -0700 Subject: Checkout: implementation of most options --- include/git2/checkout.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/git2/checkout.h b/include/git2/checkout.h index 6e0a05f7..7a32cffa 100644 --- a/include/git2/checkout.h +++ b/include/git2/checkout.h @@ -30,7 +30,8 @@ typedef struct git_checkout_opts { 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 */ + int file_mode; /* default is 0644 */ + int file_open_flags; /* default is O_CREAT | O_TRUNC | O_WRONLY */ } git_checkout_opts; /** -- cgit v1.2.1 From b31667fb695dab0510cc5fc259e0569ff2a2ef41 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Fri, 27 Jul 2012 20:29:06 -0700 Subject: Checkout: add head- and ref-centric checkouts. Renamed git_checkout_index to what it really was, and removed duplicate code from clone.c. Added git_checkout_ref, which updates HEAD and hands off to git_checkout_head. Added tests for the options the caller can pass to git_checkout_*. --- include/git2/checkout.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/git2/checkout.h b/include/git2/checkout.h index 7a32cffa..78367c29 100644 --- a/include/git2/checkout.h +++ b/include/git2/checkout.h @@ -35,26 +35,31 @@ typedef struct git_checkout_opts { } git_checkout_opts; /** - * Updates files in the working tree to match the index. + * Updates files in the working tree to match the commit pointed to by HEAD. * * @param repo repository to check out (must be non-bare) * @param opts specifies checkout options (may be NULL) + * @param stats structure through which progress information is reported * @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_indexer_stats *stats); +GIT_EXTERN(int) git_checkout_head(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. + * Updates files in the working tree to match a commit pointed to by a ref. * - * @param repo repository to check out (must be non-bare) + * @param ref reference to follow to a commit * @param opts specifies checkout options (may be NULL) + * @param stats structure through which progress information is reported * @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_indexer_stats *stats); +GIT_EXTERN(int) git_checkout_reference(git_reference *ref, + git_checkout_opts *opts, + git_indexer_stats *stats); + /** @} */ GIT_END_DECL -- cgit v1.2.1 From f1587b97a11e3a7283b32f5af46b7d057b8be4c5 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Mon, 30 Jul 2012 14:37:40 -0700 Subject: Checkout: use git_index_read_tree_with_stats. New variant of git_index_read_tree that fills in the 'total' field of a git_indexer_stats struct as it's walking the tree. --- include/git2/index.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include') diff --git a/include/git2/index.h b/include/git2/index.h index f863a606..85f8cfc3 100644 --- a/include/git2/index.h +++ b/include/git2/index.h @@ -8,6 +8,7 @@ #define INCLUDE_git_index_h__ #include "common.h" +#include "indexer.h" #include "types.h" #include "oid.h" @@ -345,6 +346,20 @@ GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry); */ GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree); + +/** + * Read a tree into the index file with stats + * + * The current index contents will be replaced by the specified tree. The total + * node count is collected in stats. + * + * @param index an existing index object + * @param tree tree to read + * @param stats structure that receives the total node count + * @return 0 or an error code + */ +GIT_EXTERN(int) git_index_read_tree_with_stats(git_index *index, git_tree *tree, git_indexer_stats *stats); + /** @} */ GIT_END_DECL #endif -- cgit v1.2.1 From 4bf5115642b64851f9a32a8157010b588bf44103 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Mon, 30 Jul 2012 14:52:46 -0700 Subject: Enable stats on git_index_read_tree. Replace with the contents of git_index_read_tree_with_stats() and improve documentation comments. --- include/git2/index.h | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/git2/index.h b/include/git2/index.h index 85f8cfc3..c88a1701 100644 --- a/include/git2/index.h +++ b/include/git2/index.h @@ -335,18 +335,6 @@ GIT_EXTERN(const git_index_entry_unmerged *) git_index_get_unmerged_byindex(git_ */ GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry); -/** - * Read a tree into the index file - * - * The current index contents will be replaced by the specified tree. - * - * @param index an existing index object - * @param tree tree to read - * @return 0 or an error code - */ -GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree); - - /** * Read a tree into the index file with stats * @@ -355,10 +343,10 @@ GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree); * * @param index an existing index object * @param tree tree to read - * @param stats structure that receives the total node count + * @param stats structure that receives the total node count (may be NULL) * @return 0 or an error code */ -GIT_EXTERN(int) git_index_read_tree_with_stats(git_index *index, git_tree *tree, git_indexer_stats *stats); +GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree, git_indexer_stats *stats); /** @} */ GIT_END_DECL -- cgit v1.2.1 From 5280f4e6983555e9ae111a6cb10765c7635e7e12 Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Tue, 31 Jul 2012 19:39:06 -0700 Subject: Add checkout.h to git2.h. Also correcting some documentation strings. --- include/git2.h | 1 + include/git2/checkout.h | 4 ++-- include/git2/clone.h | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/git2.h b/include/git2.h index edb73e8a..40167484 100644 --- a/include/git2.h +++ b/include/git2.h @@ -38,6 +38,7 @@ #include "git2/config.h" #include "git2/remote.h" #include "git2/clone.h" +#include "git2/checkout.h" #include "git2/attr.h" #include "git2/branch.h" diff --git a/include/git2/checkout.h b/include/git2/checkout.h index 78367c29..ac31b346 100644 --- a/include/git2/checkout.h +++ b/include/git2/checkout.h @@ -40,7 +40,7 @@ typedef struct git_checkout_opts { * @param repo repository to check out (must be non-bare) * @param opts specifies checkout options (may be NULL) * @param stats structure through which progress information is reported - * @return 0 on success, GIT_ERROR otherwise (use git_error_last for information about the error) + * @return 0 on success, GIT_ERROR otherwise (use giterr_last for information about the error) */ GIT_EXTERN(int) git_checkout_head(git_repository *repo, git_checkout_opts *opts, @@ -54,7 +54,7 @@ GIT_EXTERN(int) git_checkout_head(git_repository *repo, * @param ref reference to follow to a commit * @param opts specifies checkout options (may be NULL) * @param stats structure through which progress information is reported - * @return 0 on success, GIT_ERROR otherwise (use git_error_last for information about the error) + * @return 0 on success, GIT_ERROR otherwise (use giterr_last for information about the error) */ GIT_EXTERN(int) git_checkout_reference(git_reference *ref, git_checkout_opts *opts, diff --git a/include/git2/clone.h b/include/git2/clone.h index 73b6ea54..f134a045 100644 --- a/include/git2/clone.h +++ b/include/git2/clone.h @@ -30,7 +30,7 @@ GIT_BEGIN_DECL * @param workdir_path local directory to clone to * @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) + * @return 0 on success, GIT_ERROR otherwise (use giterr_last for information about the error) */ GIT_EXTERN(int) git_clone(git_repository **out, const char *origin_url, @@ -46,7 +46,7 @@ GIT_EXTERN(int) git_clone(git_repository **out, * @param origin_url repository to clone from * @param dest_path local directory to clone to * @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) + * @return 0 on success, GIT_ERROR otherwise (use giterr_last for information about the error) */ GIT_EXTERN(int) git_clone_bare(git_repository **out, const char *origin_url, -- cgit v1.2.1 From 8b67f72b9cba387f5e85ce869448d88cce23076f Mon Sep 17 00:00:00 2001 From: Ben Straub Date: Tue, 31 Jul 2012 21:25:48 -0700 Subject: Add documentation for clone methods. --- include/git2/clone.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/git2/clone.h b/include/git2/clone.h index f134a045..40292ed5 100644 --- a/include/git2/clone.h +++ b/include/git2/clone.h @@ -23,7 +23,8 @@ GIT_BEGIN_DECL /** - * TODO + * Clone a remote repository, and checkout the branch pointed to by the remote + * HEAD. * * @param out pointer that will receive the resulting repository object * @param origin_url repository to clone from @@ -40,7 +41,7 @@ GIT_EXTERN(int) git_clone(git_repository **out, git_checkout_opts *checkout_opts); /** - * TODO + * Create a bare clone of a remote repository. * * @param out pointer that will receive the resulting repository object * @param origin_url repository to clone from -- cgit v1.2.1