diff options
| author | Brian Lopez <seniorlopez@gmail.com> | 2018-01-10 19:19:34 -0800 |
|---|---|---|
| committer | Brian Lopez <seniorlopez@gmail.com> | 2018-01-10 19:19:34 -0800 |
| commit | 5734768b9edaecedaa7b13fed2ce59cb588df7e8 (patch) | |
| tree | 84a845211a548cef770bbccd32d6d041a2bcea2b /src | |
| parent | f4f0e7eb0f8280ed6100c37c3af0aa66c31a8f9e (diff) | |
| parent | f1323d9c161aeeada190fd9615a8b5a9fb8a7f3e (diff) | |
| download | libgit2-5734768b9edaecedaa7b13fed2ce59cb588df7e8.tar.gz | |
Merge remote-tracking branch 'origin/master' into charliesome/trailer-info
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 64 | ||||
| -rw-r--r-- | src/diff.h | 1 | ||||
| -rw-r--r-- | src/diff_driver.c | 17 | ||||
| -rw-r--r-- | src/diff_driver.h | 4 | ||||
| -rw-r--r-- | src/diff_file.c | 6 | ||||
| -rw-r--r-- | src/diff_generate.c | 2 | ||||
| -rw-r--r-- | src/hash/hash_openssl.h | 21 | ||||
| -rw-r--r-- | src/streams/openssl.c | 18 | ||||
| -rw-r--r-- | src/tree.c | 20 |
9 files changed, 99 insertions, 54 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2c82d1f59..b03b96af9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,11 +3,6 @@ IF(DEBUG_POOL) ENDIF() ADD_FEATURE_INFO(debugpool GIT_DEBUG_POOL "debug pool allocator") -# Add the features.h file as a dummy. This is required for Xcode -# to successfully build the libgit2 library when using only -# object libraries. -SET(LIBGIT2_OBJECTS "${CMAKE_CURRENT_BINARY_DIR}/git2/sys/features.h") - # This variable will contain the libraries we need to put into # libgit2.pc's Requires.private. That is, what we're linking to or # what someone who's statically linking us needs to link to. @@ -127,10 +122,6 @@ ELSE () PKG_CHECK_MODULES(CURL libcurl) ENDIF () - IF (NOT AMIGA AND (USE_HTTPS STREQUAL "OpenSSL" OR USE_HTTPS STREQUAL "ON")) - FIND_PACKAGE(OpenSSL QUIET) - ENDIF () - IF (CURL_FOUND) SET(GIT_CURL 1) LIST(APPEND LIBGIT2_INCLUDES ${CURL_INCLUDE_DIRS}) @@ -183,6 +174,8 @@ IF (USE_HTTPS) LIST(APPEND LIBGIT2_LIBS ${COREFOUNDATION_LIBRARIES} ${SECURITY_LIBRARIES}) LIST(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) ELSEIF (HTTPS_BACKEND STREQUAL "OpenSSL") + FIND_PACKAGE(OpenSSL) + IF (NOT OPENSSL_FOUND) MESSAGE(FATAL_ERROR "Asked for OpenSSL TLS backend, but it wasn't found") ENDIF() @@ -191,6 +184,7 @@ IF (USE_HTTPS) LIST(APPEND LIBGIT2_INCLUDES ${OPENSSL_INCLUDE_DIR}) LIST(APPEND LIBGIT2_LIBS ${OPENSSL_LIBRARIES}) LIST(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS}) + LIST(APPEND LIBGIT2_PC_REQUIRES "openssl") ELSEIF (HTTPS_BACKEND STREQUAL "WinHTTP") # WinHTTP setup was handled in the WinHTTP-specific block above ELSE() @@ -204,34 +198,42 @@ ELSE() ENDIF() # Specify sha1 implementation -IF (USE_SHA1DC) - ADD_FEATURE_INFO(SHA ON "using SHA1DC") +IF(SHA1_BACKEND STREQUAL "OpenSSL") + IF(NOT OPENSSL_FOUND) + FIND_PACKAGE(OpenSSL) + IF(NOT OPENSSL_FOUND) + MESSAGE(FATAL_ERROR "Requested OpenSSL SHA1 backend, but OpenSSL could not be found") + ENDIF() + ENDIF() + + ADD_FEATURE_INFO(SHA ON "using OpenSSL") + SET(GIT_SHA1_OPENSSL 1) + IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + LIST(APPEND LIBGIT2_PC_LIBS "-lssl") + ELSE() + LIST(APPEND LIBGIT2_PC_REQUIRES "openssl") + ENDIF() +ELSEIF(SHA1_BACKEND STREQUAL "CollisionDetection") + ADD_FEATURE_INFO(SHA ON "using CollisionDetection") SET(GIT_SHA1_COLLISIONDETECT 1) ADD_DEFINITIONS(-DSHA1DC_NO_STANDARD_INCLUDES=1) ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\") ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\") FILE(GLOB SRC_SHA1 hash/hash_collisiondetect.c hash/sha1dc/*) -ELSEIF (WIN32 AND NOT MINGW) - ADD_FEATURE_INFO(SHA ON "using SHA1_WIN32") +ELSEIF(SHA1_BACKEND STREQUAL "Generic") + ADD_FEATURE_INFO(SHA ON "using Generic") + FILE(GLOB SRC_SHA1 hash/hash_generic.c) +ELSEIF(SHA1_BACKEND STREQUAL "Win32") + ADD_FEATURE_INFO(SHA ON "using Win32") SET(GIT_SHA1_WIN32 1) FILE(GLOB SRC_SHA1 hash/hash_win32.c) -ELSEIF (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +ELSEIF(SHA1_BACKEND STREQUAL "CommonCrypto") ADD_FEATURE_INFO(SHA ON "using CommonCrypto") SET(GIT_SHA1_COMMON_CRYPTO 1) -ELSEIF (OPENSSL_FOUND) - ADD_FEATURE_INFO(SHA ON "using OpenSSL") - SET(GIT_SHA1_OPENSSL 1) - IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") - LIST(APPEND LIBGIT2_PC_LIBS "-lssl") - ELSE() - SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} openssl") - ENDIF () ELSE() - ADD_FEATURE_INFO(SHA ON "using generic") - FILE(GLOB SRC_SHA1 hash/hash_generic.c) + MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend ${SHA1_BACKEND}") ENDIF() - # Include POSIX regex when it is required IF(WIN32 OR AMIGA OR CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") ADD_SUBDIRECTORY("${libgit2_SOURCE_DIR}/deps/regex" "${libgit2_BINARY_DIR}/deps/regex") @@ -264,7 +266,7 @@ IF(NOT USE_BUNDLED_ZLIB) LIST(APPEND LIBGIT2_LIBS "z") LIST(APPEND LIBGIT2_PC_LIBS "-lz") ELSE() - SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} zlib") + LIST(APPEND LIBGIT2_PC_REQUIRES "zlib") ENDIF() ADD_FEATURE_INFO(zlib ON "using system zlib") ELSE() @@ -404,6 +406,13 @@ SET(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE) SET(LIBGIT2_LIBS ${LIBGIT2_LIBS} PARENT_SCOPE) SET(LIBGIT2_LIBDIRS ${LIBGIT2_LIBDIRS} PARENT_SCOPE) +IF(XCODE_VERSION) + # This is required for Xcode to actually link the libgit2 library + # when using only object libraries. + FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.c "") + LIST(APPEND LIBGIT2_OBJECTS ${CMAKE_CURRENT_BINARY_DIR}/dummy.c) +ENDIF() + # Compile and link libgit2 LINK_DIRECTORIES(${LIBGIT2_LIBDIRS}) ADD_LIBRARY(git2 ${WIN_RC} ${LIBGIT2_OBJECTS}) @@ -431,6 +440,9 @@ IF (SONAME) SET_TARGET_PROPERTIES(git2 PROPERTIES PREFIX "${LIBGIT2_PREFIX}") ENDIF() ENDIF() + +LIST(REMOVE_DUPLICATES LIBGIT2_PC_REQUIRES) +STRING(REPLACE ";" " " LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES}") STRING(REPLACE ";" " " LIBGIT2_PC_LIBS "${LIBGIT2_PC_LIBS}") CONFIGURE_FILE(${libgit2_SOURCE_DIR}/libgit2.pc.in ${libgit2_BINARY_DIR}/libgit2.pc @ONLY) diff --git a/src/diff.h b/src/diff.h index 4e5dd93da..8c04438fa 100644 --- a/src/diff.h +++ b/src/diff.h @@ -34,6 +34,7 @@ typedef enum { struct git_diff { git_refcount rc; git_repository *repo; + git_attr_session attrsession; git_diff_origin_t type; git_diff_options opts; git_vector deltas; /* vector of git_diff_delta */ diff --git a/src/diff_driver.c b/src/diff_driver.c index 8cd57cdf6..7114b06b6 100644 --- a/src/diff_driver.c +++ b/src/diff_driver.c @@ -354,27 +354,30 @@ done: } int git_diff_driver_lookup( - git_diff_driver **out, git_repository *repo, const char *path) + git_diff_driver **out, git_repository *repo, + git_attr_session *attrsession, const char *path) { int error = 0; - const char *value; + const char *values[1], *attrs[] = { "diff" }; assert(out); *out = NULL; if (!repo || !path || !strlen(path)) /* just use the auto value */; - else if ((error = git_attr_get(&value, repo, 0, path, "diff")) < 0) + else if ((error = git_attr_get_many_with_session(values, repo, + attrsession, 0, path, 1, attrs)) < 0) /* return error below */; - else if (GIT_ATTR_UNSPECIFIED(value)) + + else if (GIT_ATTR_UNSPECIFIED(values[0])) /* just use the auto value */; - else if (GIT_ATTR_FALSE(value)) + else if (GIT_ATTR_FALSE(values[0])) *out = &global_drivers[DIFF_DRIVER_BINARY]; - else if (GIT_ATTR_TRUE(value)) + else if (GIT_ATTR_TRUE(values[0])) *out = &global_drivers[DIFF_DRIVER_TEXT]; /* otherwise look for driver information in config and build driver */ - else if ((error = git_diff_driver_load(out, repo, value)) < 0) { + else if ((error = git_diff_driver_load(out, repo, values[0])) < 0) { if (error == GIT_ENOTFOUND) { error = 0; giterr_clear(); diff --git a/src/diff_driver.h b/src/diff_driver.h index 5691cac30..a03a67e67 100644 --- a/src/diff_driver.h +++ b/src/diff_driver.h @@ -9,6 +9,7 @@ #include "common.h" +#include "attr_file.h" #include "buffer.h" typedef struct git_diff_driver_registry git_diff_driver_registry; @@ -18,7 +19,8 @@ void git_diff_driver_registry_free(git_diff_driver_registry *); typedef struct git_diff_driver git_diff_driver; -int git_diff_driver_lookup(git_diff_driver **, git_repository *, const char *); +int git_diff_driver_lookup(git_diff_driver **, git_repository *, + git_attr_session *attrsession, const char *); void git_diff_driver_free(git_diff_driver *); /* diff option flags to force off and on for this driver */ diff --git a/src/diff_file.c b/src/diff_file.c index 0813315f5..5bb9c372a 100644 --- a/src/diff_file.c +++ b/src/diff_file.c @@ -54,7 +54,8 @@ static int diff_file_content_init_common( fc->src = GIT_ITERATOR_TYPE_TREE; if (!fc->driver && - git_diff_driver_lookup(&fc->driver, fc->repo, fc->file->path) < 0) + git_diff_driver_lookup(&fc->driver, fc->repo, + NULL, fc->file->path) < 0) return -1; /* give driver a chance to modify options */ @@ -101,7 +102,8 @@ int git_diff_file_content__init_from_diff( fc->file = use_old ? &delta->old_file : &delta->new_file; fc->src = use_old ? diff->old_src : diff->new_src; - if (git_diff_driver_lookup(&fc->driver, fc->repo, fc->file->path) < 0) + if (git_diff_driver_lookup(&fc->driver, fc->repo, + &diff->attrsession, fc->file->path) < 0) return -1; switch (delta->status) { diff --git a/src/diff_generate.c b/src/diff_generate.c index bce2a683b..e11cbe4e4 100644 --- a/src/diff_generate.c +++ b/src/diff_generate.c @@ -389,6 +389,7 @@ static void diff_generated_free(git_diff *d) { git_diff_generated *diff = (git_diff_generated *)d; + git_attr_session__free(&diff->base.attrsession); git_vector_free_deep(&diff->base.deltas); git_pathspec__vfree(&diff->pathspec); @@ -418,6 +419,7 @@ static git_diff_generated *diff_generated_alloc( diff->base.new_src = new_iter->type; diff->base.patch_fn = git_patch_generated_from_diff; diff->base.free_fn = diff_generated_free; + git_attr_session__init(&diff->base.attrsession, repo); memcpy(&diff->base.opts, &dflt, sizeof(git_diff_options)); git_pool_init(&diff->base.pool, 1); diff --git a/src/hash/hash_openssl.h b/src/hash/hash_openssl.h index 9a55d472d..048c2bdb3 100644 --- a/src/hash/hash_openssl.h +++ b/src/hash/hash_openssl.h @@ -23,21 +23,36 @@ struct git_hash_ctx { GIT_INLINE(int) git_hash_init(git_hash_ctx *ctx) { assert(ctx); - SHA1_Init(&ctx->c); + + if (SHA1_Init(&ctx->c) != 1) { + giterr_set(GITERR_SHA1, "hash_openssl: failed to initialize hash context"); + return -1; + } + return 0; } GIT_INLINE(int) git_hash_update(git_hash_ctx *ctx, const void *data, size_t len) { assert(ctx); - SHA1_Update(&ctx->c, data, len); + + if (SHA1_Update(&ctx->c, data, len) != 1) { + giterr_set(GITERR_SHA1, "hash_openssl: failed to update hash"); + return -1; + } + return 0; } GIT_INLINE(int) git_hash_final(git_oid *out, git_hash_ctx *ctx) { assert(ctx); - SHA1_Final(out->id, &ctx->c); + + if (SHA1_Final(out->id, &ctx->c) != 1) { + giterr_set(GITERR_SHA1, "hash_openssl: failed to finalize hash"); + return -1; + } + return 0; } diff --git a/src/streams/openssl.c b/src/streams/openssl.c index 9d566074c..d00e98e02 100644 --- a/src/streams/openssl.c +++ b/src/streams/openssl.c @@ -282,8 +282,9 @@ static int ssl_set_error(SSL *ssl, int error) case SSL_ERROR_SYSCALL: e = ERR_get_error(); if (e > 0) { - giterr_set(GITERR_NET, "SSL error: %s", - ERR_error_string(e, NULL)); + char errmsg[256]; + ERR_error_string_n(e, errmsg, sizeof(errmsg)); + giterr_set(GITERR_NET, "SSL error: %s", errmsg); break; } else if (error < 0) { giterr_set(GITERR_OS, "SSL error: syscall failure"); @@ -293,10 +294,13 @@ static int ssl_set_error(SSL *ssl, int error) return GIT_EEOF; break; case SSL_ERROR_SSL: + { + char errmsg[256]; e = ERR_get_error(); - giterr_set(GITERR_NET, "SSL error: %s", - ERR_error_string(e, NULL)); + ERR_error_string_n(e, errmsg, sizeof(errmsg)); + giterr_set(GITERR_NET, "SSL error: %s", errmsg); break; + } case SSL_ERROR_NONE: case SSL_ERROR_ZERO_RETURN: default: @@ -645,8 +649,12 @@ out_err: int git_openssl__set_cert_location(const char *file, const char *path) { if (SSL_CTX_load_verify_locations(git__ssl_ctx, file, path) == 0) { + char errmsg[256]; + + ERR_error_string_n(ERR_get_error(), errmsg, sizeof(errmsg)); giterr_set(GITERR_SSL, "OpenSSL error: failed to load certificates: %s", - ERR_error_string(ERR_get_error(), NULL)); + errmsg); + return -1; } return 0; diff --git a/src/tree.c b/src/tree.c index fcee7f3b3..75fde2c8f 100644 --- a/src/tree.c +++ b/src/tree.c @@ -440,16 +440,16 @@ int git_tree__parse(void *_tree, git_odb_object *odb_obj) unsigned int attr; if (parse_mode(&attr, buffer, &buffer) < 0 || !buffer) - return tree_error("Failed to parse tree. Can't parse filemode", NULL); + return tree_error("failed to parse tree: can't parse filemode", NULL); if ((nul = memchr(buffer, 0, buffer_end - buffer)) == NULL) - return tree_error("Failed to parse tree. Object is corrupted", NULL); + return tree_error("failed to parse tree: object is corrupted", NULL); if ((filename_len = nul - buffer) == 0) - return tree_error("Failed to parse tree. Can't parse filename", NULL); + return tree_error("failed to parse tree: can't parse filename", NULL); if ((buffer_end - (nul + 1)) < GIT_OID_RAWSZ) - return tree_error("Failed to parse tree. Can't parse OID", NULL); + return tree_error("failed to parse tree: can't parse OID", NULL); /* Allocate the entry */ { @@ -496,7 +496,7 @@ static int append_entry( int error = 0; if (!valid_entry_name(bld->repo, filename)) - return tree_error("Failed to insert entry. Invalid name for a tree entry", filename); + return tree_error("failed to insert entry: invalid name for a tree entry", filename); entry = alloc_entry(filename, strlen(filename), id); GITERR_CHECK_ALLOC(entry); @@ -735,14 +735,14 @@ int git_treebuilder_insert( assert(bld && id && filename); if (!valid_filemode(filemode)) - return tree_error("Failed to insert entry. Invalid filemode for file", filename); + return tree_error("failed to insert entry: invalid filemode for file", filename); if (!valid_entry_name(bld->repo, filename)) - return tree_error("Failed to insert entry. Invalid name for a tree entry", filename); + return tree_error("failed to insert entry: invalid name for a tree entry", filename); if (filemode != GIT_FILEMODE_COMMIT && !git_object__is_valid(bld->repo, id, otype_from_mode(filemode))) - return tree_error("Failed to insert entry; invalid object specified", filename); + return tree_error("failed to insert entry: invalid object specified", filename); pos = git_strmap_lookup_index(bld->map, filename); if (git_strmap_valid_index(bld->map, pos)) { @@ -793,7 +793,7 @@ int git_treebuilder_remove(git_treebuilder *bld, const char *filename) git_tree_entry *entry = treebuilder_get(bld, filename); if (entry == NULL) - return tree_error("Failed to remove entry. File isn't in the tree", filename); + return tree_error("failed to remove entry: file isn't in the tree", filename); git_strmap_delete(bld->map, filename); git_tree_entry_free(entry); @@ -946,7 +946,7 @@ int git_tree_entry_bypath( return GIT_ENOTFOUND; } - /* If there's only a slash left in the path, we + /* If there's only a slash left in the path, we * return the current entry; otherwise, we keep * walking down the path */ if (path[filename_len + 1] != '\0') |
