From 4969a6721b56d961f7d2cc925856dc07d0833c6e Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Sun, 10 Dec 2017 02:19:34 +0000 Subject: cmake: create a dummy file for Xcode Otherwise Xcode will happily not-link our git2 target, resulting in a "missing file" error when building eg. examples --- src/CMakeLists.txt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e456ab725..ac519471d 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. @@ -404,6 +399,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}) -- cgit v1.2.1 From 346c1b169d0c15adeef496e24db6ac9801b4283d Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sun, 31 Dec 2017 09:25:42 -0600 Subject: docs: git_treebuilder_insert validates entries The documentation for `git_treebuilder_insert` erroneously states that we do not validate that the entry being inserted exists. We do, as of https://github.com/libgit2/libgit2/pull/3633. Update the documentation to reflect the new reality. --- include/git2/tree.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/git2/tree.h b/include/git2/tree.h index 4740b1ffa..1a363c149 100644 --- a/include/git2/tree.h +++ b/include/git2/tree.h @@ -307,9 +307,10 @@ GIT_EXTERN(const git_tree_entry *) git_treebuilder_get( * pointer may not be valid past the next operation in this * builder. Duplicate the entry if you want to keep it. * - * No attempt is being made to ensure that the provided oid points - * to an existing git object in the object database, nor that the - * attributes make sense regarding the type of the pointed at object. + * By default the entry that you are inserting will be checked for + * validity; that it exists in the object database and is of the + * correct type. If you do not want this behavior, set the + * `GIT_OPT_ENABLE_STRICT_OBJECT_CREATION` library option to false. * * @param out Pointer to store the entry (optional) * @param bld Tree builder -- cgit v1.2.1 From 2c99011a80dcd460dadd271f279c9dc6d3c8d2a1 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sun, 31 Dec 2017 09:33:19 -0600 Subject: tree: standard error messages are lowercase Our standard error messages begin with a lower case letter so that they can be prefixed or embedded nicely. These error messages were missed during the standardization pass since they use the `tree_error` helper function. --- src/tree.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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') -- cgit v1.2.1 From 8999f6acc78810680f282db4257e842971b80cb4 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 7 Jun 2017 11:01:28 +0200 Subject: travis: build sources with tracing enabled Our tracing architecture is not built by default, causing the Travis CI to not execute some code and skip several tests. As AppVeyor has already enabled the tracing architecture when building the code, we should do the same for Travis CI to have this code being tested on macOS and Linux. Add "-DENABLE_TRACE=ON" to our release-build options of Travis. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 569a6a7d4..5d687f1ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ env: - secure: "YnhS+8n6B+uoyaYfaJ3Lei7cSJqHDPiKJCKFIF2c87YDfmCvAJke8QtE7IzjYDs7UFkTCM4ox+ph2bERUrxZbSCyEkHdjIZpKuMJfYWja/jgMqTMxdyOH9y8JLFbZsSXDIXDwqBlC6vVyl1fP90M35wuWcNTs6tctfVWVofEFbs=" - GITTEST_INVASIVE_FS_SIZE=1 matrix: - - OPTIONS="-DTHREADSAFE=ON -DCMAKE_BUILD_TYPE=Release -DENABLE_WERROR=ON" + - OPTIONS="-DTHREADSAFE=ON -DENABLE_TRACE=ON -DCMAKE_BUILD_TYPE=Release -DENABLE_WERROR=ON" - OPTIONS="-DTHREADSAFE=OFF -DBUILD_EXAMPLES=ON -DENABLE_WERROR=ON" dist: trusty -- cgit v1.2.1 From 72c28ab011759dce113c2a0c7c36ebcd56bd6ddf Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 7 Jun 2017 10:59:03 +0200 Subject: tests: status::worktree: indicate skipped tests on Win32 Some function bodies of tests which are not applicable to the Win32 platform are completely #ifdef'd out instead of calling `cl_skip()`. This leaves us with no indication that these tests are not being executed at all and may thus cause decreased scrutiny when investigating skipped tests. Improve the situation by calling `cl_skip()` instead of just doing nothing. --- tests/checkout/tree.c | 2 ++ tests/iterator/workdir.c | 2 ++ tests/repo/open.c | 2 ++ tests/status/worktree.c | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c index 56513eab7..a7e29b3db 100644 --- a/tests/checkout/tree.c +++ b/tests/checkout/tree.c @@ -1096,6 +1096,8 @@ void test_checkout_tree__filemode_preserved_in_workdir(void) cl_assert(!GIT_PERMS_IS_EXEC(read_filemode("a/b.txt"))); git_commit_free(commit); +#else + cl_skip(); #endif } diff --git a/tests/iterator/workdir.c b/tests/iterator/workdir.c index f33fd98f1..618006715 100644 --- a/tests/iterator/workdir.c +++ b/tests/iterator/workdir.c @@ -741,6 +741,8 @@ void test_iterator_workdir__skips_fifos_and_special_files(void) cl_assert_equal_i(GIT_ITEROVER, git_iterator_advance(&e, i)); git_iterator_free(i); +#else + cl_skip(); #endif } diff --git a/tests/repo/open.c b/tests/repo/open.c index 3239b6fec..ab36dd587 100644 --- a/tests/repo/open.c +++ b/tests/repo/open.c @@ -180,6 +180,8 @@ void test_repo_open__from_git_new_workdir(void) cl_assert_(git__suffixcmp(git_repository_workdir(repo2), "alternate/") == 0, git_repository_workdir(repo2)); git_repository_free(repo2); +#else + cl_skip(); #endif } diff --git a/tests/status/worktree.c b/tests/status/worktree.c index 1345dbfd2..79eece85a 100644 --- a/tests/status/worktree.c +++ b/tests/status/worktree.c @@ -1072,6 +1072,8 @@ void test_status_worktree__unreadable(void) cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); +#else + cl_skip(); #endif } @@ -1106,6 +1108,8 @@ void test_status_worktree__unreadable_not_included(void) cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); +#else + cl_skip(); #endif } -- cgit v1.2.1 From 9aba76364fcb4755930856a7bafc5294ed3ee944 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 7 Jun 2017 10:59:31 +0200 Subject: tests: iterator_helpers: assert number of iterator items When the function `expect_iterator_items` surpasses the number of expected items, we simply break the loop. This causes us to trigger an assert later on which has message attached, which is annoying when trying to locate the root error cause. Instead, directly assert that the current count is still smaller or equal to the expected count inside of the loop. --- tests/iterator/iterator_helpers.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/iterator/iterator_helpers.c b/tests/iterator/iterator_helpers.c index ae48fcd46..68d574126 100644 --- a/tests/iterator/iterator_helpers.c +++ b/tests/iterator/iterator_helpers.c @@ -51,8 +51,7 @@ void expect_iterator_items( cl_assert(entry->mode != GIT_FILEMODE_TREE); } - if (++count >= expected_flat) - break; + cl_assert(++count <= expected_flat); } assert_at_end(i, v); -- cgit v1.2.1 From b8c14499f9940feaab08a23651a2ef24d27b17b7 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 7 Jun 2017 11:00:26 +0200 Subject: tests: iterator::workdir: fix reference count in stale test The test `iterator::workdir::filesystem_gunk` is usually not executed, as it is guarded by the environment variable "GITTEST_INVASIVE_SPEED" due to its effects on speed. As such, it has become stale and does not account for new references which have meanwhile been added to the testrepo, causing it to fail. Fix this by raising the number of expected references to 15. --- tests/iterator/workdir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/iterator/workdir.c b/tests/iterator/workdir.c index 618006715..198edc7e8 100644 --- a/tests/iterator/workdir.c +++ b/tests/iterator/workdir.c @@ -662,7 +662,7 @@ void test_iterator_workdir__filesystem_gunk(void) /* should only have 13 items, since we're not asking for trees to be * returned. the goal of this test is simply to not crash. */ - expect_iterator_items(i, 13, NULL, 13, NULL); + expect_iterator_items(i, 15, NULL, 15, NULL); git_iterator_free(i); git_buf_free(&parent); } -- cgit v1.2.1 From 543ec149b86a68e12dd141a6141e82850dabbf21 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 7 Jun 2017 11:06:01 +0200 Subject: tests: perf: build but exclude performance tests by default Our performance tests (or to be more concrete, our single performance test) are not built by default, as they are always #ifdef'd out. While it is true that we don't want to run performance tests by default, not compiling them at all may cause code rot and is thus an unfavorable approach to handle this. We can easily improve this situation: this commit removes the #ifdef, causing the code to always be compiled. Furthermore, we add `-xperf` to the default command line parameters of `generate.py`, thus causing the tests to be excluded by default. Due to this approach, we are now able to execute the performance tests by passing `-sperf` to `libgit2_clar`. Unfortunately, we cannot execute the performance tests on Travis or AppVeyor as they rely on history being available for the libgit2 repository. As both do a shallow clone only, though, this is not given. --- tests/CMakeLists.txt | 2 +- tests/perf/merge.c | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 08ecb396b..4606fe979 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -20,7 +20,7 @@ ENDIF() ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite - COMMAND ${PYTHON_EXECUTABLE} generate.py -o "${CMAKE_CURRENT_BINARY_DIR}" -f -xonline -xstress . + COMMAND ${PYTHON_EXECUTABLE} generate.py -o "${CMAKE_CURRENT_BINARY_DIR}" -f -xonline -xstress -xperf . DEPENDS ${SRC_TEST} WORKING_DIRECTORY ${CLAR_PATH} ) diff --git a/tests/perf/merge.c b/tests/perf/merge.c index b2ef082eb..721902d63 100644 --- a/tests/perf/merge.c +++ b/tests/perf/merge.c @@ -25,20 +25,7 @@ #define ID_BRANCH_A "d853fb9f24e0fe63b3dce9fbc04fd9cfe17a030b" #define ID_BRANCH_B "1ce9ea3ba9b4fa666602d52a5281d41a482cc58b" - -void test_perf_merge__initialize(void) -{ -} - -void test_perf_merge__cleanup(void) -{ -} - void test_perf_merge__m1(void) { -#if 1 - cl_skip(); -#else perf__do_merge(SRC_REPO, "m1", ID_BRANCH_A, ID_BRANCH_B); -#endif } -- cgit v1.2.1 From fea6092079d5c09b499e472efead2f7aa81ce8a1 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 7 Jun 2017 12:48:48 +0200 Subject: tests: online::clone: construct credential-URL from environment We support two types of passing credentials to the proxy, either via the URL or explicitly by specifying user and password. We test these types by modifying the proxy URL and executing the tests twice, which is in fact unnecessary and requires us to maintain the list of environment variables and test executions across multiple CI infrastructures. To fix the situation, we can just always pass the host, port, user and password to the tests. The tests can then assemble the complete URL either with or without included credentials, allowing us to test both cases in-process. --- appveyor.yml | 6 ++---- script/cibuild.sh | 14 +++++--------- tests/CMakeLists.txt | 3 +-- tests/online/clone.c | 16 +++++++++++++--- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index e0c7b9b90..1c4c1af7e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -52,9 +52,7 @@ test_script: $env:GITTEST_REMOTE_USER="libgit2test" ctest -V -R libgit2_clar-cred_callback Receive-Job -Job $proxyJob - $env:GITTEST_REMOTE_PROXY_URL = "http://foo:bar@localhost:8080" - ctest -V -R libgit2_clar-proxy_credentials_in_url - $env:GITTEST_REMOTE_PROXY_URL = "http://localhost:8080" + $env:GITTEST_REMOTE_PROXY_URL = "localhost:8080" $env:GITTEST_REMOTE_PROXY_USER = "foo" $env:GITTEST_REMOTE_PROXY_PASS = "bar" - ctest -V -R libgit2_clar-proxy_credentials_request + ctest -V -R libgit2_clar-proxy_credentials diff --git a/script/cibuild.sh b/script/cibuild.sh index 1c28baae6..c06de1933 100755 --- a/script/cibuild.sh +++ b/script/cibuild.sh @@ -90,7 +90,10 @@ export GITTEST_REMOTE_USER=$USER export GITTEST_REMOTE_SSH_KEY="$HOME/.ssh/id_rsa" export GITTEST_REMOTE_SSH_PUBKEY="$HOME/.ssh/id_rsa.pub" export GITTEST_REMOTE_SSH_PASSPHRASE="" - +# Use the proxy we started at the beginning +export GITTEST_REMOTE_PROXY_URL="localhost:8080" +export GITTEST_REMOTE_PROXY_USER="foo" +export GITTEST_REMOTE_PROXY_PASS="bar" if [ -e ./libgit2_clar ]; then ./libgit2_clar -sonline::push -sonline::clone::ssh_cert && @@ -99,14 +102,7 @@ if [ -e ./libgit2_clar ]; then ./libgit2_clar -sonline::clone::cred_callback || exit $? fi - # Use the proxy we started at the beginning - export GITTEST_REMOTE_PROXY_URL="http://foo:bar@localhost:8080/" - ./libgit2_clar -sonline::clone::proxy_credentials_in_url || exit $? - export GITTEST_REMOTE_PROXY_URL="http://localhost:8080/" - export GITTEST_REMOTE_PROXY_USER="foo" - export GITTEST_REMOTE_PROXY_PASS="bar" - ./libgit2_clar -sonline::clone::proxy_credentials_request || exit $? - + ctest -V -R libgit2_clar-proxy_credentials || exit $? fi kill $(cat "$HOME/sshd/pid") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4606fe979..2d18391bd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -61,5 +61,4 @@ ENDIF () # Add a test target which runs the cred callback tests, to be # called after setting the url and user ADD_TEST(libgit2_clar-cred_callback "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::cred_callback) -ADD_TEST(libgit2_clar-proxy_credentials_in_url "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_in_url) -ADD_TEST(libgit2_clar-proxy_credentials_request "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_request) +ADD_TEST(libgit2_clar-proxy_credentials "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_in_url -sonline::clone::proxy_credentials_request) diff --git a/tests/online/clone.c b/tests/online/clone.c index 5eda73f87..b6709869e 100644 --- a/tests/online/clone.c +++ b/tests/online/clone.c @@ -677,24 +677,34 @@ static int proxy_creds(git_cred **out, const char *url, const char *username, un void test_online_clone__proxy_credentials_request(void) { + git_buf url = GIT_BUF_INIT; + if (!_remote_proxy_url || !_remote_proxy_user || !_remote_proxy_pass) cl_skip(); + cl_git_pass(git_buf_printf(&url, "http://%s/", _remote_proxy_url)); + g_options.fetch_opts.proxy_opts.type = GIT_PROXY_SPECIFIED; - g_options.fetch_opts.proxy_opts.url = _remote_proxy_url; + g_options.fetch_opts.proxy_opts.url = url.ptr; g_options.fetch_opts.proxy_opts.credentials = proxy_creds; called_proxy_creds = 0; cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options)); cl_assert(called_proxy_creds); + + git_buf_free(&url); } void test_online_clone__proxy_credentials_in_url(void) { - if (!_remote_proxy_url) + git_buf url = GIT_BUF_INIT; + + if (!_remote_proxy_url || !_remote_proxy_user || !_remote_proxy_pass) cl_skip(); + cl_git_pass(git_buf_printf(&url, "http://%s:%s@%s/", _remote_proxy_user, _remote_proxy_pass, _remote_proxy_url)); + g_options.fetch_opts.proxy_opts.type = GIT_PROXY_SPECIFIED; - g_options.fetch_opts.proxy_opts.url = _remote_proxy_url; + g_options.fetch_opts.proxy_opts.url = url.ptr; called_proxy_creds = 0; cl_git_pass(git_clone(&g_repo, "http://github.com/libgit2/TestGitRepository", "./foo", &g_options)); cl_assert(called_proxy_creds == 0); -- cgit v1.2.1 From 54a1bf057a1123cf55ac3447c79761c817382f47 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 7 Jun 2017 13:06:53 +0200 Subject: tests: online::clone: inline creds-test with nonexistent URL Right now, we test our credential callback code twice, once via SSH on localhost and once via a non-existent GitHub repository. While the first URL makes sense to be configurable, it does not make sense to hard-code the non-existing repository, which requires us to call tests multiple times. Instead, we can just inline the URL into another set of tests. --- appveyor.yml | 3 --- script/cibuild.sh | 7 ------- tests/CMakeLists.txt | 1 - tests/online/clone.c | 8 ++++---- 4 files changed, 4 insertions(+), 15 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 1c4c1af7e..9b14a9c81 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -48,9 +48,6 @@ test_script: # Run this early so we know it's ready by the time we need it $proxyJob = Start-Job { java -jar $Env:APPVEYOR_BUILD_FOLDER\build\poxyproxy.jar -d --port 8080 --credentials foo:bar } ctest -V -R libgit2_clar - $env:GITTEST_REMOTE_URL="https://github.com/libgit2/non-existent" - $env:GITTEST_REMOTE_USER="libgit2test" - ctest -V -R libgit2_clar-cred_callback Receive-Job -Job $proxyJob $env:GITTEST_REMOTE_PROXY_URL = "localhost:8080" $env:GITTEST_REMOTE_PROXY_USER = "foo" diff --git a/script/cibuild.sh b/script/cibuild.sh index c06de1933..5cebb5c17 100755 --- a/script/cibuild.sh +++ b/script/cibuild.sh @@ -98,15 +98,8 @@ export GITTEST_REMOTE_PROXY_PASS="bar" if [ -e ./libgit2_clar ]; then ./libgit2_clar -sonline::push -sonline::clone::ssh_cert && ./libgit2_clar -sonline::clone::ssh_with_paths || exit $? - if [ "$TRAVIS_OS_NAME" = "linux" ]; then - ./libgit2_clar -sonline::clone::cred_callback || exit $? - fi ctest -V -R libgit2_clar-proxy_credentials || exit $? fi kill $(cat "$HOME/sshd/pid") - -export GITTEST_REMOTE_URL="https://github.com/libgit2/non-existent" -export GITTEST_REMOTE_USER="libgit2test" -ctest -V -R libgit2_clar-cred_callback diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2d18391bd..fbc3d41e5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -60,5 +60,4 @@ ENDIF () # Add a test target which runs the cred callback tests, to be # called after setting the url and user -ADD_TEST(libgit2_clar-cred_callback "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::cred_callback) ADD_TEST(libgit2_clar-proxy_credentials "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_in_url -sonline::clone::proxy_credentials_request) diff --git a/tests/online/clone.c b/tests/online/clone.c index b6709869e..b9230eca6 100644 --- a/tests/online/clone.c +++ b/tests/online/clone.c @@ -263,8 +263,8 @@ static int cred_failure_cb( void test_online_clone__cred_callback_failure_return_code_is_tunnelled(void) { - if (!_remote_url || !_remote_user) - clar__skip(); + _remote_url = git__strdup("https://github.com/libgit2/non-existent"); + _remote_user = git__strdup("libgit2test"); g_options.fetch_opts.callbacks.credentials = cred_failure_cb; @@ -293,8 +293,8 @@ void test_online_clone__cred_callback_called_again_on_auth_failure(void) { size_t counter = 0; - if (!_remote_url || !_remote_user) - clar__skip(); + _remote_url = git__strdup("https://github.com/libgit2/non-existent"); + _remote_user = git__strdup("libgit2test"); g_options.fetch_opts.callbacks.credentials = cred_count_calls_cb; g_options.fetch_opts.callbacks.payload = &counter; -- cgit v1.2.1 From 5874e151d7b10de84fc1ca168339fdc622292219 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Mon, 20 Nov 2017 13:26:33 +0000 Subject: tests: create new test target for all SSH-based tests Some tests shall be run against our own SSH server we spin up in Travis. As those need to be run separate from our previous tests which run against git-daemon, we have to do this in a separate step. Instead of bundling all that knowledge in the CI script, move it into the test build instructions by creating a new test target. --- script/cibuild.sh | 11 ++++------- tests/CMakeLists.txt | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/script/cibuild.sh b/script/cibuild.sh index 5cebb5c17..5d70e7506 100755 --- a/script/cibuild.sh +++ b/script/cibuild.sh @@ -85,21 +85,18 @@ else export GITTEST_REMOTE_SSH_FINGERPRINT=$(ssh-keygen -F '[localhost]:2222' -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':') fi +# Use the SSH server export GITTEST_REMOTE_URL="ssh://localhost:2222/$HOME/_temp/test.git" export GITTEST_REMOTE_USER=$USER export GITTEST_REMOTE_SSH_KEY="$HOME/.ssh/id_rsa" export GITTEST_REMOTE_SSH_PUBKEY="$HOME/.ssh/id_rsa.pub" export GITTEST_REMOTE_SSH_PASSPHRASE="" +ctest -V -R libgit2_clar-ssh || exit $? + # Use the proxy we started at the beginning export GITTEST_REMOTE_PROXY_URL="localhost:8080" export GITTEST_REMOTE_PROXY_USER="foo" export GITTEST_REMOTE_PROXY_PASS="bar" - -if [ -e ./libgit2_clar ]; then - ./libgit2_clar -sonline::push -sonline::clone::ssh_cert && - ./libgit2_clar -sonline::clone::ssh_with_paths || exit $? - - ctest -V -R libgit2_clar-proxy_credentials || exit $? -fi +ctest -V -R libgit2_clar-proxy_credentials || exit $? kill $(cat "$HOME/sshd/pid") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fbc3d41e5..775f33f2d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -58,6 +58,6 @@ ELSE () ADD_TEST(libgit2_clar "${libgit2_BINARY_DIR}/libgit2_clar" -v -xclone::local::git_style_unc_paths -xclone::local::standard_unc_paths_are_written_git_style) ENDIF () -# Add a test target which runs the cred callback tests, to be -# called after setting the url and user +# Add additional test targets that require special setup ADD_TEST(libgit2_clar-proxy_credentials "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_in_url -sonline::clone::proxy_credentials_request) +ADD_TEST(libgit2_clar-ssh "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths) -- cgit v1.2.1 From 75e1737a5173709b14b669bf08dae78232c6389d Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Fri, 8 Dec 2017 10:10:19 +0000 Subject: hash: openssl: check return values of SHA1_* functions The OpenSSL functions `SHA1_Init`, `SHA1_Update` and `SHA1_Final` all return 1 for success and 0 otherwise, but we never check their return values. Do so. --- src/hash/hash_openssl.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) 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; } -- cgit v1.2.1 From ba56f781a91487ad657e1a72888c914b1cec5de9 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 3 Jan 2018 12:54:42 +0000 Subject: streams: openssl: fix thread-safety for OpenSSL error messages The function `ERR_error_string` can be invoked without providing a buffer, in which case OpenSSL will simply return a string printed into a static buffer. Obviously and as documented in ERR_error_string(3), this is not thread-safe at all. As libgit2 is a library, though, it is easily possible that other threads may be using OpenSSL at the same time, which might lead to clobbered error strings. Fix the issue by instead using a stack-allocated buffer. According to the documentation, the caller has to provide a buffer of at least 256 bytes of size. While we do so, make sure that the buffer will never get overflown by switching to `ERR_error_string_n` to specify the buffer's size. --- src/streams/openssl.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/streams/openssl.c b/src/streams/openssl.c index 2b246002f..133d1416d 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: @@ -640,8 +644,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; -- cgit v1.2.1 From d8896bda5c43616f3c755242703fce7c2a97ad67 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 3 Jan 2018 16:07:36 +0000 Subject: diff_generate: avoid excessive stats of .gitattribute files When generating a diff between two trees, for each file that is to be diffed we have to determine whether it shall be treated as text or as binary files. While git has heuristics to determine which kind of diff to generate, users can also that default behaviour by setting or unsetting the 'diff' attribute for specific files. Because of that, we have to query gitattributes in order to determine how to diff the current files. Instead of hitting the '.gitattributes' file every time we need to query an attribute, which can get expensive especially on networked file systems, we try to cache them instead. This works perfectly fine for every '.gitattributes' file that is found, but we hit cache invalidation problems when we determine that an attribuse file is _not_ existing. We do create an entry in the cache for missing '.gitattributes' files, but as soon as we hit that file again we invalidate it and stat it again to see if it has now appeared. In the case of diffing large trees with each other, this behaviour is very suboptimal. For each pair of files that is to be diffed, we will repeatedly query every directory component leading towards their respective location for an attributes file. This leads to thousands or even hundreds of thousands of wasted syscalls. The attributes cache already has a mechanism to help in that scenario in form of the `git_attr_session`. As long as the same attributes session is still active, we will not try to re-query the gitmodules files at all but simply retain our currently cached results. To fix our problem, we can create a session at the top-most level, which is the initialization of the `git_diff` structure, and use it in order to look up the correct diff driver. As the `git_diff` structure is used to generate patches for multiple files at once, this neatly solves our problem by retaining the session until patches for all files have been generated. The fix has been tested with linux.git by calling `git_diff_tree_to_tree` and `git_diff_to_buf` with v4.10^{tree} and v4.14^{tree}. | time | .gitattributes stats without fix | 33.201s | 844614 with fix | 30.327s | 4441 While execution only improved by roughly 10%, the stat(3) syscalls for .gitattributes files decreased by 99.5%. The benchmarks were quite simple with best-of-three timings on Linux ext4 systems. One can assume that for network based file systems the performance gain will be a lot larger due to a much higher latency. --- src/diff.h | 1 + src/diff_driver.c | 17 ++++++++++------- src/diff_driver.h | 4 +++- src/diff_file.c | 6 ++++-- src/diff_generate.c | 2 ++ 5 files changed, 20 insertions(+), 10 deletions(-) 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); -- cgit v1.2.1 From e7495ce6f4dee156b6a1d48a4d478c83d1053236 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 5 Dec 2017 08:47:57 +0000 Subject: cmake: default to using SHA1DC Upstream git.git has changed their default SHA1 implementation to the collision-detection algorithm SHA1DC in commit e6b07da27 (Makefile: make DC_SHA1 the default, 2017-03-17). To match upstream, align ourselves and switch over to SHA1DC by default. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bedf85819..32f8ac082 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ OPTION( PROFILE "Generate profiling information" OFF ) OPTION( ENABLE_TRACE "Enables tracing support" OFF ) OPTION( LIBGIT2_FILENAME "Name of the produced binary" OFF ) -OPTION( USE_SHA1DC "Use SHA-1 with collision detection" OFF ) +OPTION( USE_SHA1DC "Use SHA-1 with collision detection" ON ) OPTION( USE_SSH "Link with libssh to enable SSH support" ON ) OPTION( USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON ) OPTION( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF ) -- cgit v1.2.1 From 70aa61460a4f33509aa06ed86ac3becc243ee5d6 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 5 Dec 2017 08:48:31 +0000 Subject: cmake: allow explicitly choosing SHA1 backend Right now, if SHA1DC is disabled, the SHA1 backend is mostly chosen based on which system libgit2 is being compiled on and which libraries have been found. To give developers and distributions more choice, enable them to request specific backends by passing in a `-DSHA1_BACKEND=` option instead. This completely replaces the previous auto-selection. --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 46 ++++++++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32f8ac082..48a4d91a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,7 @@ OPTION( PROFILE "Generate profiling information" OFF ) OPTION( ENABLE_TRACE "Enables tracing support" OFF ) OPTION( LIBGIT2_FILENAME "Name of the produced binary" OFF ) -OPTION( USE_SHA1DC "Use SHA-1 with collision detection" ON ) +SET(SHA1_BACKEND "CollisionDetection" CACHE STRING "Backend to use for SHA1. One of Generic, OpenSSL, Win32, CommonCrypto, CollisionDetection. ") OPTION( USE_SSH "Link with libssh to enable SSH support" ON ) OPTION( USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON ) OPTION( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2c82d1f59..76bd6ce24 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -127,10 +127,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 +179,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() @@ -204,34 +202,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() + SET(LIBGIT2_PC_REQUIRES "${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") -- cgit v1.2.1 From 85e40bbf0938cac5668e810864f6be9619b9e60e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sun, 7 Jan 2018 12:51:26 +0000 Subject: cmake: move the rule to find static archives close to building clar If we're building static libraries, we want to use that for building our clar binary. This is done in 49551254 (2017-09-22; cmake: use static dependencies when building static libgit2) but that commit included the rule too early, making it affect the search for iconv, meaning we did not find it when we were building a static libgit2. Move the rule to just before building clar, after we've included the rules for building the library itself. This lets us find and link to the dynamic libiconv. --- CMakeLists.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bedf85819..e6ba74934 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -222,10 +222,6 @@ IF (MSVC) SET(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}") SET(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}") ELSE () - IF (NOT BUILD_SHARED_LIBS) - SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") - ENDIF() - IF (ENABLE_REPRODUCIBLE_BUILDS) SET(CMAKE_C_ARCHIVE_CREATE " Dqc ") SET(CMAKE_C_ARCHIVE_APPEND " Dq ") @@ -304,6 +300,12 @@ ENDIF() ADD_SUBDIRECTORY(src) # Tests +IF (NOT MSVC) + IF (NOT BUILD_SHARED_LIBS) + SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") + ENDIF() +ENDIF () + IF (BUILD_CLAR) ENABLE_TESTING() ADD_SUBDIRECTORY(tests) -- cgit v1.2.1 From b85548edb027474af3d107f9faa004cc09a1863a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 8 Jan 2018 12:30:50 +0000 Subject: cmake: treat LIBGIT2_PC_REQUIRES as a list It is indeed a list of dependencies for those which include the static archive. This is in preparation for adding two possible places where we might add openssl as a dependency. --- src/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c8389c2b8..6bcb0a1c9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -210,7 +210,7 @@ IF(SHA1_BACKEND STREQUAL "OpenSSL") IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") LIST(APPEND LIBGIT2_PC_LIBS "-lssl") ELSE() - SET(LIBGIT2_PC_REQUIRES "${LIBGIT2_PC_REQUIRES} openssl") + LIST(APPEND LIBGIT2_PC_REQUIRES "openssl") ENDIF() ELSEIF(SHA1_BACKEND STREQUAL "CollisionDetection") ADD_FEATURE_INFO(SHA ON "using CollisionDetection") @@ -265,7 +265,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() @@ -439,6 +439,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) -- cgit v1.2.1 From b21c5408ff18eaf99029f59e738f6f614a53c90d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 8 Jan 2018 12:33:07 +0000 Subject: cmake: add openssl to the private deps list when it's the TLS implementation We might want OpenSSL to be the implementation for SHA-1 and/or TLS. If we only want it for TLS (e.g. we're building with the collision-detecting SHA-1 implementation) then we did not indicate this to the systems including us a static library. Add OpenSSL to the list also during the TLS decision to make sure we say we should link to it if we use it for TLS. --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6bcb0a1c9..b03b96af9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -184,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() -- cgit v1.2.1 From 6d452600fa5c351670c9200e7c48f1da1191c5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 10 Jan 2018 11:52:15 +0000 Subject: cmake: use a FEATURE_SUMMARY call compatible with 3.0.2 When we print features, we make an effort to support all the way back to pre-3.0. However, in the code for versions from 3 onward we call `FEATURE_SUMMARY` with multiple kinds of elements to print in the same line. This is only supported in CMake 3.1 and later, making the rather popular CMake 3.0.2 unable to build the library. Use a single kind of element per invocation. This means we need to provide a "description" text, which CMake provides for us if provide multiple kinds of elements. --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d4b31364b..4d5ad9d05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -335,7 +335,8 @@ IF (BUILD_EXAMPLES) ENDIF () IF(CMAKE_VERSION VERSION_GREATER 3) - FEATURE_SUMMARY(WHAT ENABLED_FEATURES DISABLED_FEATURES) + FEATURE_SUMMARY(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:") + FEATURE_SUMMARY(WHAT DISABLED_FEATURES DESCRIPTION "Disabled features:") ELSE() PRINT_ENABLED_FEATURES() PRINT_DISABLED_FEATURES() -- cgit v1.2.1 From da9898aba0fe26ea683822e99853bfb2b02ac744 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 10 Jan 2018 12:33:56 +0000 Subject: travis: fetch trusty dependencies from bintray The trusty dependencies are now hosted on Bintray. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5d687f1ea..117a3acc6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ sudo: false addons: apt: sources: - - sourceline: 'deb http://libgit2deps.edwardthomson.com trusty libgit2deps' + - sourceline: 'deb https://dl.bintray.com/libgit2/ci-dependencies trusty libgit2deps' key_url: 'https://www.edwardthomson.com/keys/ethomson@libgit2.org' packages: cmake -- cgit v1.2.1 From 6e748130e4f910b6f8c03a3f6f2e11c856d19ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Wed, 10 Jan 2018 15:13:23 +0000 Subject: travis: we use bintray's own key for signing The VM on Travis apparently will still proceed, but it's good practice. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 117a3acc6..a4c8e91df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,7 @@ addons: apt: sources: - sourceline: 'deb https://dl.bintray.com/libgit2/ci-dependencies trusty libgit2deps' - key_url: 'https://www.edwardthomson.com/keys/ethomson@libgit2.org' + key_url: 'https://bintray.com/user/downloadSubjectPublicKey?username=bintray' packages: cmake curl -- cgit v1.2.1