diff options
33 files changed, 469 insertions, 293 deletions
diff --git a/.travis.yml b/.travis.yml index b5f1c6ff6..686041bfa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,8 +17,8 @@ env: - secure: "YnhS+8n6B+uoyaYfaJ3Lei7cSJqHDPiKJCKFIF2c87YDfmCvAJke8QtE7IzjYDs7UFkTCM4ox+ph2bERUrxZbSCyEkHdjIZpKuMJfYWja/jgMqTMxdyOH9y8JLFbZsSXDIXDwqBlC6vVyl1fP90M35wuWcNTs6tctfVWVofEFbs=" - GITTEST_INVASIVE_FS_SIZE=1 matrix: - - OPTIONS="-DTHREADSAFE=ON -DENABLE_TRACE=ON -DCMAKE_BUILD_TYPE=Release -DENABLE_WERROR=ON" - - OPTIONS="-DTHREADSAFE=OFF -DBUILD_EXAMPLES=ON -DENABLE_WERROR=ON" + - OPTIONS="-DTHREADSAFE=ON -DENABLE_TRACE=ON -DCMAKE_BUILD_TYPE=Release" + - OPTIONS="-DTHREADSAFE=OFF -DBUILD_EXAMPLES=ON" dist: trusty sudo: false @@ -74,10 +74,8 @@ install: # Run the Build script and tests script: - script/cibuild.sh - -# Run Tests -after_success: - - if [ "$TRAVIS_OS_NAME" = "linux" -a -n "$VALGRIND" ]; then valgrind --leak-check=full --show-reachable=yes --suppressions=./libgit2_clar.supp _build/libgit2_clar -ionline; fi + - script/citest.sh + - script/cileaks.sh # Only watch the development and master branches branches: diff --git a/api.docurium b/api.docurium index 9e17817db..bf733273b 100644 --- a/api.docurium +++ b/api.docurium @@ -1,7 +1,7 @@ { "name": "libgit2", "github": "libgit2/libgit2", - "input": "include/git2", + "input": "include", "prefix": "git_", "output": "docs", "branch": "gh-pages", diff --git a/include/git2/attr.h b/include/git2/attr.h index 0238f3dd7..651454abc 100644 --- a/include/git2/attr.h +++ b/include/git2/attr.h @@ -186,6 +186,22 @@ GIT_EXTERN(int) git_attr_get_many( size_t num_attr, const char **names); +/** + * The callback used with git_attr_foreach. + * + * This callback will be invoked only once per attribute name, even if there + * are multiple rules for a given file. The highest priority rule will be + * used. + * + * @see git_attr_foreach. + * + * @param name The attribute name. + * @param value The attribute value. May be NULL if the attribute is explicitly + * set to UNSPECIFIED using the '!' sign. + * @param payload A user-specified pointer. + * @return 0 to continue looping, non-zero to stop. This value will be returned + * from git_attr_foreach. + */ typedef int (*git_attr_foreach_cb)(const char *name, const char *value, void *payload); /** @@ -196,13 +212,8 @@ typedef int (*git_attr_foreach_cb)(const char *name, const char *value, void *pa * @param path Path inside the repo to check attributes. This does not have * to exist, but if it does not, then it will be treated as a * plain file (i.e. not a directory). - * @param callback Function to invoke on each attribute name and value. The - * value may be NULL is the attribute is explicitly set to - * UNSPECIFIED using the '!' sign. Callback will be invoked - * only once per attribute name, even if there are multiple - * rules for a given file. The highest priority rule will be - * used. Return a non-zero value from this to stop looping. - * The value will be returned from `git_attr_foreach`. + * @param callback Function to invoke on each attribute name and value. + * See git_attr_foreach_cb. * @param payload Passed on as extra parameter to callback function. * @return 0 on success, non-zero callback return value, or error code */ diff --git a/include/git2/blame.h b/include/git2/blame.h index 84bb7f94c..34cb69916 100644 --- a/include/git2/blame.h +++ b/include/git2/blame.h @@ -48,33 +48,38 @@ typedef enum { /** * Blame options structure * - * Use zeros to indicate default settings. It's easiest to use the - * `GIT_BLAME_OPTIONS_INIT` macro: - * git_blame_options opts = GIT_BLAME_OPTIONS_INIT; + * Initialize with `GIT_BLAME_OPTIONS_INIT`. Alternatively, you can + * use `git_blame_init_options`. * - * - `flags` is a combination of the `git_blame_flag_t` values above. - * - `min_match_characters` is the lower bound on the number of alphanumeric - * characters that must be detected as moving/copying within a file for it to - * associate those lines with the parent commit. The default value is 20. - * This value only takes effect if any of the `GIT_BLAME_TRACK_COPIES_*` - * flags are specified. - * - `newest_commit` is the id of the newest commit to consider. The default - * is HEAD. - * - `oldest_commit` is the id of the oldest commit to consider. The default - * is the first commit encountered with a NULL parent. - * - `min_line` is the first line in the file to blame. The default is 1 (line - * numbers start with 1). - * - `max_line` is the last line in the file to blame. The default is the last - * line of the file. */ typedef struct git_blame_options { unsigned int version; + /** A combination of `git_blame_flag_t` */ uint32_t flags; + /** The lower bound on the number of alphanumeric + * characters that must be detected as moving/copying within a file for it to + * associate those lines with the parent commit. The default value is 20. + * This value only takes effect if any of the `GIT_BLAME_TRACK_COPIES_*` + * flags are specified. + */ uint16_t min_match_characters; + /** The id of the newest commit to consider. The default is HEAD. */ git_oid newest_commit; + /** + * The id of the oldest commit to consider. + * The default is the first commit encountered with a NULL parent. + */ git_oid oldest_commit; + /** + * The first line in the file to blame. + * The default is 1 (line numbers start with 1). + */ size_t min_line; + /** + * The last line in the file to blame. + * The default is the last line of the file. + */ size_t max_line; } git_blame_options; @@ -82,11 +87,13 @@ typedef struct git_blame_options { #define GIT_BLAME_OPTIONS_INIT {GIT_BLAME_OPTIONS_VERSION} /** - * Initializes a `git_blame_options` with default values. Equivalent to - * creating an instance with GIT_BLAME_OPTIONS_INIT. + * Initialize git_blame_options structure * - * @param opts The `git_blame_options` struct to initialize - * @param version Version of struct; pass `GIT_BLAME_OPTIONS_VERSION` + * Initializes a `git_blame_options` with default values. Equivalent to creating + * an instance with GIT_BLAME_OPTIONS_INIT. + * + * @param opts The `git_blame_options` struct to initialize. + * @param version The struct version; pass `GIT_BLAME_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_blame_init_options( @@ -128,7 +135,7 @@ typedef struct git_blame_hunk { } git_blame_hunk; -/* Opaque structure to hold blame results */ +/** Opaque structure to hold blame results */ typedef struct git_blame git_blame; /** diff --git a/include/git2/branch.h b/include/git2/branch.h index 88fe723a0..8a4ce29a9 100644 --- a/include/git2/branch.h +++ b/include/git2/branch.h @@ -278,7 +278,7 @@ GIT_EXTERN(int) git_branch_remote_name( /** - * Retrieve the name fo the upstream remote of a local branch + * Retrieve the name of the upstream remote of a local branch * * @param buf the buffer into which to write the name * @param repo the repository in which to look diff --git a/include/git2/checkout.h b/include/git2/checkout.h index c7b0c83ef..7ba0df871 100644 --- a/include/git2/checkout.h +++ b/include/git2/checkout.h @@ -243,10 +243,9 @@ typedef void (*git_checkout_perfdata_cb)( /** * Checkout options structure * - * Zero out for defaults. Initialize with `GIT_CHECKOUT_OPTIONS_INIT` macro to - * correctly set the `version` field. E.g. + * Initialize with `GIT_CHECKOUT_OPTIONS_INIT`. Alternatively, you can + * use `git_checkout_init_options`. * - * git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; */ typedef struct git_checkout_options { unsigned int version; @@ -298,13 +297,15 @@ typedef struct git_checkout_options { #define GIT_CHECKOUT_OPTIONS_INIT {GIT_CHECKOUT_OPTIONS_VERSION, GIT_CHECKOUT_SAFE} /** -* Initializes a `git_checkout_options` with default values. Equivalent to -* creating an instance with GIT_CHECKOUT_OPTIONS_INIT. -* -* @param opts the `git_checkout_options` struct to initialize. -* @param version Version of struct; pass `GIT_CHECKOUT_OPTIONS_VERSION` -* @return Zero on success; -1 on failure. -*/ + * Initialize git_checkout_options structure + * + * Initializes a `git_checkout_options` with default values. Equivalent to creating + * an instance with GIT_CHECKOUT_OPTIONS_INIT. + * + * @param opts The `git_checkout_options` struct to initialize. + * @param version The struct version; pass `GIT_CHECKOUT_OPTIONS_VERSION`. + * @return Zero on success; -1 on failure. + */ GIT_EXTERN(int) git_checkout_init_options( git_checkout_options *opts, unsigned int version); diff --git a/include/git2/cherrypick.h b/include/git2/cherrypick.h index edec96a94..ca6f72075 100644 --- a/include/git2/cherrypick.h +++ b/include/git2/cherrypick.h @@ -37,11 +37,13 @@ typedef struct { #define GIT_CHERRYPICK_OPTIONS_INIT {GIT_CHERRYPICK_OPTIONS_VERSION, 0, GIT_MERGE_OPTIONS_INIT, GIT_CHECKOUT_OPTIONS_INIT} /** - * Initializes a `git_cherrypick_options` with default values. Equivalent to - * creating an instance with GIT_CHERRYPICK_OPTIONS_INIT. + * Initialize git_cherrypick_options structure * - * @param opts the `git_cherrypick_options` struct to initialize - * @param version Version of struct; pass `GIT_CHERRYPICK_OPTIONS_VERSION` + * Initializes a `git_cherrypick_options` with default values. Equivalent to creating + * an instance with GIT_CHERRYPICK_OPTIONS_INIT. + * + * @param opts The `git_cherrypick_options` struct to initialize. + * @param version The struct version; pass `GIT_CHERRYPICK_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_cherrypick_init_options( diff --git a/include/git2/clone.h b/include/git2/clone.h index 9e23aaccb..469031700 100644 --- a/include/git2/clone.h +++ b/include/git2/clone.h @@ -96,9 +96,9 @@ typedef int (*git_repository_create_cb)( /** * Clone options structure * - * Use the GIT_CLONE_OPTIONS_INIT to get the default settings, like this: + * Initialize with `GIT_CLONE_OPTIONS_INIT`. Alternatively, you can + * use `git_clone_init_options`. * - * git_clone_options opts = GIT_CLONE_OPTIONS_INIT; */ typedef struct git_clone_options { unsigned int version; @@ -169,11 +169,13 @@ typedef struct git_clone_options { GIT_FETCH_OPTIONS_INIT } /** - * Initializes a `git_clone_options` with default values. Equivalent to - * creating an instance with GIT_CLONE_OPTIONS_INIT. + * Initialize git_clone_options structure * - * @param opts The `git_clone_options` struct to initialize - * @param version Version of struct; pass `GIT_CLONE_OPTIONS_VERSION` + * Initializes a `git_clone_options` with default values. Equivalent to creating + * an instance with GIT_CLONE_OPTIONS_INIT. + * + * @param opts The `git_clone_options` struct to initialize. + * @param version The struct version; pass `GIT_CLONE_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_clone_init_options( diff --git a/include/git2/describe.h b/include/git2/describe.h index eb0355bb3..56f119b2d 100644 --- a/include/git2/describe.h +++ b/include/git2/describe.h @@ -36,10 +36,9 @@ typedef enum { /** * Describe options structure * - * Initialize with `GIT_DESCRIBE_OPTIONS_INIT` macro to correctly set - * the `version` field. E.g. + * Initialize with `GIT_DESCRIBE_OPTIONS_INIT`. Alternatively, you can + * use `git_describe_init_options`. * - * git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT; */ typedef struct git_describe_options { unsigned int version; @@ -70,10 +69,24 @@ typedef struct git_describe_options { GIT_DESCRIBE_DEFAULT_MAX_CANDIDATES_TAGS, \ } +/** + * Initialize git_describe_options structure + * + * Initializes a `git_describe_options` with default values. Equivalent to creating + * an instance with GIT_DESCRIBE_OPTIONS_INIT. + * + * @param opts The `git_describe_options` struct to initialize. + * @param version The struct version; pass `GIT_DESCRIBE_OPTIONS_VERSION`. + * @return Zero on success; -1 on failure. + */ GIT_EXTERN(int) git_describe_init_options(git_describe_options *opts, unsigned int version); /** - * Options for formatting the describe string + * Describe format options structure + * + * Initialize with `GIT_DESCRIBE_FORMAT_OPTIONS_INIT`. Alternatively, you can + * use `git_describe_format_init_options`. + * */ typedef struct { unsigned int version; @@ -103,6 +116,16 @@ typedef struct { GIT_DESCRIBE_DEFAULT_ABBREVIATED_SIZE, \ } +/** + * Initialize git_describe_format_options structure + * + * Initializes a `git_describe_format_options` with default values. Equivalent to creating + * an instance with GIT_DESCRIBE_FORMAT_OPTIONS_INIT. + * + * @param opts The `git_describe_format_options` struct to initialize. + * @param version The struct version; pass `GIT_DESCRIBE_FORMAT_OPTIONS_VERSION`. + * @return Zero on success; -1 on failure. + */ GIT_EXTERN(int) git_describe_init_format_options(git_describe_format_options *opts, unsigned int version); /** diff --git a/include/git2/diff.h b/include/git2/diff.h index 86009f583..b7240ff98 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -437,11 +437,13 @@ typedef struct { {GIT_DIFF_OPTIONS_VERSION, 0, GIT_SUBMODULE_IGNORE_UNSPECIFIED, {NULL,0}, NULL, NULL, NULL, 3} /** - * Initializes a `git_diff_options` with default values. Equivalent to - * creating an instance with GIT_DIFF_OPTIONS_INIT. + * Initialize git_diff_options structure * - * @param opts The `git_diff_options` struct to initialize - * @param version Version of struct; pass `GIT_DIFF_OPTIONS_VERSION` + * Initializes a `git_diff_options` with default values. Equivalent to creating + * an instance with GIT_DIFF_OPTIONS_INIT. + * + * @param opts The `git_diff_options` struct to initialize. + * @param version The struct version; pass `GIT_DIFF_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_diff_init_options( @@ -732,11 +734,13 @@ typedef struct { #define GIT_DIFF_FIND_OPTIONS_INIT {GIT_DIFF_FIND_OPTIONS_VERSION} /** - * Initializes a `git_diff_find_options` with default values. Equivalent to - * creating an instance with GIT_DIFF_FIND_OPTIONS_INIT. + * Initialize git_diff_find_options structure + * + * Initializes a `git_diff_find_options` with default values. Equivalent to creating + * an instance with GIT_DIFF_FIND_OPTIONS_INIT. * - * @param opts The `git_diff_find_options` struct to initialize - * @param version Version of struct; pass `GIT_DIFF_FIND_OPTIONS_VERSION` + * @param opts The `git_diff_find_options` struct to initialize. + * @param version The struct version; pass `GIT_DIFF_FIND_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_diff_find_init_options( @@ -1394,12 +1398,13 @@ GIT_EXTERN(int) git_diff_commit_as_email( const git_diff_options *diff_opts); /** - * Initializes a `git_diff_format_email_options` with default values. + * Initialize git_diff_format_email_options structure * - * Equivalent to creating an instance with GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT. + * Initializes a `git_diff_format_email_options` with default values. Equivalent + * to creating an instance with GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT. * - * @param opts The `git_diff_format_email_options` struct to initialize - * @param version Version of struct; pass `GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION` + * @param opts The `git_blame_options` struct to initialize. + * @param version The struct version; pass `GIT_DIFF_FORMAT_EMAIL_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_diff_format_email_init_options( @@ -1409,8 +1414,9 @@ GIT_EXTERN(int) git_diff_format_email_init_options( /** * Patch ID options structure * - * Initialize with `GIT_DIFF_PATCHID_OPTIONS_INIT` macro to - * correctly set the default values and version. + * Initialize with `GIT_PATCHID_OPTIONS_INIT`. Alternatively, you can + * use `git_patchid_init_options`. + * */ typedef struct git_diff_patchid_options { unsigned int version; @@ -1420,10 +1426,14 @@ typedef struct git_diff_patchid_options { #define GIT_DIFF_PATCHID_OPTIONS_INIT { GIT_DIFF_PATCHID_OPTIONS_VERSION } /** - * Initialize `git_diff_patchid_options` structure. + * Initialize git_diff_patchid_options structure * - * Initializes the structure with default values. Equivalent to + * Initializes a `git_diff_patchid_options` with default values. Equivalent to * creating an instance with `GIT_DIFF_PATCHID_OPTIONS_INIT`. + * + * @param opts The `git_diff_patchid_options` struct to initialize. + * @param version The struct version; pass `GIT_DIFF_PATCHID_OPTIONS_VERSION`. + * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_diff_patchid_init_options( git_diff_patchid_options *opts, diff --git a/include/git2/merge.h b/include/git2/merge.h index 80ef864d1..47bf32daa 100644 --- a/include/git2/merge.h +++ b/include/git2/merge.h @@ -203,12 +203,13 @@ typedef struct { #define GIT_MERGE_FILE_OPTIONS_INIT {GIT_MERGE_FILE_OPTIONS_VERSION} /** + * Initialize git_merge_file_options structure + * * Initializes a `git_merge_file_options` with default values. Equivalent to - * creating an instance with GIT_MERGE_FILE_OPTIONS_INIT. + * creating an instance with `GIT_MERGE_FILE_OPTIONS_INIT`. * - * @param opts the `git_merge_file_options` instance to initialize. - * @param version the version of the struct; you should pass - * `GIT_MERGE_FILE_OPTIONS_VERSION` here. + * @param opts The `git_merge_file_options` struct to initialize. + * @param version The struct version; pass `GIT_MERGE_FILE_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_merge_file_init_options( @@ -300,12 +301,13 @@ typedef struct { GIT_MERGE_OPTIONS_VERSION, GIT_MERGE_FIND_RENAMES } /** + * Initialize git_merge_options structure + * * Initializes a `git_merge_options` with default values. Equivalent to - * creating an instance with GIT_MERGE_OPTIONS_INIT. + * creating an instance with `GIT_MERGE_OPTIONS_INIT`. * - * @param opts the `git_merge_options` instance to initialize. - * @param version the version of the struct; you should pass - * `GIT_MERGE_OPTIONS_VERSION` here. + * @param opts The `git_merge_options` struct to initialize. + * @param version The struct version; pass `GIT_MERGE_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_merge_init_options( diff --git a/include/git2/proxy.h b/include/git2/proxy.h index 06d46d340..5f9d27f30 100644 --- a/include/git2/proxy.h +++ b/include/git2/proxy.h @@ -80,10 +80,14 @@ typedef struct { #define GIT_PROXY_OPTIONS_INIT {GIT_PROXY_OPTIONS_VERSION} /** - * Initialize a proxy options structure + * Initialize git_proxy_options structure * - * @param opts the options struct to initialize - * @param version the version of the struct, use `GIT_PROXY_OPTIONS_VERSION` + * Initializes a `git_proxy_options` with default values. Equivalent to + * creating an instance with `GIT_PROXY_OPTIONS_INIT`. + * + * @param opts The `git_proxy_options` struct to initialize. + * @param version The struct version; pass `GIT_PROXY_OPTIONS_VERSION`. + * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_proxy_init_options(git_proxy_options *opts, unsigned int version); diff --git a/include/git2/rebase.h b/include/git2/rebase.h index 9b9065ee4..f6b2e20ad 100644 --- a/include/git2/rebase.h +++ b/include/git2/rebase.h @@ -11,6 +11,8 @@ #include "types.h" #include "oid.h" #include "annotated_commit.h" +#include "merge.h" +#include "checkout.h" /** * @file git2/rebase.h @@ -145,12 +147,13 @@ typedef struct { } git_rebase_operation; /** + * Initialize git_rebase_options structure + * * Initializes a `git_rebase_options` with default values. Equivalent to - * creating an instance with GIT_REBASE_OPTIONS_INIT. + * creating an instance with `GIT_REBASE_OPTIONS_INIT`. * - * @param opts the `git_rebase_options` instance to initialize. - * @param version the version of the struct; you should pass - * `GIT_REBASE_OPTIONS_VERSION` here. + * @param opts The `git_rebase_options` struct to initialize. + * @param version The struct version; pass `GIT_REBASE_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_rebase_init_options( diff --git a/include/git2/remote.h b/include/git2/remote.h index 3d463dec1..757515d8a 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -596,12 +596,13 @@ typedef struct { GIT_REMOTE_DOWNLOAD_TAGS_UNSPECIFIED, GIT_PROXY_OPTIONS_INIT } /** + * Initialize git_fetch_options structure + * * Initializes a `git_fetch_options` with default values. Equivalent to - * creating an instance with GIT_FETCH_OPTIONS_INIT. + * creating an instance with `GIT_FETCH_OPTIONS_INIT`. * - * @param opts the `git_fetch_options` instance to initialize. - * @param version the version of the struct; you should pass - * `GIT_FETCH_OPTIONS_VERSION` here. + * @param opts The `git_fetch_options` struct to initialize. + * @param version The struct version; pass `GIT_FETCH_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_fetch_init_options( @@ -645,12 +646,13 @@ typedef struct { #define GIT_PUSH_OPTIONS_INIT { GIT_PUSH_OPTIONS_VERSION, 0, GIT_REMOTE_CALLBACKS_INIT, GIT_PROXY_OPTIONS_INIT } /** + * Initialize git_push_options structure + * * Initializes a `git_push_options` with default values. Equivalent to - * creating an instance with GIT_PUSH_OPTIONS_INIT. + * creating an instance with `GIT_PUSH_OPTIONS_INIT`. * - * @param opts the `git_push_options` instance to initialize. - * @param version the version of the struct; you should pass - * `GIT_PUSH_OPTIONS_VERSION` here. + * @param opts The `git_push_options` struct to initialize. + * @param version The struct version; pass `GIT_PUSH_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_push_init_options( diff --git a/include/git2/repository.h b/include/git2/repository.h index 6e0c1f71e..a39ebb99b 100644 --- a/include/git2/repository.h +++ b/include/git2/repository.h @@ -301,11 +301,13 @@ typedef struct { #define GIT_REPOSITORY_INIT_OPTIONS_INIT {GIT_REPOSITORY_INIT_OPTIONS_VERSION} /** - * Initializes a `git_repository_init_options` with default values. Equivalent - * to creating an instance with GIT_REPOSITORY_INIT_OPTIONS_INIT. + * Initialize git_repository_init_options structure * - * @param opts the `git_repository_init_options` struct to initialize - * @param version Version of struct; pass `GIT_REPOSITORY_INIT_OPTIONS_VERSION` + * Initializes a `git_repository_init_options` with default values. Equivalent to + * creating an instance with `GIT_REPOSITORY_INIT_OPTIONS_INIT`. + * + * @param opts The `git_repository_init_options` struct to initialize. + * @param version The struct version; pass `GIT_REPOSITORY_INIT_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_repository_init_init_options( @@ -368,7 +370,7 @@ GIT_EXTERN(int) git_repository_head_for_worktree(git_reference **out, git_reposi */ GIT_EXTERN(int) git_repository_head_detached(git_repository *repo); -/* +/** * Check if a worktree's HEAD is detached * * A worktree's HEAD is detached when it points directly to a diff --git a/include/git2/revert.h b/include/git2/revert.h index 82dbadcfc..260ad044b 100644 --- a/include/git2/revert.h +++ b/include/git2/revert.h @@ -37,11 +37,13 @@ typedef struct { #define GIT_REVERT_OPTIONS_INIT {GIT_REVERT_OPTIONS_VERSION, 0, GIT_MERGE_OPTIONS_INIT, GIT_CHECKOUT_OPTIONS_INIT} /** + * Initialize git_revert_options structure + * * Initializes a `git_revert_options` with default values. Equivalent to - * creating an instance with GIT_REVERT_OPTIONS_INIT. + * creating an instance with `GIT_REVERT_OPTIONS_INIT`. * - * @param opts the `git_revert_options` struct to initialize - * @param version Version of struct; pass `GIT_REVERT_OPTIONS_VERSION` + * @param opts The `git_revert_options` struct to initialize. + * @param version The struct version; pass `GIT_REVERT_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_revert_init_options( diff --git a/include/git2/stash.h b/include/git2/stash.h index 3af9cde38..1fdbeb64a 100644 --- a/include/git2/stash.h +++ b/include/git2/stash.h @@ -9,6 +9,7 @@ #include "common.h" #include "types.h" +#include "checkout.h" /** * @file git2/stash.h @@ -80,6 +81,7 @@ typedef enum { GIT_STASH_APPLY_REINSTATE_INDEX = (1 << 0), } git_stash_apply_flags; +/** Stash apply progression states */ typedef enum { GIT_STASH_APPLY_PROGRESS_NONE = 0, @@ -114,12 +116,12 @@ typedef int (*git_stash_apply_progress_cb)( git_stash_apply_progress_t progress, void *payload); -/** Stash application options structure. +/** + * Stash application options structure * - * Initialize with the `GIT_STASH_APPLY_OPTIONS_INIT` macro to set - * sensible defaults; for example: + * Initialize with `GIT_STASH_APPLY_OPTIONS_INIT`. Alternatively, you can + * use `git_stash_apply_init_options`. * - * git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT; */ typedef struct git_stash_apply_options { unsigned int version; @@ -142,12 +144,13 @@ typedef struct git_stash_apply_options { GIT_CHECKOUT_OPTIONS_INIT } /** + * Initialize git_stash_apply_options structure + * * Initializes a `git_stash_apply_options` with default values. Equivalent to - * creating an instance with GIT_STASH_APPLY_OPTIONS_INIT. + * creating an instance with `GIT_STASH_APPLY_OPTIONS_INIT`. * - * @param opts the `git_stash_apply_options` instance to initialize. - * @param version the version of the struct; you should pass - * `GIT_STASH_APPLY_OPTIONS_INIT` here. + * @param opts The `git_stash_apply_options` struct to initialize. + * @param version The struct version; pass `GIT_STASH_APPLY_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_stash_apply_init_options( diff --git a/include/git2/status.h b/include/git2/status.h index 4b86818b7..bba0d0537 100644 --- a/include/git2/status.h +++ b/include/git2/status.h @@ -9,6 +9,8 @@ #include "common.h" #include "types.h" +#include "strarray.h" +#include "diff.h" /** * @file git2/status.h @@ -189,11 +191,13 @@ typedef struct { #define GIT_STATUS_OPTIONS_INIT {GIT_STATUS_OPTIONS_VERSION} /** + * Initialize git_status_options structure + * * Initializes a `git_status_options` with default values. Equivalent to - * creating an instance with GIT_STATUS_OPTIONS_INIT. + * creating an instance with `GIT_STATUS_OPTIONS_INIT`. * - * @param opts The `git_status_options` instance to initialize. - * @param version Version of struct; pass `GIT_STATUS_OPTIONS_VERSION` + * @param opts The `git_status_options` struct to initialize. + * @param version The struct version; pass `GIT_STATUS_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_status_init_options( diff --git a/include/git2/submodule.h b/include/git2/submodule.h index b2b3039fe..c5cf00661 100644 --- a/include/git2/submodule.h +++ b/include/git2/submodule.h @@ -121,10 +121,9 @@ typedef int (*git_submodule_cb)( /** * Submodule update options structure * - * Use the GIT_SUBMODULE_UPDATE_OPTIONS_INIT to get the default settings, - * like this: + * Initialize with `GIT_SUBMODULE_UPDATE_OPTIONS_INIT`. Alternatively, you can + * use `git_submodule_update_init_options`. * - * git_submodule_update_options opts = GIT_SUBMODULE_UPDATE_OPTIONS_INIT; */ typedef struct git_submodule_update_options { unsigned int version; @@ -160,11 +159,13 @@ typedef struct git_submodule_update_options { GIT_FETCH_OPTIONS_INIT, 1 } /** - * Initializes a `git_submodule_update_options` with default values. - * Equivalent to creating an instance with GIT_SUBMODULE_UPDATE_OPTIONS_INIT. + * Initialize git_submodule_update_options structure * - * @param opts The `git_submodule_update_options` instance to initialize. - * @param version Version of struct; pass `GIT_SUBMODULE_UPDATE_OPTIONS_VERSION` + * Initializes a `git_submodule_update_options` with default values. Equivalent to + * creating an instance with `GIT_SUBMODULE_UPDATE_OPTIONS_INIT`. + * + * @param opts The `git_submodule_update_options` struct to initialize. + * @param version The struct version; pass `GIT_SUBMODULE_UPDATE_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_submodule_update_init_options( diff --git a/include/git2/sys/index.h b/include/git2/sys/index.h index 2e2b87e68..f1900df42 100644 --- a/include/git2/sys/index.h +++ b/include/git2/sys/index.h @@ -7,6 +7,9 @@ #ifndef INCLUDE_sys_git_index_h__ #define INCLUDE_sys_git_index_h__ +#include "git2/common.h" +#include "git2/types.h" + /** * @file git2/sys/index.h * @brief Low-level Git index manipulation routines diff --git a/include/git2/sys/mempack.h b/include/git2/sys/mempack.h index 490636b44..63fb38dc8 100644 --- a/include/git2/sys/mempack.h +++ b/include/git2/sys/mempack.h @@ -23,61 +23,61 @@ GIT_BEGIN_DECL /** - * Instantiate a new mempack backend. + * Instantiate a new mempack backend. * - * The backend must be added to an existing ODB with the highest - * priority. + * The backend must be added to an existing ODB with the highest + * priority. * - * git_mempack_new(&mempacker); - * git_repository_odb(&odb, repository); - * git_odb_add_backend(odb, mempacker, 999); + * git_mempack_new(&mempacker); + * git_repository_odb(&odb, repository); + * git_odb_add_backend(odb, mempacker, 999); * - * Once the backend has been loaded, all writes to the ODB will - * instead be queued in memory, and can be finalized with - * `git_mempack_dump`. + * Once the backend has been loaded, all writes to the ODB will + * instead be queued in memory, and can be finalized with + * `git_mempack_dump`. * - * Subsequent reads will also be served from the in-memory store - * to ensure consistency, until the memory store is dumped. + * Subsequent reads will also be served from the in-memory store + * to ensure consistency, until the memory store is dumped. * - * @param out Pointer where to store the ODB backend - * @return 0 on success; error code otherwise + * @param out Pointer where to store the ODB backend + * @return 0 on success; error code otherwise */ GIT_EXTERN(int) git_mempack_new(git_odb_backend **out); /** - * Dump all the queued in-memory writes to a packfile. + * Dump all the queued in-memory writes to a packfile. * - * The contents of the packfile will be stored in the given buffer. - * It is the caller's responsibility to ensure that the generated - * packfile is available to the repository (e.g. by writing it - * to disk, or doing something crazy like distributing it across - * several copies of the repository over a network). + * The contents of the packfile will be stored in the given buffer. + * It is the caller's responsibility to ensure that the generated + * packfile is available to the repository (e.g. by writing it + * to disk, or doing something crazy like distributing it across + * several copies of the repository over a network). * - * Once the generated packfile is available to the repository, - * call `git_mempack_reset` to cleanup the memory store. + * Once the generated packfile is available to the repository, + * call `git_mempack_reset` to cleanup the memory store. * - * Calling `git_mempack_reset` before the packfile has been - * written to disk will result in an inconsistent repository - * (the objects in the memory store won't be accessible). + * Calling `git_mempack_reset` before the packfile has been + * written to disk will result in an inconsistent repository + * (the objects in the memory store won't be accessible). * - * @param pack Buffer where to store the raw packfile - * @param repo The active repository where the backend is loaded - * @param backend The mempack backend - * @return 0 on success; error code otherwise + * @param pack Buffer where to store the raw packfile + * @param repo The active repository where the backend is loaded + * @param backend The mempack backend + * @return 0 on success; error code otherwise */ GIT_EXTERN(int) git_mempack_dump(git_buf *pack, git_repository *repo, git_odb_backend *backend); /** - * Reset the memory packer by clearing all the queued objects. + * Reset the memory packer by clearing all the queued objects. * - * This assumes that `git_mempack_dump` has been called before to - * store all the queued objects into a single packfile. + * This assumes that `git_mempack_dump` has been called before to + * store all the queued objects into a single packfile. * - * Alternatively, call `reset` without a previous dump to "undo" - * all the recently written objects, giving transaction-like - * semantics to the Git repository. + * Alternatively, call `reset` without a previous dump to "undo" + * all the recently written objects, giving transaction-like + * semantics to the Git repository. * - * @param backend The mempack backend + * @param backend The mempack backend */ GIT_EXTERN(void) git_mempack_reset(git_odb_backend *backend); diff --git a/include/git2/sys/merge.h b/include/git2/sys/merge.h index eed106c07..f07997d2e 100644 --- a/include/git2/sys/merge.h +++ b/include/git2/sys/merge.h @@ -7,10 +7,15 @@ #ifndef INCLUDE_sys_git_merge_h__ #define INCLUDE_sys_git_merge_h__ +#include "git2/common.h" +#include "git2/types.h" +#include "git2/index.h" +#include "git2/merge.h" + /** * @file git2/sys/merge.h * @brief Git merge driver backend and plugin routines - * @defgroup git_backend Git custom backend APIs + * @defgroup git_merge Git merge driver APIs * @ingroup Git * @{ */ diff --git a/include/git2/transaction.h b/include/git2/transaction.h index 00ca13993..4938570b5 100644 --- a/include/git2/transaction.h +++ b/include/git2/transaction.h @@ -8,6 +8,7 @@ #define INCLUDE_git_transaction_h__ #include "common.h" +#include "types.h" /** * @file git2/transaction.h diff --git a/include/git2/types.h b/include/git2/types.h index ad34e0170..67e5bd155 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -63,6 +63,9 @@ typedef int64_t git_time_t; #endif +#include "buffer.h" +#include "oid.h" + /** Basic type (loose or packed) of any Git object. */ typedef enum { GIT_OBJ_ANY = -2, /**< Object can be any of the following */ @@ -212,7 +215,7 @@ typedef enum { GIT_FILEMODE_COMMIT = 0160000, } git_filemode_t; -/* +/** * A refspec specifies the mapping between remote and local reference * names when fetch or pushing. */ @@ -422,9 +425,9 @@ typedef enum { GIT_SUBMODULE_RECURSE_ONDEMAND = 2, } git_submodule_recurse_t; -/** A type to write in a streaming fashion, for example, for filters. */ typedef struct git_writestream git_writestream; +/** A type to write in a streaming fashion, for example, for filters. */ struct git_writestream { int (*write)(git_writestream *stream, const char *buffer, size_t len); int (*close)(git_writestream *stream); diff --git a/include/git2/worktree.h b/include/git2/worktree.h index d6d4ce5cf..d1b4f84c2 100644 --- a/include/git2/worktree.h +++ b/include/git2/worktree.h @@ -74,6 +74,13 @@ GIT_EXTERN(void) git_worktree_free(git_worktree *wt); */ GIT_EXTERN(int) git_worktree_validate(const git_worktree *wt); +/** + * Worktree add options structure + * + * Initialize with `GIT_WORKTREE_ADD_OPTIONS_INIT`. Alternatively, you can + * use `git_worktree_add_init_options`. + * + */ typedef struct git_worktree_add_options { unsigned int version; @@ -85,12 +92,13 @@ typedef struct git_worktree_add_options { #define GIT_WORKTREE_ADD_OPTIONS_INIT {GIT_WORKTREE_ADD_OPTIONS_VERSION,0,NULL} /** - * Initializes a `git_worktree_add_options` with default vaules. - * Equivalent to creating an instance with - * GIT_WORKTREE_ADD_OPTIONS_INIT. + * Initialize git_worktree_add_options structure + * + * Initializes a `git_worktree_add_options` with default values. Equivalent to + * creating an instance with `GIT_WORKTREE_ADD_OPTIONS_INIT`. * - * @param opts the struct to initialize - * @param version Verison of struct; pass `GIT_WORKTREE_ADD_OPTIONS_VERSION` + * @param opts The `git_worktree_add_options` struct to initialize. + * @param version The struct version; pass `GIT_WORKTREE_ADD_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ int git_worktree_add_init_options(git_worktree_add_options *opts, @@ -180,6 +188,13 @@ typedef enum { GIT_WORKTREE_PRUNE_WORKING_TREE = 1u << 2, } git_worktree_prune_t; +/** + * Worktree prune options structure + * + * Initialize with `GIT_WORKTREE_PRUNE_OPTIONS_INIT`. Alternatively, you can + * use `git_worktree_prune_init_options`. + * + */ typedef struct git_worktree_prune_options { unsigned int version; @@ -190,12 +205,13 @@ typedef struct git_worktree_prune_options { #define GIT_WORKTREE_PRUNE_OPTIONS_INIT {GIT_WORKTREE_PRUNE_OPTIONS_VERSION,0} /** - * Initializes a `git_worktree_prune_options` with default vaules. - * Equivalent to creating an instance with - * GIT_WORKTREE_PRUNE_OPTIONS_INIT. + * Initialize git_worktree_prune_options structure + * + * Initializes a `git_worktree_prune_options` with default values. Equivalent to + * creating an instance with `GIT_WORKTREE_PRUNE_OPTIONS_INIT`. * - * @param opts the struct to initialize - * @param version Verison of struct; pass `GIT_WORKTREE_PRUNE_OPTIONS_VERSION` + * @param opts The `git_worktree_prune_options` struct to initialize. + * @param version The struct version; pass `GIT_WORKTREE_PRUNE_OPTIONS_VERSION`. * @return Zero on success; -1 on failure. */ GIT_EXTERN(int) git_worktree_prune_init_options( diff --git a/libgit2_clar.supp b/libgit2_clar.supp index bd22ada46..0cc89b57f 100644 --- a/libgit2_clar.supp +++ b/libgit2_clar.supp @@ -47,3 +47,28 @@ ... fun:__check_pf } + +{ + ignore-curl-global-init + Memcheck:Leak + ... + fun:curl_global_init +} + +{ + ignore-libssh2-gcrypt-leak + Memcheck:Leak + ... + fun:gcry_control + obj:*libssh2.so* +} + +{ + ignore-noai6ai_cached-double-free + Memcheck:Free + fun:free + fun:__libc_freeres + ... + fun:exit + ... +} diff --git a/script/cibuild.sh b/script/cibuild.sh index 5d70e7506..8e6d68e37 100755 --- a/script/cibuild.sh +++ b/script/cibuild.sh @@ -2,10 +2,9 @@ set -x -if [ -n "$COVERITY" ]; -then - ./script/coverity.sh; - exit $?; +if [ -n "$COVERITY" ]; then + ./script/coverity.sh + exit $? fi if [ "$TRAVIS_OS_NAME" = "osx" ]; then @@ -21,82 +20,8 @@ if [ "$TRAVIS_OS_NAME" = "osx" ]; then mount -t hfs $device $CLAR_TMP fi -# Should we ask Travis to cache this file? -curl -L https://github.com/ethomson/poxyproxy/releases/download/v0.1.0/poxyproxy-0.1.0.jar >poxyproxy.jar || exit $? -# Run this early so we know it's ready by the time we need it -java -jar poxyproxy.jar -d --port 8080 --credentials foo:bar & - mkdir _build cd _build # shellcheck disable=SC2086 -cmake .. -DBUILD_EXAMPLES=ON -DCMAKE_INSTALL_PREFIX=../_install $OPTIONS || exit $? -make -j2 install || exit $? - -# If this platform doesn't support test execution, bail out now -if [ -n "$SKIP_TESTS" ]; -then - exit $?; -fi - -# Create a test repo which we can use for the online::push tests -mkdir "$HOME"/_temp -git init --bare "$HOME"/_temp/test.git -git daemon --listen=localhost --export-all --enable=receive-pack --base-path="$HOME"/_temp "$HOME"/_temp 2>/dev/null & -export GITTEST_REMOTE_URL="git://localhost/test.git" - -# Run the test suite -ctest -V -R libgit2_clar || exit $? - -# Now that we've tested the raw git protocol, let's set up ssh to we -# can do the push tests over it - -killall git-daemon - -# Set up sshd -mkdir ~/sshd/ -cat >~/sshd/sshd_config<<-EOF - Port 2222 - ListenAddress 0.0.0.0 - Protocol 2 - HostKey ${HOME}/sshd/id_rsa - PidFile ${HOME}/sshd/pid - RSAAuthentication yes - PasswordAuthentication yes - PubkeyAuthentication yes - ChallengeResponseAuthentication no - # Required here as sshd will simply close connection otherwise - UsePAM no -EOF -ssh-keygen -t rsa -f ~/sshd/id_rsa -N "" -q -/usr/sbin/sshd -f ~/sshd/sshd_config - -# Set up keys -ssh-keygen -t rsa -f ~/.ssh/id_rsa -N "" -q -cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys -while read algorithm key comment; do - echo "[localhost]:2222 $algorithm $key" >>~/.ssh/known_hosts -done <~/sshd/id_rsa.pub - -# Get the fingerprint for localhost and remove the colons so we can parse it as -# a hex number. The Mac version is newer so it has a different output format. -if [ "$TRAVIS_OS_NAME" = "osx" ]; then - export GITTEST_REMOTE_SSH_FINGERPRINT=$(ssh-keygen -E md5 -F '[localhost]:2222' -l | tail -n 1 | cut -d ' ' -f 3 | cut -d : -f2- | tr -d :) -else - export GITTEST_REMOTE_SSH_FINGERPRINT=$(ssh-keygen -F '[localhost]:2222' -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':') -fi - -# Use the SSH server -export GITTEST_REMOTE_URL="ssh://localhost:2222/$HOME/_temp/test.git" -export GITTEST_REMOTE_USER=$USER -export GITTEST_REMOTE_SSH_KEY="$HOME/.ssh/id_rsa" -export GITTEST_REMOTE_SSH_PUBKEY="$HOME/.ssh/id_rsa.pub" -export GITTEST_REMOTE_SSH_PASSPHRASE="" -ctest -V -R libgit2_clar-ssh || exit $? - -# Use the proxy we started at the beginning -export GITTEST_REMOTE_PROXY_URL="localhost:8080" -export GITTEST_REMOTE_PROXY_USER="foo" -export GITTEST_REMOTE_PROXY_PASS="bar" -ctest -V -R libgit2_clar-proxy_credentials || exit $? - -kill $(cat "$HOME/sshd/pid") +cmake .. -DBUILD_EXAMPLES=ON -DENABLE_WERROR=ON -DCMAKE_INSTALL_PREFIX=../_install $OPTIONS || exit $? +cmake --build . --target install || exit $? diff --git a/script/cileaks.sh b/script/cileaks.sh new file mode 100755 index 000000000..4163613af --- /dev/null +++ b/script/cileaks.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +set -x + +# If this platform doesn't support test execution, bail out now +if [ -n "$SKIP_TESTS" ]; +then + exit $? +fi + +if [ -n "$VALGRIND" -a -e "$(which valgrind)" ]; then + valgrind --leak-check=full --show-reachable=yes --error-exitcode=125 --num-callers=50 --suppressions=./libgit2_clar.supp _build/libgit2_clar $@ -ionline -xbuf::oom +elif [ -n "$LEAKS" -a -e "$(which leaks)" ]; then + MallocStackLogging=1 MallocScribble=1 leaks -atExit -- _build/libgit2_clar -ionline +fi diff --git a/script/citest.sh b/script/citest.sh new file mode 100755 index 000000000..7e6cdb7d7 --- /dev/null +++ b/script/citest.sh @@ -0,0 +1,82 @@ +#!/bin/sh + +set -x + +# If this platform doesn't support test execution, bail out now +if [ -n "$SKIP_TESTS" ]; then + exit $? +fi + +if [ ! -d _build ]; then + echo "no _build dir found; you should run cibuild.sh first" + exit 1 +fi +cd _build + +# Should we ask Travis to cache this file? +curl -L https://github.com/ethomson/poxyproxy/releases/download/v0.1.0/poxyproxy-0.1.0.jar >poxyproxy.jar || exit $? +# Run this early so we know it's ready by the time we need it +java -jar poxyproxy.jar -d --port 8080 --credentials foo:bar & + +# Create a test repo which we can use for the online::push tests +mkdir "$HOME"/_temp +git init --bare "$HOME"/_temp/test.git +git daemon --listen=localhost --export-all --enable=receive-pack --base-path="$HOME"/_temp "$HOME"/_temp 2>/dev/null & +export GITTEST_REMOTE_URL="git://localhost/test.git" + +# Run the test suite +ctest -V -R libgit2_clar || exit $? + +# Now that we've tested the raw git protocol, let's set up ssh to we +# can do the push tests over it + +killall git-daemon + +# Set up sshd +mkdir ~/sshd/ +cat >~/sshd/sshd_config<<-EOF + Port 2222 + ListenAddress 0.0.0.0 + Protocol 2 + HostKey ${HOME}/sshd/id_rsa + PidFile ${HOME}/sshd/pid + RSAAuthentication yes + PasswordAuthentication yes + PubkeyAuthentication yes + ChallengeResponseAuthentication no + # Required here as sshd will simply close connection otherwise + UsePAM no +EOF +ssh-keygen -t rsa -f ~/sshd/id_rsa -N "" -q +/usr/sbin/sshd -f ~/sshd/sshd_config + +# Set up keys +ssh-keygen -t rsa -f ~/.ssh/id_rsa -N "" -q +cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys +while read algorithm key comment; do + echo "[localhost]:2222 $algorithm $key" >>~/.ssh/known_hosts +done <~/sshd/id_rsa.pub + +# Get the fingerprint for localhost and remove the colons so we can parse it as +# a hex number. The Mac version is newer so it has a different output format. +if [ "$TRAVIS_OS_NAME" = "osx" ]; then + export GITTEST_REMOTE_SSH_FINGERPRINT=$(ssh-keygen -E md5 -F '[localhost]:2222' -l | tail -n 1 | cut -d ' ' -f 3 | cut -d : -f2- | tr -d :) +else + export GITTEST_REMOTE_SSH_FINGERPRINT=$(ssh-keygen -F '[localhost]:2222' -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':') +fi + +# Use the SSH server +export GITTEST_REMOTE_URL="ssh://localhost:2222/$HOME/_temp/test.git" +export GITTEST_REMOTE_USER=$USER +export GITTEST_REMOTE_SSH_KEY="$HOME/.ssh/id_rsa" +export GITTEST_REMOTE_SSH_PUBKEY="$HOME/.ssh/id_rsa.pub" +export GITTEST_REMOTE_SSH_PASSPHRASE="" +ctest -V -R libgit2_clar-ssh || exit $? + +# Use the proxy we started at the beginning +export GITTEST_REMOTE_PROXY_URL="localhost:8080" +export GITTEST_REMOTE_PROXY_USER="foo" +export GITTEST_REMOTE_PROXY_PASS="bar" +ctest -V -R libgit2_clar-proxy_credentials || exit $? + +kill $(cat "$HOME/sshd/pid") diff --git a/src/refdb_fs.c b/src/refdb_fs.c index 9db62810b..0b4bbb408 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -538,12 +538,16 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter) } if ((error = git_buf_printf(&path, "%s/", backend->commonpath)) < 0 || - (error = git_buf_put(&path, ref_prefix, ref_prefix_len)) < 0 || - (error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) { + (error = git_buf_put(&path, ref_prefix, ref_prefix_len)) < 0) { git_buf_free(&path); return error; } + if ((error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) { + git_buf_free(&path); + return (iter->glob && error == GIT_ENOTFOUND)? 0 : error; + } + error = git_buf_sets(&path, ref_prefix); while (!error && !git_iterator_advance(&entry, fsit)) { diff --git a/src/submodule.c b/src/submodule.c index b927b17b6..d0aef2eeb 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -199,13 +199,16 @@ out: */ static void free_submodule_names(git_strmap *names) { - git_buf *name = 0; + git_buf *name; + if (names == NULL) return; + git_strmap_foreach_value(names, name, { git__free(name); }); git_strmap_free(names); + return; } @@ -214,23 +217,36 @@ static void free_submodule_names(git_strmap *names) * TODO: for some use-cases, this might need case-folding on a * case-insensitive filesystem */ -static int load_submodule_names(git_strmap *out, git_repository *repo, git_config *cfg) +static int load_submodule_names(git_strmap **out, git_repository *repo, git_config *cfg) { const char *key = "submodule\\..*\\.path"; - git_config_iterator *iter; + git_config_iterator *iter = NULL; git_config_entry *entry; git_buf buf = GIT_BUF_INIT; + git_strmap *names; int rval, isvalid; int error = 0; + *out = NULL; + + if ((error = git_strmap_alloc(&names)) < 0) + goto out; + if ((error = git_config_iterator_glob_new(&iter, cfg, key)) < 0) - return error; + goto out; while (git_config_next(&entry, iter) == 0) { const char *fdot, *ldot; fdot = strchr(entry->name, '.'); ldot = strrchr(entry->name, '.'); + if (git_strmap_exists(names, entry->value)) { + giterr_set(GITERR_SUBMODULE, + "duplicated submodule path '%s'", entry->value); + error = -1; + goto out; + } + git_buf_clear(&buf); git_buf_put(&buf, fdot + 1, ldot - fdot - 1); isvalid = git_submodule_name_is_valid(repo, buf.ptr, 0); @@ -241,7 +257,7 @@ static int load_submodule_names(git_strmap *out, git_repository *repo, git_confi if (!isvalid) continue; - git_strmap_insert(out, entry->value, git_buf_detach(&buf), &rval); + git_strmap_insert(names, entry->value, git_buf_detach(&buf), &rval); if (rval < 0) { giterr_set(GITERR_NOMEMORY, "error inserting submodule into hash table"); return -1; @@ -250,7 +266,11 @@ static int load_submodule_names(git_strmap *out, git_repository *repo, git_confi if (error == GIT_ITEROVER) error = 0; + *out = names; + names = NULL; + out: + free_submodule_names(names); git_buf_free(&buf); git_config_iterator_free(iter); return error; @@ -436,10 +456,9 @@ static int submodules_from_index(git_strmap *map, git_index *idx, git_config *cf int error; git_iterator *i = NULL; const git_index_entry *entry; - git_strmap *names = 0; + git_strmap *names; - git_strmap_alloc(&names); - if ((error = load_submodule_names(names, git_index_owner(idx), cfg))) + if ((error = load_submodule_names(&names, git_index_owner(idx), cfg))) goto done; if ((error = git_iterator_for_index(&i, git_index_owner(idx), idx, NULL)) < 0) @@ -489,9 +508,9 @@ static int submodules_from_head(git_strmap *map, git_tree *head, git_config *cfg int error; git_iterator *i = NULL; const git_index_entry *entry; - git_strmap *names = 0; - git_strmap_alloc(&names); - if ((error = load_submodule_names(names, git_tree_owner(head), cfg))) + git_strmap *names; + + if ((error = load_submodule_names(&names, git_tree_owner(head), cfg))) goto done; if ((error = git_iterator_for_tree(&i, head, NULL)) < 0) @@ -553,7 +572,6 @@ int git_submodule__map(git_repository *repo, git_strmap *map) git_buf path = GIT_BUF_INIT; git_submodule *sm; git_config *mods = NULL; - uint32_t mask; assert(repo && map); @@ -567,22 +585,6 @@ int git_submodule__map(git_repository *repo, git_strmap *map) if (wd && (error = git_buf_joinpath(&path, wd, GIT_MODULES_FILE)) < 0) goto cleanup; - /* clear submodule flags that are to be refreshed */ - mask = 0; - mask |= GIT_SUBMODULE_STATUS_IN_INDEX | - GIT_SUBMODULE_STATUS__INDEX_FLAGS | - GIT_SUBMODULE_STATUS__INDEX_OID_VALID | - GIT_SUBMODULE_STATUS__INDEX_MULTIPLE_ENTRIES; - - mask |= GIT_SUBMODULE_STATUS_IN_HEAD | - GIT_SUBMODULE_STATUS__HEAD_OID_VALID; - mask |= GIT_SUBMODULE_STATUS_IN_CONFIG; - if (mask != 0) - mask |= GIT_SUBMODULE_STATUS_IN_WD | - GIT_SUBMODULE_STATUS__WD_SCANNED | - GIT_SUBMODULE_STATUS__WD_FLAGS | - GIT_SUBMODULE_STATUS__WD_OID_VALID; - /* add submodule information from .gitmodules */ if (wd) { lfc_data data = { 0 }; @@ -611,7 +613,7 @@ int git_submodule__map(git_repository *repo, git_strmap *map) goto cleanup; } /* shallow scan submodules in work tree as needed */ - if (wd && mask != 0) { + if (wd) { git_strmap_foreach_value(map, sm, { submodule_load_from_wd_lite(sm); }); diff --git a/tests/refs/foreachglob.c b/tests/refs/foreachglob.c index a09191e79..a13529376 100644 --- a/tests/refs/foreachglob.c +++ b/tests/refs/foreachglob.c @@ -62,6 +62,11 @@ void test_refs_foreachglob__retrieve_local_branches(void) assert_retrieval("refs/heads/*", 12); } +void test_refs_foreachglob__retrieve_nonexistant(void) +{ + assert_retrieval("refs/nonexistent/*", 0); +} + void test_refs_foreachglob__retrieve_partially_named_references(void) { /* diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c index 170be5a44..f73ca2679 100644 --- a/tests/submodule/lookup.c +++ b/tests/submodule/lookup.c @@ -132,6 +132,27 @@ void test_submodule_lookup__foreach(void) cl_assert_equal_i(8, data.count); } +static int foreach_cb(git_submodule *sm, const char *name, void *payload) +{ + GIT_UNUSED(sm); + GIT_UNUSED(name); + GIT_UNUSED(payload); + return 0; +} + +void test_submodule_lookup__duplicated_path(void) +{ + cl_git_rewritefile("submod2/.gitmodules", + "[submodule \"sm1\"]\n" + " path = duplicated-path\n" + " url = sm1\n" + "[submodule \"sm2\"]\n" + " path = duplicated-path\n" + " url = sm2\n"); + + cl_git_fail(git_submodule_foreach(g_repo, foreach_cb, NULL)); +} + void test_submodule_lookup__lookup_even_with_unborn_head(void) { git_reference *head; @@ -430,14 +451,6 @@ void test_submodule_lookup__lookup_in_bare_repository_fails(void) cl_git_fail(git_submodule_lookup(&sm, g_repo, "nonexisting")); } -static int foreach_cb(git_submodule *sm, const char *name, void *payload) -{ - GIT_UNUSED(sm); - GIT_UNUSED(name); - GIT_UNUSED(payload); - return 0; -} - void test_submodule_lookup__foreach_in_bare_repository_fails(void) { cl_git_sandbox_cleanup(); |
