Merge branch 'master' into pr/3938

This commit is contained in:
Edward Thomson 2017-01-21 22:39:59 +00:00
commit 9e78b7279d
155 changed files with 2809 additions and 1590 deletions

14
.github/ISSUE_TEMPLATE vendored Normal file
View File

@ -0,0 +1,14 @@
You are opening a _bug report_ against the libgit2 project. If you have a
question about an API or usage, please ask on StackOverflow:
http://stackoverflow.com/questions/tagged/libgit2. Please fill out the
reproduction steps (below) and delete this introductory paragraph. Thanks!
### Reproduction steps
### Expected behavior
### Actual behavior
### Version of libgit2 (release number or SHA1)
### Operating system(s) tested

View File

@ -47,9 +47,6 @@ matrix:
os: linux
allow_failures:
- env: COVERITY=1
- env:
- VALGRIND=1
OPTIONS="-DBUILD_CLAR=ON -DBUILD_EXAMPLES=OFF -DDEBUG_POOL=ON -DCMAKE_BUILD_TYPE=Debug"
install:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then ./script/install-deps-${TRAVIS_OS_NAME}.sh; fi

View File

@ -1,4 +1,19 @@
v0.24 + 1
v0.25 + 1
-------
### Changes or improvements
* `GIT_MERGE_OPTIONS_INIT` now includes a setting to perform rename detection.
This aligns this structure with the default by `git_merge` and
`git_merge_trees` when `NULL` was provided for the options.
### API additions
### API removals
### Breaking API changes
v0.25
-------
### Changes or improvements
@ -17,14 +32,37 @@ v0.24 + 1
* Improve the performance of the revwalk and bring us closer to git's code.
* The reference db has improved support for concurrency and returns `GIT_ELOCKED`
when an operation could not be performed due to locking.
* Nanosecond resolution is now activated by default, following git's change to
do this.
* We now restrict the set of ciphers we let OpenSSL use by default.
* Users can now register their own merge drivers for use with `.gitattributes`.
The library also gained built-in support for the union merge driver.
* The default for creating references is now to validate that the object does
exist.
* Add `git_proxy_options` which is used by the different networking
implementations to let the caller specify the proxy settings instead of
relying on the environment variables.
### API additions
* You can now get the user-agent used by libgit2 using the
`GIT_OPT_GET_USER_AGENT` option with `git_libgit2_opts()`.
It is the counterpart to `GIT_OPT_SET_USER_AGENT`.
* The `GIT_OPT_SET_SSL_CIPHERS` option for `git_libgit2_opts()` lets you specify
a custom list of ciphers to use for OpenSSL.
* `git_commit_create_buffer()` creates a commit and writes it into a
user-provided buffer instead of writing it into the object db.
user-provided buffer instead of writing it into the object db. Combine it with
`git_commit_create_with_signature()` in order to create a commit with a
cryptographic signature.
* `git_blob_create_fromstream()` and
`git_blob_create_fromstream_commit()` allow you to create a blob by
@ -50,12 +88,48 @@ v0.24 + 1
`git_repository_open_ext` with this flag will error out if either
`$GIT_WORK_TREE` or `$GIT_COMMON_DIR` is set.
* `git_diff_from_buffer` can create a `git_diff` object from the contents
* `git_diff_from_buffer()` can create a `git_diff` object from the contents
of a git-style patch file.
* `git_index_version()` and `git_index_set_version()` to get and set
the index version
* `git_odb_expand_ids()` lets you check for the existence of multiple
objects at once.
* The new `git_blob_dup()`, `git_commit_dup()`, `git_tag_dup()` and
`git_tree_dup()` functions provide type-specific wrappers for
`git_object_dup()` to reduce noise and increase type safety for callers.
* `git_reference_dup()` lets you duplicate a reference to aid in ownership
management and cleanup.
* `git_signature_from_buffer()` lets you create a signature from a string in the
format that appear in objects.
* `git_tree_create_updated()` lets you create a tree based on another one
together with a list of updates. For the covered update cases, it's more
efficient than the `git_index` route.
* `git_apply_patch()` applies hunks from a `git_patch` to a buffer.
* `git_diff_to_buf()` lets you print an entire diff directory to a buffer,
similar to how `git_patch_to_buf()` works.
* `git_proxy_init_options()` is added to initialize a `git_proxy_options`
structure at run-time.
* `git_merge_driver_register()`, `git_merge_driver_unregister()` let you
register and unregister a custom merge driver to be used when `.gitattributes`
specifies it.
* `git_merge_driver_lookup()` can be used to look up a merge driver by name.
* `git_merge_driver_source_repo()`, `git_merge_driver_source_ancestor()`,
`git_merge_driver_source_ours()`, `git_merge_driver_source_theirs()`,
`git_merge_driver_source_file_options()` added as accessors to
`git_merge_driver_source`.
### API removals
* `git_blob_create_fromchunks()` has been removed in favour of
@ -84,6 +158,13 @@ v0.24 + 1
If this is `NULL`, then it will not be called and the `exists` function
will be used instead.
* `git_remote_connect()` now accepts `git_proxy_options` argument, and
`git_fetch_options` and `git_push_options` each have a `proxy_opts` field.
* `git_merge_options` now provides a `default_driver` that can be used
to provide the name of a merge driver to be used to handle files changed
during a merge.
v0.24
-------
@ -159,10 +240,6 @@ v0.24
### Breaking API changes
* `git_merge_options` now provides a `default_driver` that can be used
to provide the name of a merge driver to be used to handle files changed
during a merge.
* The `git_merge_tree_flag_t` is now `git_merge_flag_t`. Subsequently,
its members are no longer prefixed with `GIT_MERGE_TREE_FLAG` but are
now prefixed with `GIT_MERGE_FLAG`, and the `tree_flags` field of the

View File

@ -237,8 +237,6 @@ ENDIF()
IF (WIN32 AND WINHTTP)
ADD_DEFINITIONS(-DGIT_WINHTTP)
INCLUDE_DIRECTORIES(deps/http-parser)
FILE(GLOB SRC_HTTP deps/http-parser/*.c deps/http-parser/*.h)
# Since MinGW does not come with headers or an import library for winhttp,
# we have to include a private header and generate our own import library
@ -291,17 +289,6 @@ ELSE ()
LINK_LIBRARIES(${CURL_LIBRARIES})
LIST(APPEND LIBGIT2_PC_LIBS ${CURL_LDFLAGS})
ENDIF()
FIND_PACKAGE(HTTP_Parser)
IF (HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
INCLUDE_DIRECTORIES(${HTTP_PARSER_INCLUDE_DIRS})
LINK_LIBRARIES(${HTTP_PARSER_LIBRARIES})
LIST(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
ELSE()
MESSAGE(STATUS "http-parser was not found or is too old; using bundled 3rd-party sources.")
INCLUDE_DIRECTORIES(deps/http-parser)
FILE(GLOB SRC_HTTP deps/http-parser/*.c deps/http-parser/*.h)
ENDIF()
ENDIF()
# Specify sha1 implementation
@ -332,6 +319,18 @@ IF(WIN32 OR AMIGA OR CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
SET(SRC_REGEX deps/regex/regex.c)
ENDIF()
# Optional external dependency: http-parser
FIND_PACKAGE(HTTP_Parser)
IF (HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
INCLUDE_DIRECTORIES(${HTTP_PARSER_INCLUDE_DIRS})
LINK_LIBRARIES(${HTTP_PARSER_LIBRARIES})
LIST(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
ELSE()
MESSAGE(STATUS "http-parser version 2 was not found; using bundled 3rd-party sources.")
INCLUDE_DIRECTORIES(deps/http-parser)
FILE(GLOB SRC_HTTP deps/http-parser/*.c deps/http-parser/*.h)
ENDIF()
# Optional external dependency: zlib
FIND_PACKAGE(ZLIB)
IF (ZLIB_FOUND)

View File

@ -5,7 +5,7 @@ So, you want to start helping out with `libgit2`? That's fantastic! We
welcome contributions and we promise we'll try to be nice.
This is a list of libgit2 related projects that new contributors can take
on. It includes a number of good starter projects and well as some larger
on. It includes a number of good starter projects as well as some larger
ideas that no one is actively working on.
## Before You Start
@ -70,11 +70,11 @@ some incremental steps listed towards the larger goal. Those steps
might make good smaller projects by themselves.
* Port part of the Git test suite to run against the command line emulation
in examples/
* Pick a Git command that is emulated in our examples/ area
in `examples/`
* Pick a Git command that is emulated in our `examples/` area
* Extract the Git tests that exercise that command
* Convert the tests to call our emulation
* These tests could go in examples/tests/...
* These tests could go in `examples/tests/`...
* Add hooks API to enumerate and manage hooks (not run them at this point)
* Enumeration of available hooks
* Lookup API to see which hooks have a script and get the script

View File

@ -43,9 +43,17 @@ We ask that you not open a GitHub Issue for help, only for bug reports.
What It Can Do
==============
`libgit2` is already very usable and is being used in production for many
applications including the GitHub.com site, in Plastic SCM and also powering
Microsoft's Visual Studio tools for Git. The library provides:
The goal of this library is to allow its users the ability to handle Git data in
their applications from their programming language of choice, as is used in
production for many applications including the GitHub.com site, in Plastic SCM
and also powering Microsoft's Visual Studio tools for Git.
It does not aim to replace the git tool or its user-facing commands. Some APIs
resemble the plumbing commands as those align closely with the concepts of the
Git system, but most commands a user would type are out of scope for this
library to implement directly.
The library provides:
* SHA conversions, formatting and shortening
* abstracted ODB backend system
@ -236,7 +244,7 @@ Here are the bindings to libgit2 that are currently available:
* Rust
* git2-rs <https://github.com/alexcrichton/git2-rs>
* Swift
* Gift <https://github.com/modocache/Gift>
* SwiftGit2 <https://github.com/SwiftGit2/SwiftGit2>
* Vala
* libgit2.vapi <https://github.com/apmasell/vapis/blob/master/libgit2.vapi>

View File

@ -62,33 +62,38 @@ general case still affects you if you use ssh.
General Case
------------
By default we use libcurl, which has its own ![recommendations for
thread safety](http://curl.haxx.se/libcurl/c/libcurl-tutorial.html#Multi-threading).
If it's available, by default we use libcurl to provide HTTP tunneling support,
which may be linked against a number of cryptographic libraries and has its
own
[recommendations for thread safety](https://curl.haxx.se/libcurl/c/threadsafe.html).
If libcurl was not found or was disabled, libgit2 uses OpenSSL to be
able to use HTTPS as a transport. This library is made to be
thread-implementation agnostic, and the users of the library must set
which locking function it should use. This means that libgit2 cannot
know what to set as the user of libgit2 may use OpenSSL independently
and the locking settings must survive libgit2 shutting down.
If there are no alternative TLS implementations (currently only
SecureTransport), libgit2 uses OpenSSL in order to use HTTPS as a transport.
OpenSSL is thread-safe starting at version 1.1.0. If your copy of libgit2 is
linked against that version, you do not need to take any further steps.
Even if libgit2 doesn't use OpenSSL directly, OpenSSL can still be used
by libssh2 depending on the configuration. If OpenSSL is used both by
libgit2 and libssh2, you only need to set up threading for OpenSSL once.
Older versions of OpenSSL are made to be thread-implementation agnostic, and the
users of the library must set which locking function it should use. libgit2
cannot know what to set as the user of libgit2 may also be using OpenSSL independently and
the locking settings must then live outside the lifetime of libgit2.
libgit2 does provide a last-resort convenience function
Even if libgit2 doesn't use OpenSSL directly, OpenSSL can still be used by
libssh2 or libcurl depending on the configuration. If OpenSSL is used by
more than one library, you only need to set up threading for OpenSSL once.
If libgit2 is linked against OpenSSL, it provides a last-resort convenience function
`git_openssl_set_locking()` (available in `sys/openssl.h`) to use the
platform-native mutex mechanisms to perform the locking, which you may
rely on if you do not want to use OpenSSL outside of libgit2, or you
know that libgit2 will outlive the rest of the operations. It is not
platform-native mutex mechanisms to perform the locking, which you can use
if you do not want to use OpenSSL outside of libgit2, or you
know that libgit2 will outlive the rest of the operations. It is then not
safe to use OpenSSL multi-threaded after libgit2's shutdown function
has been called. Note `git_openssl_set_locking()` only works if
libgit2 uses OpenSSL directly - if OpenSSL is only used as a dependency
of libssh2 as described above, `git_openssl_set_locking()` is a no-op.
of libssh2 or libcurl as described above, `git_openssl_set_locking()` is a no-op.
If your programming language offers a package/bindings for OpenSSL,
you should very strongly prefer to use that in order to set up
locking, as they provide a level of coördination which is impossible
locking, as they provide a level of coordination which is impossible
when using this function.
See the
@ -96,13 +101,10 @@ See the
on threading for more details, and http://trac.libssh2.org/wiki/MultiThreading
for a specific example of providing the threading callbacks.
Be also aware that libgit2 does not always link against OpenSSL
if there are alternatives provided by the system.
libssh2 may be linked against OpenSSL or libgcrypt. If it uses OpenSSL,
see the above paragraphs. If it uses libgcrypt, then you need to
set up its locking before using it multi-threaded. libgit2 has no
direct connection to libgcrypt and thus has not convenience functions for
direct connection to libgcrypt and thus has no convenience functions for
it (but libgcrypt has macros). Read libgcrypt's
[threading documentation for more information](http://www.gnupg.org/documentation/manuals/gcrypt/Multi_002dThreading.html)

View File

@ -75,15 +75,14 @@ int print_matched_cb(const char *path, const char *matched_pathspec, void *paylo
{
struct print_payload p = *(struct print_payload*)(payload);
int ret;
git_status_t status;
unsigned status;
(void)matched_pathspec;
if (git_status_file((unsigned int*)(&status), p.repo, path)) {
return -1; //abort
if (git_status_file(&status, p.repo, path)) {
return -1;
}
if (status & GIT_STATUS_WT_MODIFIED ||
status & GIT_STATUS_WT_NEW) {
if (status & GIT_STATUS_WT_MODIFIED || status & GIT_STATUS_WT_NEW) {
printf("add '%s'\n", path);
ret = 0;
} else {

View File

@ -146,6 +146,25 @@ int match_uint16_arg(
return 1;
}
int match_uint32_arg(
uint32_t *out, struct args_info *args, const char *opt)
{
const char *found = match_numeric_arg(args, opt);
uint16_t val;
char *endptr = NULL;
if (!found)
return 0;
val = (uint32_t)strtoul(found, &endptr, 0);
if (!endptr || *endptr != '\0')
fatal("expected number after argument", opt);
if (out)
*out = val;
return 1;
}
static int match_int_internal(
int *out, const char *str, int allow_negative, const char *opt)
{

View File

@ -72,6 +72,15 @@ extern int match_str_arg(
extern int match_uint16_arg(
uint16_t *out, struct args_info *args, const char *opt);
/**
* Check current `args` entry against `opt` string parsing as uint32. If
* `opt` matches exactly, take the next arg as a uint16_t value; if `opt`
* is a prefix (equal sign optional), take the remainder of the arg as a
* uint32_t value; otherwise return 0.
*/
extern int match_uint32_arg(
uint32_t *out, struct args_info *args, const char *opt);
/**
* Check current `args` entry against `opt` string parsing as int. If
* `opt` matches exactly, take the next arg as an int value; if it matches

View File

@ -293,11 +293,11 @@ static void parse_opts(struct opts *o, int argc, char *argv[])
else if (is_prefixed(a, "-B") || is_prefixed(a, "--break-rewrites"))
/* TODO: parse thresholds */
o->findopts.flags |= GIT_DIFF_FIND_REWRITES;
else if (!match_uint16_arg(
else if (!match_uint32_arg(
&o->diffopts.context_lines, &args, "-U") &&
!match_uint16_arg(
!match_uint32_arg(
&o->diffopts.context_lines, &args, "--unified") &&
!match_uint16_arg(
!match_uint32_arg(
&o->diffopts.interhunk_lines, &args, "--inter-hunk-context") &&
!match_uint16_arg(
&o->diffopts.id_abbrev, &args, "--abbrev") &&

File diff suppressed because it is too large Load Diff

View File

@ -50,7 +50,7 @@ static int sideband_progress(const char *str, int len, void *payload)
{
(void)payload; // unused
printf("remote: %*s", len, str);
printf("remote: %.*s", len, str);
fflush(stdout);
return 0;
}

View File

@ -55,6 +55,8 @@ static int update_cb(const char *refname, const git_oid *a, const git_oid *b, vo
*/
static int transfer_progress_cb(const git_transfer_progress *stats, void *payload)
{
(void)payload;
if (stats->received_objects == stats->total_objects) {
printf("Resolving deltas %d/%d\r",
stats->indexed_deltas, stats->total_deltas);
@ -71,7 +73,6 @@ int fetch(git_repository *repo, int argc, char **argv)
{
git_remote *remote = NULL;
const git_transfer_progress *stats;
struct dl_data data;
git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT;
if (argc < 2) {
@ -79,14 +80,13 @@ int fetch(git_repository *repo, int argc, char **argv)
return EXIT_FAILURE;
}
// Figure out whether it's a named remote or a URL
/* Figure out whether it's a named remote or a URL */
printf("Fetching %s for repo %p\n", argv[1], repo);
if (git_remote_lookup(&remote, repo, argv[1]) < 0) {
if (git_remote_lookup(&remote, repo, argv[1]) < 0)
if (git_remote_create_anonymous(&remote, repo, argv[1]) < 0)
return -1;
}
goto on_error;
// Set up the callbacks (only update_tips for now)
/* Set up the callbacks (only update_tips for now) */
fetch_opts.callbacks.update_tips = &update_cb;
fetch_opts.callbacks.sideband_progress = &progress_cb;
fetch_opts.callbacks.transfer_progress = transfer_progress_cb;
@ -98,7 +98,7 @@ int fetch(git_repository *repo, int argc, char **argv)
* "fetch".
*/
if (git_remote_fetch(remote, NULL, &fetch_opts, "fetch") < 0)
return -1;
goto on_error;
/**
* If there are local objects (we got a thin pack), then tell

View File

@ -109,9 +109,27 @@ GIT_EXTERN(void) git_libgit2_version(int *major, int *minor, int *rev);
* was compiled
*/
typedef enum {
/**
* If set, libgit2 was built thread-aware and can be safely used from multiple
* threads.
*/
GIT_FEATURE_THREADS = (1 << 0),
/**
* If set, libgit2 was built with and linked against a TLS implementation.
* Custom TLS streams may still be added by the user to support HTTPS
* regardless of this.
*/
GIT_FEATURE_HTTPS = (1 << 1),
/**
* If set, libgit2 was built with and linked against libssh2. A custom
* transport may still be added by the user to support libssh2 regardless of
* this.
*/
GIT_FEATURE_SSH = (1 << 2),
/**
* If set, libgit2 was built with support for sub-second resolution in file
* modification times.
*/
GIT_FEATURE_NSEC = (1 << 3),
} git_feature_t;

View File

@ -44,8 +44,8 @@ typedef enum {
typedef struct git_describe_options {
unsigned int version;
unsigned int max_candidates_tags; /** default: 10 */
unsigned int describe_strategy; /** default: GIT_DESCRIBE_DEFAULT */
unsigned int max_candidates_tags; /**< default: 10 */
unsigned int describe_strategy; /**< default: GIT_DESCRIBE_DEFAULT */
const char *pattern;
/**
* When calculating the distance from the matching tag or
@ -105,6 +105,9 @@ typedef struct {
GIT_EXTERN(int) git_describe_init_format_options(git_describe_format_options *opts, unsigned int version);
/**
* A struct that stores the result of a describe operation.
*/
typedef struct git_describe_result git_describe_result;
/**

View File

@ -290,7 +290,8 @@ typedef struct {
} git_merge_options;
#define GIT_MERGE_OPTIONS_VERSION 1
#define GIT_MERGE_OPTIONS_INIT {GIT_MERGE_OPTIONS_VERSION}
#define GIT_MERGE_OPTIONS_INIT { \
GIT_MERGE_OPTIONS_VERSION, GIT_MERGE_FIND_RENAMES }
/**
* Initializes a `git_merge_options` with default values. Equivalent to

View File

@ -191,7 +191,7 @@ GIT_EXTERN(int) git_patch_get_hunk(
*
* @param patch The git_patch object
* @param hunk_idx Index of the hunk
* @return Number of lines in hunk or -1 if invalid hunk index
* @return Number of lines in hunk or GIT_ENOTFOUND if invalid hunk index
*/
GIT_EXTERN(int) git_patch_num_lines_in_hunk(
const git_patch *patch,

View File

@ -19,7 +19,7 @@ typedef enum {
/**
* Do not attempt to connect through a proxy
*
* If built against lbicurl, it itself may attempt to connect
* If built against libcurl, it itself may attempt to connect
* to a proxy if the environment variables specify it.
*/
GIT_PROXY_NONE,

View File

@ -26,8 +26,6 @@
*/
GIT_BEGIN_DECL
typedef int (*git_remote_rename_problem_cb)(const char *problematic_refspec, void *payload);
/**
* Add a remote with the default fetch refspec to the repository's configuration.
*
@ -360,6 +358,8 @@ typedef struct {
} git_push_update;
/**
* Callback used to inform of upcoming updates.
*
* @param updates an array containing the updates which will be sent
* as commands to the destination.
* @param len number of elements in `updates`
@ -403,7 +403,7 @@ struct git_remote_callbacks {
* connection to proceed. Returns 1 to allow the connection, 0
* to disallow it or a negative value to indicate an error.
*/
git_transport_certificate_check_cb certificate_check;
git_transport_certificate_check_cb certificate_check;
/**
* During the download of new data, this will be regularly
@ -569,7 +569,7 @@ typedef struct {
* Initializes a `git_fetch_options` with default values. Equivalent to
* creating an instance with GIT_FETCH_OPTIONS_INIT.
*
* @param opts the `git_push_options` instance to initialize.
* @param opts the `git_fetch_options` instance to initialize.
* @param version the version of the struct; you should pass
* `GIT_FETCH_OPTIONS_VERSION` here.
* @return Zero on success; -1 on failure.

View File

@ -135,6 +135,35 @@ GIT_EXTERN(void) git_repository_set_index(git_repository *repo, git_index *index
*/
GIT_EXTERN(int) git_repository_set_bare(git_repository *repo);
/**
* Load and cache all submodules.
*
* Because the `.gitmodules` file is unstructured, loading submodules is an
* O(N) operation. Any operation (such as `git_rebase_init`) that requires
* accessing all submodules is O(N^2) in the number of submodules, if it
* has to look each one up individually. This function loads all submodules
* and caches them so that subsequent calls to `git_submodule_lookup` are O(1).
*
* @param repo the repository whose submodules will be cached.
*/
GIT_EXTERN(int) git_repository_submodule_cache_all(
git_repository *repo);
/**
* Clear the submodule cache.
*
* Clear the submodule cache populated by `git_repository_submodule_cache_all`.
* If there is no cache, do nothing.
*
* The cache incorporates data from the repository's configuration, as well
* as the state of the working tree, the index, and HEAD. So any time any
* of these has changed, the cache might become invalid.
*
* @param repo the repository whose submodule cache will be cleared
*/
GIT_EXTERN(int) git_repository_submodule_cache_clear(
git_repository *repo);
/** @} */
GIT_END_DECL
#endif

View File

@ -8,6 +8,14 @@
#define INCLUDE_git_transaction_h__
#include "common.h"
/**
* @file git2/transaction.h
* @brief Git transactional reference routines
* @defgroup git_transaction Git transactional reference routines
* @ingroup Git
* @{
*/
GIT_BEGIN_DECL
/**
@ -107,5 +115,6 @@ GIT_EXTERN(int) git_transaction_commit(git_transaction *tx);
*/
GIT_EXTERN(void) git_transaction_free(git_transaction *tx);
/** @} */
GIT_END_DECL
#endif

View File

@ -7,12 +7,12 @@
#ifndef INCLUDE_git_version_h__
#define INCLUDE_git_version_h__
#define LIBGIT2_VERSION "0.24.0"
#define LIBGIT2_VERSION "0.25.0"
#define LIBGIT2_VER_MAJOR 0
#define LIBGIT2_VER_MINOR 24
#define LIBGIT2_VER_MINOR 25
#define LIBGIT2_VER_REVISION 0
#define LIBGIT2_VER_PATCH 0
#define LIBGIT2_SOVERSION 24
#define LIBGIT2_SOVERSION 25
#endif

View File

@ -20,7 +20,7 @@ java -jar poxyproxy.jar -d --port 8080 --credentials foo:bar &
mkdir _build
cd _build
# shellcheck disable=SC2086
cmake .. -DCMAKE_INSTALL_PREFIX=../_install $OPTIONS || exit $?
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

View File

@ -1,23 +1,22 @@
#!/bin/bash
set -e
# Only run this on our branches
echo "Branch: $TRAVIS_BRANCH | Pull request: $TRAVIS_PULL_REQUEST | Slug: $TRAVIS_REPO_SLUG"
if [ "$TRAVIS_BRANCH" != "master" -o "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_REPO_SLUG" != "libgit2/libgit2" ];
then
echo "Only analyzing the 'master' brach of the main repository."
exit 0
fi
# Environment check
[ -z "$COVERITY_TOKEN" ] && echo "Need to set a coverity token" && exit 1
# Only run this on our branches
echo "Pull request: $TRAVIS_PULL_REQUEST | Slug: $TRAVIS_REPO_SLUG"
if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_REPO_SLUG" != "libgit2/libgit2" ];
then
echo "Only analyzing 'development' on the main repo."
exit 0
fi
COV_VERSION=6.6.1
case $(uname -m) in
i?86) BITS=32 ;;
amd64|x86_64) BITS=64 ;;
esac
SCAN_TOOL=https://scan.coverity.com/download/linux-${BITS}
SCAN_TOOL=https://scan.coverity.com/download/cxx/linux${BITS}
TOOL_BASE=$(pwd)/_coverity-scan
# Install coverity tools

View File

@ -173,7 +173,7 @@ static int apply_hunk(
git_diff_line *line = git_array_get(patch->lines, linenum);
if (!line) {
error = apply_err("Preimage does not contain line %d", linenum);
error = apply_err("preimage does not contain line %"PRIuZ, linenum);
goto done;
}
@ -193,7 +193,7 @@ static int apply_hunk(
line_num = hunk->hunk.new_start ? hunk->hunk.new_start - 1 : 0;
if (!find_hunk_linenum(&line_num, image, &preimage, line_num)) {
error = apply_err("Hunk at line %d did not apply",
error = apply_err("hunk at line %d did not apply",
hunk->hunk.new_start);
goto done;
}

View File

@ -30,7 +30,7 @@ int git_attr_file__new(
GITERR_CHECK_ALLOC(attrs);
if (git_mutex_init(&attrs->lock) < 0) {
giterr_set(GITERR_OS, "Failed to initialize lock");
giterr_set(GITERR_OS, "failed to initialize lock");
git__free(attrs);
return -1;
}
@ -49,7 +49,7 @@ int git_attr_file__clear_rules(git_attr_file *file, bool need_lock)
git_attr_rule *rule;
if (need_lock && git_mutex_lock(&file->lock) < 0) {
giterr_set(GITERR_OS, "Failed to lock attribute file");
giterr_set(GITERR_OS, "failed to lock attribute file");
return -1;
}
@ -140,7 +140,7 @@ int git_attr_file__load(
break;
}
default:
giterr_set(GITERR_INVALID, "Unknown file source %d", source);
giterr_set(GITERR_INVALID, "unknown file source %d", source);
return -1;
}
@ -212,7 +212,7 @@ int git_attr_file__out_of_date(
}
default:
giterr_set(GITERR_INVALID, "Invalid file type %d", file->source);
giterr_set(GITERR_INVALID, "invalid file type %d", file->source);
return -1;
}
}
@ -238,7 +238,7 @@ int git_attr_file__parse_buffer(
context = attrs->entry->path;
if (git_mutex_lock(&attrs->lock) < 0) {
giterr_set(GITERR_OS, "Failed to lock attribute file");
giterr_set(GITERR_OS, "failed to lock attribute file");
return -1;
}

View File

@ -12,7 +12,7 @@ GIT_INLINE(int) attr_cache_lock(git_attr_cache *cache)
GIT_UNUSED(cache); /* avoid warning if threading is off */
if (git_mutex_lock(&cache->lock) < 0) {
giterr_set(GITERR_OS, "Unable to get attr cache lock");
giterr_set(GITERR_OS, "unable to get attr cache lock");
return -1;
}
return 0;
@ -365,7 +365,7 @@ int git_attr_cache__do_init(git_repository *repo)
/* set up lock */
if (git_mutex_init(&cache->lock) < 0) {
giterr_set(GITERR_OS, "Unable to initialize lock for attr cache");
giterr_set(GITERR_OS, "unable to initialize lock for attr cache");
git__free(cache);
return -1;
}
@ -430,7 +430,7 @@ int git_attr_cache__insert_macro(git_repository *repo, git_attr_rule *macro)
return 0;
if (git_mutex_lock(&cache->lock) < 0) {
giterr_set(GITERR_OS, "Unable to get attr cache lock");
giterr_set(GITERR_OS, "unable to get attr cache lock");
error = -1;
} else {
git_strmap_insert(macros, macro->match.pattern, macro, error);

View File

@ -96,7 +96,7 @@ static int write_file_stream(
p_close(fd);
if (written != file_size || read_len < 0) {
giterr_set(GITERR_OS, "Failed to read file into stream");
giterr_set(GITERR_OS, "failed to read file into stream");
error = -1;
}
@ -142,7 +142,7 @@ static int write_symlink(
read_len = p_readlink(path, link_data, link_size);
if (read_len != (ssize_t)link_size) {
giterr_set(GITERR_OS, "Failed to create blob. Can't read symlink '%s'", path);
giterr_set(GITERR_OS, "failed to create blob: cannot read symlink '%s'", path);
git__free(link_data);
return -1;
}
@ -186,7 +186,7 @@ int git_blob__create_from_paths(
goto done;
if (S_ISDIR(st.st_mode)) {
giterr_set(GITERR_ODB, "cannot create blob from '%s'; it is a directory", content_path);
giterr_set(GITERR_ODB, "cannot create blob from '%s': it is a directory", content_path);
error = GIT_EDIRECTORY;
goto done;
}

View File

@ -33,7 +33,7 @@ static int retrieve_branch_reference(
/* OOM */;
else if ((error = git_reference_lookup(&branch, repo, ref_name.ptr)) < 0)
giterr_set(
GITERR_REFERENCE, "Cannot locate %s branch '%s'",
GITERR_REFERENCE, "cannot locate %s branch '%s'",
is_remote ? "remote-tracking" : "local", branch_name);
*branch_reference_out = branch; /* will be NULL on error */
@ -46,7 +46,7 @@ static int not_a_local_branch(const char *reference_name)
{
giterr_set(
GITERR_INVALID,
"Reference '%s' is not a local branch.", reference_name);
"reference '%s' is not a local branch.", reference_name);
return -1;
}
@ -58,16 +58,17 @@ static int create_branch(
const char *from,
int force)
{
int is_head = 0;
int is_unmovable_head = 0;
git_reference *branch = NULL;
git_buf canonical_branch_name = GIT_BUF_INIT,
log_message = GIT_BUF_INIT;
int error = -1;
int bare = git_repository_is_bare(repository);
assert(branch_name && commit && ref_out);
assert(git_object_owner((const git_object *)commit) == repository);
if (force && git_branch_lookup(&branch, repository, branch_name, GIT_BRANCH_LOCAL) == 0) {
if (force && !bare && git_branch_lookup(&branch, repository, branch_name, GIT_BRANCH_LOCAL) == 0) {
error = git_branch_is_head(branch);
git_reference_free(branch);
branch = NULL;
@ -75,11 +76,11 @@ static int create_branch(
if (error < 0)
goto cleanup;
is_head = error;
is_unmovable_head = error;
}
if (is_head && force) {
giterr_set(GITERR_REFERENCE, "Cannot force update branch '%s' as it is "
if (is_unmovable_head && force) {
giterr_set(GITERR_REFERENCE, "cannot force update branch '%s' as it is "
"the current HEAD of the repository.", branch_name);
error = -1;
goto cleanup;
@ -134,7 +135,7 @@ int git_branch_delete(git_reference *branch)
assert(branch);
if (!git_reference_is_branch(branch) && !git_reference_is_remote(branch)) {
giterr_set(GITERR_INVALID, "Reference '%s' is not a valid branch.",
giterr_set(GITERR_INVALID, "reference '%s' is not a valid branch.",
git_reference_name(branch));
return GIT_ENOTFOUND;
}
@ -143,7 +144,7 @@ int git_branch_delete(git_reference *branch)
return is_head;
if (is_head) {
giterr_set(GITERR_REFERENCE, "Cannot delete branch '%s' as it is "
giterr_set(GITERR_REFERENCE, "cannot delete branch '%s' as it is "
"the current HEAD of the repository.", git_reference_name(branch));
return -1;
}
@ -305,7 +306,7 @@ int git_branch_name(
branch_name += strlen(GIT_REFS_REMOTES_DIR);
} else {
giterr_set(GITERR_INVALID,
"Reference '%s' is neither a local nor a remote branch.", ref->name);
"reference '%s' is neither a local nor a remote branch.", ref->name);
return -1;
}
*out = branch_name;
@ -435,7 +436,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna
/* Verify that this is a remote branch */
if (!git_reference__is_remote(refname)) {
giterr_set(GITERR_INVALID, "Reference '%s' is not a remote branch.",
giterr_set(GITERR_INVALID, "reference '%s' is not a remote branch.",
refname);
error = GIT_ERROR;
goto cleanup;
@ -462,7 +463,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna
git_remote_free(remote);
giterr_set(GITERR_REFERENCE,
"Reference '%s' is ambiguous", refname);
"reference '%s' is ambiguous", refname);
error = GIT_EAMBIGUOUS;
goto cleanup;
}
@ -476,7 +477,7 @@ int git_branch_remote_name(git_buf *buf, git_repository *repo, const char *refna
error = git_buf_puts(buf, remote_name);
} else {
giterr_set(GITERR_REFERENCE,
"Could not determine remote for '%s'", refname);
"could not determine remote for '%s'", refname);
error = GIT_ENOTFOUND;
}
@ -565,7 +566,7 @@ int git_branch_set_upstream(git_reference *branch, const char *upstream_name)
local = 0;
else {
giterr_set(GITERR_REFERENCE,
"Cannot set upstream for branch '%s'", shortname);
"cannot set upstream for branch '%s'", shortname);
return GIT_ENOTFOUND;
}

View File

@ -962,14 +962,14 @@ int git_buf_unquote(git_buf *buf)
case '0': case '1': case '2': case '3':
if (j == buf->size-3) {
giterr_set(GITERR_INVALID,
"Truncated quoted character \\%c", ch);
"truncated quoted character \\%c", ch);
return -1;
}
if (buf->ptr[j+1] < '0' || buf->ptr[j+1] > '7' ||
buf->ptr[j+2] < '0' || buf->ptr[j+2] > '7') {
giterr_set(GITERR_INVALID,
"Truncated quoted character \\%c%c%c",
"truncated quoted character \\%c%c%c",
buf->ptr[j], buf->ptr[j+1], buf->ptr[j+2]);
return -1;
}
@ -981,7 +981,7 @@ int git_buf_unquote(git_buf *buf)
break;
default:
giterr_set(GITERR_INVALID, "Invalid quoted character \\%c", ch);
giterr_set(GITERR_INVALID, "invalid quoted character \\%c", ch);
return -1;
}
}
@ -995,6 +995,6 @@ int git_buf_unquote(git_buf *buf)
return 0;
invalid:
giterr_set(GITERR_INVALID, "Invalid quoted line");
giterr_set(GITERR_INVALID, "invalid quoted line");
return -1;
}

View File

@ -70,7 +70,7 @@ int git_cache_init(git_cache *cache)
cache->map = git_oidmap_alloc();
GITERR_CHECK_ALLOC(cache->map);
if (git_rwlock_init(&cache->lock)) {
giterr_set(GITERR_OS, "Failed to initialize cache rwlock");
giterr_set(GITERR_OS, "failed to initialize cache rwlock");
return -1;
}
return 0;

View File

@ -1021,13 +1021,13 @@ static int checkout_conflicts_load_byname_entry(
*theirs_out = NULL;
if (!name_entry->ancestor) {
giterr_set(GITERR_INDEX, "A NAME entry exists without an ancestor");
giterr_set(GITERR_INDEX, "a NAME entry exists without an ancestor");
error = -1;
goto done;
}
if (!name_entry->ours && !name_entry->theirs) {
giterr_set(GITERR_INDEX, "A NAME entry exists without an ours or theirs");
giterr_set(GITERR_INDEX, "a NAME entry exists without an ours or theirs");
error = -1;
goto done;
}
@ -1035,7 +1035,7 @@ static int checkout_conflicts_load_byname_entry(
if ((ancestor = checkout_conflicts_search_ancestor(data,
name_entry->ancestor)) == NULL) {
giterr_set(GITERR_INDEX,
"A NAME entry referenced ancestor entry '%s' which does not exist in the main index",
"a NAME entry referenced ancestor entry '%s' which does not exist in the main index",
name_entry->ancestor);
error = -1;
goto done;
@ -1047,7 +1047,7 @@ static int checkout_conflicts_load_byname_entry(
else if ((ours = checkout_conflicts_search_branch(data, name_entry->ours)) == NULL ||
ours->ours == NULL) {
giterr_set(GITERR_INDEX,
"A NAME entry referenced our entry '%s' which does not exist in the main index",
"a NAME entry referenced our entry '%s' which does not exist in the main index",
name_entry->ours);
error = -1;
goto done;
@ -1062,7 +1062,7 @@ static int checkout_conflicts_load_byname_entry(
else if ((theirs = checkout_conflicts_search_branch(data, name_entry->theirs)) == NULL ||
theirs->theirs == NULL) {
giterr_set(GITERR_INDEX,
"A NAME entry referenced their entry '%s' which does not exist in the main index",
"a NAME entry referenced their entry '%s' which does not exist in the main index",
name_entry->theirs);
error = -1;
goto done;
@ -1161,7 +1161,7 @@ static int checkout_conflicts_mark_directoryfile(
if ((error = git_index_find(&j, index, path)) < 0) {
if (error == GIT_ENOTFOUND)
giterr_set(GITERR_INDEX,
"Index inconsistency, could not find entry for expected conflict '%s'", path);
"index inconsistency, could not find entry for expected conflict '%s'", path);
goto done;
}
@ -1169,7 +1169,7 @@ static int checkout_conflicts_mark_directoryfile(
for (; j < len; j++) {
if ((entry = git_index_get_byindex(index, j)) == NULL) {
giterr_set(GITERR_INDEX,
"Index inconsistency, truncated index while loading expected conflict '%s'", path);
"index inconsistency, truncated index while loading expected conflict '%s'", path);
error = -1;
goto done;
}
@ -1254,14 +1254,14 @@ static int checkout_verify_paths(
if (action & CHECKOUT_ACTION__REMOVE) {
if (!git_path_isvalid(repo, delta->old_file.path, flags)) {
giterr_set(GITERR_CHECKOUT, "Cannot remove invalid path '%s'", delta->old_file.path);
giterr_set(GITERR_CHECKOUT, "cannot remove invalid path '%s'", delta->old_file.path);
return -1;
}
}
if (action & ~CHECKOUT_ACTION__REMOVE) {
if (!git_path_isvalid(repo, delta->new_file.path, flags)) {
giterr_set(GITERR_CHECKOUT, "Cannot checkout to invalid path '%s'", delta->new_file.path);
giterr_set(GITERR_CHECKOUT, "cannot checkout to invalid path '%s'", delta->new_file.path);
return -1;
}
}
@ -1430,7 +1430,7 @@ static int mkpath2file(
*/
error = git_futils_rmdir_r(path, NULL, GIT_RMDIR_REMOVE_FILES);
} else if (errno != ENOENT) {
giterr_set(GITERR_OS, "Failed to stat file '%s'", path);
giterr_set(GITERR_OS, "failed to stat '%s'", path);
return GIT_EEXISTS;
} else {
giterr_clear();
@ -1454,7 +1454,7 @@ static int checkout_stream_write(
int ret;
if ((ret = p_write(stream->fd, buffer, len)) < 0)
giterr_set(GITERR_OS, "Could not write to '%s'", stream->path);
giterr_set(GITERR_OS, "could not write to '%s'", stream->path);
return ret;
}
@ -1503,7 +1503,7 @@ static int blob_content_to_file(
mode = GIT_FILEMODE_BLOB;
if ((fd = p_open(path, flags, mode)) < 0) {
giterr_set(GITERR_OS, "Could not open '%s' for writing", path);
giterr_set(GITERR_OS, "could not open '%s' for writing", path);
return fd;
}
@ -1540,7 +1540,7 @@ static int blob_content_to_file(
data->perfdata.stat_calls++;
if ((error = p_stat(path, st)) < 0) {
giterr_set(GITERR_OS, "Error statting '%s'", path);
giterr_set(GITERR_OS, "failed to stat '%s'", path);
return error;
}
@ -1567,7 +1567,7 @@ static int blob_content_to_link(
if (data->can_symlink) {
if ((error = p_symlink(git_buf_cstr(&linktarget), path)) < 0)
giterr_set(GITERR_OS, "Could not create symlink %s", path);
giterr_set(GITERR_OS, "could not create symlink %s", path);
} else {
error = git_futils_fake_symlink(git_buf_cstr(&linktarget), path);
}
@ -1576,7 +1576,7 @@ static int blob_content_to_link(
data->perfdata.stat_calls++;
if ((error = p_lstat(path, st)) < 0)
giterr_set(GITERR_CHECKOUT, "Could not stat symlink %s", path);
giterr_set(GITERR_CHECKOUT, "could not stat symlink %s", path);
st->st_mode = GIT_FILEMODE_LINK;
}
@ -1621,7 +1621,7 @@ static int checkout_submodule_update_index(
data->perfdata.stat_calls++;
if (p_stat(fullpath->ptr, &st) < 0) {
giterr_set(
GITERR_CHECKOUT, "Could not stat submodule %s\n", file->path);
GITERR_CHECKOUT, "could not stat submodule %s\n", file->path);
return GIT_ENOTFOUND;
}
@ -1694,7 +1694,7 @@ static int checkout_safe_for_update_only(
return 0;
/* otherwise, stat error and no update */
giterr_set(GITERR_OS, "Failed to stat file '%s'", path);
giterr_set(GITERR_OS, "failed to stat '%s'", path);
return -1;
}
@ -1966,7 +1966,7 @@ static int checkout_path_suffixed(git_buf *path, const char *suffix)
if (i == INT_MAX) {
git_buf_truncate(path, path_len);
giterr_set(GITERR_CHECKOUT, "Could not write '%s': working directory file exists", path);
giterr_set(GITERR_CHECKOUT, "could not write '%s': working directory file exists", path->ptr);
return GIT_EEXISTS;
}
@ -2097,7 +2097,7 @@ static int checkout_write_merge(
goto done;
if (result.path == NULL || result.mode == 0) {
giterr_set(GITERR_CHECKOUT, "Could not merge contents of file");
giterr_set(GITERR_CHECKOUT, "could not merge contents of file");
error = GIT_ECONFLICT;
goto done;
}
@ -2345,7 +2345,7 @@ static int checkout_data_init(
memset(data, 0, sizeof(*data));
if (!repo) {
giterr_set(GITERR_CHECKOUT, "Cannot checkout nothing");
giterr_set(GITERR_CHECKOUT, "cannot checkout nothing");
return -1;
}
@ -2469,7 +2469,7 @@ static int checkout_data_init(
data->opts.checkout_strategy |= GIT_CHECKOUT_CONFLICT_STYLE_DIFF3;
else {
giterr_set(GITERR_CHECKOUT, "unknown style '%s' given for 'merge.conflictstyle'",
conflict_style);
conflict_style->value);
error = -1;
git_config_entry_free(conflict_style);
goto cleanup;
@ -2553,6 +2553,10 @@ int git_checkout_iterator(
GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE;
baseline_opts.start = data.pfx;
baseline_opts.end = data.pfx;
if (opts && (opts->checkout_strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH)) {
baseline_opts.pathlist.count = opts->paths.count;
baseline_opts.pathlist.strings = opts->paths.strings;
}
if (data.opts.baseline_index) {
if ((error = git_iterator_for_index(
@ -2647,7 +2651,7 @@ int git_checkout_index(
if (!index && !repo) {
giterr_set(GITERR_CHECKOUT,
"Must provide either repository or index to checkout");
"must provide either repository or index to checkout");
return -1;
}
@ -2655,7 +2659,7 @@ int git_checkout_index(
git_index_owner(index) &&
git_index_owner(index) != repo) {
giterr_set(GITERR_CHECKOUT,
"Index to checkout does not match repository");
"index to checkout does not match repository");
return -1;
} else if(index && repo && !git_index_owner(index)) {
GIT_REFCOUNT_OWN(index, repo);
@ -2694,12 +2698,12 @@ int git_checkout_tree(
if (!treeish && !repo) {
giterr_set(GITERR_CHECKOUT,
"Must provide either repository or tree to checkout");
"must provide either repository or tree to checkout");
return -1;
}
if (treeish && repo && git_object_owner(treeish) != repo) {
giterr_set(GITERR_CHECKOUT,
"Object to checkout does not match repository");
"object to checkout does not match repository");
return -1;
}
@ -2709,7 +2713,7 @@ int git_checkout_tree(
if (treeish) {
if (git_object_peel((git_object **)&tree, treeish, GIT_OBJ_TREE) < 0) {
giterr_set(
GITERR_CHECKOUT, "Provided object cannot be peeled to a tree");
GITERR_CHECKOUT, "provided object cannot be peeled to a tree");
return -1;
}
}

View File

@ -130,13 +130,13 @@ int git_cherrypick_commit(
if (git_commit_parentcount(cherrypick_commit) > 1) {
if (!mainline)
return cherrypick_seterr(cherrypick_commit,
"Mainline branch is not specified but %s is a merge commit");
"mainline branch is not specified but %s is a merge commit");
parent = mainline;
} else {
if (mainline)
return cherrypick_seterr(cherrypick_commit,
"Mainline branch specified but %s is not a merge commit");
"mainline branch specified but %s is not a merge commit");
parent = git_commit_parentcount(cherrypick_commit);
}

View File

@ -468,7 +468,7 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj)
return 0;
bad_buffer:
giterr_set(GITERR_OBJECT, "Failed to parse bad commit object");
giterr_set(GITERR_OBJECT, "failed to parse bad commit object");
return -1;
}
@ -598,7 +598,7 @@ int git_commit_parent(
parent_id = git_commit_parent_id(commit, n);
if (parent_id == NULL) {
giterr_set(GITERR_INVALID, "Parent %u does not exist", n);
giterr_set(GITERR_INVALID, "parent %u does not exist", n);
return GIT_ENOTFOUND;
}

View File

@ -61,7 +61,7 @@ static int commit_error(git_commit_list_node *commit, const char *msg)
git_oid_fmt(commit_oid, &commit->oid);
commit_oid[GIT_OID_HEXSZ] = '\0';
giterr_set(GITERR_ODB, "Failed to parse commit %s - %s", commit_oid, msg);
giterr_set(GITERR_ODB, "failed to parse commit %s - %s", commit_oid, msg);
return -1;
}
@ -191,7 +191,7 @@ int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit)
return error;
if (obj->cached.type != GIT_OBJ_COMMIT) {
giterr_set(GITERR_INVALID, "Object is no commit object");
giterr_set(GITERR_INVALID, "object is no commit object");
error = -1;
} else
error = commit_quick_parse(

View File

@ -103,7 +103,8 @@
/**
* Set the error message for this thread, formatting as needed.
*/
void giterr_set(int error_class, const char *string, ...);
void giterr_set(int error_class, const char *string, ...) GIT_FORMAT_PRINTF(2, 3);
/**
* Set the error message for a regex failure, using the internal regex
@ -187,7 +188,7 @@ GIT_INLINE(int) giterr__check_version(const void *structure, unsigned int expect
if (actual > 0 && actual <= expected_max)
return 0;
giterr_set(GITERR_INVALID, "Invalid version %d on %s", actual, name);
giterr_set(GITERR_INVALID, "invalid version %d on %s", actual, name);
return -1;
}
#define GITERR_CHECK_VERSION(S,V,N) if (giterr__check_version(S,V,N) < 0) return -1

View File

@ -109,7 +109,7 @@ int git_config_add_file_ondisk(
res = p_stat(path, &st);
if (res < 0 && errno != ENOENT) {
giterr_set(GITERR_CONFIG, "Error stat'ing config file '%s'", path);
giterr_set(GITERR_CONFIG, "failed to stat '%s'", path);
return -1;
}
@ -203,7 +203,7 @@ static int find_internal_file_by_level(
if (pos == -1) {
giterr_set(GITERR_CONFIG,
"No config file exists for the given level '%i'", (int)level);
"no config file exists for the given level '%i'", (int)level);
return GIT_ENOTFOUND;
}
@ -218,7 +218,7 @@ static int duplicate_level(void **old_raw, void *new_raw)
GIT_UNUSED(new_raw);
giterr_set(GITERR_CONFIG, "A file with the same level (%i) has already been added to the config", (int)(*old)->level);
giterr_set(GITERR_CONFIG, "a file with the same level (%i) has already been added to the config", (int)(*old)->level);
return GIT_EEXISTS;
}
@ -579,7 +579,7 @@ int git_config_foreach_match(
static int config_error_nofiles(const char *name)
{
giterr_set(GITERR_CONFIG,
"Cannot set value for '%s' when no config files exist", name);
"cannot set value for '%s' when no config files exist", name);
return GIT_ENOTFOUND;
}
@ -620,7 +620,7 @@ int git_config_set_string(git_config *cfg, const char *name, const char *value)
file_internal *internal;
if (!value) {
giterr_set(GITERR_CONFIG, "The value to set cannot be NULL");
giterr_set(GITERR_CONFIG, "the value to set cannot be NULL");
return -1;
}
@ -674,7 +674,7 @@ int git_config__update_entry(
static int config_error_notfound(const char *name)
{
giterr_set(GITERR_CONFIG, "Config value '%s' was not found", name);
giterr_set(GITERR_CONFIG, "config value '%s' was not found", name);
return GIT_ENOTFOUND;
}
@ -1236,7 +1236,7 @@ int git_config_lookup_map_value(
}
fail_parse:
giterr_set(GITERR_CONFIG, "Failed to map '%s'", value);
giterr_set(GITERR_CONFIG, "failed to map '%s'", value);
return -1;
}
@ -1270,7 +1270,7 @@ int git_config_parse_bool(int *out, const char *value)
return 0;
}
giterr_set(GITERR_CONFIG, "Failed to parse '%s' as a boolean value", value);
giterr_set(GITERR_CONFIG, "failed to parse '%s' as a boolean value", value);
return -1;
}
@ -1313,7 +1313,7 @@ int git_config_parse_int64(int64_t *out, const char *value)
}
fail_parse:
giterr_set(GITERR_CONFIG, "Failed to parse '%s' as an integer", value ? value : "(null)");
giterr_set(GITERR_CONFIG, "failed to parse '%s' as an integer", value ? value : "(null)");
return -1;
}
@ -1333,7 +1333,7 @@ int git_config_parse_int32(int32_t *out, const char *value)
return 0;
fail_parse:
giterr_set(GITERR_CONFIG, "Failed to parse '%s' as a 32-bit integer", value ? value : "(null)");
giterr_set(GITERR_CONFIG, "failed to parse '%s' as a 32-bit integer", value ? value : "(null)");
return -1;
}
@ -1398,7 +1398,7 @@ int git_config__normalize_name(const char *in, char **out)
invalid:
git__free(name);
giterr_set(GITERR_CONFIG, "Invalid config item name '%s'", in);
giterr_set(GITERR_CONFIG, "invalid config item name '%s'", in);
return GIT_EINVALIDSPEC;
}
@ -1461,7 +1461,7 @@ int git_config_rename_section(
replace.ptr, strchr(replace.ptr, '.'))) < 0)
{
giterr_set(
GITERR_CONFIG, "Invalid config section '%s'", new_section_name);
GITERR_CONFIG, "invalid config section '%s'", new_section_name);
goto cleanup;
}

View File

@ -126,7 +126,7 @@ static int config_snapshot(git_config_backend **out, git_config_backend *in);
static void set_parse_error(struct reader *reader, int col, const char *error_str)
{
giterr_set(GITERR_CONFIG, "Failed to parse config file: %s (in %s:%d, column %d)",
giterr_set(GITERR_CONFIG, "failed to parse config file: %s (in %s:%d, column %d)",
error_str, reader->file_path, reader->line_number, col);
}
@ -233,7 +233,7 @@ static refcounted_strmap *refcounted_strmap_take(diskfile_header *h)
refcounted_strmap *map;
if (git_mutex_lock(&h->values_mutex) < 0) {
giterr_set(GITERR_OS, "Failed to lock config backend");
giterr_set(GITERR_OS, "failed to lock config backend");
return NULL;
}
@ -322,7 +322,7 @@ static int config__refresh(git_config_backend *cfg)
goto out;
if ((error = git_mutex_lock(&b->header.values_mutex)) < 0) {
giterr_set(GITERR_OS, "Failed to lock config backend");
giterr_set(GITERR_OS, "failed to lock config backend");
goto out;
}
@ -479,7 +479,7 @@ static int config_set(git_config_backend *cfg, const char *name, const char *val
cvar_t *existing = git_strmap_value_at(values, pos);
if (existing->next != NULL) {
giterr_set(GITERR_CONFIG, "Multivar incompatible with simple set");
giterr_set(GITERR_CONFIG, "multivar incompatible with simple set");
ret = -1;
goto out;
}
@ -611,7 +611,7 @@ static int config_delete(git_config_backend *cfg, const char *name)
if (!git_strmap_valid_index(values, pos)) {
refcounted_strmap_free(map);
giterr_set(GITERR_CONFIG, "Could not find key '%s' to delete", name);
giterr_set(GITERR_CONFIG, "could not find key '%s' to delete", name);
return GIT_ENOTFOUND;
}
@ -619,7 +619,7 @@ static int config_delete(git_config_backend *cfg, const char *name)
refcounted_strmap_free(map);
if (var->next != NULL) {
giterr_set(GITERR_CONFIG, "Cannot delete multivar with a single delete");
giterr_set(GITERR_CONFIG, "cannot delete multivar with a single delete");
return -1;
}
@ -651,7 +651,7 @@ static int config_delete_multivar(git_config_backend *cfg, const char *name, con
if (!git_strmap_valid_index(values, pos)) {
refcounted_strmap_free(map);
git__free(key);
giterr_set(GITERR_CONFIG, "Could not find key '%s' to delete", name);
giterr_set(GITERR_CONFIG, "could not find key '%s' to delete", name);
return GIT_ENOTFOUND;
}
@ -1325,7 +1325,7 @@ static int unescape_line(
*fixed++ = escaped[esc - escapes];
} else {
git__free(str);
giterr_set(GITERR_CONFIG, "Invalid escape at %s", ptr);
giterr_set(GITERR_CONFIG, "invalid escape at %s", ptr);
return -1;
}
}
@ -1639,7 +1639,7 @@ static int config_read(git_strmap *values, diskfile_backend *cfg_file, struct re
struct parse_data parse_data;
if (depth >= MAX_INCLUDE_DEPTH) {
giterr_set(GITERR_CONFIG, "Maximum config include depth reached");
giterr_set(GITERR_CONFIG, "maximum config include depth reached");
return -1;
}

View File

@ -218,7 +218,7 @@ static const char *line_ending(struct crlf_attrs *ca)
return "\r\n";
line_ending_error:
giterr_set(GITERR_INVALID, "Invalid input to line ending filter");
giterr_set(GITERR_INVALID, "invalid input to line ending filter");
return NULL;
}

View File

@ -15,6 +15,16 @@
#include "vector.h"
#include "proxy.h"
/* This is for backwards compatibility with curl<7.45.0. */
#ifndef CURLINFO_ACTIVESOCKET
# define CURLINFO_ACTIVESOCKET CURLINFO_LASTSOCKET
# define GIT_CURL_BADSOCKET -1
# define git_activesocket_t long
#else
# define GIT_CURL_BADSOCKET CURL_SOCKET_BAD
# define git_activesocket_t curl_socket_t
#endif
typedef struct {
git_stream parent;
CURL *handle;
@ -87,7 +97,8 @@ static int ask_and_apply_proxy_creds(curl_stream *s)
static int curls_connect(git_stream *stream)
{
curl_stream *s = (curl_stream *) stream;
long sockextr, connect_last = 0;
git_activesocket_t sockextr;
long connect_last = 0;
int failed_cert = 0, error;
bool retry_connect;
CURLcode res;
@ -117,10 +128,15 @@ static int curls_connect(git_stream *stream)
if (res == CURLE_PEER_FAILED_VERIFICATION)
failed_cert = 1;
if ((res = curl_easy_getinfo(s->handle, CURLINFO_LASTSOCKET, &sockextr)) != CURLE_OK) {
if ((res = curl_easy_getinfo(s->handle, CURLINFO_ACTIVESOCKET, &sockextr)) != CURLE_OK) {
return seterr_curl(s);
}
if (sockextr == GIT_CURL_BADSOCKET) {
giterr_set(GITERR_NET, "curl socket is no longer valid");
return -1;
}
s->socket = sockextr;
if (s->parent.encrypted && failed_cert)
@ -198,6 +214,7 @@ static int wait_for(curl_socket_t fd, bool reading)
FD_ZERO(&outfd);
FD_ZERO(&errfd);
assert(fd >= 0);
FD_SET(fd, &errfd);
if (reading)
FD_SET(fd, &infd);

View File

@ -131,7 +131,7 @@ static int lookup_index_alloc(
GITERR_CHECK_ALLOC_ADD(&index_len, index_len, hash_len);
if (!git__is_ulong(index_len)) {
giterr_set(GITERR_NOMEMORY, "Overly large delta");
giterr_set(GITERR_NOMEMORY, "overly large delta");
return -1;
}
@ -544,12 +544,12 @@ int git_delta_apply(
* base object, resulting in data corruption or segfault.
*/
if ((hdr_sz(&base_sz, &delta, delta_end) < 0) || (base_sz != base_len)) {
giterr_set(GITERR_INVALID, "Failed to apply delta. Base size does not match given data");
giterr_set(GITERR_INVALID, "failed to apply delta: base size does not match given data");
return -1;
}
if (hdr_sz(&res_sz, &delta, delta_end) < 0) {
giterr_set(GITERR_INVALID, "Failed to apply delta. Base size does not match given data");
giterr_set(GITERR_INVALID, "failed to apply delta: base size does not match given data");
return -1;
}
@ -614,6 +614,6 @@ fail:
*out = NULL;
*out_len = 0;
giterr_set(GITERR_INVALID, "Failed to apply delta");
giterr_set(GITERR_INVALID, "failed to apply delta");
return -1;
}

View File

@ -335,14 +335,14 @@ static int display_name(git_buf *buf, git_repository *repo, struct commit_name *
{
if (n->prio == 2 && !n->tag) {
if (git_tag_lookup(&n->tag, repo, &n->sha1) < 0) {
giterr_set(GITERR_TAG, "Annotated tag '%s' not available", n->path);
giterr_set(GITERR_TAG, "annotated tag '%s' not available", n->path);
return -1;
}
}
if (n->tag && !n->name_checked) {
if (!git_tag_name(n->tag)) {
giterr_set(GITERR_TAG, "Annotated tag '%s' has no embedded name", n->path);
giterr_set(GITERR_TAG, "annotated tag '%s' has no embedded name", n->path);
return -1;
}
@ -471,7 +471,7 @@ static int describe(
if (!data->opts->max_candidates_tags) {
error = describe_not_found(
git_commit_id(commit),
"Cannot describe - no tag exactly matches '%s'");
"cannot describe - no tag exactly matches '%s'");
goto cleanup;
}
@ -564,15 +564,15 @@ static int describe(
}
if (unannotated_cnt) {
error = describe_not_found(git_commit_id(commit),
"Cannot describe - "
"No annotated tags can describe '%s'."
"However, there were unannotated tags.");
"cannot describe - "
"no annotated tags can describe '%s'; "
"however, there were unannotated tags.");
goto cleanup;
}
else {
error = describe_not_found(git_commit_id(commit),
"Cannot describe - "
"No tags can describe '%s'.");
"cannot describe - "
"no tags can describe '%s'.");
goto cleanup;
}
}
@ -695,8 +695,8 @@ int git_describe_commit(
goto cleanup;
if (git_oidmap_size(data.names) == 0 && !opts->show_commit_oid_as_fallback) {
giterr_set(GITERR_DESCRIBE, "Cannot describe - "
"No reference found, cannot describe anything.");
giterr_set(GITERR_DESCRIBE, "cannot describe - "
"no reference found, cannot describe anything.");
error = -1;
goto cleanup;
}
@ -793,7 +793,7 @@ int git_describe_format(git_buf *out, const git_describe_result *result, const g
if (opts.always_use_long_format && opts.abbreviated_size == 0) {
giterr_set(GITERR_DESCRIBE, "Cannot describe - "
giterr_set(GITERR_DESCRIBE, "cannot describe - "
"'always_use_long_format' is incompatible with a zero"
"'abbreviated_size'");
return -1;

View File

@ -151,7 +151,7 @@ static git_diff_driver_registry *git_repository_driver_registry(
}
if (!repo->diff_drivers)
giterr_set(GITERR_REPOSITORY, "Unable to create diff driver registry");
giterr_set(GITERR_REPOSITORY, "unable to create diff driver registry");
return repo->diff_drivers;
}

View File

@ -304,7 +304,7 @@ static int diff_file_content_load_workdir_symlink(
read_len = p_readlink(git_buf_cstr(path), fc->map.data, alloc_len);
if (read_len < 0) {
giterr_set(GITERR_OS, "Failed to read symlink '%s'", fc->file->path);
giterr_set(GITERR_OS, "failed to read symlink '%s'", fc->file->path);
return -1;
}

View File

@ -624,7 +624,7 @@ int git_diff__oid_for_entry(
error = git_odb__hashlink(out, full_path.ptr);
diff->base.perf.oid_calculations++;
} else if (!git__is_sizet(entry.file_size)) {
giterr_set(GITERR_OS, "File size overflow (for 32-bits) on '%s'",
giterr_set(GITERR_OS, "file size overflow (for 32-bits) on '%s'",
entry.path);
error = -1;
} else if (!(error = git_filter_list_load(&fl,
@ -1587,7 +1587,7 @@ int git_diff__commit(
char commit_oidstr[GIT_OID_HEXSZ + 1];
error = -1;
giterr_set(GITERR_INVALID, "Commit %s is a merge commit",
giterr_set(GITERR_INVALID, "commit %s is a merge commit",
git_oid_tostr(commit_oidstr, GIT_OID_HEXSZ + 1, git_commit_id(commit)));
goto on_error;
}

View File

@ -222,7 +222,7 @@ static int diff_print_one_raw(
if (pi->id_strlen > id_abbrev) {
giterr_set(GITERR_PATCH,
"The patch input contains %d id characters (cannot print %d)",
"the patch input contains %d id characters (cannot print %d)",
id_abbrev, pi->id_strlen);
return -1;
}
@ -273,7 +273,7 @@ static int diff_print_oid_range(
if (delta->old_file.mode &&
id_strlen > delta->old_file.id_abbrev) {
giterr_set(GITERR_PATCH,
"The patch input contains %d id characters (cannot print %d)",
"the patch input contains %d id characters (cannot print %d)",
delta->old_file.id_abbrev, id_strlen);
return -1;
}
@ -281,7 +281,7 @@ static int diff_print_oid_range(
if ((delta->new_file.mode &&
id_strlen > delta->new_file.id_abbrev)) {
giterr_set(GITERR_PATCH,
"The patch input contains %d id characters (cannot print %d)",
"the patch input contains %d id characters (cannot print %d)",
delta->new_file.id_abbrev, id_strlen);
return -1;
}
@ -680,7 +680,7 @@ int git_diff_print(
print_file = diff_print_one_name_status;
break;
default:
giterr_set(GITERR_INVALID, "Unknown diff output format (%d)", format);
giterr_set(GITERR_INVALID, "unknown diff output format (%d)", format);
return -1;
}
@ -708,7 +708,7 @@ int git_diff_print_callback__to_buf(
GIT_UNUSED(delta); GIT_UNUSED(hunk);
if (!output) {
giterr_set(GITERR_INVALID, "Buffer pointer must be provided");
giterr_set(GITERR_INVALID, "buffer pointer must be provided");
return -1;
}

View File

@ -131,7 +131,7 @@ int git_diff__merge(
if (ignore_case != ((from->opts.flags & GIT_DIFF_IGNORE_CASE) != 0) ||
reversed != ((from->opts.flags & GIT_DIFF_REVERSE) != 0)) {
giterr_set(GITERR_INVALID,
"Attempt to merge diffs created with conflicting options");
"attempt to merge diffs created with conflicting options");
return -1;
}

View File

@ -50,7 +50,7 @@ static int git_xdiff_parse_hunk(git_diff_hunk *hunk, const char *header)
return 0;
fail:
giterr_set(GITERR_INVALID, "Malformed hunk header from xdiff");
giterr_set(GITERR_INVALID, "malformed hunk header from xdiff");
return -1;
}
@ -99,7 +99,7 @@ static int diff_update_lines(
info->new_lineno += (int)line->num_lines;
break;
default:
giterr_set(GITERR_INVALID, "Unknown diff line origin %02x",
giterr_set(GITERR_INVALID, "unknown diff line origin %02x",
(unsigned int)line->origin);
return -1;
}

View File

@ -113,7 +113,7 @@ int git_fetch_negotiate(git_remote *remote, const git_fetch_options *opts)
remote->need_pack = 0;
if (filter_wants(remote, opts) < 0) {
giterr_set(GITERR_NET, "Failed to filter the reference list for wants");
giterr_set(GITERR_NET, "failed to filter the reference list for wants");
return -1;
}

View File

@ -149,7 +149,7 @@ static int fetchhead_ref_parse(
if (!*line) {
giterr_set(GITERR_FETCHHEAD,
"Empty line in FETCH_HEAD line %d", line_num);
"empty line in FETCH_HEAD line %"PRIuZ, line_num);
return -1;
}
@ -163,15 +163,15 @@ static int fetchhead_ref_parse(
if (strlen(oid_str) != GIT_OID_HEXSZ) {
giterr_set(GITERR_FETCHHEAD,
"Invalid object ID in FETCH_HEAD line %d", line_num);
"invalid object ID in FETCH_HEAD line %"PRIuZ, line_num);
return -1;
}
if (git_oid_fromstr(oid, oid_str) < 0) {
const git_error *oid_err = giterr_last();
const char *err_msg = oid_err ? oid_err->message : "Invalid object ID";
const char *err_msg = oid_err ? oid_err->message : "invalid object ID";
giterr_set(GITERR_FETCHHEAD, "%s in FETCH_HEAD line %d",
giterr_set(GITERR_FETCHHEAD, "%s in FETCH_HEAD line %"PRIuZ,
err_msg, line_num);
return -1;
}
@ -180,7 +180,7 @@ static int fetchhead_ref_parse(
if (*line) {
if ((is_merge_str = git__strsep(&line, "\t")) == NULL) {
giterr_set(GITERR_FETCHHEAD,
"Invalid description data in FETCH_HEAD line %d", line_num);
"invalid description data in FETCH_HEAD line %"PRIuZ, line_num);
return -1;
}
@ -190,13 +190,13 @@ static int fetchhead_ref_parse(
*is_merge = 0;
else {
giterr_set(GITERR_FETCHHEAD,
"Invalid for-merge entry in FETCH_HEAD line %d", line_num);
"invalid for-merge entry in FETCH_HEAD line %"PRIuZ, line_num);
return -1;
}
if ((desc = line) == NULL) {
giterr_set(GITERR_FETCHHEAD,
"Invalid description in FETCH_HEAD line %d", line_num);
"invalid description in FETCH_HEAD line %"PRIuZ, line_num);
return -1;
}
@ -213,7 +213,7 @@ static int fetchhead_ref_parse(
if ((desc = strstr(name, "' ")) == NULL ||
git__prefixcmp(desc, "' of ") != 0) {
giterr_set(GITERR_FETCHHEAD,
"Invalid description in FETCH_HEAD line %d", line_num);
"invalid description in FETCH_HEAD line %"PRIuZ, line_num);
return -1;
}
@ -277,7 +277,7 @@ int git_repository_fetchhead_foreach(git_repository *repo,
}
if (*buffer) {
giterr_set(GITERR_FETCHHEAD, "No EOL at line %d", line_num+1);
giterr_set(GITERR_FETCHHEAD, "no EOL at line %"PRIuZ, line_num+1);
error = -1;
goto done;
}

View File

@ -23,7 +23,7 @@ static int verify_last_error(git_filebuf *file)
{
switch (file->last_error) {
case BUFERR_WRITE:
giterr_set(GITERR_OS, "Failed to write out file");
giterr_set(GITERR_OS, "failed to write out file");
return -1;
case BUFERR_MEM:
@ -48,7 +48,7 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode)
else {
giterr_clear(); /* actual OS error code just confuses */
giterr_set(GITERR_OS,
"Failed to lock file '%s' for writing", file->path_lock);
"failed to lock file '%s' for writing", file->path_lock);
return GIT_ELOCKED;
}
}
@ -75,7 +75,7 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode)
source = p_open(file->path_original, O_RDONLY);
if (source < 0) {
giterr_set(GITERR_OS,
"Failed to open file '%s' for reading",
"failed to open file '%s' for reading",
file->path_original);
return -1;
}
@ -90,10 +90,10 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode)
p_close(source);
if (read_bytes < 0) {
giterr_set(GITERR_OS, "Failed to read file '%s'", file->path_original);
giterr_set(GITERR_OS, "failed to read file '%s'", file->path_original);
return -1;
} else if (error < 0) {
giterr_set(GITERR_OS, "Failed to write file '%s'", file->path_lock);
giterr_set(GITERR_OS, "failed to write file '%s'", file->path_lock);
return -1;
}
}
@ -316,7 +316,7 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo
if (compression != 0) {
/* Initialize the ZLib stream */
if (deflateInit(&file->zs, compression) != Z_OK) {
giterr_set(GITERR_ZLIB, "Failed to initialize zlib");
giterr_set(GITERR_ZLIB, "failed to initialize zlib");
goto cleanup;
}
@ -426,14 +426,14 @@ int git_filebuf_commit(git_filebuf *file)
file->fd_is_open = false;
if (p_close(file->fd) < 0) {
giterr_set(GITERR_OS, "Failed to close file at '%s'", file->path_lock);
giterr_set(GITERR_OS, "failed to close file at '%s'", file->path_lock);
goto on_error;
}
file->fd = -1;
if (p_rename(file->path_lock, file->path_original) < 0) {
giterr_set(GITERR_OS, "Failed to rename lockfile to '%s'", file->path_original);
giterr_set(GITERR_OS, "failed to rename lockfile to '%s'", file->path_original);
goto on_error;
}
@ -571,7 +571,7 @@ int git_filebuf_stats(time_t *mtime, size_t *size, git_filebuf *file)
res = p_stat(file->path_original, &st);
if (res < 0) {
giterr_set(GITERR_OS, "Could not get stat info for '%s'",
giterr_set(GITERR_OS, "could not get stat info for '%s'",
file->path_original);
return res;
}

View File

@ -37,13 +37,13 @@ int git_futils_mktmp(git_buf *path_out, const char *filename, mode_t mode)
if ((fd = p_mkstemp(path_out->ptr)) < 0) {
giterr_set(GITERR_OS,
"Failed to create temporary file '%s'", path_out->ptr);
"failed to create temporary file '%s'", path_out->ptr);
return -1;
}
if (p_chmod(path_out->ptr, (mode & ~mask))) {
giterr_set(GITERR_OS,
"Failed to set permissions on file '%s'", path_out->ptr);
"failed to set permissions on file '%s'", path_out->ptr);
return -1;
}
@ -59,7 +59,7 @@ int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode
fd = p_creat(path, mode);
if (fd < 0) {
giterr_set(GITERR_OS, "Failed to create file '%s'", path);
giterr_set(GITERR_OS, "failed to create file '%s'", path);
return -1;
}
@ -72,8 +72,16 @@ int git_futils_creat_locked(const char *path, const mode_t mode)
O_EXCL | O_BINARY | O_CLOEXEC, mode);
if (fd < 0) {
giterr_set(GITERR_OS, "Failed to create locked file '%s'", path);
return errno == EEXIST ? GIT_ELOCKED : -1;
int error = errno;
giterr_set(GITERR_OS, "failed to create locked file '%s'", path);
switch (error) {
case EEXIST:
return GIT_ELOCKED;
case ENOENT:
return GIT_ENOTFOUND;
default:
return -1;
}
}
return fd;
@ -100,7 +108,7 @@ git_off_t git_futils_filesize(git_file fd)
struct stat sb;
if (p_fstat(fd, &sb)) {
giterr_set(GITERR_OS, "Failed to stat file descriptor");
giterr_set(GITERR_OS, "failed to stat file descriptor");
return -1;
}
@ -129,7 +137,7 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
git_buf_clear(buf);
if (!git__is_ssizet(len)) {
giterr_set(GITERR_INVALID, "Read too large.");
giterr_set(GITERR_INVALID, "read too large");
return -1;
}
@ -141,7 +149,7 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
read_size = p_read(fd, buf->ptr, len);
if (read_size != (ssize_t)len) {
giterr_set(GITERR_OS, "Failed to read descriptor");
giterr_set(GITERR_OS, "failed to read descriptor");
git_buf_free(buf);
return -1;
}
@ -176,7 +184,7 @@ int git_futils_readbuffer_updated(
}
if (!git__is_sizet(st.st_size+1)) {
giterr_set(GITERR_OS, "Invalid regular file stat for '%s'", path);
giterr_set(GITERR_OS, "invalid regular file stat for '%s'", path);
return -1;
}
@ -237,18 +245,18 @@ int git_futils_writebuffer(
mode = GIT_FILEMODE_BLOB;
if ((fd = p_open(path, flags, mode)) < 0) {
giterr_set(GITERR_OS, "Could not open '%s' for writing", path);
giterr_set(GITERR_OS, "could not open '%s' for writing", path);
return fd;
}
if ((error = p_write(fd, git_buf_cstr(buf), git_buf_len(buf))) < 0) {
giterr_set(GITERR_OS, "Could not write to '%s'", path);
giterr_set(GITERR_OS, "could not write to '%s'", path);
(void)p_close(fd);
return error;
}
if ((error = p_close(fd)) < 0)
giterr_set(GITERR_OS, "Error while closing '%s'", path);
giterr_set(GITERR_OS, "error while closing '%s'", path);
return error;
}
@ -259,7 +267,7 @@ int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmod
return -1;
if (p_rename(from, to) < 0) {
giterr_set(GITERR_OS, "Failed to rename '%s' to '%s'", from, to);
giterr_set(GITERR_OS, "failed to rename '%s' to '%s'", from, to);
return -1;
}
@ -282,7 +290,7 @@ int git_futils_mmap_ro_file(git_map *out, const char *path)
len = git_futils_filesize(fd);
if (!git__is_sizet(len)) {
giterr_set(GITERR_OS, "File `%s` too large to mmap", path);
giterr_set(GITERR_OS, "file `%s` too large to mmap", path);
return -1;
}
@ -306,14 +314,14 @@ GIT_INLINE(int) mkdir_validate_dir(
/* with exclusive create, existing dir is an error */
if ((flags & GIT_MKDIR_EXCL) != 0) {
giterr_set(GITERR_FILESYSTEM,
"Failed to make directory '%s': directory exists", path);
"failed to make directory '%s': directory exists", path);
return GIT_EEXISTS;
}
if ((S_ISREG(st->st_mode) && (flags & GIT_MKDIR_REMOVE_FILES)) ||
(S_ISLNK(st->st_mode) && (flags & GIT_MKDIR_REMOVE_SYMLINKS))) {
if (p_unlink(path) < 0) {
giterr_set(GITERR_OS, "Failed to remove %s '%s'",
giterr_set(GITERR_OS, "failed to remove %s '%s'",
S_ISLNK(st->st_mode) ? "symlink" : "file", path);
return GIT_EEXISTS;
}
@ -321,7 +329,7 @@ GIT_INLINE(int) mkdir_validate_dir(
opts->perfdata.mkdir_calls++;
if (p_mkdir(path, mode) < 0) {
giterr_set(GITERR_OS, "Failed to make directory '%s'", path);
giterr_set(GITERR_OS, "failed to make directory '%s'", path);
return GIT_EEXISTS;
}
}
@ -331,14 +339,14 @@ GIT_INLINE(int) mkdir_validate_dir(
opts->perfdata.stat_calls++;
if (p_stat(path, st) < 0) {
giterr_set(GITERR_OS, "Failed to make directory '%s'", path);
giterr_set(GITERR_OS, "failed to make directory '%s'", path);
return GIT_EEXISTS;
}
}
else if (!S_ISDIR(st->st_mode)) {
giterr_set(GITERR_FILESYSTEM,
"Failed to make directory '%s': directory exists", path);
"failed to make directory '%s': directory exists", path);
return GIT_EEXISTS;
}
@ -561,7 +569,7 @@ int git_futils_mkdir_relative(
retry_lstat:
if (p_lstat(make_path.ptr, &st) < 0) {
if (mkdir_attempted || errno != ENOENT) {
giterr_set(GITERR_OS, "Cannot access component in path '%s'", make_path.ptr);
giterr_set(GITERR_OS, "cannot access component in path '%s'", make_path.ptr);
error = -1;
goto done;
}
@ -572,7 +580,7 @@ retry_lstat:
if (p_mkdir(make_path.ptr, mode) < 0) {
if (errno == EEXIST)
goto retry_lstat;
giterr_set(GITERR_OS, "Failed to make directory '%s'", make_path.ptr);
giterr_set(GITERR_OS, "failed to make directory '%s'", make_path.ptr);
error = -1;
goto done;
}
@ -613,7 +621,7 @@ retry_lstat:
opts->perfdata.stat_calls++;
if (p_stat(make_path.ptr, &st) < 0 || !S_ISDIR(st.st_mode)) {
giterr_set(GITERR_OS, "Path is not a directory '%s'",
giterr_set(GITERR_OS, "path is not a directory '%s'",
make_path.ptr);
error = GIT_ENOTFOUND;
}
@ -636,10 +644,10 @@ typedef struct {
static int futils__error_cannot_rmdir(const char *path, const char *filemsg)
{
if (filemsg)
giterr_set(GITERR_OS, "Could not remove directory. File '%s' %s",
giterr_set(GITERR_OS, "could not remove directory '%s': %s",
path, filemsg);
else
giterr_set(GITERR_OS, "Could not remove directory '%s'", path);
giterr_set(GITERR_OS, "could not remove directory '%s'", path);
return -1;
}
@ -807,7 +815,7 @@ static int cp_by_fd(int ifd, int ofd, bool close_fd_when_done)
error = p_write(ofd, buffer, len);
if (len < 0) {
giterr_set(GITERR_OS, "Read error while copying file");
giterr_set(GITERR_OS, "read error while copying file");
error = (int)len;
}
@ -863,14 +871,14 @@ static int cp_link(const char *from, const char *to, size_t link_size)
read_len = p_readlink(from, link_data, link_size);
if (read_len != (ssize_t)link_size) {
giterr_set(GITERR_OS, "Failed to read symlink data for '%s'", from);
giterr_set(GITERR_OS, "failed to read symlink data for '%s'", from);
error = -1;
}
else {
link_data[read_len] = '\0';
if (p_symlink(link_data, to) < 0) {
giterr_set(GITERR_OS, "Could not symlink '%s' as '%s'",
giterr_set(GITERR_OS, "could not symlink '%s' as '%s'",
link_data, to);
error = -1;
}
@ -966,7 +974,7 @@ static int _cp_r_callback(void *ref, git_buf *from)
return 0;
if (p_unlink(info->to.ptr) < 0) {
giterr_set(GITERR_OS, "Cannot overwrite existing file '%s'",
giterr_set(GITERR_OS, "cannot overwrite existing file '%s'",
info->to.ptr);
return GIT_EEXISTS;
}

View File

@ -45,12 +45,12 @@ extern int git_futils_writebuffer(
extern int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode_t mode);
/**
* Create an open a process-locked file
* Create and open a process-locked file
*/
extern int git_futils_creat_locked(const char *path, const mode_t mode);
/**
* Create an open a process-locked file, while
* Create and open a process-locked file, while
* also creating all the folders in its path
*/
extern int git_futils_creat_locked_withpath(const char *path, const mode_t dirmode, const mode_t mode);

View File

@ -296,7 +296,7 @@ int git_filter_unregister(const char *name)
/* cannot unregister default filters */
if (!strcmp(GIT_FILTER_CRLF, name) || !strcmp(GIT_FILTER_IDENT, name)) {
giterr_set(GITERR_FILTER, "Cannot unregister filter '%s'", name);
giterr_set(GITERR_FILTER, "cannot unregister filter '%s'", name);
return -1;
}
@ -306,7 +306,7 @@ int git_filter_unregister(const char *name)
}
if ((fdef = filter_registry_lookup(&pos, name)) == NULL) {
giterr_set(GITERR_FILTER, "Cannot find filter '%s' to unregister", name);
giterr_set(GITERR_FILTER, "cannot find filter '%s' to unregister", name);
error = GIT_ENOTFOUND;
goto done;
}
@ -645,7 +645,7 @@ int git_filter_list_push(
git_rwlock_rdunlock(&filter_registry.lock);
if (fdef == NULL) {
giterr_set(GITERR_FILTER, "Cannot use an unregistered filter");
giterr_set(GITERR_FILTER, "cannot use an unregistered filter");
return -1;
}
@ -758,7 +758,7 @@ static int buf_from_blob(git_buf *out, git_blob *blob)
git_off_t rawsize = git_blob_rawsize(blob);
if (!git__is_sizet(rawsize)) {
giterr_set(GITERR_OS, "Blob is too large to filter");
giterr_set(GITERR_OS, "blob is too large to filter");
return -1;
}

View File

@ -247,6 +247,7 @@ BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved)
#elif defined(GIT_THREADS) && defined(_POSIX_THREADS)
static pthread_key_t _tls_key;
static pthread_mutex_t _init_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_once_t _once_init = PTHREAD_ONCE_INIT;
int init_error = 0;
@ -268,12 +269,19 @@ static void init_once(void)
int git_libgit2_init(void)
{
int ret;
int ret, err;
ret = git_atomic_inc(&git__n_inits);
pthread_once(&_once_init, init_once);
return init_error ? init_error : ret;
if ((err = pthread_mutex_lock(&_init_mutex)) != 0)
return err;
err = pthread_once(&_once_init, init_once);
err |= pthread_mutex_unlock(&_init_mutex);
if (err || init_error)
return err | init_error;
return ret;
}
int git_libgit2_shutdown(void)
@ -285,6 +293,9 @@ int git_libgit2_shutdown(void)
if ((ret = git_atomic_dec(&git__n_inits)) != 0)
return ret;
if ((ret = pthread_mutex_lock(&_init_mutex)) != 0)
return ret;
/* Shut down any subsystems that have global state */
shutdown_common();
@ -298,6 +309,9 @@ int git_libgit2_shutdown(void)
git_mutex_free(&git__mwindow_mutex);
_once_init = new_once;
if ((ret = pthread_mutex_unlock(&_init_mutex)) != 0)
return ret;
return 0;
}
@ -327,7 +341,7 @@ int git_libgit2_init(void)
{
int ret;
/* Only init SSL the first time */
/* Only init subsystems the first time */
if ((ret = git_atomic_inc(&git__n_inits)) != 1)
return ret;
@ -345,6 +359,7 @@ int git_libgit2_shutdown(void)
if ((ret = git_atomic_dec(&git__n_inits)) == 0) {
shutdown_common();
git__global_state_cleanup(&__state);
memset(&__state, 0, sizeof(__state));
}
return ret;

View File

@ -16,6 +16,12 @@ typedef struct {
git_error error_t;
git_buf error_buf;
char oid_fmt[GIT_OID_HEXSZ+1];
/* On Windows, this is the current child thread that was started by
* `git_thread_create`. This is used to set the thread's exit code
* when terminated by `git_thread_exit`. It is unused on POSIX.
*/
git_thread *current_thread;
} git_global_st;
#ifdef GIT_OPENSSL

View File

@ -59,7 +59,7 @@ static int mark_parents(git_revwalk *walk, git_commit_list_node *one,
/* as long as there are non-STALE commits */
while (interesting(&list, roots)) {
git_commit_list_node *commit = git_pqueue_pop(&list);
int flags;
unsigned int flags;
if (commit == NULL)
break;

View File

@ -214,7 +214,7 @@ static int hashsig_finalize_hashes(git_hashsig *sig)
if (sig->mins.size < HASHSIG_HEAP_MIN_SIZE &&
!(sig->opt & GIT_HASHSIG_ALLOW_SMALL_FILES)) {
giterr_set(GITERR_INVALID,
"File too small for similarity signature calculation");
"file too small for similarity signature calculation");
return GIT_EBUFS;
}
@ -286,7 +286,7 @@ int git_hashsig_create_fromfile(
if ((buflen = p_read(fd, buf, sizeof(buf))) <= 0) {
if ((error = (int)buflen) < 0)
giterr_set(GITERR_OS,
"Read error on '%s' calculating similarity hashes", path);
"read error on '%s' calculating similarity hashes", path);
break;
}

View File

@ -175,7 +175,7 @@ static int parse_ignore_file(
context = attrs->entry->path;
if (git_mutex_lock(&attrs->lock) < 0) {
giterr_set(GITERR_OS, "Failed to lock ignore file");
giterr_set(GITERR_OS, "failed to lock ignore file");
return -1;
}

View File

@ -552,7 +552,7 @@ int git_index_clear(git_index *index)
static int create_index_error(int error, const char *msg)
{
giterr_set(GITERR_INDEX, msg);
giterr_set_str(GITERR_INDEX, msg);
return error;
}
@ -570,7 +570,7 @@ int git_index_set_caps(git_index *index, int caps)
if (!repo)
return create_index_error(
-1, "Cannot access repository to set index caps");
-1, "cannot access repository to set index caps");
if (!git_repository__cvar(&val, repo, GIT_CVAR_IGNORECASE))
index->ignore_case = (val != 0);
@ -639,7 +639,7 @@ int git_index_read(git_index *index, int force)
if (!index->index_file_path)
return create_index_error(-1,
"Failed to read index: The index is in-memory only");
"failed to read index: The index is in-memory only");
index->on_disk = git_path_exists(index->index_file_path);
@ -653,7 +653,7 @@ int git_index_read(git_index *index, int force)
((updated = compare_checksum(index)) < 0)) {
giterr_set(
GITERR_INDEX,
"Failed to read index: '%s' no longer exists",
"failed to read index: '%s' no longer exists",
index->index_file_path);
return updated;
}
@ -765,7 +765,7 @@ int git_index_set_version(git_index *index, unsigned int version)
if (version < INDEX_VERSION_NUMBER_LB ||
version > INDEX_VERSION_NUMBER_UB) {
giterr_set(GITERR_INDEX, "Invalid version number");
giterr_set(GITERR_INDEX, "invalid version number");
return -1;
}
@ -805,7 +805,7 @@ int git_index_write_tree(git_oid *oid, git_index *index)
if (repo == NULL)
return create_index_error(-1, "Failed to write tree. "
"The index file is not backed up by an existing repository");
"the index file is not backed up by an existing repository");
return git_tree__write_index(oid, index, repo);
}
@ -847,7 +847,7 @@ const git_index_entry *git_index_get_bypath(
if (git_idxmap_valid_index(index->entries_map, pos))
return git_idxmap_value_at(index->entries_map, pos);
giterr_set(GITERR_INDEX, "Index does not contain %s", path);
giterr_set(GITERR_INDEX, "index does not contain '%s'", path);
return NULL;
}
@ -934,7 +934,7 @@ static int index_entry_init(
if (INDEX_OWNER(index) == NULL)
return create_index_error(-1,
"Could not initialize index entry. "
"could not initialize index entry. "
"Index is not backed up by an existing repository.");
if (index_entry_create(&entry, INDEX_OWNER(index), rel_path, true) < 0)
@ -1423,7 +1423,7 @@ int git_index_add_frombuffer(
if (INDEX_OWNER(index) == NULL)
return create_index_error(-1,
"Could not initialize index entry. "
"could not initialize index entry. "
"Index is not backed up by an existing repository.");
if (!valid_filemode(source_entry->mode)) {
@ -1637,7 +1637,7 @@ int git_index_remove(git_index *index, const char *path, int stage)
if (index_find(&position, index, path, 0, stage) < 0) {
giterr_set(
GITERR_INDEX, "Index does not contain %s at stage %d", path, stage);
GITERR_INDEX, "index does not contain %s at stage %d", path, stage);
error = GIT_ENOTFOUND;
} else {
error = index_remove_entry(index, position);
@ -1709,7 +1709,7 @@ int git_index_find(size_t *at_pos, git_index *index, const char *path)
if (git_vector_bsearch2(
&pos, &index->entries, index->entries_search_path, path) < 0) {
giterr_set(GITERR_INDEX, "Index does not contain %s", path);
giterr_set(GITERR_INDEX, "index does not contain %s", path);
return GIT_ENOTFOUND;
}
@ -2153,7 +2153,7 @@ void git_index_reuc_clear(git_index *index)
static int index_error_invalid(const char *message)
{
giterr_set(GITERR_INDEX, "Invalid data in index - %s", message);
giterr_set(GITERR_INDEX, "invalid data in index - %s", message);
return -1;
}
@ -3390,7 +3390,7 @@ static int index_apply_to_all(
i--; /* back up foreach if we removed this */
break;
default:
giterr_set(GITERR_INVALID, "Unknown index action %d", action);
giterr_set(GITERR_INVALID, "unknown index action %d", action);
error = -1;
break;
}
@ -3475,13 +3475,13 @@ int git_indexwriter_init(
if (!index->index_file_path)
return create_index_error(-1,
"Failed to write index: The index is in-memory only");
"failed to write index: The index is in-memory only");
if ((error = git_filebuf_open(
&writer->file, index->index_file_path, GIT_FILEBUF_HASH_CONTENTS, GIT_INDEX_FILE_MODE)) < 0) {
if (error == GIT_ELOCKED)
giterr_set(GITERR_INDEX, "The index is locked. This might be due to a concurrent or crashed process");
giterr_set(GITERR_INDEX, "the index is locked; this might be due to a concurrent or crashed process");
return error;
}
@ -3530,7 +3530,7 @@ int git_indexwriter_commit(git_indexwriter *writer)
if ((error = git_futils_filestamp_check(
&writer->index->stamp, writer->index->index_file_path)) < 0) {
giterr_set(GITERR_OS, "Could not read index timestamp");
giterr_set(GITERR_OS, "could not read index timestamp");
return -1;
}

View File

@ -33,7 +33,7 @@ struct entry {
struct git_indexer {
unsigned int parsed_header :1,
opened_pack :1,
pack_committed :1,
have_stream :1,
have_delta :1;
struct git_pack_header hdr;
@ -83,12 +83,12 @@ static int parse_header(struct git_pack_header *hdr, struct git_pack_file *pack)
/* Verify we recognize this pack file format. */
if (hdr->hdr_signature != ntohl(PACK_SIGNATURE)) {
giterr_set(GITERR_INDEXER, "Wrong pack signature");
giterr_set(GITERR_INDEXER, "wrong pack signature");
return -1;
}
if (!pack_version_ok(hdr->hdr_version)) {
giterr_set(GITERR_INDEXER, "Wrong pack version");
giterr_set(GITERR_INDEXER, "wrong pack version");
return -1;
}
@ -151,6 +151,12 @@ cleanup:
if (fd != -1)
p_close(fd);
if (git_buf_len(&tmp_path) > 0)
p_unlink(git_buf_cstr(&tmp_path));
if (idx->pack != NULL)
p_unlink(idx->pack->pack_name);
git_buf_free(&path);
git_buf_free(&tmp_path);
git__free(idx);
@ -376,7 +382,7 @@ static int hash_and_save(git_indexer *idx, git_rawobj *obj, git_off_t entry_star
GITERR_CHECK_ALLOC(entry);
if (git_odb__hashobj(&oid, obj) < 0) {
giterr_set(GITERR_INDEXER, "Failed to hash object");
giterr_set(GITERR_INDEXER, "failed to hash object");
goto on_error;
}
@ -1054,6 +1060,7 @@ int git_indexer_commit(git_indexer *idx, git_transfer_progress *stats)
/* And don't forget to rename the packfile to its new place. */
p_rename(idx->pack->pack_name, git_buf_cstr(&filename));
idx->pack_committed = 1;
git_buf_free(&filename);
git_hash_ctx_cleanup(&ctx);
@ -1074,7 +1081,7 @@ void git_indexer_free(git_indexer *idx)
git_vector_free_deep(&idx->objects);
if (idx->pack && idx->pack->idx_cache) {
if (idx->pack->idx_cache) {
struct git_pack_entry *pentry;
kh_foreach_value(
idx->pack->idx_cache, pentry, { git__free(pentry); });
@ -1085,6 +1092,9 @@ void git_indexer_free(git_indexer *idx)
git_vector_free_deep(&idx->deltas);
if (!git_mutex_lock(&git__mwindow_mutex)) {
if (!idx->pack_committed)
git_packfile_close(idx->pack, true);
git_packfile_free(idx->pack);
git_mutex_unlock(&git__mwindow_mutex);
}

View File

@ -1311,7 +1311,7 @@ static int filesystem_iterator_frame_push(
if (iter->frames.size == FILESYSTEM_MAX_DEPTH) {
giterr_set(GITERR_REPOSITORY,
"directory nesting too deep (%d)", iter->frames.size);
"directory nesting too deep (%"PRIuZ")", iter->frames.size);
return -1;
}

View File

@ -78,7 +78,7 @@ int merge_bases_many(git_commit_list **out, git_revwalk **walk_out, git_reposito
unsigned int i;
if (length < 2) {
giterr_set(GITERR_INVALID, "At least two commits are required to find an ancestor. Provided 'length' was %" PRIuZ ".", length);
giterr_set(GITERR_INVALID, "at least two commits are required to find an ancestor");
return -1;
}
@ -104,7 +104,7 @@ int merge_bases_many(git_commit_list **out, git_revwalk **walk_out, git_reposito
goto on_error;
if (!result) {
giterr_set(GITERR_MERGE, "No merge base found");
giterr_set(GITERR_MERGE, "no merge base found");
error = GIT_ENOTFOUND;
goto on_error;
}
@ -184,7 +184,7 @@ int git_merge_base_octopus(git_oid *out, git_repository *repo, size_t length, co
assert(out && repo && input_array);
if (length < 2) {
giterr_set(GITERR_INVALID, "At least two commits are required to find an ancestor. Provided 'length' was %" PRIuZ ".", length);
giterr_set(GITERR_INVALID, "at least two commits are required to find an ancestor");
return -1;
}
@ -230,7 +230,7 @@ static int merge_bases(git_commit_list **out, git_revwalk **walk_out, git_reposi
if (!result) {
git_revwalk_free(walk);
giterr_set(GITERR_MERGE, "No merge base found");
giterr_set(GITERR_MERGE, "no merge base found");
return GIT_ENOTFOUND;
}
@ -574,7 +574,7 @@ int git_repository_mergehead_foreach(
while ((line = git__strsep(&buffer, "\n")) != NULL) {
if (strlen(line) != GIT_OID_HEXSZ) {
giterr_set(GITERR_INVALID, "Unable to parse OID - invalid length");
giterr_set(GITERR_INVALID, "unable to parse OID - invalid length");
error = -1;
goto cleanup;
}
@ -591,7 +591,7 @@ int git_repository_mergehead_foreach(
}
if (*buffer) {
giterr_set(GITERR_MERGE, "No EOL at line %d", line_num);
giterr_set(GITERR_MERGE, "no EOL at line %"PRIuZ, line_num);
error = -1;
goto cleanup;
}
@ -1713,16 +1713,16 @@ static int merge_normalize_opts(
if ((error = git_repository_config__weakptr(&cfg, repo)) < 0)
return error;
if (given != NULL)
if (given != NULL) {
memcpy(opts, given, sizeof(git_merge_options));
else {
} else {
git_merge_options init = GIT_MERGE_OPTIONS_INIT;
memcpy(opts, &init, sizeof(init));
opts->flags = GIT_MERGE_FIND_RENAMES;
opts->rename_threshold = GIT_MERGE_DEFAULT_RENAME_THRESHOLD;
}
if ((opts->flags & GIT_MERGE_FIND_RENAMES) && !opts->rename_threshold)
opts->rename_threshold = GIT_MERGE_DEFAULT_RENAME_THRESHOLD;
if (given && given->default_driver) {
opts->default_driver = git__strdup(given->default_driver);
GITERR_CHECK_ALLOC(opts->default_driver);
@ -3043,7 +3043,7 @@ int git_merge_analysis(
assert(analysis_out && preference_out && repo && their_heads);
if (their_heads_len != 1) {
giterr_set(GITERR_MERGE, "Can only merge a single branch");
giterr_set(GITERR_MERGE, "can only merge a single branch");
error = -1;
goto done;
}
@ -3099,7 +3099,7 @@ int git_merge(
assert(repo && their_heads);
if (their_heads_len != 1) {
giterr_set(GITERR_MERGE, "Can only merge a single branch");
giterr_set(GITERR_MERGE, "can only merge a single branch");
return -1;
}

View File

@ -127,7 +127,7 @@ static int merge_file__xdiff(
if ((xdl_result = xdl_merge(&ancestor_mmfile, &our_mmfile,
&their_mmfile, &xmparam, &mmbuffer)) < 0) {
giterr_set(GITERR_MERGE, "Failed to merge files.");
giterr_set(GITERR_MERGE, "failed to merge files");
error = -1;
goto done;
}

View File

@ -231,7 +231,7 @@ static int git_mwindow_close_lru(git_mwindow_file *mwf)
}
if (!lru_w) {
giterr_set(GITERR_OS, "Failed to close memory window. Couldn't find LRU");
giterr_set(GITERR_OS, "failed to close memory window; couldn't find LRU");
return -1;
}

View File

@ -144,7 +144,7 @@ int gitno_connection_data_from_url(
default_port = "80";
if (data->use_ssl) {
giterr_set(GITERR_NET, "Redirect from HTTPS to HTTP is not allowed");
giterr_set(GITERR_NET, "redirect from HTTPS to HTTP is not allowed");
goto cleanup;
}
} else if (!git__prefixcmp(url, prefix_https)) {
@ -155,7 +155,7 @@ int gitno_connection_data_from_url(
default_port = data->use_ssl ? "443" : "80";
if (!default_port) {
giterr_set(GITERR_NET, "Unrecognized URL prefix");
giterr_set(GITERR_NET, "unrecognized URL prefix");
goto cleanup;
}
@ -187,7 +187,7 @@ int gitno_connection_data_from_url(
/* Check for errors in the resulting data */
if (original_host && url[0] != '/' && strcmp(original_host, data->host)) {
giterr_set(GITERR_NET, "Cross host redirect not allowed");
giterr_set(GITERR_NET, "cross host redirect not allowed");
error = -1;
}
}
@ -237,7 +237,7 @@ int gitno_extract_url_parts(
const char *_host, *_port, *_path, *_userinfo;
if (http_parser_parse_url(url, strlen(url), false, &u)) {
giterr_set(GITERR_NET, "Malformed URL '%s'", url);
giterr_set(GITERR_NET, "malformed URL '%s'", url);
return GIT_EINVALIDSPEC;
}

View File

@ -15,7 +15,7 @@
static int note_error_notfound(void)
{
giterr_set(GITERR_INVALID, "Note could not be found");
giterr_set(GITERR_INVALID, "note could not be found");
return GIT_ENOTFOUND;
}
@ -226,7 +226,7 @@ static int remove_note_in_tree_enotfound_cb(
GIT_UNUSED(note_oid);
GIT_UNUSED(fanout);
giterr_set(GITERR_REPOSITORY, "Object '%s' has no note", annotated_object_sha);
giterr_set(GITERR_REPOSITORY, "object '%s' has no note", annotated_object_sha);
return current_error;
}
@ -244,7 +244,7 @@ static int insert_note_in_tree_eexists_cb(git_tree **out,
GIT_UNUSED(note_oid);
GIT_UNUSED(fanout);
giterr_set(GITERR_REPOSITORY, "Note for '%s' exists already", annotated_object_sha);
giterr_set(GITERR_REPOSITORY, "note for '%s' exists already", annotated_object_sha);
return current_error;
}

View File

@ -66,12 +66,12 @@ int git_object__from_odb_object(
/* Validate type match */
if (type != GIT_OBJ_ANY && type != odb_obj->cached.type) {
giterr_set(GITERR_INVALID,
"The requested type does not match the type in the ODB");
"the requested type does not match the type in the ODB");
return GIT_ENOTFOUND;
}
if ((object_size = git_object__size(odb_obj->cached.type)) == 0) {
giterr_set(GITERR_INVALID, "The requested type is invalid");
giterr_set(GITERR_INVALID, "the requested type is invalid");
return GIT_ENOTFOUND;
}
@ -122,7 +122,7 @@ int git_object_lookup_prefix(
assert(repo && object_out && id);
if (len < GIT_OID_MINPREFIXLEN) {
giterr_set(GITERR_OBJECT, "Ambiguous lookup - OID prefix is too short");
giterr_set(GITERR_OBJECT, "ambiguous lookup - OID prefix is too short");
return GIT_EAMBIGUOUS;
}
@ -147,7 +147,7 @@ int git_object_lookup_prefix(
if (type != GIT_OBJ_ANY && type != object->cached.type) {
git_object_free(object);
giterr_set(GITERR_INVALID,
"The requested type does not match the type in ODB");
"the requested type does not match the type in ODB");
return GIT_ENOTFOUND;
}
@ -292,7 +292,7 @@ static int peel_error(int error, const git_oid *oid, git_otype type)
git_oid_fmt(hex_oid, oid);
hex_oid[GIT_OID_HEXSZ] = '\0';
giterr_set(GITERR_OBJECT, "The git_object of id '%s' can not be "
giterr_set(GITERR_OBJECT, "the git_object of id '%s' can not be "
"successfully peeled into a %s (git_otype=%i).", hex_oid, type_name, type);
return error;

View File

@ -176,7 +176,7 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type)
int error = 0;
if (!git_object_typeisloose(type)) {
giterr_set(GITERR_INVALID, "Invalid object type for hash");
giterr_set(GITERR_INVALID, "invalid object type for hash");
return -1;
}
@ -199,7 +199,7 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_otype type)
* If size is not zero, the file was truncated after we originally
* stat'd it, so we consider this a read failure too */
if (read_len < 0 || size > 0) {
giterr_set(GITERR_OS, "Error reading file for hashing");
giterr_set(GITERR_OS, "error reading file for hashing");
error = -1;
goto done;
@ -251,7 +251,7 @@ int git_odb__hashlink(git_oid *out, const char *path)
return -1;
if (!git__is_int(st.st_size) || (int)st.st_size < 0) {
giterr_set(GITERR_FILESYSTEM, "File size overflow for 32-bit systems");
giterr_set(GITERR_FILESYSTEM, "file size overflow for 32-bit systems");
return -1;
}
@ -269,7 +269,7 @@ int git_odb__hashlink(git_oid *out, const char *path)
read_len = p_readlink(path, link_data, size);
link_data[size] = '\0';
if (read_len != size) {
giterr_set(GITERR_OS, "Failed to read symlink data for '%s'", path);
giterr_set(GITERR_OS, "failed to read symlink data for '%s'", path);
git__free(link_data);
return -1;
}
@ -295,7 +295,7 @@ int git_odb_hashfile(git_oid *out, const char *path, git_otype type)
return fd;
if ((size = git_futils_filesize(fd)) < 0 || !git__is_sizet(size)) {
giterr_set(GITERR_OS, "File size overflow for 32-bit systems");
giterr_set(GITERR_OS, "file size overflow for 32-bit systems");
p_close(fd);
return -1;
}
@ -475,7 +475,7 @@ size_t git_odb_num_backends(git_odb *odb)
static int git_odb__error_unsupported_in_backend(const char *action)
{
giterr_set(GITERR_ODB,
"Cannot %s - unsupported in the loaded odb backends", action);
"cannot %s - unsupported in the loaded odb backends", action);
return -1;
}
@ -492,7 +492,7 @@ int git_odb_get_backend(git_odb_backend **out, git_odb *odb, size_t pos)
return 0;
}
giterr_set(GITERR_ODB, "No ODB backend loaded at index %" PRIuZ, pos);
giterr_set(GITERR_ODB, "no ODB backend loaded at index %" PRIuZ, pos);
return GIT_ENOTFOUND;
}
@ -517,7 +517,7 @@ static int add_default_backends(
if (as_alternates)
return 0;
giterr_set(GITERR_ODB, "Failed to load object database in '%s'", objects_dir);
giterr_set(GITERR_ODB, "failed to load object database in '%s'", objects_dir);
return -1;
}
@ -1264,7 +1264,7 @@ static int git_odb_stream__invalid_length(
const char *action)
{
giterr_set(GITERR_ODB,
"Cannot %s - "
"cannot %s - "
"Invalid length. %"PRIuZ" was expected. The "
"total size of the received chunks amounts to %"PRIuZ".",
action, stream->declared_size, stream->received_bytes);
@ -1399,17 +1399,17 @@ int git_odb__error_notfound(
if (oid != NULL) {
char oid_str[GIT_OID_HEXSZ + 1];
git_oid_tostr(oid_str, oid_len+1, oid);
giterr_set(GITERR_ODB, "Object not found - %s (%.*s)",
message, oid_len, oid_str);
giterr_set(GITERR_ODB, "object not found - %s (%.*s)",
message, (int) oid_len, oid_str);
} else
giterr_set(GITERR_ODB, "Object not found - %s", message);
giterr_set(GITERR_ODB, "object not found - %s", message);
return GIT_ENOTFOUND;
}
int git_odb__error_ambiguous(const char *message)
{
giterr_set(GITERR_ODB, "Ambiguous SHA1 prefix - %s", message);
giterr_set(GITERR_ODB, "ambiguous SHA1 prefix - %s", message);
return GIT_EAMBIGUOUS;
}

View File

@ -214,7 +214,7 @@ static int finish_inflate(z_stream *s)
inflateEnd(s);
if ((status != Z_STREAM_END) || (s->avail_in != 0)) {
giterr_set(GITERR_ZLIB, "Failed to finish ZLib inflation. Stream aborted prematurely");
giterr_set(GITERR_ZLIB, "failed to finish zlib inflation; stream aborted prematurely");
return -1;
}
@ -243,7 +243,7 @@ static int inflate_buffer(void *in, size_t inlen, void *out, size_t outlen)
zs.avail_in = (uInt)inlen;
if (inflateInit(&zs) < Z_OK) {
giterr_set(GITERR_ZLIB, "Failed to inflate buffer");
giterr_set(GITERR_ZLIB, "failed to inflate buffer");
return -1;
}
@ -255,7 +255,7 @@ static int inflate_buffer(void *in, size_t inlen, void *out, size_t outlen)
if (status != Z_STREAM_END /* || zs.avail_in != 0 */ ||
zs.total_out != outlen)
{
giterr_set(GITERR_ZLIB, "Failed to inflate buffer. Stream aborted prematurely");
giterr_set(GITERR_ZLIB, "failed to inflate buffer; stream aborted prematurely");
return -1;
}
@ -319,7 +319,7 @@ static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_buf *obj)
*/
if ((used = get_binary_object_header(&hdr, obj)) == 0 ||
!git_object_typeisloose(hdr.type)) {
giterr_set(GITERR_ODB, "Failed to inflate loose object.");
giterr_set(GITERR_ODB, "failed to inflate loose object");
return -1;
}
@ -366,7 +366,7 @@ static int inflate_disk_obj(git_rawobj *out, git_buf *obj)
(used = get_object_header(&hdr, head)) == 0 ||
!git_object_typeisloose(hdr.type))
{
giterr_set(GITERR_ODB, "Failed to inflate disk object.");
giterr_set(GITERR_ODB, "failed to inflate disk object");
return -1;
}
@ -455,7 +455,7 @@ static int read_header_loose(git_rawobj *out, git_buf *loc)
|| get_object_header(&header_obj, inflated_buffer) == 0
|| git_object_typeisloose(header_obj.type) == 0)
{
giterr_set(GITERR_ZLIB, "Failed to read loose object header");
giterr_set(GITERR_ZLIB, "failed to read loose object header");
error = -1;
} else {
out->len = header_obj.size;

View File

@ -24,7 +24,7 @@ struct memobject {
git_oid oid;
size_t len;
git_otype type;
char data[];
char data[GIT_FLEX_ARRAY];
};
struct memory_packer_db {
@ -177,6 +177,7 @@ int git_mempack_new(git_odb_backend **out)
db->objects = git_oidmap_alloc();
db->parent.version = GIT_ODB_BACKEND_VERSION;
db->parent.read = &impl__read;
db->parent.write = &impl__write;
db->parent.read_header = &impl__read_header;

View File

@ -16,7 +16,7 @@ static char to_hex[] = "0123456789abcdef";
static int oid_error_invalid(const char *msg)
{
giterr_set(GITERR_INVALID, "Unable to parse OID - %s", msg);
giterr_set(GITERR_INVALID, "unable to parse OID - %s", msg);
return -1;
}
@ -380,7 +380,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
node_index idx;
if (os->full) {
giterr_set(GITERR_INVALID, "Unable to shorten OID - OID set full");
giterr_set(GITERR_INVALID, "unable to shorten OID - OID set full");
return -1;
}
@ -395,7 +395,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
trie_node *node;
if (c == -1) {
giterr_set(GITERR_INVALID, "Unable to shorten OID - invalid hex value");
giterr_set(GITERR_INVALID, "unable to shorten OID - invalid hex value");
return -1;
}
@ -410,7 +410,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
node = push_leaf(os, idx, git__fromhex(tail[0]), &tail[1]);
if (node == NULL) {
if (os->full)
giterr_set(GITERR_INVALID, "Unable to shorten OID - OID set full");
giterr_set(GITERR_INVALID, "unable to shorten OID - OID set full");
return -1;
}
}
@ -418,7 +418,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid)
if (node->children[c] == 0) {
if (push_leaf(os, idx, c, &text_oid[i + 1]) == NULL) {
if (os->full)
giterr_set(GITERR_INVALID, "Unable to shorten OID - OID set full");
giterr_set(GITERR_INVALID, "unable to shorten OID - OID set full");
return -1;
}
break;

View File

@ -13,6 +13,7 @@
#include "posix.h"
#include "stream.h"
#include "socket_stream.h"
#include "openssl_stream.h"
#include "netops.h"
#include "git2/transport.h"
#include "git2/sys/openssl.h"
@ -71,12 +72,20 @@ static void shutdown_ssl_locking(void)
#endif /* GIT_THREADS */
static BIO_METHOD *git_stream_bio_method;
static int init_bio_method(void);
/**
* This function aims to clean-up the SSL context which
* we allocated.
*/
static void shutdown_ssl(void)
{
if (git_stream_bio_method) {
BIO_meth_free(git_stream_bio_method);
git_stream_bio_method = NULL;
}
if (git__ssl_ctx) {
SSL_CTX_free(git__ssl_ctx);
git__ssl_ctx = NULL;
@ -121,6 +130,13 @@ int git_openssl_stream_global_init(void)
git__ssl_ctx = NULL;
return -1;
}
if (init_bio_method() < 0) {
SSL_CTX_free(git__ssl_ctx);
git__ssl_ctx = NULL;
return -1;
}
#endif
git__on_shutdown(shutdown_ssl);
@ -148,7 +164,7 @@ int git_openssl_set_locking(void)
git__on_shutdown(shutdown_ssl_locking);
return 0;
#else
giterr_set(GITERR_THREAD, "libgit2 as not built with threads");
giterr_set(GITERR_THREAD, "libgit2 was not built with threads");
return -1;
#endif
}
@ -156,10 +172,8 @@ int git_openssl_set_locking(void)
static int bio_create(BIO *b)
{
b->init = 1;
b->num = 0;
b->ptr = NULL;
b->flags = 0;
BIO_set_init(b, 1);
BIO_set_data(b, NULL);
return 1;
}
@ -169,23 +183,22 @@ static int bio_destroy(BIO *b)
if (!b)
return 0;
b->init = 0;
b->num = 0;
b->ptr = NULL;
b->flags = 0;
BIO_set_data(b, NULL);
return 1;
}
static int bio_read(BIO *b, char *buf, int len)
{
git_stream *io = (git_stream *) b->ptr;
git_stream *io = (git_stream *) BIO_get_data(b);
return (int) git_stream_read(io, buf, len);
}
static int bio_write(BIO *b, const char *buf, int len)
{
git_stream *io = (git_stream *) b->ptr;
git_stream *io = (git_stream *) BIO_get_data(b);
return (int) git_stream_write(io, buf, len, 0);
}
@ -214,17 +227,22 @@ static int bio_puts(BIO *b, const char *str)
return bio_write(b, str, strlen(str));
}
static BIO_METHOD git_stream_bio_method = {
BIO_TYPE_SOURCE_SINK,
"git_stream",
bio_write,
bio_read,
bio_puts,
bio_gets,
bio_ctrl,
bio_create,
bio_destroy
};
static int init_bio_method(void)
{
/* Set up the BIO_METHOD we use for wrapping our own stream implementations */
git_stream_bio_method = BIO_meth_new(BIO_TYPE_SOURCE_SINK | BIO_get_new_index(), "git_stream");
GITERR_CHECK_ALLOC(git_stream_bio_method);
BIO_meth_set_write(git_stream_bio_method, bio_write);
BIO_meth_set_read(git_stream_bio_method, bio_read);
BIO_meth_set_puts(git_stream_bio_method, bio_puts);
BIO_meth_set_gets(git_stream_bio_method, bio_gets);
BIO_meth_set_ctrl(git_stream_bio_method, bio_ctrl);
BIO_meth_set_create(git_stream_bio_method, bio_create);
BIO_meth_set_destroy(git_stream_bio_method, bio_destroy);
return 0;
}
static int ssl_set_error(SSL *ssl, int error)
{
@ -239,10 +257,10 @@ static int ssl_set_error(SSL *ssl, int error)
switch (err) {
case SSL_ERROR_WANT_CONNECT:
case SSL_ERROR_WANT_ACCEPT:
giterr_set(GITERR_NET, "SSL error: connection failure\n");
giterr_set(GITERR_NET, "SSL error: connection failure");
break;
case SSL_ERROR_WANT_X509_LOOKUP:
giterr_set(GITERR_NET, "SSL error: x509 error\n");
giterr_set(GITERR_NET, "SSL error: x509 error");
break;
case SSL_ERROR_SYSCALL:
e = ERR_get_error();
@ -309,7 +327,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
int i = -1,j;
if (SSL_get_verify_result(ssl) != X509_V_OK) {
giterr_set(GITERR_SSL, "The SSL certificate is invalid");
giterr_set(GITERR_SSL, "the SSL certificate is invalid");
return GIT_ECERTIFICATE;
}
@ -339,7 +357,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
num = sk_GENERAL_NAME_num(alts);
for (i = 0; i < num && matched != 1; i++) {
const GENERAL_NAME *gn = sk_GENERAL_NAME_value(alts, i);
const char *name = (char *) ASN1_STRING_data(gn->d.ia5);
const char *name = (char *) ASN1_STRING_get0_data(gn->d.ia5);
size_t namelen = (size_t) ASN1_STRING_length(gn->d.ia5);
/* Skip any names of a type we're not looking for */
@ -394,7 +412,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
if (size > 0) {
peer_cn = OPENSSL_malloc(size + 1);
GITERR_CHECK_ALLOC(peer_cn);
memcpy(peer_cn, ASN1_STRING_data(str), size);
memcpy(peer_cn, ASN1_STRING_get0_data(str), size);
peer_cn[size] = '\0';
} else {
goto cert_fail_name;
@ -445,11 +463,12 @@ int openssl_connect(git_stream *stream)
st->connected = true;
bio = BIO_new(&git_stream_bio_method);
bio = BIO_new(git_stream_bio_method);
GITERR_CHECK_ALLOC(bio);
bio->ptr = st->io;
BIO_set_data(bio, st->io);
SSL_set_bio(st->ssl, bio, bio);
/* specify the host in case SNI is needed */
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
SSL_set_tlsext_host_name(st->ssl, st->host);

View File

@ -13,4 +13,110 @@ extern int git_openssl_stream_global_init(void);
extern int git_openssl_stream_new(git_stream **out, const char *host, const char *port);
/*
* OpenSSL 1.1 made BIO opaque so we have to use functions to interact with it
* which do not exist in previous versions. We define these inline functions so
* we can program against the interface instead of littering the implementation
* with ifdefs.
*/
#ifdef GIT_OPENSSL
# include <openssl/ssl.h>
# include <openssl/err.h>
# include <openssl/x509v3.h>
# include <openssl/bio.h>
# if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
GIT_INLINE(BIO_METHOD*) BIO_meth_new(int type, const char *name)
{
BIO_METHOD *meth = git__calloc(1, sizeof(BIO_METHOD));
if (!meth) {
return NULL;
}
meth->type = type;
meth->name = name;
return meth;
}
GIT_INLINE(void) BIO_meth_free(BIO_METHOD *biom)
{
git__free(biom);
}
GIT_INLINE(int) BIO_meth_set_write(BIO_METHOD *biom, int (*write) (BIO *, const char *, int))
{
biom->bwrite = write;
return 1;
}
GIT_INLINE(int) BIO_meth_set_read(BIO_METHOD *biom, int (*read) (BIO *, char *, int))
{
biom->bread = read;
return 1;
}
GIT_INLINE(int) BIO_meth_set_puts(BIO_METHOD *biom, int (*puts) (BIO *, const char *))
{
biom->bputs = puts;
return 1;
}
GIT_INLINE(int) BIO_meth_set_gets(BIO_METHOD *biom, int (*gets) (BIO *, char *, int))
{
biom->bgets = gets;
return 1;
}
GIT_INLINE(int) BIO_meth_set_ctrl(BIO_METHOD *biom, long (*ctrl) (BIO *, int, long, void *))
{
biom->ctrl = ctrl;
return 1;
}
GIT_INLINE(int) BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *))
{
biom->create = create;
return 1;
}
GIT_INLINE(int) BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *))
{
biom->destroy = destroy;
return 1;
}
GIT_INLINE(int) BIO_get_new_index(void)
{
/* This exists as of 1.1 so before we'd just have 0 */
return 0;
}
GIT_INLINE(void) BIO_set_init(BIO *b, int init)
{
b->init = init;
}
GIT_INLINE(void) BIO_set_data(BIO *a, void *ptr)
{
a->ptr = ptr;
}
GIT_INLINE(void*) BIO_get_data(BIO *a)
{
return a->ptr;
}
GIT_INLINE(const unsigned char *) ASN1_STRING_get0_data(const ASN1_STRING *x)
{
return ASN1_STRING_data((ASN1_STRING *)x);
}
# endif // OpenSSL < 1.1
#endif // GIT_OPENSSL
#endif

View File

@ -162,7 +162,7 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
git_mutex_init(&pb->progress_mutex) ||
git_cond_init(&pb->progress_cond))
{
giterr_set(GITERR_OS, "Failed to initialize packbuilder mutex");
giterr_set(GITERR_OS, "failed to initialize packbuilder mutex");
goto on_error;
}
@ -225,7 +225,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
GITERR_CHECK_ALLOC_MULTIPLY(&newsize, newsize, 3 / 2);
if (!git__is_uint32(newsize)) {
giterr_set(GITERR_NOMEMORY, "Packfile too large to fit in memory.");
giterr_set(GITERR_NOMEMORY, "packfile too large to fit in memory.");
return -1;
}
@ -298,7 +298,7 @@ static int get_delta(void **out, git_odb *odb, git_pobject *po)
goto on_error;
if (error == GIT_EBUFS || delta_size != po->delta_size) {
giterr_set(GITERR_INVALID, "Delta size changed");
giterr_set(GITERR_INVALID, "delta size changed");
goto on_error;
}
@ -808,7 +808,7 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
if (sz != trg_size) {
giterr_set(GITERR_INVALID,
"Inconsistent target object length");
"inconsistent target object length");
return -1;
}
@ -830,7 +830,7 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
if (sz != src_size) {
giterr_set(GITERR_INVALID,
"Inconsistent source object length");
"inconsistent source object length");
return -1;
}

View File

@ -45,7 +45,7 @@ static int pack_entry_find_offset(
static int packfile_error(const char *message)
{
giterr_set(GITERR_ODB, "Invalid pack file - %s", message);
giterr_set(GITERR_ODB, "invalid pack file - %s", message);
return -1;
}
@ -99,7 +99,7 @@ static int cache_init(git_pack_cache *cache)
cache->memory_limit = GIT_PACK_CACHE_MEMORY_LIMIT;
if (git_mutex_init(&cache->lock)) {
giterr_set(GITERR_OS, "Failed to initialize pack cache mutex");
giterr_set(GITERR_OS, "failed to initialize pack cache mutex");
git__free(cache->entries);
cache->entries = NULL;
@ -226,7 +226,7 @@ static int pack_index_check(const char *path, struct git_pack_file *p)
if (p_fstat(fd, &st) < 0) {
p_close(fd);
giterr_set(GITERR_OS, "Unable to stat pack index '%s'", path);
giterr_set(GITERR_OS, "unable to stat pack index '%s'", path);
return -1;
}
@ -235,7 +235,7 @@ static int pack_index_check(const char *path, struct git_pack_file *p)
(idx_size = (size_t)st.st_size) < 4 * 256 + 20 + 20)
{
p_close(fd);
giterr_set(GITERR_ODB, "Invalid pack index '%s'", path);
giterr_set(GITERR_ODB, "invalid pack index '%s'", path);
return -1;
}
@ -509,8 +509,10 @@ int git_packfile_resolve_header(
git_packfile_stream_free(&stream);
if (error < 0)
return error;
} else
} else {
*size_p = size;
base_offset = 0;
}
while (type == GIT_OBJ_OFS_DELTA || type == GIT_OBJ_REF_DELTA) {
curpos = base_offset;
@ -757,8 +759,11 @@ int git_packfile_unpack(
}
cleanup:
if (error < 0)
if (error < 0) {
git__free(obj->data);
if (cached)
git_atomic_dec(&cached->refcount);
}
if (elem)
*obj_offset = curpos;
@ -986,6 +991,18 @@ git_off_t get_delta_base(
*
***********************************************************/
void git_packfile_close(struct git_pack_file *p, bool unlink_packfile)
{
if (p->mwf.fd >= 0) {
git_mwindow_free_all_locked(&p->mwf);
p_close(p->mwf.fd);
p->mwf.fd = -1;
}
if (unlink_packfile)
p_unlink(p->pack_name);
}
void git_packfile_free(struct git_pack_file *p)
{
if (!p)
@ -993,10 +1010,7 @@ void git_packfile_free(struct git_pack_file *p)
cache_free(&p->bases);
if (p->mwf.fd >= 0) {
git_mwindow_free_all_locked(&p->mwf);
p_close(p->mwf.fd);
}
git_packfile_close(p, false);
pack_index_free(p);
@ -1077,7 +1091,7 @@ static int packfile_open(struct git_pack_file *p)
return 0;
cleanup:
giterr_set(GITERR_OS, "Invalid packfile '%s'", p->pack_name);
giterr_set(GITERR_OS, "invalid packfile '%s'", p->pack_name);
if (p->mwf.fd >= 0)
p_close(p->mwf.fd);
@ -1153,7 +1167,7 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path)
p->index_version = -1;
if (git_mutex_init(&p->lock)) {
giterr_set(GITERR_OS, "Failed to initialize packfile mutex");
giterr_set(GITERR_OS, "failed to initialize packfile mutex");
git__free(p);
return -1;
}
@ -1268,8 +1282,8 @@ static int pack_entry_find_offset(
const git_oid *short_oid,
size_t len)
{
const uint32_t *level1_ofs = p->index_map.data;
const unsigned char *index = p->index_map.data;
const uint32_t *level1_ofs;
const unsigned char *index;
unsigned hi, lo, stride;
int pos, found = 0;
git_off_t offset;
@ -1283,11 +1297,11 @@ static int pack_entry_find_offset(
if ((error = pack_index_open(p)) < 0)
return error;
assert(p->index_map.data);
index = p->index_map.data;
level1_ofs = p->index_map.data;
}
index = p->index_map.data;
level1_ofs = p->index_map.data;
if (p->index_version > 1) {
level1_ofs += 2;
index += 8;

View File

@ -149,6 +149,7 @@ git_off_t get_delta_base(struct git_pack_file *p, git_mwindow **w_curs,
git_off_t *curpos, git_otype type,
git_off_t delta_obj_offset);
void git_packfile_close(struct git_pack_file *p, bool unlink_packfile);
void git_packfile_free(struct git_pack_file *p);
int git_packfile_alloc(struct git_pack_file **pack_out, const char *path);

View File

@ -284,7 +284,7 @@ static int create_binary(
size_t b_datalen)
{
git_buf deflate = GIT_BUF_INIT, delta = GIT_BUF_INIT;
size_t delta_data_len;
size_t delta_data_len = 0;
int error;
/* The git_delta function accepts unsigned long only */
@ -417,7 +417,7 @@ static int diff_required(git_diff *diff, const char *action)
{
if (diff)
return 0;
giterr_set(GITERR_INVALID, "Must provide valid diff to %s", action);
giterr_set(GITERR_INVALID, "must provide valid diff to %s", action);
return -1;
}
@ -776,7 +776,7 @@ int git_patch_generated_from_diff(
delta = git_vector_get(&diff->deltas, idx);
if (!delta) {
giterr_set(GITERR_INVALID, "Index out of range for delta in diff");
giterr_set(GITERR_INVALID, "index out of range for delta in diff");
return GIT_ENOTFOUND;
}

View File

@ -176,7 +176,7 @@ static int parse_header_mode(uint16_t *mode, git_patch_parse_ctx *ctx)
int ret;
if (ctx->line_len < 1 || !git__isdigit(ctx->line[0]))
return parse_err("invalid file mode at line %d", ctx->line_num);
return parse_err("invalid file mode at line %"PRIuZ, ctx->line_num);
if ((ret = git__strntol32(&m, ctx->line, ctx->line_len, &end, 8)) < 0)
return ret;
@ -205,7 +205,7 @@ static int parse_header_oid(
if (len < GIT_OID_MINPREFIXLEN || len > GIT_OID_HEXSZ ||
git_oid_fromstrn(oid, ctx->line, len) < 0)
return parse_err("invalid hex formatted object id at line %d",
return parse_err("invalid hex formatted object id at line %"PRIuZ,
ctx->line_num);
parse_advance_chars(ctx, len);
@ -350,7 +350,7 @@ static int parse_header_similarity(
git_patch_parsed *patch, git_patch_parse_ctx *ctx)
{
if (parse_header_percent(&patch->base.delta->similarity, ctx) < 0)
return parse_err("invalid similarity percentage at line %d",
return parse_err("invalid similarity percentage at line %"PRIuZ,
ctx->line_num);
return 0;
@ -362,7 +362,7 @@ static int parse_header_dissimilarity(
uint16_t dissimilarity;
if (parse_header_percent(&dissimilarity, ctx) < 0)
return parse_err("invalid similarity percentage at line %d",
return parse_err("invalid similarity percentage at line %"PRIuZ,
ctx->line_num);
patch->base.delta->similarity = 100 - dissimilarity;
@ -406,15 +406,15 @@ static int parse_header_git(
/* Parse the diff --git line */
if (parse_advance_expected_str(ctx, "diff --git ") < 0)
return parse_err("corrupt git diff header at line %d", ctx->line_num);
return parse_err("corrupt git diff header at line %"PRIuZ, ctx->line_num);
if (parse_header_path(&patch->header_old_path, ctx) < 0)
return parse_err("corrupt old path in git diff header at line %d",
return parse_err("corrupt old path in git diff header at line %"PRIuZ,
ctx->line_num);
if (parse_advance_ws(ctx) < 0 ||
parse_header_path(&patch->header_new_path, ctx) < 0)
return parse_err("corrupt new path in git diff header at line %d",
return parse_err("corrupt new path in git diff header at line %"PRIuZ,
ctx->line_num);
/* Parse remaining header lines */
@ -447,7 +447,7 @@ static int parse_header_git(
parse_advance_expected_str(ctx, "\n");
if (ctx->line_len > 0) {
error = parse_err("trailing data at line %d", ctx->line_num);
error = parse_err("trailing data at line %"PRIuZ, ctx->line_num);
goto done;
}
@ -456,7 +456,7 @@ static int parse_header_git(
}
if (!found) {
error = parse_err("invalid patch header at line %d",
error = parse_err("invalid patch header at line %"PRIuZ,
ctx->line_num);
goto done;
}
@ -536,7 +536,7 @@ static int parse_hunk_header(
hunk->hunk.header_len = ctx->line - header_start;
if (hunk->hunk.header_len > (GIT_DIFF_HUNK_HEADER_SIZE - 1))
return parse_err("oversized patch hunk header at line %d",
return parse_err("oversized patch hunk header at line %"PRIuZ,
ctx->line_num);
memcpy(hunk->hunk.header, header_start, hunk->hunk.header_len);
@ -545,7 +545,7 @@ static int parse_hunk_header(
return 0;
fail:
giterr_set(GITERR_PATCH, "invalid patch hunk header at line %d",
giterr_set(GITERR_PATCH, "invalid patch hunk header at line %"PRIuZ,
ctx->line_num);
return -1;
}
@ -570,7 +570,7 @@ static int parse_hunk_body(
int prefix = 1;
if (ctx->line_len == 0 || ctx->line[ctx->line_len - 1] != '\n') {
error = parse_err("invalid patch instruction at line %d",
error = parse_err("invalid patch instruction at line %"PRIuZ,
ctx->line_num);
goto done;
}
@ -596,7 +596,7 @@ static int parse_hunk_body(
break;
default:
error = parse_err("invalid patch hunk at line %d", ctx->line_num);
error = parse_err("invalid patch hunk at line %"PRIuZ, ctx->line_num);
goto done;
}
@ -672,7 +672,7 @@ static int parse_patch_header(
continue;
}
error = parse_err("invalid hunk header outside patch at line %d",
error = parse_err("invalid hunk header outside patch at line %"PRIuZ,
line_num);
goto done;
}
@ -715,12 +715,12 @@ static int parse_patch_binary_side(
parse_advance_chars(ctx, 6);
} else {
error = parse_err(
"unknown binary delta type at line %d", ctx->line_num);
"unknown binary delta type at line %"PRIuZ, ctx->line_num);
goto done;
}
if (parse_number(&len, ctx) < 0 || parse_advance_nl(ctx) < 0 || len < 0) {
error = parse_err("invalid binary size at line %d", ctx->line_num);
error = parse_err("invalid binary size at line %"PRIuZ, ctx->line_num);
goto done;
}
@ -736,7 +736,7 @@ static int parse_patch_binary_side(
decoded_len = c - 'a' + (('z' - 'a') + 1) + 1;
if (!decoded_len) {
error = parse_err("invalid binary length at line %d", ctx->line_num);
error = parse_err("invalid binary length at line %"PRIuZ, ctx->line_num);
goto done;
}
@ -745,7 +745,7 @@ static int parse_patch_binary_side(
encoded_len = ((decoded_len / 4) + !!(decoded_len % 4)) * 5;
if (encoded_len > ctx->line_len - 1) {
error = parse_err("truncated binary data at line %d", ctx->line_num);
error = parse_err("truncated binary data at line %"PRIuZ, ctx->line_num);
goto done;
}
@ -754,14 +754,14 @@ static int parse_patch_binary_side(
goto done;
if (decoded.size - decoded_orig != decoded_len) {
error = parse_err("truncated binary data at line %d", ctx->line_num);
error = parse_err("truncated binary data at line %"PRIuZ, ctx->line_num);
goto done;
}
parse_advance_chars(ctx, encoded_len);
if (parse_advance_nl(ctx) < 0) {
error = parse_err("trailing data at line %d", ctx->line_num);
error = parse_err("trailing data at line %"PRIuZ, ctx->line_num);
goto done;
}
}
@ -785,7 +785,7 @@ static int parse_patch_binary(
if (parse_advance_expected_str(ctx, "GIT binary patch") < 0 ||
parse_advance_nl(ctx) < 0)
return parse_err("corrupt git binary header at line %d", ctx->line_num);
return parse_err("corrupt git binary header at line %"PRIuZ, ctx->line_num);
/* parse old->new binary diff */
if ((error = parse_patch_binary_side(
@ -793,7 +793,7 @@ static int parse_patch_binary(
return error;
if (parse_advance_nl(ctx) < 0)
return parse_err("corrupt git binary separator at line %d",
return parse_err("corrupt git binary separator at line %"PRIuZ,
ctx->line_num);
/* parse new->old binary diff */
@ -802,7 +802,7 @@ static int parse_patch_binary(
return error;
if (parse_advance_nl(ctx) < 0)
return parse_err("corrupt git binary patch separator at line %d",
return parse_err("corrupt git binary patch separator at line %"PRIuZ,
ctx->line_num);
patch->base.binary.contains_data = 1;
@ -820,7 +820,7 @@ static int parse_patch_binary_nodata(
parse_advance_expected_str(ctx, patch->header_new_path) < 0 ||
parse_advance_expected_str(ctx, " differ") < 0 ||
parse_advance_nl(ctx) < 0)
return parse_err("corrupt git binary header at line %d", ctx->line_num);
return parse_err("corrupt git binary header at line %"PRIuZ, ctx->line_num);
patch->base.binary.contains_data = 0;
patch->base.delta->flags |= GIT_DIFF_FLAG_BINARY;
@ -912,7 +912,7 @@ static int check_prefix(
if (remain_len || !*path)
return parse_err(
"header filename does not contain %d path components",
"header filename does not contain %"PRIuZ" path components",
prefix_len);
done:
@ -1014,8 +1014,10 @@ git_patch_parse_ctx *git_patch_parse_ctx_init(
return NULL;
if (content_len) {
if ((ctx->content = git__malloc(content_len)) == NULL)
if ((ctx->content = git__malloc(content_len)) == NULL) {
git__free(ctx);
return NULL;
}
memcpy((char *)ctx->content, content, content_len);
}

View File

@ -341,7 +341,7 @@ int git_path_prettify(git_buf *path_out, const char *path, const char *base)
if (p_realpath(path, buf) == NULL) {
/* giterr_set resets the errno when dealing with a GITERR_OS kind of error */
int error = (errno == ENOENT || errno == ENOTDIR) ? GIT_ENOTFOUND : -1;
giterr_set(GITERR_OS, "Failed to resolve path '%s'", path);
giterr_set(GITERR_OS, "failed to resolve path '%s'", path);
git_buf_clear(path_out);
@ -632,20 +632,24 @@ int git_path_set_error(int errno_value, const char *path, const char *action)
switch (errno_value) {
case ENOENT:
case ENOTDIR:
giterr_set(GITERR_OS, "Could not find '%s' to %s", path, action);
giterr_set(GITERR_OS, "could not find '%s' to %s", path, action);
return GIT_ENOTFOUND;
case EINVAL:
case ENAMETOOLONG:
giterr_set(GITERR_OS, "Invalid path for filesystem '%s'", path);
giterr_set(GITERR_OS, "invalid path for filesystem '%s'", path);
return GIT_EINVALIDSPEC;
case EEXIST:
giterr_set(GITERR_OS, "Failed %s - '%s' already exists", action, path);
giterr_set(GITERR_OS, "failed %s - '%s' already exists", action, path);
return GIT_EEXISTS;
case EACCES:
giterr_set(GITERR_OS, "failed %s - '%s' is locked", action, path);
return GIT_ELOCKED;
default:
giterr_set(GITERR_OS, "Could not %s '%s'", action, path);
giterr_set(GITERR_OS, "could not %s '%s'", action, path);
return -1;
}
}
@ -754,7 +758,7 @@ int git_path_resolve_relative(git_buf *path, size_t ceiling)
/* error out if trying to up one from a hard base */
if (to == base && ceiling != 0) {
giterr_set(GITERR_INVALID,
"Cannot strip root component off url");
"cannot strip root component off url");
return -1;
}
@ -983,7 +987,7 @@ int git_path_iconv(git_path_iconv_t *ic, const char **in, size_t *inlen)
return 0;
fail:
giterr_set(GITERR_OS, "Unable to convert unicode path data");
giterr_set(GITERR_OS, "unable to convert unicode path data");
return -1;
}
@ -1076,7 +1080,7 @@ int git_path_direach(
wd_len = git_buf_len(path);
if ((dir = opendir(path->ptr)) == NULL) {
giterr_set(GITERR_OS, "Failed to open directory '%s'", path->ptr);
giterr_set(GITERR_OS, "failed to open directory '%s'", path->ptr);
if (errno == ENOENT)
return GIT_ENOTFOUND;
@ -1141,7 +1145,6 @@ int git_path_diriter_init(
unsigned int flags)
{
git_win32_path path_filter;
git_buf hack = {0};
static int is_win7_or_later = -1;
if (is_win7_or_later < 0)
@ -1158,13 +1161,13 @@ int git_path_diriter_init(
git_path_trim_slashes(&diriter->path_utf8);
if (diriter->path_utf8.size == 0) {
giterr_set(GITERR_FILESYSTEM, "Could not open directory '%s'", path);
giterr_set(GITERR_FILESYSTEM, "could not open directory '%s'", path);
return -1;
}
if ((diriter->parent_len = git_win32_path_from_utf8(diriter->path, diriter->path_utf8.ptr)) < 0 ||
!git_win32__findfirstfile_filter(path_filter, diriter->path_utf8.ptr)) {
giterr_set(GITERR_OS, "Could not parse the directory path '%s'", path);
giterr_set(GITERR_OS, "could not parse the directory path '%s'", path);
return -1;
}
@ -1177,7 +1180,7 @@ int git_path_diriter_init(
is_win7_or_later ? FIND_FIRST_EX_LARGE_FETCH : 0);
if (diriter->handle == INVALID_HANDLE_VALUE) {
giterr_set(GITERR_OS, "Could not open directory '%s'", path);
giterr_set(GITERR_OS, "could not open directory '%s'", path);
return -1;
}
@ -1307,14 +1310,14 @@ int git_path_diriter_init(
git_path_trim_slashes(&diriter->path);
if (diriter->path.size == 0) {
giterr_set(GITERR_FILESYSTEM, "Could not open directory '%s'", path);
giterr_set(GITERR_FILESYSTEM, "could not open directory '%s'", path);
return -1;
}
if ((diriter->dir = opendir(diriter->path.ptr)) == NULL) {
git_buf_free(&diriter->path);
giterr_set(GITERR_OS, "Failed to open directory '%s'", path);
giterr_set(GITERR_OS, "failed to open directory '%s'", path);
return -1;
}
@ -1347,7 +1350,7 @@ int git_path_diriter_next(git_path_diriter *diriter)
return GIT_ITEROVER;
giterr_set(GITERR_OS,
"Could not read directory '%s'", diriter->path);
"could not read directory '%s'", diriter->path.ptr);
return -1;
}
} while (skip_dot && git_path_is_dot_or_dotdot(de->d_name));

View File

@ -487,7 +487,7 @@ static int pathspec_match_from_iterator(
/* if every pattern failed to match, then we have failed */
if ((flags & GIT_PATHSPEC_NO_MATCH_ERROR) != 0 && !found_files) {
giterr_set(GITERR_INVALID, "No matching files were found");
giterr_set(GITERR_INVALID, "no matching files were found");
error = GIT_ENOTFOUND;
}
@ -658,7 +658,7 @@ int git_pathspec_match_diff(
/* if every pattern failed to match, then we have failed */
if ((flags & GIT_PATHSPEC_NO_MATCH_ERROR) != 0 && !found_deltas) {
giterr_set(GITERR_INVALID, "No matching deltas were found");
giterr_set(GITERR_INVALID, "no matching deltas were found");
error = GIT_ENOTFOUND;
}

View File

@ -240,7 +240,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
out->len = 0;
if ((prot & GIT_PROT_WRITE) && ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED)) {
giterr_set(GITERR_OS, "Trying to map shared-writeable");
giterr_set(GITERR_OS, "trying to map shared-writeable");
return -1;
}

View File

@ -86,8 +86,9 @@ int git_pqueue_insert(git_pqueue *pq, void *item)
if ((pq->flags & GIT_PQUEUE_FIXED_SIZE) != 0 &&
pq->length >= pq->_alloc_size)
{
/* skip this item if below min item in heap */
if (pq->_cmp(item, git_vector_get(pq, 0)) <= 0)
/* skip this item if below min item in heap or if
* we do not have a comparison function */
if (!pq->_cmp || pq->_cmp(item, git_vector_get(pq, 0)) <= 0)
return 0;
/* otherwise remove the min item before inserting new */
(void)git_pqueue_pop(pq);

View File

@ -90,7 +90,7 @@ static void free_refspec(push_spec *spec)
static int check_rref(char *ref)
{
if (git__prefixcmp(ref, "refs/")) {
giterr_set(GITERR_INVALID, "Not a valid reference '%s'", ref);
giterr_set(GITERR_INVALID, "not a valid reference '%s'", ref);
return -1;
}
@ -111,7 +111,7 @@ static int check_lref(git_push *push, char *ref)
giterr_set(GITERR_REFERENCE,
"src refspec '%s' does not match any existing object", ref);
else
giterr_set(GITERR_INVALID, "Not a valid reference '%s'", ref);
giterr_set(GITERR_INVALID, "not a valid reference '%s'", ref);
return -1;
}
@ -321,7 +321,7 @@ static int revwalk(git_vector *commits, git_push *push)
if (!git_odb_exists(push->repo->_odb, &spec->roid)) {
giterr_set(GITERR_REFERENCE,
"Cannot push because a reference that you are trying to update on the remote contains commits that are not present locally.");
"cannot push because a reference that you are trying to update on the remote contains commits that are not present locally.");
error = GIT_ENONFASTFORWARD;
goto on_error;
}
@ -332,7 +332,7 @@ static int revwalk(git_vector *commits, git_push *push)
if (error == GIT_ENOTFOUND ||
(!error && !git_oid_equal(&base, &spec->roid))) {
giterr_set(GITERR_REFERENCE,
"Cannot push non-fastforwardable reference");
"cannot push non-fastforwardable reference");
error = GIT_ENONFASTFORWARD;
goto on_error;
}
@ -553,7 +553,7 @@ static int calculate_work(git_push *push)
/* This is a create or update. Local ref must exist. */
if (git_reference_name_to_id(
&spec->loid, push->repo, spec->refspec.src) < 0) {
giterr_set(GITERR_REFERENCE, "No such reference '%s'", spec->refspec.src);
giterr_set(GITERR_REFERENCE, "no such reference '%s'", spec->refspec.src);
return -1;
}
}
@ -579,7 +579,7 @@ static int do_push(git_push *push, const git_remote_callbacks *callbacks)
git_transport *transport = push->remote->transport;
if (!transport->push) {
giterr_set(GITERR_NET, "Remote transport doesn't support push");
giterr_set(GITERR_NET, "remote transport doesn't support push");
error = -1;
goto on_error;
}

View File

@ -152,7 +152,7 @@ GIT_INLINE(int) rebase_readint(
return error;
if (git__strtol32(&num, asc_out->ptr, &eol, 10) < 0 || num < 0 || *eol) {
giterr_set(GITERR_REBASE, "The file '%s' contains an invalid numeric value", filename);
giterr_set(GITERR_REBASE, "the file '%s' contains an invalid numeric value", filename);
return -1;
}
@ -170,7 +170,7 @@ GIT_INLINE(int) rebase_readoid(
return error;
if (str_out->size != GIT_OID_HEXSZ || git_oid_fromstr(out, str_out->ptr) < 0) {
giterr_set(GITERR_REBASE, "The file '%s' contains an invalid object ID", filename);
giterr_set(GITERR_REBASE, "the file '%s' contains an invalid object ID", filename);
return -1;
}
@ -316,7 +316,7 @@ int git_rebase_open(
goto done;
if (rebase->type == GIT_REBASE_TYPE_NONE) {
giterr_set(GITERR_REBASE, "There is no rebase in progress");
giterr_set(GITERR_REBASE, "there is no rebase in progress");
error = GIT_ENOTFOUND;
goto done;
}
@ -372,14 +372,14 @@ int git_rebase_open(
switch (rebase->type) {
case GIT_REBASE_TYPE_INTERACTIVE:
giterr_set(GITERR_REBASE, "Interactive rebase is not supported");
giterr_set(GITERR_REBASE, "interactive rebase is not supported");
error = -1;
break;
case GIT_REBASE_TYPE_MERGE:
error = rebase_open_merge(rebase);
break;
case GIT_REBASE_TYPE_APPLY:
giterr_set(GITERR_REBASE, "Patch application rebase is not supported");
giterr_set(GITERR_REBASE, "patch application rebase is not supported");
error = -1;
break;
default:
@ -478,7 +478,7 @@ static int rebase_setupfiles(git_rebase *rebase)
git_oid_fmt(orig_head, &rebase->orig_head_id);
if (p_mkdir(rebase->state_path, REBASE_DIR_MODE) < 0) {
giterr_set(GITERR_OS, "Failed to create rebase directory '%s'", rebase->state_path);
giterr_set(GITERR_OS, "failed to create rebase directory '%s'", rebase->state_path);
return -1;
}
@ -511,7 +511,7 @@ static int rebase_ensure_not_in_progress(git_repository *repo)
return error;
if (type != GIT_REBASE_TYPE_NONE) {
giterr_set(GITERR_REBASE, "There is an existing rebase in progress");
giterr_set(GITERR_REBASE, "there is an existing rebase in progress");
return -1;
}
@ -536,7 +536,7 @@ static int rebase_ensure_not_dirty(
goto done;
if (git_diff_num_deltas(diff) > 0) {
giterr_set(GITERR_REBASE, "Uncommitted changes exist in index");
giterr_set(GITERR_REBASE, "uncommitted changes exist in index");
error = fail_with;
goto done;
}
@ -550,7 +550,7 @@ static int rebase_ensure_not_dirty(
goto done;
if (git_diff_num_deltas(diff) > 0) {
giterr_set(GITERR_REBASE, "Unstaged changes exist in workdir");
giterr_set(GITERR_REBASE, "unstaged changes exist in workdir");
error = fail_with;
goto done;
}
@ -630,7 +630,7 @@ static int rebase_init_merge(
rebase->state_path = git_buf_detach(&state_path);
GITERR_CHECK_ALLOC(rebase->state_path);
if (branch->ref_name) {
if (branch->ref_name && strcmp(branch->ref_name, "HEAD")) {
rebase->orig_head_name = git__strdup(branch->ref_name);
GITERR_CHECK_ALLOC(rebase->orig_head_name);
} else {
@ -731,7 +731,7 @@ int git_rebase_init(
if (inmemory)
error = rebase_init_inmemory(rebase, repo, branch, upstream, onto);
else
rebase_init_merge(rebase, repo, branch ,upstream, onto);
error = rebase_init_merge(rebase, repo, branch ,upstream, onto);
if (error == 0)
*out = rebase;
@ -807,7 +807,7 @@ static int rebase_next_merge(
goto done;
if ((parent_count = git_commit_parentcount(current_commit)) > 1) {
giterr_set(GITERR_REBASE, "Cannot rebase a merge commit");
giterr_set(GITERR_REBASE, "cannot rebase a merge commit");
error = -1;
goto done;
} else if (parent_count) {
@ -864,7 +864,7 @@ static int rebase_next_inmemory(
goto done;
if ((parent_count = git_commit_parentcount(current_commit)) > 1) {
giterr_set(GITERR_REBASE, "Cannot rebase a merge commit");
giterr_set(GITERR_REBASE, "cannot rebase a merge commit");
error = -1;
goto done;
} else if (parent_count) {
@ -1259,7 +1259,7 @@ static int rebase_copy_notes(
goto done;
on_error:
giterr_set(GITERR_REBASE, "Invalid rewritten file at line %d", linenum);
giterr_set(GITERR_REBASE, "invalid rewritten file at line %d", linenum);
error = -1;
done:

View File

@ -125,13 +125,15 @@ int git_refdb_lookup(git_reference **out, git_refdb *db, const char *ref_name)
int git_refdb_iterator(git_reference_iterator **out, git_refdb *db, const char *glob)
{
int error;
if (!db->backend || !db->backend->iterator) {
giterr_set(GITERR_REFERENCE, "This backend doesn't support iterators");
giterr_set(GITERR_REFERENCE, "this backend doesn't support iterators");
return -1;
}
if (db->backend->iterator(out, db->backend, glob) < 0)
return -1;
if ((error = db->backend->iterator(out, db->backend, glob)) < 0)
return error;
GIT_REFCOUNT_INC(db);
(*out)->db = db;

View File

@ -185,7 +185,7 @@ static int packed_reload(refdb_fs_backend *backend)
return 0;
parse_failed:
giterr_set(GITERR_REFERENCE, "Corrupted packed references file");
giterr_set(GITERR_REFERENCE, "corrupted packed references file");
git_sortedcache_clear(backend->refcache, false);
git_sortedcache_wunlock(backend->refcache);
@ -212,7 +212,7 @@ static int loose_parse_oid(
return 0;
corrupted:
giterr_set(GITERR_REFERENCE, "Corrupted loose reference file: %s", filename);
giterr_set(GITERR_REFERENCE, "corrupted loose reference file: %s", filename);
return -1;
}
@ -326,12 +326,13 @@ static int refdb_fs_backend__exists(
{
refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
git_buf ref_path = GIT_BUF_INIT;
int error;
assert(backend);
if (packed_reload(backend) < 0 ||
git_buf_joinpath(&ref_path, backend->path, ref_name) < 0)
return -1;
if ((error = packed_reload(backend)) < 0 ||
(error = git_buf_joinpath(&ref_path, backend->path, ref_name)) < 0)
return error;
*exists = git_path_isfile(ref_path.ptr) ||
(git_sortedcache_lookup(backend->refcache, ref_name) != NULL);
@ -348,7 +349,7 @@ static const char *loose_parse_symbolic(git_buf *file_content)
refname_start = (const char *)file_content->ptr;
if (git_buf_len(file_content) < header_len + 1) {
giterr_set(GITERR_REFERENCE, "Corrupted loose reference file");
giterr_set(GITERR_REFERENCE, "corrupted loose reference file");
return NULL;
}
@ -397,7 +398,7 @@ static int loose_lookup(
static int ref_error_notfound(const char *name)
{
giterr_set(GITERR_REFERENCE, "Reference '%s' not found", name);
giterr_set(GITERR_REFERENCE, "reference '%s' not found", name);
return GIT_ENOTFOUND;
}
@ -409,8 +410,8 @@ static int packed_lookup(
int error = 0;
struct packref *entry;
if (packed_reload(backend) < 0)
return -1;
if ((error = packed_reload(backend)) < 0)
return error;
if (git_sortedcache_rlock(backend->refcache) < 0)
return -1;
@ -615,13 +616,14 @@ static int refdb_fs_backend__iterator_next_name(
static int refdb_fs_backend__iterator(
git_reference_iterator **out, git_refdb_backend *_backend, const char *glob)
{
int error;
refdb_fs_iter *iter;
refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
assert(backend);
if (packed_reload(backend) < 0)
return -1;
if ((error = packed_reload(backend)) < 0)
return error;
iter = git__calloc(1, sizeof(refdb_fs_iter));
GITERR_CHECK_ALLOC(iter);
@ -674,20 +676,22 @@ static int reference_path_available(
int force)
{
size_t i;
int error;
if (packed_reload(backend) < 0)
return -1;
if ((error = packed_reload(backend)) < 0)
return error;
if (!force) {
int exists;
if (refdb_fs_backend__exists(
&exists, (git_refdb_backend *)backend, new_ref) < 0)
return -1;
if ((error = refdb_fs_backend__exists(
&exists, (git_refdb_backend *)backend, new_ref)) < 0) {
return error;
}
if (exists) {
giterr_set(GITERR_REFERENCE,
"Failed to write reference '%s': a reference with "
"failed to write reference '%s': a reference with "
"that name already exists.", new_ref);
return GIT_EEXISTS;
}
@ -701,7 +705,7 @@ static int reference_path_available(
if (ref && !ref_is_available(old_ref, new_ref, ref->name)) {
git_sortedcache_runlock(backend->refcache);
giterr_set(GITERR_REFERENCE,
"Path to reference '%s' collides with existing one", new_ref);
"path to reference '%s' collides with existing one", new_ref);
return -1;
}
}
@ -718,15 +722,15 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
assert(file && backend && name);
if (!git_path_isvalid(backend->repo, name, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
giterr_set(GITERR_INVALID, "Invalid reference name '%s'.", name);
giterr_set(GITERR_INVALID, "invalid reference name '%s'", name);
return GIT_EINVALIDSPEC;
}
/* Remove a possibly existing empty directory hierarchy
* which name would collide with the reference name
*/
if (git_futils_rmdir_r(name, backend->path, GIT_RMDIR_SKIP_NONEMPTY) < 0)
return -1;
if ((error = git_futils_rmdir_r(name, backend->path, GIT_RMDIR_SKIP_NONEMPTY)) < 0)
return error;
if (git_buf_joinpath(&ref_path, backend->path, name) < 0)
return -1;
@ -901,40 +905,62 @@ static int packed_write_ref(struct packref *ref, git_filebuf *file)
static int packed_remove_loose(refdb_fs_backend *backend)
{
size_t i;
git_buf full_path = GIT_BUF_INIT;
int failed = 0;
git_filebuf lock = GIT_FILEBUF_INIT;
git_buf ref_content = GIT_BUF_INIT;
int error = 0;
/* backend->refcache is already locked when this is called */
for (i = 0; i < git_sortedcache_entrycount(backend->refcache); ++i) {
struct packref *ref = git_sortedcache_entry(backend->refcache, i);
git_oid current_id;
if (!ref || !(ref->flags & PACKREF_WAS_LOOSE))
continue;
if (git_buf_joinpath(&full_path, backend->path, ref->name) < 0)
return -1; /* critical; do not try to recover on oom */
git_filebuf_cleanup(&lock);
if (git_path_exists(full_path.ptr) && p_unlink(full_path.ptr) < 0) {
if (failed)
continue;
/* We need to stop anybody from updating the ref while we try to do a safe delete */
error = loose_lock(&lock, backend, ref->name);
/* If someone else is updating it, let them do it */
if (error == GIT_EEXISTS || error == GIT_ENOTFOUND)
continue;
giterr_set(GITERR_REFERENCE,
"Failed to remove loose reference '%s' after packing: %s",
full_path.ptr, strerror(errno));
failed = 1;
if (error < 0) {
git_buf_free(&ref_content);
giterr_set(GITERR_REFERENCE, "failed to lock loose reference '%s'", ref->name);
return error;
}
error = git_futils_readbuffer(&ref_content, lock.path_original);
/* Someone else beat us to cleaning up the ref, let's simply continue */
if (error == GIT_ENOTFOUND)
continue;
/* This became a symref between us packing and trying to delete it, so ignore it */
if (!git__prefixcmp(ref_content.ptr, GIT_SYMREF))
continue;
/* Figure out the current id; if we find a bad ref file, skip it so we can do the rest */
if (loose_parse_oid(&current_id, lock.path_original, &ref_content) < 0)
continue;
/* If the ref moved since we packed it, we must not delete it */
if (!git_oid_equal(&current_id, &ref->oid))
continue;
/*
* if we fail to remove a single file, this is *not* good,
* but we should keep going and remove as many as possible.
* After we've removed as many files as possible, we return
* the error code anyway.
* If we fail to remove, the ref is still in the old state, so
* we haven't lost information.
*/
p_unlink(lock.path_original);
}
git_buf_free(&full_path);
return failed ? -1 : 0;
git_buf_free(&ref_content);
git_filebuf_cleanup(&lock);
return 0;
}
/*
@ -944,41 +970,42 @@ static int packed_write(refdb_fs_backend *backend)
{
git_sortedcache *refcache = backend->refcache;
git_filebuf pack_file = GIT_FILEBUF_INIT;
int error;
size_t i;
/* lock the cache to updates while we do this */
if (git_sortedcache_wlock(refcache) < 0)
return -1;
if ((error = git_sortedcache_wlock(refcache)) < 0)
return error;
/* Open the file! */
if (git_filebuf_open(&pack_file, git_sortedcache_path(refcache), 0, GIT_PACKEDREFS_FILE_MODE) < 0)
if ((error = git_filebuf_open(&pack_file, git_sortedcache_path(refcache), 0, GIT_PACKEDREFS_FILE_MODE)) < 0)
goto fail;
/* Packfiles have a header... apparently
* This is in fact not required, but we might as well print it
* just for kicks */
if (git_filebuf_printf(&pack_file, "%s\n", GIT_PACKEDREFS_HEADER) < 0)
if ((error = git_filebuf_printf(&pack_file, "%s\n", GIT_PACKEDREFS_HEADER)) < 0)
goto fail;
for (i = 0; i < git_sortedcache_entrycount(refcache); ++i) {
struct packref *ref = git_sortedcache_entry(refcache, i);
assert(ref);
if (packed_find_peel(backend, ref) < 0)
if ((error = packed_find_peel(backend, ref)) < 0)
goto fail;
if (packed_write_ref(ref, &pack_file) < 0)
if ((error = packed_write_ref(ref, &pack_file)) < 0)
goto fail;
}
/* if we've written all the references properly, we can commit
* the packfile to make the changes effective */
if (git_filebuf_commit(&pack_file) < 0)
if ((error = git_filebuf_commit(&pack_file)) < 0)
goto fail;
/* when and only when the packfile has been properly written,
* we can go ahead and remove the loose refs */
if (packed_remove_loose(backend) < 0)
if ((error = packed_remove_loose(backend)) < 0)
goto fail;
git_sortedcache_updated(refcache);
@ -991,7 +1018,7 @@ fail:
git_filebuf_cleanup(&pack_file);
git_sortedcache_wunlock(refcache);
return -1;
return error;
}
static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, const git_oid *old, const git_oid *new, const git_signature *author, const char *message);
@ -1143,8 +1170,7 @@ static int refdb_fs_backend__write(
assert(backend);
error = reference_path_available(backend, ref->name, NULL, force);
if (error < 0)
if ((error = reference_path_available(backend, ref->name, NULL, force)) < 0)
return error;
/* We need to perform the reflog append and old value check under the ref's lock */
@ -1260,15 +1286,14 @@ static int refdb_fs_backend__delete_tail(
if (git_buf_joinpath(&loose_path, backend->path, ref_name) < 0)
return -1;
if (git_path_isfile(loose_path.ptr)) {
error = p_unlink(loose_path.ptr);
loose_deleted = 1;
}
git_buf_free(&loose_path);
if (error != 0)
error = p_unlink(loose_path.ptr);
if (error < 0 && errno == ENOENT)
error = 0;
else if (error < 0)
goto cleanup;
else if (error == 0)
loose_deleted = 1;
if ((error = packed_reload(backend)) < 0)
goto cleanup;
@ -1291,6 +1316,7 @@ static int refdb_fs_backend__delete_tail(
error = packed_write(backend);
cleanup:
git_buf_free(&loose_path);
git_filebuf_cleanup(file);
return error;
@ -1362,14 +1388,15 @@ static int refdb_fs_backend__rename(
static int refdb_fs_backend__compress(git_refdb_backend *_backend)
{
int error;
refdb_fs_backend *backend = (refdb_fs_backend *)_backend;
assert(backend);
if (packed_reload(backend) < 0 || /* load the existing packfile */
packed_loadloose(backend) < 0 || /* add all the loose refs */
packed_write(backend) < 0) /* write back to disk */
return -1;
if ((error = packed_reload(backend)) < 0 || /* load the existing packfile */
(error = packed_loadloose(backend)) < 0 || /* add all the loose refs */
(error = packed_write(backend)) < 0) /* write back to disk */
return error;
return 0;
}
@ -1457,7 +1484,7 @@ static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size)
#define seek_forward(_increase) do { \
if (_increase >= buf_size) { \
giterr_set(GITERR_INVALID, "Ran out of data while parsing reflog"); \
giterr_set(GITERR_INVALID, "ran out of data while parsing reflog"); \
goto fail; \
} \
buf += _increase; \
@ -1673,7 +1700,7 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char
repo = backend->repo;
if (!git_path_isvalid(backend->repo, refname, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
giterr_set(GITERR_INVALID, "Invalid reference name '%s'.", refname);
giterr_set(GITERR_INVALID, "invalid reference name '%s'", refname);
return GIT_EINVALIDSPEC;
}
@ -1682,7 +1709,7 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char
if (!git_path_isfile(git_buf_cstr(&log_path))) {
giterr_set(GITERR_INVALID,
"Log file for reference '%s' doesn't exist.", refname);
"log file for reference '%s' doesn't exist", refname);
error = -1;
goto cleanup;
}
@ -1789,9 +1816,10 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
* there maybe an obsolete/unused directory (or directory hierarchy) in the way.
*/
if (git_path_isdir(git_buf_cstr(&path))) {
if ((git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_SKIP_NONEMPTY) < 0))
error = -1;
else if (git_path_isdir(git_buf_cstr(&path))) {
if ((error = git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_SKIP_NONEMPTY)) < 0) {
if (error == GIT_ENOTFOUND)
error = 0;
} else if (git_path_isdir(git_buf_cstr(&path))) {
giterr_set(GITERR_REFERENCE, "cannot create reflog at '%s', there are reflogs beneath that folder",
ref->name);
error = GIT_EDIRECTORY;
@ -1861,7 +1889,7 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
p_close(fd);
if (p_rename(git_buf_cstr(&old_path), git_buf_cstr(&temp_path)) < 0) {
giterr_set(GITERR_OS, "Failed to rename reflog for %s", new_name);
giterr_set(GITERR_OS, "failed to rename reflog for %s", new_name);
error = -1;
goto cleanup;
}
@ -1878,7 +1906,7 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
}
if (p_rename(git_buf_cstr(&temp_path), git_buf_cstr(&new_path)) < 0) {
giterr_set(GITERR_OS, "Failed to rename reflog for %s", new_name);
giterr_set(GITERR_OS, "failed to rename reflog for %s", new_name);
error = -1;
}

View File

@ -93,7 +93,7 @@ int git_reflog_append(git_reflog *reflog, const git_oid *new_oid, const git_sign
if (newline) {
if (newline[1] != '\0') {
giterr_set(GITERR_INVALID, "Reflog message cannot contain newline");
giterr_set(GITERR_INVALID, "reflog message cannot contain newline");
goto cleanup;
}
@ -193,7 +193,7 @@ int git_reflog_drop(git_reflog *reflog, size_t idx, int rewrite_previous_entry)
entry = (git_reflog_entry *)git_reflog_entry_byindex(reflog, idx);
if (entry == NULL) {
giterr_set(GITERR_REFERENCE, "No reflog entry at index %"PRIuZ, idx);
giterr_set(GITERR_REFERENCE, "no reflog entry at index %"PRIuZ, idx);
return GIT_ENOTFOUND;
}

View File

@ -236,7 +236,7 @@ int git_reference_lookup_resolved(
if (scan_type != GIT_REF_OID && max_nesting != 0) {
giterr_set(GITERR_REFERENCE,
"Cannot resolve reference (>%u levels deep)", max_nesting);
"cannot resolve reference (>%u levels deep)", max_nesting);
git_reference_free(ref);
return -1;
}
@ -298,7 +298,7 @@ cleanup:
if (error && !foundvalid) {
/* never found a valid reference name */
giterr_set(GITERR_REFERENCE,
"Could not use '%s' as valid reference name", git_buf_cstr(&name));
"could not use '%s' as valid reference name", git_buf_cstr(&name));
}
if (error == GIT_ENOTFOUND)
@ -396,7 +396,7 @@ static int reference__create(
if (!git_object__is_valid(repo, oid, GIT_OBJ_ANY)) {
giterr_set(GITERR_REFERENCE,
"Target OID for the reference doesn't exist on the repository");
"target OID for the reference doesn't exist on the repository");
return -1;
}
@ -524,7 +524,7 @@ static int ensure_is_an_updatable_direct_reference(git_reference *ref)
if (ref->type == GIT_REF_OID)
return 0;
giterr_set(GITERR_REFERENCE, "Cannot set OID on symbolic reference");
giterr_set(GITERR_REFERENCE, "cannot set OID on symbolic reference");
return -1;
}
@ -552,7 +552,7 @@ static int ensure_is_an_updatable_symbolic_reference(git_reference *ref)
if (ref->type == GIT_REF_SYMBOLIC)
return 0;
giterr_set(GITERR_REFERENCE, "Cannot set symbolic target on a direct reference");
giterr_set(GITERR_REFERENCE, "cannot set symbolic target on a direct reference");
return -1;
}
@ -599,7 +599,7 @@ static int reference__rename(git_reference **out, git_reference *ref, const char
/* Update HEAD it was pointing to the reference being renamed */
if (should_head_be_updated &&
(error = git_repository_set_head(ref->db->repo, normalized)) < 0) {
giterr_set(GITERR_REFERENCE, "Failed to update HEAD after renaming reference");
giterr_set(GITERR_REFERENCE, "failed to update HEAD after renaming reference");
return error;
}
@ -636,7 +636,7 @@ int git_reference_resolve(git_reference **ref_out, const git_reference *ref)
return git_reference_lookup_resolved(ref_out, ref->db->repo, ref->target.symbolic, -1);
default:
giterr_set(GITERR_REFERENCE, "Invalid reference");
giterr_set(GITERR_REFERENCE, "invalid reference");
return -1;
}
}
@ -973,7 +973,7 @@ cleanup:
if (error == GIT_EINVALIDSPEC)
giterr_set(
GITERR_REFERENCE,
"The given reference name '%s' is not valid", name);
"the given reference name '%s' is not valid", name);
if (error && normalize)
git_buf_free(buf);
@ -1000,7 +1000,7 @@ int git_reference_normalize_name(
if (git_buf_len(&buf) > buffer_size - 1) {
giterr_set(
GITERR_REFERENCE,
"The provided buffer is too short to hold the normalization of '%s'", name);
"the provided buffer is too short to hold the normalization of '%s'", name);
error = GIT_EBUFS;
goto cleanup;
}
@ -1046,7 +1046,7 @@ static int get_terminal(git_reference **out, git_repository *repo, const char *r
int error = 0;
if (nesting > MAX_NESTING_LEVEL) {
giterr_set(GITERR_REFERENCE, "Reference chain too deep (%d)", nesting);
giterr_set(GITERR_REFERENCE, "reference chain too deep (%d)", nesting);
return GIT_ENOTFOUND;
}
@ -1229,7 +1229,7 @@ static int peel_error(int error, git_reference *ref, const char* msg)
{
giterr_set(
GITERR_INVALID,
"The reference '%s' cannot be peeled - %s", git_reference_name(ref), msg);
"the reference '%s' cannot be peeled - %s", git_reference_name(ref), msg);
return error;
}

View File

@ -283,7 +283,7 @@ static int ensure_remote_doesnot_exist(git_repository *repo, const char *name)
giterr_set(
GITERR_CONFIG,
"Remote '%s' already exists.", name);
"remote '%s' already exists", name);
return GIT_EEXISTS;
}
@ -476,7 +476,7 @@ int git_remote_lookup(git_remote **out, git_repository *repo, const char *name)
if (!optional_setting_found) {
error = GIT_ENOTFOUND;
giterr_set(GITERR_CONFIG, "Remote '%s' does not exist.", name);
giterr_set(GITERR_CONFIG, "remote '%s' does not exist", name);
goto cleanup;
}
@ -1718,7 +1718,7 @@ int git_remote_set_autotag(git_repository *repo, const char *remote, git_remote_
error = 0;
break;
default:
giterr_set(GITERR_INVALID, "Invalid value for the tagopt setting");
giterr_set(GITERR_INVALID, "invalid value for the tagopt setting");
error = -1;
}

View File

@ -27,6 +27,10 @@
#include "merge.h"
#include "diff_driver.h"
#include "annotated_commit.h"
#include "submodule.h"
GIT__USE_STRMAP
#include "strmap.h"
#ifdef GIT_WIN32
# include "win32/w32_util.h"
@ -109,6 +113,7 @@ void git_repository__cleanup(git_repository *repo)
{
assert(repo);
git_repository_submodule_cache_clear(repo);
git_cache_clear(&repo->objects);
git_attr_cache_flush(repo);
@ -332,7 +337,7 @@ static int read_gitfile(git_buf *path_out, const char *file_path)
memcmp(git_buf_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0)
{
giterr_set(GITERR_REPOSITORY,
"The `.git` file at '%s' is malformed", file_path);
"the `.git` file at '%s' is malformed", file_path);
error = -1;
}
else if ((error = git_path_dirname_r(path_out, file_path)) >= 0) {
@ -410,7 +415,7 @@ static int find_repo(
break;
}
}
else if (S_ISREG(st.st_mode)) {
else if (S_ISREG(st.st_mode) && git__suffixcmp(path.ptr, "/" DOT_GIT) == 0) {
error = read_gitfile(&repo_link, path.ptr);
if (error < 0)
break;
@ -459,7 +464,7 @@ static int find_repo(
* to report, report that. */
if (!git_buf_len(repo_path) && !error) {
giterr_set(GITERR_REPOSITORY,
"Could not find repository from '%s'", start_path);
"could not find repository from '%s'", start_path);
error = GIT_ENOTFOUND;
}
@ -481,7 +486,7 @@ int git_repository_open_bare(
if (!valid_repository_path(&path)) {
git_buf_free(&path);
giterr_set(GITERR_REPOSITORY, "Path is not a repository: %s", bare_path);
giterr_set(GITERR_REPOSITORY, "path is not a repository: %s", bare_path);
return GIT_ENOTFOUND;
}
@ -613,9 +618,10 @@ static int _git_repository_open_ext_from_env(
git_repository_set_odb(repo, odb);
error = git__getenv(&alts_buf, "GIT_ALTERNATE_OBJECT_DIRECTORIES");
if (error == GIT_ENOTFOUND)
if (error == GIT_ENOTFOUND) {
giterr_clear();
else if (error < 0)
error = 0;
} else if (error < 0)
goto error;
else {
const char *end;
@ -638,9 +644,11 @@ static int _git_repository_open_ext_from_env(
}
}
error = git_repository_set_namespace(repo, git_buf_cstr(&namespace_buf));
if (error < 0)
goto error;
if (git_buf_len(&namespace_buf)) {
error = git_repository_set_namespace(repo, git_buf_cstr(&namespace_buf));
if (error < 0)
goto error;
}
git_repository_set_index(repo, index);
@ -1177,7 +1185,7 @@ static int check_repositoryformatversion(git_config *config)
if (GIT_REPO_VERSION < version) {
giterr_set(GITERR_REPOSITORY,
"Unsupported repository version %d. Only versions up to %d are supported.",
"unsupported repository version %d. Only versions up to %d are supported.",
version, GIT_REPO_VERSION);
return -1;
}
@ -1271,12 +1279,12 @@ static int create_empty_file(const char *path, mode_t mode)
int fd;
if ((fd = p_creat(path, mode)) < 0) {
giterr_set(GITERR_OS, "Error while creating '%s'", path);
giterr_set(GITERR_OS, "error while creating '%s'", path);
return -1;
}
if (p_close(fd) < 0) {
giterr_set(GITERR_OS, "Error while closing '%s'", path);
giterr_set(GITERR_OS, "error while closing '%s'", path);
return -1;
}
@ -1505,7 +1513,7 @@ static int repo_write_template(
if (error)
giterr_set(GITERR_OS,
"Failed to initialize repository with template '%s'", file);
"failed to initialize repository with template '%s'", file);
return error;
}
@ -1536,7 +1544,7 @@ static int repo_write_gitlink(
if (!p_stat(buf.ptr, &st) && !S_ISREG(st.st_mode)) {
giterr_set(GITERR_REPOSITORY,
"Cannot overwrite gitlink file into path '%s'", in_dir);
"cannot overwrite gitlink file into path '%s'", in_dir);
error = GIT_EEXISTS;
goto cleanup;
}
@ -1590,7 +1598,7 @@ static int repo_init_structure(
if ((opts->flags & GIT_REPOSITORY_INIT__HAS_DOTGIT) != 0) {
if (git_win32__set_hidden(repo_dir, true) < 0) {
giterr_set(GITERR_OS,
"Failed to mark Git repository folder as hidden");
"failed to mark Git repository folder as hidden");
return -1;
}
}
@ -1744,7 +1752,7 @@ static int repo_init_directories(
if (git_path_dirname_r(wd_path, repo_path->ptr) < 0)
return -1;
} else {
giterr_set(GITERR_REPOSITORY, "Cannot pick working directory"
giterr_set(GITERR_REPOSITORY, "cannot pick working directory"
" for non-bare repository that isn't a '.git' directory");
return -1;
}
@ -1864,7 +1872,7 @@ int git_repository_init_ext(
if ((opts->flags & GIT_REPOSITORY_INIT_NO_REINIT) != 0) {
giterr_set(GITERR_REPOSITORY,
"Attempt to reinitialize '%s'", given_repo);
"attempt to reinitialize '%s'", given_repo);
error = GIT_EEXISTS;
goto cleanup;
}
@ -2146,7 +2154,7 @@ int git_repository_message(git_buf *out, git_repository *repo)
if ((error = p_stat(git_buf_cstr(&path), &st)) < 0) {
if (errno == ENOENT)
error = GIT_ENOTFOUND;
giterr_set(GITERR_OS, "Could not access message file");
giterr_set(GITERR_OS, "could not access message file");
} else {
error = git_futils_readbuffer(out, git_buf_cstr(&path));
}
@ -2224,7 +2232,7 @@ int git_repository_hashfile(
}
if (!git__is_sizet(len)) {
giterr_set(GITERR_OS, "File size overflow for 32-bit systems");
giterr_set(GITERR_OS, "file size overflow for 32-bit systems");
error = -1;
goto cleanup;
}
@ -2538,3 +2546,31 @@ int git_repository_set_ident(git_repository *repo, const char *name, const char
return 0;
}
int git_repository_submodule_cache_all(git_repository *repo)
{
int error;
assert(repo);
if ((error = git_strmap_alloc(&repo->submodule_cache)))
return error;
error = git_submodule__map(repo, repo->submodule_cache);
return error;
}
int git_repository_submodule_cache_clear(git_repository *repo)
{
git_submodule *sm;
assert(repo);
if (repo->submodule_cache == NULL) {
return 0;
}
git_strmap_foreach_value(repo->submodule_cache, sm, {
git_submodule_free(sm);
});
git_strmap_free(repo->submodule_cache);
repo->submodule_cache = 0;
return 0;
}

View File

@ -143,6 +143,7 @@ struct git_repository {
git_atomic attr_session_key;
git_cvar_value cvar_cache[GIT_CVAR_CACHE_MAX];
git_strmap *submodule_cache;
};
GIT_INLINE(git_attr_cache *) git_repository_attr_cache(git_repository *repo)
@ -182,7 +183,7 @@ GIT_INLINE(int) git_repository__ensure_not_bare(
giterr_set(
GITERR_REPOSITORY,
"Cannot %s. This operation is not allowed against bare repositories.",
"cannot %s. This operation is not allowed against bare repositories.",
operation_name);
return GIT_EBAREREPO;

View File

@ -137,7 +137,7 @@ static int reset(
(git_repository_state(repo) == GIT_REPOSITORY_STATE_MERGE ||
git_index_has_conflicts(index)))
{
giterr_set(GITERR_OBJECT, "%s (soft) in the middle of a merge.", ERROR_MSG);
giterr_set(GITERR_OBJECT, "%s (soft) in the middle of a merge", ERROR_MSG);
error = GIT_EUNMERGED;
goto cleanup;
}

View File

@ -133,13 +133,13 @@ int git_revert_commit(
if (git_commit_parentcount(revert_commit) > 1) {
if (!mainline)
return revert_seterr(revert_commit,
"Mainline branch is not specified but %s is a merge commit");
"mainline branch is not specified but %s is a merge commit");
parent = mainline;
} else {
if (mainline)
return revert_seterr(revert_commit,
"Mainline branch specified but %s is not a merge commit");
"mainline branch specified but %s is not a merge commit");
parent = git_commit_parentcount(revert_commit);
}

View File

@ -46,7 +46,7 @@ static int build_regex(regex_t *regex, const char *pattern)
int error;
if (*pattern == '\0') {
giterr_set(GITERR_REGEX, "Empty pattern");
giterr_set(GITERR_REGEX, "empty pattern");
return GIT_EINVALIDSPEC;
}
@ -118,7 +118,7 @@ static int revparse_lookup_object(
if ((error = maybe_describe(object_out, repo, spec)) != GIT_ENOTFOUND)
return error;
giterr_set(GITERR_REFERENCE, "Revspec '%s' not found.", spec);
giterr_set(GITERR_REFERENCE, "revspec '%s' not found", spec);
return GIT_ENOTFOUND;
}
@ -245,7 +245,7 @@ static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, size_t ide
notfound:
giterr_set(
GITERR_REFERENCE,
"Reflog for '%s' has only %"PRIuZ" entries, asked for %"PRIuZ,
"reflog for '%s' has only %"PRIuZ" entries, asked for %"PRIuZ,
git_reference_name(ref), numentries, identifier);
git_reflog_free(reflog);
@ -757,7 +757,7 @@ int revparse__ext(
* TODO: support merge-stage path lookup (":2:Makefile")
* and plain index blob lookup (:i-am/a/blob)
*/
giterr_set(GITERR_INVALID, "Unimplemented");
giterr_set(GITERR_INVALID, "unimplemented");
error = GIT_ERROR;
goto cleanup;
}
@ -816,7 +816,7 @@ cleanup:
if (error) {
if (error == GIT_EINVALIDSPEC)
giterr_set(GITERR_INVALID,
"Failed to parse revision specifier - Invalid pattern '%s'", spec);
"failed to parse revision specifier - Invalid pattern '%s'", spec);
git_object_free(base_rev);
git_reference_free(reference);

View File

@ -61,7 +61,7 @@ static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting,
if (from_glob)
return 0;
giterr_set(GITERR_INVALID, "Object is not a committish");
giterr_set(GITERR_INVALID, "object is not a committish");
return -1;
}
if (error < 0)
@ -198,7 +198,7 @@ int git_revwalk_push_range(git_revwalk *walk, const char *range)
if (revspec.flags & GIT_REVPARSE_MERGE_BASE) {
/* TODO: support "<commit>...<commit>" */
giterr_set(GITERR_INVALID, "Symmetric differences not implemented in revwalk");
giterr_set(GITERR_INVALID, "symmetric differences not implemented in revwalk");
return GIT_EINVALIDSPEC;
}
@ -290,7 +290,7 @@ static void mark_parents_uninteresting(git_commit_list_node *commit)
while (parents) {
git_commit_list_node *commit = git_commit_list_pop(&parents);
commit = git_commit_list_pop(&parents);
while (commit) {
if (commit->uninteresting)
@ -733,7 +733,7 @@ int git_revwalk_add_hide_cb(
if (walk->hide_cb) {
/* There is already a callback added */
giterr_set(GITERR_INVALID, "There is already a callback added to hide commits in revision walker.");
giterr_set(GITERR_INVALID, "there is already a callback added to hide commits in revwalk");
return -1;
}

View File

@ -29,7 +29,9 @@ int git_libgit2_features(void)
#ifdef GIT_THREADS
| GIT_FEATURE_THREADS
#endif
#if defined(GIT_OPENSSL) || defined(GIT_WINHTTP) || defined(GIT_SECURE_TRANSPORT)
| GIT_FEATURE_HTTPS
#endif
#if defined(GIT_SSH)
| GIT_FEATURE_SSH
#endif
@ -62,7 +64,7 @@ static int config_level_to_sysdir(int config_level)
break;
default:
giterr_set(
GITERR_INVALID, "Invalid config path selector %d", config_level);
GITERR_INVALID, "invalid config path selector %d", config_level);
}
return val;

View File

@ -206,7 +206,7 @@ int sha1_entry_pos(const void *table,
#endif
if (!(lo <= mi && mi < hi)) {
giterr_set(GITERR_INVALID, "Assertion failure. Binary search invariant is false");
giterr_set(GITERR_INVALID, "assertion failure: binary search invariant is false");
return -1;
}

View File

@ -25,7 +25,7 @@ void git_signature_free(git_signature *sig)
static int signature_error(const char *msg)
{
giterr_set(GITERR_INVALID, "Failed to parse signature - %s", msg);
giterr_set(GITERR_INVALID, "failed to parse signature - %s", msg);
return -1;
}
@ -251,7 +251,7 @@ int git_signature__parse(git_signature *sig, const char **buffer_out,
* only store timezone if it's not overflowing;
* see http://www.worldtimezone.com/faq.html
*/
if (hours < 14 && mins < 59) {
if (hours <= 14 && mins <= 59) {
sig->when.offset = (hours * 60) + mins;
if (tz_start[0] == '-')
sig->when.offset = -sig->when.offset;

Some files were not shown because too many files have changed in this diff Show More