From f66e7f36ffba13e5eac5bac965f128c39642c174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20K=C3=BChl?= Date: Thu, 28 Oct 2021 10:25:09 +0200 Subject: libgit2_clar is now libgit2_tests in #6083 the test runner was renamed to libgit2_tests, but not all references to the old name were updated. this change changes all of them to use the new name. --- .vscode/launch.json | 4 ++-- .vscode/tasks.json | 4 ++-- README.md | 6 +++--- cmake/IdeSplitSources.cmake | 2 +- docs/contributing.md | 8 ++++---- fuzzers/corpora/objects/blob | 6 +++--- tests/README.md | 8 ++++---- tests/core/init.c | 2 +- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index d47d93aab..62d4ec949 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}/build/libgit2_clar", + "program": "${workspaceFolder}/build/libgit2_tests", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", @@ -24,4 +24,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 64142d341..24b4d745b 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -16,7 +16,7 @@ { "label": "Run Tests", "type": "shell", - "command": "build/libgit2_clar -v", + "command": "build/libgit2_tests -v", "group": "test", "presentation": { "reveal": "always", @@ -24,4 +24,4 @@ } } ] - } \ No newline at end of file + } diff --git a/README.md b/README.md index ea1c8e29f..2a365df30 100644 --- a/README.md +++ b/README.md @@ -236,18 +236,18 @@ Once built, you can run the tests from the `build` directory with the command Alternatively you can run the test suite directly using, - $ ./libgit2_clar + $ ./libgit2_tests Invoking the test suite directly is useful because it allows you to execute individual tests, or groups of tests using the `-s` flag. For example, to run the index tests: - $ ./libgit2_clar -sindex + $ ./libgit2_tests -sindex To run a single test named `index::racy::diff`, which corresponds to the test function [`test_index_racy__diff`](https://github.com/libgit2/libgit2/blob/main/tests/index/racy.c#L23): - $ ./libgit2_clar -sindex::racy::diff + $ ./libgit2_tests -sindex::racy::diff The test suite will print a `.` for every passing test, and an `F` for any failing test. An `S` indicates that a test was skipped because it is not diff --git a/cmake/IdeSplitSources.cmake b/cmake/IdeSplitSources.cmake index e2e09b4ce..396f18eb4 100644 --- a/cmake/IdeSplitSources.cmake +++ b/cmake/IdeSplitSources.cmake @@ -1,6 +1,6 @@ # This function splits the sources files up into their appropriate # subdirectories. This is especially useful for IDEs like Xcode and -# Visual Studio, so that you can navigate into the libgit2_clar project, +# Visual Studio, so that you can navigate into the libgit2_tests project, # and see the folders within the tests folder (instead of just seeing all # source and tests in a single folder.) FUNCTION(IDE_SPLIT_SOURCES target) diff --git a/docs/contributing.md b/docs/contributing.md index f3e559c9d..03e001709 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -120,15 +120,15 @@ In addition to new tests, please ensure that your changes do not cause any other test failures. Running the entire test suite is helpful before you submit a pull request. When you build libgit2, the test suite will also be built. You can run most of the tests by simply running -the resultant `libgit2_clar` binary. If you want to run a specific +the resultant `libgit2_tests` binary. If you want to run a specific unit test, you can name it with the `-s` option. For example: - libgit2_clar -sstatus::worktree::long_filenames + libgit2_tests -sstatus::worktree::long_filenames Or you can run an entire class of tests. For example, to run all the worktree status tests: - libgit2_clar -sstatus::worktree + libgit2_tests -sstatus::worktree The default test run is fairly exhaustive, but it will exclude some unit tests by default: in particular, those that talk to network @@ -136,7 +136,7 @@ servers and the tests that manipulate the filesystem in onerous ways (and may need to have special privileges to run). To run the network tests: - libgit2_clar -ionline + libgit2_tests -ionline In addition, various tests may be enabled by environment variables, like the ones that write exceptionally large repositories or manipulate diff --git a/fuzzers/corpora/objects/blob b/fuzzers/corpora/objects/blob index 2031037b1..b09444c80 100644 --- a/fuzzers/corpora/objects/blob +++ b/fuzzers/corpora/objects/blob @@ -187,18 +187,18 @@ Once built, you can run the tests from the `build` directory with the command Alternatively you can run the test suite directly using, - $ ./libgit2_clar + $ ./libgit2_tests Invoking the test suite directly is useful because it allows you to execute individual tests, or groups of tests using the `-s` flag. For example, to run the index tests: - $ ./libgit2_clar -sindex + $ ./libgit2_tests -sindex To run a single test named `index::racy::diff`, which corresponds to the test function (`test_index_racy__diff`)[https://github.com/libgit2/libgit2/blob/master/tests/index/racy.c#L23]: - $ ./libgit2_clar -sindex::racy::diff + $ ./libgit2_tests -sindex::racy::diff The test suite will print a `.` for every passing test, and an `F` for any failing test. An `S` indicates that a test was skipped because it is not diff --git a/tests/README.md b/tests/README.md index 7684a6e64..4369a8f33 100644 --- a/tests/README.md +++ b/tests/README.md @@ -15,7 +15,7 @@ https://github.com/vmg/clar * Test: - ./build/libgit2_clar + ./build/libgit2_tests * Make sure everything is fine. @@ -34,8 +34,8 @@ Uses [`valgrind`](http://www.valgrind.org/): ```console $ cmake -DBUILD_TESTS=ON -DVALGRIND=ON .. $ cmake --build . -$ valgrind --leak-check=full --show-reachable=yes --num-callers=50 --suppressions=../libgit2_clar.supp \ - ./libgit2_clar +$ valgrind --leak-check=full --show-reachable=yes --num-callers=50 --suppressions=../libgit2_tests.supp \ + ./libgit2_tests ``` #### macOS @@ -44,5 +44,5 @@ Uses [`leaks`](https://developer.apple.com/library/archive/documentation/Perform ```console $ MallocStackLogging=1 MallocScribble=1 MallocLogFile=/dev/null CLAR_AT_EXIT="leaks -quiet \$PPID" \ - ./libgit2_clar + ./libgit2_tests ``` diff --git a/tests/core/init.c b/tests/core/init.c index a8cbd930b..eba77ef52 100644 --- a/tests/core/init.c +++ b/tests/core/init.c @@ -2,7 +2,7 @@ void test_core_init__returns_count(void) { - /* libgit2_clar initializes us first, so we have an existing + /* libgit2_tests initializes us first, so we have an existing * initialization. */ cl_assert_equal_i(2, git_libgit2_init()); -- cgit v1.2.1 From 3993e9aebc7d293e9aec420800c581f7f234def7 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Mon, 8 Nov 2021 14:00:09 +0100 Subject: Update documentation for ODB backend refresh logic Commit b1a6c316a6070fac4ab1ec5792979838f7145c39 moved auto-refresh into the pack backend, and added a comment accordingly. Commit 43820f204ea32503b4083e3b6b83f30a0a0031c9 moved auto-refresh back *out* of backends into the ODB layer, but didn't update the comment. --- include/git2/sys/odb_backend.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/git2/sys/odb_backend.h b/include/git2/sys/odb_backend.h index 9ae0ed9b3..8598f94e5 100644 --- a/include/git2/sys/odb_backend.h +++ b/include/git2/sys/odb_backend.h @@ -69,11 +69,8 @@ struct git_odb_backend { * If the backend implements a refreshing mechanism, it should be exposed * through this endpoint. Each call to `git_odb_refresh()` will invoke it. * - * However, the backend implementation should try to stay up-to-date as much - * as possible by itself as libgit2 will not automatically invoke - * `git_odb_refresh()`. For instance, a potential strategy for the backend - * implementation to achieve this could be to internally invoke this - * endpoint on failed lookups (ie. `exists()`, `read()`, `read_header()`). + * The odb layer will automatically call this when needed on failed + * lookups (ie. `exists()`, `read()`, `read_header()`). */ int GIT_CALLBACK(refresh)(git_odb_backend *); -- cgit v1.2.1 From 81662d432c585df651a9f733670ac577f6b555a5 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Mon, 8 Nov 2021 14:48:45 +0100 Subject: Support checking for object existence without refresh Looking up a non-existent object currently always invokes `git_odb_refresh`. If looking up a large batch of objects, many of which may legitimately not exist, this will repeatedly refresh the ODB to no avail. Add a `git_odb_exists_ext` that accepts flags controlling the ODB lookup, and add a flag to suppress the refresh. This allows the user to control if and when they refresh (for instance, refreshing once before starting the batch). --- include/git2/odb.h | 22 ++++++++++++++++++++++ src/odb.c | 7 ++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/git2/odb.h b/include/git2/odb.h index dd484553f..6c86cd625 100644 --- a/include/git2/odb.h +++ b/include/git2/odb.h @@ -22,6 +22,17 @@ */ GIT_BEGIN_DECL +/** Flags controlling the behavior of ODB lookup operations */ +typedef enum { + /** + * Don't call `git_odb_refresh` if the lookup fails. Useful when doing + * a batch of lookup operations for objects that may legitimately not + * exist. When using this flag, you may wish to manually call + * `git_odb_refresh` before processing a batch of objects. + */ + GIT_ODB_LOOKUP_NO_REFRESH = (1 << 0), +} git_odb_lookup_flags_t; + /** * Function type for callbacks from git_odb_foreach. */ @@ -155,6 +166,17 @@ GIT_EXTERN(int) git_odb_read_header(size_t *len_out, git_object_t *type_out, git */ GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id); +/** + * Determine if the given object can be found in the object database, with + * extended options. + * + * @param db database to be searched for the given object. + * @param id the object to search for. + * @param flags flags affecting the lookup (see `git_odb_lookup_flags_t`) + * @return 1 if the object was found, 0 otherwise + */ +GIT_EXTERN(int) git_odb_exists_ext(git_odb *db, const git_oid *id, unsigned int flags); + /** * Determine if an object can be found in the object database by an * abbreviated object ID. diff --git a/src/odb.c b/src/odb.c index 7bf575474..79328672b 100644 --- a/src/odb.c +++ b/src/odb.c @@ -882,6 +882,11 @@ int git_odb__freshen(git_odb *db, const git_oid *id) } int git_odb_exists(git_odb *db, const git_oid *id) +{ + return git_odb_exists_ext(db, id, 0); +} + +int git_odb_exists_ext(git_odb *db, const git_oid *id, unsigned int flags) { git_odb_object *object; @@ -899,7 +904,7 @@ int git_odb_exists(git_odb *db, const git_oid *id) if (odb_exists_1(db, id, false)) return 1; - if (!git_odb_refresh(db)) + if (!(flags & GIT_ODB_LOOKUP_NO_REFRESH) && !git_odb_refresh(db)) return odb_exists_1(db, id, true); /* Failed to refresh, hence not found */ -- cgit v1.2.1 From 94cb060c37269485470fb11b7b7207ccf4f9b784 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Mon, 8 Nov 2021 14:54:09 +0100 Subject: Add tests for ODB refresh Add optional refreshing in the fake backend, and count the number of refresh calls if enabled. --- tests/odb/backend/backend_helpers.c | 17 +++- tests/odb/backend/backend_helpers.h | 4 +- tests/odb/backend/multiple.c | 4 +- tests/odb/backend/nonrefreshing.c | 2 +- tests/odb/backend/refreshing.c | 176 ++++++++++++++++++++++++++++++++++++ tests/odb/backend/simple.c | 2 +- 6 files changed, 198 insertions(+), 7 deletions(-) create mode 100644 tests/odb/backend/refreshing.c diff --git a/tests/odb/backend/backend_helpers.c b/tests/odb/backend/backend_helpers.c index 139d2fc72..542799242 100644 --- a/tests/odb/backend/backend_helpers.c +++ b/tests/odb/backend/backend_helpers.c @@ -123,6 +123,18 @@ static int fake_backend__read_prefix( return 0; } +static int fake_backend__refresh(git_odb_backend *backend) +{ + fake_backend *fake; + + fake = (fake_backend *)backend; + + fake->refresh_calls++; + + return 0; +} + + static void fake_backend__free(git_odb_backend *_backend) { fake_backend *backend; @@ -134,7 +146,8 @@ static void fake_backend__free(git_odb_backend *_backend) int build_fake_backend( git_odb_backend **out, - const fake_object *objects) + const fake_object *objects, + bool support_refresh) { fake_backend *backend; @@ -143,12 +156,12 @@ int build_fake_backend( backend->parent.version = GIT_ODB_BACKEND_VERSION; - backend->parent.refresh = NULL; backend->objects = objects; backend->parent.read = fake_backend__read; backend->parent.read_prefix = fake_backend__read_prefix; backend->parent.read_header = fake_backend__read_header; + backend->parent.refresh = support_refresh ? fake_backend__refresh : NULL; backend->parent.exists = fake_backend__exists; backend->parent.exists_prefix = fake_backend__exists_prefix; backend->parent.free = &fake_backend__free; diff --git a/tests/odb/backend/backend_helpers.h b/tests/odb/backend/backend_helpers.h index 5c393c0a5..32d7a8bf0 100644 --- a/tests/odb/backend/backend_helpers.h +++ b/tests/odb/backend/backend_helpers.h @@ -13,10 +13,12 @@ typedef struct { int read_calls; int read_header_calls; int read_prefix_calls; + int refresh_calls; const fake_object *objects; } fake_backend; int build_fake_backend( git_odb_backend **out, - const fake_object *objects); + const fake_object *objects, + bool support_refresh); diff --git a/tests/odb/backend/multiple.c b/tests/odb/backend/multiple.c index 1c6068df3..5f1eacd52 100644 --- a/tests/odb/backend/multiple.c +++ b/tests/odb/backend/multiple.c @@ -29,10 +29,10 @@ void test_odb_backend_multiple__initialize(void) _obj = NULL; _repo = cl_git_sandbox_init("testrepo.git"); - cl_git_pass(build_fake_backend(&backend, _objects_filled)); + cl_git_pass(build_fake_backend(&backend, _objects_filled, false)); _fake_filled = (fake_backend *)backend; - cl_git_pass(build_fake_backend(&backend, _objects_empty)); + cl_git_pass(build_fake_backend(&backend, _objects_empty, false)); _fake_empty = (fake_backend *)backend; } diff --git a/tests/odb/backend/nonrefreshing.c b/tests/odb/backend/nonrefreshing.c index ede48ade6..2db10efbc 100644 --- a/tests/odb/backend/nonrefreshing.c +++ b/tests/odb/backend/nonrefreshing.c @@ -23,7 +23,7 @@ static void setup_repository_and_backend(void) _repo = cl_git_sandbox_init("testrepo.git"); - cl_git_pass(build_fake_backend(&backend, _objects)); + cl_git_pass(build_fake_backend(&backend, _objects, false)); cl_git_pass(git_repository_odb__weakptr(&odb, _repo)); cl_git_pass(git_odb_add_backend(odb, backend, 10)); diff --git a/tests/odb/backend/refreshing.c b/tests/odb/backend/refreshing.c new file mode 100644 index 000000000..9e49298a8 --- /dev/null +++ b/tests/odb/backend/refreshing.c @@ -0,0 +1,176 @@ +#include "clar_libgit2.h" +#include "repository.h" +#include "backend_helpers.h" + +static git_repository *_repo; +static fake_backend *_fake; + +#define NONEXISTING_HASH "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef" +#define EXISTING_HASH "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" + +static const fake_object _objects[] = { + { EXISTING_HASH, "" }, + { NULL, NULL } +}; + +static git_oid _nonexisting_oid; +static git_oid _existing_oid; + +static void setup_repository_and_backend(void) +{ + git_odb *odb = NULL; + git_odb_backend *backend = NULL; + + _repo = cl_git_sandbox_init("testrepo.git"); + + cl_git_pass(build_fake_backend(&backend, _objects, true)); + + cl_git_pass(git_repository_odb__weakptr(&odb, _repo)); + cl_git_pass(git_odb_add_backend(odb, backend, 10)); + + _fake = (fake_backend *)backend; +} + +void test_odb_backend_refreshing__initialize(void) +{ + git_oid_fromstr(&_nonexisting_oid, NONEXISTING_HASH); + git_oid_fromstr(&_existing_oid, EXISTING_HASH); + setup_repository_and_backend(); +} + +void test_odb_backend_refreshing__cleanup(void) +{ + cl_git_sandbox_cleanup(); +} + +void test_odb_backend_refreshing__exists_is_invoked_twice_on_failure(void) +{ + git_odb *odb; + + cl_git_pass(git_repository_odb__weakptr(&odb, _repo)); + cl_assert_equal_b(false, git_odb_exists(odb, &_nonexisting_oid)); + + cl_assert_equal_i(2, _fake->exists_calls); + cl_assert_equal_i(1, _fake->refresh_calls); +} + +void test_odb_backend_refreshing__read_is_invoked_twice_on_failure(void) +{ + git_object *obj; + + cl_git_fail_with( + git_object_lookup(&obj, _repo, &_nonexisting_oid, GIT_OBJECT_ANY), + GIT_ENOTFOUND); + + cl_assert_equal_i(2, _fake->read_calls); + cl_assert_equal_i(1, _fake->refresh_calls); +} + +void test_odb_backend_refreshing__readprefix_is_invoked_twice_on_failure(void) +{ + git_object *obj; + + cl_git_fail_with( + git_object_lookup_prefix(&obj, _repo, &_nonexisting_oid, 7, GIT_OBJECT_ANY), + GIT_ENOTFOUND); + + cl_assert_equal_i(2, _fake->read_prefix_calls); + cl_assert_equal_i(1, _fake->refresh_calls); +} + +void test_odb_backend_refreshing__readheader_is_invoked_twice_on_failure(void) +{ + git_odb *odb; + size_t len; + git_object_t type; + + cl_git_pass(git_repository_odb__weakptr(&odb, _repo)); + + cl_git_fail_with( + git_odb_read_header(&len, &type, odb, &_nonexisting_oid), + GIT_ENOTFOUND); + + cl_assert_equal_i(2, _fake->read_header_calls); + cl_assert_equal_i(1, _fake->refresh_calls); +} + +void test_odb_backend_refreshing__exists_is_invoked_once_on_success(void) +{ + git_odb *odb; + + cl_git_pass(git_repository_odb__weakptr(&odb, _repo)); + cl_assert_equal_b(true, git_odb_exists(odb, &_existing_oid)); + + cl_assert_equal_i(1, _fake->exists_calls); + cl_assert_equal_i(0, _fake->refresh_calls); +} + +void test_odb_backend_refreshing__read_is_invoked_once_on_success(void) +{ + git_object *obj; + + cl_git_pass(git_object_lookup(&obj, _repo, &_existing_oid, GIT_OBJECT_ANY)); + + cl_assert_equal_i(1, _fake->read_calls); + cl_assert_equal_i(0, _fake->refresh_calls); + + git_object_free(obj); +} + +void test_odb_backend_refreshing__readprefix_is_invoked_once_on_success(void) +{ + git_object *obj; + + cl_git_pass(git_object_lookup_prefix(&obj, _repo, &_existing_oid, 7, GIT_OBJECT_ANY)); + + cl_assert_equal_i(1, _fake->read_prefix_calls); + cl_assert_equal_i(0, _fake->refresh_calls); + + git_object_free(obj); +} + +void test_odb_backend_refreshing__readheader_is_invoked_once_on_success(void) +{ + git_odb *odb; + size_t len; + git_object_t type; + + cl_git_pass(git_repository_odb__weakptr(&odb, _repo)); + + cl_git_pass(git_odb_read_header(&len, &type, odb, &_existing_oid)); + + cl_assert_equal_i(1, _fake->read_header_calls); + cl_assert_equal_i(0, _fake->refresh_calls); +} + +void test_odb_backend_refreshing__read_is_invoked_twice_when_revparsing_a_full_oid(void) +{ + git_object *obj; + + cl_git_fail_with( + git_revparse_single(&obj, _repo, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"), + GIT_ENOTFOUND); + + cl_assert_equal_i(2, _fake->read_calls); + cl_assert_equal_i(1, _fake->refresh_calls); +} + +void test_odb_backend_refreshing__refresh_is_invoked(void) +{ + git_odb *odb; + + cl_git_pass(git_repository_odb__weakptr(&odb, _repo)); + cl_assert_equal_i(0, git_odb_refresh(odb)); + + cl_assert_equal_i(1, _fake->refresh_calls); +} + +void test_odb_backend_refreshing__refresh_suppressed_with_no_refresh(void) +{ + git_odb *odb; + + cl_git_pass(git_repository_odb__weakptr(&odb, _repo)); + cl_assert_equal_b(false, git_odb_exists_ext(odb, &_nonexisting_oid, GIT_ODB_LOOKUP_NO_REFRESH)); + + cl_assert_equal_i(0, _fake->refresh_calls); +} diff --git a/tests/odb/backend/simple.c b/tests/odb/backend/simple.c index 484dcba5a..6c9293ac0 100644 --- a/tests/odb/backend/simple.c +++ b/tests/odb/backend/simple.c @@ -13,7 +13,7 @@ static void setup_backend(const fake_object *objs) { git_odb_backend *backend; - cl_git_pass(build_fake_backend(&backend, objs)); + cl_git_pass(build_fake_backend(&backend, objs, false)); cl_git_pass(git_repository_odb__weakptr(&_odb, _repo)); cl_git_pass(git_odb_add_backend(_odb, backend, 10)); -- cgit v1.2.1 From f45ff6c92d8d27ff0c3eb007267eadb4aeeaf16f Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Mon, 8 Nov 2021 17:33:35 +0100 Subject: Omit trailing comma on enum To accommodate less capable compilers. Co-authored-by: Peter Pettersson <85582231+boretrk@users.noreply.github.com> --- include/git2/odb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/git2/odb.h b/include/git2/odb.h index 6c86cd625..0691aa4d0 100644 --- a/include/git2/odb.h +++ b/include/git2/odb.h @@ -30,7 +30,7 @@ typedef enum { * exist. When using this flag, you may wish to manually call * `git_odb_refresh` before processing a batch of objects. */ - GIT_ODB_LOOKUP_NO_REFRESH = (1 << 0), + GIT_ODB_LOOKUP_NO_REFRESH = (1 << 0) } git_odb_lookup_flags_t; /** -- cgit v1.2.1 From 51f6f15d710c39c6844ceef58efea6db93c46d61 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Tue, 9 Nov 2021 09:03:06 -0500 Subject: ci: only update docs on push Only update the documentation on a `push`. We were previously updating the documentation only when not in a `pull_request`, which meant that we would push documentation updates in manual build triggers. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 572f02544..e805b1bb8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -300,4 +300,4 @@ jobs: - name: Push documentation branch working-directory: source run: git push origin gh-pages - if: github.event_name != 'pull_request' && github.repository == 'libgit2/libgit2' + if: github.event_name == 'push' && github.repository == 'libgit2/libgit2' -- cgit v1.2.1 From 95117d4744cf5a66f2bcde7991a925e9852d9b1e Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sun, 31 Oct 2021 09:45:46 -0400 Subject: path: separate git-specific path functions from util Introduce `git_fs_path`, which operates on generic filesystem paths. `git_path` will be kept for only git-specific path functionality (for example, checking for `.git` in a path). --- fuzzers/standalone_driver.c | 2 +- src/attr.c | 8 +- src/attr_file.c | 6 +- src/attrcache.c | 8 +- src/blob.c | 4 +- src/checkout.c | 25 +- src/clone.c | 16 +- src/config.c | 2 +- src/config_file.c | 22 +- src/diff_generate.c | 4 +- src/diff_stats.c | 2 +- src/diff_tform.c | 4 +- src/filebuf.c | 14 +- src/filter.c | 4 +- src/fs_path.c | 1839 ++++++++++++++++++++++++++++++++++ src/fs_path.h | 728 ++++++++++++++ src/futils.c | 50 +- src/futils.h | 2 +- src/ignore.c | 22 +- src/index.c | 9 +- src/iterator.c | 29 +- src/mailmap.c | 6 +- src/merge.c | 2 +- src/midx.c | 8 +- src/odb.c | 4 +- src/odb_loose.c | 20 +- src/odb_pack.c | 6 +- src/pack.c | 2 +- src/patch_parse.c | 4 +- src/path.c | 1867 ++--------------------------------- src/path.h | 723 +------------- src/posix.c | 6 +- src/rebase.c | 8 +- src/refdb_fs.c | 43 +- src/refs.c | 8 +- src/repository.c | 118 +-- src/submodule.c | 37 +- src/sysdir.c | 4 +- src/transport.c | 6 +- src/transports/local.c | 6 +- src/tree.c | 11 +- src/win32/findfile.c | 2 +- src/win32/path_w32.c | 14 +- src/win32/posix_w32.c | 10 +- src/worktree.c | 48 +- tests/attr/repo.c | 2 +- tests/checkout/conflict.c | 24 +- tests/checkout/crlf.c | 18 +- tests/checkout/head.c | 24 +- tests/checkout/icase.c | 22 +- tests/checkout/index.c | 62 +- tests/checkout/nasty.c | 6 +- tests/checkout/tree.c | 192 ++-- tests/checkout/typechange.c | 34 +- tests/cherrypick/workdir.c | 18 +- tests/clar_libgit2.c | 20 +- tests/clone/nonetwork.c | 16 +- tests/config/global.c | 8 +- tests/config/read.c | 8 +- tests/config/readonly.c | 10 +- tests/config/stress.c | 6 +- tests/core/copy.c | 80 +- tests/core/dirent.c | 48 +- tests/core/env.c | 6 +- tests/core/filebuf.c | 24 +- tests/core/futils.c | 6 +- tests/core/iconv.c | 20 +- tests/core/mkdir.c | 108 +- tests/core/path.c | 98 +- tests/core/posix.c | 12 +- tests/core/rmdir.c | 26 +- tests/core/stat.c | 2 +- tests/diff/drivers.c | 2 +- tests/diff/workdir.c | 10 +- tests/fetchhead/nonetwork.c | 8 +- tests/ignore/path.c | 4 +- tests/index/crlf.c | 16 +- tests/index/tests.c | 4 +- tests/iterator/index.c | 2 +- tests/iterator/workdir.c | 2 +- tests/merge/merge_helpers.c | 2 +- tests/merge/workdir/setup.c | 178 ++-- tests/merge/workdir/simple.c | 2 +- tests/object/blob/write.c | 4 +- tests/object/raw/write.c | 4 +- tests/odb/alternates.c | 2 +- tests/odb/emptyobjects.c | 2 +- tests/online/clone.c | 6 +- tests/online/customcert.c | 4 +- tests/pack/indexer.c | 2 +- tests/pack/packbuilder.c | 4 +- tests/path/core.c | 384 +++---- tests/path/dotgit.c | 86 ++ tests/refs/branches/create.c | 2 +- tests/refs/branches/delete.c | 8 +- tests/refs/delete.c | 4 +- tests/refs/pack.c | 4 +- tests/refs/ref_helpers.c | 2 +- tests/refs/reflog/reflog.c | 18 +- tests/refs/rename.c | 12 +- tests/refs/revparse.c | 4 +- tests/repo/config.c | 22 +- tests/repo/discover.c | 6 +- tests/repo/env.c | 10 +- tests/repo/init.c | 26 +- tests/repo/open.c | 10 +- tests/repo/setters.c | 2 +- tests/repo/template.c | 6 +- tests/reset/hard.c | 12 +- tests/revert/workdir.c | 10 +- tests/stash/drop.c | 14 +- tests/stash/save.c | 20 +- tests/status/submodules.c | 12 +- tests/status/worktree.c | 10 +- tests/submodule/add.c | 16 +- tests/submodule/init.c | 6 +- tests/submodule/open.c | 10 +- tests/submodule/repository_init.c | 8 +- tests/submodule/submodule_helpers.c | 2 +- tests/worktree/merge.c | 2 +- tests/worktree/refs.c | 4 +- tests/worktree/submodule.c | 2 +- tests/worktree/worktree.c | 14 +- 123 files changed, 3894 insertions(+), 3775 deletions(-) create mode 100644 src/fs_path.c create mode 100644 src/fs_path.h diff --git a/fuzzers/standalone_driver.c b/fuzzers/standalone_driver.c index 88c8cfbda..c29102e65 100644 --- a/fuzzers/standalone_driver.c +++ b/fuzzers/standalone_driver.c @@ -52,7 +52,7 @@ int main(int argc, char **argv) fprintf(stderr, "Running %s against %s\n", argv[0], argv[1]); LLVMFuzzerInitialize(&argc, &argv); - if (git_path_dirload(&corpus_files, argv[1], 0, 0x0) < 0) { + if (git_fs_path_dirload(&corpus_files, argv[1], 0, 0x0) < 0) { fprintf(stderr, "Failed to scan corpus directory '%s': %s\n", argv[1], git_error_last()->message); error = -1; diff --git a/src/attr.c b/src/attr.c index 5849e701f..409c30b01 100644 --- a/src/attr.c +++ b/src/attr.c @@ -629,7 +629,7 @@ static int collect_attr_files( const char *workdir = git_repository_workdir(repo); attr_walk_up_info info = { NULL }; - GIT_ASSERT(!git_path_is_absolute(path)); + GIT_ASSERT(!git_fs_path_is_absolute(path)); if ((error = attr_setup(repo, attr_session, opts)) < 0) return error; @@ -637,10 +637,10 @@ static int collect_attr_files( /* Resolve path in a non-bare repo */ if (workdir != NULL) { if (!(error = git_repository_workdir_path(&dir, repo, path))) - error = git_path_find_dir(&dir); + error = git_fs_path_find_dir(&dir); } else { - error = git_path_dirname_r(&dir, path); + error = git_fs_path_dirname_r(&dir, path); } if (error < 0) @@ -670,7 +670,7 @@ static int collect_attr_files( if (!strcmp(dir.ptr, ".")) error = push_one_attr(&info, ""); else - error = git_path_walk_up(&dir, workdir, push_one_attr, &info); + error = git_fs_path_walk_up(&dir, workdir, push_one_attr, &info); if (error < 0) goto cleanup; diff --git a/src/attr_file.c b/src/attr_file.c index 09f0ce1b8..0eb881a9b 100644 --- a/src/attr_file.c +++ b/src/attr_file.c @@ -345,7 +345,7 @@ int git_attr_file__parse_buffer( int error = 0; /* If subdir file path, convert context for file paths */ - if (attrs->entry && git_path_root(attrs->entry->path) < 0 && + if (attrs->entry && git_fs_path_root(attrs->entry->path) < 0 && !git__suffixcmp(attrs->entry->path, "/" GIT_ATTR_FILE)) context = attrs->entry->path; @@ -560,7 +560,7 @@ int git_attr_path__init( /* build full path as best we can */ git_str_init(&info->full, 0); - if (git_path_join_unrooted(&info->full, path, base, &root) < 0) + if (git_fs_path_join_unrooted(&info->full, path, base, &root) < 0) return -1; info->path = info->full.ptr + root; @@ -596,7 +596,7 @@ int git_attr_path__init( case GIT_DIR_FLAG_UNKNOWN: default: - info->is_dir = (int)git_path_isdir(info->full.ptr); + info->is_dir = (int)git_fs_path_isdir(info->full.ptr); break; } diff --git a/src/attrcache.c b/src/attrcache.c index 98d73cbc3..15c7fab48 100644 --- a/src/attrcache.c +++ b/src/attrcache.c @@ -47,7 +47,7 @@ int git_attr_cache__alloc_file_entry( size_t cachesize = sizeof(git_attr_file_entry) + pathlen + 1; git_attr_file_entry *ce; - if (base != NULL && git_path_root(path) < 0) { + if (base != NULL && git_fs_path_root(path) < 0) { baselen = strlen(base); cachesize += baselen; @@ -66,7 +66,7 @@ int git_attr_cache__alloc_file_entry( } memcpy(&ce->fullpath[baselen], path, pathlen); - if (git_path_validate_workdir_with_len(repo, ce->fullpath, pathlen + baselen) < 0) + if (git_fs_path_validate_workdir_with_len(repo, ce->fullpath, pathlen + baselen) < 0) return -1; ce->path = &ce->fullpath[baselen]; @@ -169,11 +169,11 @@ static int attr_cache_lookup( git_attr_file *file = NULL; /* join base and path as needed */ - if (source->base != NULL && git_path_root(source->filename) < 0) { + if (source->base != NULL && git_fs_path_root(source->filename) < 0) { git_str *p = attr_session ? &attr_session->tmp : &path; if (git_str_joinpath(p, source->base, source->filename) < 0 || - git_path_validate_workdir_buf(repo, p) < 0) + git_fs_path_validate_workdir_buf(repo, p) < 0) return -1; filename = p->ptr; diff --git a/src/blob.c b/src/blob.c index 6f57d09e4..65841ab03 100644 --- a/src/blob.c +++ b/src/blob.c @@ -205,7 +205,7 @@ int git_blob__create_from_paths( content_path = path.ptr; } - if ((error = git_path_lstat(content_path, &st)) < 0 || + if ((error = git_fs_path_lstat(content_path, &st)) < 0 || (error = git_repository_odb(&odb, repo)) < 0) goto done; @@ -280,7 +280,7 @@ int git_blob_create_from_disk( git_str full_path = GIT_STR_INIT; const char *workdir, *hintpath = NULL; - if ((error = git_path_prettify(&full_path, path, NULL)) < 0) { + if ((error = git_fs_path_prettify(&full_path, path, NULL)) < 0) { git_str_dispose(&full_path); return error; } diff --git a/src/checkout.c b/src/checkout.c index b31918fc8..96ba4da38 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -27,10 +27,11 @@ #include "diff_generate.h" #include "pathspec.h" #include "diff_xdiff.h" -#include "path.h" +#include "fs_path.h" #include "attr.h" #include "pool.h" #include "strmap.h" +#include "path.h" /* See docs/checkout-internals.md for more information */ @@ -328,7 +329,7 @@ static int checkout_target_fullpath( if (path && git_str_puts(&data->target_path, path) < 0) return -1; - if (git_path_validate_workdir_buf(data->repo, &data->target_path) < 0) + if (git_fs_path_validate_workdir_buf(data->repo, &data->target_path) < 0) return -1; *out = &data->target_path; @@ -347,7 +348,7 @@ static bool wd_item_is_removable( if (checkout_target_fullpath(&full, data, wd->path) < 0) return false; - return !full || !git_path_contains(full, DOT_GIT); + return !full || !git_fs_path_contains(full, DOT_GIT); } static int checkout_queue_remove(checkout_data *data, const char *path) @@ -481,7 +482,7 @@ static bool checkout_is_empty_dir(checkout_data *data, const char *path) if (checkout_target_fullpath(&fullpath, data, path) < 0) return false; - return git_path_is_empty_dir(fullpath->ptr); + return git_fs_path_is_empty_dir(fullpath->ptr); } static int checkout_action_with_wd( @@ -1201,12 +1202,12 @@ static int checkout_conflicts_mark_directoryfile( goto done; } - prefixed = git_path_equal_or_prefixed(path, entry->path, NULL); + prefixed = git_fs_path_equal_or_prefixed(path, entry->path, NULL); - if (prefixed == GIT_PATH_EQUAL) + if (prefixed == GIT_FS_PATH_EQUAL) continue; - if (prefixed == GIT_PATH_PREFIX) + if (prefixed == GIT_FS_PATH_PREFIX) conflict->directoryfile = 1; break; @@ -1949,7 +1950,7 @@ static int checkout_path_suffixed(git_str *path, const char *suffix) path_len = git_str_len(path); - while (git_path_exists(git_str_cstr(path)) && i < INT_MAX) { + while (git_fs_path_exists(git_str_cstr(path)) && i < INT_MAX) { git_str_truncate(path, path_len); if ((error = git_str_putc(path, '_')) < 0 || @@ -2034,7 +2035,7 @@ static int checkout_merge_path( int error = 0; if ((error = git_str_joinpath(out, data->opts.target_directory, result->path)) < 0 || - (error = git_path_validate_workdir_buf(data->repo, out)) < 0) + (error = git_fs_path_validate_workdir_buf(data->repo, out)) < 0) return error; /* Most conflicts simply use the filename in the index */ @@ -2337,10 +2338,10 @@ static int validate_target_directory(checkout_data *data) { int error; - if ((error = git_path_validate_workdir(data->repo, data->opts.target_directory)) < 0) + if ((error = git_fs_path_validate_workdir(data->repo, data->opts.target_directory)) < 0) return error; - if (git_path_isdir(data->opts.target_directory)) + if (git_fs_path_isdir(data->opts.target_directory)) return 0; error = checkout_mkdir(data, data->opts.target_directory, NULL, @@ -2507,7 +2508,7 @@ static int checkout_data_init( (error = git_vector_init(&data->remove_conflicts, 0, NULL)) < 0 || (error = git_vector_init(&data->update_conflicts, 0, NULL)) < 0 || (error = git_str_puts(&data->target_path, data->opts.target_directory)) < 0 || - (error = git_path_to_dir(&data->target_path)) < 0 || + (error = git_fs_path_to_dir(&data->target_path)) < 0 || (error = git_strmap_new(&data->mkdir_map)) < 0) goto cleanup; diff --git a/src/clone.c b/src/clone.c index cf4cc3c7f..1843875f8 100644 --- a/src/clone.c +++ b/src/clone.c @@ -19,7 +19,7 @@ #include "remote.h" #include "futils.h" #include "refs.h" -#include "path.h" +#include "fs_path.h" #include "repository.h" #include "odb.h" @@ -333,7 +333,7 @@ static int create_and_configure_origin( void *payload = options->remote_cb_payload; /* If the path exists and is a dir, the url should be the absolute path */ - if (git_path_root(url) < 0 && git_path_exists(url) && git_path_isdir(url)) { + if (git_fs_path_root(url) < 0 && git_fs_path_exists(url) && git_fs_path_isdir(url)) { if (p_realpath(url, buf) == NULL) return -1; @@ -433,8 +433,8 @@ int git_clone__should_clone_local(const char *url_or_path, git_clone_local_t loc if (local == GIT_CLONE_NO_LOCAL) return 0; - if ((is_url = git_path_is_local_file_url(url_or_path)) != 0) { - if (git_path_fromurl(&fromurl, url_or_path) < 0) { + if ((is_url = git_fs_path_is_local_file_url(url_or_path)) != 0) { + if (git_fs_path_fromurl(&fromurl, url_or_path) < 0) { is_local = -1; goto done; } @@ -443,7 +443,7 @@ int git_clone__should_clone_local(const char *url_or_path, git_clone_local_t loc } is_local = (!is_url || local != GIT_CLONE_LOCAL_AUTO) && - git_path_isdir(path); + git_fs_path_isdir(path); done: git_str_dispose(&fromurl); @@ -474,14 +474,14 @@ static int git__clone( GIT_ERROR_CHECK_VERSION(&options, GIT_CLONE_OPTIONS_VERSION, "git_clone_options"); /* Only clone to a new directory or an empty directory */ - if (git_path_exists(local_path) && !use_existing && !git_path_is_empty_dir(local_path)) { + if (git_fs_path_exists(local_path) && !use_existing && !git_fs_path_is_empty_dir(local_path)) { git_error_set(GIT_ERROR_INVALID, "'%s' exists and is not an empty directory", local_path); return GIT_EEXISTS; } /* Only remove the root directory on failure if we create it */ - if (git_path_exists(local_path)) + if (git_fs_path_exists(local_path)) rmdir_flags |= GIT_RMDIR_SKIP_ROOT; if (options.repository_cb) @@ -602,7 +602,7 @@ static int clone_local_into(git_repository *repo, git_remote *remote, const git_ * repo, if it's not rooted, the path should be relative to * the repository's worktree/gitdir. */ - if ((error = git_path_from_url_or_path(&src_path, git_remote_url(remote))) < 0) + if ((error = git_fs_path_from_url_or_path(&src_path, git_remote_url(remote))) < 0) return error; /* Copy .git/objects/ from the source to the target */ diff --git a/src/config.c b/src/config.c index 9033a92c5..88da34c5e 100644 --- a/src/config.c +++ b/src/config.c @@ -1177,7 +1177,7 @@ int git_config__find_programdata(git_str *path) if (ret != GIT_OK) return ret; - return git_path_validate_system_file_ownership(path->ptr); + return git_fs_path_validate_system_file_ownership(path->ptr); } int git_config__global_location(git_str *buf) diff --git a/src/config_file.c b/src/config_file.c index 9c3d2ceb8..11b444094 100644 --- a/src/config_file.c +++ b/src/config_file.c @@ -108,7 +108,7 @@ static int config_file_open(git_config_backend *cfg, git_config_level_t level, c if ((res = git_config_entries_new(&b->entries)) < 0) return res; - if (!git_path_exists(b->file.path)) + if (!git_fs_path_exists(b->file.path)) return 0; /* @@ -529,7 +529,7 @@ static int included_path(git_str *out, const char *dir, const char *path) if (path[0] == '~' && path[1] == '/') return git_sysdir_expand_global_file(out, &path[1]); - return git_path_join_unrooted(out, path, dir, NULL); + return git_fs_path_join_unrooted(out, path, dir, NULL); } /* Escape the values to write them to the file */ @@ -574,7 +574,7 @@ static int parse_include(config_file_parse_data *parse_data, const char *file) if (!file) return 0; - if ((result = git_path_dirname_r(&path, parse_data->file->path)) < 0) + if ((result = git_fs_path_dirname_r(&path, parse_data->file->path)) < 0) return result; dir = git_str_detach(&path); @@ -611,17 +611,17 @@ static int do_match_gitdir( git_str pattern = GIT_STR_INIT, gitdir = GIT_STR_INIT; int error; - if (condition[0] == '.' && git_path_is_dirsep(condition[1])) { - git_path_dirname_r(&pattern, cfg_file); + if (condition[0] == '.' && git_fs_path_is_dirsep(condition[1])) { + git_fs_path_dirname_r(&pattern, cfg_file); git_str_joinpath(&pattern, pattern.ptr, condition + 2); - } else if (condition[0] == '~' && git_path_is_dirsep(condition[1])) + } else if (condition[0] == '~' && git_fs_path_is_dirsep(condition[1])) git_sysdir_expand_global_file(&pattern, condition + 1); - else if (!git_path_is_absolute(condition)) + else if (!git_fs_path_is_absolute(condition)) git_str_joinpath(&pattern, "**", condition); else git_str_sets(&pattern, condition); - if (git_path_is_dirsep(condition[strlen(condition) - 1])) + if (git_fs_path_is_dirsep(condition[strlen(condition) - 1])) git_str_puts(&pattern, "**"); if (git_str_oom(&pattern)) { @@ -632,7 +632,7 @@ static int do_match_gitdir( if ((error = git_repository__item_path(&gitdir, repo, GIT_REPOSITORY_ITEM_GITDIR)) < 0) goto out; - if (git_path_is_dirsep(gitdir.ptr[gitdir.size - 1])) + if (git_fs_path_is_dirsep(gitdir.ptr[gitdir.size - 1])) git_str_truncate(&gitdir, gitdir.size - 1); *matches = wildmatch(pattern.ptr, gitdir.ptr, @@ -699,7 +699,7 @@ static int conditional_match_onbranch( */ if ((error = git_str_sets(&buf, condition)) < 0) goto out; - if (git_path_is_dirsep(condition[strlen(condition) - 1]) && + if (git_fs_path_is_dirsep(condition[strlen(condition) - 1]) && (error = git_str_puts(&buf, "**")) < 0) goto out; @@ -861,7 +861,7 @@ static int config_file_read( int error; if (p_stat(file->path, &st) < 0) { - error = git_path_set_error(errno, file->path, "stat"); + error = git_fs_path_set_error(errno, file->path, "stat"); goto out; } diff --git a/src/diff_generate.c b/src/diff_generate.c index dc690aa9b..dca16d51a 100644 --- a/src/diff_generate.c +++ b/src/diff_generate.c @@ -605,7 +605,7 @@ int git_diff__oid_for_entry( diff->base.perf.stat_calls++; if (p_stat(full_path.ptr, &st) < 0) { - error = git_path_set_error(errno, entry.path, "stat"); + error = git_fs_path_set_error(errno, entry.path, "stat"); git_str_dispose(&full_path); return error; } @@ -1026,7 +1026,7 @@ static int handle_unmatched_new_item( git_str *full = NULL; if (git_iterator_current_workdir_path(&full, info->new_iter) < 0) return -1; - if (full && git_path_contains(full, DOT_GIT)) { + if (full && git_fs_path_contains(full, DOT_GIT)) { /* TODO: warning if not a valid git repository */ recurse_into_dir = false; } diff --git a/src/diff_stats.c b/src/diff_stats.c index 228f6f892..259939844 100644 --- a/src/diff_stats.c +++ b/src/diff_stats.c @@ -70,7 +70,7 @@ static int diff_file_stats_full_to_buf( padding = stats->max_name - strlen(old_path) - strlen(new_path); - if ((common_dirlen = git_path_common_dirlen(old_path, new_path)) && + if ((common_dirlen = git_fs_path_common_dirlen(old_path, new_path)) && common_dirlen <= INT_MAX) { error = git_str_printf(out, " %.*s{%s"DIFF_RENAME_FILE_SEPARATOR"%s}", (int) common_dirlen, old_path, diff --git a/src/diff_tform.c b/src/diff_tform.c index be55de6c3..d14134071 100644 --- a/src/diff_tform.c +++ b/src/diff_tform.c @@ -13,7 +13,7 @@ #include "diff.h" #include "diff_generate.h" -#include "path.h" +#include "fs_path.h" #include "futils.h" #include "config.h" @@ -481,7 +481,7 @@ static int similarity_sig( return error; /* if path is not a regular file, just skip this item */ - if (!git_path_isfile(info->data.ptr)) + if (!git_fs_path_isfile(info->data.ptr)) return 0; /* TODO: apply wd-to-odb filters to file data if necessary */ diff --git a/src/filebuf.c b/src/filebuf.c index 10f8c5813..f0bd0004f 100644 --- a/src/filebuf.c +++ b/src/filebuf.c @@ -43,7 +43,7 @@ static int verify_last_error(git_filebuf *file) static int lock_file(git_filebuf *file, int flags, mode_t mode) { - if (git_path_exists(file->path_lock) == true) { + if (git_fs_path_exists(file->path_lock) == true) { git_error_clear(); /* actual OS error code just confuses */ git_error_set(GIT_ERROR_OS, "failed to lock file '%s' for writing", file->path_lock); @@ -63,7 +63,7 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode) file->fd_is_open = true; - if ((flags & GIT_FILEBUF_APPEND) && git_path_exists(file->path_original) == true) { + if ((flags & GIT_FILEBUF_APPEND) && git_fs_path_exists(file->path_original) == true) { git_file source; char buffer[FILEIO_BUFSIZE]; ssize_t read_bytes; @@ -103,7 +103,7 @@ void git_filebuf_cleanup(git_filebuf *file) if (file->fd_is_open && file->fd >= 0) p_close(file->fd); - if (file->created_lock && !file->did_rename && file->path_lock && git_path_exists(file->path_lock)) + if (file->created_lock && !file->did_rename && file->path_lock && git_fs_path_exists(file->path_lock)) p_unlink(file->path_lock); if (file->compute_digest) { @@ -241,20 +241,20 @@ static int resolve_symlink(git_str *out, const char *path) target.ptr[ret] = '\0'; target.size = ret; - root = git_path_root(target.ptr); + root = git_fs_path_root(target.ptr); if (root >= 0) { if ((error = git_str_sets(&curpath, target.ptr)) < 0) goto cleanup; } else { git_str dir = GIT_STR_INIT; - if ((error = git_path_dirname_r(&dir, curpath.ptr)) < 0) + if ((error = git_fs_path_dirname_r(&dir, curpath.ptr)) < 0) goto cleanup; git_str_swap(&curpath, &dir); git_str_dispose(&dir); - if ((error = git_path_apply_relative(&curpath, target.ptr)) < 0) + if ((error = git_fs_path_apply_relative(&curpath, target.ptr)) < 0) goto cleanup; } } @@ -366,7 +366,7 @@ int git_filebuf_open_withsize(git_filebuf *file, const char *path, int flags, mo memcpy(file->path_lock, file->path_original, path_len); memcpy(file->path_lock + path_len, GIT_FILELOCK_EXTENSION, GIT_FILELOCK_EXTLENGTH); - if (git_path_isdir(file->path_original)) { + if (git_fs_path_isdir(file->path_original)) { git_error_set(GIT_ERROR_FILESYSTEM, "path '%s' is a directory", file->path_original); error = GIT_EDIRECTORY; goto cleanup; diff --git a/src/filter.c b/src/filter.c index 417d9cb8b..950296033 100644 --- a/src/filter.c +++ b/src/filter.c @@ -1094,8 +1094,8 @@ int git_filter_list_stream_file( if ((error = stream_list_init( &stream_start, &filter_streams, filters, target)) < 0 || - (error = git_path_join_unrooted(&abspath, path, base, NULL)) < 0 || - (error = git_path_validate_workdir_buf(repo, &abspath)) < 0) + (error = git_fs_path_join_unrooted(&abspath, path, base, NULL)) < 0 || + (error = git_fs_path_validate_workdir_buf(repo, &abspath)) < 0) goto done; initialized = 1; diff --git a/src/fs_path.c b/src/fs_path.c new file mode 100644 index 000000000..e180d5866 --- /dev/null +++ b/src/fs_path.c @@ -0,0 +1,1839 @@ +/* + * Copyright (C) the libgit2 contributors. All rights reserved. + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ + +#include "fs_path.h" + +#include "posix.h" +#include "repository.h" +#ifdef GIT_WIN32 +#include "win32/posix.h" +#include "win32/w32_buffer.h" +#include "win32/w32_util.h" +#include "win32/version.h" +#include +#else +#include +#endif +#include +#include + +static int dos_drive_prefix_length(const char *path) +{ + int i; + + /* + * Does it start with an ASCII letter (i.e. highest bit not set), + * followed by a colon? + */ + if (!(0x80 & (unsigned char)*path)) + return *path && path[1] == ':' ? 2 : 0; + + /* + * While drive letters must be letters of the English alphabet, it is + * possible to assign virtually _any_ Unicode character via `subst` as + * a drive letter to "virtual drives". Even `1`, or `ä`. Or fun stuff + * like this: + * + * subst ֍: %USERPROFILE%\Desktop + */ + for (i = 1; i < 4 && (0x80 & (unsigned char)path[i]); i++) + ; /* skip first UTF-8 character */ + return path[i] == ':' ? i + 1 : 0; +} + +#ifdef GIT_WIN32 +static bool looks_like_network_computer_name(const char *path, int pos) +{ + if (pos < 3) + return false; + + if (path[0] != '/' || path[1] != '/') + return false; + + while (pos-- > 2) { + if (path[pos] == '/') + return false; + } + + return true; +} +#endif + +/* + * Based on the Android implementation, BSD licensed. + * http://android.git.kernel.org/ + * + * Copyright (C) 2008 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +int git_fs_path_basename_r(git_str *buffer, const char *path) +{ + const char *endp, *startp; + int len, result; + + /* Empty or NULL string gets treated as "." */ + if (path == NULL || *path == '\0') { + startp = "."; + len = 1; + goto Exit; + } + + /* Strip trailing slashes */ + endp = path + strlen(path) - 1; + while (endp > path && *endp == '/') + endp--; + + /* All slashes becomes "/" */ + if (endp == path && *endp == '/') { + startp = "/"; + len = 1; + goto Exit; + } + + /* Find the start of the base */ + startp = endp; + while (startp > path && *(startp - 1) != '/') + startp--; + + /* Cast is safe because max path < max int */ + len = (int)(endp - startp + 1); + +Exit: + result = len; + + if (buffer != NULL && git_str_set(buffer, startp, len) < 0) + return -1; + + return result; +} + +/* + * Determine if the path is a Windows prefix and, if so, returns + * its actual lentgh. If it is not a prefix, returns -1. + */ +static int win32_prefix_length(const char *path, int len) +{ +#ifndef GIT_WIN32 + GIT_UNUSED(path); + GIT_UNUSED(len); +#else + /* + * Mimic unix behavior where '/.git' returns '/': 'C:/.git' + * will return 'C:/' here + */ + if (dos_drive_prefix_length(path) == len) + return len; + + /* + * Similarly checks if we're dealing with a network computer name + * '//computername/.git' will return '//computername/' + */ + if (looks_like_network_computer_name(path, len)) + return len; +#endif + + return -1; +} + +/* + * Based on the Android implementation, BSD licensed. + * Check http://android.git.kernel.org/ + */ +int git_fs_path_dirname_r(git_str *buffer, const char *path) +{ + const char *endp; + int is_prefix = 0, len; + + /* Empty or NULL string gets treated as "." */ + if (path == NULL || *path == '\0') { + path = "."; + len = 1; + goto Exit; + } + + /* Strip trailing slashes */ + endp = path + strlen(path) - 1; + while (endp > path && *endp == '/') + endp--; + + if (endp - path + 1 > INT_MAX) { + git_error_set(GIT_ERROR_INVALID, "path too long"); + len = -1; + goto Exit; + } + + if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) { + is_prefix = 1; + goto Exit; + } + + /* Find the start of the dir */ + while (endp > path && *endp != '/') + endp--; + + /* Either the dir is "/" or there are no slashes */ + if (endp == path) { + path = (*endp == '/') ? "/" : "."; + len = 1; + goto Exit; + } + + do { + endp--; + } while (endp > path && *endp == '/'); + + if (endp - path + 1 > INT_MAX) { + git_error_set(GIT_ERROR_INVALID, "path too long"); + len = -1; + goto Exit; + } + + if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) { + is_prefix = 1; + goto Exit; + } + + /* Cast is safe because max path < max int */ + len = (int)(endp - path + 1); + +Exit: + if (buffer) { + if (git_str_set(buffer, path, len) < 0) + return -1; + if (is_prefix && git_str_putc(buffer, '/') < 0) + return -1; + } + + return len; +} + + +char *git_fs_path_dirname(const char *path) +{ + git_str buf = GIT_STR_INIT; + char *dirname; + + git_fs_path_dirname_r(&buf, path); + dirname = git_str_detach(&buf); + git_str_dispose(&buf); /* avoid memleak if error occurs */ + + return dirname; +} + +char *git_fs_path_basename(const char *path) +{ + git_str buf = GIT_STR_INIT; + char *basename; + + git_fs_path_basename_r(&buf, path); + basename = git_str_detach(&buf); + git_str_dispose(&buf); /* avoid memleak if error occurs */ + + return basename; +} + +size_t git_fs_path_basename_offset(git_str *buffer) +{ + ssize_t slash; + + if (!buffer || buffer->size <= 0) + return 0; + + slash = git_str_rfind_next(buffer, '/'); + + if (slash >= 0 && buffer->ptr[slash] == '/') + return (size_t)(slash + 1); + + return 0; +} + +int git_fs_path_root(const char *path) +{ + int offset = 0, prefix_len; + + /* Does the root of the path look like a windows drive ? */ + if ((prefix_len = dos_drive_prefix_length(path))) + offset += prefix_len; + +#ifdef GIT_WIN32 + /* Are we dealing with a windows network path? */ + else if ((path[0] == '/' && path[1] == '/' && path[2] != '/') || + (path[0] == '\\' && path[1] == '\\' && path[2] != '\\')) + { + offset += 2; + + /* Skip the computer name segment */ + while (path[offset] && path[offset] != '/' && path[offset] != '\\') + offset++; + } + + if (path[offset] == '\\') + return offset; +#endif + + if (path[offset] == '/') + return offset; + + return -1; /* Not a real error - signals that path is not rooted */ +} + +static void path_trim_slashes(git_str *path) +{ + int ceiling = git_fs_path_root(path->ptr) + 1; + + if (ceiling < 0) + return; + + while (path->size > (size_t)ceiling) { + if (path->ptr[path->size-1] != '/') + break; + + path->ptr[path->size-1] = '\0'; + path->size--; + } +} + +int git_fs_path_join_unrooted( + git_str *path_out, const char *path, const char *base, ssize_t *root_at) +{ + ssize_t root; + + GIT_ASSERT_ARG(path_out); + GIT_ASSERT_ARG(path); + + root = (ssize_t)git_fs_path_root(path); + + if (base != NULL && root < 0) { + if (git_str_joinpath(path_out, base, path) < 0) + return -1; + + root = (ssize_t)strlen(base); + } else { + if (git_str_sets(path_out, path) < 0) + return -1; + + if (root < 0) + root = 0; + else if (base) + git_fs_path_equal_or_prefixed(base, path, &root); + } + + if (root_at) + *root_at = root; + + return 0; +} + +void git_fs_path_squash_slashes(git_str *path) +{ + char *p, *q; + + if (path->size == 0) + return; + + for (p = path->ptr, q = path->ptr; *q; p++, q++) { + *p = *q; + + while (*q == '/' && *(q+1) == '/') { + path->size--; + q++; + } + } + + *p = '\0'; +} + +int git_fs_path_prettify(git_str *path_out, const char *path, const char *base) +{ + char buf[GIT_PATH_MAX]; + + GIT_ASSERT_ARG(path_out); + GIT_ASSERT_ARG(path); + + /* construct path if needed */ + if (base != NULL && git_fs_path_root(path) < 0) { + if (git_str_joinpath(path_out, base, path) < 0) + return -1; + path = path_out->ptr; + } + + if (p_realpath(path, buf) == NULL) { + /* git_error_set resets the errno when dealing with a GIT_ERROR_OS kind of error */ + int error = (errno == ENOENT || errno == ENOTDIR) ? GIT_ENOTFOUND : -1; + git_error_set(GIT_ERROR_OS, "failed to resolve path '%s'", path); + + git_str_clear(path_out); + + return error; + } + + return git_str_sets(path_out, buf); +} + +int git_fs_path_prettify_dir(git_str *path_out, const char *path, const char *base) +{ + int error = git_fs_path_prettify(path_out, path, base); + return (error < 0) ? error : git_fs_path_to_dir(path_out); +} + +int git_fs_path_to_dir(git_str *path) +{ + if (path->asize > 0 && + git_str_len(path) > 0 && + path->ptr[git_str_len(path) - 1] != '/') + git_str_putc(path, '/'); + + return git_str_oom(path) ? -1 : 0; +} + +void git_fs_path_string_to_dir(char *path, size_t size) +{ + size_t end = strlen(path); + + if (end && path[end - 1] != '/' && end < size) { + path[end] = '/'; + path[end + 1] = '\0'; + } +} + +int git__percent_decode(git_str *decoded_out, const char *input) +{ + int len, hi, lo, i; + + GIT_ASSERT_ARG(decoded_out); + GIT_ASSERT_ARG(input); + + len = (int)strlen(input); + git_str_clear(decoded_out); + + for(i = 0; i < len; i++) + { + char c = input[i]; + + if (c != '%') + goto append; + + if (i >= len - 2) + goto append; + + hi = git__fromhex(input[i + 1]); + lo = git__fromhex(input[i + 2]); + + if (hi < 0 || lo < 0) + goto append; + + c = (char)(hi << 4 | lo); + i += 2; + +append: + if (git_str_putc(decoded_out, c) < 0) + return -1; + } + + return 0; +} + +static int error_invalid_local_file_uri(const char *uri) +{ + git_error_set(GIT_ERROR_CONFIG, "'%s' is not a valid local file URI", uri); + return -1; +} + +static int local_file_url_prefixlen(const char *file_url) +{ + int len = -1; + + if (git__prefixcmp(file_url, "file://") == 0) { + if (file_url[7] == '/') + len = 8; + else if (git__prefixcmp(file_url + 7, "localhost/") == 0) + len = 17; + } + + return len; +} + +bool git_fs_path_is_local_file_url(const char *file_url) +{ + return (local_file_url_prefixlen(file_url) > 0); +} + +int git_fs_path_fromurl(git_str *local_path_out, const char *file_url) +{ + int offset; + + GIT_ASSERT_ARG(local_path_out); + GIT_ASSERT_ARG(file_url); + + if ((offset = local_file_url_prefixlen(file_url)) < 0 || + file_url[offset] == '\0' || file_url[offset] == '/') + return error_invalid_local_file_uri(file_url); + +#ifndef GIT_WIN32 + offset--; /* A *nix absolute path starts with a forward slash */ +#endif + + git_str_clear(local_path_out); + return git__percent_decode(local_path_out, file_url + offset); +} + +int git_fs_path_walk_up( + git_str *path, + const char *ceiling, + int (*cb)(void *data, const char *), + void *data) +{ + int error = 0; + git_str iter; + ssize_t stop = 0, scan; + char oldc = '\0'; + + GIT_ASSERT_ARG(path); + GIT_ASSERT_ARG(cb); + + if (ceiling != NULL) { + if (git__prefixcmp(path->ptr, ceiling) == 0) + stop = (ssize_t)strlen(ceiling); + else + stop = git_str_len(path); + } + scan = git_str_len(path); + + /* empty path: yield only once */ + if (!scan) { + error = cb(data, ""); + if (error) + git_error_set_after_callback(error); + return error; + } + + iter.ptr = path->ptr; + iter.size = git_str_len(path); + iter.asize = path->asize; + + while (scan >= stop) { + error = cb(data, iter.ptr); + iter.ptr[scan] = oldc; + + if (error) { + git_error_set_after_callback(error); + break; + } + + scan = git_str_rfind_next(&iter, '/'); + if (scan >= 0) { + scan++; + oldc = iter.ptr[scan]; + iter.size = scan; + iter.ptr[scan] = '\0'; + } + } + + if (scan >= 0) + iter.ptr[scan] = oldc; + + /* relative path: yield for the last component */ + if (!error && stop == 0 && iter.ptr[0] != '/') { + error = cb(data, ""); + if (error) + git_error_set_after_callback(error); + } + + return error; +} + +bool git_fs_path_exists(const char *path) +{ + GIT_ASSERT_ARG_WITH_RETVAL(path, false); + return p_access(path, F_OK) == 0; +} + +bool git_fs_path_isdir(const char *path) +{ + struct stat st; + if (p_stat(path, &st) < 0) + return false; + + return S_ISDIR(st.st_mode) != 0; +} + +bool git_fs_path_isfile(const char *path) +{ + struct stat st; + + GIT_ASSERT_ARG_WITH_RETVAL(path, false); + if (p_stat(path, &st) < 0) + return false; + + return S_ISREG(st.st_mode) != 0; +} + +bool git_fs_path_islink(const char *path) +{ + struct stat st; + + GIT_ASSERT_ARG_WITH_RETVAL(path, false); + if (p_lstat(path, &st) < 0) + return false; + + return S_ISLNK(st.st_mode) != 0; +} + +#ifdef GIT_WIN32 + +bool git_fs_path_is_empty_dir(const char *path) +{ + git_win32_path filter_w; + bool empty = false; + + if (git_win32__findfirstfile_filter(filter_w, path)) { + WIN32_FIND_DATAW findData; + HANDLE hFind = FindFirstFileW(filter_w, &findData); + + /* FindFirstFile will fail if there are no children to the given + * path, which can happen if the given path is a file (and obviously + * has no children) or if the given path is an empty mount point. + * (Most directories have at least directory entries '.' and '..', + * but ridiculously another volume mounted in another drive letter's + * path space do not, and thus have nothing to enumerate.) If + * FindFirstFile fails, check if this is a directory-like thing + * (a mount point). + */ + if (hFind == INVALID_HANDLE_VALUE) + return git_fs_path_isdir(path); + + /* If the find handle was created successfully, then it's a directory */ + empty = true; + + do { + /* Allow the enumeration to return . and .. and still be considered + * empty. In the special case of drive roots (i.e. C:\) where . and + * .. do not occur, we can still consider the path to be an empty + * directory if there's nothing there. */ + if (!git_fs_path_is_dot_or_dotdotW(findData.cFileName)) { + empty = false; + break; + } + } while (FindNextFileW(hFind, &findData)); + + FindClose(hFind); + } + + return empty; +} + +#else + +static int path_found_entry(void *payload, git_str *path) +{ + GIT_UNUSED(payload); + return !git_fs_path_is_dot_or_dotdot(path->ptr); +} + +bool git_fs_path_is_empty_dir(const char *path) +{ + int error; + git_str dir = GIT_STR_INIT; + + if (!git_fs_path_isdir(path)) + return false; + + if ((error = git_str_sets(&dir, path)) != 0) + git_error_clear(); + else + error = git_fs_path_direach(&dir, 0, path_found_entry, NULL); + + git_str_dispose(&dir); + + return !error; +} + +#endif + +int git_fs_path_set_error(int errno_value, const char *path, const char *action) +{ + switch (errno_value) { + case ENOENT: + case ENOTDIR: + git_error_set(GIT_ERROR_OS, "could not find '%s' to %s", path, action); + return GIT_ENOTFOUND; + + case EINVAL: + case ENAMETOOLONG: + git_error_set(GIT_ERROR_OS, "invalid path for filesystem '%s'", path); + return GIT_EINVALIDSPEC; + + case EEXIST: + git_error_set(GIT_ERROR_OS, "failed %s - '%s' already exists", action, path); + return GIT_EEXISTS; + + case EACCES: + git_error_set(GIT_ERROR_OS, "failed %s - '%s' is locked", action, path); + return GIT_ELOCKED; + + default: + git_error_set(GIT_ERROR_OS, "could not %s '%s'", action, path); + return -1; + } +} + +int git_fs_path_lstat(const char *path, struct stat *st) +{ + if (p_lstat(path, st) == 0) + return 0; + + return git_fs_path_set_error(errno, path, "stat"); +} + +static bool _check_dir_contents( + git_str *dir, + const char *sub, + bool (*predicate)(const char *)) +{ + bool result; + size_t dir_size = git_str_len(dir); + size_t sub_size = strlen(sub); + size_t alloc_size; + + /* leave base valid even if we could not make space for subdir */ + if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, dir_size, sub_size) || + GIT_ADD_SIZET_OVERFLOW(&alloc_size, alloc_size, 2) || + git_str_try_grow(dir, alloc_size, false) < 0) + return false; + + /* save excursion */ + if (git_str_joinpath(dir, dir->ptr, sub) < 0) + return false; + + result = predicate(dir->ptr); + + /* restore path */ + git_str_truncate(dir, dir_size); + return result; +} + +bool git_fs_path_contains(git_str *dir, const char *item) +{ + return _check_dir_contents(dir, item, &git_fs_path_exists); +} + +bool git_fs_path_contains_dir(git_str *base, const char *subdir) +{ + return _check_dir_contents(base, subdir, &git_fs_path_isdir); +} + +bool git_fs_path_contains_file(git_str *base, const char *file) +{ + return _check_dir_contents(base, file, &git_fs_path_isfile); +} + +int git_fs_path_find_dir(git_str *dir) +{ + int error = 0; + char buf[GIT_PATH_MAX]; + + if (p_realpath(dir->ptr, buf) != NULL) + error = git_str_sets(dir, buf); + + /* call dirname if this is not a directory */ + if (!error) /* && git_fs_path_isdir(dir->ptr) == false) */ + error = (git_fs_path_dirname_r(dir, dir->ptr) < 0) ? -1 : 0; + + if (!error) + error = git_fs_path_to_dir(dir); + + return error; +} + +int git_fs_path_resolve_relative(git_str *path, size_t ceiling) +{ + char *base, *to, *from, *next; + size_t len; + + GIT_ERROR_CHECK_ALLOC_STR(path); + + if (ceiling > path->size) + ceiling = path->size; + + /* recognize drive prefixes, etc. that should not be backed over */ + if (ceiling == 0) + ceiling = git_fs_path_root(path->ptr) + 1; + + /* recognize URL prefixes that should not be backed over */ + if (ceiling == 0) { + for (next = path->ptr; *next && git__isalpha(*next); ++next); + if (next[0] == ':' && next[1] == '/' && next[2] == '/') + ceiling = (next + 3) - path->ptr; + } + + base = to = from = path->ptr + ceiling; + + while (*from) { + for (next = from; *next && *next != '/'; ++next); + + len = next - from; + + if (len == 1 && from[0] == '.') + /* do nothing with singleton dot */; + + else if (len == 2 && from[0] == '.' && from[1] == '.') { + /* error out if trying to up one from a hard base */ + if (to == base && ceiling != 0) { + git_error_set(GIT_ERROR_INVALID, + "cannot strip root component off url"); + return -1; + } + + /* no more path segments to strip, + * use '../' as a new base path */ + if (to == base) { + if (*next == '/') + len++; + + if (to != from) + memmove(to, from, len); + + to += len; + /* this is now the base, can't back up from a + * relative prefix */ + base = to; + } else { + /* back up a path segment */ + while (to > base && to[-1] == '/') to--; + while (to > base && to[-1] != '/') to--; + } + } else { + if (*next == '/' && *from != '/') + len++; + + if (to != from) + memmove(to, from, len); + + to += len; + } + + from += len; + + while (*from == '/') from++; + } + + *to = '\0'; + + path->size = to - path->ptr; + + return 0; +} + +int git_fs_path_apply_relative(git_str *target, const char *relpath) +{ + return git_str_joinpath(target, git_str_cstr(target), relpath) || + git_fs_path_resolve_relative(target, 0); +} + +int git_fs_path_cmp( + const char *name1, size_t len1, int isdir1, + const char *name2, size_t len2, int isdir2, + int (*compare)(const char *, const char *, size_t)) +{ + unsigned char c1, c2; + size_t len = len1 < len2 ? len1 : len2; + int cmp; + + cmp = compare(name1, name2, len); + if (cmp) + return cmp; + + c1 = name1[len]; + c2 = name2[len]; + + if (c1 == '\0' && isdir1) + c1 = '/'; + + if (c2 == '\0' && isdir2) + c2 = '/'; + + return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0; +} + +size_t git_fs_path_common_dirlen(const char *one, const char *two) +{ + const char *p, *q, *dirsep = NULL; + + for (p = one, q = two; *p && *q; p++, q++) { + if (*p == '/' && *q == '/') + dirsep = p; + else if (*p != *q) + break; + } + + return dirsep ? (dirsep - one) + 1 : 0; +} + +int git_fs_path_make_relative(git_str *path, const char *parent) +{ + const char *p, *q, *p_dirsep, *q_dirsep; + size_t plen = path->size, newlen, alloclen, depth = 1, i, offset; + + for (p_dirsep = p = path->ptr, q_dirsep = q = parent; *p && *q; p++, q++) { + if (*p == '/' && *q == '/') { + p_dirsep = p; + q_dirsep = q; + } + else if (*p != *q) + break; + } + + /* need at least 1 common path segment */ + if ((p_dirsep == path->ptr || q_dirsep == parent) && + (*p_dirsep != '/' || *q_dirsep != '/')) { + git_error_set(GIT_ERROR_INVALID, + "%s is not a parent of %s", parent, path->ptr); + return GIT_ENOTFOUND; + } + + if (*p == '/' && !*q) + p++; + else if (!*p && *q == '/') + q++; + else if (!*p && !*q) + return git_str_clear(path), 0; + else { + p = p_dirsep + 1; + q = q_dirsep + 1; + } + + plen -= (p - path->ptr); + + if (!*q) + return git_str_set(path, p, plen); + + for (; (q = strchr(q, '/')) && *(q + 1); q++) + depth++; + + GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newlen, depth, 3); + GIT_ERROR_CHECK_ALLOC_ADD(&newlen, newlen, plen); + + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, newlen, 1); + + /* save the offset as we might realllocate the pointer */ + offset = p - path->ptr; + if (git_str_try_grow(path, alloclen, 1) < 0) + return -1; + p = path->ptr + offset; + + memmove(path->ptr + (depth * 3), p, plen + 1); + + for (i = 0; i < depth; i++) + memcpy(path->ptr + (i * 3), "../", 3); + + path->size = newlen; + return 0; +} + +bool git_fs_path_has_non_ascii(const char *path, size_t pathlen) +{ + const uint8_t *scan = (const uint8_t *)path, *end; + + for (end = scan + pathlen; scan < end; ++scan) + if (*scan & 0x80) + return true; + + return false; +} + +#ifdef GIT_USE_ICONV + +int git_fs_path_iconv_init_precompose(git_fs_path_iconv_t *ic) +{ + git_str_init(&ic->buf, 0); + ic->map = iconv_open(GIT_PATH_REPO_ENCODING, GIT_PATH_NATIVE_ENCODING); + return 0; +} + +void git_fs_path_iconv_clear(git_fs_path_iconv_t *ic) +{ + if (ic) { + if (ic->map != (iconv_t)-1) + iconv_close(ic->map); + git_str_dispose(&ic->buf); + } +} + +int git_fs_path_iconv(git_fs_path_iconv_t *ic, const char **in, size_t *inlen) +{ + char *nfd = (char*)*in, *nfc; + size_t nfdlen = *inlen, nfclen, wantlen = nfdlen, alloclen, rv; + int retry = 1; + + if (!ic || ic->map == (iconv_t)-1 || + !git_fs_path_has_non_ascii(*in, *inlen)) + return 0; + + git_str_clear(&ic->buf); + + while (1) { + GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, wantlen, 1); + if (git_str_grow(&ic->buf, alloclen) < 0) + return -1; + + nfc = ic->buf.ptr + ic->buf.size; + nfclen = ic->buf.asize - ic->buf.size; + + rv = iconv(ic->map, &nfd, &nfdlen, &nfc, &nfclen); + + ic->buf.size = (nfc - ic->buf.ptr); + + if (rv != (size_t)-1) + break; + + /* if we cannot convert the data (probably because iconv thinks + * it is not valid UTF-8 source data), then use original data + */ + if (errno != E2BIG) + return 0; + + /* make space for 2x the remaining data to be converted + * (with per retry overhead to avoid infinite loops) + */ + wantlen = ic->buf.size + max(nfclen, nfdlen) * 2 + (size_t)(retry * 4); + + if (retry++ > 4) + goto fail; + } + + ic->buf.ptr[ic->buf.size] = '\0'; + + *in = ic->buf.ptr; + *inlen = ic->buf.size; + + return 0; + +fail: + git_error_set(GIT_ERROR_OS, "unable to convert unicode path data"); + return -1; +} + +static const char *nfc_file = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D.XXXXXX"; +static const char *nfd_file = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D.XXXXXX"; + +/* Check if the platform is decomposing unicode data for us. We will + * emulate core Git and prefer to use precomposed unicode data internally + * on these platforms, composing the decomposed unicode on the fly. + * + * This mainly happens on the Mac where HDFS stores filenames as + * decomposed unicode. Even on VFAT and SAMBA file systems, the Mac will + * return decomposed unicode from readdir() even when the actual + * filesystem is storing precomposed unicode. + */ +bool git_fs_path_does_decompose_unicode(const char *root) +{ + git_str path = GIT_STR_INIT; + int fd; + bool found_decomposed = false; + char tmp[6]; + + /* Create a file using a precomposed path and then try to find it + * using the decomposed name. If the lookup fails, then we will mark + * that we should precompose unicode for this repository. + */ + if (git_str_joinpath(&path, root, nfc_file) < 0 || + (fd = p_mkstemp(path.ptr)) < 0) + goto done; + p_close(fd); + + /* record trailing digits generated by mkstemp */ + memcpy(tmp, path.ptr + path.size - sizeof(tmp), sizeof(tmp)); + + /* try to look up as NFD path */ + if (git_str_joinpath(&path, root, nfd_file) < 0) + goto done; + memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp)); + + found_decomposed = git_fs_path_exists(path.ptr); + + /* remove temporary file (using original precomposed path) */ + if (git_str_joinpath(&path, root, nfc_file) < 0) + goto done; + memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp)); + + (void)p_unlink(path.ptr); + +done: + git_str_dispose(&path); + return found_decomposed; +} + +#else + +bool git_fs_path_does_decompose_unicode(const char *root) +{ + GIT_UNUSED(root); + return false; +} + +#endif + +#if defined(__sun) || defined(__GNU__) +typedef char path_dirent_data[sizeof(struct dirent) + FILENAME_MAX + 1]; +#else +typedef struct dirent path_dirent_data; +#endif + +int git_fs_path_direach( + git_str *path, + uint32_t flags, + int (*fn)(void *, git_str *), + void *arg) +{ + int error = 0; + ssize_t wd_len; + DIR *dir; + struct dirent *de; + +#ifdef GIT_USE_ICONV + git_fs_path_iconv_t ic = GIT_PATH_ICONV_INIT; +#endif + + GIT_UNUSED(flags); + + if (git_fs_path_to_dir(path) < 0) + return -1; + + wd_len = git_str_len(path); + + if ((dir = opendir(path->ptr)) == NULL) { + git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path->ptr); + if (errno == ENOENT) + return GIT_ENOTFOUND; + + return -1; + } + +#ifdef GIT_USE_ICONV + if ((flags & GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE) != 0) + (void)git_fs_path_iconv_init_precompose(&ic); +#endif + + while ((de = readdir(dir)) != NULL) { + const char *de_path = de->d_name; + size_t de_len = strlen(de_path); + + if (git_fs_path_is_dot_or_dotdot(de_path)) + continue; + +#ifdef GIT_USE_ICONV + if ((error = git_fs_path_iconv(&ic, &de_path, &de_len)) < 0) + break; +#endif + + if ((error = git_str_put(path, de_path, de_len)) < 0) + break; + + git_error_clear(); + error = fn(arg, path); + + git_str_truncate(path, wd_len); /* restore path */ + + /* Only set our own error if the callback did not set one already */ + if (error != 0) { + if (!git_error_last()) + git_error_set_after_callback(error); + + break; + } + } + + closedir(dir); + +#ifdef GIT_USE_ICONV + git_fs_path_iconv_clear(&ic); +#endif + + return error; +} + +#if defined(GIT_WIN32) && !defined(__MINGW32__) + +/* Using _FIND_FIRST_EX_LARGE_FETCH may increase performance in Windows 7 + * and better. + */ +#ifndef FIND_FIRST_EX_LARGE_FETCH +# define FIND_FIRST_EX_LARGE_FETCH 2 +#endif + +int git_fs_path_diriter_init( + git_fs_path_diriter *diriter, + const char *path, + unsigned int flags) +{ + git_win32_path path_filter; + + static int is_win7_or_later = -1; + if (is_win7_or_later < 0) + is_win7_or_later = git_has_win32_version(6, 1, 0); + + GIT_ASSERT_ARG(diriter); + GIT_ASSERT_ARG(path); + + memset(diriter, 0, sizeof(git_fs_path_diriter)); + diriter->handle = INVALID_HANDLE_VALUE; + + if (git_str_puts(&diriter->path_utf8, path) < 0) + return -1; + + path_trim_slashes(&diriter->path_utf8); + + if (diriter->path_utf8.size == 0) { + git_error_set(GIT_ERROR_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)) { + git_error_set(GIT_ERROR_OS, "could not parse the directory path '%s'", path); + return -1; + } + + diriter->handle = FindFirstFileExW( + path_filter, + is_win7_or_later ? FindExInfoBasic : FindExInfoStandard, + &diriter->current, + FindExSearchNameMatch, + NULL, + is_win7_or_later ? FIND_FIRST_EX_LARGE_FETCH : 0); + + if (diriter->handle == INVALID_HANDLE_VALUE) { + git_error_set(GIT_ERROR_OS, "could not open directory '%s'", path); + return -1; + } + + diriter->parent_utf8_len = diriter->path_utf8.size; + diriter->flags = flags; + return 0; +} + +static int diriter_update_paths(git_fs_path_diriter *diriter) +{ + size_t filename_len, path_len; + + filename_len = wcslen(diriter->current.cFileName); + + if (GIT_ADD_SIZET_OVERFLOW(&path_len, diriter->parent_len, filename_len) || + GIT_ADD_SIZET_OVERFLOW(&path_len, path_len, 2)) + return -1; + + if (path_len > GIT_WIN_PATH_UTF16) { + git_error_set(GIT_ERROR_FILESYSTEM, + "invalid path '%.*ls\\%ls' (path too long)", + diriter->parent_len, diriter->path, diriter->current.cFileName); + return -1; + } + + diriter->path[diriter->parent_len] = L'\\'; + memcpy(&diriter->path[diriter->parent_len+1], + diriter->current.cFileName, filename_len * sizeof(wchar_t)); + diriter->path[path_len-1] = L'\0'; + + git_str_truncate(&diriter->path_utf8, diriter->parent_utf8_len); + + if (diriter->parent_utf8_len > 0 && + diriter->path_utf8.ptr[diriter->parent_utf8_len-1] != '/') + git_str_putc(&diriter->path_utf8, '/'); + + git_str_put_w(&diriter->path_utf8, diriter->current.cFileName, filename_len); + + if (git_str_oom(&diriter->path_utf8)) + return -1; + + return 0; +} + +int git_fs_path_diriter_next(git_fs_path_diriter *diriter) +{ + bool skip_dot = !(diriter->flags & GIT_FS_PATH_DIR_INCLUDE_DOT_AND_DOTDOT); + + do { + /* Our first time through, we already have the data from + * FindFirstFileW. Use it, otherwise get the next file. + */ + if (!diriter->needs_next) + diriter->needs_next = 1; + else if (!FindNextFileW(diriter->handle, &diriter->current)) + return GIT_ITEROVER; + } while (skip_dot && git_fs_path_is_dot_or_dotdotW(diriter->current.cFileName)); + + if (diriter_update_paths(diriter) < 0) + return -1; + + return 0; +} + +int git_fs_path_diriter_filename( + const char **out, + size_t *out_len, + git_fs_path_diriter *diriter) +{ + GIT_ASSERT_ARG(out); + GIT_ASSERT_ARG(out_len); + GIT_ASSERT_ARG(diriter); + GIT_ASSERT(diriter->path_utf8.size > diriter->parent_utf8_len); + + *out = &diriter->path_utf8.ptr[diriter->parent_utf8_len+1]; + *out_len = diriter->path_utf8.size - diriter->parent_utf8_len - 1; + return 0; +} + +int git_fs_path_diriter_fullpath( + const char **out, + size_t *out_len, + git_fs_path_diriter *diriter) +{ + GIT_ASSERT_ARG(out); + GIT_ASSERT_ARG(out_len); + GIT_ASSERT_ARG(diriter); + + *out = diriter->path_utf8.ptr; + *out_len = diriter->path_utf8.size; + return 0; +} + +int git_fs_path_diriter_stat(struct stat *out, git_fs_path_diriter *diriter) +{ + GIT_ASSERT_ARG(out); + GIT_ASSERT_ARG(diriter); + + return git_win32__file_attribute_to_stat(out, + (WIN32_FILE_ATTRIBUTE_DATA *)&diriter->current, + diriter->path); +} + +void git_fs_path_diriter_free(git_fs_path_diriter *diriter) +{ + if (diriter == NULL) + return; + + git_str_dispose(&diriter->path_utf8); + + if (diriter->handle != INVALID_HANDLE_VALUE) { + FindClose(diriter->handle); + diriter->handle = INVALID_HANDLE_VALUE; + } +} + +#else + +int git_fs_path_diriter_init( + git_fs_path_diriter *diriter, + const char *path, + unsigned int flags) +{ + GIT_ASSERT_ARG(diriter); + GIT_ASSERT_ARG(path); + + memset(diriter, 0, sizeof(git_fs_path_diriter)); + + if (git_str_puts(&diriter->path, path) < 0) + return -1; + + path_trim_slashes(&diriter->path); + + if (diriter->path.size == 0) { + git_error_set(GIT_ERROR_FILESYSTEM, "could not open directory '%s'", path); + return -1; + } + + if ((diriter->dir = opendir(diriter->path.ptr)) == NULL) { + git_str_dispose(&diriter->path); + + git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path); + return -1; + } + +#ifdef GIT_USE_ICONV + if ((flags & GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE) != 0) + (void)git_fs_path_iconv_init_precompose(&diriter->ic); +#endif + + diriter->parent_len = diriter->path.size; + diriter->flags = flags; + + return 0; +} + +int git_fs_path_diriter_next(git_fs_path_diriter *diriter) +{ + struct dirent *de; + const char *filename; + size_t filename_len; + bool skip_dot = !(diriter->flags & GIT_FS_PATH_DIR_INCLUDE_DOT_AND_DOTDOT); + int error = 0; + + GIT_ASSERT_ARG(diriter); + + errno = 0; + + do { + if ((de = readdir(diriter->dir)) == NULL) { + if (!errno) + return GIT_ITEROVER; + + git_error_set(GIT_ERROR_OS, + "could not read directory '%s'", diriter->path.ptr); + return -1; + } + } while (skip_dot && git_fs_path_is_dot_or_dotdot(de->d_name)); + + filename = de->d_name; + filename_len = strlen(filename); + +#ifdef GIT_USE_ICONV + if ((diriter->flags & GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE) != 0 && + (error = git_fs_path_iconv(&diriter->ic, &filename, &filename_len)) < 0) + return error; +#endif + + git_str_truncate(&diriter->path, diriter->parent_len); + + if (diriter->parent_len > 0 && + diriter->path.ptr[diriter->parent_len-1] != '/') + git_str_putc(&diriter->path, '/'); + + git_str_put(&diriter->path, filename, filename_len); + + if (git_str_oom(&diriter->path)) + return -1; + + return error; +} + +int git_fs_path_diriter_filename( + const char **out, + size_t *out_len, + git_fs_path_diriter *diriter) +{ + GIT_ASSERT_ARG(out); + GIT_ASSERT_ARG(out_len); + GIT_ASSERT_ARG(diriter); + GIT_ASSERT(diriter->path.size > diriter->parent_len); + + *out = &diriter->path.ptr[diriter->parent_len+1]; + *out_len = diriter->path.size - diriter->parent_len - 1; + return 0; +} + +int git_fs_path_diriter_fullpath( + const char **out, + size_t *out_len, + git_fs_path_diriter *diriter) +{ + GIT_ASSERT_ARG(out); + GIT_ASSERT_ARG(out_len); + GIT_ASSERT_ARG(diriter); + + *out = diriter->path.ptr; + *out_len = diriter->path.size; + return 0; +} + +int git_fs_path_diriter_stat(struct stat *out, git_fs_path_diriter *diriter) +{ + GIT_ASSERT_ARG(out); + GIT_ASSERT_ARG(diriter); + + return git_fs_path_lstat(diriter->path.ptr, out); +} + +void git_fs_path_diriter_free(git_fs_path_diriter *diriter) +{ + if (diriter == NULL) + return; + + if (diriter->dir) { + closedir(diriter->dir); + diriter->dir = NULL; + } + +#ifdef GIT_USE_ICONV + git_fs_path_iconv_clear(&diriter->ic); +#endif + + git_str_dispose(&diriter->path); +} + +#endif + +int git_fs_path_dirload( + git_vector *contents, + const char *path, + size_t prefix_len, + uint32_t flags) +{ + git_fs_path_diriter iter = GIT_FS_PATH_DIRITER_INIT; + const char *name; + size_t name_len; + char *dup; + int error; + + GIT_ASSERT_ARG(contents); + GIT_ASSERT_ARG(path); + + if ((error = git_fs_path_diriter_init(&iter, path, flags)) < 0) + return error; + + while ((error = git_fs_path_diriter_next(&iter)) == 0) { + if ((error = git_fs_path_diriter_fullpath(&name, &name_len, &iter)) < 0) + break; + + GIT_ASSERT(name_len > prefix_len); + + dup = git__strndup(name + prefix_len, name_len - prefix_len); + GIT_ERROR_CHECK_ALLOC(dup); + + if ((error = git_vector_insert(contents, dup)) < 0) + break; + } + + if (error == GIT_ITEROVER) + error = 0; + + git_fs_path_diriter_free(&iter); + return error; +} + +int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url_or_path) +{ + if (git_fs_path_is_local_file_url(url_or_path)) + return git_fs_path_fromurl(local_path_out, url_or_path); + else + return git_str_sets(local_path_out, url_or_path); +} + +/* Reject paths like AUX or COM1, or those versions that end in a dot or + * colon. ("AUX." or "AUX:") + */ +GIT_INLINE(bool) validate_dospath( + const char *component, + size_t len, + const char dospath[3], + bool trailing_num) +{ + size_t last = trailing_num ? 4 : 3; + + if (len < last || git__strncasecmp(component, dospath, 3) != 0) + return true; + + if (trailing_num && (component[3] < '1' || component[3] > '9')) + return true; + + return (len > last && + component[last] != '.' && + component[last] != ':'); +} + +GIT_INLINE(bool) validate_char(unsigned char c, unsigned int flags) +{ + if ((flags & GIT_FS_PATH_REJECT_BACKSLASH) && c == '\\') + return false; + + if ((flags & GIT_FS_PATH_REJECT_SLASH) && c == '/') + return false; + + if (flags & GIT_FS_PATH_REJECT_NT_CHARS) { + if (c < 32) + return false; + + switch (c) { + case '<': + case '>': + case ':': + case '"': + case '|': + case '?': + case '*': + return false; + } + } + + return true; +} + +/* + * We fundamentally don't like some paths when dealing with user-inputted + * strings (to avoid escaping a sandbox): we don't want dot or dot-dot + * anywhere, we want to avoid writing weird paths on Windows that can't + * be handled by tools that use the non-\\?\ APIs, we don't want slashes + * or double slashes at the end of paths that can make them ambiguous. + * + * For checkout, we don't want to recurse into ".git" either. + */ +static bool validate_component( + const char *component, + size_t len, + unsigned int flags) +{ + if (len == 0) + return false; + + if ((flags & GIT_FS_PATH_REJECT_TRAVERSAL) && + len == 1 && component[0] == '.') + return false; + + if ((flags & GIT_FS_PATH_REJECT_TRAVERSAL) && + len == 2 && component[0] == '.' && component[1] == '.') + return false; + + if ((flags & GIT_FS_PATH_REJECT_TRAILING_DOT) && + component[len - 1] == '.') + return false; + + if ((flags & GIT_FS_PATH_REJECT_TRAILING_SPACE) && + component[len - 1] == ' ') + return false; + + if ((flags & GIT_FS_PATH_REJECT_TRAILING_COLON) && + component[len - 1] == ':') + return false; + + if (flags & GIT_FS_PATH_REJECT_DOS_PATHS) { + if (!validate_dospath(component, len, "CON", false) || + !validate_dospath(component, len, "PRN", false) || + !validate_dospath(component, len, "AUX", false) || + !validate_dospath(component, len, "NUL", false) || + !validate_dospath(component, len, "COM", true) || + !validate_dospath(component, len, "LPT", true)) + return false; + } + + return true; +} + +bool git_fs_path_validate_ext( + const char *path, + unsigned int flags, + bool (*validate_char_cb)(char ch, void *payload), + bool (*validate_component_cb)(const char *component, size_t len, void *payload), + void *payload) +{ + const char *start, *c; + + for (start = c = path; *c; c++) { + if (!validate_char(*c, flags)) + return false; + + if (validate_char_cb && !validate_char_cb(*c, payload)) + return false; + + if (*c != '/') + continue; + + if (!validate_component(start, (c - start), flags)) + return false; + + if (validate_component_cb && + !validate_component_cb(start, (c - start), payload)) + return false; + + start = c + 1; + } + + if (!validate_component(start, (c - start), flags)) + return false; + + if (validate_component_cb && + !validate_component_cb(start, (c - start), payload)) + return false; + + return true; +} + +bool git_fs_path_validate(const char *path, unsigned int flags) +{ + return git_fs_path_validate_ext(path, flags, NULL, NULL, NULL); +} + +#ifdef GIT_WIN32 +GIT_INLINE(bool) should_validate_longpaths(git_repository *repo) +{ + int longpaths = 0; + + if (repo && + git_repository__configmap_lookup(&longpaths, repo, GIT_CONFIGMAP_LONGPATHS) < 0) + longpaths = 0; + + return (longpaths == 0); +} + +#else + +GIT_INLINE(bool) should_validate_longpaths(git_repository *repo) +{ + GIT_UNUSED(repo); + + return false; +} +#endif + +int git_fs_path_validate_workdir(git_repository *repo, const char *path) +{ + if (should_validate_longpaths(repo)) + return git_fs_path_validate_filesystem(path, strlen(path)); + + return 0; +} + +int git_fs_path_validate_workdir_with_len( + git_repository *repo, + const char *path, + size_t path_len) +{ + if (should_validate_longpaths(repo)) + return git_fs_path_validate_filesystem(path, path_len); + + return 0; +} + +int git_fs_path_validate_workdir_buf(git_repository *repo, git_str *path) +{ + return git_fs_path_validate_workdir_with_len(repo, path->ptr, path->size); +} + +int git_fs_path_normalize_slashes(git_str *out, const char *path) +{ + int error; + char *p; + + if ((error = git_str_puts(out, path)) < 0) + return error; + + for (p = out->ptr; *p; p++) { + if (*p == '\\') + *p = '/'; + } + + return 0; +} + +bool git_fs_path_supports_symlinks(const char *dir) +{ + git_str path = GIT_STR_INIT; + bool supported = false; + struct stat st; + int fd; + + if ((fd = git_futils_mktmp(&path, dir, 0666)) < 0 || + p_close(fd) < 0 || + p_unlink(path.ptr) < 0 || + p_symlink("testing", path.ptr) < 0 || + p_lstat(path.ptr, &st) < 0) + goto done; + + supported = (S_ISLNK(st.st_mode) != 0); +done: + if (path.size) + (void)p_unlink(path.ptr); + git_str_dispose(&path); + return supported; +} + +int git_fs_path_validate_system_file_ownership(const char *path) +{ +#ifndef GIT_WIN32 + GIT_UNUSED(path); + return GIT_OK; +#else + git_win32_path buf; + PSID owner_sid; + PSECURITY_DESCRIPTOR descriptor = NULL; + HANDLE token; + TOKEN_USER *info = NULL; + DWORD err, len; + int ret; + + if (git_win32_path_from_utf8(buf, path) < 0) + return -1; + + err = GetNamedSecurityInfoW(buf, SE_FILE_OBJECT, + OWNER_SECURITY_INFORMATION | + DACL_SECURITY_INFORMATION, + &owner_sid, NULL, NULL, NULL, &descriptor); + + if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) { + ret = GIT_ENOTFOUND; + goto cleanup; + } + + if (err != ERROR_SUCCESS) { + git_error_set(GIT_ERROR_OS, "failed to get security information"); + ret = GIT_ERROR; + goto cleanup; + } + + if (!IsValidSid(owner_sid)) { + git_error_set(GIT_ERROR_INVALID, "programdata configuration file owner is unknown"); + ret = GIT_ERROR; + goto cleanup; + } + + if (IsWellKnownSid(owner_sid, WinBuiltinAdministratorsSid) || + IsWellKnownSid(owner_sid, WinLocalSystemSid)) { + ret = GIT_OK; + goto cleanup; + } + + /* Obtain current user's SID */ + if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token) && + !GetTokenInformation(token, TokenUser, NULL, 0, &len)) { + info = git__malloc(len); + GIT_ERROR_CHECK_ALLOC(info); + if (!GetTokenInformation(token, TokenUser, info, len, &len)) { + git__free(info); + info = NULL; + } + } + + /* + * If the file is owned by the same account that is running the current + * process, it's okay to read from that file. + */ + if (info && EqualSid(owner_sid, info->User.Sid)) + ret = GIT_OK; + else { + git_error_set(GIT_ERROR_INVALID, "programdata configuration file owner is not valid"); + ret = GIT_ERROR; + } + git__free(info); + +cleanup: + if (descriptor) + LocalFree(descriptor); + + return ret; +#endif +} diff --git a/src/fs_path.h b/src/fs_path.h new file mode 100644 index 000000000..a60a37d98 --- /dev/null +++ b/src/fs_path.h @@ -0,0 +1,728 @@ +/* + * Copyright (C) the libgit2 contributors. All rights reserved. + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ +#ifndef INCLUDE_fs_path_h__ +#define INCLUDE_fs_path_h__ + +#include "common.h" + +#include "posix.h" +#include "str.h" +#include "vector.h" + +#include "git2/sys/path.h" + +/** + * Path manipulation utils + * + * These are path utilities that munge paths without actually + * looking at the real filesystem. + */ + +/* + * The dirname() function shall take a pointer to a character string + * that contains a pathname, and return a pointer to a string that is a + * pathname of the parent directory of that file. Trailing '/' characters + * in the path are not counted as part of the path. + * + * If path does not contain a '/', then dirname() shall return a pointer to + * the string ".". If path is a null pointer or points to an empty string, + * dirname() shall return a pointer to the string "." . + * + * The `git_fs_path_dirname` implementation is thread safe. The returned + * string must be manually free'd. + * + * The `git_fs_path_dirname_r` implementation writes the dirname to a `git_str` + * if the buffer pointer is not NULL. + * It returns an error code < 0 if there is an allocation error, otherwise + * the length of the dirname (which will be > 0). + */ +extern char *git_fs_path_dirname(const char *path); +extern int git_fs_path_dirname_r(git_str *buffer, const char *path); + +/* + * This function returns the basename of the file, which is the last + * part of its full name given by fname, with the drive letter and + * leading directories stripped off. For example, the basename of + * c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo. + * + * Trailing slashes and backslashes are significant: the basename of + * c:/foo/bar/ is an empty string after the rightmost slash. + * + * The `git_fs_path_basename` implementation is thread safe. The returned + * string must be manually free'd. + * + * The `git_fs_path_basename_r` implementation writes the basename to a `git_str`. + * It returns an error code < 0 if there is an allocation error, otherwise + * the length of the basename (which will be >= 0). + */ +extern char *git_fs_path_basename(const char *path); +extern int git_fs_path_basename_r(git_str *buffer, const char *path); + +/* Return the offset of the start of the basename. Unlike the other + * basename functions, this returns 0 if the path is empty. + */ +extern size_t git_fs_path_basename_offset(git_str *buffer); + +/** + * Find offset to root of path if path has one. + * + * This will return a number >= 0 which is the offset to the start of the + * path, if the path is rooted (i.e. "/rooted/path" returns 0 and + * "c:/windows/rooted/path" returns 2). If the path is not rooted, this + * returns -1. + */ +extern int git_fs_path_root(const char *path); + +/** + * Ensure path has a trailing '/'. + */ +extern int git_fs_path_to_dir(git_str *path); + +/** + * Ensure string has a trailing '/' if there is space for it. + */ +extern void git_fs_path_string_to_dir(char *path, size_t size); + +/** + * Taken from git.git; returns nonzero if the given path is "." or "..". + */ +GIT_INLINE(int) git_fs_path_is_dot_or_dotdot(const char *name) +{ + return (name[0] == '.' && + (name[1] == '\0' || + (name[1] == '.' && name[2] == '\0'))); +} + +#ifdef GIT_WIN32 +GIT_INLINE(int) git_fs_path_is_dot_or_dotdotW(const wchar_t *name) +{ + return (name[0] == L'.' && + (name[1] == L'\0' || + (name[1] == L'.' && name[2] == L'\0'))); +} + +#define git_fs_path_is_absolute(p) \ + (git__isalpha((p)[0]) && (p)[1] == ':' && ((p)[2] == '\\' || (p)[2] == '/')) + +#define git_fs_path_is_dirsep(p) \ + ((p) == '/' || (p) == '\\') + +/** + * Convert backslashes in path to forward slashes. + */ +GIT_INLINE(void) git_fs_path_mkposix(char *path) +{ + while (*path) { + if (*path == '\\') + *path = '/'; + + path++; + } +} +#else +# define git_fs_path_mkposix(p) /* blank */ + +#define git_fs_path_is_absolute(p) \ + ((p)[0] == '/') + +#define git_fs_path_is_dirsep(p) \ + ((p) == '/') + +#endif + +/** + * Check if string is a relative path (i.e. starts with "./" or "../") + */ +GIT_INLINE(int) git_fs_path_is_relative(const char *p) +{ + return (p[0] == '.' && (p[1] == '/' || (p[1] == '.' && p[2] == '/'))); +} + +/** + * Check if string is at end of path segment (i.e. looking at '/' or '\0') + */ +GIT_INLINE(int) git_fs_path_at_end_of_segment(const char *p) +{ + return !*p || *p == '/'; +} + +extern int git__percent_decode(git_str *decoded_out, const char *input); + +/** + * Extract path from file:// URL. + */ +extern int git_fs_path_fromurl(git_str *local_path_out, const char *file_url); + + +/** + * Path filesystem utils + * + * These are path utilities that actually access the filesystem. + */ + +/** + * Check if a file exists and can be accessed. + * @return true or false + */ +extern bool git_fs_path_exists(const char *path); + +/** + * Check if the given path points to a directory. + * @return true or false + */ +extern bool git_fs_path_isdir(const char *path); + +/** + * Check if the given path points to a regular file. + * @return true or false + */ +extern bool git_fs_path_isfile(const char *path); + +/** + * Check if the given path points to a symbolic link. + * @return true or false + */ +extern bool git_fs_path_islink(const char *path); + +/** + * Check if the given path is a directory, and is empty. + */ +extern bool git_fs_path_is_empty_dir(const char *path); + +/** + * Stat a file and/or link and set error if needed. + */ +extern int git_fs_path_lstat(const char *path, struct stat *st); + +/** + * Check if the parent directory contains the item. + * + * @param dir Directory to check. + * @param item Item that might be in the directory. + * @return 0 if item exists in directory, <0 otherwise. + */ +extern bool git_fs_path_contains(git_str *dir, const char *item); + +/** + * Check if the given path contains the given subdirectory. + * + * @param parent Directory path that might contain subdir + * @param subdir Subdirectory name to look for in parent + * @return true if subdirectory exists, false otherwise. + */ +extern bool git_fs_path_contains_dir(git_str *parent, const char *subdir); + +/** + * Determine the common directory length between two paths, including + * the final path separator. For example, given paths 'a/b/c/1.txt + * and 'a/b/c/d/2.txt', the common directory is 'a/b/c/', and this + * will return the length of the string 'a/b/c/', which is 6. + * + * @param one The first path + * @param two The second path + * @return The length of the common directory + */ +extern size_t git_fs_path_common_dirlen(const char *one, const char *two); + +/** + * Make the path relative to the given parent path. + * + * @param path The path to make relative + * @param parent The parent path to make path relative to + * @return 0 if path was made relative, GIT_ENOTFOUND + * if there was not common root between the paths, + * or <0. + */ +extern int git_fs_path_make_relative(git_str *path, const char *parent); + +/** + * Check if the given path contains the given file. + * + * @param dir Directory path that might contain file + * @param file File name to look for in parent + * @return true if file exists, false otherwise. + */ +extern bool git_fs_path_contains_file(git_str *dir, const char *file); + +/** + * Prepend base to unrooted path or just copy path over. + * + * This will optionally return the index into the path where the "root" + * is, either the end of the base directory prefix or the path root. + */ +extern int git_fs_path_join_unrooted( + git_str *path_out, const char *path, const char *base, ssize_t *root_at); + +/** + * Removes multiple occurrences of '/' in a row, squashing them into a + * single '/'. + */ +extern void git_fs_path_squash_slashes(git_str *path); + +/** + * Clean up path, prepending base if it is not already rooted. + */ +extern int git_fs_path_prettify(git_str *path_out, const char *path, const char *base); + +/** + * Clean up path, prepending base if it is not already rooted and + * appending a slash. + */ +extern int git_fs_path_prettify_dir(git_str *path_out, const char *path, const char *base); + +/** + * Get a directory from a path. + * + * If path is a directory, this acts like `git_fs_path_prettify_dir` + * (cleaning up path and appending a '/'). If path is a normal file, + * this prettifies it, then removed the filename a la dirname and + * appends the trailing '/'. If the path does not exist, it is + * treated like a regular filename. + */ +extern int git_fs_path_find_dir(git_str *dir); + +/** + * Resolve relative references within a path. + * + * This eliminates "./" and "../" relative references inside a path, + * as well as condensing multiple slashes into single ones. It will + * not touch the path before the "ceiling" length. + * + * Additionally, this will recognize an "c:/" drive prefix or a "xyz://" URL + * prefix and not touch that part of the path. + */ +extern int git_fs_path_resolve_relative(git_str *path, size_t ceiling); + +/** + * Apply a relative path to base path. + * + * Note that the base path could be a filename or a URL and this + * should still work. The relative path is walked segment by segment + * with three rules: series of slashes will be condensed to a single + * slash, "." will be eaten with no change, and ".." will remove a + * segment from the base path. + */ +extern int git_fs_path_apply_relative(git_str *target, const char *relpath); + +enum { + GIT_FS_PATH_DIR_IGNORE_CASE = (1u << 0), + GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE = (1u << 1), + GIT_FS_PATH_DIR_INCLUDE_DOT_AND_DOTDOT = (1u << 2), +}; + +/** + * Walk each directory entry, except '.' and '..', calling fn(state). + * + * @param pathbuf Buffer the function reads the initial directory + * path from, and updates with each successive entry's name. + * @param flags Combination of GIT_FS_PATH_DIR flags. + * @param callback Callback for each entry. Passed the `payload` and each + * successive path inside the directory as a full path. This may + * safely append text to the pathbuf if needed. Return non-zero to + * cancel iteration (and return value will be propagated back). + * @param payload Passed to callback as first argument. + * @return 0 on success or error code from OS error or from callback + */ +extern int git_fs_path_direach( + git_str *pathbuf, + uint32_t flags, + int (*callback)(void *payload, git_str *path), + void *payload); + +/** + * Sort function to order two paths + */ +extern int git_fs_path_cmp( + const char *name1, size_t len1, int isdir1, + const char *name2, size_t len2, int isdir2, + int (*compare)(const char *, const char *, size_t)); + +/** + * Invoke callback up path directory by directory until the ceiling is + * reached (inclusive of a final call at the root_path). + * + * Returning anything other than 0 from the callback function + * will stop the iteration and propagate the error to the caller. + * + * @param pathbuf Buffer the function reads the directory from and + * and updates with each successive name. + * @param ceiling Prefix of path at which to stop walking up. If NULL, + * this will walk all the way up to the root. If not a prefix of + * pathbuf, the callback will be invoked a single time on the + * original input path. + * @param callback Function to invoke on each path. Passed the `payload` + * and the buffer containing the current path. The path should not + * be modified in any way. Return non-zero to stop iteration. + * @param payload Passed to fn as the first ath. + */ +extern int git_fs_path_walk_up( + git_str *pathbuf, + const char *ceiling, + int (*callback)(void *payload, const char *path), + void *payload); + + +enum { + GIT_FS_PATH_NOTEQUAL = 0, + GIT_FS_PATH_EQUAL = 1, + GIT_FS_PATH_PREFIX = 2 +}; + +/* + * Determines if a path is equal to or potentially a child of another. + * @param parent The possible parent + * @param child The possible child + */ +GIT_INLINE(int) git_fs_path_equal_or_prefixed( + const char *parent, + const char *child, + ssize_t *prefixlen) +{ + const char *p = parent, *c = child; + int lastslash = 0; + + while (*p && *c) { + lastslash = (*p == '/'); + + if (*p++ != *c++) + return GIT_FS_PATH_NOTEQUAL; + } + + if (*p != '\0') + return GIT_FS_PATH_NOTEQUAL; + + if (*c == '\0') { + if (prefixlen) + *prefixlen = p - parent; + + return GIT_FS_PATH_EQUAL; + } + + if (*c == '/' || lastslash) { + if (prefixlen) + *prefixlen = (p - parent) - lastslash; + + return GIT_FS_PATH_PREFIX; + } + + return GIT_FS_PATH_NOTEQUAL; +} + +/* translate errno to libgit2 error code and set error message */ +extern int git_fs_path_set_error( + int errno_value, const char *path, const char *action); + +/* check if non-ascii characters are present in filename */ +extern bool git_fs_path_has_non_ascii(const char *path, size_t pathlen); + +#define GIT_PATH_REPO_ENCODING "UTF-8" + +#ifdef __APPLE__ +#define GIT_PATH_NATIVE_ENCODING "UTF-8-MAC" +#else +#define GIT_PATH_NATIVE_ENCODING "UTF-8" +#endif + +#ifdef GIT_USE_ICONV + +#include + +typedef struct { + iconv_t map; + git_str buf; +} git_fs_path_iconv_t; + +#define GIT_PATH_ICONV_INIT { (iconv_t)-1, GIT_STR_INIT } + +/* Init iconv data for converting decomposed UTF-8 to precomposed */ +extern int git_fs_path_iconv_init_precompose(git_fs_path_iconv_t *ic); + +/* Clear allocated iconv data */ +extern void git_fs_path_iconv_clear(git_fs_path_iconv_t *ic); + +/* + * Rewrite `in` buffer using iconv map if necessary, replacing `in` + * pointer internal iconv buffer if rewrite happened. The `in` pointer + * will be left unchanged if no rewrite was needed. + */ +extern int git_fs_path_iconv(git_fs_path_iconv_t *ic, const char **in, size_t *inlen); + +#endif /* GIT_USE_ICONV */ + +extern bool git_fs_path_does_decompose_unicode(const char *root); + + +typedef struct git_fs_path_diriter git_fs_path_diriter; + +#if defined(GIT_WIN32) && !defined(__MINGW32__) + +struct git_fs_path_diriter +{ + git_win32_path path; + size_t parent_len; + + git_str path_utf8; + size_t parent_utf8_len; + + HANDLE handle; + + unsigned int flags; + + WIN32_FIND_DATAW current; + unsigned int needs_next; +}; + +#define GIT_FS_PATH_DIRITER_INIT { {0}, 0, GIT_STR_INIT, 0, INVALID_HANDLE_VALUE } + +#else + +struct git_fs_path_diriter +{ + git_str path; + size_t parent_len; + + unsigned int flags; + + DIR *dir; + +#ifdef GIT_USE_ICONV + git_fs_path_iconv_t ic; +#endif +}; + +#define GIT_FS_PATH_DIRITER_INIT { GIT_STR_INIT } + +#endif + +/** + * Initialize a directory iterator. + * + * @param diriter Pointer to a diriter structure that will be setup. + * @param path The path that will be iterated over + * @param flags Directory reader flags + * @return 0 or an error code + */ +extern int git_fs_path_diriter_init( + git_fs_path_diriter *diriter, + const char *path, + unsigned int flags); + +/** + * Advance the directory iterator. Will return GIT_ITEROVER when + * the iteration has completed successfully. + * + * @param diriter The directory iterator + * @return 0, GIT_ITEROVER, or an error code + */ +extern int git_fs_path_diriter_next(git_fs_path_diriter *diriter); + +/** + * Returns the file name of the current item in the iterator. + * + * @param out Pointer to store the path in + * @param out_len Pointer to store the length of the path in + * @param diriter The directory iterator + * @return 0 or an error code + */ +extern int git_fs_path_diriter_filename( + const char **out, + size_t *out_len, + git_fs_path_diriter *diriter); + +/** + * Returns the full path of the current item in the iterator; that + * is the current filename plus the path of the directory that the + * iterator was constructed with. + * + * @param out Pointer to store the path in + * @param out_len Pointer to store the length of the path in + * @param diriter The directory iterator + * @return 0 or an error code + */ +extern int git_fs_path_diriter_fullpath( + const char **out, + size_t *out_len, + git_fs_path_diriter *diriter); + +/** + * Performs an `lstat` on the current item in the iterator. + * + * @param out Pointer to store the stat data in + * @param diriter The directory iterator + * @return 0 or an error code + */ +extern int git_fs_path_diriter_stat(struct stat *out, git_fs_path_diriter *diriter); + +/** + * Closes the directory iterator. + * + * @param diriter The directory iterator + */ +extern void git_fs_path_diriter_free(git_fs_path_diriter *diriter); + +/** + * Load all directory entries (except '.' and '..') into a vector. + * + * For cases where `git_fs_path_direach()` is not appropriate, this + * allows you to load the filenames in a directory into a vector + * of strings. That vector can then be sorted, iterated, or whatever. + * Remember to free alloc of the allocated strings when you are done. + * + * @param contents Vector to fill with directory entry names. + * @param path The directory to read from. + * @param prefix_len When inserting entries, the trailing part of path + * will be prefixed after this length. I.e. given path "/a/b" and + * prefix_len 3, the entries will look like "b/e1", "b/e2", etc. + * @param flags Combination of GIT_FS_PATH_DIR flags. + */ +extern int git_fs_path_dirload( + git_vector *contents, + const char *path, + size_t prefix_len, + uint32_t flags); + + +/* Used for paths to repositories on the filesystem */ +extern bool git_fs_path_is_local_file_url(const char *file_url); +extern int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url_or_path); + +/* Flags to determine path validity in `git_fs_path_isvalid` */ +#define GIT_FS_PATH_REJECT_TRAVERSAL (1 << 0) +#define GIT_FS_PATH_REJECT_SLASH (1 << 2) +#define GIT_FS_PATH_REJECT_BACKSLASH (1 << 3) +#define GIT_FS_PATH_REJECT_TRAILING_DOT (1 << 4) +#define GIT_FS_PATH_REJECT_TRAILING_SPACE (1 << 5) +#define GIT_FS_PATH_REJECT_TRAILING_COLON (1 << 6) +#define GIT_FS_PATH_REJECT_DOS_PATHS (1 << 7) +#define GIT_FS_PATH_REJECT_NT_CHARS (1 << 8) + +#define GIT_FS_PATH_REJECT_MAX (1 << 8) + +/* Default path safety for writing files to disk: since we use the + * Win32 "File Namespace" APIs ("\\?\") we need to protect from + * paths that the normal Win32 APIs would not write. + */ +#ifdef GIT_WIN32 +# define GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS \ + GIT_FS_PATH_REJECT_TRAVERSAL | \ + GIT_FS_PATH_REJECT_BACKSLASH | \ + GIT_FS_PATH_REJECT_TRAILING_DOT | \ + GIT_FS_PATH_REJECT_TRAILING_SPACE | \ + GIT_FS_PATH_REJECT_TRAILING_COLON | \ + GIT_FS_PATH_REJECT_DOS_PATHS | \ + GIT_FS_PATH_REJECT_NT_CHARS +#else +# define GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS \ + GIT_FS_PATH_REJECT_TRAVERSAL +#endif + +/** + * Validate a filesystem path. This ensures that the given path is legal + * and does not contain any "unsafe" components like path traversal ('.' + * or '..'), characters that are inappropriate for lesser filesystems + * (trailing ' ' or ':' characters), or filenames ("component names") + * that are not supported ('AUX', 'COM1"). + */ +extern bool git_fs_path_validate(const char *path, unsigned int flags); + +/** + * Validate a filesystem path; with custom callbacks per-character and + * per-path component. + */ +extern bool git_fs_path_validate_ext( + const char *path, + unsigned int flags, + bool (*validate_char_cb)(char ch, void *payload), + bool (*validate_component_cb)(const char *component, size_t len, void *payload), + void *payload); + +/** + * Validate an on-disk path, taking into account that it will have a + * suffix appended (eg, `.lock`). + */ +GIT_INLINE(int) git_fs_path_validate_filesystem_with_suffix( + const char *path, + size_t path_len, + size_t suffix_len) +{ +#ifdef GIT_WIN32 + size_t path_chars, total_chars; + + path_chars = git_utf8_char_length(path, path_len); + + if (GIT_ADD_SIZET_OVERFLOW(&total_chars, path_chars, suffix_len) || + total_chars > MAX_PATH) { + git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%s'", path); + return -1; + } + return 0; +#else + GIT_UNUSED(path); + GIT_UNUSED(path_len); + GIT_UNUSED(suffix_len); + return 0; +#endif +} + +/** + * Validate an path on the filesystem. This ensures that the given + * path is valid for the operating system/platform; for example, this + * will ensure that the given absolute path is smaller than MAX_PATH on + * Windows. + * + * For paths within the working directory, you should use ensure that + * `core.longpaths` is obeyed. Use `git_fs_path_validate_workdir`. + */ +GIT_INLINE(int) git_fs_path_validate_filesystem( + const char *path, + size_t path_len) +{ + return git_fs_path_validate_filesystem_with_suffix(path, path_len, 0); +} + +/** + * Validate a path relative to the repo's worktree. This ensures that + * the given working tree path is valid for the operating system/platform. + * This will ensure that an absolute path is smaller than MAX_PATH on + * Windows, while keeping `core.longpaths` configuration settings in mind. + * + * This should be checked by mechamisms like `git_checkout` after + * contructing on-disk paths and before trying to write them. + * + * If the repository is null, no repository configuration is applied. + */ +extern int git_fs_path_validate_workdir( + git_repository *repo, + const char *path); +extern int git_fs_path_validate_workdir_with_len( + git_repository *repo, + const char *path, + size_t path_len); +extern int git_fs_path_validate_workdir_buf( + git_repository *repo, + git_str *buf); + +/** + * Convert any backslashes into slashes + */ +int git_fs_path_normalize_slashes(git_str *out, const char *path); + +bool git_fs_path_supports_symlinks(const char *dir); + +/** + * Validate a system file's ownership + * + * Verify that the file in question is owned by an administrator or system + * account, or at least by the current user. + * + * This function returns 0 if successful. If the file is not owned by any of + * these, or any other if there have been problems determining the file + * ownership, it returns -1. + */ +int git_fs_path_validate_system_file_ownership(const char *path); + +#endif diff --git a/src/futils.c b/src/futils.c index 9a15ceeb9..7ec1009bd 100644 --- a/src/futils.c +++ b/src/futils.c @@ -99,7 +99,7 @@ int git_futils_open_ro(const char *path) { int fd = p_open(path, O_RDONLY); if (fd < 0) - return git_path_set_error(errno, path, "open"); + return git_fs_path_set_error(errno, path, "open"); return fd; } @@ -107,7 +107,7 @@ int git_futils_truncate(const char *path, int mode) { int fd = p_open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, mode); if (fd < 0) - return git_path_set_error(errno, path, "open"); + return git_fs_path_set_error(errno, path, "open"); close(fd); return 0; @@ -195,7 +195,7 @@ int git_futils_readbuffer_updated( *updated = 0; if (p_stat(path, &st) < 0) - return git_path_set_error(errno, path, "stat"); + return git_fs_path_set_error(errno, path, "stat"); if (S_ISDIR(st.st_mode)) { @@ -429,7 +429,7 @@ GIT_INLINE(int) mkdir_canonicalize( } /* Trim trailing slashes (except the root) */ - if ((root_len = git_path_root(path->ptr)) < 0) + if ((root_len = git_fs_path_root(path->ptr)) < 0) root_len = 0; else root_len++; @@ -439,11 +439,11 @@ GIT_INLINE(int) mkdir_canonicalize( /* if we are not supposed to made the last element, truncate it */ if ((flags & GIT_MKDIR_SKIP_LAST2) != 0) { - git_path_dirname_r(path, path->ptr); + git_fs_path_dirname_r(path, path->ptr); flags |= GIT_MKDIR_SKIP_LAST; } if ((flags & GIT_MKDIR_SKIP_LAST) != 0) { - git_path_dirname_r(path, path->ptr); + git_fs_path_dirname_r(path, path->ptr); } /* We were either given the root path (or trimmed it to @@ -473,7 +473,7 @@ int git_futils_mkdir( make_path.size == 0) goto done; - root_len = git_path_root(make_path.ptr); + root_len = git_fs_path_root(make_path.ptr); /* find the first parent directory that exists. this will be used * as the base to dirname_relative. @@ -492,7 +492,7 @@ int git_futils_mkdir( depth++; /* examine the parent of the current path */ - if ((len = git_path_dirname_r(&parent_path, parent_path.ptr)) < 0) { + if ((len = git_fs_path_dirname_r(&parent_path, parent_path.ptr)) < 0) { error = len; goto done; } @@ -569,7 +569,7 @@ int git_futils_mkdir_relative( opts = &empty_opts; /* build path and find "root" where we should start calling mkdir */ - if (git_path_join_unrooted(&make_path, relative_path, base, &root) < 0) + if (git_fs_path_join_unrooted(&make_path, relative_path, base, &root) < 0) return -1; if ((error = mkdir_canonicalize(&make_path, flags)) < 0 || @@ -581,7 +581,7 @@ int git_futils_mkdir_relative( root = git_str_rfind(&make_path, '/'); /* advance root past drive name or network mount prefix */ - min_root_len = git_path_root(make_path.ptr); + min_root_len = git_fs_path_root(make_path.ptr); if (root < min_root_len) root = min_root_len; while (root >= 0 && make_path.ptr[root] == '/') @@ -744,13 +744,13 @@ static int futils__rmdir_recurs_foreach(void *opaque, git_str *path) path->ptr, "parent is not directory"); } else - error = git_path_set_error(errno, path->ptr, "rmdir"); + error = git_fs_path_set_error(errno, path->ptr, "rmdir"); } else if (S_ISDIR(st.st_mode)) { data->depth++; - error = git_path_direach(path, 0, futils__rmdir_recurs_foreach, data); + error = git_fs_path_direach(path, 0, futils__rmdir_recurs_foreach, data); data->depth--; @@ -765,13 +765,13 @@ static int futils__rmdir_recurs_foreach(void *opaque, git_str *path) (errno == ENOTEMPTY || errno == EEXIST || errno == EBUSY)) error = 0; else - error = git_path_set_error(errno, path->ptr, "rmdir"); + error = git_fs_path_set_error(errno, path->ptr, "rmdir"); } } else if ((data->flags & GIT_RMDIR_REMOVE_FILES) != 0) { if (p_unlink(path->ptr) < 0) - error = git_path_set_error(errno, path->ptr, "remove"); + error = git_fs_path_set_error(errno, path->ptr, "remove"); } else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0) @@ -795,11 +795,11 @@ static int futils__rmdir_empty_parent(void *opaque, const char *path) /* do nothing */ } else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0 && en == EBUSY) { - error = git_path_set_error(errno, path, "rmdir"); + error = git_fs_path_set_error(errno, path, "rmdir"); } else if (en == ENOTEMPTY || en == EEXIST || en == EBUSY) { error = GIT_ITEROVER; } else { - error = git_path_set_error(errno, path, "rmdir"); + error = git_fs_path_set_error(errno, path, "rmdir"); } } @@ -814,7 +814,7 @@ int git_futils_rmdir_r( futils__rmdir_data data; /* build path and find "root" where we should start calling mkdir */ - if (git_path_join_unrooted(&fullpath, path, base, NULL) < 0) + if (git_fs_path_join_unrooted(&fullpath, path, base, NULL) < 0) return -1; memset(&data, 0, sizeof(data)); @@ -826,7 +826,7 @@ int git_futils_rmdir_r( /* remove now-empty parents if requested */ if (!error && (flags & GIT_RMDIR_EMPTY_PARENTS) != 0) - error = git_path_walk_up( + error = git_fs_path_walk_up( &fullpath, base, futils__rmdir_empty_parent, &data); if (error == GIT_ITEROVER) { @@ -887,7 +887,7 @@ int git_futils_cp(const char *from, const char *to, mode_t filemode) if ((ofd = p_open(to, O_WRONLY | O_CREAT | O_EXCL, filemode)) < 0) { p_close(ifd); - return git_path_set_error(errno, to, "open for writing"); + return git_fs_path_set_error(errno, to, "open for writing"); } return cp_by_fd(ifd, ofd, true); @@ -903,7 +903,7 @@ int git_futils_touch(const char *path, time_t *when) ret = p_utimes(path, times); - return (ret < 0) ? git_path_set_error(errno, path, "touch") : 0; + return (ret < 0) ? git_fs_path_set_error(errno, path, "touch") : 0; } static int cp_link(const char *from, const char *to, size_t link_size) @@ -977,14 +977,14 @@ static int _cp_r_callback(void *ref, git_str *from) bool exists = false; if ((info->flags & GIT_CPDIR_COPY_DOTFILES) == 0 && - from->ptr[git_path_basename_offset(from)] == '.') + from->ptr[git_fs_path_basename_offset(from)] == '.') return 0; if ((error = git_str_joinpath( &info->to, info->to_root, from->ptr + info->from_prefix)) < 0) return error; - if (!(error = git_path_lstat(info->to.ptr, &to_st))) + if (!(error = git_fs_path_lstat(info->to.ptr, &to_st))) exists = true; else if (error != GIT_ENOTFOUND) return error; @@ -993,7 +993,7 @@ static int _cp_r_callback(void *ref, git_str *from) error = 0; } - if ((error = git_path_lstat(from->ptr, &from_st)) < 0) + if ((error = git_fs_path_lstat(from->ptr, &from_st)) < 0) return error; if (S_ISDIR(from_st.st_mode)) { @@ -1009,7 +1009,7 @@ static int _cp_r_callback(void *ref, git_str *from) /* recurse onto target directory */ if (!error && (!exists || S_ISDIR(to_st.st_mode))) - error = git_path_direach(from, 0, _cp_r_callback, info); + error = git_fs_path_direach(from, 0, _cp_r_callback, info); if (oldmode != 0) info->dirmode = oldmode; @@ -1182,7 +1182,7 @@ int git_futils_fsync_parent(const char *path) char *parent; int error; - if ((parent = git_path_dirname(path)) == NULL) + if ((parent = git_fs_path_dirname(path)) == NULL) return -1; error = git_futils_fsync_dir(parent); diff --git a/src/futils.h b/src/futils.h index eea69adde..22098addf 100644 --- a/src/futils.h +++ b/src/futils.h @@ -11,7 +11,7 @@ #include "map.h" #include "posix.h" -#include "path.h" +#include "fs_path.h" #include "pool.h" #include "strmap.h" #include "hash.h" diff --git a/src/ignore.c b/src/ignore.c index eb9fd8a9e..e7d8b799f 100644 --- a/src/ignore.c +++ b/src/ignore.c @@ -10,7 +10,7 @@ #include "git2/ignore.h" #include "common.h" #include "attrcache.h" -#include "path.h" +#include "fs_path.h" #include "config.h" #include "wildmatch.h" @@ -181,7 +181,7 @@ static int parse_ignore_file( /* if subdir file path, convert context for file paths */ if (attrs->entry && - git_path_root(attrs->entry->path) < 0 && + git_fs_path_root(attrs->entry->path) < 0 && !git__suffixcmp(attrs->entry->path, "/" GIT_IGNORE_FILE)) context = attrs->entry->path; @@ -313,21 +313,21 @@ int git_ignore__for_path( goto cleanup; /* given a unrooted path in a non-bare repo, resolve it */ - if (workdir && git_path_root(path) < 0) { + if (workdir && git_fs_path_root(path) < 0) { git_str local = GIT_STR_INIT; - if ((error = git_path_dirname_r(&local, path)) < 0 || - (error = git_path_resolve_relative(&local, 0)) < 0 || - (error = git_path_to_dir(&local)) < 0 || + if ((error = git_fs_path_dirname_r(&local, path)) < 0 || + (error = git_fs_path_resolve_relative(&local, 0)) < 0 || + (error = git_fs_path_to_dir(&local)) < 0 || (error = git_str_joinpath(&ignores->dir, workdir, local.ptr)) < 0 || - (error = git_path_validate_workdir_buf(repo, &ignores->dir)) < 0) { + (error = git_fs_path_validate_workdir_buf(repo, &ignores->dir)) < 0) { /* Nothing, we just want to stop on the first error */ } git_str_dispose(&local); } else { if (!(error = git_str_joinpath(&ignores->dir, path, ""))) - error = git_path_validate_filesystem(ignores->dir.ptr, ignores->dir.size); + error = git_fs_path_validate_filesystem(ignores->dir.ptr, ignores->dir.size); } if (error < 0) @@ -342,7 +342,7 @@ int git_ignore__for_path( /* load .gitignore up the path */ if (workdir != NULL) { - error = git_path_walk_up( + error = git_fs_path_walk_up( &ignores->dir, workdir, push_one_ignore, ignores); if (error < 0) goto cleanup; @@ -410,7 +410,7 @@ int git_ignore__pop_dir(git_ignores *ign) if (--ign->depth > 0) { git_str_rtruncate_at_char(&ign->dir, '/'); - git_path_to_dir(&ign->dir); + git_fs_path_to_dir(&ign->dir); } return 0; @@ -629,7 +629,7 @@ int git_ignore__check_pathspec_for_exact_ignores( break; /* is there a file on disk that matches this exactly? */ - if (!git_path_isfile(path.ptr)) + if (!git_fs_path_isfile(path.ptr)) continue; /* is that file ignored? */ diff --git a/src/index.c b/src/index.c index b8aa310d3..448852f29 100644 --- a/src/index.c +++ b/src/index.c @@ -20,6 +20,7 @@ #include "idxmap.h" #include "diff.h" #include "varint.h" +#include "path.h" #include "git2/odb.h" #include "git2/oid.h" @@ -420,7 +421,7 @@ int git_index_open(git_index **index_out, const char *index_path) goto fail; /* Check if index file is stored on disk already */ - if (git_path_exists(index->index_file_path) == true) + if (git_fs_path_exists(index->index_file_path) == true) index->on_disk = 1; } @@ -648,7 +649,7 @@ int git_index_read(git_index *index, int force) return create_index_error(-1, "failed to read index: The index is in-memory only"); - index->on_disk = git_path_exists(index->index_file_path); + index->on_disk = git_fs_path_exists(index->index_file_path); if (!index->on_disk) { if (force && (error = git_index_clear(index)) < 0) @@ -991,7 +992,7 @@ static int index_entry_init( if (git_repository_workdir_path(&path, repo, rel_path) < 0) return -1; - error = git_path_lstat(path.ptr, &st); + error = git_fs_path_lstat(path.ptr, &st); git_str_dispose(&path); if (error < 0) @@ -1728,7 +1729,7 @@ int git_index_remove_directory(git_index *index, const char *dir, int stage) git_index_entry *entry; if (!(error = git_str_sets(&pfx, dir)) && - !(error = git_path_to_dir(&pfx))) + !(error = git_fs_path_to_dir(&pfx))) index_find(&pos, index, pfx.ptr, pfx.size, GIT_INDEX_STAGE_ANY); while (!error) { diff --git a/src/iterator.c b/src/iterator.c index 5549c636a..a627e0f88 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -472,7 +472,7 @@ GIT_INLINE(tree_iterator_frame *) tree_iterator_current_frame( GIT_INLINE(int) tree_entry_cmp( const git_tree_entry *a, const git_tree_entry *b, bool icase) { - return git_path_cmp( + return git_fs_path_cmp( a->filename, a->filename_len, a->attr == GIT_FILEMODE_TREE, b->filename, b->filename_len, b->attr == GIT_FILEMODE_TREE, icase ? git__strncasecmp : git__strncmp); @@ -1279,7 +1279,7 @@ static int filesystem_iterator_entry_hash( iter->base.repo, entry->path, GIT_OBJECT_BLOB, NULL); if (!(error = git_str_joinpath(&fullpath, iter->root, entry->path)) && - !(error = git_path_validate_workdir_buf(iter->base.repo, &fullpath))) + !(error = git_fs_path_validate_workdir_buf(iter->base.repo, &fullpath))) error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB); git_str_dispose(&fullpath); @@ -1336,7 +1336,7 @@ static int filesystem_iterator_frame_push( filesystem_iterator_entry *frame_entry) { filesystem_iterator_frame *new_frame = NULL; - git_path_diriter diriter = GIT_PATH_DIRITER_INIT; + git_fs_path_diriter diriter = GIT_FS_PATH_DIRITER_INIT; git_str root = GIT_STR_INIT; const char *path; filesystem_iterator_entry *entry; @@ -1361,7 +1361,7 @@ static int filesystem_iterator_frame_push( git_str_puts(&root, iter->root); if (git_str_oom(&root) || - git_path_validate_workdir_buf(iter->base.repo, &root) < 0) { + git_fs_path_validate_workdir_buf(iter->base.repo, &root) < 0) { error = -1; goto done; } @@ -1369,7 +1369,7 @@ static int filesystem_iterator_frame_push( new_frame->path_len = frame_entry ? frame_entry->path_len : 0; /* Any error here is equivalent to the dir not existing, skip over it */ - if ((error = git_path_diriter_init( + if ((error = git_fs_path_diriter_init( &diriter, root.ptr, iter->dirload_flags)) < 0) { error = GIT_ENOTFOUND; goto done; @@ -1387,12 +1387,12 @@ static int filesystem_iterator_frame_push( /* check if this directory is ignored */ filesystem_iterator_frame_push_ignores(iter, frame_entry, new_frame); - while ((error = git_path_diriter_next(&diriter)) == 0) { + while ((error = git_fs_path_diriter_next(&diriter)) == 0) { iterator_pathlist_search_t pathlist_match = ITERATOR_PATHLIST_FULL; bool dir_expected = false; - if ((error = git_path_diriter_fullpath(&path, &path_len, &diriter)) < 0 || - (error = git_path_validate_workdir_with_len(iter->base.repo, path, path_len)) < 0) + if ((error = git_fs_path_diriter_fullpath(&path, &path_len, &diriter)) < 0 || + (error = git_fs_path_validate_workdir_with_len(iter->base.repo, path, path_len)) < 0) goto done; GIT_ASSERT(path_len > iter->root_len); @@ -1414,7 +1414,7 @@ static int filesystem_iterator_frame_push( * we have an index, we can just copy the data out of it. */ - if ((error = git_path_diriter_stat(&statbuf, &diriter)) < 0) { + if ((error = git_fs_path_diriter_stat(&statbuf, &diriter)) < 0) { /* file was removed between readdir and lstat */ if (error == GIT_ENOTFOUND) continue; @@ -1472,7 +1472,7 @@ done: git_array_pop(iter->frames); git_str_dispose(&root); - git_path_diriter_free(&diriter); + git_fs_path_diriter_free(&diriter); return error; } @@ -1565,7 +1565,7 @@ static int filesystem_iterator_is_dir( } if ((error = git_str_joinpath(&fullpath, iter->root, entry->path)) < 0 || - (error = git_path_validate_workdir_buf(iter->base.repo, &fullpath)) < 0 || + (error = git_fs_path_validate_workdir_buf(iter->base.repo, &fullpath)) < 0 || (error = p_stat(fullpath.ptr, &st)) < 0) goto done; @@ -1961,9 +1961,10 @@ static int iterator_for_filesystem( iter->index = index; iter->dirload_flags = - (iterator__ignore_case(&iter->base) ? GIT_PATH_DIR_IGNORE_CASE : 0) | + (iterator__ignore_case(&iter->base) ? + GIT_FS_PATH_DIR_IGNORE_CASE : 0) | (iterator__flag(&iter->base, PRECOMPOSE_UNICODE) ? - GIT_PATH_DIR_PRECOMPOSE_UNICODE : 0); + GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE : 0); if ((error = filesystem_iterator_init(iter)) < 0) goto on_error; @@ -2058,7 +2059,7 @@ static bool index_iterator_create_pseudotree( prev_path = iter->entry ? iter->entry->path : ""; /* determine if the new path is in a different directory from the old */ - common_len = git_path_common_dirlen(prev_path, path); + common_len = git_fs_path_common_dirlen(prev_path, path); relative_path = path + common_len; if ((dirsep = strchr(relative_path, '/')) == NULL) diff --git a/src/mailmap.c b/src/mailmap.c index 38ae01645..4fbb1ae77 100644 --- a/src/mailmap.c +++ b/src/mailmap.c @@ -9,7 +9,7 @@ #include "common.h" #include "config.h" -#include "path.h" +#include "fs_path.h" #include "repository.h" #include "signature.h" #include "git2/config.h" @@ -327,11 +327,11 @@ static int mailmap_add_file_ondisk( git_str content = GIT_STR_INIT; int error; - error = git_path_join_unrooted(&fullpath, path, base, NULL); + error = git_fs_path_join_unrooted(&fullpath, path, base, NULL); if (error < 0) goto cleanup; - error = git_path_validate_workdir_buf(repo, &fullpath); + error = git_fs_path_validate_workdir_buf(repo, &fullpath); if (error < 0) goto cleanup; diff --git a/src/merge.c b/src/merge.c index ae1d453ec..ec7e5bfd1 100644 --- a/src/merge.c +++ b/src/merge.c @@ -12,7 +12,7 @@ #include "repository.h" #include "revwalk.h" #include "commit_list.h" -#include "path.h" +#include "fs_path.h" #include "refs.h" #include "object.h" #include "iterator.h" diff --git a/src/midx.c b/src/midx.c index b8da98986..d4f9bd5a0 100644 --- a/src/midx.c +++ b/src/midx.c @@ -14,7 +14,7 @@ #include "hash.h" #include "odb.h" #include "pack.h" -#include "path.h" +#include "fs_path.h" #include "repository.h" #include "str.h" @@ -502,7 +502,7 @@ int git_midx_writer_new( git__free(w); return -1; } - git_path_squash_slashes(&w->pack_dir); + git_fs_path_squash_slashes(&w->pack_dir); if (git_vector_init(&w->packs, 0, packfile__cmp) < 0) { git_str_dispose(&w->pack_dir); @@ -537,7 +537,7 @@ int git_midx_writer_add( int error; struct git_pack_file *p; - error = git_path_prettify(&idx_path_buf, idx_path, git_str_cstr(&w->pack_dir)); + error = git_fs_path_prettify(&idx_path_buf, idx_path, git_str_cstr(&w->pack_dir)); if (error < 0) return error; @@ -687,7 +687,7 @@ static int midx_write( error = git_str_sets(&relative_index, p->pack_name); if (error < 0) goto cleanup; - error = git_path_make_relative(&relative_index, git_str_cstr(&w->pack_dir)); + error = git_fs_path_make_relative(&relative_index, git_str_cstr(&w->pack_dir)); if (error < 0) { git_str_dispose(&relative_index); goto cleanup; diff --git a/src/odb.c b/src/odb.c index 7bf575474..5bc69c3f6 100644 --- a/src/odb.c +++ b/src/odb.c @@ -277,7 +277,7 @@ int git_odb__hashlink(git_oid *out, const char *path) int size; int result; - if (git_path_lstat(path, &st) < 0) + if (git_fs_path_lstat(path, &st) < 0) return -1; if (!git__is_int(st.st_size) || (int)st.st_size < 0) { @@ -649,7 +649,7 @@ static int load_alternates(git_odb *odb, const char *objects_dir, int alternate_ if (git_str_joinpath(&alternates_path, objects_dir, GIT_ALTERNATES_FILE) < 0) return -1; - if (git_path_exists(alternates_path.ptr) == false) { + if (git_fs_path_exists(alternates_path.ptr) == false) { git_str_dispose(&alternates_path); return 0; } diff --git a/src/odb_loose.c b/src/odb_loose.c index f0c3ac2c8..463e24fa5 100644 --- a/src/odb_loose.c +++ b/src/odb_loose.c @@ -87,7 +87,7 @@ static int object_file_name( return -1; git_str_set(name, be->objects_dir, be->objects_dirlen); - git_path_to_dir(name); + git_fs_path_to_dir(name); /* loose object filename: aa/aaa... (41 bytes) */ git_oid_pathfmt(name->ptr + name->size, id); @@ -452,7 +452,7 @@ static int locate_object( { int error = object_file_name(object_location, backend, oid); - if (!error && !git_path_exists(object_location->ptr)) + if (!error && !git_fs_path_exists(object_location->ptr)) return GIT_ENOTFOUND; return error; @@ -467,7 +467,7 @@ static int fn_locate_object_short_oid(void *state, git_str *pathbuf) { return 0; } - if (git_path_isdir(pathbuf->ptr) == false) { + if (git_fs_path_isdir(pathbuf->ptr) == false) { /* We are already in the directory matching the 2 first hex characters, * compare the first ncmp characters of the oids */ if (!memcmp(sstate->short_oid + 2, @@ -509,7 +509,7 @@ static int locate_object_short_oid( return -1; git_str_set(object_location, objects_dir, dir_len); - git_path_to_dir(object_location); + git_fs_path_to_dir(object_location); /* save adjusted position at end of dir so it can be restored later */ dir_len = git_str_len(object_location); @@ -523,7 +523,7 @@ static int locate_object_short_oid( object_location->ptr[object_location->size - 1] = '/'; /* Check that directory exists */ - if (git_path_isdir(object_location->ptr) == false) + if (git_fs_path_isdir(object_location->ptr) == false) return git_odb__error_notfound("no matching loose object for prefix", short_oid, len); @@ -532,7 +532,7 @@ static int locate_object_short_oid( state.found = 0; /* Explore directory to find a unique object matching short_oid */ - error = git_path_direach( + error = git_fs_path_direach( object_location, 0, fn_locate_object_short_oid, &state); if (error < 0 && error != GIT_EAMBIGUOUS) return error; @@ -753,10 +753,10 @@ static int foreach_cb(void *_state, git_str *path) struct foreach_state *state = (struct foreach_state *) _state; /* non-dir is some stray file, ignore it */ - if (!git_path_isdir(git_str_cstr(path))) + if (!git_fs_path_isdir(git_str_cstr(path))) return 0; - return git_path_direach(path, 0, foreach_object_dir_cb, state); + return git_fs_path_direach(path, 0, foreach_object_dir_cb, state); } static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data) @@ -773,7 +773,7 @@ static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb objects_dir = backend->objects_dir; git_str_sets(&buf, objects_dir); - git_path_to_dir(&buf); + git_fs_path_to_dir(&buf); if (git_str_oom(&buf)) return -1; @@ -782,7 +782,7 @@ static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb state.data = data; state.dir_len = git_str_len(&buf); - error = git_path_direach(&buf, 0, foreach_cb, &state); + error = git_fs_path_direach(&buf, 0, foreach_cb, &state); git_str_dispose(&buf); diff --git a/src/odb_pack.c b/src/odb_pack.c index f2c47adbe..5b7521029 100644 --- a/src/odb_pack.c +++ b/src/odb_pack.c @@ -524,7 +524,7 @@ static int pack_backend__refresh(git_odb_backend *backend_) /* reload all packs */ git_str_sets(&path, backend->pack_folder); - error = git_path_direach(&path, 0, packfile_load__cb, backend); + error = git_fs_path_direach(&path, 0, packfile_load__cb, backend); git_str_dispose(&path); git_vector_sort(&backend->packs); @@ -750,7 +750,7 @@ static int get_idx_path( size_t path_len; int error; - error = git_path_prettify(idx_path, p->pack_name, backend->pack_folder); + error = git_fs_path_prettify(idx_path, p->pack_name, backend->pack_folder); if (error < 0) return error; path_len = git_str_len(idx_path); @@ -902,7 +902,7 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir) return -1; if (!(error = git_str_joinpath(&path, objects_dir, "pack")) && - git_path_isdir(git_str_cstr(&path))) + git_fs_path_isdir(git_str_cstr(&path))) { backend->pack_folder = git_str_detach(&path); error = pack_backend__refresh((git_odb_backend *)backend); diff --git a/src/pack.c b/src/pack.c index e17d20f8c..5c0cba7e8 100644 --- a/src/pack.c +++ b/src/pack.c @@ -1198,7 +1198,7 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path) if (!git_disable_pack_keep_file_checks) { memcpy(p->pack_name + root_len, ".keep", sizeof(".keep")); - if (git_path_exists(p->pack_name) == true) + if (git_fs_path_exists(p->pack_name) == true) p->pack_keep = 1; } diff --git a/src/patch_parse.c b/src/patch_parse.c index fce4bc9e4..891cf79a3 100644 --- a/src/patch_parse.c +++ b/src/patch_parse.c @@ -10,7 +10,7 @@ #include "git2/patch.h" #include "patch.h" #include "diff_parse.h" -#include "path.h" +#include "fs_path.h" typedef struct { git_patch base; @@ -80,7 +80,7 @@ static int parse_header_path_buf(git_str *path, git_patch_parse_ctx *ctx, size_t (error = git_str_unquote(path)) < 0) return error; - git_path_squash_slashes(path); + git_fs_path_squash_slashes(path); if (!path->size) return git_parse_err("patch contains empty path at line %"PRIuZ, diff --git a/src/path.c b/src/path.c index d8d33a141..d34125128 100644 --- a/src/path.c +++ b/src/path.c @@ -7,1555 +7,14 @@ #include "path.h" -#include "posix.h" #include "repository.h" -#ifdef GIT_WIN32 -#include "win32/posix.h" -#include "win32/w32_buffer.h" -#include "win32/w32_util.h" -#include "win32/version.h" -#include -#else -#include -#endif -#include -#include - -static int dos_drive_prefix_length(const char *path) -{ - int i; - - /* - * Does it start with an ASCII letter (i.e. highest bit not set), - * followed by a colon? - */ - if (!(0x80 & (unsigned char)*path)) - return *path && path[1] == ':' ? 2 : 0; - - /* - * While drive letters must be letters of the English alphabet, it is - * possible to assign virtually _any_ Unicode character via `subst` as - * a drive letter to "virtual drives". Even `1`, or `ä`. Or fun stuff - * like this: - * - * subst ֍: %USERPROFILE%\Desktop - */ - for (i = 1; i < 4 && (0x80 & (unsigned char)path[i]); i++) - ; /* skip first UTF-8 character */ - return path[i] == ':' ? i + 1 : 0; -} - -#ifdef GIT_WIN32 -static bool looks_like_network_computer_name(const char *path, int pos) -{ - if (pos < 3) - return false; - - if (path[0] != '/' || path[1] != '/') - return false; - - while (pos-- > 2) { - if (path[pos] == '/') - return false; - } - - return true; -} -#endif - -/* - * Based on the Android implementation, BSD licensed. - * http://android.git.kernel.org/ - * - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -int git_path_basename_r(git_str *buffer, const char *path) -{ - const char *endp, *startp; - int len, result; - - /* Empty or NULL string gets treated as "." */ - if (path == NULL || *path == '\0') { - startp = "."; - len = 1; - goto Exit; - } - - /* Strip trailing slashes */ - endp = path + strlen(path) - 1; - while (endp > path && *endp == '/') - endp--; - - /* All slashes becomes "/" */ - if (endp == path && *endp == '/') { - startp = "/"; - len = 1; - goto Exit; - } - - /* Find the start of the base */ - startp = endp; - while (startp > path && *(startp - 1) != '/') - startp--; - - /* Cast is safe because max path < max int */ - len = (int)(endp - startp + 1); - -Exit: - result = len; - - if (buffer != NULL && git_str_set(buffer, startp, len) < 0) - return -1; - - return result; -} - -/* - * Determine if the path is a Windows prefix and, if so, returns - * its actual lentgh. If it is not a prefix, returns -1. - */ -static int win32_prefix_length(const char *path, int len) -{ -#ifndef GIT_WIN32 - GIT_UNUSED(path); - GIT_UNUSED(len); -#else - /* - * Mimic unix behavior where '/.git' returns '/': 'C:/.git' - * will return 'C:/' here - */ - if (dos_drive_prefix_length(path) == len) - return len; - - /* - * Similarly checks if we're dealing with a network computer name - * '//computername/.git' will return '//computername/' - */ - if (looks_like_network_computer_name(path, len)) - return len; -#endif - - return -1; -} - -/* - * Based on the Android implementation, BSD licensed. - * Check http://android.git.kernel.org/ - */ -int git_path_dirname_r(git_str *buffer, const char *path) -{ - const char *endp; - int is_prefix = 0, len; - - /* Empty or NULL string gets treated as "." */ - if (path == NULL || *path == '\0') { - path = "."; - len = 1; - goto Exit; - } - - /* Strip trailing slashes */ - endp = path + strlen(path) - 1; - while (endp > path && *endp == '/') - endp--; - - if (endp - path + 1 > INT_MAX) { - git_error_set(GIT_ERROR_INVALID, "path too long"); - len = -1; - goto Exit; - } - - if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) { - is_prefix = 1; - goto Exit; - } - - /* Find the start of the dir */ - while (endp > path && *endp != '/') - endp--; - - /* Either the dir is "/" or there are no slashes */ - if (endp == path) { - path = (*endp == '/') ? "/" : "."; - len = 1; - goto Exit; - } - - do { - endp--; - } while (endp > path && *endp == '/'); - - if (endp - path + 1 > INT_MAX) { - git_error_set(GIT_ERROR_INVALID, "path too long"); - len = -1; - goto Exit; - } - - if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) { - is_prefix = 1; - goto Exit; - } - - /* Cast is safe because max path < max int */ - len = (int)(endp - path + 1); - -Exit: - if (buffer) { - if (git_str_set(buffer, path, len) < 0) - return -1; - if (is_prefix && git_str_putc(buffer, '/') < 0) - return -1; - } - - return len; -} - - -char *git_path_dirname(const char *path) -{ - git_str buf = GIT_STR_INIT; - char *dirname; - - git_path_dirname_r(&buf, path); - dirname = git_str_detach(&buf); - git_str_dispose(&buf); /* avoid memleak if error occurs */ - - return dirname; -} - -char *git_path_basename(const char *path) -{ - git_str buf = GIT_STR_INIT; - char *basename; - - git_path_basename_r(&buf, path); - basename = git_str_detach(&buf); - git_str_dispose(&buf); /* avoid memleak if error occurs */ - - return basename; -} - -size_t git_path_basename_offset(git_str *buffer) -{ - ssize_t slash; - - if (!buffer || buffer->size <= 0) - return 0; - - slash = git_str_rfind_next(buffer, '/'); - - if (slash >= 0 && buffer->ptr[slash] == '/') - return (size_t)(slash + 1); - - return 0; -} - -int git_path_root(const char *path) -{ - int offset = 0, prefix_len; - - /* Does the root of the path look like a windows drive ? */ - if ((prefix_len = dos_drive_prefix_length(path))) - offset += prefix_len; - -#ifdef GIT_WIN32 - /* Are we dealing with a windows network path? */ - else if ((path[0] == '/' && path[1] == '/' && path[2] != '/') || - (path[0] == '\\' && path[1] == '\\' && path[2] != '\\')) - { - offset += 2; - - /* Skip the computer name segment */ - while (path[offset] && path[offset] != '/' && path[offset] != '\\') - offset++; - } - - if (path[offset] == '\\') - return offset; -#endif - - if (path[offset] == '/') - return offset; - - return -1; /* Not a real error - signals that path is not rooted */ -} - -static void path_trim_slashes(git_str *path) -{ - int ceiling = git_path_root(path->ptr) + 1; - - if (ceiling < 0) - return; - - while (path->size > (size_t)ceiling) { - if (path->ptr[path->size-1] != '/') - break; - - path->ptr[path->size-1] = '\0'; - path->size--; - } -} - -int git_path_join_unrooted( - git_str *path_out, const char *path, const char *base, ssize_t *root_at) -{ - ssize_t root; - - GIT_ASSERT_ARG(path_out); - GIT_ASSERT_ARG(path); - - root = (ssize_t)git_path_root(path); - - if (base != NULL && root < 0) { - if (git_str_joinpath(path_out, base, path) < 0) - return -1; - - root = (ssize_t)strlen(base); - } else { - if (git_str_sets(path_out, path) < 0) - return -1; - - if (root < 0) - root = 0; - else if (base) - git_path_equal_or_prefixed(base, path, &root); - } - - if (root_at) - *root_at = root; - - return 0; -} - -void git_path_squash_slashes(git_str *path) -{ - char *p, *q; - - if (path->size == 0) - return; - - for (p = path->ptr, q = path->ptr; *q; p++, q++) { - *p = *q; - - while (*q == '/' && *(q+1) == '/') { - path->size--; - q++; - } - } - - *p = '\0'; -} - -int git_path_prettify(git_str *path_out, const char *path, const char *base) -{ - char buf[GIT_PATH_MAX]; - - GIT_ASSERT_ARG(path_out); - GIT_ASSERT_ARG(path); - - /* construct path if needed */ - if (base != NULL && git_path_root(path) < 0) { - if (git_str_joinpath(path_out, base, path) < 0) - return -1; - path = path_out->ptr; - } - - if (p_realpath(path, buf) == NULL) { - /* git_error_set resets the errno when dealing with a GIT_ERROR_OS kind of error */ - int error = (errno == ENOENT || errno == ENOTDIR) ? GIT_ENOTFOUND : -1; - git_error_set(GIT_ERROR_OS, "failed to resolve path '%s'", path); - - git_str_clear(path_out); - - return error; - } - - return git_str_sets(path_out, buf); -} - -int git_path_prettify_dir(git_str *path_out, const char *path, const char *base) -{ - int error = git_path_prettify(path_out, path, base); - return (error < 0) ? error : git_path_to_dir(path_out); -} - -int git_path_to_dir(git_str *path) -{ - if (path->asize > 0 && - git_str_len(path) > 0 && - path->ptr[git_str_len(path) - 1] != '/') - git_str_putc(path, '/'); - - return git_str_oom(path) ? -1 : 0; -} - -void git_path_string_to_dir(char *path, size_t size) -{ - size_t end = strlen(path); - - if (end && path[end - 1] != '/' && end < size) { - path[end] = '/'; - path[end + 1] = '\0'; - } -} - -int git__percent_decode(git_str *decoded_out, const char *input) -{ - int len, hi, lo, i; - - GIT_ASSERT_ARG(decoded_out); - GIT_ASSERT_ARG(input); - - len = (int)strlen(input); - git_str_clear(decoded_out); - - for(i = 0; i < len; i++) - { - char c = input[i]; - - if (c != '%') - goto append; - - if (i >= len - 2) - goto append; - - hi = git__fromhex(input[i + 1]); - lo = git__fromhex(input[i + 2]); - - if (hi < 0 || lo < 0) - goto append; - - c = (char)(hi << 4 | lo); - i += 2; - -append: - if (git_str_putc(decoded_out, c) < 0) - return -1; - } - - return 0; -} - -static int error_invalid_local_file_uri(const char *uri) -{ - git_error_set(GIT_ERROR_CONFIG, "'%s' is not a valid local file URI", uri); - return -1; -} - -static int local_file_url_prefixlen(const char *file_url) -{ - int len = -1; - - if (git__prefixcmp(file_url, "file://") == 0) { - if (file_url[7] == '/') - len = 8; - else if (git__prefixcmp(file_url + 7, "localhost/") == 0) - len = 17; - } - - return len; -} - -bool git_path_is_local_file_url(const char *file_url) -{ - return (local_file_url_prefixlen(file_url) > 0); -} - -int git_path_fromurl(git_str *local_path_out, const char *file_url) -{ - int offset; - - GIT_ASSERT_ARG(local_path_out); - GIT_ASSERT_ARG(file_url); - - if ((offset = local_file_url_prefixlen(file_url)) < 0 || - file_url[offset] == '\0' || file_url[offset] == '/') - return error_invalid_local_file_uri(file_url); - -#ifndef GIT_WIN32 - offset--; /* A *nix absolute path starts with a forward slash */ -#endif - - git_str_clear(local_path_out); - return git__percent_decode(local_path_out, file_url + offset); -} - -int git_path_walk_up( - git_str *path, - const char *ceiling, - int (*cb)(void *data, const char *), - void *data) -{ - int error = 0; - git_str iter; - ssize_t stop = 0, scan; - char oldc = '\0'; - - GIT_ASSERT_ARG(path); - GIT_ASSERT_ARG(cb); - - if (ceiling != NULL) { - if (git__prefixcmp(path->ptr, ceiling) == 0) - stop = (ssize_t)strlen(ceiling); - else - stop = git_str_len(path); - } - scan = git_str_len(path); - - /* empty path: yield only once */ - if (!scan) { - error = cb(data, ""); - if (error) - git_error_set_after_callback(error); - return error; - } - - iter.ptr = path->ptr; - iter.size = git_str_len(path); - iter.asize = path->asize; - - while (scan >= stop) { - error = cb(data, iter.ptr); - iter.ptr[scan] = oldc; - - if (error) { - git_error_set_after_callback(error); - break; - } - - scan = git_str_rfind_next(&iter, '/'); - if (scan >= 0) { - scan++; - oldc = iter.ptr[scan]; - iter.size = scan; - iter.ptr[scan] = '\0'; - } - } - - if (scan >= 0) - iter.ptr[scan] = oldc; - - /* relative path: yield for the last component */ - if (!error && stop == 0 && iter.ptr[0] != '/') { - error = cb(data, ""); - if (error) - git_error_set_after_callback(error); - } - - return error; -} - -bool git_path_exists(const char *path) -{ - GIT_ASSERT_ARG_WITH_RETVAL(path, false); - return p_access(path, F_OK) == 0; -} - -bool git_path_isdir(const char *path) -{ - struct stat st; - if (p_stat(path, &st) < 0) - return false; - - return S_ISDIR(st.st_mode) != 0; -} - -bool git_path_isfile(const char *path) -{ - struct stat st; - - GIT_ASSERT_ARG_WITH_RETVAL(path, false); - if (p_stat(path, &st) < 0) - return false; - - return S_ISREG(st.st_mode) != 0; -} - -bool git_path_islink(const char *path) -{ - struct stat st; - - GIT_ASSERT_ARG_WITH_RETVAL(path, false); - if (p_lstat(path, &st) < 0) - return false; - - return S_ISLNK(st.st_mode) != 0; -} - -#ifdef GIT_WIN32 - -bool git_path_is_empty_dir(const char *path) -{ - git_win32_path filter_w; - bool empty = false; - - if (git_win32__findfirstfile_filter(filter_w, path)) { - WIN32_FIND_DATAW findData; - HANDLE hFind = FindFirstFileW(filter_w, &findData); - - /* FindFirstFile will fail if there are no children to the given - * path, which can happen if the given path is a file (and obviously - * has no children) or if the given path is an empty mount point. - * (Most directories have at least directory entries '.' and '..', - * but ridiculously another volume mounted in another drive letter's - * path space do not, and thus have nothing to enumerate.) If - * FindFirstFile fails, check if this is a directory-like thing - * (a mount point). - */ - if (hFind == INVALID_HANDLE_VALUE) - return git_path_isdir(path); - - /* If the find handle was created successfully, then it's a directory */ - empty = true; - - do { - /* Allow the enumeration to return . and .. and still be considered - * empty. In the special case of drive roots (i.e. C:\) where . and - * .. do not occur, we can still consider the path to be an empty - * directory if there's nothing there. */ - if (!git_path_is_dot_or_dotdotW(findData.cFileName)) { - empty = false; - break; - } - } while (FindNextFileW(hFind, &findData)); - - FindClose(hFind); - } - - return empty; -} - -#else - -static int path_found_entry(void *payload, git_str *path) -{ - GIT_UNUSED(payload); - return !git_path_is_dot_or_dotdot(path->ptr); -} - -bool git_path_is_empty_dir(const char *path) -{ - int error; - git_str dir = GIT_STR_INIT; - - if (!git_path_isdir(path)) - return false; - - if ((error = git_str_sets(&dir, path)) != 0) - git_error_clear(); - else - error = git_path_direach(&dir, 0, path_found_entry, NULL); - - git_str_dispose(&dir); - - return !error; -} - -#endif - -int git_path_set_error(int errno_value, const char *path, const char *action) -{ - switch (errno_value) { - case ENOENT: - case ENOTDIR: - git_error_set(GIT_ERROR_OS, "could not find '%s' to %s", path, action); - return GIT_ENOTFOUND; - - case EINVAL: - case ENAMETOOLONG: - git_error_set(GIT_ERROR_OS, "invalid path for filesystem '%s'", path); - return GIT_EINVALIDSPEC; - - case EEXIST: - git_error_set(GIT_ERROR_OS, "failed %s - '%s' already exists", action, path); - return GIT_EEXISTS; - - case EACCES: - git_error_set(GIT_ERROR_OS, "failed %s - '%s' is locked", action, path); - return GIT_ELOCKED; - - default: - git_error_set(GIT_ERROR_OS, "could not %s '%s'", action, path); - return -1; - } -} - -int git_path_lstat(const char *path, struct stat *st) -{ - if (p_lstat(path, st) == 0) - return 0; - - return git_path_set_error(errno, path, "stat"); -} - -static bool _check_dir_contents( - git_str *dir, - const char *sub, - bool (*predicate)(const char *)) -{ - bool result; - size_t dir_size = git_str_len(dir); - size_t sub_size = strlen(sub); - size_t alloc_size; - - /* leave base valid even if we could not make space for subdir */ - if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, dir_size, sub_size) || - GIT_ADD_SIZET_OVERFLOW(&alloc_size, alloc_size, 2) || - git_str_try_grow(dir, alloc_size, false) < 0) - return false; - - /* save excursion */ - if (git_str_joinpath(dir, dir->ptr, sub) < 0) - return false; - - result = predicate(dir->ptr); - - /* restore path */ - git_str_truncate(dir, dir_size); - return result; -} - -bool git_path_contains(git_str *dir, const char *item) -{ - return _check_dir_contents(dir, item, &git_path_exists); -} - -bool git_path_contains_dir(git_str *base, const char *subdir) -{ - return _check_dir_contents(base, subdir, &git_path_isdir); -} - -bool git_path_contains_file(git_str *base, const char *file) -{ - return _check_dir_contents(base, file, &git_path_isfile); -} - -int git_path_find_dir(git_str *dir) -{ - int error = 0; - char buf[GIT_PATH_MAX]; - - if (p_realpath(dir->ptr, buf) != NULL) - error = git_str_sets(dir, buf); - - /* call dirname if this is not a directory */ - if (!error) /* && git_path_isdir(dir->ptr) == false) */ - error = (git_path_dirname_r(dir, dir->ptr) < 0) ? -1 : 0; - - if (!error) - error = git_path_to_dir(dir); - - return error; -} - -int git_path_resolve_relative(git_str *path, size_t ceiling) -{ - char *base, *to, *from, *next; - size_t len; - - GIT_ERROR_CHECK_ALLOC_STR(path); - - if (ceiling > path->size) - ceiling = path->size; - - /* recognize drive prefixes, etc. that should not be backed over */ - if (ceiling == 0) - ceiling = git_path_root(path->ptr) + 1; - - /* recognize URL prefixes that should not be backed over */ - if (ceiling == 0) { - for (next = path->ptr; *next && git__isalpha(*next); ++next); - if (next[0] == ':' && next[1] == '/' && next[2] == '/') - ceiling = (next + 3) - path->ptr; - } - - base = to = from = path->ptr + ceiling; - - while (*from) { - for (next = from; *next && *next != '/'; ++next); - - len = next - from; - - if (len == 1 && from[0] == '.') - /* do nothing with singleton dot */; - - else if (len == 2 && from[0] == '.' && from[1] == '.') { - /* error out if trying to up one from a hard base */ - if (to == base && ceiling != 0) { - git_error_set(GIT_ERROR_INVALID, - "cannot strip root component off url"); - return -1; - } - - /* no more path segments to strip, - * use '../' as a new base path */ - if (to == base) { - if (*next == '/') - len++; - - if (to != from) - memmove(to, from, len); - - to += len; - /* this is now the base, can't back up from a - * relative prefix */ - base = to; - } else { - /* back up a path segment */ - while (to > base && to[-1] == '/') to--; - while (to > base && to[-1] != '/') to--; - } - } else { - if (*next == '/' && *from != '/') - len++; - - if (to != from) - memmove(to, from, len); - - to += len; - } - - from += len; - - while (*from == '/') from++; - } - - *to = '\0'; - - path->size = to - path->ptr; - - return 0; -} - -int git_path_apply_relative(git_str *target, const char *relpath) -{ - return git_str_joinpath(target, git_str_cstr(target), relpath) || - git_path_resolve_relative(target, 0); -} - -int git_path_cmp( - const char *name1, size_t len1, int isdir1, - const char *name2, size_t len2, int isdir2, - int (*compare)(const char *, const char *, size_t)) -{ - unsigned char c1, c2; - size_t len = len1 < len2 ? len1 : len2; - int cmp; - - cmp = compare(name1, name2, len); - if (cmp) - return cmp; - - c1 = name1[len]; - c2 = name2[len]; - - if (c1 == '\0' && isdir1) - c1 = '/'; - - if (c2 == '\0' && isdir2) - c2 = '/'; - - return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0; -} - -size_t git_path_common_dirlen(const char *one, const char *two) -{ - const char *p, *q, *dirsep = NULL; - - for (p = one, q = two; *p && *q; p++, q++) { - if (*p == '/' && *q == '/') - dirsep = p; - else if (*p != *q) - break; - } - - return dirsep ? (dirsep - one) + 1 : 0; -} - -int git_path_make_relative(git_str *path, const char *parent) -{ - const char *p, *q, *p_dirsep, *q_dirsep; - size_t plen = path->size, newlen, alloclen, depth = 1, i, offset; - - for (p_dirsep = p = path->ptr, q_dirsep = q = parent; *p && *q; p++, q++) { - if (*p == '/' && *q == '/') { - p_dirsep = p; - q_dirsep = q; - } - else if (*p != *q) - break; - } - - /* need at least 1 common path segment */ - if ((p_dirsep == path->ptr || q_dirsep == parent) && - (*p_dirsep != '/' || *q_dirsep != '/')) { - git_error_set(GIT_ERROR_INVALID, - "%s is not a parent of %s", parent, path->ptr); - return GIT_ENOTFOUND; - } - - if (*p == '/' && !*q) - p++; - else if (!*p && *q == '/') - q++; - else if (!*p && !*q) - return git_str_clear(path), 0; - else { - p = p_dirsep + 1; - q = q_dirsep + 1; - } - - plen -= (p - path->ptr); - - if (!*q) - return git_str_set(path, p, plen); - - for (; (q = strchr(q, '/')) && *(q + 1); q++) - depth++; - - GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newlen, depth, 3); - GIT_ERROR_CHECK_ALLOC_ADD(&newlen, newlen, plen); - - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, newlen, 1); - - /* save the offset as we might realllocate the pointer */ - offset = p - path->ptr; - if (git_str_try_grow(path, alloclen, 1) < 0) - return -1; - p = path->ptr + offset; - - memmove(path->ptr + (depth * 3), p, plen + 1); - - for (i = 0; i < depth; i++) - memcpy(path->ptr + (i * 3), "../", 3); - - path->size = newlen; - return 0; -} - -bool git_path_has_non_ascii(const char *path, size_t pathlen) -{ - const uint8_t *scan = (const uint8_t *)path, *end; - - for (end = scan + pathlen; scan < end; ++scan) - if (*scan & 0x80) - return true; - - return false; -} - -#ifdef GIT_USE_ICONV - -int git_path_iconv_init_precompose(git_path_iconv_t *ic) -{ - git_str_init(&ic->buf, 0); - ic->map = iconv_open(GIT_PATH_REPO_ENCODING, GIT_PATH_NATIVE_ENCODING); - return 0; -} - -void git_path_iconv_clear(git_path_iconv_t *ic) -{ - if (ic) { - if (ic->map != (iconv_t)-1) - iconv_close(ic->map); - git_str_dispose(&ic->buf); - } -} - -int git_path_iconv(git_path_iconv_t *ic, const char **in, size_t *inlen) -{ - char *nfd = (char*)*in, *nfc; - size_t nfdlen = *inlen, nfclen, wantlen = nfdlen, alloclen, rv; - int retry = 1; - - if (!ic || ic->map == (iconv_t)-1 || - !git_path_has_non_ascii(*in, *inlen)) - return 0; - - git_str_clear(&ic->buf); - - while (1) { - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, wantlen, 1); - if (git_str_grow(&ic->buf, alloclen) < 0) - return -1; - - nfc = ic->buf.ptr + ic->buf.size; - nfclen = ic->buf.asize - ic->buf.size; - - rv = iconv(ic->map, &nfd, &nfdlen, &nfc, &nfclen); - - ic->buf.size = (nfc - ic->buf.ptr); - - if (rv != (size_t)-1) - break; - - /* if we cannot convert the data (probably because iconv thinks - * it is not valid UTF-8 source data), then use original data - */ - if (errno != E2BIG) - return 0; - - /* make space for 2x the remaining data to be converted - * (with per retry overhead to avoid infinite loops) - */ - wantlen = ic->buf.size + max(nfclen, nfdlen) * 2 + (size_t)(retry * 4); - - if (retry++ > 4) - goto fail; - } - - ic->buf.ptr[ic->buf.size] = '\0'; - - *in = ic->buf.ptr; - *inlen = ic->buf.size; - - return 0; - -fail: - git_error_set(GIT_ERROR_OS, "unable to convert unicode path data"); - return -1; -} - -static const char *nfc_file = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D.XXXXXX"; -static const char *nfd_file = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D.XXXXXX"; - -/* Check if the platform is decomposing unicode data for us. We will - * emulate core Git and prefer to use precomposed unicode data internally - * on these platforms, composing the decomposed unicode on the fly. - * - * This mainly happens on the Mac where HDFS stores filenames as - * decomposed unicode. Even on VFAT and SAMBA file systems, the Mac will - * return decomposed unicode from readdir() even when the actual - * filesystem is storing precomposed unicode. - */ -bool git_path_does_fs_decompose_unicode(const char *root) -{ - git_str path = GIT_STR_INIT; - int fd; - bool found_decomposed = false; - char tmp[6]; - - /* Create a file using a precomposed path and then try to find it - * using the decomposed name. If the lookup fails, then we will mark - * that we should precompose unicode for this repository. - */ - if (git_str_joinpath(&path, root, nfc_file) < 0 || - (fd = p_mkstemp(path.ptr)) < 0) - goto done; - p_close(fd); - - /* record trailing digits generated by mkstemp */ - memcpy(tmp, path.ptr + path.size - sizeof(tmp), sizeof(tmp)); - - /* try to look up as NFD path */ - if (git_str_joinpath(&path, root, nfd_file) < 0) - goto done; - memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp)); - - found_decomposed = git_path_exists(path.ptr); - - /* remove temporary file (using original precomposed path) */ - if (git_str_joinpath(&path, root, nfc_file) < 0) - goto done; - memcpy(path.ptr + path.size - sizeof(tmp), tmp, sizeof(tmp)); - - (void)p_unlink(path.ptr); - -done: - git_str_dispose(&path); - return found_decomposed; -} - -#else - -bool git_path_does_fs_decompose_unicode(const char *root) -{ - GIT_UNUSED(root); - return false; -} - -#endif - -#if defined(__sun) || defined(__GNU__) -typedef char path_dirent_data[sizeof(struct dirent) + FILENAME_MAX + 1]; -#else -typedef struct dirent path_dirent_data; -#endif - -int git_path_direach( - git_str *path, - uint32_t flags, - int (*fn)(void *, git_str *), - void *arg) -{ - int error = 0; - ssize_t wd_len; - DIR *dir; - struct dirent *de; - -#ifdef GIT_USE_ICONV - git_path_iconv_t ic = GIT_PATH_ICONV_INIT; -#endif - - GIT_UNUSED(flags); - - if (git_path_to_dir(path) < 0) - return -1; - - wd_len = git_str_len(path); - - if ((dir = opendir(path->ptr)) == NULL) { - git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path->ptr); - if (errno == ENOENT) - return GIT_ENOTFOUND; - - return -1; - } - -#ifdef GIT_USE_ICONV - if ((flags & GIT_PATH_DIR_PRECOMPOSE_UNICODE) != 0) - (void)git_path_iconv_init_precompose(&ic); -#endif - - while ((de = readdir(dir)) != NULL) { - const char *de_path = de->d_name; - size_t de_len = strlen(de_path); - - if (git_path_is_dot_or_dotdot(de_path)) - continue; - -#ifdef GIT_USE_ICONV - if ((error = git_path_iconv(&ic, &de_path, &de_len)) < 0) - break; -#endif - - if ((error = git_str_put(path, de_path, de_len)) < 0) - break; - - git_error_clear(); - error = fn(arg, path); - - git_str_truncate(path, wd_len); /* restore path */ - - /* Only set our own error if the callback did not set one already */ - if (error != 0) { - if (!git_error_last()) - git_error_set_after_callback(error); - - break; - } - } - - closedir(dir); - -#ifdef GIT_USE_ICONV - git_path_iconv_clear(&ic); -#endif - - return error; -} - -#if defined(GIT_WIN32) && !defined(__MINGW32__) - -/* Using _FIND_FIRST_EX_LARGE_FETCH may increase performance in Windows 7 - * and better. - */ -#ifndef FIND_FIRST_EX_LARGE_FETCH -# define FIND_FIRST_EX_LARGE_FETCH 2 -#endif - -int git_path_diriter_init( - git_path_diriter *diriter, - const char *path, - unsigned int flags) -{ - git_win32_path path_filter; +#include "fs_path.h" - static int is_win7_or_later = -1; - if (is_win7_or_later < 0) - is_win7_or_later = git_has_win32_version(6, 1, 0); - - GIT_ASSERT_ARG(diriter); - GIT_ASSERT_ARG(path); - - memset(diriter, 0, sizeof(git_path_diriter)); - diriter->handle = INVALID_HANDLE_VALUE; - - if (git_str_puts(&diriter->path_utf8, path) < 0) - return -1; - - path_trim_slashes(&diriter->path_utf8); - - if (diriter->path_utf8.size == 0) { - git_error_set(GIT_ERROR_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)) { - git_error_set(GIT_ERROR_OS, "could not parse the directory path '%s'", path); - return -1; - } - - diriter->handle = FindFirstFileExW( - path_filter, - is_win7_or_later ? FindExInfoBasic : FindExInfoStandard, - &diriter->current, - FindExSearchNameMatch, - NULL, - is_win7_or_later ? FIND_FIRST_EX_LARGE_FETCH : 0); - - if (diriter->handle == INVALID_HANDLE_VALUE) { - git_error_set(GIT_ERROR_OS, "could not open directory '%s'", path); - return -1; - } - - diriter->parent_utf8_len = diriter->path_utf8.size; - diriter->flags = flags; - return 0; -} - -static int diriter_update_paths(git_path_diriter *diriter) -{ - size_t filename_len, path_len; - - filename_len = wcslen(diriter->current.cFileName); - - if (GIT_ADD_SIZET_OVERFLOW(&path_len, diriter->parent_len, filename_len) || - GIT_ADD_SIZET_OVERFLOW(&path_len, path_len, 2)) - return -1; - - if (path_len > GIT_WIN_PATH_UTF16) { - git_error_set(GIT_ERROR_FILESYSTEM, - "invalid path '%.*ls\\%ls' (path too long)", - diriter->parent_len, diriter->path, diriter->current.cFileName); - return -1; - } - - diriter->path[diriter->parent_len] = L'\\'; - memcpy(&diriter->path[diriter->parent_len+1], - diriter->current.cFileName, filename_len * sizeof(wchar_t)); - diriter->path[path_len-1] = L'\0'; - - git_str_truncate(&diriter->path_utf8, diriter->parent_utf8_len); - - if (diriter->parent_utf8_len > 0 && - diriter->path_utf8.ptr[diriter->parent_utf8_len-1] != '/') - git_str_putc(&diriter->path_utf8, '/'); - - git_str_put_w(&diriter->path_utf8, diriter->current.cFileName, filename_len); - - if (git_str_oom(&diriter->path_utf8)) - return -1; - - return 0; -} - -int git_path_diriter_next(git_path_diriter *diriter) -{ - bool skip_dot = !(diriter->flags & GIT_PATH_DIR_INCLUDE_DOT_AND_DOTDOT); - - do { - /* Our first time through, we already have the data from - * FindFirstFileW. Use it, otherwise get the next file. - */ - if (!diriter->needs_next) - diriter->needs_next = 1; - else if (!FindNextFileW(diriter->handle, &diriter->current)) - return GIT_ITEROVER; - } while (skip_dot && git_path_is_dot_or_dotdotW(diriter->current.cFileName)); - - if (diriter_update_paths(diriter) < 0) - return -1; - - return 0; -} - -int git_path_diriter_filename( - const char **out, - size_t *out_len, - git_path_diriter *diriter) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(out_len); - GIT_ASSERT_ARG(diriter); - GIT_ASSERT(diriter->path_utf8.size > diriter->parent_utf8_len); - - *out = &diriter->path_utf8.ptr[diriter->parent_utf8_len+1]; - *out_len = diriter->path_utf8.size - diriter->parent_utf8_len - 1; - return 0; -} - -int git_path_diriter_fullpath( - const char **out, - size_t *out_len, - git_path_diriter *diriter) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(out_len); - GIT_ASSERT_ARG(diriter); - - *out = diriter->path_utf8.ptr; - *out_len = diriter->path_utf8.size; - return 0; -} - -int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(diriter); - - return git_win32__file_attribute_to_stat(out, - (WIN32_FILE_ATTRIBUTE_DATA *)&diriter->current, - diriter->path); -} - -void git_path_diriter_free(git_path_diriter *diriter) -{ - if (diriter == NULL) - return; - - git_str_dispose(&diriter->path_utf8); - - if (diriter->handle != INVALID_HANDLE_VALUE) { - FindClose(diriter->handle); - diriter->handle = INVALID_HANDLE_VALUE; - } -} - -#else - -int git_path_diriter_init( - git_path_diriter *diriter, - const char *path, - unsigned int flags) -{ - GIT_ASSERT_ARG(diriter); - GIT_ASSERT_ARG(path); - - memset(diriter, 0, sizeof(git_path_diriter)); - - if (git_str_puts(&diriter->path, path) < 0) - return -1; - - path_trim_slashes(&diriter->path); - - if (diriter->path.size == 0) { - git_error_set(GIT_ERROR_FILESYSTEM, "could not open directory '%s'", path); - return -1; - } - - if ((diriter->dir = opendir(diriter->path.ptr)) == NULL) { - git_str_dispose(&diriter->path); - - git_error_set(GIT_ERROR_OS, "failed to open directory '%s'", path); - return -1; - } - -#ifdef GIT_USE_ICONV - if ((flags & GIT_PATH_DIR_PRECOMPOSE_UNICODE) != 0) - (void)git_path_iconv_init_precompose(&diriter->ic); -#endif - - diriter->parent_len = diriter->path.size; - diriter->flags = flags; - - return 0; -} - -int git_path_diriter_next(git_path_diriter *diriter) -{ - struct dirent *de; - const char *filename; - size_t filename_len; - bool skip_dot = !(diriter->flags & GIT_PATH_DIR_INCLUDE_DOT_AND_DOTDOT); - int error = 0; - - GIT_ASSERT_ARG(diriter); - - errno = 0; - - do { - if ((de = readdir(diriter->dir)) == NULL) { - if (!errno) - return GIT_ITEROVER; - - git_error_set(GIT_ERROR_OS, - "could not read directory '%s'", diriter->path.ptr); - return -1; - } - } while (skip_dot && git_path_is_dot_or_dotdot(de->d_name)); - - filename = de->d_name; - filename_len = strlen(filename); - -#ifdef GIT_USE_ICONV - if ((diriter->flags & GIT_PATH_DIR_PRECOMPOSE_UNICODE) != 0 && - (error = git_path_iconv(&diriter->ic, &filename, &filename_len)) < 0) - return error; -#endif - - git_str_truncate(&diriter->path, diriter->parent_len); - - if (diriter->parent_len > 0 && - diriter->path.ptr[diriter->parent_len-1] != '/') - git_str_putc(&diriter->path, '/'); - - git_str_put(&diriter->path, filename, filename_len); - - if (git_str_oom(&diriter->path)) - return -1; - - return error; -} - -int git_path_diriter_filename( - const char **out, - size_t *out_len, - git_path_diriter *diriter) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(out_len); - GIT_ASSERT_ARG(diriter); - GIT_ASSERT(diriter->path.size > diriter->parent_len); - - *out = &diriter->path.ptr[diriter->parent_len+1]; - *out_len = diriter->path.size - diriter->parent_len - 1; - return 0; -} - -int git_path_diriter_fullpath( - const char **out, - size_t *out_len, - git_path_diriter *diriter) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(out_len); - GIT_ASSERT_ARG(diriter); - - *out = diriter->path.ptr; - *out_len = diriter->path.size; - return 0; -} - -int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter) -{ - GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(diriter); - - return git_path_lstat(diriter->path.ptr, out); -} - -void git_path_diriter_free(git_path_diriter *diriter) -{ - if (diriter == NULL) - return; - - if (diriter->dir) { - closedir(diriter->dir); - diriter->dir = NULL; - } - -#ifdef GIT_USE_ICONV - git_path_iconv_clear(&diriter->ic); -#endif - - git_str_dispose(&diriter->path); -} - -#endif - -int git_path_dirload( - git_vector *contents, - const char *path, - size_t prefix_len, - uint32_t flags) -{ - git_path_diriter iter = GIT_PATH_DIRITER_INIT; - const char *name; - size_t name_len; - char *dup; - int error; - - GIT_ASSERT_ARG(contents); - GIT_ASSERT_ARG(path); - - if ((error = git_path_diriter_init(&iter, path, flags)) < 0) - return error; - - while ((error = git_path_diriter_next(&iter)) == 0) { - if ((error = git_path_diriter_fullpath(&name, &name_len, &iter)) < 0) - break; - - GIT_ASSERT(name_len > prefix_len); - - dup = git__strndup(name + prefix_len, name_len - prefix_len); - GIT_ERROR_CHECK_ALLOC(dup); - - if ((error = git_vector_insert(contents, dup)) < 0) - break; - } - - if (error == GIT_ITEROVER) - error = 0; - - git_path_diriter_free(&iter); - return error; -} - -int git_path_from_url_or_path(git_str *local_path_out, const char *url_or_path) -{ - if (git_path_is_local_file_url(url_or_path)) - return git_path_fromurl(local_path_out, url_or_path); - else - return git_str_sets(local_path_out, url_or_path); -} - -/* Reject paths like AUX or COM1, or those versions that end in a dot or - * colon. ("AUX." or "AUX:") - */ -GIT_INLINE(bool) verify_dospath( - const char *component, - size_t len, - const char dospath[3], - bool trailing_num) -{ - size_t last = trailing_num ? 4 : 3; - - if (len < last || git__strncasecmp(component, dospath, 3) != 0) - return true; - - if (trailing_num && (component[3] < '1' || component[3] > '9')) - return true; - - return (len > last && - component[last] != '.' && - component[last] != ':'); -} +typedef struct { + git_repository *repo; + uint16_t file_mode; + unsigned int flags; +} repository_path_validate_data; static int32_t next_hfs_char(const char **in, size_t *len) { @@ -1598,7 +57,11 @@ static int32_t next_hfs_char(const char **in, size_t *len) return 0; /* NULL byte -- end of string */ } -static bool verify_dotgit_hfs_generic(const char *path, size_t len, const char *needle, size_t needle_len) +static bool validate_dotgit_hfs_generic( + const char *path, + size_t len, + const char *needle, + size_t needle_len) { size_t i; char c; @@ -1618,12 +81,15 @@ static bool verify_dotgit_hfs_generic(const char *path, size_t len, const char * return false; } -static bool verify_dotgit_hfs(const char *path, size_t len) +static bool validate_dotgit_hfs(const char *path, size_t len) { - return verify_dotgit_hfs_generic(path, len, "git", CONST_STRLEN("git")); + return validate_dotgit_hfs_generic(path, len, "git", CONST_STRLEN("git")); } -GIT_INLINE(bool) verify_dotgit_ntfs(git_repository *repo, const char *path, size_t len) +GIT_INLINE(bool) validate_dotgit_ntfs( + git_repository *repo, + const char *path, + size_t len) { git_str *reserved = git_repository__reserved_names_win32; size_t reserved_len = git_repository__reserved_names_win32_len; @@ -1685,7 +151,12 @@ GIT_INLINE(bool) ntfs_end_of_filename(const char *path) return true; } -GIT_INLINE(bool) verify_dotgit_ntfs_generic(const char *name, size_t len, const char *dotgit_name, size_t dotgit_len, const char *shortname_pfix) +GIT_INLINE(bool) validate_dotgit_ntfs_generic( + const char *name, + size_t len, + const char *dotgit_name, + size_t dotgit_len, + const char *shortname_pfix) { int i, saw_tilde; @@ -1722,33 +193,6 @@ GIT_INLINE(bool) verify_dotgit_ntfs_generic(const char *name, size_t len, const return !ntfs_end_of_filename(name + i); } -GIT_INLINE(bool) verify_char(unsigned char c, unsigned int flags) -{ - if ((flags & GIT_PATH_REJECT_BACKSLASH) && c == '\\') - return false; - - if ((flags & GIT_PATH_REJECT_SLASH) && c == '/') - return false; - - if (flags & GIT_PATH_REJECT_NT_CHARS) { - if (c < 32) - return false; - - switch (c) { - case '<': - case '>': - case ':': - case '"': - case '|': - case '?': - case '*': - return false; - } - } - - return true; -} - /* * Return the length of the common prefix between str and prefix, comparing them * case-insensitively (must be ASCII to match). @@ -1757,7 +201,7 @@ GIT_INLINE(size_t) common_prefix_icase(const char *str, size_t len, const char * { size_t count = 0; - while (len >0 && tolower(*str) == tolower(*prefix)) { + while (len > 0 && tolower(*str) == tolower(*prefix)) { count++; str++; prefix++; @@ -1767,72 +211,37 @@ GIT_INLINE(size_t) common_prefix_icase(const char *str, size_t len, const char * return count; } -/* - * We fundamentally don't like some paths when dealing with user-inputted - * strings (in checkout or ref names): we don't want dot or dot-dot - * anywhere, we want to avoid writing weird paths on Windows that can't - * be handled by tools that use the non-\\?\ APIs, we don't want slashes - * or double slashes at the end of paths that can make them ambiguous. - * - * For checkout, we don't want to recurse into ".git" either. - */ -static bool verify_component( - git_repository *repo, +static bool validate_repo_component( const char *component, size_t len, - uint16_t mode, - unsigned int flags) + void *payload) { - if (len == 0) - return false; - - if ((flags & GIT_PATH_REJECT_TRAVERSAL) && - len == 1 && component[0] == '.') - return false; - - if ((flags & GIT_PATH_REJECT_TRAVERSAL) && - len == 2 && component[0] == '.' && component[1] == '.') - return false; - - if ((flags & GIT_PATH_REJECT_TRAILING_DOT) && component[len-1] == '.') - return false; - - if ((flags & GIT_PATH_REJECT_TRAILING_SPACE) && component[len-1] == ' ') - return false; - - if ((flags & GIT_PATH_REJECT_TRAILING_COLON) && component[len-1] == ':') - return false; + repository_path_validate_data *data = (repository_path_validate_data *)payload; - if (flags & GIT_PATH_REJECT_DOS_PATHS) { - if (!verify_dospath(component, len, "CON", false) || - !verify_dospath(component, len, "PRN", false) || - !verify_dospath(component, len, "AUX", false) || - !verify_dospath(component, len, "NUL", false) || - !verify_dospath(component, len, "COM", true) || - !verify_dospath(component, len, "LPT", true)) + if (data->flags & GIT_PATH_REJECT_DOT_GIT_HFS) { + if (!validate_dotgit_hfs(component, len)) return false; - } - if (flags & GIT_PATH_REJECT_DOT_GIT_HFS) { - if (!verify_dotgit_hfs(component, len)) - return false; - if (S_ISLNK(mode) && git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS)) + if (S_ISLNK(data->file_mode) && + git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS)) return false; } - if (flags & GIT_PATH_REJECT_DOT_GIT_NTFS) { - if (!verify_dotgit_ntfs(repo, component, len)) + if (data->flags & GIT_PATH_REJECT_DOT_GIT_NTFS) { + if (!validate_dotgit_ntfs(data->repo, component, len)) return false; - if (S_ISLNK(mode) && git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_NTFS)) + + if (S_ISLNK(data->file_mode) && + git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_NTFS)) return false; } /* don't bother rerunning the `.git` test if we ran the HFS or NTFS * specific tests, they would have already rejected `.git`. */ - if ((flags & GIT_PATH_REJECT_DOT_GIT_HFS) == 0 && - (flags & GIT_PATH_REJECT_DOT_GIT_NTFS) == 0 && - (flags & GIT_PATH_REJECT_DOT_GIT_LITERAL)) { + if ((data->flags & GIT_PATH_REJECT_DOT_GIT_HFS) == 0 && + (data->flags & GIT_PATH_REJECT_DOT_GIT_NTFS) == 0 && + (data->flags & GIT_PATH_REJECT_DOT_GIT_LITERAL)) { if (len >= 4 && component[0] == '.' && (component[1] == 'g' || component[1] == 'G') && @@ -1841,10 +250,11 @@ static bool verify_component( if (len == 4) return false; - if (S_ISLNK(mode) && common_prefix_icase(component, len, ".gitmodules") == len) + if (S_ISLNK(data->file_mode) && + common_prefix_icase(component, len, ".gitmodules") == len) return false; } - } + } return true; } @@ -1878,90 +288,20 @@ GIT_INLINE(unsigned int) dotgit_flags( bool git_path_validate( git_repository *repo, const char *path, - uint16_t mode, + uint16_t file_mode, unsigned int flags) { - const char *start, *c; + repository_path_validate_data data = {0}; /* Upgrade the ".git" checks based on platform */ if ((flags & GIT_PATH_REJECT_DOT_GIT)) flags = dotgit_flags(repo, flags); - for (start = c = path; *c; c++) { - if (!verify_char(*c, flags)) - return false; - - if (*c == '/') { - if (!verify_component(repo, start, (c - start), mode, flags)) - return false; - - start = c+1; - } - } - - return verify_component(repo, start, (c - start), mode, flags); -} - -#ifdef GIT_WIN32 -GIT_INLINE(bool) should_validate_longpaths(git_repository *repo) -{ - int longpaths = 0; - - if (repo && - git_repository__configmap_lookup(&longpaths, repo, GIT_CONFIGMAP_LONGPATHS) < 0) - longpaths = 0; - - return (longpaths == 0); -} - -#else - -GIT_INLINE(bool) should_validate_longpaths(git_repository *repo) -{ - GIT_UNUSED(repo); - - return false; -} -#endif - -int git_path_validate_workdir(git_repository *repo, const char *path) -{ - if (should_validate_longpaths(repo)) - return git_path_validate_filesystem(path, strlen(path)); - - return 0; -} - -int git_path_validate_workdir_with_len( - git_repository *repo, - const char *path, - size_t path_len) -{ - if (should_validate_longpaths(repo)) - return git_path_validate_filesystem(path, path_len); - - return 0; -} - -int git_path_validate_workdir_buf(git_repository *repo, git_str *path) -{ - return git_path_validate_workdir_with_len(repo, path->ptr, path->size); -} - -int git_path_normalize_slashes(git_str *out, const char *path) -{ - int error; - char *p; - - if ((error = git_str_puts(out, path)) < 0) - return error; - - for (p = out->ptr; *p; p++) { - if (*p == '\\') - *p = '/'; - } + data.repo = repo; + data.file_mode = file_mode; + data.flags = flags; - return 0; + return git_fs_path_validate_ext(path, flags, NULL, validate_repo_component, &data); } static const struct { @@ -1974,7 +314,11 @@ static const struct { { "gitattributes", "gi7d29", CONST_STRLEN("gitattributes") } }; -extern int git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfile gitfile, git_path_fs fs) +extern int git_path_is_gitfile( + const char *path, + size_t pathlen, + git_path_gitfile gitfile, + git_path_fs fs) { const char *file, *hash; size_t filelen; @@ -1990,112 +334,15 @@ extern int git_path_is_gitfile(const char *path, size_t pathlen, git_path_gitfil switch (fs) { case GIT_PATH_FS_GENERIC: - return !verify_dotgit_ntfs_generic(path, pathlen, file, filelen, hash) || - !verify_dotgit_hfs_generic(path, pathlen, file, filelen); + return !validate_dotgit_ntfs_generic(path, pathlen, file, filelen, hash) || + !validate_dotgit_hfs_generic(path, pathlen, file, filelen); case GIT_PATH_FS_NTFS: - return !verify_dotgit_ntfs_generic(path, pathlen, file, filelen, hash); + return !validate_dotgit_ntfs_generic(path, pathlen, file, filelen, hash); case GIT_PATH_FS_HFS: - return !verify_dotgit_hfs_generic(path, pathlen, file, filelen); + return !validate_dotgit_hfs_generic(path, pathlen, file, filelen); default: git_error_set(GIT_ERROR_OS, "invalid filesystem for path validation"); return -1; } } -bool git_path_supports_symlinks(const char *dir) -{ - git_str path = GIT_STR_INIT; - bool supported = false; - struct stat st; - int fd; - - if ((fd = git_futils_mktmp(&path, dir, 0666)) < 0 || - p_close(fd) < 0 || - p_unlink(path.ptr) < 0 || - p_symlink("testing", path.ptr) < 0 || - p_lstat(path.ptr, &st) < 0) - goto done; - - supported = (S_ISLNK(st.st_mode) != 0); -done: - if (path.size) - (void)p_unlink(path.ptr); - git_str_dispose(&path); - return supported; -} - -int git_path_validate_system_file_ownership(const char *path) -{ -#ifndef GIT_WIN32 - GIT_UNUSED(path); - return GIT_OK; -#else - git_win32_path buf; - PSID owner_sid; - PSECURITY_DESCRIPTOR descriptor = NULL; - HANDLE token; - TOKEN_USER *info = NULL; - DWORD err, len; - int ret; - - if (git_win32_path_from_utf8(buf, path) < 0) - return -1; - - err = GetNamedSecurityInfoW(buf, SE_FILE_OBJECT, - OWNER_SECURITY_INFORMATION | - DACL_SECURITY_INFORMATION, - &owner_sid, NULL, NULL, NULL, &descriptor); - - if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) { - ret = GIT_ENOTFOUND; - goto cleanup; - } - - if (err != ERROR_SUCCESS) { - git_error_set(GIT_ERROR_OS, "failed to get security information"); - ret = GIT_ERROR; - goto cleanup; - } - - if (!IsValidSid(owner_sid)) { - git_error_set(GIT_ERROR_INVALID, "programdata configuration file owner is unknown"); - ret = GIT_ERROR; - goto cleanup; - } - - if (IsWellKnownSid(owner_sid, WinBuiltinAdministratorsSid) || - IsWellKnownSid(owner_sid, WinLocalSystemSid)) { - ret = GIT_OK; - goto cleanup; - } - - /* Obtain current user's SID */ - if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token) && - !GetTokenInformation(token, TokenUser, NULL, 0, &len)) { - info = git__malloc(len); - GIT_ERROR_CHECK_ALLOC(info); - if (!GetTokenInformation(token, TokenUser, info, len, &len)) { - git__free(info); - info = NULL; - } - } - - /* - * If the file is owned by the same account that is running the current - * process, it's okay to read from that file. - */ - if (info && EqualSid(owner_sid, info->User.Sid)) - ret = GIT_OK; - else { - git_error_set(GIT_ERROR_INVALID, "programdata configuration file owner is not valid"); - ret = GIT_ERROR; - } - git__free(info); - -cleanup: - if (descriptor) - LocalFree(descriptor); - - return ret; -#endif -} diff --git a/src/path.h b/src/path.h index 4074c3425..ca220d121 100644 --- a/src/path.h +++ b/src/path.h @@ -9,729 +9,26 @@ #include "common.h" -#include "posix.h" -#include "str.h" -#include "vector.h" +#include "fs_path.h" +#include -#include "git2/sys/path.h" +#define GIT_PATH_REJECT_DOT_GIT (GIT_FS_PATH_REJECT_MAX << 1) +#define GIT_PATH_REJECT_DOT_GIT_LITERAL (GIT_FS_PATH_REJECT_MAX << 2) +#define GIT_PATH_REJECT_DOT_GIT_HFS (GIT_FS_PATH_REJECT_MAX << 3) +#define GIT_PATH_REJECT_DOT_GIT_NTFS (GIT_FS_PATH_REJECT_MAX << 4) -/** - * Path manipulation utils - * - * These are path utilities that munge paths without actually - * looking at the real filesystem. - */ - -/* - * The dirname() function shall take a pointer to a character string - * that contains a pathname, and return a pointer to a string that is a - * pathname of the parent directory of that file. Trailing '/' characters - * in the path are not counted as part of the path. - * - * If path does not contain a '/', then dirname() shall return a pointer to - * the string ".". If path is a null pointer or points to an empty string, - * dirname() shall return a pointer to the string "." . - * - * The `git_path_dirname` implementation is thread safe. The returned - * string must be manually free'd. - * - * The `git_path_dirname_r` implementation writes the dirname to a `git_str` - * if the buffer pointer is not NULL. - * It returns an error code < 0 if there is an allocation error, otherwise - * the length of the dirname (which will be > 0). - */ -extern char *git_path_dirname(const char *path); -extern int git_path_dirname_r(git_str *buffer, const char *path); - -/* - * This function returns the basename of the file, which is the last - * part of its full name given by fname, with the drive letter and - * leading directories stripped off. For example, the basename of - * c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo. - * - * Trailing slashes and backslashes are significant: the basename of - * c:/foo/bar/ is an empty string after the rightmost slash. - * - * The `git_path_basename` implementation is thread safe. The returned - * string must be manually free'd. - * - * The `git_path_basename_r` implementation writes the basename to a `git_str`. - * It returns an error code < 0 if there is an allocation error, otherwise - * the length of the basename (which will be >= 0). - */ -extern char *git_path_basename(const char *path); -extern int git_path_basename_r(git_str *buffer, const char *path); - -/* Return the offset of the start of the basename. Unlike the other - * basename functions, this returns 0 if the path is empty. - */ -extern size_t git_path_basename_offset(git_str *buffer); - -/** - * Find offset to root of path if path has one. - * - * This will return a number >= 0 which is the offset to the start of the - * path, if the path is rooted (i.e. "/rooted/path" returns 0 and - * "c:/windows/rooted/path" returns 2). If the path is not rooted, this - * returns -1. - */ -extern int git_path_root(const char *path); - -/** - * Ensure path has a trailing '/'. - */ -extern int git_path_to_dir(git_str *path); - -/** - * Ensure string has a trailing '/' if there is space for it. - */ -extern void git_path_string_to_dir(char *path, size_t size); - -/** - * Taken from git.git; returns nonzero if the given path is "." or "..". - */ -GIT_INLINE(int) git_path_is_dot_or_dotdot(const char *name) -{ - return (name[0] == '.' && - (name[1] == '\0' || - (name[1] == '.' && name[2] == '\0'))); -} - -#ifdef GIT_WIN32 -GIT_INLINE(int) git_path_is_dot_or_dotdotW(const wchar_t *name) -{ - return (name[0] == L'.' && - (name[1] == L'\0' || - (name[1] == L'.' && name[2] == L'\0'))); -} - -#define git_path_is_absolute(p) \ - (git__isalpha((p)[0]) && (p)[1] == ':' && ((p)[2] == '\\' || (p)[2] == '/')) - -#define git_path_is_dirsep(p) \ - ((p) == '/' || (p) == '\\') - -/** - * Convert backslashes in path to forward slashes. - */ -GIT_INLINE(void) git_path_mkposix(char *path) -{ - while (*path) { - if (*path == '\\') - *path = '/'; - - path++; - } -} -#else -# define git_path_mkposix(p) /* blank */ - -#define git_path_is_absolute(p) \ - ((p)[0] == '/') - -#define git_path_is_dirsep(p) \ - ((p) == '/') - -#endif - -/** - * Check if string is a relative path (i.e. starts with "./" or "../") - */ -GIT_INLINE(int) git_path_is_relative(const char *p) -{ - return (p[0] == '.' && (p[1] == '/' || (p[1] == '.' && p[2] == '/'))); -} - -/** - * Check if string is at end of path segment (i.e. looking at '/' or '\0') - */ -GIT_INLINE(int) git_path_at_end_of_segment(const char *p) -{ - return !*p || *p == '/'; -} - -extern int git__percent_decode(git_str *decoded_out, const char *input); - -/** - * Extract path from file:// URL. - */ -extern int git_path_fromurl(git_str *local_path_out, const char *file_url); - - -/** - * Path filesystem utils - * - * These are path utilities that actually access the filesystem. - */ - -/** - * Check if a file exists and can be accessed. - * @return true or false - */ -extern bool git_path_exists(const char *path); - -/** - * Check if the given path points to a directory. - * @return true or false - */ -extern bool git_path_isdir(const char *path); - -/** - * Check if the given path points to a regular file. - * @return true or false - */ -extern bool git_path_isfile(const char *path); - -/** - * Check if the given path points to a symbolic link. - * @return true or false - */ -extern bool git_path_islink(const char *path); - -/** - * Check if the given path is a directory, and is empty. - */ -extern bool git_path_is_empty_dir(const char *path); - -/** - * Stat a file and/or link and set error if needed. - */ -extern int git_path_lstat(const char *path, struct stat *st); - -/** - * Check if the parent directory contains the item. - * - * @param dir Directory to check. - * @param item Item that might be in the directory. - * @return 0 if item exists in directory, <0 otherwise. - */ -extern bool git_path_contains(git_str *dir, const char *item); - -/** - * Check if the given path contains the given subdirectory. - * - * @param parent Directory path that might contain subdir - * @param subdir Subdirectory name to look for in parent - * @return true if subdirectory exists, false otherwise. - */ -extern bool git_path_contains_dir(git_str *parent, const char *subdir); - -/** - * Determine the common directory length between two paths, including - * the final path separator. For example, given paths 'a/b/c/1.txt - * and 'a/b/c/d/2.txt', the common directory is 'a/b/c/', and this - * will return the length of the string 'a/b/c/', which is 6. - * - * @param one The first path - * @param two The second path - * @return The length of the common directory - */ -extern size_t git_path_common_dirlen(const char *one, const char *two); - -/** - * Make the path relative to the given parent path. - * - * @param path The path to make relative - * @param parent The parent path to make path relative to - * @return 0 if path was made relative, GIT_ENOTFOUND - * if there was not common root between the paths, - * or <0. - */ -extern int git_path_make_relative(git_str *path, const char *parent); - -/** - * Check if the given path contains the given file. - * - * @param dir Directory path that might contain file - * @param file File name to look for in parent - * @return true if file exists, false otherwise. - */ -extern bool git_path_contains_file(git_str *dir, const char *file); - -/** - * Prepend base to unrooted path or just copy path over. - * - * This will optionally return the index into the path where the "root" - * is, either the end of the base directory prefix or the path root. - */ -extern int git_path_join_unrooted( - git_str *path_out, const char *path, const char *base, ssize_t *root_at); - -/** - * Removes multiple occurrences of '/' in a row, squashing them into a - * single '/'. - */ -extern void git_path_squash_slashes(git_str *path); - -/** - * Clean up path, prepending base if it is not already rooted. - */ -extern int git_path_prettify(git_str *path_out, const char *path, const char *base); - -/** - * Clean up path, prepending base if it is not already rooted and - * appending a slash. - */ -extern int git_path_prettify_dir(git_str *path_out, const char *path, const char *base); - -/** - * Get a directory from a path. - * - * If path is a directory, this acts like `git_path_prettify_dir` - * (cleaning up path and appending a '/'). If path is a normal file, - * this prettifies it, then removed the filename a la dirname and - * appends the trailing '/'. If the path does not exist, it is - * treated like a regular filename. - */ -extern int git_path_find_dir(git_str *dir); - -/** - * Resolve relative references within a path. - * - * This eliminates "./" and "../" relative references inside a path, - * as well as condensing multiple slashes into single ones. It will - * not touch the path before the "ceiling" length. - * - * Additionally, this will recognize an "c:/" drive prefix or a "xyz://" URL - * prefix and not touch that part of the path. - */ -extern int git_path_resolve_relative(git_str *path, size_t ceiling); - -/** - * Apply a relative path to base path. - * - * Note that the base path could be a filename or a URL and this - * should still work. The relative path is walked segment by segment - * with three rules: series of slashes will be condensed to a single - * slash, "." will be eaten with no change, and ".." will remove a - * segment from the base path. - */ -extern int git_path_apply_relative(git_str *target, const char *relpath); - -enum { - GIT_PATH_DIR_IGNORE_CASE = (1u << 0), - GIT_PATH_DIR_PRECOMPOSE_UNICODE = (1u << 1), - GIT_PATH_DIR_INCLUDE_DOT_AND_DOTDOT = (1u << 2), -}; - -/** - * Walk each directory entry, except '.' and '..', calling fn(state). - * - * @param pathbuf Buffer the function reads the initial directory - * path from, and updates with each successive entry's name. - * @param flags Combination of GIT_PATH_DIR flags. - * @param callback Callback for each entry. Passed the `payload` and each - * successive path inside the directory as a full path. This may - * safely append text to the pathbuf if needed. Return non-zero to - * cancel iteration (and return value will be propagated back). - * @param payload Passed to callback as first argument. - * @return 0 on success or error code from OS error or from callback - */ -extern int git_path_direach( - git_str *pathbuf, - uint32_t flags, - int (*callback)(void *payload, git_str *path), - void *payload); - -/** - * Sort function to order two paths - */ -extern int git_path_cmp( - const char *name1, size_t len1, int isdir1, - const char *name2, size_t len2, int isdir2, - int (*compare)(const char *, const char *, size_t)); - -/** - * Invoke callback up path directory by directory until the ceiling is - * reached (inclusive of a final call at the root_path). - * - * Returning anything other than 0 from the callback function - * will stop the iteration and propagate the error to the caller. - * - * @param pathbuf Buffer the function reads the directory from and - * and updates with each successive name. - * @param ceiling Prefix of path at which to stop walking up. If NULL, - * this will walk all the way up to the root. If not a prefix of - * pathbuf, the callback will be invoked a single time on the - * original input path. - * @param callback Function to invoke on each path. Passed the `payload` - * and the buffer containing the current path. The path should not - * be modified in any way. Return non-zero to stop iteration. - * @param payload Passed to fn as the first ath. - */ -extern int git_path_walk_up( - git_str *pathbuf, - const char *ceiling, - int (*callback)(void *payload, const char *path), - void *payload); - - -enum { GIT_PATH_NOTEQUAL = 0, GIT_PATH_EQUAL = 1, GIT_PATH_PREFIX = 2 }; - -/* - * Determines if a path is equal to or potentially a child of another. - * @param parent The possible parent - * @param child The possible child - */ -GIT_INLINE(int) git_path_equal_or_prefixed( - const char *parent, - const char *child, - ssize_t *prefixlen) -{ - const char *p = parent, *c = child; - int lastslash = 0; - - while (*p && *c) { - lastslash = (*p == '/'); - - if (*p++ != *c++) - return GIT_PATH_NOTEQUAL; - } - - if (*p != '\0') - return GIT_PATH_NOTEQUAL; - - if (*c == '\0') { - if (prefixlen) - *prefixlen = p - parent; - - return GIT_PATH_EQUAL; - } - - if (*c == '/' || lastslash) { - if (prefixlen) - *prefixlen = (p - parent) - lastslash; - - return GIT_PATH_PREFIX; - } - - return GIT_PATH_NOTEQUAL; -} - -/* translate errno to libgit2 error code and set error message */ -extern int git_path_set_error( - int errno_value, const char *path, const char *action); - -/* check if non-ascii characters are present in filename */ -extern bool git_path_has_non_ascii(const char *path, size_t pathlen); - -#define GIT_PATH_REPO_ENCODING "UTF-8" - -#ifdef __APPLE__ -#define GIT_PATH_NATIVE_ENCODING "UTF-8-MAC" -#else -#define GIT_PATH_NATIVE_ENCODING "UTF-8" -#endif - -#ifdef GIT_USE_ICONV - -#include - -typedef struct { - iconv_t map; - git_str buf; -} git_path_iconv_t; - -#define GIT_PATH_ICONV_INIT { (iconv_t)-1, GIT_STR_INIT } - -/* Init iconv data for converting decomposed UTF-8 to precomposed */ -extern int git_path_iconv_init_precompose(git_path_iconv_t *ic); - -/* Clear allocated iconv data */ -extern void git_path_iconv_clear(git_path_iconv_t *ic); - -/* - * Rewrite `in` buffer using iconv map if necessary, replacing `in` - * pointer internal iconv buffer if rewrite happened. The `in` pointer - * will be left unchanged if no rewrite was needed. - */ -extern int git_path_iconv(git_path_iconv_t *ic, const char **in, size_t *inlen); - -#endif /* GIT_USE_ICONV */ - -extern bool git_path_does_fs_decompose_unicode(const char *root); - - -typedef struct git_path_diriter git_path_diriter; - -#if defined(GIT_WIN32) && !defined(__MINGW32__) - -struct git_path_diriter -{ - git_win32_path path; - size_t parent_len; - - git_str path_utf8; - size_t parent_utf8_len; - - HANDLE handle; - - unsigned int flags; - - WIN32_FIND_DATAW current; - unsigned int needs_next; -}; - -#define GIT_PATH_DIRITER_INIT { {0}, 0, GIT_STR_INIT, 0, INVALID_HANDLE_VALUE } - -#else - -struct git_path_diriter -{ - git_str path; - size_t parent_len; - - unsigned int flags; - - DIR *dir; - -#ifdef GIT_USE_ICONV - git_path_iconv_t ic; -#endif -}; - -#define GIT_PATH_DIRITER_INIT { GIT_STR_INIT } - -#endif - -/** - * Initialize a directory iterator. - * - * @param diriter Pointer to a diriter structure that will be setup. - * @param path The path that will be iterated over - * @param flags Directory reader flags - * @return 0 or an error code - */ -extern int git_path_diriter_init( - git_path_diriter *diriter, - const char *path, - unsigned int flags); - -/** - * Advance the directory iterator. Will return GIT_ITEROVER when - * the iteration has completed successfully. - * - * @param diriter The directory iterator - * @return 0, GIT_ITEROVER, or an error code - */ -extern int git_path_diriter_next(git_path_diriter *diriter); - -/** - * Returns the file name of the current item in the iterator. - * - * @param out Pointer to store the path in - * @param out_len Pointer to store the length of the path in - * @param diriter The directory iterator - * @return 0 or an error code - */ -extern int git_path_diriter_filename( - const char **out, - size_t *out_len, - git_path_diriter *diriter); - -/** - * Returns the full path of the current item in the iterator; that - * is the current filename plus the path of the directory that the - * iterator was constructed with. - * - * @param out Pointer to store the path in - * @param out_len Pointer to store the length of the path in - * @param diriter The directory iterator - * @return 0 or an error code - */ -extern int git_path_diriter_fullpath( - const char **out, - size_t *out_len, - git_path_diriter *diriter); - -/** - * Performs an `lstat` on the current item in the iterator. - * - * @param out Pointer to store the stat data in - * @param diriter The directory iterator - * @return 0 or an error code - */ -extern int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter); - -/** - * Closes the directory iterator. - * - * @param diriter The directory iterator - */ -extern void git_path_diriter_free(git_path_diriter *diriter); - -/** - * Load all directory entries (except '.' and '..') into a vector. - * - * For cases where `git_path_direach()` is not appropriate, this - * allows you to load the filenames in a directory into a vector - * of strings. That vector can then be sorted, iterated, or whatever. - * Remember to free alloc of the allocated strings when you are done. - * - * @param contents Vector to fill with directory entry names. - * @param path The directory to read from. - * @param prefix_len When inserting entries, the trailing part of path - * will be prefixed after this length. I.e. given path "/a/b" and - * prefix_len 3, the entries will look like "b/e1", "b/e2", etc. - * @param flags Combination of GIT_PATH_DIR flags. - */ -extern int git_path_dirload( - git_vector *contents, - const char *path, - size_t prefix_len, - uint32_t flags); - - -/* Used for paths to repositories on the filesystem */ -extern bool git_path_is_local_file_url(const char *file_url); -extern int git_path_from_url_or_path(git_str *local_path_out, const char *url_or_path); - -/* Flags to determine path validity in `git_path_isvalid` */ -#define GIT_PATH_REJECT_TRAVERSAL (1 << 0) -#define GIT_PATH_REJECT_DOT_GIT (1 << 1) -#define GIT_PATH_REJECT_SLASH (1 << 2) -#define GIT_PATH_REJECT_BACKSLASH (1 << 3) -#define GIT_PATH_REJECT_TRAILING_DOT (1 << 4) -#define GIT_PATH_REJECT_TRAILING_SPACE (1 << 5) -#define GIT_PATH_REJECT_TRAILING_COLON (1 << 6) -#define GIT_PATH_REJECT_DOS_PATHS (1 << 7) -#define GIT_PATH_REJECT_NT_CHARS (1 << 8) -#define GIT_PATH_REJECT_DOT_GIT_LITERAL (1 << 9) -#define GIT_PATH_REJECT_DOT_GIT_HFS (1 << 10) -#define GIT_PATH_REJECT_DOT_GIT_NTFS (1 << 11) - -/* Default path safety for writing files to disk: since we use the - * Win32 "File Namespace" APIs ("\\?\") we need to protect from - * paths that the normal Win32 APIs would not write. - */ -#ifdef GIT_WIN32 -# define GIT_PATH_REJECT_FILESYSTEM_DEFAULTS \ - GIT_PATH_REJECT_TRAVERSAL | \ - GIT_PATH_REJECT_BACKSLASH | \ - GIT_PATH_REJECT_TRAILING_DOT | \ - GIT_PATH_REJECT_TRAILING_SPACE | \ - GIT_PATH_REJECT_TRAILING_COLON | \ - GIT_PATH_REJECT_DOS_PATHS | \ - GIT_PATH_REJECT_NT_CHARS -#else -# define GIT_PATH_REJECT_FILESYSTEM_DEFAULTS \ - GIT_PATH_REJECT_TRAVERSAL -#endif - - /* Paths that should never be written into the working directory. */ +/* Paths that should never be written into the working directory. */ #define GIT_PATH_REJECT_WORKDIR_DEFAULTS \ - GIT_PATH_REJECT_FILESYSTEM_DEFAULTS | GIT_PATH_REJECT_DOT_GIT + GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS | GIT_PATH_REJECT_DOT_GIT /* Paths that should never be written to the index. */ #define GIT_PATH_REJECT_INDEX_DEFAULTS \ - GIT_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT + GIT_FS_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT -/** - * Validate a "bare" git path. This ensures that the given path is legal - * to place in the index or a tree. This should be checked by mechanisms - * like `git_index_add` and `git_treebuilder_insert` when taking user - * data, and by `git_checkout` before constructing on-disk paths. - * - * This will ensure that a git path does not contain any "unsafe" components, - * a '.' or '..' component, or a component that is ".git" (in any case). - * - * (Note: if you take or construct an on-disk path -- a workdir path, - * a path to a git repository or a reference name that could be a loose - * ref -- you should _also_ validate that with `git_path_validate_workdir`.) - * - * `repo` is optional. If specified, it will be used to determine the short - * path name to reject (if `GIT_PATH_REJECT_DOS_SHORTNAME` is specified), - * in addition to the default of "git~1". - */ extern bool git_path_validate( git_repository *repo, const char *path, - uint16_t mode, + uint16_t file_mode, unsigned int flags); -/** - * Validate an on-disk path, taking into account that it will have a - * suffix appended (eg, `.lock`). - */ -GIT_INLINE(int) git_path_validate_filesystem_with_suffix( - const char *path, - size_t path_len, - size_t suffix_len) -{ -#ifdef GIT_WIN32 - size_t path_chars, total_chars; - - path_chars = git_utf8_char_length(path, path_len); - - if (GIT_ADD_SIZET_OVERFLOW(&total_chars, path_chars, suffix_len) || - total_chars > MAX_PATH) { - git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%s'", path); - return -1; - } - return 0; -#else - GIT_UNUSED(path); - GIT_UNUSED(path_len); - GIT_UNUSED(suffix_len); - return 0; -#endif -} - -/** - * Validate an path on the filesystem. This ensures that the given - * path is valid for the operating system/platform; for example, this - * will ensure that the given absolute path is smaller than MAX_PATH on - * Windows. - * - * For paths within the working directory, you should use ensure that - * `core.longpaths` is obeyed. Use `git_path_validate_workdir`. - */ -GIT_INLINE(int) git_path_validate_filesystem( - const char *path, - size_t path_len) -{ - return git_path_validate_filesystem_with_suffix(path, path_len, 0); -} - -/** - * Validate a path relative to the repo's worktree. This ensures that - * the given working tree path is valid for the operating system/platform. - * This will ensure that an absolute path is smaller than MAX_PATH on - * Windows, while keeping `core.longpaths` configuration settings in mind. - * - * This should be checked by mechamisms like `git_checkout` after - * contructing on-disk paths and before trying to write them. - * - * If the repository is null, no repository configuration is applied. - */ -extern int git_path_validate_workdir( - git_repository *repo, - const char *path); -extern int git_path_validate_workdir_with_len( - git_repository *repo, - const char *path, - size_t path_len); -extern int git_path_validate_workdir_buf( - git_repository *repo, - git_str *buf); - -/** - * Convert any backslashes into slashes - */ -int git_path_normalize_slashes(git_str *out, const char *path); - -bool git_path_supports_symlinks(const char *dir); - -/** - * Validate a system file's ownership - * - * Verify that the file in question is owned by an administrator or system - * account, or at least by the current user. - * - * This function returns 0 if successful. If the file is not owned by any of - * these, or any other if there have been problems determining the file - * ownership, it returns -1. - */ -int git_path_validate_system_file_ownership(const char *path); - #endif diff --git a/src/posix.c b/src/posix.c index c40134824..b1f85dc94 100644 --- a/src/posix.c +++ b/src/posix.c @@ -7,7 +7,7 @@ #include "posix.h" -#include "path.h" +#include "fs_path.h" #include #include @@ -144,8 +144,8 @@ int p_getcwd(char *buffer_out, size_t size) if (cwd_buffer == NULL) return -1; - git_path_mkposix(buffer_out); - git_path_string_to_dir(buffer_out, size); /* append trailing slash */ + git_fs_path_mkposix(buffer_out); + git_fs_path_string_to_dir(buffer_out, size); /* append trailing slash */ return 0; } diff --git a/src/rebase.c b/src/rebase.c index 302fc81fc..26b03b38c 100644 --- a/src/rebase.c +++ b/src/rebase.c @@ -97,7 +97,7 @@ static int rebase_state_type( if (git_str_joinpath(&path, repo->gitdir, REBASE_APPLY_DIR) < 0) return -1; - if (git_path_isdir(git_str_cstr(&path))) { + if (git_fs_path_isdir(git_str_cstr(&path))) { type = GIT_REBASE_APPLY; goto done; } @@ -106,7 +106,7 @@ static int rebase_state_type( if (git_str_joinpath(&path, repo->gitdir, REBASE_MERGE_DIR) < 0) return -1; - if (git_path_isdir(git_str_cstr(&path))) { + if (git_fs_path_isdir(git_str_cstr(&path))) { type = GIT_REBASE_MERGE; goto done; } @@ -340,7 +340,7 @@ int git_rebase_open( if ((error = git_str_joinpath(&path, path.ptr, ORIG_HEAD_FILE)) < 0) goto done; - if (!git_path_isfile(path.ptr)) { + if (!git_fs_path_isfile(path.ptr)) { /* Previous versions of git.git used 'head' here; support that. */ git_str_truncate(&path, state_path_len); @@ -404,7 +404,7 @@ static int rebase_cleanup(git_rebase *rebase) if (!rebase || rebase->inmemory) return 0; - return git_path_isdir(rebase->state_path) ? + return git_fs_path_isdir(rebase->state_path) ? git_futils_rmdir_r(rebase->state_path, NULL, GIT_RMDIR_REMOVE_FILES) : 0; } diff --git a/src/refdb_fs.c b/src/refdb_fs.c index 37eb85ecc..39dc16e9d 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -18,6 +18,7 @@ #include "sortedcache.h" #include "signature.h" #include "wildmatch.h" +#include "path.h" #include #include @@ -76,7 +77,7 @@ GIT_INLINE(int) loose_path( if (git_str_joinpath(out, base, refname) < 0) return -1; - return git_path_validate_filesystem_with_suffix(out->ptr, out->size, + return git_fs_path_validate_filesystem_with_suffix(out->ptr, out->size, CONST_STRLEN(".lock")); } @@ -307,8 +308,8 @@ static int _dirent_loose_load(void *payload, git_str *full_path) if (git__suffixcmp(full_path->ptr, ".lock") == 0) return 0; - if (git_path_isdir(full_path->ptr)) { - int error = git_path_direach( + if (git_fs_path_isdir(full_path->ptr)) { + int error = git_fs_path_direach( full_path, backend->direach_flags, _dirent_loose_load, backend); /* Race with the filesystem, ignore it */ if (error == GIT_ENOTFOUND) { @@ -343,7 +344,7 @@ static int packed_loadloose(refdb_fs_backend *backend) * This will overwrite any old packed entries with their * updated loose versions */ - error = git_path_direach( + error = git_fs_path_direach( &refs_path, backend->direach_flags, _dirent_loose_load, backend); git_str_dispose(&refs_path); @@ -367,7 +368,7 @@ static int refdb_fs_backend__exists( if ((error = loose_path(&ref_path, backend->gitpath, ref_name)) < 0) goto out; - if (git_path_isfile(ref_path.ptr)) { + if (git_fs_path_isfile(ref_path.ptr)) { *exists = 1; goto out; } @@ -817,7 +818,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char * GIT_ASSERT_ARG(backend); GIT_ASSERT_ARG(name); - if (!git_path_validate(backend->repo, name, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) { + if (!git_path_validate(backend->repo, name, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) { git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", name); return GIT_EINVALIDSPEC; } @@ -1344,10 +1345,10 @@ static int refdb_fs_backend__prune_refs( if ((error = git_str_sets(&relative_path, ref_name)) < 0) goto cleanup; - git_path_squash_slashes(&relative_path); - if ((commonlen = git_path_common_dirlen("refs/heads/", git_str_cstr(&relative_path))) == strlen("refs/heads/") || - (commonlen = git_path_common_dirlen("refs/tags/", git_str_cstr(&relative_path))) == strlen("refs/tags/") || - (commonlen = git_path_common_dirlen("refs/remotes/", git_str_cstr(&relative_path))) == strlen("refs/remotes/")) { + git_fs_path_squash_slashes(&relative_path); + if ((commonlen = git_fs_path_common_dirlen("refs/heads/", git_str_cstr(&relative_path))) == strlen("refs/heads/") || + (commonlen = git_fs_path_common_dirlen("refs/tags/", git_str_cstr(&relative_path))) == strlen("refs/tags/") || + (commonlen = git_fs_path_common_dirlen("refs/remotes/", git_str_cstr(&relative_path))) == strlen("refs/remotes/")) { git_str_truncate(&relative_path, commonlen); @@ -1361,7 +1362,7 @@ static int refdb_fs_backend__prune_refs( git_str_cstr(&relative_path)); if (!error) - error = git_path_validate_filesystem(base_path.ptr, base_path.size); + error = git_fs_path_validate_filesystem(base_path.ptr, base_path.size); if (error < 0) goto cleanup; @@ -1741,7 +1742,7 @@ static int has_reflog(git_repository *repo, const char *name) if (reflog_path(&path, repo, name) < 0) goto cleanup; - ret = git_path_isfile(git_str_cstr(&path)); + ret = git_fs_path_isfile(git_str_cstr(&path)); cleanup: git_str_dispose(&path); @@ -1856,7 +1857,7 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char repo = backend->repo; - if (!git_path_validate(backend->repo, refname, 0, GIT_PATH_REJECT_FILESYSTEM_DEFAULTS)) { + if (!git_path_validate(backend->repo, refname, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) { git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", refname); return GIT_EINVALIDSPEC; } @@ -1864,7 +1865,7 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char if (reflog_path(&log_path, repo, refname) < 0) return -1; - if (!git_path_isfile(git_str_cstr(&log_path))) { + if (!git_fs_path_isfile(git_str_cstr(&log_path))) { git_error_set(GIT_ERROR_INVALID, "log file for reference '%s' doesn't exist", refname); error = -1; @@ -1973,11 +1974,11 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co /* If the new branch matches part of the namespace of a previously deleted branch, * there maybe an obsolete/unused directory (or directory hierarchy) in the way. */ - if (git_path_isdir(git_str_cstr(&path))) { + if (git_fs_path_isdir(git_str_cstr(&path))) { if ((error = git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_SKIP_NONEMPTY)) < 0) { if (error == GIT_ENOTFOUND) error = 0; - } else if (git_path_isdir(git_str_cstr(&path))) { + } else if (git_fs_path_isdir(git_str_cstr(&path))) { git_error_set(GIT_ERROR_REFERENCE, "cannot create reflog at '%s', there are reflogs beneath that folder", ref->name); error = GIT_EDIRECTORY; @@ -2031,7 +2032,7 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_ if ((error = loose_path(&new_path, git_str_cstr(&temp_path), git_str_cstr(&normalized))) < 0) return error; - if (!git_path_exists(git_str_cstr(&old_path))) { + if (!git_fs_path_exists(git_str_cstr(&old_path))) { error = GIT_ENOTFOUND; goto cleanup; } @@ -2059,7 +2060,7 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_ goto cleanup; } - if (git_path_isdir(git_str_cstr(&new_path)) && + if (git_fs_path_isdir(git_str_cstr(&new_path)) && (git_futils_rmdir_r(git_str_cstr(&new_path), NULL, GIT_RMDIR_SKIP_NONEMPTY) < 0)) { error = -1; goto cleanup; @@ -2096,7 +2097,7 @@ static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name if ((error = reflog_path(&path, backend->repo, name)) < 0) goto out; - if (!git_path_exists(path.ptr)) + if (!git_fs_path_exists(path.ptr)) goto out; if ((error = p_unlink(path.ptr)) < 0) @@ -2150,11 +2151,11 @@ int git_refdb_backend_fs( if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_IGNORECASE) && t) { backend->iterator_flags |= GIT_ITERATOR_IGNORE_CASE; - backend->direach_flags |= GIT_PATH_DIR_IGNORE_CASE; + backend->direach_flags |= GIT_FS_PATH_DIR_IGNORE_CASE; } if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_PRECOMPOSE) && t) { backend->iterator_flags |= GIT_ITERATOR_PRECOMPOSE_UNICODE; - backend->direach_flags |= GIT_PATH_DIR_PRECOMPOSE_UNICODE; + backend->direach_flags |= GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE; } if ((!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t) || git_repository__fsync_gitdir) diff --git a/src/refs.c b/src/refs.c index 0ac455d24..5c875b95b 100644 --- a/src/refs.c +++ b/src/refs.c @@ -902,7 +902,7 @@ int git_reference__normalize_name( bool validate = (flags & GIT_REFERENCE_FORMAT__VALIDATION_DISABLE) == 0; #ifdef GIT_USE_ICONV - git_path_iconv_t ic = GIT_PATH_ICONV_INIT; + git_fs_path_iconv_t ic = GIT_PATH_ICONV_INIT; #endif GIT_ASSERT_ARG(name); @@ -919,8 +919,8 @@ int git_reference__normalize_name( #ifdef GIT_USE_ICONV if ((flags & GIT_REFERENCE_FORMAT__PRECOMPOSE_UNICODE) != 0) { size_t namelen = strlen(current); - if ((error = git_path_iconv_init_precompose(&ic)) < 0 || - (error = git_path_iconv(&ic, ¤t, &namelen)) < 0) + if ((error = git_fs_path_iconv_init_precompose(&ic)) < 0 || + (error = git_fs_path_iconv(&ic, ¤t, &namelen)) < 0) goto cleanup; error = GIT_EINVALIDSPEC; } @@ -1011,7 +1011,7 @@ cleanup: git_str_dispose(buf); #ifdef GIT_USE_ICONV - git_path_iconv_clear(&ic); + git_fs_path_iconv_clear(&ic); #endif return error; diff --git a/src/repository.c b/src/repository.c index 29684e463..2f7ae9b3d 100644 --- a/src/repository.c +++ b/src/repository.c @@ -197,9 +197,9 @@ static int lookup_commondir(bool *separate, git_str *commondir, git_str *reposit * If there's no commondir file, the repository path is the * common path, but it needs a trailing slash. */ - if (!git_path_contains_file(repository_path, GIT_COMMONDIR_FILE)) { + if (!git_fs_path_contains_file(repository_path, GIT_COMMONDIR_FILE)) { if ((error = git_str_set(commondir, repository_path->ptr, repository_path->size)) == 0) - error = git_path_to_dir(commondir); + error = git_fs_path_to_dir(commondir); *separate = false; goto done; @@ -212,7 +212,7 @@ static int lookup_commondir(bool *separate, git_str *commondir, git_str *reposit goto done; git_str_rtrim(&common_link); - if (git_path_is_relative(common_link.ptr)) { + if (git_fs_path_is_relative(common_link.ptr)) { if ((error = git_str_joinpath(commondir, repository_path->ptr, common_link.ptr)) < 0) goto done; } else { @@ -222,7 +222,7 @@ static int lookup_commondir(bool *separate, git_str *commondir, git_str *reposit git_str_dispose(&common_link); /* Make sure the commondir path always has a trailing slash */ - error = git_path_prettify_dir(commondir, commondir->ptr, NULL); + error = git_fs_path_prettify_dir(commondir, commondir->ptr, NULL); done: return error; @@ -240,7 +240,7 @@ GIT_INLINE(int) validate_repo_path(git_str *path) CONST_STRLEN("objects/pack/pack-.pack.lock") + GIT_OID_HEXSZ; - return git_path_validate_filesystem_with_suffix( + return git_fs_path_validate_filesystem_with_suffix( path->ptr, path->size, suffix_len); } @@ -260,13 +260,13 @@ static int is_valid_repository_path(bool *out, git_str *repository_path, git_str return error; /* Ensure HEAD file exists */ - if (git_path_contains_file(repository_path, GIT_HEAD_FILE) == false) + if (git_fs_path_contains_file(repository_path, GIT_HEAD_FILE) == false) return 0; /* Check files in common dir */ - if (git_path_contains_dir(common_path, GIT_OBJECTS_DIR) == false) + if (git_fs_path_contains_dir(common_path, GIT_OBJECTS_DIR) == false) return 0; - if (git_path_contains_dir(common_path, GIT_REFS_DIR) == false) + if (git_fs_path_contains_dir(common_path, GIT_REFS_DIR) == false) return 0; /* Ensure the repo (and commondir) are valid paths */ @@ -357,8 +357,8 @@ static int load_workdir(git_repository *repo, git_config *config, git_str *paren git_str_attach(&worktree, gitlink, 0); - if ((git_path_dirname_r(&worktree, worktree.ptr)) < 0 || - git_path_to_dir(&worktree) < 0) { + if ((git_fs_path_dirname_r(&worktree, worktree.ptr)) < 0 || + git_fs_path_to_dir(&worktree) < 0) { error = -1; goto cleanup; } @@ -366,17 +366,17 @@ static int load_workdir(git_repository *repo, git_config *config, git_str *paren repo->workdir = git_str_detach(&worktree); } else if (ce && ce->value) { - if ((error = git_path_prettify_dir( + if ((error = git_fs_path_prettify_dir( &worktree, ce->value, repo->gitdir)) < 0) goto cleanup; repo->workdir = git_str_detach(&worktree); } - else if (parent_path && git_path_isdir(parent_path->ptr)) + else if (parent_path && git_fs_path_isdir(parent_path->ptr)) repo->workdir = git_str_detach(parent_path); else { - if (git_path_dirname_r(&worktree, repo->gitdir) < 0 || - git_path_to_dir(&worktree) < 0) { + if (git_fs_path_dirname_r(&worktree, repo->gitdir) < 0 || + git_fs_path_to_dir(&worktree) < 0) { error = -1; goto cleanup; } @@ -410,7 +410,7 @@ static size_t find_ceiling_dir_offset( GIT_ASSERT_ARG(path); - min_len = (size_t)(git_path_root(path) + 1); + min_len = (size_t)(git_fs_path_root(path) + 1); if (ceiling_directories == NULL || min_len == 0) return min_len; @@ -419,7 +419,7 @@ static size_t find_ceiling_dir_offset( for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++); len = sep - ceil; - if (len == 0 || len >= sizeof(buf) || git_path_root(ceil) == -1) + if (len == 0 || len >= sizeof(buf) || git_fs_path_root(ceil) == -1) continue; strncpy(buf, ceil, len); @@ -462,7 +462,7 @@ static int read_gitfile(git_str *path_out, const char *file_path) git_str_rtrim(&file); /* apparently on Windows, some people use backslashes in paths */ - git_path_mkposix(file.ptr); + git_fs_path_mkposix(file.ptr); if (git_str_len(&file) <= prefix_len || memcmp(git_str_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0) @@ -471,11 +471,11 @@ static int read_gitfile(git_str *path_out, const char *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) { + else if ((error = git_fs_path_dirname_r(path_out, file_path)) >= 0) { const char *gitlink = git_str_cstr(&file) + prefix_len; while (*gitlink && git__isspace(*gitlink)) gitlink++; - error = git_path_prettify_dir( + error = git_fs_path_prettify_dir( path_out, gitlink, git_str_cstr(path_out)); } @@ -504,7 +504,7 @@ static int find_repo( git_str_clear(gitdir_path); - error = git_path_prettify(&path, start_path, NULL); + error = git_fs_path_prettify(&path, start_path, NULL); if (error < 0) return error; @@ -545,7 +545,7 @@ static int find_repo( goto out; if (is_valid) { - if ((error = git_path_to_dir(&path)) < 0 || + if ((error = git_fs_path_to_dir(&path)) < 0 || (error = git_str_set(gitdir_path, path.ptr, path.size)) < 0) goto out; @@ -578,7 +578,7 @@ static int find_repo( /* Move up one directory. If we're in_dot_git, we'll search the * parent itself next. If we're !in_dot_git, we'll search .git * in the parent directory next (added at the top of the loop). */ - if ((error = git_path_dirname_r(&path, path.ptr)) < 0) + if ((error = git_fs_path_dirname_r(&path, path.ptr)) < 0) goto out; /* Once we've checked the directory (and .git if applicable), @@ -595,8 +595,8 @@ static int find_repo( if (workdir_path && !(flags & GIT_REPOSITORY_OPEN_BARE)) { if (!git_str_len(gitdir_path)) git_str_clear(workdir_path); - else if ((error = git_path_dirname_r(workdir_path, path.ptr)) < 0 || - (error = git_path_to_dir(workdir_path)) < 0) + else if ((error = git_fs_path_dirname_r(workdir_path, path.ptr)) < 0 || + (error = git_fs_path_to_dir(workdir_path)) < 0) goto out; } @@ -624,7 +624,7 @@ int git_repository_open_bare( bool is_valid; int error; - if ((error = git_path_prettify_dir(&path, bare_path, NULL)) < 0 || + if ((error = git_fs_path_prettify_dir(&path, bare_path, NULL)) < 0 || (error = is_valid_repository_path(&is_valid, &path, &common_path)) < 0) return error; @@ -838,7 +838,7 @@ static int repo_is_worktree(unsigned *out, const git_repository *repo) /* A 'gitdir' file inside a git directory is currently * only used when the repository is a working tree. */ - *out = !!git_path_exists(gitdir_link.ptr); + *out = !!git_fs_path_exists(gitdir_link.ptr); git_str_dispose(&gitdir_link); return error; @@ -1600,7 +1600,7 @@ static bool is_filesystem_case_insensitive(const char *gitdir_path) int is_insensitive = -1; if (!git_str_joinpath(&path, gitdir_path, "CoNfIg")) - is_insensitive = git_path_exists(git_str_cstr(&path)); + is_insensitive = git_fs_path_exists(git_str_cstr(&path)); git_str_dispose(&path); return is_insensitive; @@ -1639,7 +1639,7 @@ static bool are_symlinks_supported(const char *wd_path) goto done; #endif - if (!(symlinks = git_path_supports_symlinks(wd_path))) + if (!(symlinks = git_fs_path_supports_symlinks(wd_path))) goto done; done: @@ -1683,7 +1683,7 @@ static int repo_local_config( cfg_path = git_str_cstr(config_dir); /* make LOCAL config if missing */ - if (!git_path_isfile(cfg_path) && + if (!git_fs_path_isfile(cfg_path) && (error = create_empty_file(cfg_path, GIT_CONFIG_FILE_MODE)) < 0) return error; @@ -1741,7 +1741,7 @@ static int repo_init_fs_configs( #ifdef GIT_USE_ICONV if ((error = git_config_set_bool( cfg, "core.precomposeunicode", - git_path_does_fs_decompose_unicode(work_dir))) < 0) + git_fs_path_does_decompose_unicode(work_dir))) < 0) return error; /* on non-iconv platforms, don't even set core.precomposeunicode */ #endif @@ -1790,7 +1790,7 @@ static int repo_init_config( goto cleanup; if ((flags & GIT_REPOSITORY_INIT_RELATIVE_GITLINK)) - if ((error = git_path_make_relative(&worktree_path, repo_dir)) < 0) + if ((error = git_fs_path_make_relative(&worktree_path, repo_dir)) < 0) goto cleanup; SET_REPO_CONFIG(string, "core.worktree", worktree_path.ptr); @@ -1907,8 +1907,8 @@ static int repo_write_gitlink( git_str path_to_repo = GIT_STR_INIT; struct stat st; - git_path_dirname_r(&buf, to_repo); - git_path_to_dir(&buf); + git_fs_path_dirname_r(&buf, to_repo); + git_fs_path_to_dir(&buf); if (git_str_oom(&buf)) return -1; @@ -1935,7 +1935,7 @@ static int repo_write_gitlink( error = git_str_sets(&path_to_repo, to_repo); if (!error && use_relative_path) - error = git_path_make_relative(&path_to_repo, in_dir); + error = git_fs_path_make_relative(&path_to_repo, in_dir); if (!error) error = git_str_join(&buf, ' ', GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr); @@ -2132,11 +2132,11 @@ static int repo_init_directories( if (!is_bare) { if (opts->workdir_path) { - if (git_path_join_unrooted( + if (git_fs_path_join_unrooted( wd_path, opts->workdir_path, repo_path->ptr, NULL) < 0) return -1; } else if (has_dotgit) { - if (git_path_dirname_r(wd_path, repo_path->ptr) < 0) + if (git_fs_path_dirname_r(wd_path, repo_path->ptr) < 0) return -1; } else { git_error_set(GIT_ERROR_REPOSITORY, "cannot pick working directory" @@ -2144,7 +2144,7 @@ static int repo_init_directories( return -1; } - if (git_path_to_dir(wd_path) < 0) + if (git_fs_path_to_dir(wd_path) < 0) return -1; } else { git_str_clear(wd_path); @@ -2204,10 +2204,10 @@ static int repo_init_directories( /* prettify both directories now that they are created */ if (!error) { - error = git_path_prettify_dir(repo_path, repo_path->ptr, NULL); + error = git_fs_path_prettify_dir(repo_path, repo_path->ptr, NULL); if (!error && wd_path->size > 0) - error = git_path_prettify_dir(wd_path, wd_path->ptr, NULL); + error = git_fs_path_prettify_dir(wd_path, wd_path->ptr, NULL); } return error; @@ -2227,7 +2227,7 @@ static int repo_init_head(const char *repo_dir, const char *given) * A template may have set a HEAD; use that unless it's been * overridden by the caller's given initial head setting. */ - if (git_path_exists(head_path.ptr) && !given) + if (git_fs_path_exists(head_path.ptr) && !given) goto out; if (given) { @@ -2628,7 +2628,7 @@ int git_repository__item_path( } if (items[item].directory) { - if (git_path_to_dir(out) < 0) + if (git_fs_path_to_dir(out) < 0) return -1; } @@ -2662,7 +2662,7 @@ int git_repository_workdir_path( } if (!(error = git_str_joinpath(out, repo->workdir, path))) - error = git_path_validate_workdir_buf(repo, out); + error = git_fs_path_validate_workdir_buf(repo, out); return error; } @@ -2682,7 +2682,7 @@ int git_repository_set_workdir( GIT_ASSERT_ARG(repo); GIT_ASSERT_ARG(workdir); - if (git_path_prettify_dir(&path, workdir, NULL) < 0) + if (git_fs_path_prettify_dir(&path, workdir, NULL) < 0) return -1; if (repo->workdir && strcmp(repo->workdir, path.ptr) == 0) @@ -2857,8 +2857,8 @@ int git_repository_hashfile( GIT_ASSERT_ARG(path); GIT_ASSERT_ARG(repo); - if ((error = git_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 || - (error = git_path_validate_workdir_buf(repo, &full_path)) < 0) + if ((error = git_fs_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 || + (error = git_fs_path_validate_workdir_buf(repo, &full_path)) < 0) return error; /* @@ -3084,29 +3084,29 @@ int git_repository_state(git_repository *repo) if (git_str_puts(&repo_path, repo->gitdir) < 0) return -1; - if (git_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE)) + if (git_fs_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE)) state = GIT_REPOSITORY_STATE_REBASE_INTERACTIVE; - else if (git_path_contains_dir(&repo_path, GIT_REBASE_MERGE_DIR)) + else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_MERGE_DIR)) state = GIT_REPOSITORY_STATE_REBASE_MERGE; - else if (git_path_contains_file(&repo_path, GIT_REBASE_APPLY_REBASING_FILE)) + else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_REBASING_FILE)) state = GIT_REPOSITORY_STATE_REBASE; - else if (git_path_contains_file(&repo_path, GIT_REBASE_APPLY_APPLYING_FILE)) + else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_APPLYING_FILE)) state = GIT_REPOSITORY_STATE_APPLY_MAILBOX; - else if (git_path_contains_dir(&repo_path, GIT_REBASE_APPLY_DIR)) + else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_APPLY_DIR)) state = GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE; - else if (git_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE)) + else if (git_fs_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE)) state = GIT_REPOSITORY_STATE_MERGE; - else if (git_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE)) { + else if (git_fs_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE)) { state = GIT_REPOSITORY_STATE_REVERT; - if (git_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) { + if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) { state = GIT_REPOSITORY_STATE_REVERT_SEQUENCE; } - } else if (git_path_contains_file(&repo_path, GIT_CHERRYPICK_HEAD_FILE)) { + } else if (git_fs_path_contains_file(&repo_path, GIT_CHERRYPICK_HEAD_FILE)) { state = GIT_REPOSITORY_STATE_CHERRYPICK; - if (git_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) { + if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) { state = GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE; } - } else if (git_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE)) + } else if (git_fs_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE)) state = GIT_REPOSITORY_STATE_BISECT; git_str_dispose(&repo_path); @@ -3128,9 +3128,9 @@ int git_repository__cleanup_files( path = git_str_cstr(&buf); - if (git_path_isfile(path)) { + if (git_fs_path_isfile(path)) { error = p_unlink(path); - } else if (git_path_isdir(path)) { + } else if (git_fs_path_isdir(path)) { error = git_futils_rmdir_r(path, NULL, GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS); } @@ -3170,7 +3170,7 @@ int git_repository_is_shallow(git_repository *repo) if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0) return error; - error = git_path_lstat(path.ptr, &st); + error = git_fs_path_lstat(path.ptr, &st); git_str_dispose(&path); if (error == GIT_ENOTFOUND) { diff --git a/src/submodule.c b/src/submodule.c index b0f7294be..727b6c6e4 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -16,11 +16,12 @@ #include "repository.h" #include "tree.h" #include "iterator.h" -#include "path.h" +#include "fs_path.h" #include "str.h" #include "index.h" #include "worktree.h" #include "clone.h" +#include "path.h" #include "git2/config.h" #include "git2/sys/config.h" @@ -149,7 +150,7 @@ static int is_path_occupied(bool *occupied, git_repository *repo, const char *pa if ((error = git_str_sets(&dir, path)) < 0) goto out; - if ((error = git_path_to_dir(&dir)) < 0) + if ((error = git_fs_path_to_dir(&dir)) < 0) goto out; if ((error = git_index_find_prefix(NULL, index, dir.ptr)) != GIT_ENOTFOUND) { @@ -385,10 +386,10 @@ int git_submodule__lookup_with_cache( if (git_str_join3(&path, '/', git_repository_workdir(repo), name, DOT_GIT) < 0 || - git_path_validate_workdir_buf(NULL, &path) < 0) + git_fs_path_validate_workdir_buf(NULL, &path) < 0) return -1; - if (git_path_exists(path.ptr)) + if (git_fs_path_exists(path.ptr)) error = GIT_EEXISTS; git_str_dispose(&path); @@ -412,17 +413,17 @@ int git_submodule_name_is_valid(git_repository *repo, const char *name, int flag int error, isvalid; if (flags == 0) - flags = GIT_PATH_REJECT_FILESYSTEM_DEFAULTS; + flags = GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS; /* Avoid allocating a new string if we can avoid it */ if (strchr(name, '\\') != NULL) { - if ((error = git_path_normalize_slashes(&buf, name)) < 0) + if ((error = git_fs_path_normalize_slashes(&buf, name)) < 0) return error; } else { git_str_attach_notowned(&buf, name, strlen(name)); } - isvalid = git_path_validate(repo, buf.ptr, 0, flags); + isvalid = git_path_validate(repo, buf.ptr, 0, flags); git_str_dispose(&buf); return isvalid; @@ -743,16 +744,16 @@ static int git_submodule__resolve_url( /* We do this in all platforms in case someone on Windows created the .gitmodules */ if (strchr(url, '\\')) { - if ((error = git_path_normalize_slashes(&normalized, url)) < 0) + if ((error = git_fs_path_normalize_slashes(&normalized, url)) < 0) return error; url = normalized.ptr; } - if (git_path_is_relative(url)) { + if (git_fs_path_is_relative(url)) { if (!(error = get_url_base(out, repo))) - error = git_path_apply_relative(out, url); + error = git_fs_path_apply_relative(out, url); } else if (strchr(url, ':') != NULL || url[0] == '/') { error = git_str_sets(out, url); } else { @@ -805,7 +806,7 @@ int git_submodule_add_setup( if (git__prefixcmp(path, git_repository_workdir(repo)) == 0) path += strlen(git_repository_workdir(repo)); - if (git_path_root(path) >= 0) { + if (git_fs_path_root(path) >= 0) { git_error_set(GIT_ERROR_SUBMODULE, "submodule path must be a relative path"); error = -1; goto cleanup; @@ -846,8 +847,8 @@ int git_submodule_add_setup( /* if the repo does not already exist, then init a new repo and add it. * Otherwise, just add the existing repo. */ - if (!(git_path_exists(name.ptr) && - git_path_contains(&name, DOT_GIT))) { + if (!(git_fs_path_exists(name.ptr) && + git_fs_path_contains(&name, DOT_GIT))) { /* resolve the actual URL to use */ if ((error = git_submodule__resolve_url(&real_url, repo, url)) < 0) @@ -1568,13 +1569,13 @@ static int git_submodule__open( sm->flags |= GIT_SUBMODULE_STATUS__WD_OID_VALID; else git_error_clear(); - } else if (git_path_exists(path.ptr)) { + } else if (git_fs_path_exists(path.ptr)) { sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED | GIT_SUBMODULE_STATUS_IN_WD; } else { git_str_rtruncate_at_char(&path, '/'); /* remove "/.git" */ - if (git_path_isdir(path.ptr)) + if (git_fs_path_isdir(path.ptr)) sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED; } @@ -2105,10 +2106,10 @@ static int submodule_load_from_wd_lite(git_submodule *sm) if (git_repository_workdir_path(&path, sm->repo, sm->path) < 0) return -1; - if (git_path_isdir(path.ptr)) + if (git_fs_path_isdir(path.ptr)) sm->flags |= GIT_SUBMODULE_STATUS__WD_SCANNED; - if (git_path_contains(&path, DOT_GIT)) + if (git_fs_path_contains(&path, DOT_GIT)) sm->flags |= GIT_SUBMODULE_STATUS_IN_WD; git_str_dispose(&path); @@ -2160,7 +2161,7 @@ static git_config_backend *open_gitmodules( if (git_repository_workdir_path(&path, repo, GIT_MODULES_FILE) != 0) return NULL; - if (okay_to_create || git_path_isfile(path.ptr)) { + if (okay_to_create || git_fs_path_isfile(path.ptr)) { /* git_config_backend_from_file should only fail if OOM */ if (git_config_backend_from_file(&mods, path.ptr) < 0) mods = NULL; diff --git a/src/sysdir.c b/src/sysdir.c index 457d7f8a8..84d212e01 100644 --- a/src/sysdir.c +++ b/src/sysdir.c @@ -9,7 +9,7 @@ #include "runtime.h" #include "str.h" -#include "path.h" +#include "fs_path.h" #include #if GIT_WIN32 #include "win32/findfile.h" @@ -291,7 +291,7 @@ static int git_sysdir_find_in_dirlist( if (name) GIT_ERROR_CHECK_ERROR(git_str_joinpath(path, path->ptr, name)); - if (git_path_exists(path->ptr)) + if (git_fs_path_exists(path->ptr)) return 0; } diff --git a/src/transport.c b/src/transport.c index fa1d35fce..640ccacae 100644 --- a/src/transport.c +++ b/src/transport.c @@ -12,7 +12,7 @@ #include "git2/net.h" #include "git2/transport.h" #include "git2/sys/transport.h" -#include "path.h" +#include "fs_path.h" typedef struct transport_definition { char *prefix; @@ -82,7 +82,7 @@ static int transport_find_fn( * to a directory and if so assume local path, else assume SSH */ /* Check to see if the path points to a file on the local file system */ - if (!definition && git_path_exists(url) && git_path_isdir(url)) + if (!definition && git_fs_path_exists(url) && git_fs_path_isdir(url)) definition = &local_transport_definition; #endif @@ -98,7 +98,7 @@ static int transport_find_fn( #ifndef GIT_WIN32 /* Check to see if the path points to a file on the local file system */ - if (!definition && git_path_exists(url) && git_path_isdir(url)) + if (!definition && git_fs_path_exists(url) && git_fs_path_isdir(url)) definition = &local_transport_definition; #endif diff --git a/src/transports/local.c b/src/transports/local.c index 0656ea592..0983914b1 100644 --- a/src/transports/local.c +++ b/src/transports/local.c @@ -10,7 +10,7 @@ #include "pack-objects.h" #include "refs.h" #include "posix.h" -#include "path.h" +#include "fs_path.h" #include "repository.h" #include "odb.h" #include "push.h" @@ -226,7 +226,7 @@ static int local_connect( t->flags = flags; /* 'url' may be a url or path; convert to a path */ - if ((error = git_path_from_url_or_path(&buf, url)) < 0) { + if ((error = git_fs_path_from_url_or_path(&buf, url)) < 0) { git_str_dispose(&buf); return error; } @@ -352,7 +352,7 @@ static int local_push( GIT_UNUSED(cbs); /* 'push->remote->url' may be a url or path; convert to a path */ - if ((error = git_path_from_url_or_path(&buf, push->remote->url)) < 0) { + if ((error = git_fs_path_from_url_or_path(&buf, push->remote->url)) < 0) { git_str_dispose(&buf); return error; } diff --git a/src/tree.c b/src/tree.c index c1e39158d..256e72080 100644 --- a/src/tree.c +++ b/src/tree.c @@ -13,6 +13,7 @@ #include "futils.h" #include "tree-cache.h" #include "index.h" +#include "path.h" #define DEFAULT_TREE_SIZE 16 #define MAX_FILEMODE_BYTES 6 @@ -55,7 +56,7 @@ static int valid_entry_name(git_repository *repo, const char *filename) { return *filename != '\0' && git_path_validate(repo, filename, 0, - GIT_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT | GIT_PATH_REJECT_SLASH); + GIT_FS_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT | GIT_FS_PATH_REJECT_SLASH); } static int entry_sort_cmp(const void *a, const void *b) @@ -63,7 +64,7 @@ static int entry_sort_cmp(const void *a, const void *b) const git_tree_entry *e1 = (const git_tree_entry *)a; const git_tree_entry *e2 = (const git_tree_entry *)b; - return git_path_cmp( + return git_fs_path_cmp( e1->filename, e1->filename_len, git_tree_entry__is_tree(e1), e2->filename, e2->filename_len, git_tree_entry__is_tree(e2), git__strncmp); @@ -1171,7 +1172,7 @@ int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseli /* Figure out how much we need to change from the previous tree */ if (last_update) - common_prefix = git_path_common_dirlen(last_update->path, update->path); + common_prefix = git_fs_path_common_dirlen(last_update->path, update->path); /* * The entries are sorted, so when we find we're no @@ -1233,7 +1234,7 @@ int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseli { /* Make sure we're replacing something of the same type */ tree_stack_entry *last = git_array_last(stack); - char *basename = git_path_basename(update->path); + char *basename = git_fs_path_basename(update->path); const git_tree_entry *e = git_treebuilder_get(last->bld, basename); if (e && git_tree_entry_type(e) != git_object__type_from_filemode(update->filemode)) { git__free(basename); @@ -1252,7 +1253,7 @@ int git_tree_create_updated(git_oid *out, git_repository *repo, git_tree *baseli case GIT_TREE_UPDATE_REMOVE: { tree_stack_entry *last = git_array_last(stack); - char *basename = git_path_basename(update->path); + char *basename = git_fs_path_basename(update->path); error = git_treebuilder_remove(last->bld, basename); git__free(basename); break; diff --git a/src/win32/findfile.c b/src/win32/findfile.c index caa79398a..7578d960e 100644 --- a/src/win32/findfile.c +++ b/src/win32/findfile.c @@ -44,7 +44,7 @@ static int win32_path_to_8(git_str *dest, const wchar_t *src) } /* Convert backslashes to forward slashes */ - git_path_mkposix(utf8_path); + git_fs_path_mkposix(utf8_path); return git_str_sets(dest, utf8_path); } diff --git a/src/win32/path_w32.c b/src/win32/path_w32.c index e6640c85e..1f765f1de 100644 --- a/src/win32/path_w32.c +++ b/src/win32/path_w32.c @@ -57,7 +57,7 @@ static wchar_t *path__skip_server(wchar_t *path) wchar_t *c; for (c = path; *c; c++) { - if (git_path_is_dirsep(*c)) + if (git_fs_path_is_dirsep(*c)) return c + 1; } @@ -71,9 +71,9 @@ static wchar_t *path__skip_prefix(wchar_t *path) if (wcsncmp(path, L"UNC\\", 4) == 0) path = path__skip_server(path + 4); - else if (git_path_is_absolute(path)) + else if (git_fs_path_is_absolute(path)) path += PATH__ABSOLUTE_LEN; - } else if (git_path_is_absolute(path)) { + } else if (git_fs_path_is_absolute(path)) { path += PATH__ABSOLUTE_LEN; } else if (path__is_unc(path)) { path = path__skip_server(path + 2); @@ -204,7 +204,7 @@ int git_win32_path_from_utf8(git_win32_path out, const char *src) dest += PATH__NT_NAMESPACE_LEN; /* See if this is an absolute path (beginning with a drive letter) */ - if (git_path_is_absolute(src)) { + if (git_fs_path_is_absolute(src)) { if (git__utf8_to_16(dest, GIT_WIN_PATH_MAX, src) < 0) goto on_error; } @@ -228,7 +228,7 @@ int git_win32_path_from_utf8(git_win32_path out, const char *src) if (path__cwd(dest, GIT_WIN_PATH_MAX) < 0) goto on_error; - if (!git_path_is_absolute(dest)) { + if (!git_fs_path_is_absolute(dest)) { errno = ENOENT; goto on_error; } @@ -266,7 +266,7 @@ int git_win32_path_relative_from_utf8(git_win32_path out, const char *src) int len; /* Handle absolute paths */ - if (git_path_is_absolute(src) || + if (git_fs_path_is_absolute(src) || path__is_nt_namespace(src) || path__is_unc(src) || path__startswith_slash(src)) { @@ -305,7 +305,7 @@ int git_win32_path_to_utf8(git_win32_utf8_path dest, const wchar_t *src) if ((len = git__utf16_to_8(out, GIT_WIN_PATH_UTF8, src)) < 0) return len; - git_path_mkposix(dest); + git_fs_path_mkposix(dest); return len; } diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index f26983d97..398287f9e 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -418,10 +418,10 @@ static bool target_is_dir(const char *target, const char *path) git_win32_path resolved_w; bool isdir = true; - if (git_path_is_absolute(target)) + if (git_fs_path_is_absolute(target)) git_win32_path_from_utf8(resolved_w, target); - else if (git_path_dirname_r(&resolved, path) < 0 || - git_path_apply_relative(&resolved, target) < 0 || + else if (git_fs_path_dirname_r(&resolved, path) < 0 || + git_fs_path_apply_relative(&resolved, target) < 0 || git_win32_path_from_utf8(resolved_w, resolved.ptr) < 0) goto out; @@ -661,7 +661,7 @@ int p_getcwd(char *buffer_out, size_t size) return -1; } - git_path_mkposix(buffer_out); + git_fs_path_mkposix(buffer_out); return 0; } @@ -821,7 +821,7 @@ char *p_realpath(const char *orig_path, char *buffer) if (git_win32_path_to_utf8(buffer, buffer_w) < 0) return NULL; - git_path_mkposix(buffer); + git_fs_path_mkposix(buffer); return buffer; } diff --git a/src/worktree.c b/src/worktree.c index 92a0900b0..f0fc6d752 100644 --- a/src/worktree.c +++ b/src/worktree.c @@ -22,9 +22,9 @@ static bool is_worktree_dir(const char *dir) if (git_str_sets(&buf, dir) < 0) return -1; - error = git_path_contains_file(&buf, "commondir") - && git_path_contains_file(&buf, "gitdir") - && git_path_contains_file(&buf, "HEAD"); + error = git_fs_path_contains_file(&buf, "commondir") + && git_fs_path_contains_file(&buf, "gitdir") + && git_fs_path_contains_file(&buf, "HEAD"); git_str_dispose(&buf); return error; @@ -46,9 +46,9 @@ int git_worktree_list(git_strarray *wts, git_repository *repo) if ((error = git_str_joinpath(&path, repo->commondir, "worktrees/")) < 0) goto exit; - if (!git_path_exists(path.ptr) || git_path_is_empty_dir(path.ptr)) + if (!git_fs_path_exists(path.ptr) || git_fs_path_is_empty_dir(path.ptr)) goto exit; - if ((error = git_path_dirload(&worktrees, path.ptr, path.size, 0x0)) < 0) + if ((error = git_fs_path_dirload(&worktrees, path.ptr, path.size, 0x0)) < 0) goto exit; len = path.size; @@ -86,12 +86,12 @@ char *git_worktree__read_link(const char *base, const char *file) git_str_rtrim(&buf); - if (!git_path_is_relative(buf.ptr)) + if (!git_fs_path_is_relative(buf.ptr)) return git_str_detach(&buf); if (git_str_sets(&path, base) < 0) goto err; - if (git_path_apply_relative(&path, buf.ptr) < 0) + if (git_fs_path_apply_relative(&path, buf.ptr) < 0) goto err; git_str_dispose(&buf); @@ -136,7 +136,7 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char goto out; } - if ((error = git_path_validate_workdir(NULL, dir)) < 0) + if ((error = git_fs_path_validate_workdir(NULL, dir)) < 0) goto out; if ((wt = git__calloc(1, sizeof(*wt))) == NULL) { @@ -148,12 +148,12 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char (wt->commondir_path = git_worktree__read_link(dir, "commondir")) == NULL || (wt->gitlink_path = git_worktree__read_link(dir, "gitdir")) == NULL || (parent && (wt->parent_path = git__strdup(parent)) == NULL) || - (wt->worktree_path = git_path_dirname(wt->gitlink_path)) == NULL) { + (wt->worktree_path = git_fs_path_dirname(wt->gitlink_path)) == NULL) { error = -1; goto out; } - if ((error = git_path_prettify_dir(&gitdir, dir, NULL)) < 0) + if ((error = git_fs_path_prettify_dir(&gitdir, dir, NULL)) < 0) goto out; wt->gitdir_path = git_str_detach(&gitdir); @@ -214,11 +214,11 @@ int git_worktree_open_from_repository(git_worktree **out, git_repository *repo) gitdir = git_repository_path(repo); commondir = git_repository_commondir(repo); - if ((error = git_path_prettify_dir(&parent, "..", commondir)) < 0) + if ((error = git_fs_path_prettify_dir(&parent, "..", commondir)) < 0) goto out; /* The name is defined by the last component in '.git/worktree/%s' */ - name = git_path_basename(gitdir); + name = git_fs_path_basename(gitdir); if ((error = open_worktree_dir(out, parent.ptr, gitdir, name)) < 0) goto out; @@ -255,21 +255,21 @@ int git_worktree_validate(const git_worktree *wt) return GIT_ERROR; } - if (wt->parent_path && !git_path_exists(wt->parent_path)) { + if (wt->parent_path && !git_fs_path_exists(wt->parent_path)) { git_error_set(GIT_ERROR_WORKTREE, "worktree parent directory ('%s') does not exist ", wt->parent_path); return GIT_ERROR; } - if (!git_path_exists(wt->commondir_path)) { + if (!git_fs_path_exists(wt->commondir_path)) { git_error_set(GIT_ERROR_WORKTREE, "worktree common directory ('%s') does not exist ", wt->commondir_path); return GIT_ERROR; } - if (!git_path_exists(wt->worktree_path)) { + if (!git_fs_path_exists(wt->worktree_path)) { git_error_set(GIT_ERROR_WORKTREE, "worktree directory '%s' does not exist", wt->worktree_path); @@ -337,20 +337,20 @@ int git_worktree_add(git_worktree **out, git_repository *repo, /* Create gitdir directory ".git/worktrees/" */ if ((err = git_str_joinpath(&gitdir, repo->commondir, "worktrees")) < 0) goto out; - if (!git_path_exists(gitdir.ptr)) + if (!git_fs_path_exists(gitdir.ptr)) if ((err = git_futils_mkdir(gitdir.ptr, 0755, GIT_MKDIR_EXCL)) < 0) goto out; if ((err = git_str_joinpath(&gitdir, gitdir.ptr, name)) < 0) goto out; if ((err = git_futils_mkdir(gitdir.ptr, 0755, GIT_MKDIR_EXCL)) < 0) goto out; - if ((err = git_path_prettify_dir(&gitdir, gitdir.ptr, NULL)) < 0) + if ((err = git_fs_path_prettify_dir(&gitdir, gitdir.ptr, NULL)) < 0) goto out; /* Create worktree work dir */ if ((err = git_futils_mkdir(worktree, 0755, GIT_MKDIR_EXCL)) < 0) goto out; - if ((err = git_path_prettify_dir(&wddir, worktree, NULL)) < 0) + if ((err = git_fs_path_prettify_dir(&wddir, worktree, NULL)) < 0) goto out; if (wtopts.lock) { @@ -375,7 +375,7 @@ int git_worktree_add(git_worktree **out, git_repository *repo, goto out; /* Create gitdir files */ - if ((err = git_path_prettify_dir(&buf, repo->commondir, NULL) < 0) + if ((err = git_fs_path_prettify_dir(&buf, repo->commondir, NULL) < 0) || (err = git_str_putc(&buf, '\n')) < 0 || (err = write_wtfile(gitdir.ptr, "commondir", &buf)) < 0) goto out; @@ -494,7 +494,7 @@ static int git_worktree__is_locked(git_str *reason, const git_worktree *wt) if ((error = git_str_joinpath(&path, wt->gitdir_path, "locked")) < 0) goto out; - locked = git_path_exists(path.ptr); + locked = git_fs_path_exists(path.ptr); if (locked && reason && (error = git_futils_readbuffer(reason, path.ptr)) < 0) goto out; @@ -614,7 +614,7 @@ int git_worktree_prune(git_worktree *wt, /* Delete gitdir in parent repository */ if ((err = git_str_join3(&path, '/', wt->commondir_path, "worktrees", wt->name)) < 0) goto out; - if (!git_path_exists(path.ptr)) + if (!git_fs_path_exists(path.ptr)) { git_error_set(GIT_ERROR_WORKTREE, "worktree gitdir '%s' does not exist", path.ptr); err = -1; @@ -626,15 +626,15 @@ int git_worktree_prune(git_worktree *wt, /* Skip deletion of the actual working tree if it does * not exist or deletion was not requested */ if ((popts.flags & GIT_WORKTREE_PRUNE_WORKING_TREE) == 0 || - !git_path_exists(wt->gitlink_path)) + !git_fs_path_exists(wt->gitlink_path)) { goto out; } - if ((wtpath = git_path_dirname(wt->gitlink_path)) == NULL) + if ((wtpath = git_fs_path_dirname(wt->gitlink_path)) == NULL) goto out; git_str_attach(&path, wtpath, 0); - if (!git_path_exists(path.ptr)) + if (!git_fs_path_exists(path.ptr)) { git_error_set(GIT_ERROR_WORKTREE, "working tree '%s' does not exist", path.ptr); err = -1; diff --git a/tests/attr/repo.c b/tests/attr/repo.c index e7b975290..abd238154 100644 --- a/tests/attr/repo.c +++ b/tests/attr/repo.c @@ -283,7 +283,7 @@ void test_attr_repo__bare_repo_with_index(void) git_index_free(index); cl_must_pass(p_unlink("attr/.gitattributes")); - cl_assert(!git_path_exists("attr/.gitattributes")); + cl_assert(!git_fs_path_exists("attr/.gitattributes")); cl_git_pass(git_repository_set_bare(g_repo)); diff --git a/tests/checkout/conflict.c b/tests/checkout/conflict.c index 3f5e7162d..4a9e4b9fa 100644 --- a/tests/checkout/conflict.c +++ b/tests/checkout/conflict.c @@ -227,7 +227,7 @@ void test_checkout_conflict__ignored(void) cl_git_pass(git_checkout_index(g_repo, g_index, &opts)); - cl_assert(!git_path_exists(TEST_REPO_PATH "/conflicting.txt")); + cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/conflicting.txt")); } void test_checkout_conflict__ours(void) @@ -1030,15 +1030,15 @@ void test_checkout_conflict__update_only(void) ensure_workdir_contents("automergeable.txt", AUTOMERGEABLE_MERGED_FILE); ensure_workdir("directory_file-two/file", 0100644, CONFLICTING_OURS_OID); - cl_assert(!git_path_exists("merge-resolve/modify-delete")); - cl_assert(!git_path_exists("merge-resolve/test-one.txt")); - cl_assert(!git_path_exists("merge-resolve/test-one-side-one.txt")); - cl_assert(!git_path_exists("merge-resolve/test-one-side-two.txt")); - cl_assert(!git_path_exists("merge-resolve/test-one.txt~ours")); - cl_assert(!git_path_exists("merge-resolve/test-one.txt~theirs")); - cl_assert(!git_path_exists("merge-resolve/directory_file-one/file")); - cl_assert(!git_path_exists("merge-resolve/directory_file-one~ours")); - cl_assert(!git_path_exists("merge-resolve/directory_file-two~theirs")); + cl_assert(!git_fs_path_exists("merge-resolve/modify-delete")); + cl_assert(!git_fs_path_exists("merge-resolve/test-one.txt")); + cl_assert(!git_fs_path_exists("merge-resolve/test-one-side-one.txt")); + cl_assert(!git_fs_path_exists("merge-resolve/test-one-side-two.txt")); + cl_assert(!git_fs_path_exists("merge-resolve/test-one.txt~ours")); + cl_assert(!git_fs_path_exists("merge-resolve/test-one.txt~theirs")); + cl_assert(!git_fs_path_exists("merge-resolve/directory_file-one/file")); + cl_assert(!git_fs_path_exists("merge-resolve/directory_file-one~ours")); + cl_assert(!git_fs_path_exists("merge-resolve/directory_file-two~theirs")); } void test_checkout_conflict__path_filters(void) @@ -1076,9 +1076,9 @@ void test_checkout_conflict__path_filters(void) cl_git_pass(git_checkout_index(g_repo, g_index, &opts)); ensure_workdir_contents("conflicting-1.txt", CONFLICTING_DIFF3_FILE); - cl_assert(!git_path_exists("merge-resolve/conflicting-2.txt")); + cl_assert(!git_fs_path_exists("merge-resolve/conflicting-2.txt")); ensure_workdir_contents("conflicting-3.txt", AUTOMERGEABLE_MERGED_FILE); - cl_assert(!git_path_exists("merge-resolve/conflicting-4.txt")); + cl_assert(!git_fs_path_exists("merge-resolve/conflicting-4.txt")); } static void collect_progress( diff --git a/tests/checkout/crlf.c b/tests/checkout/crlf.c index eb4c61f39..8fd16a004 100644 --- a/tests/checkout/crlf.c +++ b/tests/checkout/crlf.c @@ -17,7 +17,7 @@ static int unlink_file(void *payload, git_str *path) { char *fn; - cl_assert(fn = git_path_basename(path->ptr)); + cl_assert(fn = git_fs_path_basename(path->ptr)); GIT_UNUSED(payload); @@ -39,7 +39,7 @@ void test_checkout_crlf__initialize(void) * check out over it. */ cl_git_pass(git_str_puts(&reponame, "crlf")); - cl_git_pass(git_path_direach(&reponame, 0, unlink_file, NULL)); + cl_git_pass(git_fs_path_direach(&reponame, 0, unlink_file, NULL)); if (GIT_EOL_NATIVE == GIT_EOL_CRLF) systype = "windows"; @@ -76,7 +76,7 @@ static int compare_file(void *payload, git_str *actual_path) int cmp_git, cmp_gitattributes; char *basename; - basename = git_path_basename(actual_path->ptr); + basename = git_fs_path_basename(actual_path->ptr); cmp_git = strcmp(basename, ".git"); cmp_gitattributes = strcmp(basename, ".gitattributes"); @@ -87,8 +87,8 @@ static int compare_file(void *payload, git_str *actual_path) cl_git_pass(git_str_joinpath(&expected_path, cd->dirname, basename)); - if (!git_path_isfile(expected_path.ptr) || - !git_path_isfile(actual_path->ptr)) + if (!git_fs_path_isfile(expected_path.ptr) || + !git_fs_path_isfile(actual_path->ptr)) goto done; if (git_futils_readbuffer(&actual_contents, actual_path->ptr) < 0 || @@ -107,7 +107,7 @@ done: if (failed) { git_str details = GIT_STR_INIT; git_str_printf(&details, "filename=%s, system=%s, autocrlf=%s, attrs={%s}", - git_path_basename(actual_path->ptr), systype, cd->autocrlf, cd->attrs); + git_fs_path_basename(actual_path->ptr), systype, cd->autocrlf, cd->attrs); clar__fail(__FILE__, __func__, __LINE__, "checked out contents did not match expected", details.ptr, 0); git_str_dispose(&details); @@ -166,7 +166,7 @@ static void test_checkout(const char *autocrlf, const char *attrs) cl_git_pass(git_checkout_head(g_repo, &opts)); compare_data.dirname = sandboxname.ptr; - cl_git_pass(git_path_direach(&reponame, 0, compare_file, &compare_data)); + cl_git_pass(git_fs_path_direach(&reponame, 0, compare_file, &compare_data)); cl_fixture_cleanup(expected_fixture.ptr); git_str_dispose(&expected_fixture); @@ -187,9 +187,9 @@ static void empty_workdir(const char *name) size_t i; const char *fn; - cl_git_pass(git_path_dirload(&contents, name, 0, 0)); + cl_git_pass(git_fs_path_dirload(&contents, name, 0, 0)); git_vector_foreach(&contents, i, fn) { - cl_assert(basename = git_path_basename(fn)); + cl_assert(basename = git_fs_path_basename(fn)); cmp = strncasecmp(basename, ".git", 4); git__free(basename); diff --git a/tests/checkout/head.c b/tests/checkout/head.c index 5b3a034e7..3b0bf4729 100644 --- a/tests/checkout/head.c +++ b/tests/checkout/head.c @@ -43,7 +43,7 @@ void test_checkout_head__with_index_only_tree(void) cl_git_pass(git_index_add_bypath(index, "newdir/newfile.txt")); cl_git_pass(git_index_write(index)); - cl_assert(git_path_isfile("testrepo/newdir/newfile.txt")); + cl_assert(git_fs_path_isfile("testrepo/newdir/newfile.txt")); cl_assert(git_index_get_bypath(index, "newdir/newfile.txt", 0) != NULL); git_index_free(index); @@ -55,7 +55,7 @@ void test_checkout_head__with_index_only_tree(void) cl_git_pass(git_repository_index(&index, g_repo)); - cl_assert(!git_path_isfile("testrepo/newdir/newfile.txt")); + cl_assert(!git_fs_path_isfile("testrepo/newdir/newfile.txt")); cl_assert(git_index_get_bypath(index, "newdir/newfile.txt", 0) == NULL); git_index_free(index); @@ -79,8 +79,8 @@ void test_checkout_head__do_not_remove_untracked_file(void) opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_git_pass(git_checkout_head(g_repo, &opts)); - cl_assert(!git_path_isfile("testrepo/tracked/tracked")); - cl_assert(git_path_isfile("testrepo/tracked/untracked")); + cl_assert(!git_fs_path_isfile("testrepo/tracked/tracked")); + cl_assert(git_fs_path_isfile("testrepo/tracked/untracked")); } void test_checkout_head__do_not_remove_untracked_file_in_subdir(void) @@ -104,9 +104,9 @@ void test_checkout_head__do_not_remove_untracked_file_in_subdir(void) opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_git_pass(git_checkout_head(g_repo, &opts)); - cl_assert(!git_path_isfile("testrepo/tracked/tracked")); - cl_assert(!git_path_isfile("testrepo/tracked/subdir/tracked")); - cl_assert(git_path_isfile("testrepo/tracked/subdir/untracked")); + cl_assert(!git_fs_path_isfile("testrepo/tracked/tracked")); + cl_assert(!git_fs_path_isfile("testrepo/tracked/subdir/tracked")); + cl_assert(git_fs_path_isfile("testrepo/tracked/subdir/untracked")); } void test_checkout_head__do_remove_untracked_paths(void) @@ -131,8 +131,8 @@ void test_checkout_head__do_remove_untracked_paths(void) opts.paths.count = 1; cl_git_pass(git_checkout_head(g_repo, &opts)); - cl_assert(git_path_isfile("testrepo/tracked/tracked")); - cl_assert(!git_path_isfile("testrepo/tracked/untracked")); + cl_assert(git_fs_path_isfile("testrepo/tracked/tracked")); + cl_assert(!git_fs_path_isfile("testrepo/tracked/untracked")); } void test_checkout_head__do_remove_tracked_subdir(void) @@ -158,9 +158,9 @@ void test_checkout_head__do_remove_tracked_subdir(void) opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_git_pass(git_checkout_head(g_repo, &opts)); - cl_assert(!git_path_isdir("testrepo/subdir/tracked")); - cl_assert(!git_path_isfile("testrepo/subdir/tracked-file")); - cl_assert(git_path_isfile("testrepo/subdir/untracked-file")); + cl_assert(!git_fs_path_isdir("testrepo/subdir/tracked")); + cl_assert(!git_fs_path_isfile("testrepo/subdir/tracked-file")); + cl_assert(git_fs_path_isfile("testrepo/subdir/untracked-file")); } void test_checkout_head__typechange_workdir(void) diff --git a/tests/checkout/icase.c b/tests/checkout/icase.c index 6c30765a3..d77c7abd5 100644 --- a/tests/checkout/icase.c +++ b/tests/checkout/icase.c @@ -50,8 +50,8 @@ static char *get_filename(const char *in) DIR *dir; struct dirent *de; - cl_assert(search_dirname = git_path_dirname(in)); - cl_assert(search_filename = git_path_basename(in)); + cl_assert(search_dirname = git_fs_path_dirname(in)); + cl_assert(search_filename = git_fs_path_basename(in)); cl_assert(dir = opendir(search_dirname)); @@ -134,7 +134,7 @@ void test_checkout_icase__refuses_to_overwrite_links_for_files(void) cl_git_fail(git_checkout_tree(repo, obj, &checkout_opts)); - cl_assert(!git_path_exists("tmp")); + cl_assert(!git_fs_path_exists("tmp")); assert_name_is("testrepo/BRANCH_FILE.txt"); } @@ -146,7 +146,7 @@ void test_checkout_icase__overwrites_links_for_files_when_forced(void) cl_git_pass(git_checkout_tree(repo, obj, &checkout_opts)); - cl_assert(!git_path_exists("tmp")); + cl_assert(!git_fs_path_exists("tmp")); assert_name_is("testrepo/new.txt"); } @@ -159,7 +159,7 @@ void test_checkout_icase__overwrites_empty_folders_for_files(void) cl_git_pass(git_checkout_tree(repo, obj, &checkout_opts)); assert_name_is("testrepo/new.txt"); - cl_assert(!git_path_isdir("testrepo/new.txt")); + cl_assert(!git_fs_path_isdir("testrepo/new.txt")); } void test_checkout_icase__refuses_to_overwrite_populated_folders_for_files(void) @@ -173,7 +173,7 @@ void test_checkout_icase__refuses_to_overwrite_populated_folders_for_files(void) cl_git_fail(git_checkout_tree(repo, obj, &checkout_opts)); assert_name_is("testrepo/BRANCH_FILE.txt"); - cl_assert(git_path_isdir("testrepo/BRANCH_FILE.txt")); + cl_assert(git_fs_path_isdir("testrepo/BRANCH_FILE.txt")); } void test_checkout_icase__overwrites_folders_for_files_when_forced(void) @@ -187,7 +187,7 @@ void test_checkout_icase__overwrites_folders_for_files_when_forced(void) cl_git_pass(git_checkout_tree(repo, obj, &checkout_opts)); assert_name_is("testrepo/new.txt"); - cl_assert(!git_path_isdir("testrepo/new.txt")); + cl_assert(!git_fs_path_isdir("testrepo/new.txt")); } void test_checkout_icase__refuses_to_overwrite_files_for_folders(void) @@ -199,7 +199,7 @@ void test_checkout_icase__refuses_to_overwrite_files_for_folders(void) cl_git_fail(git_checkout_tree(repo, obj, &checkout_opts)); assert_name_is("testrepo/A"); - cl_assert(!git_path_isdir("testrepo/A")); + cl_assert(!git_fs_path_isdir("testrepo/A")); } void test_checkout_icase__overwrites_files_for_folders_when_forced(void) @@ -211,7 +211,7 @@ void test_checkout_icase__overwrites_files_for_folders_when_forced(void) cl_git_pass(git_checkout_tree(repo, obj, &checkout_opts)); assert_name_is("testrepo/a"); - cl_assert(git_path_isdir("testrepo/a")); + cl_assert(git_fs_path_isdir("testrepo/a")); } void test_checkout_icase__refuses_to_overwrite_links_for_folders(void) @@ -222,7 +222,7 @@ void test_checkout_icase__refuses_to_overwrite_links_for_folders(void) cl_git_fail(git_checkout_tree(repo, obj, &checkout_opts)); - cl_assert(!git_path_exists("b.txt")); + cl_assert(!git_fs_path_exists("b.txt")); assert_name_is("testrepo/A"); } @@ -234,7 +234,7 @@ void test_checkout_icase__overwrites_links_for_folders_when_forced(void) cl_git_pass(git_checkout_tree(repo, obj, &checkout_opts)); - cl_assert(!git_path_exists("b.txt")); + cl_assert(!git_fs_path_exists("b.txt")); assert_name_is("testrepo/a"); } diff --git a/tests/checkout/index.c b/tests/checkout/index.c index 13eecc984..6a80d22c5 100644 --- a/tests/checkout/index.c +++ b/tests/checkout/index.c @@ -56,9 +56,9 @@ void test_checkout_index__can_create_missing_files(void) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; - cl_assert_equal_i(false, git_path_isfile("./testrepo/README")); - cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt")); - cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt")); + cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/README")); + cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/branch_file.txt")); + cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/new.txt")); opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING; @@ -77,7 +77,7 @@ void test_checkout_index__can_remove_untracked_files(void) cl_git_mkfile("./testrepo/dir/one", "one\n"); cl_git_mkfile("./testrepo/dir/subdir/two", "two\n"); - cl_assert_equal_i(true, git_path_isdir("./testrepo/dir/subdir/subsubdir")); + cl_assert_equal_i(true, git_fs_path_isdir("./testrepo/dir/subdir/subsubdir")); opts.checkout_strategy = GIT_CHECKOUT_SAFE | @@ -86,7 +86,7 @@ void test_checkout_index__can_remove_untracked_files(void) cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); - cl_assert_equal_i(false, git_path_isdir("./testrepo/dir")); + cl_assert_equal_i(false, git_fs_path_isdir("./testrepo/dir")); } void test_checkout_index__can_disable_pathspec_match(void) @@ -152,15 +152,15 @@ void test_checkout_index__honor_the_specified_pathspecs(void) opts.paths.strings = entries; opts.paths.count = 1; - cl_assert_equal_i(false, git_path_isfile("./testrepo/README")); - cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt")); - cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt")); + cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/README")); + cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/branch_file.txt")); + cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/new.txt")); opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING; cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); - cl_assert_equal_i(false, git_path_isfile("./testrepo/README")); + cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/README")); check_file_contents("./testrepo/branch_file.txt", "hi\nbye!\n"); check_file_contents("./testrepo/new.txt", "my new file\n"); } @@ -236,7 +236,7 @@ void test_checkout_index__honor_coresymlinks_default_true(void) cl_must_pass(p_mkdir("symlink", 0777)); - if (!git_path_supports_symlinks("symlink/test")) + if (!git_fs_path_supports_symlinks("symlink/test")) cl_skip(); #ifdef GIT_WIN32 @@ -269,7 +269,7 @@ void test_checkout_index__honor_coresymlinks_default_false(void) * supports symlinks. Bail entirely on POSIX platforms that * do support symlinks. */ - if (git_path_supports_symlinks("symlink/test")) + if (git_fs_path_supports_symlinks("symlink/test")) cl_skip(); #endif @@ -281,7 +281,7 @@ void test_checkout_index__coresymlinks_set_to_true_fails_when_unsupported(void) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; - if (git_path_supports_symlinks("testrepo/test")) { + if (git_fs_path_supports_symlinks("testrepo/test")) { cl_skip(); } @@ -297,7 +297,7 @@ void test_checkout_index__honor_coresymlinks_setting_set_to_true(void) char link_data[GIT_PATH_MAX]; size_t link_size = GIT_PATH_MAX; - if (!git_path_supports_symlinks("testrepo/test")) { + if (!git_fs_path_supports_symlinks("testrepo/test")) { cl_skip(); } @@ -578,8 +578,8 @@ void test_checkout_index__can_overcome_name_clashes(void) cl_git_pass(p_mkdir("./testrepo/path0", 0777)); cl_git_mkfile("./testrepo/path0/file0", "content\r\n"); - cl_assert(git_path_isfile("./testrepo/path1")); - cl_assert(git_path_isfile("./testrepo/path0/file0")); + cl_assert(git_fs_path_isfile("./testrepo/path1")); + cl_assert(git_fs_path_isfile("./testrepo/path0/file0")); opts.checkout_strategy = GIT_CHECKOUT_SAFE | @@ -587,14 +587,14 @@ void test_checkout_index__can_overcome_name_clashes(void) GIT_CHECKOUT_ALLOW_CONFLICTS; cl_git_pass(git_checkout_index(g_repo, index, &opts)); - cl_assert(git_path_isfile("./testrepo/path1")); - cl_assert(git_path_isfile("./testrepo/path0/file0")); + cl_assert(git_fs_path_isfile("./testrepo/path1")); + cl_assert(git_fs_path_isfile("./testrepo/path0/file0")); opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_git_pass(git_checkout_index(g_repo, index, &opts)); - cl_assert(git_path_isfile("./testrepo/path0")); - cl_assert(git_path_isfile("./testrepo/path1/file1")); + cl_assert(git_fs_path_isfile("./testrepo/path0")); + cl_assert(git_fs_path_isfile("./testrepo/path1/file1")); git_index_free(index); } @@ -622,9 +622,9 @@ void test_checkout_index__can_update_prefixed_files(void) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; - cl_assert_equal_i(false, git_path_isfile("./testrepo/README")); - cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt")); - cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt")); + cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/README")); + cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/branch_file.txt")); + cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/new.txt")); cl_git_mkfile("./testrepo/READ", "content\n"); cl_git_mkfile("./testrepo/README.after", "content\n"); @@ -647,10 +647,10 @@ void test_checkout_index__can_update_prefixed_files(void) check_file_contents_nocr("./testrepo/branch_file.txt", "hi\nbye!\n"); check_file_contents_nocr("./testrepo/new.txt", "my new file\n"); - cl_assert(!git_path_exists("testrepo/READ")); - cl_assert(!git_path_exists("testrepo/README.after")); - cl_assert(!git_path_exists("testrepo/branch_file")); - cl_assert(!git_path_exists("testrepo/branch_file.txt.after")); + cl_assert(!git_fs_path_exists("testrepo/READ")); + cl_assert(!git_fs_path_exists("testrepo/README.after")); + cl_assert(!git_fs_path_exists("testrepo/branch_file")); + cl_assert(!git_fs_path_exists("testrepo/branch_file.txt.after")); } void test_checkout_index__can_checkout_a_newly_initialized_repository(void) @@ -688,7 +688,7 @@ void test_checkout_index__target_directory(void) opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING; opts.target_directory = "alternative"; - cl_assert(!git_path_isdir("alternative")); + cl_assert(!git_fs_path_isdir("alternative")); opts.notify_flags = GIT_CHECKOUT_NOTIFY_ALL; opts.notify_cb = checkout_count_callback; @@ -741,7 +741,7 @@ void test_checkout_index__target_directory_from_bare(void) cl_git_fail(git_checkout_index(g_repo, NULL, &opts)); opts.target_directory = "alternative"; - cl_assert(!git_path_isdir("alternative")); + cl_assert(!git_fs_path_isdir("alternative")); cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); @@ -765,9 +765,9 @@ void test_checkout_index__can_get_repo_from_index(void) git_index *index; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; - cl_assert_equal_i(false, git_path_isfile("./testrepo/README")); - cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt")); - cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt")); + cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/README")); + cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/branch_file.txt")); + cl_assert_equal_i(false, git_fs_path_isfile("./testrepo/new.txt")); opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING; diff --git a/tests/checkout/nasty.c b/tests/checkout/nasty.c index a1b3164be..732f1d5e8 100644 --- a/tests/checkout/nasty.c +++ b/tests/checkout/nasty.c @@ -38,7 +38,7 @@ static void test_checkout_passes(const char *refname, const char *filename) GIT_CHECKOUT_DONT_UPDATE_INDEX; cl_git_pass(git_checkout_tree(repo, (const git_object *)commit, &opts)); - cl_assert(!git_path_exists(path.ptr)); + cl_assert(!git_fs_path_exists(path.ptr)); git_commit_free(commit); git_str_dispose(&path); @@ -59,7 +59,7 @@ static void test_checkout_fails(const char *refname, const char *filename) opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_git_fail(git_checkout_tree(repo, (const git_object *)commit, &opts)); - cl_assert(!git_path_exists(path.ptr)); + cl_assert(!git_fs_path_exists(path.ptr)); git_commit_free(commit); git_str_dispose(&path); @@ -246,7 +246,7 @@ void test_checkout_nasty__only_looks_like_a_git_shortname(void) opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_git_pass(git_checkout_tree(repo, (const git_object *)commit, &opts)); - cl_assert(git_path_exists("nasty/git~3/foobar")); + cl_assert(git_fs_path_exists("nasty/git~3/foobar")); git_commit_free(commit); #endif diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c index cdfb456b7..2f54f4e3e 100644 --- a/tests/checkout/tree.c +++ b/tests/checkout/tree.c @@ -34,7 +34,7 @@ void test_checkout_tree__cleanup(void) cl_git_sandbox_cleanup(); - if (git_path_isdir("alternative")) + if (git_fs_path_isdir("alternative")) git_futils_rmdir_r("alternative", NULL, GIT_RMDIR_REMOVE_FILES); } @@ -54,17 +54,17 @@ void test_checkout_tree__can_checkout_a_subdirectory_from_a_commit(void) cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees")); - cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/")); + cl_assert_equal_i(false, git_fs_path_isdir("./testrepo/ab/")); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); - cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt")); - cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/fgh/1.txt")); + cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/ab/de/2.txt")); + cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/ab/de/fgh/1.txt")); } void test_checkout_tree__can_checkout_and_remove_directory(void) { - cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/")); + cl_assert_equal_i(false, git_fs_path_isdir("./testrepo/ab/")); /* Checkout brach "subtrees" and update HEAD, so that HEAD matches the * current working tree @@ -74,9 +74,9 @@ void test_checkout_tree__can_checkout_and_remove_directory(void) cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees")); - cl_assert_equal_i(true, git_path_isdir("./testrepo/ab/")); - cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt")); - cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/fgh/1.txt")); + cl_assert_equal_i(true, git_fs_path_isdir("./testrepo/ab/")); + cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/ab/de/2.txt")); + cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/ab/de/fgh/1.txt")); git_object_free(g_object); g_object = NULL; @@ -90,7 +90,7 @@ void test_checkout_tree__can_checkout_and_remove_directory(void) cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master")); /* This directory should no longer exist */ - cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/")); + cl_assert_equal_i(false, git_fs_path_isdir("./testrepo/ab/")); } void test_checkout_tree__can_checkout_a_subdirectory_from_a_subtree(void) @@ -102,12 +102,12 @@ void test_checkout_tree__can_checkout_a_subdirectory_from_a_subtree(void) cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees:ab")); - cl_assert_equal_i(false, git_path_isdir("./testrepo/de/")); + cl_assert_equal_i(false, git_fs_path_isdir("./testrepo/de/")); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); - cl_assert_equal_i(true, git_path_isfile("./testrepo/de/2.txt")); - cl_assert_equal_i(true, git_path_isfile("./testrepo/de/fgh/1.txt")); + cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/de/2.txt")); + cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/de/fgh/1.txt")); } static void progress(const char *path, size_t cur, size_t tot, void *payload) @@ -149,7 +149,7 @@ void test_checkout_tree__doesnt_write_unrequested_files_to_worktree(void) */ opts.checkout_strategy = GIT_CHECKOUT_NONE; git_checkout_tree(g_repo, (git_object*)p_chomped_commit, &opts); - cl_assert_equal_i(false, git_path_isfile("testrepo/readme.txt")); + cl_assert_equal_i(false, git_fs_path_isfile("testrepo/readme.txt")); git_commit_free(p_master_commit); git_commit_free(p_chomped_commit); @@ -174,12 +174,12 @@ void test_checkout_tree__can_switch_branches(void) cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir")); - cl_assert(git_path_isfile("testrepo/README")); - cl_assert(git_path_isfile("testrepo/branch_file.txt")); - cl_assert(git_path_isfile("testrepo/new.txt")); - cl_assert(git_path_isfile("testrepo/a/b.txt")); + cl_assert(git_fs_path_isfile("testrepo/README")); + cl_assert(git_fs_path_isfile("testrepo/branch_file.txt")); + cl_assert(git_fs_path_isfile("testrepo/new.txt")); + cl_assert(git_fs_path_isfile("testrepo/a/b.txt")); - cl_assert(!git_path_isdir("testrepo/ab")); + cl_assert(!git_fs_path_isdir("testrepo/ab")); assert_on_branch(g_repo, "dir"); @@ -194,15 +194,15 @@ void test_checkout_tree__can_switch_branches(void) cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees")); - cl_assert(git_path_isfile("testrepo/README")); - cl_assert(git_path_isfile("testrepo/branch_file.txt")); - cl_assert(git_path_isfile("testrepo/new.txt")); - cl_assert(git_path_isfile("testrepo/ab/4.txt")); - cl_assert(git_path_isfile("testrepo/ab/c/3.txt")); - cl_assert(git_path_isfile("testrepo/ab/de/2.txt")); - cl_assert(git_path_isfile("testrepo/ab/de/fgh/1.txt")); + cl_assert(git_fs_path_isfile("testrepo/README")); + cl_assert(git_fs_path_isfile("testrepo/branch_file.txt")); + cl_assert(git_fs_path_isfile("testrepo/new.txt")); + cl_assert(git_fs_path_isfile("testrepo/ab/4.txt")); + cl_assert(git_fs_path_isfile("testrepo/ab/c/3.txt")); + cl_assert(git_fs_path_isfile("testrepo/ab/de/2.txt")); + cl_assert(git_fs_path_isfile("testrepo/ab/de/fgh/1.txt")); - cl_assert(!git_path_isdir("testrepo/a")); + cl_assert(!git_fs_path_isdir("testrepo/a")); assert_on_branch(g_repo, "subtrees"); @@ -216,11 +216,11 @@ void test_checkout_tree__can_remove_untracked(void) opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_REMOVE_UNTRACKED; cl_git_mkfile("testrepo/untracked_file", "as you wish"); - cl_assert(git_path_isfile("testrepo/untracked_file")); + cl_assert(git_fs_path_isfile("testrepo/untracked_file")); cl_git_pass(git_checkout_head(g_repo, &opts)); - cl_assert(!git_path_isfile("testrepo/untracked_file")); + cl_assert(!git_fs_path_isfile("testrepo/untracked_file")); } void test_checkout_tree__can_remove_ignored(void) @@ -237,11 +237,11 @@ void test_checkout_tree__can_remove_ignored(void) cl_git_pass(git_ignore_path_is_ignored(&ignored, g_repo, "ignored_file")); cl_assert_equal_i(1, ignored); - cl_assert(git_path_isfile("testrepo/ignored_file")); + cl_assert(git_fs_path_isfile("testrepo/ignored_file")); cl_git_pass(git_checkout_head(g_repo, &opts)); - cl_assert(!git_path_isfile("testrepo/ignored_file")); + cl_assert(!git_fs_path_isfile("testrepo/ignored_file")); } static int checkout_tree_with_blob_ignored_in_workdir(int strategy, bool isdir) @@ -264,12 +264,12 @@ static int checkout_tree_with_blob_ignored_in_workdir(int strategy, bool isdir) cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir")); - cl_assert(git_path_isfile("testrepo/README")); - cl_assert(git_path_isfile("testrepo/branch_file.txt")); - cl_assert(git_path_isfile("testrepo/new.txt")); - cl_assert(git_path_isfile("testrepo/a/b.txt")); + cl_assert(git_fs_path_isfile("testrepo/README")); + cl_assert(git_fs_path_isfile("testrepo/branch_file.txt")); + cl_assert(git_fs_path_isfile("testrepo/new.txt")); + cl_assert(git_fs_path_isfile("testrepo/a/b.txt")); - cl_assert(!git_path_isdir("testrepo/ab")); + cl_assert(!git_fs_path_isdir("testrepo/ab")); assert_on_branch(g_repo, "dir"); @@ -285,12 +285,12 @@ static int checkout_tree_with_blob_ignored_in_workdir(int strategy, bool isdir) cl_git_mkfile("testrepo/ab/4.txt/file2.txt", "foo bar foo"); cl_git_mkfile("testrepo/ab/4.txt/file3.txt", "inky blinky pinky clyde"); - cl_assert(git_path_isdir("testrepo/ab/4.txt")); + cl_assert(git_fs_path_isdir("testrepo/ab/4.txt")); } else { cl_must_pass(p_mkdir("testrepo/ab", 0777)); cl_git_mkfile("testrepo/ab/4.txt", "as you wish"); - cl_assert(git_path_isfile("testrepo/ab/4.txt")); + cl_assert(git_fs_path_isfile("testrepo/ab/4.txt")); } cl_git_pass(git_ignore_add_rule(g_repo, "ab/4.txt\n")); @@ -324,7 +324,7 @@ void test_checkout_tree__can_overwrite_ignored_by_default(void) cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees")); - cl_assert(git_path_isfile("testrepo/ab/4.txt")); + cl_assert(git_fs_path_isfile("testrepo/ab/4.txt")); assert_on_branch(g_repo, "subtrees"); } @@ -345,7 +345,7 @@ void test_checkout_tree__can_overwrite_ignored_folder_by_default(void) cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees")); - cl_assert(git_path_isfile("testrepo/ab/4.txt")); + cl_assert(git_fs_path_isfile("testrepo/ab/4.txt")); assert_on_branch(g_repo, "subtrees"); @@ -364,7 +364,7 @@ void test_checkout_tree__can_update_only(void) opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_git_pass(git_checkout_head(g_repo, &opts)); - cl_assert(!git_path_isdir("testrepo/a")); + cl_assert(!git_fs_path_isdir("testrepo/a")); check_file_contents_nocr("testrepo/branch_file.txt", "hi\nbye!\n"); @@ -384,7 +384,7 @@ void test_checkout_tree__can_update_only(void) * the test_checkout_tree__can_switch_branches test), but with * UPDATE_ONLY it will not have been created. */ - cl_assert(!git_path_isdir("testrepo/a")); + cl_assert(!git_fs_path_isdir("testrepo/a")); /* but this file still should have been updated */ check_file_contents_nocr("testrepo/branch_file.txt", "hi\n"); @@ -410,10 +410,10 @@ void test_checkout_tree__can_checkout_with_pattern(void) git_object_free(g_object); g_object = NULL; - cl_assert(git_path_exists("testrepo/README")); - cl_assert(!git_path_exists("testrepo/branch_file.txt")); - cl_assert(!git_path_exists("testrepo/link_to_new.txt")); - cl_assert(!git_path_exists("testrepo/new.txt")); + cl_assert(git_fs_path_exists("testrepo/README")); + cl_assert(!git_fs_path_exists("testrepo/branch_file.txt")); + cl_assert(!git_fs_path_exists("testrepo/link_to_new.txt")); + cl_assert(!git_fs_path_exists("testrepo/new.txt")); /* now to a narrow patterned checkout */ @@ -425,10 +425,10 @@ void test_checkout_tree__can_checkout_with_pattern(void) cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); - cl_assert(git_path_exists("testrepo/README")); - cl_assert(!git_path_exists("testrepo/branch_file.txt")); - cl_assert(git_path_exists("testrepo/link_to_new.txt")); - cl_assert(git_path_exists("testrepo/new.txt")); + cl_assert(git_fs_path_exists("testrepo/README")); + cl_assert(!git_fs_path_exists("testrepo/branch_file.txt")); + cl_assert(git_fs_path_exists("testrepo/link_to_new.txt")); + cl_assert(git_fs_path_exists("testrepo/new.txt")); } void test_checkout_tree__pathlist_checkout_ignores_non_matches(void) @@ -445,10 +445,10 @@ void test_checkout_tree__pathlist_checkout_ignores_non_matches(void) cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master")); - cl_assert(git_path_exists("testrepo/README")); - cl_assert(git_path_exists("testrepo/branch_file.txt")); - cl_assert(git_path_exists("testrepo/link_to_new.txt")); - cl_assert(git_path_exists("testrepo/new.txt")); + cl_assert(git_fs_path_exists("testrepo/README")); + cl_assert(git_fs_path_exists("testrepo/branch_file.txt")); + cl_assert(git_fs_path_exists("testrepo/link_to_new.txt")); + cl_assert(git_fs_path_exists("testrepo/new.txt")); git_object_free(g_object); cl_git_pass(git_revparse_single(&g_object, g_repo, "8496071c1b46c854b31185ea97743be6a8774479")); @@ -460,10 +460,10 @@ void test_checkout_tree__pathlist_checkout_ignores_non_matches(void) cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); - cl_assert(git_path_exists("testrepo/README")); - cl_assert(!git_path_exists("testrepo/branch_file.txt")); - cl_assert(!git_path_exists("testrepo/link_to_new.txt")); - cl_assert(git_path_exists("testrepo/new.txt")); + cl_assert(git_fs_path_exists("testrepo/README")); + cl_assert(!git_fs_path_exists("testrepo/branch_file.txt")); + cl_assert(!git_fs_path_exists("testrepo/link_to_new.txt")); + cl_assert(git_fs_path_exists("testrepo/new.txt")); } void test_checkout_tree__can_disable_pattern_match(void) @@ -484,7 +484,7 @@ void test_checkout_tree__can_disable_pattern_match(void) git_object_free(g_object); g_object = NULL; - cl_assert(!git_path_isfile("testrepo/branch_file.txt")); + cl_assert(!git_fs_path_isfile("testrepo/branch_file.txt")); /* now to a narrow patterned checkout, but disable pattern */ @@ -498,7 +498,7 @@ void test_checkout_tree__can_disable_pattern_match(void) cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); - cl_assert(!git_path_isfile("testrepo/branch_file.txt")); + cl_assert(!git_fs_path_isfile("testrepo/branch_file.txt")); /* let's try that again, but allow the pattern match */ @@ -506,7 +506,7 @@ void test_checkout_tree__can_disable_pattern_match(void) cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); - cl_assert(git_path_isfile("testrepo/branch_file.txt")); + cl_assert(git_fs_path_isfile("testrepo/branch_file.txt")); } void assert_conflict( @@ -623,7 +623,7 @@ void test_checkout_tree__donot_update_deleted_file_by_default(void) cl_git_pass(git_index_remove_bypath(index ,"branch_file.txt")); cl_git_pass(git_index_write(index)); - cl_assert(!git_path_exists("testrepo/branch_file.txt")); + cl_assert(!git_fs_path_exists("testrepo/branch_file.txt")); cl_git_pass(git_oid_fromstr(&new_id, "099fabac3a9ea935598528c27f866e34089c2eff")); cl_git_pass(git_commit_lookup(&new_commit, g_repo, &new_id)); @@ -686,16 +686,16 @@ void test_checkout_tree__can_cancel_checkout_from_notify(void) opts.notify_payload = &ca; opts.checkout_strategy = GIT_CHECKOUT_FORCE; - cl_assert(!git_path_exists("testrepo/new.txt")); + cl_assert(!git_fs_path_exists("testrepo/new.txt")); cl_git_fail_with(git_checkout_tree(g_repo, obj, &opts), -5555); - cl_assert(!git_path_exists("testrepo/new.txt")); + cl_assert(!git_fs_path_exists("testrepo/new.txt")); /* on case-insensitive FS = a/b.txt, branch_file.txt, new.txt */ /* on case-sensitive FS = README, then above */ - if (git_path_exists("testrepo/.git/CoNfIg")) /* case insensitive */ + if (git_fs_path_exists("testrepo/.git/CoNfIg")) /* case insensitive */ cl_assert_equal_i(3, ca.count); else cl_assert_equal_i(4, ca.count); @@ -707,9 +707,9 @@ void test_checkout_tree__can_cancel_checkout_from_notify(void) cl_git_fail_with(git_checkout_tree(g_repo, obj, &opts), 123); - cl_assert(!git_path_exists("testrepo/new.txt")); + cl_assert(!git_fs_path_exists("testrepo/new.txt")); - if (git_path_exists("testrepo/.git/CoNfIg")) /* case insensitive */ + if (git_fs_path_exists("testrepo/.git/CoNfIg")) /* case insensitive */ cl_assert_equal_i(4, ca.count); else cl_assert_equal_i(1, ca.count); @@ -799,7 +799,7 @@ void test_checkout_tree__can_write_to_empty_dirs(void) cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); - cl_assert(git_path_isfile("testrepo/a/b.txt")); + cl_assert(git_fs_path_isfile("testrepo/a/b.txt")); git_object_free(obj); } @@ -818,7 +818,7 @@ void test_checkout_tree__fails_when_dir_in_use(void) cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); - cl_assert(git_path_isfile("testrepo/a/b.txt")); + cl_assert(git_fs_path_isfile("testrepo/a/b.txt")); git_object_free(obj); @@ -831,7 +831,7 @@ void test_checkout_tree__fails_when_dir_in_use(void) cl_git_pass(p_chdir("../..")); - cl_assert(git_path_is_empty_dir("testrepo/a")); + cl_assert(git_fs_path_is_empty_dir("testrepo/a")); git_object_free(obj); #endif @@ -852,7 +852,7 @@ void test_checkout_tree__can_continue_when_dir_in_use(void) cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); - cl_assert(git_path_isfile("testrepo/a/b.txt")); + cl_assert(git_fs_path_isfile("testrepo/a/b.txt")); git_object_free(obj); @@ -865,7 +865,7 @@ void test_checkout_tree__can_continue_when_dir_in_use(void) cl_git_pass(p_chdir("../..")); - cl_assert(git_path_is_empty_dir("testrepo/a")); + cl_assert(git_fs_path_is_empty_dir("testrepo/a")); git_object_free(obj); #endif @@ -896,7 +896,7 @@ void test_checkout_tree__target_directory_from_bare(void) cl_git_fail(git_checkout_tree(g_repo, g_object, &opts)); opts.target_directory = "alternative"; - cl_assert(!git_path_isdir("alternative")); + cl_assert(!git_fs_path_isdir("alternative")); cl_git_pass(git_checkout_tree(g_repo, g_object, &opts)); @@ -923,12 +923,12 @@ void test_checkout_tree__extremely_long_file_name(void) cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); sprintf(path, "testrepo/%s.txt", longname); - cl_assert(git_path_exists(path)); + cl_assert(git_fs_path_exists(path)); git_object_free(g_object); cl_git_pass(git_revparse_single(&g_object, g_repo, "master")); cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); - cl_assert(!git_path_exists(path)); + cl_assert(!git_fs_path_exists(path)); } static void create_conflict(const char *path) @@ -1138,7 +1138,7 @@ void test_checkout_tree__removes_conflicts(void) cl_assert_equal_p(NULL, git_index_get_bypath(index, "other.txt", 2)); cl_assert_equal_p(NULL, git_index_get_bypath(index, "other.txt", 3)); - cl_assert(!git_path_exists("testrepo/other.txt")); + cl_assert(!git_fs_path_exists("testrepo/other.txt")); git_commit_free(commit); git_index_free(index); @@ -1183,7 +1183,7 @@ void test_checkout_tree__removes_conflicts_only_by_pathscope(void) cl_assert(git_index_get_bypath(index, "other.txt", 2) != NULL); cl_assert(git_index_get_bypath(index, "other.txt", 3) != NULL); - cl_assert(git_path_exists("testrepo/other.txt")); + cl_assert(git_fs_path_exists("testrepo/other.txt")); git_commit_free(commit); git_index_free(index); @@ -1214,8 +1214,8 @@ void test_checkout_tree__case_changing_rename(void) cl_git_pass(git_checkout_tree(g_repo, (git_object *)dir_commit, &opts)); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir")); - cl_assert(git_path_isfile("testrepo/README")); - case_sensitive = !git_path_isfile("testrepo/readme"); + cl_assert(git_fs_path_isfile("testrepo/README")); + case_sensitive = !git_fs_path_isfile("testrepo/readme"); cl_assert(index_entry = git_index_get_bypath(index, "README", 0)); cl_assert_equal_s("README", index_entry->path); @@ -1235,9 +1235,9 @@ void test_checkout_tree__case_changing_rename(void) cl_git_pass(git_commit_create(&commit_id, g_repo, "refs/heads/dir", signature, signature, NULL, "case-changing rename", tree, 1, (const git_commit **)&dir_commit)); - cl_assert(git_path_isfile("testrepo/readme")); + cl_assert(git_fs_path_isfile("testrepo/readme")); if (case_sensitive) - cl_assert(!git_path_isfile("testrepo/README")); + cl_assert(!git_fs_path_isfile("testrepo/README")); cl_assert(index_entry = git_index_get_bypath(index, "readme", 0)); cl_assert_equal_s("readme", index_entry->path); @@ -1253,9 +1253,9 @@ void test_checkout_tree__case_changing_rename(void) assert_on_branch(g_repo, "master"); - cl_assert(git_path_isfile("testrepo/README")); + cl_assert(git_fs_path_isfile("testrepo/README")); if (case_sensitive) - cl_assert(!git_path_isfile("testrepo/readme")); + cl_assert(!git_fs_path_isfile("testrepo/readme")); cl_assert(index_entry = git_index_get_bypath(index, "README", 0)); cl_assert_equal_s("README", index_entry->path); @@ -1366,13 +1366,13 @@ void test_checkout_tree__can_not_update_index(void) cl_git_pass(git_reset(g_repo, head, GIT_RESET_HARD, &g_opts)); - cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/")); + cl_assert_equal_i(false, git_fs_path_isdir("./testrepo/ab/")); cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees")); cl_git_pass(git_checkout_tree(g_repo, g_object, &opts)); - cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt")); + cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/ab/de/2.txt")); cl_git_pass(git_status_file(&status, g_repo, "ab/de/2.txt")); cl_assert_equal_i(GIT_STATUS_WT_NEW, status); @@ -1403,13 +1403,13 @@ void test_checkout_tree__can_update_but_not_write_index(void) cl_git_pass(git_reset(g_repo, head, GIT_RESET_HARD, &g_opts)); - cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/")); + cl_assert_equal_i(false, git_fs_path_isdir("./testrepo/ab/")); cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees")); cl_git_pass(git_checkout_tree(g_repo, g_object, &opts)); - cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt")); + cl_assert_equal_i(true, git_fs_path_isfile("./testrepo/ab/de/2.txt")); cl_git_pass(git_status_file(&status, g_repo, "ab/de/2.txt")); cl_assert_equal_i(GIT_STATUS_INDEX_NEW, status); @@ -1450,15 +1450,15 @@ void test_checkout_tree__safe_proceeds_if_no_index(void) cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees")); - cl_assert(git_path_isfile("testrepo/README")); - cl_assert(git_path_isfile("testrepo/branch_file.txt")); - cl_assert(git_path_isfile("testrepo/new.txt")); - cl_assert(git_path_isfile("testrepo/ab/4.txt")); - cl_assert(git_path_isfile("testrepo/ab/c/3.txt")); - cl_assert(git_path_isfile("testrepo/ab/de/2.txt")); - cl_assert(git_path_isfile("testrepo/ab/de/fgh/1.txt")); + cl_assert(git_fs_path_isfile("testrepo/README")); + cl_assert(git_fs_path_isfile("testrepo/branch_file.txt")); + cl_assert(git_fs_path_isfile("testrepo/new.txt")); + cl_assert(git_fs_path_isfile("testrepo/ab/4.txt")); + cl_assert(git_fs_path_isfile("testrepo/ab/c/3.txt")); + cl_assert(git_fs_path_isfile("testrepo/ab/de/2.txt")); + cl_assert(git_fs_path_isfile("testrepo/ab/de/fgh/1.txt")); - cl_assert(!git_path_isdir("testrepo/a")); + cl_assert(!git_fs_path_isdir("testrepo/a")); assert_on_branch(g_repo, "subtrees"); @@ -1650,7 +1650,7 @@ void test_checkout_tree__dry_run(void) opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_git_pass(git_checkout_head(g_repo, &opts)); - cl_assert(!git_path_isdir("testrepo/a")); + cl_assert(!git_fs_path_isdir("testrepo/a")); check_file_contents_nocr("testrepo/branch_file.txt", "hi\nbye!\n"); @@ -1673,7 +1673,7 @@ void test_checkout_tree__dry_run(void) /* these normally would have been created and updated, but with * DRY_RUN they will be unchanged. */ - cl_assert(!git_path_isdir("testrepo/a")); + cl_assert(!git_fs_path_isdir("testrepo/a")); check_file_contents_nocr("testrepo/branch_file.txt", "hi\nbye!\n"); /* check that notify callback was invoked */ diff --git a/tests/checkout/typechange.c b/tests/checkout/typechange.c index 205ce657f..b888843f0 100644 --- a/tests/checkout/typechange.c +++ b/tests/checkout/typechange.c @@ -76,12 +76,12 @@ void test_checkout_typechange__cleanup(void) static void assert_file_exists(const char *path) { - cl_assert_(git_path_isfile(path), path); + cl_assert_(git_fs_path_isfile(path), path); } static void assert_dir_exists(const char *path) { - cl_assert_(git_path_isdir(path), path); + cl_assert_(git_fs_path_isdir(path), path); } static void assert_workdir_matches_tree( @@ -126,7 +126,7 @@ static void assert_workdir_matches_tree( /* because of cross-platform, don't confirm exec bit yet */ break; case GIT_FILEMODE_LINK: - cl_assert_(git_path_exists(path.ptr), path.ptr); + cl_assert_(git_fs_path_exists(path.ptr), path.ptr); /* because of cross-platform, don't confirm link yet */ break; default: @@ -163,19 +163,19 @@ void test_checkout_typechange__checkout_typechanges_safe(void) git_object_free(obj); if (!g_typechange_empty[i]) { - cl_assert(git_path_isdir("typechanges")); - cl_assert(git_path_exists("typechanges/a")); - cl_assert(git_path_exists("typechanges/b")); - cl_assert(git_path_exists("typechanges/c")); - cl_assert(git_path_exists("typechanges/d")); - cl_assert(git_path_exists("typechanges/e")); + cl_assert(git_fs_path_isdir("typechanges")); + cl_assert(git_fs_path_exists("typechanges/a")); + cl_assert(git_fs_path_exists("typechanges/b")); + cl_assert(git_fs_path_exists("typechanges/c")); + cl_assert(git_fs_path_exists("typechanges/d")); + cl_assert(git_fs_path_exists("typechanges/e")); } else { - cl_assert(git_path_isdir("typechanges")); - cl_assert(!git_path_exists("typechanges/a")); - cl_assert(!git_path_exists("typechanges/b")); - cl_assert(!git_path_exists("typechanges/c")); - cl_assert(!git_path_exists("typechanges/d")); - cl_assert(!git_path_exists("typechanges/e")); + cl_assert(git_fs_path_isdir("typechanges")); + cl_assert(!git_fs_path_exists("typechanges/a")); + cl_assert(!git_fs_path_exists("typechanges/b")); + cl_assert(!git_fs_path_exists("typechanges/c")); + cl_assert(!git_fs_path_exists("typechanges/d")); + cl_assert(!git_fs_path_exists("typechanges/e")); } } } @@ -293,12 +293,12 @@ void test_checkout_typechange__checkout_with_conflicts(void) GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED; memset(&cts, 0, sizeof(cts)); - cl_assert(git_path_exists("typechanges/untracked")); + cl_assert(git_fs_path_exists("typechanges/untracked")); cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); cl_assert_equal_i(0, cts.conflicts); - cl_assert(!git_path_exists("typechanges/untracked")); + cl_assert(!git_fs_path_exists("typechanges/untracked")); cl_git_pass( git_repository_set_head_detached(g_repo, git_object_id(obj))); diff --git a/tests/cherrypick/workdir.c b/tests/cherrypick/workdir.c index f7765f2c2..868b9d5ff 100644 --- a/tests/cherrypick/workdir.c +++ b/tests/cherrypick/workdir.c @@ -71,8 +71,8 @@ void test_cherrypick_workdir__automerge(void) cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick(repo, commit, NULL)); - cl_assert(git_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD")); - cl_assert(git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); + cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD")); + cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); cl_git_pass(git_index_write_tree(&cherrypicked_tree_oid, repo_index)); cl_git_pass(git_tree_lookup(&cherrypicked_tree, repo, &cherrypicked_tree_oid)); @@ -114,7 +114,7 @@ void test_cherrypick_workdir__empty_result(void) /* Create an untracked file that should not conflict */ cl_git_mkfile(TEST_REPO_PATH "/file4.txt", ""); - cl_assert(git_path_exists(TEST_REPO_PATH "/file4.txt")); + cl_assert(git_fs_path_exists(TEST_REPO_PATH "/file4.txt")); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); @@ -160,8 +160,8 @@ void test_cherrypick_workdir__conflicts(void) cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick(repo, commit, NULL)); - cl_assert(git_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD")); - cl_assert(git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); + cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD")); + cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); cl_assert(merge_test_index(repo_index, merge_index_entries, 7)); @@ -373,8 +373,8 @@ void test_cherrypick_workdir__nonmerge_fails_mainline_specified(void) opts.mainline = 1; cl_must_fail(git_cherrypick(repo, commit, &opts)); - cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD")); - cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); + cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD")); + cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); git_reference_free(head); git_commit_free(commit); @@ -396,8 +396,8 @@ void test_cherrypick_workdir__merge_fails_without_mainline_specified(void) cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_must_fail(git_cherrypick(repo, commit, NULL)); - cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD")); - cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); + cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD")); + cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); git_commit_free(commit); git_commit_free(head); diff --git a/tests/clar_libgit2.c b/tests/clar_libgit2.c index adea597e3..55a09d111 100644 --- a/tests/clar_libgit2.c +++ b/tests/clar_libgit2.c @@ -1,6 +1,6 @@ #include "clar_libgit2.h" #include "posix.h" -#include "path.h" +#include "fs_path.h" #include "git2/sys/repository.h" void cl_git_report_failure( @@ -281,7 +281,7 @@ const char* cl_git_path_url(const char *path) git_str path_buf = GIT_STR_INIT; git_str url_buf = GIT_STR_INIT; - cl_git_pass(git_path_prettify_dir(&path_buf, path, NULL)); + cl_git_pass(git_fs_path_prettify_dir(&path_buf, path, NULL)); cl_git_pass(git_str_puts(&url_buf, "file://")); #ifdef GIT_WIN32 @@ -336,9 +336,9 @@ const char *cl_git_sandbox_path(int is_dir, ...) } va_end(arg); - cl_git_pass(git_path_prettify(&buf, buf.ptr, NULL)); + cl_git_pass(git_fs_path_prettify(&buf, buf.ptr, NULL)); if (is_dir) - git_path_to_dir(&buf); + git_fs_path_to_dir(&buf); /* make sure we won't truncate */ cl_assert(git_str_len(&buf) < sizeof(_temp)); @@ -359,8 +359,8 @@ static int remove_placeholders_recurs(void *_data, git_str *path) remove_data *data = (remove_data *)_data; size_t pathlen; - if (git_path_isdir(path->ptr) == true) - return git_path_direach(path, 0, remove_placeholders_recurs, data); + if (git_fs_path_isdir(path->ptr) == true) + return git_fs_path_direach(path, 0, remove_placeholders_recurs, data); pathlen = path->size; @@ -382,7 +382,7 @@ int cl_git_remove_placeholders(const char *directory_path, const char *filename) remove_data data; git_str buffer = GIT_STR_INIT; - if (git_path_isdir(directory_path) == false) + if (git_fs_path_isdir(directory_path) == false) return -1; if (git_str_sets(&buffer, directory_path) < 0) @@ -570,9 +570,9 @@ void cl_fake_home(void) cl_set_cleanup(cl_fake_home_cleanup, NULL); - if (!git_path_exists("home")) + if (!git_fs_path_exists("home")) cl_must_pass(p_mkdir("home", 0777)); - cl_git_pass(git_path_prettify(&path, "home", NULL)); + cl_git_pass(git_fs_path_prettify(&path, "home", NULL)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); git_str_dispose(&path); @@ -584,7 +584,7 @@ void cl_sandbox_set_search_path_defaults(void) git_str_joinpath(&path, clar_sandbox_path(), "__config"); - if (!git_path_exists(path.ptr)) + if (!git_fs_path_exists(path.ptr)) cl_must_pass(p_mkdir(path.ptr, 0777)); git_libgit2_opts( diff --git a/tests/clone/nonetwork.c b/tests/clone/nonetwork.c index 7625a2183..c3515b53f 100644 --- a/tests/clone/nonetwork.c +++ b/tests/clone/nonetwork.c @@ -51,10 +51,10 @@ void test_clone_nonetwork__bad_urls(void) { /* Clone should clean up the mess if the URL isn't a git repository */ cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options)); - cl_assert(!git_path_exists("./foo")); + cl_assert(!git_fs_path_exists("./foo")); g_options.bare = true; cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options)); - cl_assert(!git_path_exists("./foo")); + cl_assert(!git_fs_path_exists("./foo")); cl_git_fail(git_clone(&g_repo, "git://example.com:asdf", "./foo", &g_options)); cl_git_fail(git_clone(&g_repo, "https://example.com:asdf/foo", "./foo", &g_options)); @@ -70,12 +70,12 @@ void test_clone_nonetwork__do_not_clean_existing_directory(void) * Should clean up entries it creates. */ p_mkdir("./foo", GIT_DIR_MODE); cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options)); - cl_assert(git_path_is_empty_dir("./foo")); + cl_assert(git_fs_path_is_empty_dir("./foo")); /* Try again with a bare repository. */ g_options.bare = true; cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", &g_options)); - cl_assert(git_path_is_empty_dir("./foo")); + cl_assert(git_fs_path_is_empty_dir("./foo")); } void test_clone_nonetwork__local(void) @@ -151,7 +151,7 @@ void test_clone_nonetwork__can_prevent_the_checkout_of_a_standard_repo(void) cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options)); cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "master.txt")); - cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&path))); + cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&path))); git_str_dispose(&path); } @@ -168,7 +168,7 @@ void test_clone_nonetwork__can_checkout_given_branch(void) cl_git_pass(git_repository_head(&g_ref, g_repo)); cl_assert_equal_s(git_reference_name(g_ref), "refs/heads/test"); - cl_assert(git_path_exists("foo/readme.txt")); + cl_assert(git_fs_path_exists("foo/readme.txt")); cl_git_pass(git_reference_lookup(&remote_head, g_repo, "refs/remotes/origin/HEAD")); cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(remote_head)); @@ -196,7 +196,7 @@ void test_clone_nonetwork__can_cancel_clone_in_fetch(void) -54321); cl_assert(!g_repo); - cl_assert(!git_path_exists("foo/readme.txt")); + cl_assert(!git_fs_path_exists("foo/readme.txt")); } static int clone_cancel_checkout_cb( @@ -227,7 +227,7 @@ void test_clone_nonetwork__can_cancel_clone_in_checkout(void) -12345); cl_assert(!g_repo); - cl_assert(!git_path_exists("foo/readme.txt")); + cl_assert(!git_fs_path_exists("foo/readme.txt")); } void test_clone_nonetwork__can_detached_head(void) diff --git a/tests/config/global.c b/tests/config/global.c index d59c39fa2..5aba4eec6 100644 --- a/tests/config/global.c +++ b/tests/config/global.c @@ -6,17 +6,17 @@ void test_config_global__initialize(void) git_str path = GIT_STR_INIT; cl_git_pass(git_futils_mkdir_r("home", 0777)); - cl_git_pass(git_path_prettify(&path, "home", NULL)); + cl_git_pass(git_fs_path_prettify(&path, "home", NULL)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); cl_git_pass(git_futils_mkdir_r("xdg/git", 0777)); - cl_git_pass(git_path_prettify(&path, "xdg/git", NULL)); + cl_git_pass(git_fs_path_prettify(&path, "xdg/git", NULL)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr)); cl_git_pass(git_futils_mkdir_r("etc", 0777)); - cl_git_pass(git_path_prettify(&path, "etc", NULL)); + cl_git_pass(git_fs_path_prettify(&path, "etc", NULL)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr)); @@ -141,7 +141,7 @@ void test_config_global__open_programdata(void) cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_PROGRAMDATA, &dir_path)); - if (!git_path_isdir(dir_path.ptr)) + if (!git_fs_path_isdir(dir_path.ptr)) cl_git_pass(p_mkdir(dir_path.ptr, 0777)); cl_git_pass(git_str_joinpath(&config_path, dir_path.ptr, "config")); diff --git a/tests/config/read.c b/tests/config/read.c index 77f8a1262..3c96f8519 100644 --- a/tests/config/read.c +++ b/tests/config/read.c @@ -1,5 +1,5 @@ #include "clar_libgit2.h" -#include "path.h" +#include "fs_path.h" static git_buf buf = GIT_BUF_INIT; @@ -705,11 +705,11 @@ void test_config_read__path(void) git_str expected_path = GIT_STR_INIT; cl_git_pass(p_mkdir("fakehome", 0777)); - cl_git_pass(git_path_prettify(&home_path, "fakehome", NULL)); + cl_git_pass(git_fs_path_prettify(&home_path, "fakehome", NULL)); cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &old_path)); cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, home_path.ptr)); cl_git_mkfile("./testconfig", "[some]\n path = ~/somefile"); - cl_git_pass(git_path_join_unrooted(&expected_path, "somefile", home_path.ptr, NULL)); + cl_git_pass(git_fs_path_join_unrooted(&expected_path, "somefile", home_path.ptr, NULL)); cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig")); cl_git_pass(git_config_get_path(&path, cfg, "some.path")); @@ -717,7 +717,7 @@ void test_config_read__path(void) git_buf_dispose(&path); cl_git_mkfile("./testconfig", "[some]\n path = ~/"); - cl_git_pass(git_path_join_unrooted(&expected_path, "", home_path.ptr, NULL)); + cl_git_pass(git_fs_path_join_unrooted(&expected_path, "", home_path.ptr, NULL)); cl_git_pass(git_config_get_path(&path, cfg, "some.path")); cl_assert_equal_s(expected_path.ptr, path.ptr); diff --git a/tests/config/readonly.c b/tests/config/readonly.c index 5d544b8cb..a8901e394 100644 --- a/tests/config/readonly.c +++ b/tests/config/readonly.c @@ -25,7 +25,7 @@ void test_config_readonly__writing_to_readonly_fails(void) cl_git_pass(git_config_add_backend(cfg, backend, GIT_CONFIG_LEVEL_GLOBAL, NULL, 0)); cl_git_fail_with(GIT_ENOTFOUND, git_config_set_string(cfg, "foo.bar", "baz")); - cl_assert(!git_path_exists("global")); + cl_assert(!git_fs_path_exists("global")); } void test_config_readonly__writing_to_cfg_with_rw_precedence_succeeds(void) @@ -41,8 +41,8 @@ void test_config_readonly__writing_to_cfg_with_rw_precedence_succeeds(void) cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz")); - cl_assert(git_path_exists("local")); - cl_assert(!git_path_exists("global")); + cl_assert(git_fs_path_exists("local")); + cl_assert(!git_fs_path_exists("global")); cl_git_pass(p_unlink("local")); } @@ -59,7 +59,7 @@ void test_config_readonly__writing_to_cfg_with_ro_precedence_succeeds(void) cl_git_pass(git_config_set_string(cfg, "foo.bar", "baz")); - cl_assert(!git_path_exists("local")); - cl_assert(git_path_exists("global")); + cl_assert(!git_fs_path_exists("local")); + cl_assert(git_fs_path_exists("global")); cl_git_pass(p_unlink("global")); } diff --git a/tests/config/stress.c b/tests/config/stress.c index 7ec274b18..c823284ff 100644 --- a/tests/config/stress.c +++ b/tests/config/stress.c @@ -30,7 +30,7 @@ void test_config_stress__dont_break_on_invalid_input(void) { git_config *config; - cl_assert(git_path_exists(TEST_CONFIG)); + cl_assert(git_fs_path_exists(TEST_CONFIG)); cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); cl_git_pass(git_config_get_string_buf(&buf, config, "color.ui")); @@ -72,7 +72,7 @@ void test_config_stress__escape_subsection_names(void) { git_config *config; - cl_assert(git_path_exists("git-test-config")); + cl_assert(git_fs_path_exists("git-test-config")); cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); cl_git_pass(git_config_set_string(config, "some.sec\\tion.other", "foo")); @@ -90,7 +90,7 @@ void test_config_stress__trailing_backslash(void) git_config *config; const char *path = "C:\\iam\\some\\windows\\path\\"; - cl_assert(git_path_exists("git-test-config")); + cl_assert(git_fs_path_exists("git-test-config")); cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); cl_git_pass(git_config_set_string(config, "windows.path", path)); git_config_free(config); diff --git a/tests/core/copy.c b/tests/core/copy.c index d31274808..2b90fb6bf 100644 --- a/tests/core/copy.c +++ b/tests/core/copy.c @@ -12,7 +12,7 @@ void test_core_copy__file(void) cl_git_pass(git_futils_cp("copy_me", "copy_me_two", 0664)); - cl_git_pass(git_path_lstat("copy_me_two", &st)); + cl_git_pass(git_fs_path_lstat("copy_me_two", &st)); cl_assert(S_ISREG(st.st_mode)); cl_assert(strlen(content) == (size_t)st.st_size); @@ -27,7 +27,7 @@ void test_core_copy__file_in_dir(void) cl_git_pass(git_futils_mkdir("an_dir/in_a_dir", 0775, GIT_MKDIR_PATH)); cl_git_mkfile("an_dir/in_a_dir/copy_me", content); - cl_assert(git_path_isdir("an_dir")); + cl_assert(git_fs_path_isdir("an_dir")); cl_git_pass(git_futils_mkpath2file ("an_dir/second_dir/and_more/copy_me_two", 0775)); @@ -37,12 +37,12 @@ void test_core_copy__file_in_dir(void) "an_dir/second_dir/and_more/copy_me_two", 0664)); - cl_git_pass(git_path_lstat("an_dir/second_dir/and_more/copy_me_two", &st)); + cl_git_pass(git_fs_path_lstat("an_dir/second_dir/and_more/copy_me_two", &st)); cl_assert(S_ISREG(st.st_mode)); cl_assert(strlen(content) == (size_t)st.st_size); cl_git_pass(git_futils_rmdir_r("an_dir", NULL, GIT_RMDIR_REMOVE_FILES)); - cl_assert(!git_path_isdir("an_dir")); + cl_assert(!git_fs_path_isdir("an_dir")); } void assert_hard_link(const char *path) @@ -50,7 +50,7 @@ void assert_hard_link(const char *path) /* we assert this by checking that there's more than one link to the file */ struct stat st; - cl_assert(git_path_isfile(path)); + cl_assert(git_fs_path_isfile(path)); cl_git_pass(p_stat(path, &st)); cl_assert(st.st_nlink > 1); } @@ -74,73 +74,73 @@ void test_core_copy__tree(void) cl_assert(p_symlink("../../b/f2", "src/c/d/l1") == 0); #endif - cl_assert(git_path_isdir("src")); - cl_assert(git_path_isdir("src/b")); - cl_assert(git_path_isdir("src/c/d")); - cl_assert(git_path_isfile("src/c/d/f4")); + cl_assert(git_fs_path_isdir("src")); + cl_assert(git_fs_path_isdir("src/b")); + cl_assert(git_fs_path_isdir("src/c/d")); + cl_assert(git_fs_path_isfile("src/c/d/f4")); /* copy with no empty dirs, yes links, no dotfiles, no overwrite */ cl_git_pass( git_futils_cp_r("src", "t1", GIT_CPDIR_COPY_SYMLINKS, 0) ); - cl_assert(git_path_isdir("t1")); - cl_assert(git_path_isdir("t1/b")); - cl_assert(git_path_isdir("t1/c")); - cl_assert(git_path_isdir("t1/c/d")); - cl_assert(!git_path_isdir("t1/c/e")); + cl_assert(git_fs_path_isdir("t1")); + cl_assert(git_fs_path_isdir("t1/b")); + cl_assert(git_fs_path_isdir("t1/c")); + cl_assert(git_fs_path_isdir("t1/c/d")); + cl_assert(!git_fs_path_isdir("t1/c/e")); - cl_assert(git_path_isfile("t1/f1")); - cl_assert(git_path_isfile("t1/b/f2")); - cl_assert(git_path_isfile("t1/c/f3")); - cl_assert(git_path_isfile("t1/c/d/f4")); - cl_assert(!git_path_isfile("t1/c/d/.f5")); + cl_assert(git_fs_path_isfile("t1/f1")); + cl_assert(git_fs_path_isfile("t1/b/f2")); + cl_assert(git_fs_path_isfile("t1/c/f3")); + cl_assert(git_fs_path_isfile("t1/c/d/f4")); + cl_assert(!git_fs_path_isfile("t1/c/d/.f5")); - cl_git_pass(git_path_lstat("t1/c/f3", &st)); + cl_git_pass(git_fs_path_lstat("t1/c/f3", &st)); cl_assert(S_ISREG(st.st_mode)); cl_assert(strlen(content) == (size_t)st.st_size); #ifndef GIT_WIN32 - cl_git_pass(git_path_lstat("t1/c/d/l1", &st)); + cl_git_pass(git_fs_path_lstat("t1/c/d/l1", &st)); cl_assert(S_ISLNK(st.st_mode)); #endif cl_git_pass(git_futils_rmdir_r("t1", NULL, GIT_RMDIR_REMOVE_FILES)); - cl_assert(!git_path_isdir("t1")); + cl_assert(!git_fs_path_isdir("t1")); /* copy with empty dirs, no links, yes dotfiles, no overwrite */ cl_git_pass( git_futils_cp_r("src", "t2", GIT_CPDIR_CREATE_EMPTY_DIRS | GIT_CPDIR_COPY_DOTFILES, 0) ); - cl_assert(git_path_isdir("t2")); - cl_assert(git_path_isdir("t2/b")); - cl_assert(git_path_isdir("t2/c")); - cl_assert(git_path_isdir("t2/c/d")); - cl_assert(git_path_isdir("t2/c/e")); + cl_assert(git_fs_path_isdir("t2")); + cl_assert(git_fs_path_isdir("t2/b")); + cl_assert(git_fs_path_isdir("t2/c")); + cl_assert(git_fs_path_isdir("t2/c/d")); + cl_assert(git_fs_path_isdir("t2/c/e")); - cl_assert(git_path_isfile("t2/f1")); - cl_assert(git_path_isfile("t2/b/f2")); - cl_assert(git_path_isfile("t2/c/f3")); - cl_assert(git_path_isfile("t2/c/d/f4")); - cl_assert(git_path_isfile("t2/c/d/.f5")); + cl_assert(git_fs_path_isfile("t2/f1")); + cl_assert(git_fs_path_isfile("t2/b/f2")); + cl_assert(git_fs_path_isfile("t2/c/f3")); + cl_assert(git_fs_path_isfile("t2/c/d/f4")); + cl_assert(git_fs_path_isfile("t2/c/d/.f5")); #ifndef GIT_WIN32 - cl_git_fail(git_path_lstat("t2/c/d/l1", &st)); + cl_git_fail(git_fs_path_lstat("t2/c/d/l1", &st)); #endif cl_git_pass(git_futils_rmdir_r("t2", NULL, GIT_RMDIR_REMOVE_FILES)); - cl_assert(!git_path_isdir("t2")); + cl_assert(!git_fs_path_isdir("t2")); #ifndef GIT_WIN32 cl_git_pass(git_futils_cp_r("src", "t3", GIT_CPDIR_CREATE_EMPTY_DIRS | GIT_CPDIR_LINK_FILES, 0)); - cl_assert(git_path_isdir("t3")); + cl_assert(git_fs_path_isdir("t3")); - cl_assert(git_path_isdir("t3")); - cl_assert(git_path_isdir("t3/b")); - cl_assert(git_path_isdir("t3/c")); - cl_assert(git_path_isdir("t3/c/d")); - cl_assert(git_path_isdir("t3/c/e")); + cl_assert(git_fs_path_isdir("t3")); + cl_assert(git_fs_path_isdir("t3/b")); + cl_assert(git_fs_path_isdir("t3/c")); + cl_assert(git_fs_path_isdir("t3/c/d")); + cl_assert(git_fs_path_isdir("t3/c/e")); assert_hard_link("t3/f1"); assert_hard_link("t3/b/f2"); diff --git a/tests/core/dirent.c b/tests/core/dirent.c index ce93e0358..2419ec7ab 100644 --- a/tests/core/dirent.c +++ b/tests/core/dirent.c @@ -113,7 +113,7 @@ void test_core_dirent__dont_traverse_dot(void) cl_set_cleanup(&dirent_cleanup__cb, &dot); setup(&dot); - cl_git_pass(git_path_direach(&dot.path, 0, one_entry, &dot)); + cl_git_pass(git_fs_path_direach(&dot.path, 0, one_entry, &dot)); check_counts(&dot); } @@ -137,7 +137,7 @@ void test_core_dirent__traverse_subfolder(void) cl_set_cleanup(&dirent_cleanup__cb, &sub); setup(&sub); - cl_git_pass(git_path_direach(&sub.path, 0, one_entry, &sub)); + cl_git_pass(git_fs_path_direach(&sub.path, 0, one_entry, &sub)); check_counts(&sub); } @@ -155,7 +155,7 @@ void test_core_dirent__traverse_slash_terminated_folder(void) cl_set_cleanup(&dirent_cleanup__cb, &sub_slash); setup(&sub_slash); - cl_git_pass(git_path_direach(&sub_slash.path, 0, one_entry, &sub_slash)); + cl_git_pass(git_fs_path_direach(&sub_slash.path, 0, one_entry, &sub_slash)); check_counts(&sub_slash); } @@ -176,12 +176,12 @@ void test_core_dirent__dont_traverse_empty_folders(void) cl_set_cleanup(&dirent_cleanup__cb, &empty); setup(&empty); - cl_git_pass(git_path_direach(&empty.path, 0, one_entry, &empty)); + cl_git_pass(git_fs_path_direach(&empty.path, 0, one_entry, &empty)); check_counts(&empty); /* make sure callback not called */ - cl_assert(git_path_is_empty_dir(empty.path.ptr)); + cl_assert(git_fs_path_is_empty_dir(empty.path.ptr)); } static name_data odd_names[] = { @@ -204,7 +204,7 @@ void test_core_dirent__traverse_weird_filenames(void) cl_set_cleanup(&dirent_cleanup__cb, &odd); setup(&odd); - cl_git_pass(git_path_direach(&odd.path, 0, one_entry, &odd)); + cl_git_pass(git_fs_path_direach(&odd.path, 0, one_entry, &odd)); check_counts(&odd); } @@ -224,30 +224,30 @@ void test_core_dirent__length_limits(void) void test_core_dirent__empty_dir(void) { cl_must_pass(p_mkdir("empty_dir", 0777)); - cl_assert(git_path_is_empty_dir("empty_dir")); + cl_assert(git_fs_path_is_empty_dir("empty_dir")); cl_git_mkfile("empty_dir/content", "whatever\n"); - cl_assert(!git_path_is_empty_dir("empty_dir")); - cl_assert(!git_path_is_empty_dir("empty_dir/content")); + cl_assert(!git_fs_path_is_empty_dir("empty_dir")); + cl_assert(!git_fs_path_is_empty_dir("empty_dir/content")); cl_must_pass(p_unlink("empty_dir/content")); cl_must_pass(p_mkdir("empty_dir/content", 0777)); - cl_assert(!git_path_is_empty_dir("empty_dir")); - cl_assert(git_path_is_empty_dir("empty_dir/content")); + cl_assert(!git_fs_path_is_empty_dir("empty_dir")); + cl_assert(git_fs_path_is_empty_dir("empty_dir/content")); cl_must_pass(p_rmdir("empty_dir/content")); cl_must_pass(p_rmdir("empty_dir")); } -static void handle_next(git_path_diriter *diriter, walk_data *walk) +static void handle_next(git_fs_path_diriter *diriter, walk_data *walk) { const char *fullpath, *filename; size_t fullpath_len, filename_len; - cl_git_pass(git_path_diriter_fullpath(&fullpath, &fullpath_len, diriter)); - cl_git_pass(git_path_diriter_filename(&filename, &filename_len, diriter)); + cl_git_pass(git_fs_path_diriter_fullpath(&fullpath, &fullpath_len, diriter)); + cl_git_pass(git_fs_path_diriter_filename(&filename, &filename_len, diriter)); cl_assert_equal_strn(fullpath, "sub/", 4); cl_assert_equal_s(fullpath+4, filename); @@ -258,42 +258,42 @@ static void handle_next(git_path_diriter *diriter, walk_data *walk) /* test directory iterator */ void test_core_dirent__diriter_with_fullname(void) { - git_path_diriter diriter = GIT_PATH_DIRITER_INIT; + git_fs_path_diriter diriter = GIT_FS_PATH_DIRITER_INIT; int error; cl_set_cleanup(&dirent_cleanup__cb, &sub); setup(&sub); - cl_git_pass(git_path_diriter_init(&diriter, sub.path.ptr, 0)); + cl_git_pass(git_fs_path_diriter_init(&diriter, sub.path.ptr, 0)); - while ((error = git_path_diriter_next(&diriter)) == 0) + while ((error = git_fs_path_diriter_next(&diriter)) == 0) handle_next(&diriter, &sub); cl_assert_equal_i(error, GIT_ITEROVER); - git_path_diriter_free(&diriter); + git_fs_path_diriter_free(&diriter); check_counts(&sub); } void test_core_dirent__diriter_at_directory_root(void) { - git_path_diriter diriter = GIT_PATH_DIRITER_INIT; + git_fs_path_diriter diriter = GIT_FS_PATH_DIRITER_INIT; const char *sandbox_path, *path; char *root_path; size_t path_len; int root_offset, error; sandbox_path = clar_sandbox_path(); - cl_assert((root_offset = git_path_root(sandbox_path)) >= 0); + cl_assert((root_offset = git_fs_path_root(sandbox_path)) >= 0); cl_assert(root_path = git__calloc(1, root_offset + 2)); strncpy(root_path, sandbox_path, root_offset + 1); - cl_git_pass(git_path_diriter_init(&diriter, root_path, 0)); + cl_git_pass(git_fs_path_diriter_init(&diriter, root_path, 0)); - while ((error = git_path_diriter_next(&diriter)) == 0) { - cl_git_pass(git_path_diriter_fullpath(&path, &path_len, &diriter)); + while ((error = git_fs_path_diriter_next(&diriter)) == 0) { + cl_git_pass(git_fs_path_diriter_fullpath(&path, &path_len, &diriter)); cl_assert(path_len > (size_t)(root_offset + 1)); cl_assert(path[root_offset+1] != '/'); @@ -301,6 +301,6 @@ void test_core_dirent__diriter_at_directory_root(void) cl_assert_equal_i(error, GIT_ITEROVER); - git_path_diriter_free(&diriter); + git_fs_path_diriter_free(&diriter); git__free(root_path); } diff --git a/tests/core/env.c b/tests/core/env.c index 9a3f0ae76..88c5c6aa3 100644 --- a/tests/core/env.c +++ b/tests/core/env.c @@ -103,7 +103,7 @@ void test_core_env__0(void) continue; } - cl_git_pass(git_path_prettify(&path, *val, NULL)); + cl_git_pass(git_fs_path_prettify(&path, *val, NULL)); /* vary testfile name in each directory so accidentally leaving * an environment variable set from a previous iteration won't @@ -137,7 +137,7 @@ void test_core_env__0(void) cl_git_pass(git_sysdir_find_global_file(&found, testfile)); { - int root = git_path_root(path.ptr); + int root = git_fs_path_root(path.ptr); char old; if (root >= 0) { @@ -270,7 +270,7 @@ void test_core_env__2(void) continue; } - cl_git_pass(git_path_prettify(&path, *val, NULL)); + cl_git_pass(git_fs_path_prettify(&path, *val, NULL)); /* vary testfile name so any sloppiness is resetting variables or * deleting files won't accidentally make a test pass. diff --git a/tests/core/filebuf.c b/tests/core/filebuf.c index 6f654f523..6f40c2456 100644 --- a/tests/core/filebuf.c +++ b/tests/core/filebuf.c @@ -14,7 +14,7 @@ void test_core_filebuf__0(void) cl_must_pass(p_close(fd)); cl_git_fail(git_filebuf_open(&file, test, 0, 0666)); - cl_assert(git_path_exists(testlock)); + cl_assert(git_fs_path_exists(testlock)); cl_must_pass(p_unlink(testlock)); } @@ -142,14 +142,14 @@ void test_core_filebuf__rename_error(void) cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); - cl_assert_equal_i(true, git_path_exists(test_lock)); + cl_assert_equal_i(true, git_fs_path_exists(test_lock)); cl_git_fail(git_filebuf_commit(&file)); p_close(fd); git_filebuf_cleanup(&file); - cl_assert_equal_i(false, git_path_exists(test_lock)); + cl_assert_equal_i(false, git_fs_path_exists(test_lock)); } void test_core_filebuf__symlink_follow(void) @@ -157,7 +157,7 @@ void test_core_filebuf__symlink_follow(void) git_filebuf file = GIT_FILEBUF_INIT; const char *dir = "linkdir", *source = "linkdir/link"; - if (!git_path_supports_symlinks(clar_sandbox_path())) + if (!git_fs_path_supports_symlinks(clar_sandbox_path())) cl_skip(); cl_git_pass(p_mkdir(dir, 0777)); @@ -166,10 +166,10 @@ void test_core_filebuf__symlink_follow(void) cl_git_pass(git_filebuf_open(&file, source, 0, 0666)); cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); - cl_assert_equal_i(true, git_path_exists("linkdir/target.lock")); + cl_assert_equal_i(true, git_fs_path_exists("linkdir/target.lock")); cl_git_pass(git_filebuf_commit(&file)); - cl_assert_equal_i(true, git_path_exists("linkdir/target")); + cl_assert_equal_i(true, git_fs_path_exists("linkdir/target")); git_filebuf_cleanup(&file); @@ -177,10 +177,10 @@ void test_core_filebuf__symlink_follow(void) cl_git_pass(git_filebuf_open(&file, source, 0, 0666)); cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); - cl_assert_equal_i(true, git_path_exists("linkdir/target.lock")); + cl_assert_equal_i(true, git_fs_path_exists("linkdir/target.lock")); cl_git_pass(git_filebuf_commit(&file)); - cl_assert_equal_i(true, git_path_exists("linkdir/target")); + cl_assert_equal_i(true, git_fs_path_exists("linkdir/target")); git_filebuf_cleanup(&file); cl_git_pass(git_futils_rmdir_r(dir, NULL, GIT_RMDIR_REMOVE_FILES)); @@ -191,7 +191,7 @@ void test_core_filebuf__symlink_follow_absolute_paths(void) git_filebuf file = GIT_FILEBUF_INIT; git_str source = GIT_STR_INIT, target = GIT_STR_INIT; - if (!git_path_supports_symlinks(clar_sandbox_path())) + if (!git_fs_path_supports_symlinks(clar_sandbox_path())) cl_skip(); cl_git_pass(git_str_joinpath(&source, clar_sandbox_path(), "linkdir/link")); @@ -202,10 +202,10 @@ void test_core_filebuf__symlink_follow_absolute_paths(void) cl_git_pass(git_filebuf_open(&file, source.ptr, 0, 0666)); cl_git_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); - cl_assert_equal_i(true, git_path_exists("linkdir/target.lock")); + cl_assert_equal_i(true, git_fs_path_exists("linkdir/target.lock")); cl_git_pass(git_filebuf_commit(&file)); - cl_assert_equal_i(true, git_path_exists("linkdir/target")); + cl_assert_equal_i(true, git_fs_path_exists("linkdir/target")); git_filebuf_cleanup(&file); git_str_dispose(&source); @@ -219,7 +219,7 @@ void test_core_filebuf__symlink_depth(void) git_filebuf file = GIT_FILEBUF_INIT; const char *dir = "linkdir", *source = "linkdir/link"; - if (!git_path_supports_symlinks(clar_sandbox_path())) + if (!git_fs_path_supports_symlinks(clar_sandbox_path())) cl_skip(); cl_git_pass(p_mkdir(dir, 0777)); diff --git a/tests/core/futils.c b/tests/core/futils.c index d08043b6e..b87ea183b 100644 --- a/tests/core/futils.c +++ b/tests/core/futils.c @@ -68,7 +68,7 @@ void test_core_futils__write_hidden_file(void) void test_core_futils__recursive_rmdir_keeps_symlink_targets(void) { - if (!git_path_supports_symlinks(clar_sandbox_path())) + if (!git_fs_path_supports_symlinks(clar_sandbox_path())) cl_skip(); cl_git_pass(git_futils_mkdir_r("a/b", 0777)); @@ -80,8 +80,8 @@ void test_core_futils__recursive_rmdir_keeps_symlink_targets(void) cl_git_pass(git_futils_rmdir_r("a", NULL, GIT_RMDIR_REMOVE_FILES)); - cl_assert(git_path_exists("dir-target")); - cl_assert(git_path_exists("file-target")); + cl_assert(git_fs_path_exists("dir-target")); + cl_assert(git_fs_path_exists("file-target")); cl_must_pass(p_unlink("dir-target/file")); cl_must_pass(p_rmdir("dir-target")); diff --git a/tests/core/iconv.c b/tests/core/iconv.c index 498094bdb..af1b4eabf 100644 --- a/tests/core/iconv.c +++ b/tests/core/iconv.c @@ -1,8 +1,8 @@ #include "clar_libgit2.h" -#include "path.h" +#include "fs_path.h" #ifdef GIT_USE_ICONV -static git_path_iconv_t ic; +static git_fs_path_iconv_t ic; static char *nfc = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D"; static char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D"; #endif @@ -10,14 +10,14 @@ static char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D"; void test_core_iconv__initialize(void) { #ifdef GIT_USE_ICONV - cl_git_pass(git_path_iconv_init_precompose(&ic)); + cl_git_pass(git_fs_path_iconv_init_precompose(&ic)); #endif } void test_core_iconv__cleanup(void) { #ifdef GIT_USE_ICONV - git_path_iconv_clear(&ic); + git_fs_path_iconv_clear(&ic); #endif } @@ -27,7 +27,7 @@ void test_core_iconv__unchanged(void) const char *data = "Ascii data", *original = data; size_t datalen = strlen(data); - cl_git_pass(git_path_iconv(&ic, &data, &datalen)); + cl_git_pass(git_fs_path_iconv(&ic, &data, &datalen)); GIT_UNUSED(datalen); /* There are no high bits set, so this should leave data untouched */ @@ -42,7 +42,7 @@ void test_core_iconv__decomposed_to_precomposed(void) size_t datalen, nfdlen = strlen(nfd); datalen = nfdlen; - cl_git_pass(git_path_iconv(&ic, &data, &datalen)); + cl_git_pass(git_fs_path_iconv(&ic, &data, &datalen)); GIT_UNUSED(datalen); /* The decomposed nfd string should be transformed to the nfc form @@ -50,13 +50,13 @@ void test_core_iconv__decomposed_to_precomposed(void) */ cl_assert_equal_s(nfc, data); - /* should be able to do it multiple times with the same git_path_iconv_t */ + /* should be able to do it multiple times with the same git_fs_path_iconv_t */ data = nfd; datalen = nfdlen; - cl_git_pass(git_path_iconv(&ic, &data, &datalen)); + cl_git_pass(git_fs_path_iconv(&ic, &data, &datalen)); cl_assert_equal_s(nfc, data); data = nfd; datalen = nfdlen; - cl_git_pass(git_path_iconv(&ic, &data, &datalen)); + cl_git_pass(git_fs_path_iconv(&ic, &data, &datalen)); cl_assert_equal_s(nfc, data); #endif } @@ -67,7 +67,7 @@ void test_core_iconv__precomposed_is_unmodified(void) const char *data = nfc; size_t datalen = strlen(nfc); - cl_git_pass(git_path_iconv(&ic, &data, &datalen)); + cl_git_pass(git_fs_path_iconv(&ic, &data, &datalen)); GIT_UNUSED(datalen); /* data is already in precomposed form, so even though some bytes have diff --git a/tests/core/mkdir.c b/tests/core/mkdir.c index f0461ac1f..8d4b9afd6 100644 --- a/tests/core/mkdir.c +++ b/tests/core/mkdir.c @@ -22,32 +22,32 @@ void test_core_mkdir__absolute(void) git_str_joinpath(&path, clar_sandbox_path(), "d0"); /* make a directory */ - cl_assert(!git_path_isdir(path.ptr)); + cl_assert(!git_fs_path_isdir(path.ptr)); cl_git_pass(git_futils_mkdir(path.ptr, 0755, 0)); - cl_assert(git_path_isdir(path.ptr)); + cl_assert(git_fs_path_isdir(path.ptr)); git_str_joinpath(&path, path.ptr, "subdir"); - cl_assert(!git_path_isdir(path.ptr)); + cl_assert(!git_fs_path_isdir(path.ptr)); cl_git_pass(git_futils_mkdir(path.ptr, 0755, 0)); - cl_assert(git_path_isdir(path.ptr)); + cl_assert(git_fs_path_isdir(path.ptr)); /* ensure mkdir_r works for a single subdir */ git_str_joinpath(&path, path.ptr, "another"); - cl_assert(!git_path_isdir(path.ptr)); + cl_assert(!git_fs_path_isdir(path.ptr)); cl_git_pass(git_futils_mkdir_r(path.ptr, 0755)); - cl_assert(git_path_isdir(path.ptr)); + cl_assert(git_fs_path_isdir(path.ptr)); /* ensure mkdir_r works */ git_str_joinpath(&path, clar_sandbox_path(), "d1/foo/bar/asdf"); - cl_assert(!git_path_isdir(path.ptr)); + cl_assert(!git_fs_path_isdir(path.ptr)); cl_git_pass(git_futils_mkdir_r(path.ptr, 0755)); - cl_assert(git_path_isdir(path.ptr)); + cl_assert(git_fs_path_isdir(path.ptr)); /* ensure we don't imply recursive */ git_str_joinpath(&path, clar_sandbox_path(), "d2/foo/bar/asdf"); - cl_assert(!git_path_isdir(path.ptr)); + cl_assert(!git_fs_path_isdir(path.ptr)); cl_git_fail(git_futils_mkdir(path.ptr, 0755, 0)); - cl_assert(!git_path_isdir(path.ptr)); + cl_assert(!git_fs_path_isdir(path.ptr)); git_str_dispose(&path); } @@ -57,39 +57,39 @@ void test_core_mkdir__basic(void) cl_set_cleanup(cleanup_basic_dirs, NULL); /* make a directory */ - cl_assert(!git_path_isdir("d0")); + cl_assert(!git_fs_path_isdir("d0")); cl_git_pass(git_futils_mkdir("d0", 0755, 0)); - cl_assert(git_path_isdir("d0")); + cl_assert(git_fs_path_isdir("d0")); /* make a path */ - cl_assert(!git_path_isdir("d1")); + cl_assert(!git_fs_path_isdir("d1")); cl_git_pass(git_futils_mkdir("d1/d1.1/d1.2", 0755, GIT_MKDIR_PATH)); - cl_assert(git_path_isdir("d1")); - cl_assert(git_path_isdir("d1/d1.1")); - cl_assert(git_path_isdir("d1/d1.1/d1.2")); + cl_assert(git_fs_path_isdir("d1")); + cl_assert(git_fs_path_isdir("d1/d1.1")); + cl_assert(git_fs_path_isdir("d1/d1.1/d1.2")); /* make a dir exclusively */ - cl_assert(!git_path_isdir("d2")); + cl_assert(!git_fs_path_isdir("d2")); cl_git_pass(git_futils_mkdir("d2", 0755, GIT_MKDIR_EXCL)); - cl_assert(git_path_isdir("d2")); + cl_assert(git_fs_path_isdir("d2")); /* make exclusive failure */ cl_git_fail(git_futils_mkdir("d2", 0755, GIT_MKDIR_EXCL)); /* make a path exclusively */ - cl_assert(!git_path_isdir("d3")); + cl_assert(!git_fs_path_isdir("d3")); cl_git_pass(git_futils_mkdir("d3/d3.1/d3.2", 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL)); - cl_assert(git_path_isdir("d3")); - cl_assert(git_path_isdir("d3/d3.1/d3.2")); + cl_assert(git_fs_path_isdir("d3")); + cl_assert(git_fs_path_isdir("d3/d3.1/d3.2")); /* make exclusive path failure */ cl_git_fail(git_futils_mkdir("d3/d3.1/d3.2", 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL)); /* ??? Should EXCL only apply to the last item in the path? */ /* path with trailing slash? */ - cl_assert(!git_path_isdir("d4")); + cl_assert(!git_fs_path_isdir("d4")); cl_git_pass(git_futils_mkdir("d4/d4.1/", 0755, GIT_MKDIR_PATH)); - cl_assert(git_path_isdir("d4/d4.1")); + cl_assert(git_fs_path_isdir("d4/d4.1")); } static void cleanup_basedir(void *ref) @@ -107,10 +107,10 @@ void test_core_mkdir__with_base(void) cl_git_pass(git_futils_mkdir(BASEDIR, 0755, GIT_MKDIR_PATH)); cl_git_pass(git_futils_mkdir_relative("a", BASEDIR, 0755, 0, NULL)); - cl_assert(git_path_isdir(BASEDIR "/a")); + cl_assert(git_fs_path_isdir(BASEDIR "/a")); cl_git_pass(git_futils_mkdir_relative("b/b1/b2", BASEDIR, 0755, GIT_MKDIR_PATH, NULL)); - cl_assert(git_path_isdir(BASEDIR "/b/b1/b2")); + cl_assert(git_fs_path_isdir(BASEDIR "/b/b1/b2")); /* exclusive with existing base */ cl_git_pass(git_futils_mkdir_relative("c/c1/c2", BASEDIR, 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL, NULL)); @@ -126,7 +126,7 @@ void test_core_mkdir__with_base(void) /* path with shorter base and existing dirs */ cl_git_pass(git_futils_mkdir_relative("dir/here/d/", "base", 0755, GIT_MKDIR_PATH, NULL)); - cl_assert(git_path_isdir("base/dir/here/d")); + cl_assert(git_fs_path_isdir("base/dir/here/d")); /* fail: path with shorter base and existing dirs */ cl_git_fail(git_futils_mkdir_relative("dir/here/e/", "base", 0755, GIT_MKDIR_PATH | GIT_MKDIR_EXCL, NULL)); @@ -179,51 +179,51 @@ void test_core_mkdir__chmods(void) cl_git_pass(git_futils_mkdir_relative("mode/is/important", "r", 0777, GIT_MKDIR_PATH, NULL)); - cl_git_pass(git_path_lstat("r/mode", &st)); + cl_git_pass(git_fs_path_lstat("r/mode", &st)); check_mode(0755, st.st_mode); - cl_git_pass(git_path_lstat("r/mode/is", &st)); + cl_git_pass(git_fs_path_lstat("r/mode/is", &st)); check_mode(0755, st.st_mode); - cl_git_pass(git_path_lstat("r/mode/is/important", &st)); + cl_git_pass(git_fs_path_lstat("r/mode/is/important", &st)); check_mode(0755, st.st_mode); cl_git_pass(git_futils_mkdir_relative("mode2/is2/important2", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD, NULL)); - cl_git_pass(git_path_lstat("r/mode2", &st)); + cl_git_pass(git_fs_path_lstat("r/mode2", &st)); check_mode(0755, st.st_mode); - cl_git_pass(git_path_lstat("r/mode2/is2", &st)); + cl_git_pass(git_fs_path_lstat("r/mode2/is2", &st)); check_mode(0755, st.st_mode); - cl_git_pass(git_path_lstat("r/mode2/is2/important2", &st)); + cl_git_pass(git_fs_path_lstat("r/mode2/is2/important2", &st)); check_mode(0777, st.st_mode); cl_git_pass(git_futils_mkdir_relative("mode3/is3/important3", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD_PATH, NULL)); - cl_git_pass(git_path_lstat("r/mode3", &st)); + cl_git_pass(git_fs_path_lstat("r/mode3", &st)); check_mode(0777, st.st_mode); - cl_git_pass(git_path_lstat("r/mode3/is3", &st)); + cl_git_pass(git_fs_path_lstat("r/mode3/is3", &st)); check_mode(0777, st.st_mode); - cl_git_pass(git_path_lstat("r/mode3/is3/important3", &st)); + cl_git_pass(git_fs_path_lstat("r/mode3/is3/important3", &st)); check_mode(0777, st.st_mode); /* test that we chmod existing dir */ cl_git_pass(git_futils_mkdir_relative("mode/is/important", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD, NULL)); - cl_git_pass(git_path_lstat("r/mode", &st)); + cl_git_pass(git_fs_path_lstat("r/mode", &st)); check_mode(0755, st.st_mode); - cl_git_pass(git_path_lstat("r/mode/is", &st)); + cl_git_pass(git_fs_path_lstat("r/mode/is", &st)); check_mode(0755, st.st_mode); - cl_git_pass(git_path_lstat("r/mode/is/important", &st)); + cl_git_pass(git_fs_path_lstat("r/mode/is/important", &st)); check_mode(0777, st.st_mode); /* test that we chmod even existing dirs if CHMOD_PATH is set */ cl_git_pass(git_futils_mkdir_relative("mode2/is2/important2.1", "r", 0777, GIT_MKDIR_PATH | GIT_MKDIR_CHMOD_PATH, NULL)); - cl_git_pass(git_path_lstat("r/mode2", &st)); + cl_git_pass(git_fs_path_lstat("r/mode2", &st)); check_mode(0777, st.st_mode); - cl_git_pass(git_path_lstat("r/mode2/is2", &st)); + cl_git_pass(git_fs_path_lstat("r/mode2/is2", &st)); check_mode(0777, st.st_mode); - cl_git_pass(git_path_lstat("r/mode2/is2/important2.1", &st)); + cl_git_pass(git_fs_path_lstat("r/mode2/is2/important2.1", &st)); check_mode(0777, st.st_mode); } @@ -235,27 +235,27 @@ void test_core_mkdir__keeps_parent_symlinks(void) cl_set_cleanup(cleanup_basic_dirs, NULL); /* make a directory */ - cl_assert(!git_path_isdir("d0")); + cl_assert(!git_fs_path_isdir("d0")); cl_git_pass(git_futils_mkdir("d0", 0755, 0)); - cl_assert(git_path_isdir("d0")); + cl_assert(git_fs_path_isdir("d0")); cl_must_pass(symlink("d0", "d1")); - cl_assert(git_path_islink("d1")); + cl_assert(git_fs_path_islink("d1")); cl_git_pass(git_futils_mkdir("d1/foo/bar", 0755, GIT_MKDIR_PATH|GIT_MKDIR_REMOVE_SYMLINKS)); - cl_assert(git_path_islink("d1")); - cl_assert(git_path_isdir("d1/foo/bar")); - cl_assert(git_path_isdir("d0/foo/bar")); + cl_assert(git_fs_path_islink("d1")); + cl_assert(git_fs_path_isdir("d1/foo/bar")); + cl_assert(git_fs_path_isdir("d0/foo/bar")); cl_must_pass(symlink("d0", "d2")); - cl_assert(git_path_islink("d2")); + cl_assert(git_fs_path_islink("d2")); git_str_joinpath(&path, clar_sandbox_path(), "d2/other/dir"); cl_git_pass(git_futils_mkdir(path.ptr, 0755, GIT_MKDIR_PATH|GIT_MKDIR_REMOVE_SYMLINKS)); - cl_assert(git_path_islink("d2")); - cl_assert(git_path_isdir("d2/other/dir")); - cl_assert(git_path_isdir("d0/other/dir")); + cl_assert(git_fs_path_islink("d2")); + cl_assert(git_fs_path_isdir("d2/other/dir")); + cl_assert(git_fs_path_isdir("d0/other/dir")); git_str_dispose(&path); #endif @@ -276,16 +276,16 @@ void test_core_mkdir__mkdir_path_inside_unwriteable_parent(void) cl_git_pass(git_futils_mkdir("r", 0777, 0)); cl_git_pass(git_futils_mkdir_relative("mode/is/important", "r", 0777, GIT_MKDIR_PATH, NULL)); - cl_git_pass(git_path_lstat("r/mode", &st)); + cl_git_pass(git_fs_path_lstat("r/mode", &st)); check_mode(0755, st.st_mode); cl_must_pass(p_chmod("r/mode", 0111)); - cl_git_pass(git_path_lstat("r/mode", &st)); + cl_git_pass(git_fs_path_lstat("r/mode", &st)); check_mode(0111, st.st_mode); cl_git_pass( git_futils_mkdir_relative("mode/is/okay/inside", "r", 0777, GIT_MKDIR_PATH, NULL)); - cl_git_pass(git_path_lstat("r/mode/is/okay/inside", &st)); + cl_git_pass(git_fs_path_lstat("r/mode/is/okay/inside", &st)); check_mode(0755, st.st_mode); cl_must_pass(p_chmod("r/mode", 0777)); diff --git a/tests/core/path.c b/tests/core/path.c index 6decf23ea..563dcd2a3 100644 --- a/tests/core/path.c +++ b/tests/core/path.c @@ -1,5 +1,6 @@ #include "clar_libgit2.h" #include "futils.h" +#include "fs_path.h" static void check_dirname(const char *A, const char *B) @@ -7,11 +8,11 @@ check_dirname(const char *A, const char *B) git_str dir = GIT_STR_INIT; char *dir2; - cl_assert(git_path_dirname_r(&dir, A) >= 0); + cl_assert(git_fs_path_dirname_r(&dir, A) >= 0); cl_assert_equal_s(B, dir.ptr); git_str_dispose(&dir); - cl_assert((dir2 = git_path_dirname(A)) != NULL); + cl_assert((dir2 = git_fs_path_dirname(A)) != NULL); cl_assert_equal_s(B, dir2); git__free(dir2); } @@ -22,11 +23,11 @@ check_basename(const char *A, const char *B) git_str base = GIT_STR_INIT; char *base2; - cl_assert(git_path_basename_r(&base, A) >= 0); + cl_assert(git_fs_path_basename_r(&base, A) >= 0); cl_assert_equal_s(B, base.ptr); git_str_dispose(&base); - cl_assert((base2 = git_path_basename(A)) != NULL); + cl_assert((base2 = git_fs_path_basename(A)) != NULL); cl_assert_equal_s(B, base2); git__free(base2); } @@ -175,7 +176,7 @@ check_path_to_dir( git_str tgt = GIT_STR_INIT; git_str_sets(&tgt, path); - cl_git_pass(git_path_to_dir(&tgt)); + cl_git_pass(git_fs_path_to_dir(&tgt)); cl_assert_equal_s(expected, tgt.ptr); git_str_dispose(&tgt); @@ -193,7 +194,7 @@ check_string_to_dir( strncpy(buf, path, len + 2); - git_path_string_to_dir(buf, maxlen); + git_fs_path_string_to_dir(buf, maxlen); cl_assert_equal_s(expected, buf); @@ -294,10 +295,10 @@ static void check_fromurl(const char *expected_result, const char *input, int sh assert(should_fail || expected_result); if (!should_fail) { - cl_git_pass(git_path_fromurl(&buf, input)); + cl_git_pass(git_fs_path_fromurl(&buf, input)); cl_assert_equal_s(expected_result, git_str_cstr(&buf)); } else - cl_git_fail(git_path_fromurl(&buf, input)); + cl_git_fail(git_fs_path_fromurl(&buf, input)); git_str_dispose(&buf); } @@ -402,7 +403,7 @@ void test_core_path__11_walkup(void) info.expect_idx = i; cl_git_pass( - git_path_walk_up(&p, root[j], check_one_walkup_step, &info) + git_fs_path_walk_up(&p, root[j], check_one_walkup_step, &info) ); cl_assert_equal_s(p.ptr, expect[i]); @@ -439,7 +440,7 @@ void test_core_path__11a_walkup_cancel(void) cl_assert_equal_i( CANCEL_VALUE, - git_path_walk_up(&p, root[j], check_one_walkup_step, &info) + git_fs_path_walk_up(&p, root[j], check_one_walkup_step, &info) ); /* skip to next run of expectations */ @@ -451,16 +452,16 @@ void test_core_path__11a_walkup_cancel(void) void test_core_path__12_offset_to_path_root(void) { - cl_assert(git_path_root("non/rooted/path") == -1); - cl_assert(git_path_root("/rooted/path") == 0); + cl_assert(git_fs_path_root("non/rooted/path") == -1); + cl_assert(git_fs_path_root("/rooted/path") == 0); #ifdef GIT_WIN32 /* Windows specific tests */ - cl_assert(git_path_root("C:non/rooted/path") == -1); - cl_assert(git_path_root("C:/rooted/path") == 2); - cl_assert(git_path_root("//computername/sharefolder/resource") == 14); - cl_assert(git_path_root("//computername/sharefolder") == 14); - cl_assert(git_path_root("//computername") == -1); + cl_assert(git_fs_path_root("C:non/rooted/path") == -1); + cl_assert(git_fs_path_root("C:/rooted/path") == 2); + cl_assert(git_fs_path_root("//computername/sharefolder/resource") == 14); + cl_assert(git_fs_path_root("//computername/sharefolder") == 14); + cl_assert(git_fs_path_root("//computername") == -1); #endif } @@ -470,9 +471,9 @@ void test_core_path__13_cannot_prettify_a_non_existing_file(void) { git_str p = GIT_STR_INIT; - cl_assert_equal_b(git_path_exists(NON_EXISTING_FILEPATH), false); - cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH, NULL)); - cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH "/so-do-i", NULL)); + cl_assert_equal_b(git_fs_path_exists(NON_EXISTING_FILEPATH), false); + cl_assert_equal_i(GIT_ENOTFOUND, git_fs_path_prettify(&p, NON_EXISTING_FILEPATH, NULL)); + cl_assert_equal_i(GIT_ENOTFOUND, git_fs_path_prettify(&p, NON_EXISTING_FILEPATH "/so-do-i", NULL)); git_str_dispose(&p); } @@ -483,57 +484,57 @@ void test_core_path__14_apply_relative(void) cl_git_pass(git_str_sets(&p, "/this/is/a/base")); - cl_git_pass(git_path_apply_relative(&p, "../test")); + cl_git_pass(git_fs_path_apply_relative(&p, "../test")); cl_assert_equal_s("/this/is/a/test", p.ptr); - cl_git_pass(git_path_apply_relative(&p, "../../the/./end")); + cl_git_pass(git_fs_path_apply_relative(&p, "../../the/./end")); cl_assert_equal_s("/this/is/the/end", p.ptr); - cl_git_pass(git_path_apply_relative(&p, "./of/this/../the/string")); + cl_git_pass(git_fs_path_apply_relative(&p, "./of/this/../the/string")); cl_assert_equal_s("/this/is/the/end/of/the/string", p.ptr); - cl_git_pass(git_path_apply_relative(&p, "../../../../../..")); + cl_git_pass(git_fs_path_apply_relative(&p, "../../../../../..")); cl_assert_equal_s("/this/", p.ptr); - cl_git_pass(git_path_apply_relative(&p, "../")); + cl_git_pass(git_fs_path_apply_relative(&p, "../")); cl_assert_equal_s("/", p.ptr); - cl_git_fail(git_path_apply_relative(&p, "../../..")); + cl_git_fail(git_fs_path_apply_relative(&p, "../../..")); cl_git_pass(git_str_sets(&p, "d:/another/test")); - cl_git_pass(git_path_apply_relative(&p, "../..")); + cl_git_pass(git_fs_path_apply_relative(&p, "../..")); cl_assert_equal_s("d:/", p.ptr); - cl_git_pass(git_path_apply_relative(&p, "from/here/to/../and/./back/.")); + cl_git_pass(git_fs_path_apply_relative(&p, "from/here/to/../and/./back/.")); cl_assert_equal_s("d:/from/here/and/back/", p.ptr); cl_git_pass(git_str_sets(&p, "https://my.url.com/test.git")); - cl_git_pass(git_path_apply_relative(&p, "../another.git")); + cl_git_pass(git_fs_path_apply_relative(&p, "../another.git")); cl_assert_equal_s("https://my.url.com/another.git", p.ptr); - cl_git_pass(git_path_apply_relative(&p, "../full/path/url.patch")); + cl_git_pass(git_fs_path_apply_relative(&p, "../full/path/url.patch")); cl_assert_equal_s("https://my.url.com/full/path/url.patch", p.ptr); - cl_git_pass(git_path_apply_relative(&p, "..")); + cl_git_pass(git_fs_path_apply_relative(&p, "..")); cl_assert_equal_s("https://my.url.com/full/path/", p.ptr); - cl_git_pass(git_path_apply_relative(&p, "../../../")); + cl_git_pass(git_fs_path_apply_relative(&p, "../../../")); cl_assert_equal_s("https://", p.ptr); cl_git_pass(git_str_sets(&p, "../../this/is/relative")); - cl_git_pass(git_path_apply_relative(&p, "../../preserves/the/prefix")); + cl_git_pass(git_fs_path_apply_relative(&p, "../../preserves/the/prefix")); cl_assert_equal_s("../../this/preserves/the/prefix", p.ptr); - cl_git_pass(git_path_apply_relative(&p, "../../../../that")); + cl_git_pass(git_fs_path_apply_relative(&p, "../../../../that")); cl_assert_equal_s("../../that", p.ptr); - cl_git_pass(git_path_apply_relative(&p, "../there")); + cl_git_pass(git_fs_path_apply_relative(&p, "../there")); cl_assert_equal_s("../../there", p.ptr); git_str_dispose(&p); } @@ -542,7 +543,7 @@ static void assert_resolve_relative( git_str *buf, const char *expected, const char *path) { cl_git_pass(git_str_sets(buf, path)); - cl_git_pass(git_path_resolve_relative(buf, 0)); + cl_git_pass(git_fs_path_resolve_relative(buf, 0)); cl_assert_equal_s(expected, buf->ptr); } @@ -596,22 +597,22 @@ void test_core_path__15_resolve_relative(void) assert_resolve_relative(&buf, "../d", "a/b/../../../c/../d"); cl_git_pass(git_str_sets(&buf, "/..")); - cl_git_fail(git_path_resolve_relative(&buf, 0)); + cl_git_fail(git_fs_path_resolve_relative(&buf, 0)); cl_git_pass(git_str_sets(&buf, "/./..")); - cl_git_fail(git_path_resolve_relative(&buf, 0)); + cl_git_fail(git_fs_path_resolve_relative(&buf, 0)); cl_git_pass(git_str_sets(&buf, "/.//..")); - cl_git_fail(git_path_resolve_relative(&buf, 0)); + cl_git_fail(git_fs_path_resolve_relative(&buf, 0)); cl_git_pass(git_str_sets(&buf, "/../.")); - cl_git_fail(git_path_resolve_relative(&buf, 0)); + cl_git_fail(git_fs_path_resolve_relative(&buf, 0)); cl_git_pass(git_str_sets(&buf, "/../.././../a")); - cl_git_fail(git_path_resolve_relative(&buf, 0)); + cl_git_fail(git_fs_path_resolve_relative(&buf, 0)); cl_git_pass(git_str_sets(&buf, "////..")); - cl_git_fail(git_path_resolve_relative(&buf, 0)); + cl_git_fail(git_fs_path_resolve_relative(&buf, 0)); /* things that start with Windows network paths */ #ifdef GIT_WIN32 @@ -620,7 +621,7 @@ void test_core_path__15_resolve_relative(void) assert_resolve_relative(&buf, "//a/b/c", "//a/Q/../b/x/y/../../c"); cl_git_pass(git_str_sets(&buf, "//a/b/../..")); - cl_git_fail(git_path_resolve_relative(&buf, 0)); + cl_git_fail(git_fs_path_resolve_relative(&buf, 0)); #else assert_resolve_relative(&buf, "/a/b/c", "//a/b/c"); assert_resolve_relative(&buf, "/a/", "//a/b/.."); @@ -632,7 +633,7 @@ void test_core_path__15_resolve_relative(void) } #define assert_common_dirlen(i, p, q) \ - cl_assert_equal_i((i), git_path_common_dirlen((p), (q))); + cl_assert_equal_i((i), git_fs_path_common_dirlen((p), (q))); void test_core_path__16_resolve_relative(void) { @@ -650,12 +651,3 @@ void test_core_path__16_resolve_relative(void) assert_common_dirlen(6, "a/b/c/foo.txt", "a/b/c/d/e/bar.txt"); assert_common_dirlen(7, "/a/b/c/foo.txt", "/a/b/c/d/e/bar.txt"); } - -void test_core_path__git_path_is_file(void) -{ - cl_git_fail(git_path_is_gitfile("blob", 4, -1, GIT_PATH_FS_HFS)); - cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITIGNORE, GIT_PATH_FS_HFS)); - cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS)); - cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITATTRIBUTES, GIT_PATH_FS_HFS)); - cl_git_fail(git_path_is_gitfile("blob", 4, 3, GIT_PATH_FS_HFS)); -} diff --git a/tests/core/posix.c b/tests/core/posix.c index 247bd43f5..cba312913 100644 --- a/tests/core/posix.c +++ b/tests/core/posix.c @@ -147,7 +147,7 @@ void test_core_posix__utimes(void) void test_core_posix__unlink_removes_symlink(void) { - if (!git_path_supports_symlinks(clar_sandbox_path())) + if (!git_fs_path_supports_symlinks(clar_sandbox_path())) clar__skip(); cl_git_mkfile("file", "Dummy file."); @@ -159,8 +159,8 @@ void test_core_posix__unlink_removes_symlink(void) cl_must_pass(p_unlink("file-symlink")); cl_must_pass(p_unlink("dir-symlink")); - cl_assert(git_path_exists("file")); - cl_assert(git_path_exists("dir")); + cl_assert(git_fs_path_exists("file")); + cl_assert(git_fs_path_exists("dir")); cl_must_pass(p_unlink("file")); cl_must_pass(p_rmdir("dir")); @@ -170,7 +170,7 @@ void test_core_posix__symlink_resolves_to_correct_type(void) { git_str contents = GIT_STR_INIT; - if (!git_path_supports_symlinks(clar_sandbox_path())) + if (!git_fs_path_supports_symlinks(clar_sandbox_path())) clar__skip(); cl_must_pass(git_futils_mkdir("dir", 0777, 0)); @@ -194,7 +194,7 @@ void test_core_posix__relative_symlink(void) { git_str contents = GIT_STR_INIT; - if (!git_path_supports_symlinks(clar_sandbox_path())) + if (!git_fs_path_supports_symlinks(clar_sandbox_path())) clar__skip(); cl_must_pass(git_futils_mkdir("dir", 0777, 0)); @@ -214,7 +214,7 @@ void test_core_posix__symlink_to_file_across_dirs(void) { git_str contents = GIT_STR_INIT; - if (!git_path_supports_symlinks(clar_sandbox_path())) + if (!git_fs_path_supports_symlinks(clar_sandbox_path())) clar__skip(); /* diff --git a/tests/core/rmdir.c b/tests/core/rmdir.c index 56ea320be..8e5bd5878 100644 --- a/tests/core/rmdir.c +++ b/tests/core/rmdir.c @@ -29,7 +29,7 @@ void test_core_rmdir__initialize(void) void test_core_rmdir__cleanup(void) { - if (git_path_exists(empty_tmp_dir)) + if (git_fs_path_exists(empty_tmp_dir)) cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_REMOVE_FILES)); } @@ -38,11 +38,11 @@ void test_core_rmdir__delete_recursive(void) { git_str path = GIT_STR_INIT; cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one")); - cl_assert(git_path_exists(git_str_cstr(&path))); + cl_assert(git_fs_path_exists(git_str_cstr(&path))); cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY)); - cl_assert(!git_path_exists(git_str_cstr(&path))); + cl_assert(!git_fs_path_exists(git_str_cstr(&path))); git_str_dispose(&path); } @@ -61,7 +61,7 @@ void test_core_rmdir__fail_to_delete_non_empty_dir(void) cl_must_pass(p_unlink(file.ptr)); cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_EMPTY_HIERARCHY)); - cl_assert(!git_path_exists(empty_tmp_dir)); + cl_assert(!git_fs_path_exists(empty_tmp_dir)); git_str_dispose(&file); } @@ -69,7 +69,7 @@ void test_core_rmdir__fail_to_delete_non_empty_dir(void) void test_core_rmdir__keep_base(void) { cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_SKIP_ROOT)); - cl_assert(git_path_exists(empty_tmp_dir)); + cl_assert(git_fs_path_exists(empty_tmp_dir)); } void test_core_rmdir__can_skip_non_empty_dir(void) @@ -81,10 +81,10 @@ void test_core_rmdir__can_skip_non_empty_dir(void) cl_git_mkfile(git_str_cstr(&file), "dummy"); cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_SKIP_NONEMPTY)); - cl_assert(git_path_exists(git_str_cstr(&file)) == true); + cl_assert(git_fs_path_exists(git_str_cstr(&file)) == true); cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_REMOVE_FILES)); - cl_assert(git_path_exists(empty_tmp_dir) == false); + cl_assert(git_fs_path_exists(empty_tmp_dir) == false); git_str_dispose(&file); } @@ -96,23 +96,23 @@ void test_core_rmdir__can_remove_empty_parents(void) cl_git_pass( git_str_joinpath(&file, empty_tmp_dir, "/one/two_two/three/file.txt")); cl_git_mkfile(git_str_cstr(&file), "dummy"); - cl_assert(git_path_isfile(git_str_cstr(&file))); + cl_assert(git_fs_path_isfile(git_str_cstr(&file))); cl_git_pass(git_futils_rmdir_r("one/two_two/three/file.txt", empty_tmp_dir, GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_EMPTY_PARENTS)); - cl_assert(!git_path_exists(git_str_cstr(&file))); + cl_assert(!git_fs_path_exists(git_str_cstr(&file))); git_str_rtruncate_at_char(&file, '/'); /* three (only contained file.txt) */ - cl_assert(!git_path_exists(git_str_cstr(&file))); + cl_assert(!git_fs_path_exists(git_str_cstr(&file))); git_str_rtruncate_at_char(&file, '/'); /* two_two (only contained three) */ - cl_assert(!git_path_exists(git_str_cstr(&file))); + cl_assert(!git_fs_path_exists(git_str_cstr(&file))); git_str_rtruncate_at_char(&file, '/'); /* one (contained two_one also) */ - cl_assert(git_path_exists(git_str_cstr(&file))); + cl_assert(git_fs_path_exists(git_str_cstr(&file))); - cl_assert(git_path_exists(empty_tmp_dir) == true); + cl_assert(git_fs_path_exists(empty_tmp_dir) == true); git_str_dispose(&file); diff --git a/tests/core/stat.c b/tests/core/stat.c index 56d141e98..022380ba6 100644 --- a/tests/core/stat.c +++ b/tests/core/stat.c @@ -102,7 +102,7 @@ void test_core_stat__root(void) int root_len; struct stat st; - root_len = git_path_root(sandbox); + root_len = git_fs_path_root(sandbox); cl_assert(root_len >= 0); git_str_set(&root, sandbox, root_len+1); diff --git a/tests/diff/drivers.c b/tests/diff/drivers.c index ce24e9bc0..304a54b56 100644 --- a/tests/diff/drivers.c +++ b/tests/diff/drivers.c @@ -187,7 +187,7 @@ void test_diff_drivers__builtins(void) g_repo = cl_git_sandbox_init("userdiff"); - cl_git_pass(git_path_dirload(&files, "userdiff/files", 9, 0)); + cl_git_pass(git_fs_path_dirload(&files, "userdiff/files", 9, 0)); opts.interhunk_lines = 1; opts.context_lines = 1; diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c index f7c74a294..444fc2f97 100644 --- a/tests/diff/workdir.c +++ b/tests/diff/workdir.c @@ -1252,7 +1252,7 @@ void test_diff_workdir__can_diff_empty_file(void) /* empty contents of file */ cl_git_rewritefile("attr_index/README.txt", ""); - cl_git_pass(git_path_lstat("attr_index/README.txt", &st)); + cl_git_pass(git_fs_path_lstat("attr_index/README.txt", &st)); cl_assert_equal_i(0, (int)st.st_size); cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts)); @@ -1265,7 +1265,7 @@ void test_diff_workdir__can_diff_empty_file(void) /* remove a file altogether */ cl_git_pass(p_unlink("attr_index/README.txt")); - cl_assert(!git_path_exists("attr_index/README.txt")); + cl_assert(!git_fs_path_exists("attr_index/README.txt")); cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, tree, &opts)); cl_assert_equal_i(3, (int)git_diff_num_deltas(diff)); @@ -1759,7 +1759,7 @@ static int touch_file(void *payload, git_str *path) struct p_timeval times[2]; GIT_UNUSED(payload); - if (git_path_isdir(path->ptr)) + if (git_fs_path_isdir(path->ptr)) return 0; cl_must_pass(p_stat(path->ptr, &st)); @@ -1805,7 +1805,7 @@ void test_diff_workdir__can_update_index(void) { git_str path = GIT_STR_INIT; cl_git_pass(git_str_sets(&path, "status")); - cl_git_pass(git_path_direach(&path, 0, touch_file, NULL)); + cl_git_pass(git_fs_path_direach(&path, 0, touch_file, NULL)); git_str_dispose(&path); } @@ -2040,7 +2040,7 @@ void test_diff_workdir__only_writes_index_when_necessary(void) /* touch all the files so stat times are different */ cl_git_pass(git_str_sets(&path, "status")); - cl_git_pass(git_path_direach(&path, 0, touch_file, NULL)); + cl_git_pass(git_fs_path_direach(&path, 0, touch_file, NULL)); cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); git_diff_free(diff); diff --git a/tests/fetchhead/nonetwork.c b/tests/fetchhead/nonetwork.c index 0de712be8..334755cc3 100644 --- a/tests/fetchhead/nonetwork.c +++ b/tests/fetchhead/nonetwork.c @@ -446,9 +446,9 @@ void test_fetchhead_nonetwork__create_when_refpecs_given(void) cl_git_pass(git_str_joinpath(&path, git_repository_path(g_repo), "FETCH_HEAD")); cl_git_pass(git_remote_create(&remote, g_repo, "origin", cl_fixture("testrepo.git"))); - cl_assert(!git_path_exists(path.ptr)); + cl_assert(!git_fs_path_exists(path.ptr)); cl_git_pass(git_remote_fetch(remote, &specs, NULL, NULL)); - cl_assert(git_path_exists(path.ptr)); + cl_assert(git_fs_path_exists(path.ptr)); cl_git_pass(git_repository_fetchhead_foreach(g_repo, find_master_haacked, NULL)); cl_assert(find_master_haacked_called); @@ -500,9 +500,9 @@ void test_fetchhead_nonetwork__create_with_multiple_refspecs(void) cl_git_pass(git_remote_lookup(&remote, g_repo, "origin")); cl_git_pass(git_str_joinpath(&path, git_repository_path(g_repo), "FETCH_HEAD")); - cl_assert(!git_path_exists(path.ptr)); + cl_assert(!git_fs_path_exists(path.ptr)); cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL)); - cl_assert(git_path_exists(path.ptr)); + cl_assert(git_fs_path_exists(path.ptr)); { int i; diff --git a/tests/ignore/path.c b/tests/ignore/path.c index d55bdc5dd..a574d1d79 100644 --- a/tests/ignore/path.c +++ b/tests/ignore/path.c @@ -257,7 +257,7 @@ void test_ignore_path__skip_gitignore_directory(void) { cl_git_rewritefile("attr/.git/info/exclude", "/NewFolder\n/NewFolder/NewFolder"); cl_must_pass(p_unlink("attr/.gitignore")); - cl_assert(!git_path_exists("attr/.gitignore")); + cl_assert(!git_fs_path_exists("attr/.gitignore")); p_mkdir("attr/.gitignore", 0777); cl_git_mkfile("attr/.gitignore/garbage.txt", "new_file\n"); @@ -270,7 +270,7 @@ void test_ignore_path__skip_gitignore_directory(void) void test_ignore_path__subdirectory_gitignore(void) { cl_must_pass(p_unlink("attr/.gitignore")); - cl_assert(!git_path_exists("attr/.gitignore")); + cl_assert(!git_fs_path_exists("attr/.gitignore")); cl_git_mkfile( "attr/.gitignore", "file1\n"); diff --git a/tests/index/crlf.c b/tests/index/crlf.c index 8d2a5fcce..7520c23a3 100644 --- a/tests/index/crlf.c +++ b/tests/index/crlf.c @@ -53,7 +53,7 @@ static int add_and_check_file(void *payload, git_str *actual_path) git_blob *blob; bool failed = true; - basename = git_path_basename(actual_path->ptr); + basename = git_fs_path_basename(actual_path->ptr); if (!strcmp(basename, ".git") || !strcmp(basename, ".gitattributes")) { failed = false; @@ -65,7 +65,7 @@ static int add_and_check_file(void *payload, git_str *actual_path) cl_git_pass(git_str_puts(&expected_path_fail, expected_path.ptr)); cl_git_pass(git_str_puts(&expected_path_fail, ".fail")); - if (git_path_isfile(expected_path.ptr)) { + if (git_fs_path_isfile(expected_path.ptr)) { cl_git_pass(git_index_add_bypath(g_index, basename)); cl_assert(entry = git_index_get_bypath(g_index, basename, 0)); @@ -77,7 +77,7 @@ static int add_and_check_file(void *payload, git_str *actual_path) goto done; git_blob_free(blob); - } else if (git_path_isfile(expected_path_fail.ptr)) { + } else if (git_fs_path_isfile(expected_path_fail.ptr)) { cl_git_pass(git_futils_readbuffer(&expected_contents, expected_path_fail.ptr)); git_str_rtrim(&expected_contents); @@ -161,7 +161,7 @@ static void test_add_index(const char *safecrlf, const char *autocrlf, const cha cl_fixture_sandbox(expected_fixture.ptr); compare_data.dirname = sandboxname.ptr; - cl_git_pass(git_path_direach(&reponame, 0, add_and_check_file, &compare_data)); + cl_git_pass(git_fs_path_direach(&reponame, 0, add_and_check_file, &compare_data)); cl_fixture_cleanup(expected_fixture.ptr); git_str_dispose(&expected_fixture); @@ -179,9 +179,9 @@ static void set_up_workingdir(const char *name) size_t i; const char *fn; - git_path_dirload(&contents, name, 0, 0); + git_fs_path_dirload(&contents, name, 0, 0); git_vector_foreach(&contents, i, fn) { - char *basename = git_path_basename(fn); + char *basename = git_fs_path_basename(fn); bool skip = strncasecmp(basename, ".git", 4) == 0 && strlen(basename) == 4; git__free(basename); @@ -193,9 +193,9 @@ static void set_up_workingdir(const char *name) git_vector_free_deep(&contents); /* copy input files */ - git_path_dirload(&contents, cl_fixture("crlf"), 0, 0); + git_fs_path_dirload(&contents, cl_fixture("crlf"), 0, 0); git_vector_foreach(&contents, i, fn) { - char *basename = git_path_basename(fn); + char *basename = git_fs_path_basename(fn); git_str dest_filename = GIT_STR_INIT; if (strcmp(basename, ".gitted") && diff --git a/tests/index/tests.c b/tests/index/tests.c index 9b28028e6..b6715574e 100644 --- a/tests/index/tests.c +++ b/tests/index/tests.c @@ -571,9 +571,9 @@ void test_index_tests__cannot_add_invalid_filename(void) cl_must_pass(p_mkdir("./invalid/subdir", 0777)); /* cl_git_mkfile() needs the dir to exist */ - if (!git_path_exists("./invalid/.GIT")) + if (!git_fs_path_exists("./invalid/.GIT")) cl_must_pass(p_mkdir("./invalid/.GIT", 0777)); - if (!git_path_exists("./invalid/.GiT")) + if (!git_fs_path_exists("./invalid/.GiT")) cl_must_pass(p_mkdir("./invalid/.GiT", 0777)); assert_add_bypath_fails(repo, ".git/hello"); diff --git a/tests/iterator/index.c b/tests/iterator/index.c index 69b795f5c..7218b4f75 100644 --- a/tests/iterator/index.c +++ b/tests/iterator/index.c @@ -283,7 +283,7 @@ void test_iterator_index__case_folding(void) int fs_is_ci = 0; cl_git_pass(git_str_joinpath(&path, cl_fixture("icase"), ".gitted/CoNfIg")); - fs_is_ci = git_path_exists(path.ptr); + fs_is_ci = git_fs_path_exists(path.ptr); git_str_dispose(&path); index_iterator_test( diff --git a/tests/iterator/workdir.c b/tests/iterator/workdir.c index 7ca726c24..86b847cab 100644 --- a/tests/iterator/workdir.c +++ b/tests/iterator/workdir.c @@ -1024,7 +1024,7 @@ static void create_paths(const char *root, int depth) int i; cl_git_pass(git_str_puts(&fullpath, root)); - cl_git_pass(git_path_to_dir(&fullpath)); + cl_git_pass(git_fs_path_to_dir(&fullpath)); root_len = fullpath.size; diff --git a/tests/merge/merge_helpers.c b/tests/merge/merge_helpers.c index 1eb423ef7..73a1d852d 100644 --- a/tests/merge/merge_helpers.c +++ b/tests/merge/merge_helpers.c @@ -346,7 +346,7 @@ int merge_test_workdir(git_repository *repo, const struct merge_index_entry expe git_str wd = GIT_STR_INIT; git_str_puts(&wd, repo->workdir); - git_path_direach(&wd, 0, dircount, &actual_len); + git_fs_path_direach(&wd, 0, dircount, &actual_len); if (actual_len != expected_len) return 0; diff --git a/tests/merge/workdir/setup.c b/tests/merge/workdir/setup.c index fe33e21f2..3db2d074f 100644 --- a/tests/merge/workdir/setup.c +++ b/tests/merge/workdir/setup.c @@ -48,15 +48,15 @@ static bool test_file_contents(const char *filename, const char *expected) { git_str file_path_buf = GIT_STR_INIT, file_buf = GIT_STR_INIT; bool equals; - + git_str_joinpath(&file_path_buf, git_repository_path(repo), filename); - + cl_git_pass(git_futils_readbuffer(&file_buf, file_path_buf.ptr)); equals = (strcmp(file_buf.ptr, expected) == 0); git_str_dispose(&file_path_buf); git_str_dispose(&file_buf); - + return equals; } @@ -77,13 +77,13 @@ void test_merge_workdir_setup__one_branch(void) git_oid our_oid; git_reference *octo1_ref; git_annotated_commit *our_head, *their_heads[1]; - + cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - + cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref)); - + cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 1)); cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n")); @@ -92,7 +92,7 @@ void test_merge_workdir_setup__one_branch(void) cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "'\n")); git_reference_free(octo1_ref); - + git_annotated_commit_free(our_head); git_annotated_commit_free(their_heads[0]); } @@ -103,10 +103,10 @@ void test_merge_workdir_setup__one_oid(void) git_oid our_oid; git_oid octo1_oid; git_annotated_commit *our_head, *their_heads[1]; - + cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - + cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID)); cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_oid)); @@ -128,10 +128,10 @@ void test_merge_workdir_setup__two_branches(void) git_reference *octo1_ref; git_reference *octo2_ref; git_annotated_commit *our_head, *their_heads[2]; - + cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - + cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref)); @@ -139,15 +139,15 @@ void test_merge_workdir_setup__two_branches(void) cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref)); cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2)); - + cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n")); cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO2_BRANCH "'\n")); - + git_reference_free(octo1_ref); git_reference_free(octo2_ref); - + git_annotated_commit_free(our_head); git_annotated_commit_free(their_heads[0]); git_annotated_commit_free(their_heads[1]); @@ -161,13 +161,13 @@ void test_merge_workdir_setup__three_branches(void) git_reference *octo2_ref; git_reference *octo3_ref; git_annotated_commit *our_head, *their_heads[3]; - + cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref)); - + cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref)); @@ -180,7 +180,7 @@ void test_merge_workdir_setup__three_branches(void) cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "', '" OCTO2_BRANCH "' and '" OCTO3_BRANCH "'\n")); - + git_reference_free(octo1_ref); git_reference_free(octo2_ref); git_reference_free(octo3_ref); @@ -199,13 +199,13 @@ void test_merge_workdir_setup__three_oids(void) git_oid octo2_oid; git_oid octo3_oid; git_annotated_commit *our_head, *their_heads[3]; - + cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID)); cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_oid)); - + cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID)); cl_git_pass(git_annotated_commit_lookup(&their_heads[1], repo, &octo2_oid)); @@ -218,7 +218,7 @@ void test_merge_workdir_setup__three_oids(void) cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; commit '" OCTO2_OID "'; commit '" OCTO3_OID "'\n")); - + git_annotated_commit_free(our_head); git_annotated_commit_free(their_heads[0]); git_annotated_commit_free(their_heads[1]); @@ -232,7 +232,7 @@ void test_merge_workdir_setup__branches_and_oids_1(void) git_reference *octo1_ref; git_oid octo2_oid; git_annotated_commit *our_head, *their_heads[2]; - + cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); @@ -248,7 +248,7 @@ void test_merge_workdir_setup__branches_and_oids_1(void) cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "'; commit '" OCTO2_OID "'\n")); - + git_reference_free(octo1_ref); git_annotated_commit_free(our_head); @@ -271,23 +271,23 @@ void test_merge_workdir_setup__branches_and_oids_2(void) cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref)); - + cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID)); cl_git_pass(git_annotated_commit_lookup(&their_heads[1], repo, &octo2_oid)); cl_git_pass(git_reference_lookup(&octo3_ref, repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[2], repo, octo3_ref)); - + cl_git_pass(git_oid_fromstr(&octo4_oid, OCTO4_OID)); cl_git_pass(git_annotated_commit_lookup(&their_heads[3], repo, &octo4_oid)); - + cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 4)); cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n")); cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO3_BRANCH "'; commit '" OCTO2_OID "'; commit '" OCTO4_OID "'\n")); - + git_reference_free(octo1_ref); git_reference_free(octo3_ref); @@ -307,7 +307,7 @@ void test_merge_workdir_setup__branches_and_oids_3(void) git_oid octo3_oid; git_reference *octo4_ref; git_annotated_commit *our_head, *their_heads[4]; - + cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); @@ -319,17 +319,17 @@ void test_merge_workdir_setup__branches_and_oids_3(void) cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID)); cl_git_pass(git_annotated_commit_lookup(&their_heads[2], repo, &octo3_oid)); - + cl_git_pass(git_reference_lookup(&octo4_ref, repo, GIT_REFS_HEADS_DIR OCTO4_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[3], repo, octo4_ref)); - + cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 4)); cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n")); cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; branches '" OCTO2_BRANCH "' and '" OCTO4_BRANCH "'; commit '" OCTO3_OID "'\n")); - + git_reference_free(octo2_ref); git_reference_free(octo4_ref); @@ -350,19 +350,19 @@ void test_merge_workdir_setup__branches_and_oids_4(void) git_reference *octo4_ref; git_reference *octo5_ref; git_annotated_commit *our_head, *their_heads[5]; - + cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - + cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID)); cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_oid)); - + cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref)); - + cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID)); cl_git_pass(git_annotated_commit_lookup(&their_heads[2], repo, &octo3_oid)); - + cl_git_pass(git_reference_lookup(&octo4_ref, repo, GIT_REFS_HEADS_DIR OCTO4_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[3], repo, octo4_ref)); @@ -375,7 +375,7 @@ void test_merge_workdir_setup__branches_and_oids_4(void) cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; branches '" OCTO2_BRANCH "', '" OCTO4_BRANCH "' and '" OCTO5_BRANCH "'; commit '" OCTO3_OID "'\n")); - + git_reference_free(octo2_ref); git_reference_free(octo4_ref); git_reference_free(octo5_ref); @@ -396,30 +396,30 @@ void test_merge_workdir_setup__three_same_branches(void) git_reference *octo1_2_ref; git_reference *octo1_3_ref; git_annotated_commit *our_head, *their_heads[3]; - + cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - + cl_git_pass(git_reference_lookup(&octo1_1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_1_ref)); - + cl_git_pass(git_reference_lookup(&octo1_2_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo1_2_ref)); - + cl_git_pass(git_reference_lookup(&octo1_3_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[2], repo, octo1_3_ref)); - + cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 3)); cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO1_OID "\n" OCTO1_OID "\n")); cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "', '" OCTO1_BRANCH "' and '" OCTO1_BRANCH "'\n")); - + git_reference_free(octo1_1_ref); git_reference_free(octo1_2_ref); git_reference_free(octo1_3_ref); - + git_annotated_commit_free(our_head); git_annotated_commit_free(their_heads[0]); git_annotated_commit_free(their_heads[1]); @@ -434,26 +434,26 @@ void test_merge_workdir_setup__three_same_oids(void) git_oid octo1_2_oid; git_oid octo1_3_oid; git_annotated_commit *our_head, *their_heads[3]; - + cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - + cl_git_pass(git_oid_fromstr(&octo1_1_oid, OCTO1_OID)); cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_1_oid)); - + cl_git_pass(git_oid_fromstr(&octo1_2_oid, OCTO1_OID)); cl_git_pass(git_annotated_commit_lookup(&their_heads[1], repo, &octo1_2_oid)); - + cl_git_pass(git_oid_fromstr(&octo1_3_oid, OCTO1_OID)); cl_git_pass(git_annotated_commit_lookup(&their_heads[2], repo, &octo1_3_oid)); - + cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 3)); - + cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO1_OID "\n" OCTO1_OID "\n")); cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge commit '" OCTO1_OID "'; commit '" OCTO1_OID "'; commit '" OCTO1_OID "'\n")); - + git_annotated_commit_free(our_head); git_annotated_commit_free(their_heads[0]); git_annotated_commit_free(their_heads[1]); @@ -473,7 +473,7 @@ static int create_remote_tracking_branch(const char *branch_name, const char *oi (error = git_str_puts(&remotes_path, GIT_REFS_REMOTES_DIR)) < 0) goto done; - if (!git_path_exists(git_str_cstr(&remotes_path)) && + if (!git_fs_path_exists(git_str_cstr(&remotes_path)) && (error = p_mkdir(git_str_cstr(&remotes_path), 0777)) < 0) goto done; @@ -481,7 +481,7 @@ static int create_remote_tracking_branch(const char *branch_name, const char *oi (error = git_str_puts(&origin_path, "origin")) < 0) goto done; - if (!git_path_exists(git_str_cstr(&origin_path)) && + if (!git_fs_path_exists(git_str_cstr(&origin_path)) && (error = p_mkdir(git_str_cstr(&origin_path), 0777)) < 0) goto done; @@ -514,10 +514,10 @@ void test_merge_workdir_setup__remote_tracking_one_branch(void) cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - + cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref)); - + cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 1)); cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n")); @@ -526,7 +526,7 @@ void test_merge_workdir_setup__remote_tracking_one_branch(void) cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge remote-tracking branch 'refs/remotes/origin/" OCTO1_BRANCH "'\n")); git_reference_free(octo1_ref); - + git_annotated_commit_free(our_head); git_annotated_commit_free(their_heads[0]); } @@ -544,7 +544,7 @@ void test_merge_workdir_setup__remote_tracking_two_branches(void) cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - + cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref)); @@ -552,15 +552,15 @@ void test_merge_workdir_setup__remote_tracking_two_branches(void) cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref)); cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2)); - + cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n")); cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge remote-tracking branches 'refs/remotes/origin/" OCTO1_BRANCH "' and 'refs/remotes/origin/" OCTO2_BRANCH "'\n")); - + git_reference_free(octo1_ref); git_reference_free(octo2_ref); - + git_annotated_commit_free(our_head); git_annotated_commit_free(their_heads[0]); git_annotated_commit_free(their_heads[1]); @@ -578,13 +578,13 @@ void test_merge_workdir_setup__remote_tracking_three_branches(void) cl_git_pass(create_remote_tracking_branch(OCTO1_BRANCH, OCTO1_OID)); cl_git_pass(create_remote_tracking_branch(OCTO2_BRANCH, OCTO2_OID)); cl_git_pass(create_remote_tracking_branch(OCTO3_BRANCH, OCTO3_OID)); - + cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref)); - + cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO2_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref)); @@ -597,7 +597,7 @@ void test_merge_workdir_setup__remote_tracking_three_branches(void) cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge remote-tracking branches 'refs/remotes/origin/" OCTO1_BRANCH "', 'refs/remotes/origin/" OCTO2_BRANCH "' and 'refs/remotes/origin/" OCTO3_BRANCH "'\n")); - + git_reference_free(octo1_ref); git_reference_free(octo2_ref); git_reference_free(octo3_ref); @@ -628,15 +628,15 @@ void test_merge_workdir_setup__normal_branch_and_remote_tracking_branch(void) cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref)); cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2)); - + cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n")); cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "', remote-tracking branch 'refs/remotes/origin/" OCTO2_BRANCH "'\n")); - + git_reference_free(octo1_ref); git_reference_free(octo2_ref); - + git_annotated_commit_free(our_head); git_annotated_commit_free(their_heads[0]); git_annotated_commit_free(their_heads[1]); @@ -654,7 +654,7 @@ void test_merge_workdir_setup__remote_tracking_branch_and_normal_branch(void) cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - + cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref)); @@ -662,15 +662,15 @@ void test_merge_workdir_setup__remote_tracking_branch_and_normal_branch(void) cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref)); cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2)); - + cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n")); cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO2_BRANCH "', remote-tracking branch 'refs/remotes/origin/" OCTO1_BRANCH "'\n")); - + git_reference_free(octo1_ref); git_reference_free(octo2_ref); - + git_annotated_commit_free(our_head); git_annotated_commit_free(their_heads[0]); git_annotated_commit_free(their_heads[1]); @@ -691,7 +691,7 @@ void test_merge_workdir_setup__two_remote_tracking_branch_and_two_normal_branche cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - + cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref)); @@ -705,17 +705,17 @@ void test_merge_workdir_setup__two_remote_tracking_branch_and_two_normal_branche cl_git_pass(git_annotated_commit_from_ref(&their_heads[3], repo, octo4_ref)); cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 4)); - + cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n" OCTO2_OID "\n" OCTO3_OID "\n" OCTO4_OID "\n")); cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO3_BRANCH "', remote-tracking branches 'refs/remotes/origin/" OCTO2_BRANCH "' and 'refs/remotes/origin/" OCTO4_BRANCH "'\n")); - + git_reference_free(octo1_ref); git_reference_free(octo2_ref); git_reference_free(octo3_ref); git_reference_free(octo4_ref); - + git_annotated_commit_free(our_head); git_annotated_commit_free(their_heads[0]); git_annotated_commit_free(their_heads[1]); @@ -735,14 +735,14 @@ void test_merge_workdir_setup__pull_one(void) cl_git_pass(git_oid_fromstr(&octo1_1_oid, OCTO1_OID)); cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.url/repo.git", &octo1_1_oid)); - + cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 1)); - + cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n")); cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch 'octo1' of http://remote.url/repo.git\n")); - + git_annotated_commit_free(our_head); git_annotated_commit_free(their_heads[0]); } @@ -754,7 +754,7 @@ void test_merge_workdir_setup__pull_two(void) git_oid octo1_oid; git_oid octo2_oid; git_annotated_commit *our_head, *their_heads[2]; - + cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); @@ -770,7 +770,7 @@ void test_merge_workdir_setup__pull_two(void) cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO2_BRANCH "' of http://remote.url/repo.git\n")); - + git_annotated_commit_free(our_head); git_annotated_commit_free(their_heads[0]); git_annotated_commit_free(their_heads[1]); @@ -784,7 +784,7 @@ void test_merge_workdir_setup__pull_three(void) git_oid octo2_oid; git_oid octo3_oid; git_annotated_commit *our_head, *their_heads[3]; - + cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); @@ -803,7 +803,7 @@ void test_merge_workdir_setup__pull_three(void) cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "', '" OCTO2_BRANCH "' and '" OCTO3_BRANCH "' of http://remote.url/repo.git\n")); - + git_annotated_commit_free(our_head); git_annotated_commit_free(their_heads[0]); git_annotated_commit_free(their_heads[1]); @@ -817,7 +817,7 @@ void test_merge_workdir_setup__three_remotes(void) git_oid octo2_oid; git_oid octo3_oid; git_annotated_commit *our_head, *their_heads[3]; - + cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); @@ -836,7 +836,7 @@ void test_merge_workdir_setup__three_remotes(void) cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branch '" OCTO1_BRANCH "' of http://remote.first/repo.git, branch '" OCTO2_BRANCH "' of http://remote.second/repo.git, branch '" OCTO3_BRANCH "' of http://remote.third/repo.git\n")); - + git_annotated_commit_free(our_head); git_annotated_commit_free(their_heads[0]); git_annotated_commit_free(their_heads[1]); @@ -851,7 +851,7 @@ void test_merge_workdir_setup__two_remotes(void) git_oid octo3_oid; git_oid octo4_oid; git_annotated_commit *our_head, *their_heads[4]; - + cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); @@ -873,7 +873,7 @@ void test_merge_workdir_setup__two_remotes(void) cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n")); cl_assert(test_file_contents(GIT_MERGE_MODE_FILE, "no-ff")); cl_assert(test_file_contents(GIT_MERGE_MSG_FILE, "Merge branches '" OCTO1_BRANCH "' and '" OCTO3_BRANCH "' of http://remote.first/repo.git, branches '" OCTO2_BRANCH "' and '" OCTO4_BRANCH "' of http://remote.second/repo.git\n")); - + git_annotated_commit_free(our_head); git_annotated_commit_free(their_heads[0]); git_annotated_commit_free(their_heads[1]); @@ -1036,9 +1036,9 @@ void test_merge_workdir_setup__removed_after_failure(void) cl_git_fail(git_merge( repo, (const git_annotated_commit **)&their_heads[0], 1, NULL, NULL)); - cl_assert(!git_path_exists("merge-resolve/.git/" GIT_MERGE_HEAD_FILE)); - cl_assert(!git_path_exists("merge-resolve/.git/" GIT_MERGE_MODE_FILE)); - cl_assert(!git_path_exists("merge-resolve/.git/" GIT_MERGE_MSG_FILE)); + cl_assert(!git_fs_path_exists("merge-resolve/.git/" GIT_MERGE_HEAD_FILE)); + cl_assert(!git_fs_path_exists("merge-resolve/.git/" GIT_MERGE_MODE_FILE)); + cl_assert(!git_fs_path_exists("merge-resolve/.git/" GIT_MERGE_MSG_FILE)); git_reference_free(octo1_ref); @@ -1061,7 +1061,7 @@ void test_merge_workdir_setup__unlocked_after_success(void) cl_git_pass(git_merge( repo, (const git_annotated_commit **)&their_heads[0], 1, NULL, NULL)); - cl_assert(!git_path_exists("merge-resolve/.git/index.lock")); + cl_assert(!git_fs_path_exists("merge-resolve/.git/index.lock")); git_reference_free(octo1_ref); @@ -1087,7 +1087,7 @@ void test_merge_workdir_setup__unlocked_after_conflict(void) cl_git_fail(git_merge( repo, (const git_annotated_commit **)&their_heads[0], 1, NULL, NULL)); - cl_assert(!git_path_exists("merge-resolve/.git/index.lock")); + cl_assert(!git_fs_path_exists("merge-resolve/.git/index.lock")); git_reference_free(octo1_ref); diff --git a/tests/merge/workdir/simple.c b/tests/merge/workdir/simple.c index 6c4cf7e3c..f51ff09a7 100644 --- a/tests/merge/workdir/simple.c +++ b/tests/merge/workdir/simple.c @@ -504,7 +504,7 @@ void test_merge_workdir_simple__checkout_ours(void) cl_assert(merge_test_index(repo_index, merge_index_entries, 8)); cl_assert(merge_test_reuc(repo_index, merge_reuc_entries, 3)); - cl_assert(git_path_exists(TEST_REPO_PATH "/conflicting.txt")); + cl_assert(git_fs_path_exists(TEST_REPO_PATH "/conflicting.txt")); } void test_merge_workdir_simple__favor_ours(void) diff --git a/tests/object/blob/write.c b/tests/object/blob/write.c index 802467498..422258d63 100644 --- a/tests/object/blob/write.c +++ b/tests/object/blob/write.c @@ -42,7 +42,7 @@ void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_absolut repo = cl_git_sandbox_init(WORKDIR); cl_must_pass(p_mkdir(ELSEWHERE, 0777)); - cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL)); + cl_must_pass(git_fs_path_prettify_dir(&full_path, ELSEWHERE, NULL)); cl_must_pass(git_str_puts(&full_path, "test.txt")); assert_blob_creation(ELSEWHERE "/test.txt", git_str_cstr(&full_path), &git_blob_create_from_disk); @@ -58,7 +58,7 @@ void test_object_blob_write__can_create_a_blob_in_a_bare_repo_from_a_absolute_fi repo = cl_git_sandbox_init(BARE_REPO); cl_must_pass(p_mkdir(ELSEWHERE, 0777)); - cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL)); + cl_must_pass(git_fs_path_prettify_dir(&full_path, ELSEWHERE, NULL)); cl_must_pass(git_str_puts(&full_path, "test.txt")); assert_blob_creation(ELSEWHERE "/test.txt", git_str_cstr(&full_path), &git_blob_create_from_disk); diff --git a/tests/object/raw/write.c b/tests/object/raw/write.c index 9bc127680..40e05f357 100644 --- a/tests/object/raw/write.c +++ b/tests/object/raw/write.c @@ -39,8 +39,8 @@ static void streaming_write(git_oid *oid, git_odb *odb, git_rawobj *raw) static void check_object_files(object_data *d) { - cl_assert(git_path_exists(d->dir)); - cl_assert(git_path_exists(d->file)); + cl_assert(git_fs_path_exists(d->dir)); + cl_assert(git_fs_path_exists(d->file)); } static void cmp_objects(git_rawobj *o1, git_rawobj *o2) diff --git a/tests/odb/alternates.c b/tests/odb/alternates.c index e36010b75..6c00fda2f 100644 --- a/tests/odb/alternates.c +++ b/tests/odb/alternates.c @@ -26,7 +26,7 @@ static void init_linked_repo(const char *path, const char *alternate) git_str_clear(&filepath); cl_git_pass(git_repository_init(&repo, path, 1)); - cl_git_pass(git_path_prettify(&destpath, alternate, NULL)); + cl_git_pass(git_fs_path_prettify(&destpath, alternate, NULL)); cl_git_pass(git_str_joinpath(&destpath, destpath.ptr, "objects")); cl_git_pass(git_str_joinpath(&filepath, git_repository_path(repo), "objects/info")); cl_git_pass(git_futils_mkdir(filepath.ptr, 0755, GIT_MKDIR_PATH)); diff --git a/tests/odb/emptyobjects.c b/tests/odb/emptyobjects.c index 89b22ad4a..e3ec62d3f 100644 --- a/tests/odb/emptyobjects.c +++ b/tests/odb/emptyobjects.c @@ -28,7 +28,7 @@ void test_odb_emptyobjects__blob_notfound(void) cl_git_fail_with(GIT_ENOTFOUND, git_blob_lookup(&blob, g_repo, &id)); cl_git_pass(git_odb_write(&written_id, g_odb, "", 0, GIT_OBJECT_BLOB)); - cl_assert(git_path_exists(TEST_REPO_PATH "/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391")); + cl_assert(git_fs_path_exists(TEST_REPO_PATH "/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391")); } void test_odb_emptyobjects__read_tree(void) diff --git a/tests/online/clone.c b/tests/online/clone.c index c55cf9f95..ba88dff9c 100644 --- a/tests/online/clone.c +++ b/tests/online/clone.c @@ -194,7 +194,7 @@ void test_online_clone__can_checkout_a_cloned_repo(void) cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options)); cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "master.txt")); - cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&path))); + cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&path))); cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD")); cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head)); @@ -930,11 +930,11 @@ void test_online_clone__proxy_cred_callback_after_failed_url_creds(void) void test_online_clone__azurerepos(void) { cl_git_pass(git_clone(&g_repo, "https://libgit2@dev.azure.com/libgit2/test/_git/test", "./foo", &g_options)); - cl_assert(git_path_exists("./foo/master.txt")); + cl_assert(git_fs_path_exists("./foo/master.txt")); } void test_online_clone__path_whitespace(void) { cl_git_pass(git_clone(&g_repo, "https://libgit2@dev.azure.com/libgit2/test/_git/spaces%20in%20the%20name", "./foo", &g_options)); - cl_assert(git_path_exists("./foo/master.txt")); + cl_assert(git_fs_path_exists("./foo/master.txt")); } diff --git a/tests/online/customcert.c b/tests/online/customcert.c index 098212b14..7932a9e68 100644 --- a/tests/online/customcert.c +++ b/tests/online/customcert.c @@ -66,7 +66,7 @@ void test_online_customcert__file(void) { #if (GIT_OPENSSL || GIT_MBEDTLS) cl_git_pass(git_clone(&g_repo, CUSTOM_CERT_ONE_URL, "./cloned", NULL)); - cl_assert(git_path_exists("./cloned/master.txt")); + cl_assert(git_fs_path_exists("./cloned/master.txt")); #endif } @@ -74,6 +74,6 @@ void test_online_customcert__path(void) { #if (GIT_OPENSSL || GIT_MBEDTLS) cl_git_pass(git_clone(&g_repo, CUSTOM_CERT_TWO_URL, "./cloned", NULL)); - cl_assert(git_path_exists("./cloned/master.txt")); + cl_assert(git_fs_path_exists("./cloned/master.txt")); #endif } diff --git a/tests/pack/indexer.c b/tests/pack/indexer.c index 5958bc4ba..954bee953 100644 --- a/tests/pack/indexer.c +++ b/tests/pack/indexer.c @@ -289,7 +289,7 @@ static int find_tmp_file_recurs(void *opaque, git_str *path) return error; if (S_ISDIR(st.st_mode)) - return git_path_direach(path, 0, find_tmp_file_recurs, opaque); + return git_fs_path_direach(path, 0, find_tmp_file_recurs, opaque); /* This is the template that's used in git_futils_mktmp. */ if (strstr(git_str_cstr(path), "_git2_") != NULL) diff --git a/tests/pack/packbuilder.c b/tests/pack/packbuilder.c index b4c655c5e..5b1f7b9e9 100644 --- a/tests/pack/packbuilder.c +++ b/tests/pack/packbuilder.c @@ -156,8 +156,8 @@ void test_pack_packbuilder__write_default_path(void) seed_packbuilder(); cl_git_pass(git_packbuilder_write(_packbuilder, NULL, 0, NULL, NULL)); - cl_assert(git_path_exists("objects/pack/pack-7f5fa362c664d68ba7221259be1cbd187434b2f0.idx")); - cl_assert(git_path_exists("objects/pack/pack-7f5fa362c664d68ba7221259be1cbd187434b2f0.pack")); + cl_assert(git_fs_path_exists("objects/pack/pack-7f5fa362c664d68ba7221259be1cbd187434b2f0.idx")); + cl_assert(git_fs_path_exists("objects/pack/pack-7f5fa362c664d68ba7221259be1cbd187434b2f0.pack")); } static void test_write_pack_permission(mode_t given, mode_t expected) diff --git a/tests/path/core.c b/tests/path/core.c index 1d6066933..8576b471e 100644 --- a/tests/path/core.c +++ b/tests/path/core.c @@ -1,5 +1,5 @@ #include "clar_libgit2.h" -#include "path.h" +#include "fs_path.h" void test_path_core__cleanup(void) { @@ -14,7 +14,7 @@ static void test_make_relative( { git_str buf = GIT_STR_INIT; git_str_puts(&buf, path); - cl_assert_equal_i(expected_status, git_path_make_relative(&buf, parent)); + cl_assert_equal_i(expected_status, git_fs_path_make_relative(&buf, parent)); cl_assert_equal_s(expected_path, buf.ptr); git_str_dispose(&buf); } @@ -59,284 +59,208 @@ void test_path_core__make_relative(void) void test_path_core__isvalid_standard(void) { - cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar/file.txt", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar/.file", 0, 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo/bar", 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo/bar/file.txt", 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo/bar/.file", 0)); } void test_path_core__isvalid_empty_dir_component(void) { - cl_assert_equal_b(false, git_path_validate(NULL, "foo//bar", 0, 0)); + cl_assert_equal_b(false, git_fs_path_validate("foo//bar", 0)); /* leading slash */ - cl_assert_equal_b(false, git_path_validate(NULL, "/", 0, 0)); - cl_assert_equal_b(false, git_path_validate(NULL, "/foo", 0, 0)); - cl_assert_equal_b(false, git_path_validate(NULL, "/foo/bar", 0, 0)); + cl_assert_equal_b(false, git_fs_path_validate("/", 0)); + cl_assert_equal_b(false, git_fs_path_validate("/foo", 0)); + cl_assert_equal_b(false, git_fs_path_validate("/foo/bar", 0)); /* trailing slash */ - cl_assert_equal_b(false, git_path_validate(NULL, "foo/", 0, 0)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar/", 0, 0)); + cl_assert_equal_b(false, git_fs_path_validate("foo/", 0)); + cl_assert_equal_b(false, git_fs_path_validate("foo/bar/", 0)); } void test_path_core__isvalid_dot_and_dotdot(void) { - cl_assert_equal_b(true, git_path_validate(NULL, ".", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "./foo", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/.", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "./foo", 0, 0)); - - cl_assert_equal_b(true, git_path_validate(NULL, "..", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "../foo", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/..", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "../foo", 0, 0)); - - cl_assert_equal_b(false, git_path_validate(NULL, ".", 0, GIT_PATH_REJECT_TRAVERSAL)); - cl_assert_equal_b(false, git_path_validate(NULL, "./foo", 0, GIT_PATH_REJECT_TRAVERSAL)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/.", 0, GIT_PATH_REJECT_TRAVERSAL)); - cl_assert_equal_b(false, git_path_validate(NULL, "./foo", 0, GIT_PATH_REJECT_TRAVERSAL)); - - cl_assert_equal_b(false, git_path_validate(NULL, "..", 0, GIT_PATH_REJECT_TRAVERSAL)); - cl_assert_equal_b(false, git_path_validate(NULL, "../foo", 0, GIT_PATH_REJECT_TRAVERSAL)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/..", 0, GIT_PATH_REJECT_TRAVERSAL)); - cl_assert_equal_b(false, git_path_validate(NULL, "../foo", 0, GIT_PATH_REJECT_TRAVERSAL)); -} - -void test_path_core__isvalid_dot_git(void) -{ - cl_assert_equal_b(true, git_path_validate(NULL, ".git", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, ".git/foo", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/.git", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/.git/bar", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/.GIT/bar", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar/.Git", 0, 0)); - - cl_assert_equal_b(false, git_path_validate(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - cl_assert_equal_b(false, git_path_validate(NULL, ".git/foo", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/.git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/.git/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/.GIT/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar/.Git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - - cl_assert_equal_b(true, git_path_validate(NULL, "!git", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/!git", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "!git/bar", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, ".tig", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/.tig", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, ".tig/bar", 0, 0)); + cl_assert_equal_b(true, git_fs_path_validate(".", 0)); + cl_assert_equal_b(true, git_fs_path_validate("./foo", 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo/.", 0)); + cl_assert_equal_b(true, git_fs_path_validate("./foo", 0)); + + cl_assert_equal_b(true, git_fs_path_validate("..", 0)); + cl_assert_equal_b(true, git_fs_path_validate("../foo", 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo/..", 0)); + cl_assert_equal_b(true, git_fs_path_validate("../foo", 0)); + + cl_assert_equal_b(false, git_fs_path_validate(".", GIT_FS_PATH_REJECT_TRAVERSAL)); + cl_assert_equal_b(false, git_fs_path_validate("./foo", GIT_FS_PATH_REJECT_TRAVERSAL)); + cl_assert_equal_b(false, git_fs_path_validate("foo/.", GIT_FS_PATH_REJECT_TRAVERSAL)); + cl_assert_equal_b(false, git_fs_path_validate("./foo", GIT_FS_PATH_REJECT_TRAVERSAL)); + + cl_assert_equal_b(false, git_fs_path_validate("..", GIT_FS_PATH_REJECT_TRAVERSAL)); + cl_assert_equal_b(false, git_fs_path_validate("../foo", GIT_FS_PATH_REJECT_TRAVERSAL)); + cl_assert_equal_b(false, git_fs_path_validate("foo/..", GIT_FS_PATH_REJECT_TRAVERSAL)); + cl_assert_equal_b(false, git_fs_path_validate("../foo", GIT_FS_PATH_REJECT_TRAVERSAL)); } void test_path_core__isvalid_backslash(void) { - cl_assert_equal_b(true, git_path_validate(NULL, "foo\\file.txt", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar\\file.txt", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar\\", 0, 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo\\file.txt", 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo/bar\\file.txt", 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo/bar\\", 0)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo\\file.txt", 0, GIT_PATH_REJECT_BACKSLASH)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar\\file.txt", 0, GIT_PATH_REJECT_BACKSLASH)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar\\", 0, GIT_PATH_REJECT_BACKSLASH)); + cl_assert_equal_b(false, git_fs_path_validate("foo\\file.txt", GIT_FS_PATH_REJECT_BACKSLASH)); + cl_assert_equal_b(false, git_fs_path_validate("foo/bar\\file.txt", GIT_FS_PATH_REJECT_BACKSLASH)); + cl_assert_equal_b(false, git_fs_path_validate("foo/bar\\", GIT_FS_PATH_REJECT_BACKSLASH)); } void test_path_core__isvalid_trailing_dot(void) { - cl_assert_equal_b(true, git_path_validate(NULL, "foo.", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo...", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar.", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo./bar", 0, 0)); - - cl_assert_equal_b(false, git_path_validate(NULL, "foo.", 0, GIT_PATH_REJECT_TRAILING_DOT)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo...", 0, GIT_PATH_REJECT_TRAILING_DOT)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar.", 0, GIT_PATH_REJECT_TRAILING_DOT)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo./bar", 0, GIT_PATH_REJECT_TRAILING_DOT)); + cl_assert_equal_b(true, git_fs_path_validate("foo.", 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo...", 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo/bar.", 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo./bar", 0)); + + cl_assert_equal_b(false, git_fs_path_validate("foo.", GIT_FS_PATH_REJECT_TRAILING_DOT)); + cl_assert_equal_b(false, git_fs_path_validate("foo...", GIT_FS_PATH_REJECT_TRAILING_DOT)); + cl_assert_equal_b(false, git_fs_path_validate("foo/bar.", GIT_FS_PATH_REJECT_TRAILING_DOT)); + cl_assert_equal_b(false, git_fs_path_validate("foo./bar", GIT_FS_PATH_REJECT_TRAILING_DOT)); } void test_path_core__isvalid_trailing_space(void) { - cl_assert_equal_b(true, git_path_validate(NULL, "foo ", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo ", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar ", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, " ", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo /bar", 0, 0)); - - cl_assert_equal_b(false, git_path_validate(NULL, "foo ", 0, GIT_PATH_REJECT_TRAILING_SPACE)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo ", 0, GIT_PATH_REJECT_TRAILING_SPACE)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar ", 0, GIT_PATH_REJECT_TRAILING_SPACE)); - cl_assert_equal_b(false, git_path_validate(NULL, " ", 0, GIT_PATH_REJECT_TRAILING_SPACE)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo /bar", 0, GIT_PATH_REJECT_TRAILING_SPACE)); + cl_assert_equal_b(true, git_fs_path_validate("foo ", 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo ", 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo/bar ", 0)); + cl_assert_equal_b(true, git_fs_path_validate(" ", 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo /bar", 0)); + + cl_assert_equal_b(false, git_fs_path_validate("foo ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); + cl_assert_equal_b(false, git_fs_path_validate("foo ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); + cl_assert_equal_b(false, git_fs_path_validate("foo/bar ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); + cl_assert_equal_b(false, git_fs_path_validate(" ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); + cl_assert_equal_b(false, git_fs_path_validate("foo /bar", GIT_FS_PATH_REJECT_TRAILING_SPACE)); } void test_path_core__isvalid_trailing_colon(void) { - cl_assert_equal_b(true, git_path_validate(NULL, "foo:", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar:", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, ":", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo:/bar", 0, 0)); - - cl_assert_equal_b(false, git_path_validate(NULL, "foo:", 0, GIT_PATH_REJECT_TRAILING_COLON)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar:", 0, GIT_PATH_REJECT_TRAILING_COLON)); - cl_assert_equal_b(false, git_path_validate(NULL, ":", 0, GIT_PATH_REJECT_TRAILING_COLON)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo:/bar", 0, GIT_PATH_REJECT_TRAILING_COLON)); -} - -void test_path_core__isvalid_dotgit_ntfs(void) -{ - cl_assert_equal_b(true, git_path_validate(NULL, ".git", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, ".git ", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, ".git.", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, ".git.. .", 0, 0)); - - cl_assert_equal_b(true, git_path_validate(NULL, "git~1", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "git~1 ", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "git~1.", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "git~1.. .", 0, 0)); - - cl_assert_equal_b(false, git_path_validate(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".git ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".git.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".git.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - - cl_assert_equal_b(false, git_path_validate(NULL, "git~1", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_validate(NULL, "git~1 ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_validate(NULL, "git~1.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_validate(NULL, "git~1.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(true, git_fs_path_validate("foo:", 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo/bar:", 0)); + cl_assert_equal_b(true, git_fs_path_validate(":", 0)); + cl_assert_equal_b(true, git_fs_path_validate("foo:/bar", 0)); + + cl_assert_equal_b(false, git_fs_path_validate("foo:", GIT_FS_PATH_REJECT_TRAILING_COLON)); + cl_assert_equal_b(false, git_fs_path_validate("foo/bar:", GIT_FS_PATH_REJECT_TRAILING_COLON)); + cl_assert_equal_b(false, git_fs_path_validate(":", GIT_FS_PATH_REJECT_TRAILING_COLON)); + cl_assert_equal_b(false, git_fs_path_validate("foo:/bar", GIT_FS_PATH_REJECT_TRAILING_COLON)); } void test_path_core__isvalid_dos_paths(void) { - cl_assert_equal_b(true, git_path_validate(NULL, "aux", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "aux.", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "aux:", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "aux.asdf", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "aux.asdf\\zippy", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "aux:asdf\\foobar", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "con", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "prn", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "nul", 0, 0)); - - cl_assert_equal_b(false, git_path_validate(NULL, "aux", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_path_validate(NULL, "aux.", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_path_validate(NULL, "aux:", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_path_validate(NULL, "aux.asdf", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_path_validate(NULL, "aux.asdf\\zippy", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_path_validate(NULL, "aux:asdf\\foobar", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_path_validate(NULL, "con", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_path_validate(NULL, "prn", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_path_validate(NULL, "nul", 0, GIT_PATH_REJECT_DOS_PATHS)); - - cl_assert_equal_b(true, git_path_validate(NULL, "aux1", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "aux1", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_path_validate(NULL, "auxn", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_path_validate(NULL, "aux\\foo", 0, GIT_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_validate("aux", 0)); + cl_assert_equal_b(true, git_fs_path_validate("aux.", 0)); + cl_assert_equal_b(true, git_fs_path_validate("aux:", 0)); + cl_assert_equal_b(true, git_fs_path_validate("aux.asdf", 0)); + cl_assert_equal_b(true, git_fs_path_validate("aux.asdf\\zippy", 0)); + cl_assert_equal_b(true, git_fs_path_validate("aux:asdf\\foobar", 0)); + cl_assert_equal_b(true, git_fs_path_validate("con", 0)); + cl_assert_equal_b(true, git_fs_path_validate("prn", 0)); + cl_assert_equal_b(true, git_fs_path_validate("nul", 0)); + + cl_assert_equal_b(false, git_fs_path_validate("aux", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_validate("aux.", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_validate("aux:", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_validate("aux.asdf", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_validate("aux.asdf\\zippy", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_validate("aux:asdf\\foobar", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_validate("con", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_validate("prn", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_validate("nul", GIT_FS_PATH_REJECT_DOS_PATHS)); + + cl_assert_equal_b(true, git_fs_path_validate("aux1", 0)); + cl_assert_equal_b(true, git_fs_path_validate("aux1", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_validate("auxn", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_validate("aux\\foo", GIT_FS_PATH_REJECT_DOS_PATHS)); } void test_path_core__isvalid_dos_paths_withnum(void) { - cl_assert_equal_b(true, git_path_validate(NULL, "com1", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "com1.", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "com1:", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "com1.asdf", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "com1.asdf\\zippy", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "com1:asdf\\foobar", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "com1\\foo", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "lpt1", 0, 0)); - - cl_assert_equal_b(false, git_path_validate(NULL, "com1", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_path_validate(NULL, "com1.", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_path_validate(NULL, "com1:", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_path_validate(NULL, "com1.asdf", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_path_validate(NULL, "com1.asdf\\zippy", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_path_validate(NULL, "com1:asdf\\foobar", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_path_validate(NULL, "com1/foo", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_path_validate(NULL, "lpt1", 0, GIT_PATH_REJECT_DOS_PATHS)); - - cl_assert_equal_b(true, git_path_validate(NULL, "com0", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "com0", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_path_validate(NULL, "com10", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "com10", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_path_validate(NULL, "comn", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_path_validate(NULL, "com1\\foo", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_path_validate(NULL, "lpt0", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_path_validate(NULL, "lpt10", 0, GIT_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_path_validate(NULL, "lptn", 0, GIT_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_validate("com1", 0)); + cl_assert_equal_b(true, git_fs_path_validate("com1.", 0)); + cl_assert_equal_b(true, git_fs_path_validate("com1:", 0)); + cl_assert_equal_b(true, git_fs_path_validate("com1.asdf", 0)); + cl_assert_equal_b(true, git_fs_path_validate("com1.asdf\\zippy", 0)); + cl_assert_equal_b(true, git_fs_path_validate("com1:asdf\\foobar", 0)); + cl_assert_equal_b(true, git_fs_path_validate("com1\\foo", 0)); + cl_assert_equal_b(true, git_fs_path_validate("lpt1", 0)); + + cl_assert_equal_b(false, git_fs_path_validate("com1", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_validate("com1.", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_validate("com1:", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_validate("com1.asdf", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_validate("com1.asdf\\zippy", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_validate("com1:asdf\\foobar", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_validate("com1/foo", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_validate("lpt1", GIT_FS_PATH_REJECT_DOS_PATHS)); + + cl_assert_equal_b(true, git_fs_path_validate("com0", 0)); + cl_assert_equal_b(true, git_fs_path_validate("com0", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_validate("com10", 0)); + cl_assert_equal_b(true, git_fs_path_validate("com10", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_validate("comn", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_validate("com1\\foo", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_validate("lpt0", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_validate("lpt10", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_validate("lptn", GIT_FS_PATH_REJECT_DOS_PATHS)); } void test_path_core__isvalid_nt_chars(void) { - cl_assert_equal_b(true, git_path_validate(NULL, "asdf\001foo", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "asdf\037bar", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "asdffoo", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "asdf:foo", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "asdf\"bar", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "asdf|foo", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "asdf?bar", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "asdf*bar", 0, 0)); - - cl_assert_equal_b(false, git_path_validate(NULL, "asdf\001foo", 0, GIT_PATH_REJECT_NT_CHARS)); - cl_assert_equal_b(false, git_path_validate(NULL, "asdf\037bar", 0, GIT_PATH_REJECT_NT_CHARS)); - cl_assert_equal_b(false, git_path_validate(NULL, "asdffoo", 0, GIT_PATH_REJECT_NT_CHARS)); - cl_assert_equal_b(false, git_path_validate(NULL, "asdf:foo", 0, GIT_PATH_REJECT_NT_CHARS)); - cl_assert_equal_b(false, git_path_validate(NULL, "asdf\"bar", 0, GIT_PATH_REJECT_NT_CHARS)); - cl_assert_equal_b(false, git_path_validate(NULL, "asdf|foo", 0, GIT_PATH_REJECT_NT_CHARS)); - cl_assert_equal_b(false, git_path_validate(NULL, "asdf?bar", 0, GIT_PATH_REJECT_NT_CHARS)); - cl_assert_equal_b(false, git_path_validate(NULL, "asdf*bar", 0, GIT_PATH_REJECT_NT_CHARS)); -} - -void test_path_core__isvalid_dotgit_with_hfs_ignorables(void) -{ - cl_assert_equal_b(false, git_path_validate(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".gi\xe2\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".g\xe2\x80\x8eIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".\xe2\x80\x8fgIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x80\xaa.gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - - cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x80\xab.\xe2\x80\xacG\xe2\x80\xadI\xe2\x80\xaet", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x81\xab.\xe2\x80\xaaG\xe2\x81\xabI\xe2\x80\xact", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x81\xad.\xe2\x80\xaeG\xef\xbb\xbfIT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - - cl_assert_equal_b(true, git_path_validate(NULL, ".", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".g", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, " .git", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, "..git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".gi\xe2\x80\x8dT.", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".g\xe2\x80It", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".\xe2gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, "\xe2\x80\xaa.gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".gi\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".gi\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".g\xe2i\x80T\x8e", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".git\xe2\x80\xbf", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".git\xe2\xab\x81", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_fs_path_validate("asdf\001foo", 0)); + cl_assert_equal_b(true, git_fs_path_validate("asdf\037bar", 0)); + cl_assert_equal_b(true, git_fs_path_validate("asdffoo", 0)); + cl_assert_equal_b(true, git_fs_path_validate("asdf:foo", 0)); + cl_assert_equal_b(true, git_fs_path_validate("asdf\"bar", 0)); + cl_assert_equal_b(true, git_fs_path_validate("asdf|foo", 0)); + cl_assert_equal_b(true, git_fs_path_validate("asdf?bar", 0)); + cl_assert_equal_b(true, git_fs_path_validate("asdf*bar", 0)); + + cl_assert_equal_b(false, git_fs_path_validate("asdf\001foo", GIT_FS_PATH_REJECT_NT_CHARS)); + cl_assert_equal_b(false, git_fs_path_validate("asdf\037bar", GIT_FS_PATH_REJECT_NT_CHARS)); + cl_assert_equal_b(false, git_fs_path_validate("asdffoo", GIT_FS_PATH_REJECT_NT_CHARS)); + cl_assert_equal_b(false, git_fs_path_validate("asdf:foo", GIT_FS_PATH_REJECT_NT_CHARS)); + cl_assert_equal_b(false, git_fs_path_validate("asdf\"bar", GIT_FS_PATH_REJECT_NT_CHARS)); + cl_assert_equal_b(false, git_fs_path_validate("asdf|foo", GIT_FS_PATH_REJECT_NT_CHARS)); + cl_assert_equal_b(false, git_fs_path_validate("asdf?bar", GIT_FS_PATH_REJECT_NT_CHARS)); + cl_assert_equal_b(false, git_fs_path_validate("asdf*bar", GIT_FS_PATH_REJECT_NT_CHARS)); } void test_path_core__validate_workdir(void) { - cl_must_pass(git_path_validate_workdir(NULL, "/foo/bar")); - cl_must_pass(git_path_validate_workdir(NULL, "C:\\Foo\\Bar")); - cl_must_pass(git_path_validate_workdir(NULL, "\\\\?\\C:\\Foo\\Bar")); - cl_must_pass(git_path_validate_workdir(NULL, "\\\\?\\C:\\Foo\\Bar")); - cl_must_pass(git_path_validate_workdir(NULL, "\\\\?\\UNC\\server\\C$\\folder")); + cl_must_pass(git_fs_path_validate_workdir(NULL, "/foo/bar")); + cl_must_pass(git_fs_path_validate_workdir(NULL, "C:\\Foo\\Bar")); + cl_must_pass(git_fs_path_validate_workdir(NULL, "\\\\?\\C:\\Foo\\Bar")); + cl_must_pass(git_fs_path_validate_workdir(NULL, "\\\\?\\C:\\Foo\\Bar")); + cl_must_pass(git_fs_path_validate_workdir(NULL, "\\\\?\\UNC\\server\\C$\\folder")); #ifdef GIT_WIN32 /* * In the absense of a repo configuration, 259 character paths * succeed. >= 260 character paths fail. */ - cl_must_pass(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\ok.txt")); - cl_must_pass(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\260.txt")); - cl_must_fail(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\longer_than_260.txt")); + cl_must_pass(git_fs_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\ok.txt")); + cl_must_pass(git_fs_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\260.txt")); + cl_must_fail(git_fs_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\longer_than_260.txt")); /* count characters, not bytes */ - cl_must_pass(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt")); - cl_must_fail(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt")); + cl_must_pass(git_fs_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt")); + cl_must_fail(git_fs_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt")); #else - cl_must_pass(git_path_validate_workdir(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/ok.txt")); - cl_must_pass(git_path_validate_workdir(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/260.txt")); - cl_must_pass(git_path_validate_workdir(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); - cl_must_pass(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt")); - cl_must_pass(git_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt")); + cl_must_pass(git_fs_path_validate_workdir(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/ok.txt")); + cl_must_pass(git_fs_path_validate_workdir(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/260.txt")); + cl_must_pass(git_fs_path_validate_workdir(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); + cl_must_pass(git_fs_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt")); + cl_must_pass(git_fs_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt")); #endif } @@ -352,15 +276,15 @@ void test_path_core__validate_workdir_with_core_longpath(void) cl_git_pass(git_repository_config(&config, repo)); /* fail by default */ - cl_must_fail(git_path_validate_workdir(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); + cl_must_fail(git_fs_path_validate_workdir(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); /* set core.longpaths explicitly on */ cl_git_pass(git_config_set_bool(config, "core.longpaths", 1)); - cl_must_pass(git_path_validate_workdir(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); + cl_must_pass(git_fs_path_validate_workdir(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); /* set core.longpaths explicitly off */ cl_git_pass(git_config_set_bool(config, "core.longpaths", 0)); - cl_must_fail(git_path_validate_workdir(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); + cl_must_fail(git_fs_path_validate_workdir(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); git_config_free(config); git_repository_free(repo); @@ -376,7 +300,7 @@ static void test_join_unrooted( git_str result = GIT_STR_INIT; ssize_t root_at; - cl_git_pass(git_path_join_unrooted(&result, path, base, &root_at)); + cl_git_pass(git_fs_path_join_unrooted(&result, path, base, &root_at)); cl_assert_equal_s(expected_result, result.ptr); cl_assert_equal_i(expected_rootlen, root_at); diff --git a/tests/path/dotgit.c b/tests/path/dotgit.c index 2f9fcae4f..5b3a31137 100644 --- a/tests/path/dotgit.c +++ b/tests/path/dotgit.c @@ -1,4 +1,5 @@ #include "clar_libgit2.h" + #include "path.h" static char *gitmodules_altnames[] = { @@ -118,3 +119,88 @@ void test_path_dotgit__dotgit_modules_symlink(void) cl_assert_equal_b(false, git_path_validate(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS)); cl_assert_equal_b(false, git_path_validate(NULL, ".gitmodules . .::$DATA", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS)); } + +void test_core_path__git_fs_path_is_file(void) +{ + cl_git_fail(git_path_is_gitfile("blob", 4, -1, GIT_PATH_FS_HFS)); + cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITIGNORE, GIT_PATH_FS_HFS)); + cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS)); + cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITATTRIBUTES, GIT_PATH_FS_HFS)); + cl_git_fail(git_path_is_gitfile("blob", 4, 3, GIT_PATH_FS_HFS)); +} + +void test_path_dotgit__isvalid_dot_git(void) +{ + cl_assert_equal_b(true, git_path_validate(NULL, ".git", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, ".git/foo", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, "foo/.git", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, "foo/.git/bar", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, "foo/.GIT/bar", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar/.Git", 0, 0)); + + cl_assert_equal_b(false, git_path_validate(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); + cl_assert_equal_b(false, git_path_validate(NULL, ".git/foo", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); + cl_assert_equal_b(false, git_path_validate(NULL, "foo/.git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); + cl_assert_equal_b(false, git_path_validate(NULL, "foo/.git/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); + cl_assert_equal_b(false, git_path_validate(NULL, "foo/.GIT/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); + cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar/.Git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); + + cl_assert_equal_b(true, git_path_validate(NULL, "!git", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, "foo/!git", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, "!git/bar", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, ".tig", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, "foo/.tig", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, ".tig/bar", 0, 0)); +} + +void test_path_dotgit__isvalid_dotgit_ntfs(void) +{ + cl_assert_equal_b(true, git_path_validate(NULL, ".git", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, ".git ", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, ".git.", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, ".git.. .", 0, 0)); + + cl_assert_equal_b(true, git_path_validate(NULL, "git~1", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, "git~1 ", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, "git~1.", 0, 0)); + cl_assert_equal_b(true, git_path_validate(NULL, "git~1.. .", 0, 0)); + + cl_assert_equal_b(false, git_path_validate(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(false, git_path_validate(NULL, ".git ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(false, git_path_validate(NULL, ".git.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(false, git_path_validate(NULL, ".git.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + + cl_assert_equal_b(false, git_path_validate(NULL, "git~1", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(false, git_path_validate(NULL, "git~1 ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(false, git_path_validate(NULL, "git~1.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(false, git_path_validate(NULL, "git~1.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); +} + +void test_path_dotgit__isvalid_dotgit_with_hfs_ignorables(void) +{ + cl_assert_equal_b(false, git_path_validate(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_validate(NULL, ".git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_validate(NULL, ".gi\xe2\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_validate(NULL, ".g\xe2\x80\x8eIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_validate(NULL, ".\xe2\x80\x8fgIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x80\xaa.gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + + cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x80\xab.\xe2\x80\xacG\xe2\x80\xadI\xe2\x80\xaet", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x81\xab.\xe2\x80\xaaG\xe2\x81\xabI\xe2\x80\xact", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x81\xad.\xe2\x80\xaeG\xef\xbb\xbfIT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + + cl_assert_equal_b(true, git_path_validate(NULL, ".", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_validate(NULL, ".g", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_validate(NULL, ".gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_validate(NULL, " .git", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_validate(NULL, "..git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_validate(NULL, ".gi\xe2\x80\x8dT.", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_validate(NULL, ".g\xe2\x80It", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_validate(NULL, ".\xe2gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_validate(NULL, "\xe2\x80\xaa.gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_validate(NULL, ".gi\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_validate(NULL, ".gi\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_validate(NULL, ".g\xe2i\x80T\x8e", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_validate(NULL, ".git\xe2\x80\xbf", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_validate(NULL, ".git\xe2\xab\x81", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); +} diff --git a/tests/refs/branches/create.c b/tests/refs/branches/create.c index 7a49ad548..2fb11668b 100644 --- a/tests/refs/branches/create.c +++ b/tests/refs/branches/create.c @@ -145,7 +145,7 @@ void test_refs_branches_create__can_create_branch_with_unicode(void) const char *expected[] = { nfc, nfd, emoji }; unsigned int i; bool fs_decompose_unicode = - git_path_does_fs_decompose_unicode(git_repository_path(repo)); + git_fs_path_does_decompose_unicode(git_repository_path(repo)); retrieve_known_commit(&target, repo); diff --git a/tests/refs/branches/delete.c b/tests/refs/branches/delete.c index aad5c090f..077882b22 100644 --- a/tests/refs/branches/delete.c +++ b/tests/refs/branches/delete.c @@ -173,13 +173,13 @@ void test_refs_branches_delete__removes_empty_folders(void) cl_git_pass(git_str_joinpath(&ref_folder, commondir, "refs/heads/some/deep")); cl_git_pass(git_str_join3(&reflog_folder, '/', commondir, GIT_REFLOG_DIR, "refs/heads/some/deep")); - cl_assert(git_path_exists(git_str_cstr(&ref_folder)) == true); - cl_assert(git_path_exists(git_str_cstr(&reflog_folder)) == true); + cl_assert(git_fs_path_exists(git_str_cstr(&ref_folder)) == true); + cl_assert(git_fs_path_exists(git_str_cstr(&reflog_folder)) == true); cl_git_pass(git_branch_delete(branch)); - cl_assert(git_path_exists(git_str_cstr(&ref_folder)) == false); - cl_assert(git_path_exists(git_str_cstr(&reflog_folder)) == false); + cl_assert(git_fs_path_exists(git_str_cstr(&ref_folder)) == false); + cl_assert(git_fs_path_exists(git_str_cstr(&reflog_folder)) == false); git_reference_free(branch); git_str_dispose(&ref_folder); diff --git a/tests/refs/delete.c b/tests/refs/delete.c index c76d126eb..42cc534b5 100644 --- a/tests/refs/delete.c +++ b/tests/refs/delete.c @@ -33,7 +33,7 @@ void test_refs_delete__packed_loose(void) /* Ensure the loose reference exists on the file system */ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name)); - cl_assert(git_path_exists(temp_path.ptr)); + cl_assert(git_fs_path_exists(temp_path.ptr)); /* Lookup the reference */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_test_head_name)); @@ -49,7 +49,7 @@ void test_refs_delete__packed_loose(void) cl_git_fail(git_reference_lookup(&another_looked_up_ref, g_repo, packed_test_head_name)); /* Ensure the loose reference doesn't exist any longer on the file system */ - cl_assert(!git_path_exists(temp_path.ptr)); + cl_assert(!git_fs_path_exists(temp_path.ptr)); git_reference_free(another_looked_up_ref); git_str_dispose(&temp_path); diff --git a/tests/refs/pack.c b/tests/refs/pack.c index 125b1adb0..1c1cd51cb 100644 --- a/tests/refs/pack.c +++ b/tests/refs/pack.c @@ -63,7 +63,7 @@ void test_refs_pack__loose(void) /* Ensure the packed-refs file exists */ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), GIT_PACKEDREFS_FILE)); - cl_assert(git_path_exists(temp_path.ptr)); + cl_assert(git_fs_path_exists(temp_path.ptr)); /* Ensure the known ref can still be looked up but is now packed */ cl_git_pass(git_reference_lookup(&reference, g_repo, loose_tag_ref_name)); @@ -72,7 +72,7 @@ void test_refs_pack__loose(void) /* Ensure the known ref has been removed from the loose folder structure */ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), loose_tag_ref_name)); - cl_assert(!git_path_exists(temp_path.ptr)); + cl_assert(!git_fs_path_exists(temp_path.ptr)); git_reference_free(reference); git_str_dispose(&temp_path); diff --git a/tests/refs/ref_helpers.c b/tests/refs/ref_helpers.c index e55364c6e..943d0f551 100644 --- a/tests/refs/ref_helpers.c +++ b/tests/refs/ref_helpers.c @@ -16,7 +16,7 @@ int reference_is_packed(git_reference *ref) git_reference_name(ref)) < 0) return -1; - packed = !git_path_isfile(ref_path.ptr); + packed = !git_fs_path_isfile(ref_path.ptr); git_str_dispose(&ref_path); diff --git a/tests/refs/reflog/reflog.c b/tests/refs/reflog/reflog.c index 5bb6138df..32ce7ffb7 100644 --- a/tests/refs/reflog/reflog.c +++ b/tests/refs/reflog/reflog.c @@ -107,15 +107,15 @@ void test_refs_reflog_reflog__renaming_the_reference_moves_the_reflog(void) git_str_joinpath(&master_log_path, git_str_cstr(&master_log_path), "refs/heads/master"); git_str_joinpath(&moved_log_path, git_str_cstr(&moved_log_path), "refs/moved"); - cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&master_log_path))); - cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&moved_log_path))); + cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&master_log_path))); + cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&moved_log_path))); cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master")); cl_git_pass(git_reference_rename(&new_master, master, "refs/moved", 0, NULL)); git_reference_free(master); - cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&master_log_path))); - cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&moved_log_path))); + cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&master_log_path))); + cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&moved_log_path))); git_reference_free(new_master); git_str_dispose(&moved_log_path); @@ -130,13 +130,13 @@ void test_refs_reflog_reflog__deleting_the_reference_deletes_the_reflog(void) git_str_joinpath(&master_log_path, git_repository_path(g_repo), GIT_REFLOG_DIR); git_str_joinpath(&master_log_path, git_str_cstr(&master_log_path), "refs/heads/master"); - cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&master_log_path))); + cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&master_log_path))); cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master")); cl_git_pass(git_reference_delete(master)); git_reference_free(master); - cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&master_log_path))); + cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&master_log_path))); git_str_dispose(&master_log_path); } @@ -153,7 +153,7 @@ void test_refs_reflog_reflog__removes_empty_reflog_dir(void) git_str_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR); git_str_joinpath(&log_path, git_str_cstr(&log_path), "refs/heads/new-dir/new-head"); - cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&log_path))); + cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&log_path))); cl_git_pass(git_reference_delete(ref)); git_reference_free(ref); @@ -180,7 +180,7 @@ void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void) git_str_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR); git_str_joinpath(&log_path, git_str_cstr(&log_path), "refs/heads/new-dir/new-head"); - cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&log_path))); + cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&log_path))); /* delete the ref manually, leave the reflog */ cl_must_pass(p_unlink("testrepo.git/refs/heads/new-dir/new-head")); @@ -212,7 +212,7 @@ void test_refs_reflog_reflog__reading_the_reflog_from_a_reference_with_no_log_re git_str subtrees_log_path = GIT_STR_INIT; git_str_join_n(&subtrees_log_path, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, refname); - cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&subtrees_log_path))); + cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&subtrees_log_path))); cl_git_pass(git_reflog_read(&reflog, g_repo, refname)); diff --git a/tests/refs/rename.c b/tests/refs/rename.c index fa732234a..f71e65782 100644 --- a/tests/refs/rename.c +++ b/tests/refs/rename.c @@ -41,7 +41,7 @@ void test_refs_rename__loose(void) /* Ensure the ref doesn't exist on the file system */ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), new_name)); - cl_assert(!git_path_exists(temp_path.ptr)); + cl_assert(!git_fs_path_exists(temp_path.ptr)); /* Retrieval of the reference to rename */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, loose_tag_ref_name)); @@ -67,7 +67,7 @@ void test_refs_rename__loose(void) /* ...and the ref can be found in the file system */ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), new_name)); - cl_assert(git_path_exists(temp_path.ptr)); + cl_assert(git_fs_path_exists(temp_path.ptr)); git_reference_free(new_ref); git_reference_free(another_looked_up_ref); @@ -83,7 +83,7 @@ void test_refs_rename__packed(void) /* Ensure the ref doesn't exist on the file system */ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_head_name)); - cl_assert(!git_path_exists(temp_path.ptr)); + cl_assert(!git_fs_path_exists(temp_path.ptr)); /* The reference can however be looked-up... */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_head_name)); @@ -109,7 +109,7 @@ void test_refs_rename__packed(void) /* ...and the ref now happily lives in the file system */ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), brand_new_name)); - cl_assert(git_path_exists(temp_path.ptr)); + cl_assert(git_fs_path_exists(temp_path.ptr)); git_reference_free(new_ref); git_reference_free(another_looked_up_ref); @@ -125,7 +125,7 @@ void test_refs_rename__packed_doesnt_pack_others(void) /* Ensure the other reference exists on the file system */ cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name)); - cl_assert(git_path_exists(temp_path.ptr)); + cl_assert(git_fs_path_exists(temp_path.ptr)); /* Lookup the other reference */ cl_git_pass(git_reference_lookup(&another_looked_up_ref, g_repo, packed_test_head_name)); @@ -151,7 +151,7 @@ void test_refs_rename__packed_doesnt_pack_others(void) cl_assert(reference_is_packed(another_looked_up_ref) == 0); /* Ensure the other ref still exists on the file system */ - cl_assert(git_path_exists(temp_path.ptr)); + cl_assert(git_fs_path_exists(temp_path.ptr)); git_reference_free(renamed_ref); git_reference_free(another_looked_up_ref); diff --git a/tests/refs/revparse.c b/tests/refs/revparse.c index 9c960702a..d02249754 100644 --- a/tests/refs/revparse.c +++ b/tests/refs/revparse.c @@ -329,13 +329,13 @@ static void create_fake_stash_reference_and_reflog(git_repository *repo) git_str_joinpath(&log_path, git_repository_path(repo), "logs/refs/fakestash"); - cl_assert_equal_i(false, git_path_isfile(git_str_cstr(&log_path))); + cl_assert_equal_i(false, git_fs_path_isfile(git_str_cstr(&log_path))); cl_git_pass(git_reference_lookup(&master, repo, "refs/heads/master")); cl_git_pass(git_reference_rename(&new_master, master, "refs/fakestash", 0, NULL)); git_reference_free(master); - cl_assert_equal_i(true, git_path_isfile(git_str_cstr(&log_path))); + cl_assert_equal_i(true, git_fs_path_isfile(git_str_cstr(&log_path))); git_str_dispose(&log_path); git_reference_free(new_master); diff --git a/tests/repo/config.c b/tests/repo/config.c index 0b9daac98..ee7e43dff 100644 --- a/tests/repo/config.c +++ b/tests/repo/config.c @@ -14,7 +14,7 @@ void test_repo_config__initialize(void) git_str_clear(&path); cl_must_pass(p_mkdir("alternate", 0777)); - cl_git_pass(git_path_prettify(&path, "alternate", NULL)); + cl_git_pass(git_fs_path_prettify(&path, "alternate", NULL)); } void test_repo_config__cleanup(void) @@ -25,7 +25,7 @@ void test_repo_config__cleanup(void) cl_git_pass( git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES)); - cl_assert(!git_path_isdir("alternate")); + cl_assert(!git_fs_path_isdir("alternate")); cl_fixture_cleanup("empty_standard_repo"); @@ -101,7 +101,7 @@ void test_repo_config__read_with_no_configs_at_all(void) /* with none */ cl_must_pass(p_unlink("empty_standard_repo/.git/config")); - cl_assert(!git_path_isfile("empty_standard_repo/.git/config")); + cl_assert(!git_fs_path_isfile("empty_standard_repo/.git/config")); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__configmap_lookup_cache_clear(repo); @@ -177,16 +177,16 @@ void test_repo_config__read_with_no_configs_at_all(void) cl_assert_equal_i(40, val); cl_must_pass(p_unlink("empty_standard_repo/.git/config")); - cl_assert(!git_path_isfile("empty_standard_repo/.git/config")); + cl_assert(!git_fs_path_isfile("empty_standard_repo/.git/config")); cl_must_pass(p_unlink("alternate/1/gitconfig")); - cl_assert(!git_path_isfile("alternate/1/gitconfig")); + cl_assert(!git_fs_path_isfile("alternate/1/gitconfig")); cl_must_pass(p_unlink("alternate/2/config")); - cl_assert(!git_path_isfile("alternate/2/config")); + cl_assert(!git_fs_path_isfile("alternate/2/config")); cl_must_pass(p_unlink("alternate/3/.gitconfig")); - cl_assert(!git_path_isfile("alternate/3/.gitconfig")); + cl_assert(!git_fs_path_isfile("alternate/3/.gitconfig")); git_repository__configmap_lookup_cache_clear(repo); val = -1; @@ -196,8 +196,8 @@ void test_repo_config__read_with_no_configs_at_all(void) /* reopen */ - cl_assert(!git_path_isfile("empty_standard_repo/.git/config")); - cl_assert(!git_path_isfile("alternate/3/.gitconfig")); + cl_assert(!git_fs_path_isfile("empty_standard_repo/.git/config")); + cl_assert(!git_fs_path_isfile("alternate/3/.gitconfig")); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); git_repository__configmap_lookup_cache_clear(repo); @@ -206,6 +206,6 @@ void test_repo_config__read_with_no_configs_at_all(void) cl_assert_equal_i(7, val); git_repository_free(repo); - cl_assert(!git_path_exists("empty_standard_repo/.git/config")); - cl_assert(!git_path_exists("alternate/3/.gitconfig")); + cl_assert(!git_fs_path_exists("empty_standard_repo/.git/config")); + cl_assert(!git_fs_path_exists("alternate/3/.gitconfig")); } diff --git a/tests/repo/discover.c b/tests/repo/discover.c index 2a24f1b29..523fdf8e3 100644 --- a/tests/repo/discover.c +++ b/tests/repo/discover.c @@ -33,7 +33,7 @@ static void ensure_repository_discover(const char *start_path, git_str_attach(&resolved, p_realpath(expected_path, NULL), 0); cl_assert(resolved.size > 0); - cl_git_pass(git_path_to_dir(&resolved)); + cl_git_pass(git_fs_path_to_dir(&resolved)); cl_git_pass(git_repository_discover(&found_path, start_path, 1, ceiling_dirs)); cl_assert_equal_s(found_path.ptr, resolved.ptr); @@ -47,7 +47,7 @@ static void write_file(const char *path, const char *content) git_file file; int error; - if (git_path_exists(path)) { + if (git_fs_path_exists(path)) { cl_git_pass(p_unlink(path)); } @@ -65,7 +65,7 @@ static void append_ceiling_dir(git_str *ceiling_dirs, const char *path) git_str pretty_path = GIT_STR_INIT; char ceiling_separator[2] = { GIT_PATH_LIST_SEPARATOR, '\0' }; - cl_git_pass(git_path_prettify_dir(&pretty_path, path, NULL)); + cl_git_pass(git_fs_path_prettify_dir(&pretty_path, path, NULL)); if (ceiling_dirs->size > 0) git_str_puts(ceiling_dirs, ceiling_separator); diff --git a/tests/repo/env.c b/tests/repo/env.c index 4bd45d1a6..e3e522480 100644 --- a/tests/repo/env.c +++ b/tests/repo/env.c @@ -24,11 +24,11 @@ void test_repo_env__cleanup(void) { cl_git_sandbox_cleanup(); - if (git_path_isdir("attr")) + if (git_fs_path_isdir("attr")) git_futils_rmdir_r("attr", NULL, GIT_RMDIR_REMOVE_FILES); - if (git_path_isdir("testrepo.git")) + if (git_fs_path_isdir("testrepo.git")) git_futils_rmdir_r("testrepo.git", NULL, GIT_RMDIR_REMOVE_FILES); - if (git_path_isdir("peeled.git")) + if (git_fs_path_isdir("peeled.git")) git_futils_rmdir_r("peeled.git", NULL, GIT_RMDIR_REMOVE_FILES); clear_git_env(); @@ -81,7 +81,7 @@ static void env_cd_( const char *file, const char *func, int line) { git_str cwd_buf = GIT_STR_INIT; - cl_git_pass(git_path_prettify_dir(&cwd_buf, ".", NULL)); + cl_git_pass(git_fs_path_prettify_dir(&cwd_buf, ".", NULL)); cl_must_pass(p_chdir(path)); passfail_(NULL, file, func, line); cl_must_pass(p_chdir(git_str_cstr(&cwd_buf))); @@ -141,7 +141,7 @@ void test_repo_env__open(void) cl_fixture_sandbox("peeled.git"); cl_git_pass(p_rename("attr/.gitted", "attr/.git")); - cl_git_pass(git_path_prettify_dir(&repo_dir_buf, "attr", NULL)); + cl_git_pass(git_fs_path_prettify_dir(&repo_dir_buf, "attr", NULL)); repo_dir = git_str_cstr(&repo_dir_buf); /* GIT_DIR that doesn't exist */ diff --git a/tests/repo/init.c b/tests/repo/init.c index b41608cca..7cf6742ca 100644 --- a/tests/repo/init.c +++ b/tests/repo/init.c @@ -47,7 +47,7 @@ static void ensure_repository_init( { const char *workdir; - cl_assert(!git_path_isdir(working_directory)); + cl_assert(!git_fs_path_isdir(working_directory)); cl_git_pass(git_repository_init(&g_repo, working_directory, is_bare)); @@ -103,7 +103,7 @@ void test_repo_init__bare_repo_escaping_current_workdir(void) git_str path_repository = GIT_STR_INIT; git_str path_current_workdir = GIT_STR_INIT; - cl_git_pass(git_path_prettify_dir(&path_current_workdir, ".", NULL)); + cl_git_pass(git_fs_path_prettify_dir(&path_current_workdir, ".", NULL)); cl_git_pass(git_str_joinpath(&path_repository, git_str_cstr(&path_current_workdir), "a/b/c")); cl_git_pass(git_futils_mkdir_r(git_str_cstr(&path_repository), GIT_DIR_MODE)); @@ -176,15 +176,15 @@ void test_repo_init__additional_templates(void) cl_git_pass( git_str_joinpath(&path, git_repository_path(g_repo), "description")); - cl_assert(git_path_isfile(git_str_cstr(&path))); + cl_assert(git_fs_path_isfile(git_str_cstr(&path))); cl_git_pass( git_str_joinpath(&path, git_repository_path(g_repo), "info/exclude")); - cl_assert(git_path_isfile(git_str_cstr(&path))); + cl_assert(git_fs_path_isfile(git_str_cstr(&path))); cl_git_pass( git_str_joinpath(&path, git_repository_path(g_repo), "hooks")); - cl_assert(git_path_isdir(git_str_cstr(&path))); + cl_assert(git_fs_path_isdir(git_str_cstr(&path))); /* won't confirm specific contents of hooks dir since it may vary */ git_str_dispose(&path); @@ -257,7 +257,7 @@ void test_repo_init__symlinks_win32_enabled_by_global_config(void) git_config *config, *repo_config; int val; - if (!git_path_supports_symlinks("link")) + if (!git_fs_path_supports_symlinks("link")) cl_skip(); create_tmp_global_config("tmp_global_config", "core.symlinks", "true"); @@ -303,7 +303,7 @@ void test_repo_init__symlinks_posix_detected(void) cl_skip(); #else assert_config_entry_on_init( - "core.symlinks", git_path_supports_symlinks("link") ? GIT_ENOTFOUND : false); + "core.symlinks", git_fs_path_supports_symlinks("link") ? GIT_ENOTFOUND : false); #endif } @@ -418,12 +418,12 @@ void test_repo_init__extended_1(void) cl_assert(!git__suffixcmp(git_repository_workdir(g_repo), "/c_wd/")); cl_assert(!git__suffixcmp(git_repository_path(g_repo), "/c.git/")); - cl_assert(git_path_isfile("root/b/c_wd/.git")); + cl_assert(git_fs_path_isfile("root/b/c_wd/.git")); cl_assert(!git_repository_is_bare(g_repo)); /* repo will not be counted as empty because we set head to "development" */ cl_assert(!git_repository_is_empty(g_repo)); - cl_git_pass(git_path_lstat(git_repository_path(g_repo), &st)); + cl_git_pass(git_fs_path_lstat(git_repository_path(g_repo), &st)); cl_assert(S_ISDIR(st.st_mode)); if (cl_is_chmod_supported()) cl_assert((S_ISGID & st.st_mode) == S_ISGID); @@ -482,7 +482,7 @@ void test_repo_init__relative_gitdir_2(void) git_str dot_git_content = GIT_STR_INIT; git_str full_path = GIT_STR_INIT; - cl_git_pass(git_path_prettify(&full_path, ".", NULL)); + cl_git_pass(git_fs_path_prettify(&full_path, ".", NULL)); cl_git_pass(git_str_joinpath(&full_path, full_path.ptr, "root/b/c_wd")); opts.workdir_path = full_path.ptr; @@ -604,16 +604,16 @@ void test_repo_init__at_filesystem_root(void) if (!cl_is_env_set("GITTEST_INVASIVE_FS_STRUCTURE")) cl_skip(); - root_len = git_path_root(sandbox); + root_len = git_fs_path_root(sandbox); cl_assert(root_len >= 0); git_str_put(&root, sandbox, root_len+1); git_str_joinpath(&root, root.ptr, "libgit2_test_dir"); - cl_assert(!git_path_exists(root.ptr)); + cl_assert(!git_fs_path_exists(root.ptr)); cl_git_pass(git_repository_init(&repo, root.ptr, 0)); - cl_assert(git_path_isdir(root.ptr)); + cl_assert(git_fs_path_isdir(root.ptr)); cl_git_pass(git_futils_rmdir_r(root.ptr, NULL, GIT_RMDIR_REMOVE_FILES)); git_str_dispose(&root); diff --git a/tests/repo/open.c b/tests/repo/open.c index 6558805c8..f7ed2c373 100644 --- a/tests/repo/open.c +++ b/tests/repo/open.c @@ -8,7 +8,7 @@ void test_repo_open__cleanup(void) { cl_git_sandbox_cleanup(); - if (git_path_isdir("alternate")) + if (git_fs_path_isdir("alternate")) git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES); } @@ -147,7 +147,7 @@ void test_repo_open__with_symlinked_config(void) cl_git_pass(git_futils_mkdir_r("home", 0777)); cl_git_mkfile("home/.gitconfig.linked", "[global]\ntest = 4567\n"); cl_must_pass(symlink(".gitconfig.linked", "home/.gitconfig")); - cl_git_pass(git_path_prettify(&path, "home", NULL)); + cl_git_pass(git_fs_path_prettify(&path, "home", NULL)); cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); @@ -191,7 +191,7 @@ void test_repo_open__from_git_new_workdir(void) for (scan = links; *scan != NULL; scan++) { git_str_joinpath(&link_tgt, "empty_standard_repo/.git", *scan); - if (git_path_exists(link_tgt.ptr)) { + if (git_fs_path_exists(link_tgt.ptr)) { git_str_joinpath(&link_tgt, "../../empty_standard_repo/.git", *scan); git_str_joinpath(&link, "alternate/.git", *scan); if (strchr(*scan, '/')) @@ -201,7 +201,7 @@ void test_repo_open__from_git_new_workdir(void) } for (scan = copies; *scan != NULL; scan++) { git_str_joinpath(&link_tgt, "empty_standard_repo/.git", *scan); - if (git_path_exists(link_tgt.ptr)) { + if (git_fs_path_exists(link_tgt.ptr)) { git_str_joinpath(&link, "alternate/.git", *scan); cl_git_pass(git_futils_readbuffer(&body, link_tgt.ptr)); @@ -381,7 +381,7 @@ void test_repo_open__no_config(void) /* isolate from system level configs */ cl_must_pass(p_mkdir("alternate", 0777)); - cl_git_pass(git_path_prettify(&path, "alternate", NULL)); + cl_git_pass(git_fs_path_prettify(&path, "alternate", NULL)); cl_git_pass(git_libgit2_opts( GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); cl_git_pass(git_libgit2_opts( diff --git a/tests/repo/setters.c b/tests/repo/setters.c index 2c33db0db..9a965dec6 100644 --- a/tests/repo/setters.c +++ b/tests/repo/setters.c @@ -50,7 +50,7 @@ void test_repo_setters__setting_a_workdir_creates_a_gitlink(void) cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", true)); - cl_assert(git_path_isfile("./new_workdir/.git")); + cl_assert(git_fs_path_isfile("./new_workdir/.git")); cl_git_pass(git_futils_readbuffer(&content, "./new_workdir/.git")); cl_assert(git__prefixcmp(git_str_cstr(&content), "gitdir: ") == 0); diff --git a/tests/repo/template.c b/tests/repo/template.c index 6f369c6d6..b0af96e36 100644 --- a/tests/repo/template.c +++ b/tests/repo/template.c @@ -56,10 +56,10 @@ static void assert_hooks_match( struct stat expected_st, st; cl_git_pass(git_str_joinpath(&expected, template_dir, hook_path)); - cl_git_pass(git_path_lstat(expected.ptr, &expected_st)); + cl_git_pass(git_fs_path_lstat(expected.ptr, &expected_st)); cl_git_pass(git_str_joinpath(&actual, repo_dir, hook_path)); - cl_git_pass(git_path_lstat(actual.ptr, &st)); + cl_git_pass(git_fs_path_lstat(actual.ptr, &st)); cl_assert(expected_st.st_size == st.st_size); @@ -88,7 +88,7 @@ static void assert_mode_seems_okay( struct stat st; cl_git_pass(git_str_joinpath(&full, base, path)); - cl_git_pass(git_path_lstat(full.ptr, &st)); + cl_git_pass(git_fs_path_lstat(full.ptr, &st)); git_str_dispose(&full); if (!core_filemode) { diff --git a/tests/reset/hard.c b/tests/reset/hard.c index 36e8f1470..9d177c021 100644 --- a/tests/reset/hard.c +++ b/tests/reset/hard.c @@ -79,7 +79,7 @@ void test_reset_hard__resetting_reverts_modified_files(void) cl_git_pass(git_futils_readbuffer(&content, path.ptr)); cl_assert(strequal_ignore_eol(after[i], content.ptr)); } else { - cl_assert(!git_path_exists(path.ptr)); + cl_assert(!git_fs_path_exists(path.ptr)); } } @@ -154,7 +154,7 @@ void test_reset_hard__resetting_reverts_unmerged(void) cl_git_pass(git_revparse_single(&target, repo, "26a125e")); cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL)); - cl_assert(git_path_exists("status/conflicting_file") == 0); + cl_assert(git_fs_path_exists("status/conflicting_file") == 0); git_object_free(target); target = NULL; @@ -185,11 +185,11 @@ void test_reset_hard__cleans_up_merge(void) cl_git_pass(git_revparse_single(&target, repo, "0017bd4")); cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL)); - cl_assert(!git_path_exists(git_str_cstr(&merge_head_path))); - cl_assert(!git_path_exists(git_str_cstr(&merge_msg_path))); - cl_assert(!git_path_exists(git_str_cstr(&merge_mode_path))); + cl_assert(!git_fs_path_exists(git_str_cstr(&merge_head_path))); + cl_assert(!git_fs_path_exists(git_str_cstr(&merge_msg_path))); + cl_assert(!git_fs_path_exists(git_str_cstr(&merge_mode_path))); - cl_assert(git_path_exists(git_str_cstr(&orig_head_path))); + cl_assert(git_fs_path_exists(git_str_cstr(&orig_head_path))); cl_git_pass(p_unlink(git_str_cstr(&orig_head_path))); git_str_dispose(&merge_head_path); diff --git a/tests/revert/workdir.c b/tests/revert/workdir.c index 36824044b..0c9810814 100644 --- a/tests/revert/workdir.c +++ b/tests/revert/workdir.c @@ -111,7 +111,7 @@ void test_revert_workdir__conflicts(void) "File one\n" \ ">>>>>>> parent of 72333f4... automergeable changes\n") == 0); - cl_assert(git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); + cl_assert(git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); cl_git_pass(git_futils_readbuffer(&mergemsg_buf, TEST_REPO_PATH "/.git/MERGE_MSG")); cl_assert(strcmp(mergemsg_buf.ptr, @@ -498,8 +498,8 @@ void test_revert_workdir__nonmerge_fails_mainline_specified(void) opts.mainline = 1; cl_must_fail(git_revert(repo, commit, &opts)); - cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); - cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/REVERT_HEAD")); + cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); + cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/REVERT_HEAD")); git_reference_free(head); git_commit_free(commit); @@ -517,8 +517,8 @@ void test_revert_workdir__merge_fails_without_mainline_specified(void) cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); cl_must_fail(git_revert(repo, head, NULL)); - cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); - cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/REVERT_HEAD")); + cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG")); + cl_assert(!git_fs_path_exists(TEST_REPO_PATH "/.git/REVERT_HEAD")); git_commit_free(head); } diff --git a/tests/stash/drop.c b/tests/stash/drop.c index 6b0895ba8..709ff0f9e 100644 --- a/tests/stash/drop.c +++ b/tests/stash/drop.c @@ -37,26 +37,26 @@ static void push_three_states(void) cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_index_add_bypath(index, "zero.txt")); cl_repo_commit_from_index(NULL, repo, signature, 0, "Initial commit"); - cl_assert(git_path_exists("stash/zero.txt")); + cl_assert(git_fs_path_exists("stash/zero.txt")); git_index_free(index); cl_git_mkfile("stash/one.txt", "content\n"); cl_git_pass(git_stash_save( &oid, repo, signature, "First", GIT_STASH_INCLUDE_UNTRACKED)); - cl_assert(!git_path_exists("stash/one.txt")); - cl_assert(git_path_exists("stash/zero.txt")); + cl_assert(!git_fs_path_exists("stash/one.txt")); + cl_assert(git_fs_path_exists("stash/zero.txt")); cl_git_mkfile("stash/two.txt", "content\n"); cl_git_pass(git_stash_save( &oid, repo, signature, "Second", GIT_STASH_INCLUDE_UNTRACKED)); - cl_assert(!git_path_exists("stash/two.txt")); - cl_assert(git_path_exists("stash/zero.txt")); + cl_assert(!git_fs_path_exists("stash/two.txt")); + cl_assert(git_fs_path_exists("stash/zero.txt")); cl_git_mkfile("stash/three.txt", "content\n"); cl_git_pass(git_stash_save( &oid, repo, signature, "Third", GIT_STASH_INCLUDE_UNTRACKED)); - cl_assert(!git_path_exists("stash/three.txt")); - cl_assert(git_path_exists("stash/zero.txt")); + cl_assert(!git_fs_path_exists("stash/three.txt")); + cl_assert(git_fs_path_exists("stash/zero.txt")); } void test_stash_drop__cannot_drop_a_non_existing_stashed_state(void) diff --git a/tests/stash/save.c b/tests/stash/save.c index 1fbcf0957..f574211d7 100644 --- a/tests/stash/save.c +++ b/tests/stash/save.c @@ -161,16 +161,16 @@ void test_stash_save__untracked_skips_ignored(void) cl_must_pass(p_mkdir("stash/bundle/vendor", 0777)); cl_git_mkfile("stash/bundle/vendor/blah", "contents\n"); - cl_assert(git_path_exists("stash/when")); /* untracked */ - cl_assert(git_path_exists("stash/just.ignore")); /* ignored */ - cl_assert(git_path_exists("stash/bundle/vendor/blah")); /* ignored */ + cl_assert(git_fs_path_exists("stash/when")); /* untracked */ + cl_assert(git_fs_path_exists("stash/just.ignore")); /* ignored */ + cl_assert(git_fs_path_exists("stash/bundle/vendor/blah")); /* ignored */ cl_git_pass(git_stash_save( &stash_tip_oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED)); - cl_assert(!git_path_exists("stash/when")); - cl_assert(git_path_exists("stash/bundle/vendor/blah")); - cl_assert(git_path_exists("stash/just.ignore")); + cl_assert(!git_fs_path_exists("stash/when")); + cl_assert(git_fs_path_exists("stash/bundle/vendor/blah")); + cl_assert(git_fs_path_exists("stash/just.ignore")); } void test_stash_save__can_include_untracked_and_ignored_files(void) @@ -185,7 +185,7 @@ void test_stash_save__can_include_untracked_and_ignored_files(void) assert_blob_oid("refs/stash^3:when", "b6ed15e81e2593d7bb6265eb4a991d29dc3e628b"); assert_blob_oid("refs/stash^3:just.ignore", "78925fb1236b98b37a35e9723033e627f97aa88b"); - cl_assert(!git_path_exists("stash/just.ignore")); + cl_assert(!git_fs_path_exists("stash/just.ignore")); } /* @@ -450,9 +450,9 @@ void test_stash_save__ignored_directory(void) cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED | GIT_STASH_INCLUDE_IGNORED)); - cl_assert(!git_path_exists("stash/ignored_directory/sub/some_file")); - cl_assert(!git_path_exists("stash/ignored_directory/sub")); - cl_assert(!git_path_exists("stash/ignored_directory")); + cl_assert(!git_fs_path_exists("stash/ignored_directory/sub/some_file")); + cl_assert(!git_fs_path_exists("stash/ignored_directory/sub")); + cl_assert(!git_fs_path_exists("stash/ignored_directory")); } void test_stash_save__skip_submodules(void) diff --git a/tests/status/submodules.c b/tests/status/submodules.c index 38a39471a..d223657b4 100644 --- a/tests/status/submodules.c +++ b/tests/status/submodules.c @@ -36,9 +36,9 @@ void test_status_submodules__0(void) g_repo = setup_fixture_submodules(); - cl_assert(git_path_isdir("submodules/.git")); - cl_assert(git_path_isdir("submodules/testrepo/.git")); - cl_assert(git_path_isfile("submodules/.gitmodules")); + cl_assert(git_fs_path_isdir("submodules/.git")); + cl_assert(git_fs_path_isdir("submodules/testrepo/.git")); + cl_assert(git_fs_path_isfile("submodules/.gitmodules")); cl_git_pass( git_status_foreach(g_repo, cb_status__count, &counts) @@ -89,9 +89,9 @@ void test_status_submodules__1(void) g_repo = setup_fixture_submodules(); - cl_assert(git_path_isdir("submodules/.git")); - cl_assert(git_path_isdir("submodules/testrepo/.git")); - cl_assert(git_path_isfile("submodules/.gitmodules")); + cl_assert(git_fs_path_isdir("submodules/.git")); + cl_assert(git_fs_path_isdir("submodules/testrepo/.git")); + cl_assert(git_fs_path_isfile("submodules/.gitmodules")); status_counts_init(counts, expected_files, expected_status); diff --git a/tests/status/worktree.c b/tests/status/worktree.c index 4ab04094a..692ea93ef 100644 --- a/tests/status/worktree.c +++ b/tests/status/worktree.c @@ -109,7 +109,7 @@ static int remove_file_cb(void *data, git_str *file) if (git__suffixcmp(filename, ".git") == 0) return 0; - if (git_path_isdir(filename)) + if (git_fs_path_isdir(filename)) cl_git_pass(git_futils_rmdir_r(filename, NULL, GIT_RMDIR_REMOVE_FILES)); else cl_git_pass(p_unlink(git_str_cstr(file))); @@ -126,7 +126,7 @@ void test_status_worktree__purged_worktree(void) /* first purge the contents of the worktree */ cl_git_pass(git_str_sets(&workdir, git_repository_workdir(repo))); - cl_git_pass(git_path_direach(&workdir, 0, remove_file_cb, NULL)); + cl_git_pass(git_fs_path_direach(&workdir, 0, remove_file_cb, NULL)); git_str_dispose(&workdir); /* now get status */ @@ -374,7 +374,7 @@ void test_status_worktree__issue_592(void) repo = cl_git_sandbox_init("issue_592"); cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "l.txt")); cl_git_pass(p_unlink(git_str_cstr(&path))); - cl_assert(!git_path_exists("issue_592/l.txt")); + cl_assert(!git_fs_path_exists("issue_592/l.txt")); cl_git_pass(git_status_foreach(repo, cb_status__check_592, "l.txt")); @@ -389,7 +389,7 @@ void test_status_worktree__issue_592_2(void) repo = cl_git_sandbox_init("issue_592"); cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "c/a.txt")); cl_git_pass(p_unlink(git_str_cstr(&path))); - cl_assert(!git_path_exists("issue_592/c/a.txt")); + cl_assert(!git_fs_path_exists("issue_592/c/a.txt")); cl_git_pass(git_status_foreach(repo, cb_status__check_592, "c/a.txt")); @@ -405,7 +405,7 @@ void test_status_worktree__issue_592_3(void) cl_git_pass(git_str_joinpath(&path, git_repository_workdir(repo), "c")); cl_git_pass(git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES)); - cl_assert(!git_path_exists("issue_592/c/a.txt")); + cl_assert(!git_fs_path_exists("issue_592/c/a.txt")); cl_git_pass(git_status_foreach(repo, cb_status__check_592, "c/a.txt")); diff --git a/tests/submodule/add.c b/tests/submodule/add.c index b564123dd..ae5507d7f 100644 --- a/tests/submodule/add.c +++ b/tests/submodule/add.c @@ -46,11 +46,11 @@ void test_submodule_add__url_absolute(void) ); git_submodule_free(sm); - cl_assert(git_path_isfile("submod2/" "sm_libgit2" "/.git")); + cl_assert(git_fs_path_isfile("submod2/" "sm_libgit2" "/.git")); - cl_assert(git_path_isdir("submod2/.git/modules")); - cl_assert(git_path_isdir("submod2/.git/modules/" "sm_libgit2")); - cl_assert(git_path_isfile("submod2/.git/modules/" "sm_libgit2" "/HEAD")); + cl_assert(git_fs_path_isdir("submod2/.git/modules")); + cl_assert(git_fs_path_isdir("submod2/.git/modules/" "sm_libgit2")); + cl_assert(git_fs_path_isfile("submod2/.git/modules/" "sm_libgit2" "/HEAD")); assert_submodule_url("sm_libgit2", "https://github.com/libgit2/libgit2.git"); cl_git_pass(git_repository_open(&repo, "submod2/" "sm_libgit2")); @@ -72,9 +72,9 @@ void test_submodule_add__url_absolute(void) ); git_submodule_free(sm); - cl_assert(git_path_isdir("submod2/" "sm_libgit2b" "/.git")); - cl_assert(git_path_isfile("submod2/" "sm_libgit2b" "/.git/HEAD")); - cl_assert(!git_path_exists("submod2/.git/modules/" "sm_libgit2b")); + cl_assert(git_fs_path_isdir("submod2/" "sm_libgit2b" "/.git")); + cl_assert(git_fs_path_isfile("submod2/" "sm_libgit2b" "/.git/HEAD")); + cl_assert(!git_fs_path_exists("submod2/.git/modules/" "sm_libgit2b")); assert_submodule_url("sm_libgit2b", "https://github.com/libgit2/libgit2.git"); } @@ -227,7 +227,7 @@ void test_submodule_add__submodule_clone_into_nonempty_dir_succeeds(void) cl_git_pass(git_submodule_clone(NULL, sm, NULL)); cl_git_pass(git_submodule_add_finalize(sm)); - cl_assert(git_path_exists("empty_standard_repo/sm/foobar")); + cl_assert(git_fs_path_exists("empty_standard_repo/sm/foobar")); assert_submodule_exists(g_repo, "sm"); diff --git a/tests/submodule/init.c b/tests/submodule/init.c index bf865a9e8..a8e1291c4 100644 --- a/tests/submodule/init.c +++ b/tests/submodule/init.c @@ -20,7 +20,7 @@ void test_submodule_init__absolute_url(void) g_repo = setup_fixture_submodule_simple(); - cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0); + cl_assert(git_fs_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0); cl_git_pass(git_str_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git")); /* write the absolute url to the .gitmodules file*/ @@ -53,7 +53,7 @@ void test_submodule_init__relative_url(void) g_repo = setup_fixture_submodule_simple(); - cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0); + cl_assert(git_fs_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0); cl_git_pass(git_str_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git")); cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); @@ -91,7 +91,7 @@ void test_submodule_init__relative_url_detached_head(void) cl_git_pass(git_repository_set_head_detached(g_repo, git_commit_id((git_commit *)head_commit))); - cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0); + cl_assert(git_fs_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0); cl_git_pass(git_str_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git")); cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); diff --git a/tests/submodule/open.c b/tests/submodule/open.c index 4f31feedf..e6883d208 100644 --- a/tests/submodule/open.c +++ b/tests/submodule/open.c @@ -27,9 +27,9 @@ static void assert_sm_valid(git_repository *parent, git_repository *child, const /* assert working directory */ cl_git_pass(git_str_joinpath(&expected, git_repository_workdir(parent), sm_name)); - cl_git_pass(git_path_prettify_dir(&expected, expected.ptr, NULL)); + cl_git_pass(git_fs_path_prettify_dir(&expected, expected.ptr, NULL)); cl_git_pass(git_str_sets(&actual, git_repository_workdir(child))); - cl_git_pass(git_path_prettify_dir(&actual, actual.ptr, NULL)); + cl_git_pass(git_fs_path_prettify_dir(&actual, actual.ptr, NULL)); cl_assert_equal_s(expected.ptr, actual.ptr); git_str_clear(&expected); @@ -38,14 +38,14 @@ static void assert_sm_valid(git_repository *parent, git_repository *child, const /* assert common directory */ cl_git_pass(git_str_joinpath(&expected, git_repository_commondir(parent), "modules")); cl_git_pass(git_str_joinpath(&expected, expected.ptr, sm_name)); - cl_git_pass(git_path_prettify_dir(&expected, expected.ptr, NULL)); + cl_git_pass(git_fs_path_prettify_dir(&expected, expected.ptr, NULL)); cl_git_pass(git_str_sets(&actual, git_repository_commondir(child))); - cl_git_pass(git_path_prettify_dir(&actual, actual.ptr, NULL)); + cl_git_pass(git_fs_path_prettify_dir(&actual, actual.ptr, NULL)); cl_assert_equal_s(expected.ptr, actual.ptr); /* assert git directory */ cl_git_pass(git_str_sets(&actual, git_repository_path(child))); - cl_git_pass(git_path_prettify_dir(&actual, actual.ptr, NULL)); + cl_git_pass(git_fs_path_prettify_dir(&actual, actual.ptr, NULL)); cl_assert_equal_s(expected.ptr, actual.ptr); git_str_dispose(&expected); diff --git a/tests/submodule/repository_init.c b/tests/submodule/repository_init.c index 3927afc2e..39b55c403 100644 --- a/tests/submodule/repository_init.c +++ b/tests/submodule/repository_init.c @@ -26,11 +26,11 @@ void test_submodule_repository_init__basic(void) cl_git_pass(git_futils_readbuffer(&dot_git_content, "submod2/" "sm_gitmodules_only" "/.git")); cl_assert_equal_s("gitdir: ../.git/modules/sm_gitmodules_only/", dot_git_content.ptr); - cl_assert(git_path_isfile("submod2/" "sm_gitmodules_only" "/.git")); + cl_assert(git_fs_path_isfile("submod2/" "sm_gitmodules_only" "/.git")); - cl_assert(git_path_isdir("submod2/.git/modules")); - cl_assert(git_path_isdir("submod2/.git/modules/" "sm_gitmodules_only")); - cl_assert(git_path_isfile("submod2/.git/modules/" "sm_gitmodules_only" "/HEAD")); + cl_assert(git_fs_path_isdir("submod2/.git/modules")); + cl_assert(git_fs_path_isdir("submod2/.git/modules/" "sm_gitmodules_only")); + cl_assert(git_fs_path_isfile("submod2/.git/modules/" "sm_gitmodules_only" "/HEAD")); git_submodule_free(sm); git_repository_free(repo); diff --git a/tests/submodule/submodule_helpers.c b/tests/submodule/submodule_helpers.c index 95d20a009..b8fc9f60d 100644 --- a/tests/submodule/submodule_helpers.c +++ b/tests/submodule/submodule_helpers.c @@ -65,7 +65,7 @@ void rewrite_gitmodules(const char *workdir) continue; } - git_path_prettify(&path, path.ptr, NULL); + git_fs_path_prettify(&path, path.ptr, NULL); git_str_putc(&path, '\n'); cl_assert(!git_str_oom(&path)); diff --git a/tests/worktree/merge.c b/tests/worktree/merge.c index 8bb95d1f7..5b7e2a837 100644 --- a/tests/worktree/merge.c +++ b/tests/worktree/merge.c @@ -73,7 +73,7 @@ void test_worktree_merge__merge_setup(void) cl_git_pass(git_str_joinpath(&path, fixture.worktree->gitdir, merge_files[i])); - cl_assert(git_path_exists(path.ptr)); + cl_assert(git_fs_path_exists(path.ptr)); } git_str_dispose(&path); diff --git a/tests/worktree/refs.c b/tests/worktree/refs.c index 5ae17ca19..557726aaf 100644 --- a/tests/worktree/refs.c +++ b/tests/worktree/refs.c @@ -181,14 +181,14 @@ void test_worktree_refs__creating_refs_uses_commondir(void) cl_git_pass(git_str_joinpath(&refpath, git_repository_commondir(fixture.worktree), "refs/heads/testbranch")); - cl_assert(!git_path_exists(refpath.ptr)); + cl_assert(!git_fs_path_exists(refpath.ptr)); cl_git_pass(git_repository_head(&head, fixture.worktree)); cl_git_pass(git_commit_lookup(&commit, fixture.worktree, git_reference_target(head))); cl_git_pass(git_branch_create(&branch, fixture.worktree, "testbranch", commit, 0)); cl_git_pass(git_branch_lookup(&lookup, fixture.worktree, "testbranch", GIT_BRANCH_LOCAL)); cl_assert(git_reference_cmp(branch, lookup) == 0); - cl_assert(git_path_exists(refpath.ptr)); + cl_assert(git_fs_path_exists(refpath.ptr)); git_reference_free(lookup); git_reference_free(branch); diff --git a/tests/worktree/submodule.c b/tests/worktree/submodule.c index 4c6c657d3..6b0c07452 100644 --- a/tests/worktree/submodule.c +++ b/tests/worktree/submodule.c @@ -67,7 +67,7 @@ void test_worktree_submodule__resolve_relative_url(void) git_worktree *wt; cl_git_pass(git_futils_mkdir("subdir", 0755, GIT_MKDIR_PATH)); - cl_git_pass(git_path_prettify_dir(&wt_path, "subdir", NULL)); + cl_git_pass(git_fs_path_prettify_dir(&wt_path, "subdir", NULL)); cl_git_pass(git_str_joinpath(&wt_path, wt_path.ptr, "wt")); /* Open child repository, which is a submodule */ diff --git a/tests/worktree/worktree.c b/tests/worktree/worktree.c index a9a50fbf1..6f14b17f1 100644 --- a/tests/worktree/worktree.c +++ b/tests/worktree/worktree.c @@ -330,7 +330,7 @@ void test_worktree_worktree__init_existing_path(void) for (i = 0; i < ARRAY_SIZE(wtfiles); i++) { cl_git_pass(git_str_joinpath(&path, fixture.worktree->gitdir, wtfiles[i])); - cl_assert(!git_path_exists(path.ptr)); + cl_assert(!git_fs_path_exists(path.ptr)); } git_str_dispose(&path); @@ -351,9 +351,9 @@ void test_worktree_worktree__init_submodule(void) cl_git_pass(git_worktree_add(&worktree, sm, "repo-worktree", path.ptr, NULL)); cl_git_pass(git_repository_open_from_worktree(&wt, worktree)); - cl_git_pass(git_path_prettify_dir(&path, path.ptr, NULL)); + cl_git_pass(git_fs_path_prettify_dir(&path, path.ptr, NULL)); cl_assert_equal_s(path.ptr, wt->workdir); - cl_git_pass(git_path_prettify_dir(&path, sm->commondir, NULL)); + cl_git_pass(git_fs_path_prettify_dir(&path, sm->commondir, NULL)); cl_assert_equal_s(sm->commondir, wt->commondir); cl_git_pass(git_str_joinpath(&path, sm->gitdir, "worktrees/repo-worktree/")); @@ -560,8 +560,8 @@ void test_worktree_worktree__prune_gitdir_only(void) cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree")); cl_git_pass(git_worktree_prune(wt, &opts)); - cl_assert(!git_path_exists(wt->gitdir_path)); - cl_assert(git_path_exists(wt->gitlink_path)); + cl_assert(!git_fs_path_exists(wt->gitdir_path)); + cl_assert(git_fs_path_exists(wt->gitlink_path)); git_worktree_free(wt); } @@ -576,8 +576,8 @@ void test_worktree_worktree__prune_worktree(void) cl_git_pass(git_worktree_lookup(&wt, fixture.repo, "testrepo-worktree")); cl_git_pass(git_worktree_prune(wt, &opts)); - cl_assert(!git_path_exists(wt->gitdir_path)); - cl_assert(!git_path_exists(wt->gitlink_path)); + cl_assert(!git_fs_path_exists(wt->gitdir_path)); + cl_assert(!git_fs_path_exists(wt->gitlink_path)); git_worktree_free(wt); } -- cgit v1.2.1 From 434a46107bbb1c4d90832c92d4d0f5c89cb82ead Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 1 Nov 2021 09:31:32 -0400 Subject: fs_path: `validate` -> `is_valid` Since we're returning a boolean about validation, the name is more properly "is valid". --- src/fs_path.c | 6 +- src/fs_path.h | 4 +- src/path.c | 2 +- tests/path/core.c | 266 +++++++++++++++++++++++++++--------------------------- 4 files changed, 139 insertions(+), 139 deletions(-) diff --git a/src/fs_path.c b/src/fs_path.c index e180d5866..ceba02d62 100644 --- a/src/fs_path.c +++ b/src/fs_path.c @@ -1634,7 +1634,7 @@ static bool validate_component( return true; } -bool git_fs_path_validate_ext( +bool git_fs_path_is_valid_ext( const char *path, unsigned int flags, bool (*validate_char_cb)(char ch, void *payload), @@ -1673,9 +1673,9 @@ bool git_fs_path_validate_ext( return true; } -bool git_fs_path_validate(const char *path, unsigned int flags) +bool git_fs_path_is_valid(const char *path, unsigned int flags) { - return git_fs_path_validate_ext(path, flags, NULL, NULL, NULL); + return git_fs_path_is_valid_ext(path, flags, NULL, NULL, NULL); } #ifdef GIT_WIN32 diff --git a/src/fs_path.h b/src/fs_path.h index a60a37d98..991e7cd83 100644 --- a/src/fs_path.h +++ b/src/fs_path.h @@ -627,13 +627,13 @@ extern int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url * (trailing ' ' or ':' characters), or filenames ("component names") * that are not supported ('AUX', 'COM1"). */ -extern bool git_fs_path_validate(const char *path, unsigned int flags); +extern bool git_fs_path_is_valid(const char *path, unsigned int flags); /** * Validate a filesystem path; with custom callbacks per-character and * per-path component. */ -extern bool git_fs_path_validate_ext( +extern bool git_fs_path_is_valid_ext( const char *path, unsigned int flags, bool (*validate_char_cb)(char ch, void *payload), diff --git a/src/path.c b/src/path.c index d34125128..063009fa1 100644 --- a/src/path.c +++ b/src/path.c @@ -301,7 +301,7 @@ bool git_path_validate( data.file_mode = file_mode; data.flags = flags; - return git_fs_path_validate_ext(path, flags, NULL, validate_repo_component, &data); + return git_fs_path_is_valid_ext(path, flags, NULL, validate_repo_component, &data); } static const struct { diff --git a/tests/path/core.c b/tests/path/core.c index 8576b471e..f48a76957 100644 --- a/tests/path/core.c +++ b/tests/path/core.c @@ -59,180 +59,180 @@ void test_path_core__make_relative(void) void test_path_core__isvalid_standard(void) { - cl_assert_equal_b(true, git_fs_path_validate("foo/bar", 0)); - cl_assert_equal_b(true, git_fs_path_validate("foo/bar/file.txt", 0)); - cl_assert_equal_b(true, git_fs_path_validate("foo/bar/.file", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar/file.txt", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar/.file", 0)); } void test_path_core__isvalid_empty_dir_component(void) { - cl_assert_equal_b(false, git_fs_path_validate("foo//bar", 0)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo//bar", 0)); /* leading slash */ - cl_assert_equal_b(false, git_fs_path_validate("/", 0)); - cl_assert_equal_b(false, git_fs_path_validate("/foo", 0)); - cl_assert_equal_b(false, git_fs_path_validate("/foo/bar", 0)); + cl_assert_equal_b(false, git_fs_path_is_valid("/", 0)); + cl_assert_equal_b(false, git_fs_path_is_valid("/foo", 0)); + cl_assert_equal_b(false, git_fs_path_is_valid("/foo/bar", 0)); /* trailing slash */ - cl_assert_equal_b(false, git_fs_path_validate("foo/", 0)); - cl_assert_equal_b(false, git_fs_path_validate("foo/bar/", 0)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo/", 0)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar/", 0)); } void test_path_core__isvalid_dot_and_dotdot(void) { - cl_assert_equal_b(true, git_fs_path_validate(".", 0)); - cl_assert_equal_b(true, git_fs_path_validate("./foo", 0)); - cl_assert_equal_b(true, git_fs_path_validate("foo/.", 0)); - cl_assert_equal_b(true, git_fs_path_validate("./foo", 0)); - - cl_assert_equal_b(true, git_fs_path_validate("..", 0)); - cl_assert_equal_b(true, git_fs_path_validate("../foo", 0)); - cl_assert_equal_b(true, git_fs_path_validate("foo/..", 0)); - cl_assert_equal_b(true, git_fs_path_validate("../foo", 0)); - - cl_assert_equal_b(false, git_fs_path_validate(".", GIT_FS_PATH_REJECT_TRAVERSAL)); - cl_assert_equal_b(false, git_fs_path_validate("./foo", GIT_FS_PATH_REJECT_TRAVERSAL)); - cl_assert_equal_b(false, git_fs_path_validate("foo/.", GIT_FS_PATH_REJECT_TRAVERSAL)); - cl_assert_equal_b(false, git_fs_path_validate("./foo", GIT_FS_PATH_REJECT_TRAVERSAL)); - - cl_assert_equal_b(false, git_fs_path_validate("..", GIT_FS_PATH_REJECT_TRAVERSAL)); - cl_assert_equal_b(false, git_fs_path_validate("../foo", GIT_FS_PATH_REJECT_TRAVERSAL)); - cl_assert_equal_b(false, git_fs_path_validate("foo/..", GIT_FS_PATH_REJECT_TRAVERSAL)); - cl_assert_equal_b(false, git_fs_path_validate("../foo", GIT_FS_PATH_REJECT_TRAVERSAL)); + cl_assert_equal_b(true, git_fs_path_is_valid(".", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("./foo", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo/.", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("./foo", 0)); + + cl_assert_equal_b(true, git_fs_path_is_valid("..", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("../foo", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo/..", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("../foo", 0)); + + cl_assert_equal_b(false, git_fs_path_is_valid(".", GIT_FS_PATH_REJECT_TRAVERSAL)); + cl_assert_equal_b(false, git_fs_path_is_valid("./foo", GIT_FS_PATH_REJECT_TRAVERSAL)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo/.", GIT_FS_PATH_REJECT_TRAVERSAL)); + cl_assert_equal_b(false, git_fs_path_is_valid("./foo", GIT_FS_PATH_REJECT_TRAVERSAL)); + + cl_assert_equal_b(false, git_fs_path_is_valid("..", GIT_FS_PATH_REJECT_TRAVERSAL)); + cl_assert_equal_b(false, git_fs_path_is_valid("../foo", GIT_FS_PATH_REJECT_TRAVERSAL)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo/..", GIT_FS_PATH_REJECT_TRAVERSAL)); + cl_assert_equal_b(false, git_fs_path_is_valid("../foo", GIT_FS_PATH_REJECT_TRAVERSAL)); } void test_path_core__isvalid_backslash(void) { - cl_assert_equal_b(true, git_fs_path_validate("foo\\file.txt", 0)); - cl_assert_equal_b(true, git_fs_path_validate("foo/bar\\file.txt", 0)); - cl_assert_equal_b(true, git_fs_path_validate("foo/bar\\", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo\\file.txt", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar\\file.txt", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar\\", 0)); - cl_assert_equal_b(false, git_fs_path_validate("foo\\file.txt", GIT_FS_PATH_REJECT_BACKSLASH)); - cl_assert_equal_b(false, git_fs_path_validate("foo/bar\\file.txt", GIT_FS_PATH_REJECT_BACKSLASH)); - cl_assert_equal_b(false, git_fs_path_validate("foo/bar\\", GIT_FS_PATH_REJECT_BACKSLASH)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo\\file.txt", GIT_FS_PATH_REJECT_BACKSLASH)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar\\file.txt", GIT_FS_PATH_REJECT_BACKSLASH)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar\\", GIT_FS_PATH_REJECT_BACKSLASH)); } void test_path_core__isvalid_trailing_dot(void) { - cl_assert_equal_b(true, git_fs_path_validate("foo.", 0)); - cl_assert_equal_b(true, git_fs_path_validate("foo...", 0)); - cl_assert_equal_b(true, git_fs_path_validate("foo/bar.", 0)); - cl_assert_equal_b(true, git_fs_path_validate("foo./bar", 0)); - - cl_assert_equal_b(false, git_fs_path_validate("foo.", GIT_FS_PATH_REJECT_TRAILING_DOT)); - cl_assert_equal_b(false, git_fs_path_validate("foo...", GIT_FS_PATH_REJECT_TRAILING_DOT)); - cl_assert_equal_b(false, git_fs_path_validate("foo/bar.", GIT_FS_PATH_REJECT_TRAILING_DOT)); - cl_assert_equal_b(false, git_fs_path_validate("foo./bar", GIT_FS_PATH_REJECT_TRAILING_DOT)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo.", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo...", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar.", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo./bar", 0)); + + cl_assert_equal_b(false, git_fs_path_is_valid("foo.", GIT_FS_PATH_REJECT_TRAILING_DOT)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo...", GIT_FS_PATH_REJECT_TRAILING_DOT)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar.", GIT_FS_PATH_REJECT_TRAILING_DOT)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo./bar", GIT_FS_PATH_REJECT_TRAILING_DOT)); } void test_path_core__isvalid_trailing_space(void) { - cl_assert_equal_b(true, git_fs_path_validate("foo ", 0)); - cl_assert_equal_b(true, git_fs_path_validate("foo ", 0)); - cl_assert_equal_b(true, git_fs_path_validate("foo/bar ", 0)); - cl_assert_equal_b(true, git_fs_path_validate(" ", 0)); - cl_assert_equal_b(true, git_fs_path_validate("foo /bar", 0)); - - cl_assert_equal_b(false, git_fs_path_validate("foo ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); - cl_assert_equal_b(false, git_fs_path_validate("foo ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); - cl_assert_equal_b(false, git_fs_path_validate("foo/bar ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); - cl_assert_equal_b(false, git_fs_path_validate(" ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); - cl_assert_equal_b(false, git_fs_path_validate("foo /bar", GIT_FS_PATH_REJECT_TRAILING_SPACE)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo ", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo ", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar ", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid(" ", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo /bar", 0)); + + cl_assert_equal_b(false, git_fs_path_is_valid("foo ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); + cl_assert_equal_b(false, git_fs_path_is_valid(" ", GIT_FS_PATH_REJECT_TRAILING_SPACE)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo /bar", GIT_FS_PATH_REJECT_TRAILING_SPACE)); } void test_path_core__isvalid_trailing_colon(void) { - cl_assert_equal_b(true, git_fs_path_validate("foo:", 0)); - cl_assert_equal_b(true, git_fs_path_validate("foo/bar:", 0)); - cl_assert_equal_b(true, git_fs_path_validate(":", 0)); - cl_assert_equal_b(true, git_fs_path_validate("foo:/bar", 0)); - - cl_assert_equal_b(false, git_fs_path_validate("foo:", GIT_FS_PATH_REJECT_TRAILING_COLON)); - cl_assert_equal_b(false, git_fs_path_validate("foo/bar:", GIT_FS_PATH_REJECT_TRAILING_COLON)); - cl_assert_equal_b(false, git_fs_path_validate(":", GIT_FS_PATH_REJECT_TRAILING_COLON)); - cl_assert_equal_b(false, git_fs_path_validate("foo:/bar", GIT_FS_PATH_REJECT_TRAILING_COLON)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo:", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar:", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid(":", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo:/bar", 0)); + + cl_assert_equal_b(false, git_fs_path_is_valid("foo:", GIT_FS_PATH_REJECT_TRAILING_COLON)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar:", GIT_FS_PATH_REJECT_TRAILING_COLON)); + cl_assert_equal_b(false, git_fs_path_is_valid(":", GIT_FS_PATH_REJECT_TRAILING_COLON)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo:/bar", GIT_FS_PATH_REJECT_TRAILING_COLON)); } void test_path_core__isvalid_dos_paths(void) { - cl_assert_equal_b(true, git_fs_path_validate("aux", 0)); - cl_assert_equal_b(true, git_fs_path_validate("aux.", 0)); - cl_assert_equal_b(true, git_fs_path_validate("aux:", 0)); - cl_assert_equal_b(true, git_fs_path_validate("aux.asdf", 0)); - cl_assert_equal_b(true, git_fs_path_validate("aux.asdf\\zippy", 0)); - cl_assert_equal_b(true, git_fs_path_validate("aux:asdf\\foobar", 0)); - cl_assert_equal_b(true, git_fs_path_validate("con", 0)); - cl_assert_equal_b(true, git_fs_path_validate("prn", 0)); - cl_assert_equal_b(true, git_fs_path_validate("nul", 0)); - - cl_assert_equal_b(false, git_fs_path_validate("aux", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_fs_path_validate("aux.", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_fs_path_validate("aux:", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_fs_path_validate("aux.asdf", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_fs_path_validate("aux.asdf\\zippy", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_fs_path_validate("aux:asdf\\foobar", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_fs_path_validate("con", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_fs_path_validate("prn", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_fs_path_validate("nul", GIT_FS_PATH_REJECT_DOS_PATHS)); - - cl_assert_equal_b(true, git_fs_path_validate("aux1", 0)); - cl_assert_equal_b(true, git_fs_path_validate("aux1", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_fs_path_validate("auxn", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_fs_path_validate("aux\\foo", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_is_valid("aux", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("aux.", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("aux:", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("aux.asdf", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("aux.asdf\\zippy", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("aux:asdf\\foobar", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("con", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("prn", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("nul", 0)); + + cl_assert_equal_b(false, git_fs_path_is_valid("aux", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_is_valid("aux.", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_is_valid("aux:", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_is_valid("aux.asdf", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_is_valid("aux.asdf\\zippy", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_is_valid("aux:asdf\\foobar", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_is_valid("con", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_is_valid("prn", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_is_valid("nul", GIT_FS_PATH_REJECT_DOS_PATHS)); + + cl_assert_equal_b(true, git_fs_path_is_valid("aux1", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("aux1", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_is_valid("auxn", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_is_valid("aux\\foo", GIT_FS_PATH_REJECT_DOS_PATHS)); } void test_path_core__isvalid_dos_paths_withnum(void) { - cl_assert_equal_b(true, git_fs_path_validate("com1", 0)); - cl_assert_equal_b(true, git_fs_path_validate("com1.", 0)); - cl_assert_equal_b(true, git_fs_path_validate("com1:", 0)); - cl_assert_equal_b(true, git_fs_path_validate("com1.asdf", 0)); - cl_assert_equal_b(true, git_fs_path_validate("com1.asdf\\zippy", 0)); - cl_assert_equal_b(true, git_fs_path_validate("com1:asdf\\foobar", 0)); - cl_assert_equal_b(true, git_fs_path_validate("com1\\foo", 0)); - cl_assert_equal_b(true, git_fs_path_validate("lpt1", 0)); - - cl_assert_equal_b(false, git_fs_path_validate("com1", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_fs_path_validate("com1.", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_fs_path_validate("com1:", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_fs_path_validate("com1.asdf", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_fs_path_validate("com1.asdf\\zippy", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_fs_path_validate("com1:asdf\\foobar", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_fs_path_validate("com1/foo", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(false, git_fs_path_validate("lpt1", GIT_FS_PATH_REJECT_DOS_PATHS)); - - cl_assert_equal_b(true, git_fs_path_validate("com0", 0)); - cl_assert_equal_b(true, git_fs_path_validate("com0", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_fs_path_validate("com10", 0)); - cl_assert_equal_b(true, git_fs_path_validate("com10", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_fs_path_validate("comn", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_fs_path_validate("com1\\foo", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_fs_path_validate("lpt0", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_fs_path_validate("lpt10", GIT_FS_PATH_REJECT_DOS_PATHS)); - cl_assert_equal_b(true, git_fs_path_validate("lptn", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_is_valid("com1", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("com1.", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("com1:", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("com1.asdf", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("com1.asdf\\zippy", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("com1:asdf\\foobar", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("com1\\foo", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("lpt1", 0)); + + cl_assert_equal_b(false, git_fs_path_is_valid("com1", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_is_valid("com1.", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_is_valid("com1:", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_is_valid("com1.asdf", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_is_valid("com1.asdf\\zippy", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_is_valid("com1:asdf\\foobar", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_is_valid("com1/foo", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(false, git_fs_path_is_valid("lpt1", GIT_FS_PATH_REJECT_DOS_PATHS)); + + cl_assert_equal_b(true, git_fs_path_is_valid("com0", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("com0", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_is_valid("com10", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("com10", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_is_valid("comn", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_is_valid("com1\\foo", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_is_valid("lpt0", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_is_valid("lpt10", GIT_FS_PATH_REJECT_DOS_PATHS)); + cl_assert_equal_b(true, git_fs_path_is_valid("lptn", GIT_FS_PATH_REJECT_DOS_PATHS)); } void test_path_core__isvalid_nt_chars(void) { - cl_assert_equal_b(true, git_fs_path_validate("asdf\001foo", 0)); - cl_assert_equal_b(true, git_fs_path_validate("asdf\037bar", 0)); - cl_assert_equal_b(true, git_fs_path_validate("asdffoo", 0)); - cl_assert_equal_b(true, git_fs_path_validate("asdf:foo", 0)); - cl_assert_equal_b(true, git_fs_path_validate("asdf\"bar", 0)); - cl_assert_equal_b(true, git_fs_path_validate("asdf|foo", 0)); - cl_assert_equal_b(true, git_fs_path_validate("asdf?bar", 0)); - cl_assert_equal_b(true, git_fs_path_validate("asdf*bar", 0)); - - cl_assert_equal_b(false, git_fs_path_validate("asdf\001foo", GIT_FS_PATH_REJECT_NT_CHARS)); - cl_assert_equal_b(false, git_fs_path_validate("asdf\037bar", GIT_FS_PATH_REJECT_NT_CHARS)); - cl_assert_equal_b(false, git_fs_path_validate("asdffoo", GIT_FS_PATH_REJECT_NT_CHARS)); - cl_assert_equal_b(false, git_fs_path_validate("asdf:foo", GIT_FS_PATH_REJECT_NT_CHARS)); - cl_assert_equal_b(false, git_fs_path_validate("asdf\"bar", GIT_FS_PATH_REJECT_NT_CHARS)); - cl_assert_equal_b(false, git_fs_path_validate("asdf|foo", GIT_FS_PATH_REJECT_NT_CHARS)); - cl_assert_equal_b(false, git_fs_path_validate("asdf?bar", GIT_FS_PATH_REJECT_NT_CHARS)); - cl_assert_equal_b(false, git_fs_path_validate("asdf*bar", GIT_FS_PATH_REJECT_NT_CHARS)); + cl_assert_equal_b(true, git_fs_path_is_valid("asdf\001foo", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("asdf\037bar", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("asdffoo", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("asdf:foo", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("asdf\"bar", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("asdf|foo", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("asdf?bar", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("asdf*bar", 0)); + + cl_assert_equal_b(false, git_fs_path_is_valid("asdf\001foo", GIT_FS_PATH_REJECT_NT_CHARS)); + cl_assert_equal_b(false, git_fs_path_is_valid("asdf\037bar", GIT_FS_PATH_REJECT_NT_CHARS)); + cl_assert_equal_b(false, git_fs_path_is_valid("asdffoo", GIT_FS_PATH_REJECT_NT_CHARS)); + cl_assert_equal_b(false, git_fs_path_is_valid("asdf:foo", GIT_FS_PATH_REJECT_NT_CHARS)); + cl_assert_equal_b(false, git_fs_path_is_valid("asdf\"bar", GIT_FS_PATH_REJECT_NT_CHARS)); + cl_assert_equal_b(false, git_fs_path_is_valid("asdf|foo", GIT_FS_PATH_REJECT_NT_CHARS)); + cl_assert_equal_b(false, git_fs_path_is_valid("asdf?bar", GIT_FS_PATH_REJECT_NT_CHARS)); + cl_assert_equal_b(false, git_fs_path_is_valid("asdf*bar", GIT_FS_PATH_REJECT_NT_CHARS)); } void test_path_core__validate_workdir(void) -- cgit v1.2.1 From 63e36c53caa8c3f1581471de64bbef3ca87f3921 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 1 Nov 2021 09:34:32 -0400 Subject: path: `validate` -> `is_valid` Since we're returning a boolean about validation, the name is more properly "is valid". --- src/checkout.c | 4 +- src/index.c | 2 +- src/path.c | 2 +- src/path.h | 2 +- src/refdb_fs.c | 4 +- src/submodule.c | 2 +- src/tree.c | 2 +- tests/path/dotgit.c | 136 ++++++++++++++++++++++++++-------------------------- 8 files changed, 77 insertions(+), 77 deletions(-) diff --git a/src/checkout.c b/src/checkout.c index 96ba4da38..ad4edddd3 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -1281,14 +1281,14 @@ static int checkout_verify_paths( unsigned int flags = GIT_PATH_REJECT_WORKDIR_DEFAULTS; if (action & CHECKOUT_ACTION__REMOVE) { - if (!git_path_validate(repo, delta->old_file.path, delta->old_file.mode, flags)) { + if (!git_path_is_valid(repo, delta->old_file.path, delta->old_file.mode, flags)) { git_error_set(GIT_ERROR_CHECKOUT, "cannot remove invalid path '%s'", delta->old_file.path); return -1; } } if (action & ~CHECKOUT_ACTION__REMOVE) { - if (!git_path_validate(repo, delta->new_file.path, delta->new_file.mode, flags)) { + if (!git_path_is_valid(repo, delta->new_file.path, delta->new_file.mode, flags)) { git_error_set(GIT_ERROR_CHECKOUT, "cannot checkout to invalid path '%s'", delta->new_file.path); return -1; } diff --git a/src/index.c b/src/index.c index 448852f29..bd6ea8f03 100644 --- a/src/index.c +++ b/src/index.c @@ -945,7 +945,7 @@ static int index_entry_create( if (st) mode = st->st_mode; - if (!git_path_validate(repo, path, mode, path_valid_flags)) { + if (!git_path_is_valid(repo, path, mode, path_valid_flags)) { git_error_set(GIT_ERROR_INDEX, "invalid path: '%s'", path); return -1; } diff --git a/src/path.c b/src/path.c index 063009fa1..d54bc5bfe 100644 --- a/src/path.c +++ b/src/path.c @@ -285,7 +285,7 @@ GIT_INLINE(unsigned int) dotgit_flags( return flags; } -bool git_path_validate( +bool git_path_is_valid( git_repository *repo, const char *path, uint16_t file_mode, diff --git a/src/path.h b/src/path.h index ca220d121..f874a16be 100644 --- a/src/path.h +++ b/src/path.h @@ -25,7 +25,7 @@ #define GIT_PATH_REJECT_INDEX_DEFAULTS \ GIT_FS_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT -extern bool git_path_validate( +extern bool git_path_is_valid( git_repository *repo, const char *path, uint16_t file_mode, diff --git a/src/refdb_fs.c b/src/refdb_fs.c index 39dc16e9d..acd627091 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -818,7 +818,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char * GIT_ASSERT_ARG(backend); GIT_ASSERT_ARG(name); - if (!git_path_validate(backend->repo, name, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) { + if (!git_path_is_valid(backend->repo, name, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) { git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", name); return GIT_EINVALIDSPEC; } @@ -1857,7 +1857,7 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char repo = backend->repo; - if (!git_path_validate(backend->repo, refname, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) { + if (!git_path_is_valid(backend->repo, refname, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) { git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", refname); return GIT_EINVALIDSPEC; } diff --git a/src/submodule.c b/src/submodule.c index 727b6c6e4..ffe29ccfb 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -423,7 +423,7 @@ int git_submodule_name_is_valid(git_repository *repo, const char *name, int flag git_str_attach_notowned(&buf, name, strlen(name)); } - isvalid = git_path_validate(repo, buf.ptr, 0, flags); + isvalid = git_path_is_valid(repo, buf.ptr, 0, flags); git_str_dispose(&buf); return isvalid; diff --git a/src/tree.c b/src/tree.c index 256e72080..b8e82d485 100644 --- a/src/tree.c +++ b/src/tree.c @@ -55,7 +55,7 @@ GIT_INLINE(git_filemode_t) normalize_filemode(git_filemode_t filemode) static int valid_entry_name(git_repository *repo, const char *filename) { return *filename != '\0' && - git_path_validate(repo, filename, 0, + git_path_is_valid(repo, filename, 0, GIT_FS_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT | GIT_FS_PATH_REJECT_SLASH); } diff --git a/tests/path/dotgit.c b/tests/path/dotgit.c index 5b3a31137..9ac68b0ff 100644 --- a/tests/path/dotgit.c +++ b/tests/path/dotgit.c @@ -114,10 +114,10 @@ void test_path_dotgit__dotgit_modules(void) void test_path_dotgit__dotgit_modules_symlink(void) { - cl_assert_equal_b(true, git_path_validate(NULL, ".gitmodules", 0, GIT_PATH_REJECT_DOT_GIT_HFS|GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".gitmodules . .::$DATA", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".gitmodules", 0, GIT_PATH_REJECT_DOT_GIT_HFS|GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, ".gitmodules . .::$DATA", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS)); } void test_core_path__git_fs_path_is_file(void) @@ -131,76 +131,76 @@ void test_core_path__git_fs_path_is_file(void) void test_path_dotgit__isvalid_dot_git(void) { - cl_assert_equal_b(true, git_path_validate(NULL, ".git", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, ".git/foo", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/.git", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/.git/bar", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/.GIT/bar", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/bar/.Git", 0, 0)); - - cl_assert_equal_b(false, git_path_validate(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - cl_assert_equal_b(false, git_path_validate(NULL, ".git/foo", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/.git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/.git/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/.GIT/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - cl_assert_equal_b(false, git_path_validate(NULL, "foo/bar/.Git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - - cl_assert_equal_b(true, git_path_validate(NULL, "!git", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/!git", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "!git/bar", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, ".tig", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "foo/.tig", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, ".tig/bar", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".git", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".git/foo", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.git", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.git/bar", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.GIT/bar", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/bar/.Git", 0, 0)); + + cl_assert_equal_b(false, git_path_is_valid(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); + cl_assert_equal_b(false, git_path_is_valid(NULL, ".git/foo", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); + cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/.git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); + cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/.git/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); + cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/.GIT/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); + cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/bar/.Git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); + + cl_assert_equal_b(true, git_path_is_valid(NULL, "!git", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/!git", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, "!git/bar", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".tig", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.tig", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".tig/bar", 0, 0)); } void test_path_dotgit__isvalid_dotgit_ntfs(void) { - cl_assert_equal_b(true, git_path_validate(NULL, ".git", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, ".git ", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, ".git.", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, ".git.. .", 0, 0)); - - cl_assert_equal_b(true, git_path_validate(NULL, "git~1", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "git~1 ", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "git~1.", 0, 0)); - cl_assert_equal_b(true, git_path_validate(NULL, "git~1.. .", 0, 0)); - - cl_assert_equal_b(false, git_path_validate(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".git ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".git.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".git.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - - cl_assert_equal_b(false, git_path_validate(NULL, "git~1", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_validate(NULL, "git~1 ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_validate(NULL, "git~1.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_validate(NULL, "git~1.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".git", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".git ", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".git.", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".git.. .", 0, 0)); + + cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1 ", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1.", 0, 0)); + cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1.. .", 0, 0)); + + cl_assert_equal_b(false, git_path_is_valid(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, ".git ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, ".git.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, ".git.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + + cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1 ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); } void test_path_dotgit__isvalid_dotgit_with_hfs_ignorables(void) { - cl_assert_equal_b(false, git_path_validate(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".gi\xe2\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".g\xe2\x80\x8eIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_validate(NULL, ".\xe2\x80\x8fgIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x80\xaa.gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - - cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x80\xab.\xe2\x80\xacG\xe2\x80\xadI\xe2\x80\xaet", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x81\xab.\xe2\x80\xaaG\xe2\x81\xabI\xe2\x80\xact", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_validate(NULL, "\xe2\x81\xad.\xe2\x80\xaeG\xef\xbb\xbfIT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - - cl_assert_equal_b(true, git_path_validate(NULL, ".", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".g", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, " .git", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, "..git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".gi\xe2\x80\x8dT.", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".g\xe2\x80It", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".\xe2gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, "\xe2\x80\xaa.gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".gi\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".gi\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".g\xe2i\x80T\x8e", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".git\xe2\x80\xbf", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_validate(NULL, ".git\xe2\xab\x81", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, ".git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, ".gi\xe2\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, ".g\xe2\x80\x8eIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, ".\xe2\x80\x8fgIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x80\xaa.gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + + cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x80\xab.\xe2\x80\xacG\xe2\x80\xadI\xe2\x80\xaet", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x81\xab.\xe2\x80\xaaG\xe2\x81\xabI\xe2\x80\xact", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x81\xad.\xe2\x80\xaeG\xef\xbb\xbfIT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + + cl_assert_equal_b(true, git_path_is_valid(NULL, ".", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".g", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_is_valid(NULL, " .git", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_is_valid(NULL, "..git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi\xe2\x80\x8dT.", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".g\xe2\x80It", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".\xe2gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_is_valid(NULL, "\xe2\x80\xaa.gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".g\xe2i\x80T\x8e", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".git\xe2\x80\xbf", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); + cl_assert_equal_b(true, git_path_is_valid(NULL, ".git\xe2\xab\x81", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); } -- cgit v1.2.1 From bef02d3e638ce8c95c9e63622b46d87a0f8ee2b2 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 1 Nov 2021 10:57:28 -0400 Subject: fs_path: introduce `str_is_valid` Provide a mechanism for users to limit the number of characters that are examined; `git_fs_path_str_is_valid` and friends will only examine up to `str->size` bytes. `git_fs_path_is_valid` delegates to these new functions by passing `SIZE_MAX` (instead of doing a `strlen`), which is a sentinel value meaning "look for a NUL terminator". --- src/fs_path.c | 21 +++++++++++++-------- src/fs_path.h | 52 +++++++++++++++++++++++++++++++++++++++++----------- tests/path/core.c | 27 +++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 19 deletions(-) diff --git a/src/fs_path.c b/src/fs_path.c index ceba02d62..fa27a6e73 100644 --- a/src/fs_path.c +++ b/src/fs_path.c @@ -1634,16 +1634,17 @@ static bool validate_component( return true; } -bool git_fs_path_is_valid_ext( - const char *path, +bool git_fs_path_is_valid_str_ext( + const git_str *path, unsigned int flags, bool (*validate_char_cb)(char ch, void *payload), bool (*validate_component_cb)(const char *component, size_t len, void *payload), void *payload) { const char *start, *c; + size_t len = 0; - for (start = c = path; *c; c++) { + for (start = c = path->ptr; *c && len < path->size; c++, len++) { if (!validate_char(*c, flags)) return false; @@ -1663,6 +1664,15 @@ bool git_fs_path_is_valid_ext( start = c + 1; } + /* + * We want to support paths specified as either `const char *` + * or `git_str *`; we pass size as `SIZE_MAX` when we use a + * `const char *` to avoid a `strlen`. Ensure that we didn't + * have a NUL in the buffer if there was a non-SIZE_MAX length. + */ + if (path->size != SIZE_MAX && len != path->size) + return false; + if (!validate_component(start, (c - start), flags)) return false; @@ -1673,11 +1683,6 @@ bool git_fs_path_is_valid_ext( return true; } -bool git_fs_path_is_valid(const char *path, unsigned int flags) -{ - return git_fs_path_is_valid_ext(path, flags, NULL, NULL, NULL); -} - #ifdef GIT_WIN32 GIT_INLINE(bool) should_validate_longpaths(git_repository *repo) { diff --git a/src/fs_path.h b/src/fs_path.h index 991e7cd83..2f4bc9f79 100644 --- a/src/fs_path.h +++ b/src/fs_path.h @@ -620,26 +620,56 @@ extern int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url GIT_FS_PATH_REJECT_TRAVERSAL #endif -/** - * Validate a filesystem path. This ensures that the given path is legal - * and does not contain any "unsafe" components like path traversal ('.' - * or '..'), characters that are inappropriate for lesser filesystems - * (trailing ' ' or ':' characters), or filenames ("component names") - * that are not supported ('AUX', 'COM1"). - */ -extern bool git_fs_path_is_valid(const char *path, unsigned int flags); - /** * Validate a filesystem path; with custom callbacks per-character and * per-path component. */ -extern bool git_fs_path_is_valid_ext( - const char *path, +extern bool git_fs_path_is_valid_str_ext( + const git_str *path, unsigned int flags, bool (*validate_char_cb)(char ch, void *payload), bool (*validate_component_cb)(const char *component, size_t len, void *payload), void *payload); +GIT_INLINE(bool) git_fs_path_is_valid_ext( + const char *path, + unsigned int flags, + bool (*validate_char_cb)(char ch, void *payload), + bool (*validate_component_cb)(const char *component, size_t len, void *payload), + void *payload) +{ + const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX); + return git_fs_path_is_valid_str_ext( + &str, + flags, + validate_char_cb, + validate_component_cb, + payload); +} + +/** + * Validate a filesystem path. This ensures that the given path is legal + * and does not contain any "unsafe" components like path traversal ('.' + * or '..'), characters that are inappropriate for lesser filesystems + * (trailing ' ' or ':' characters), or filenames ("component names") + * that are not supported ('AUX', 'COM1"). + */ +GIT_INLINE(bool) git_fs_path_is_valid( + const char *path, + unsigned int flags) +{ + const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX); + return git_fs_path_is_valid_str_ext(&str, flags, NULL, NULL, NULL); +} + +/** Validate a filesystem path in a `git_str`. */ +GIT_INLINE(bool) git_fs_path_is_valid_str( + const git_str *path, + unsigned int flags) +{ + return git_fs_path_is_valid_str_ext(path, flags, NULL, NULL, NULL); +} + /** * Validate an on-disk path, taking into account that it will have a * suffix appended (eg, `.lock`). diff --git a/tests/path/core.c b/tests/path/core.c index f48a76957..6fa0450ca 100644 --- a/tests/path/core.c +++ b/tests/path/core.c @@ -64,6 +64,33 @@ void test_path_core__isvalid_standard(void) cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar/.file", 0)); } +/* Ensure that `is_valid_str` only reads str->size bytes */ +void test_path_core__isvalid_standard_str(void) +{ + git_str str = GIT_STR_INIT_CONST("foo/bar//zap", 0); + + str.size = 0; + cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, 0)); + + str.size = 3; + cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, 0)); + + str.size = 4; + cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, 0)); + + str.size = 5; + cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, 0)); + + str.size = 7; + cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, 0)); + + str.size = 8; + cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, 0)); + + str.size = strlen(str.ptr); + cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, 0)); +} + void test_path_core__isvalid_empty_dir_component(void) { cl_assert_equal_b(false, git_fs_path_is_valid("foo//bar", 0)); -- cgit v1.2.1 From dd748dbede1a36f1e929461ecbfcde749eb685bb Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 1 Nov 2021 13:04:40 -0400 Subject: fs_path: make empty component validation optional --- src/fs_path.c | 5 ++++- src/fs_path.h | 5 ++++- tests/path/core.c | 43 ++++++++++++++++++++++++++++++------------- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/fs_path.c b/src/fs_path.c index fa27a6e73..483b21c1e 100644 --- a/src/fs_path.c +++ b/src/fs_path.c @@ -1599,7 +1599,7 @@ static bool validate_component( unsigned int flags) { if (len == 0) - return false; + return !(flags & GIT_FS_PATH_REJECT_EMPTY_COMPONENT); if ((flags & GIT_FS_PATH_REJECT_TRAVERSAL) && len == 1 && component[0] == '.') @@ -1644,6 +1644,9 @@ bool git_fs_path_is_valid_str_ext( const char *start, *c; size_t len = 0; + if (!flags) + return true; + for (start = c = path->ptr; *c && len < path->size; c++, len++) { if (!validate_char(*c, flags)) return false; diff --git a/src/fs_path.h b/src/fs_path.h index 2f4bc9f79..275b3d857 100644 --- a/src/fs_path.h +++ b/src/fs_path.h @@ -591,7 +591,8 @@ extern bool git_fs_path_is_local_file_url(const char *file_url); extern int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url_or_path); /* Flags to determine path validity in `git_fs_path_isvalid` */ -#define GIT_FS_PATH_REJECT_TRAVERSAL (1 << 0) +#define GIT_FS_PATH_REJECT_EMPTY_COMPONENT (1 << 0) +#define GIT_FS_PATH_REJECT_TRAVERSAL (1 << 1) #define GIT_FS_PATH_REJECT_SLASH (1 << 2) #define GIT_FS_PATH_REJECT_BACKSLASH (1 << 3) #define GIT_FS_PATH_REJECT_TRAILING_DOT (1 << 4) @@ -608,6 +609,7 @@ extern int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url */ #ifdef GIT_WIN32 # define GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS \ + GIT_FS_PATH_REJECT_EMPTY_COMPONENT | \ GIT_FS_PATH_REJECT_TRAVERSAL | \ GIT_FS_PATH_REJECT_BACKSLASH | \ GIT_FS_PATH_REJECT_TRAILING_DOT | \ @@ -617,6 +619,7 @@ extern int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url GIT_FS_PATH_REJECT_NT_CHARS #else # define GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS \ + GIT_FS_PATH_REJECT_EMPTY_COMPONENT | \ GIT_FS_PATH_REJECT_TRAVERSAL #endif diff --git a/tests/path/core.c b/tests/path/core.c index 6fa0450ca..ccb328b10 100644 --- a/tests/path/core.c +++ b/tests/path/core.c @@ -68,41 +68,58 @@ void test_path_core__isvalid_standard(void) void test_path_core__isvalid_standard_str(void) { git_str str = GIT_STR_INIT_CONST("foo/bar//zap", 0); + unsigned int flags = GIT_FS_PATH_REJECT_EMPTY_COMPONENT; str.size = 0; - cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, 0)); + cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags)); str.size = 3; - cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, 0)); + cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, flags)); str.size = 4; - cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, 0)); + cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags)); str.size = 5; - cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, 0)); + cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, flags)); str.size = 7; - cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, 0)); + cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, flags)); str.size = 8; - cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, 0)); + cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags)); str.size = strlen(str.ptr); - cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, 0)); + cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags)); } void test_path_core__isvalid_empty_dir_component(void) { - cl_assert_equal_b(false, git_fs_path_is_valid("foo//bar", 0)); + unsigned int flags = GIT_FS_PATH_REJECT_EMPTY_COMPONENT; + + /* empty component */ + cl_assert_equal_b(true, git_fs_path_is_valid("foo//bar", 0)); + + /* leading slash */ + cl_assert_equal_b(true, git_fs_path_is_valid("/", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("/foo", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("/foo/bar", 0)); + + /* trailing slash */ + cl_assert_equal_b(true, git_fs_path_is_valid("foo/", 0)); + cl_assert_equal_b(true, git_fs_path_is_valid("foo/bar/", 0)); + + + /* empty component */ + cl_assert_equal_b(false, git_fs_path_is_valid("foo//bar", flags)); /* leading slash */ - cl_assert_equal_b(false, git_fs_path_is_valid("/", 0)); - cl_assert_equal_b(false, git_fs_path_is_valid("/foo", 0)); - cl_assert_equal_b(false, git_fs_path_is_valid("/foo/bar", 0)); + cl_assert_equal_b(false, git_fs_path_is_valid("/", flags)); + cl_assert_equal_b(false, git_fs_path_is_valid("/foo", flags)); + cl_assert_equal_b(false, git_fs_path_is_valid("/foo/bar", flags)); /* trailing slash */ - cl_assert_equal_b(false, git_fs_path_is_valid("foo/", 0)); - cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar/", 0)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo/", flags)); + cl_assert_equal_b(false, git_fs_path_is_valid("foo/bar/", flags)); } void test_path_core__isvalid_dot_and_dotdot(void) -- cgit v1.2.1 From ebacd24c6039c992ef9122a0d6f7de0ca4ba3bd1 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 1 Nov 2021 13:58:18 -0400 Subject: fs_path: add long path validation on windows --- src/fs_path.c | 29 +++++++++++++++++++++++++++++ src/fs_path.h | 10 +++++++--- src/path.c | 2 +- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/fs_path.c b/src/fs_path.c index 483b21c1e..de3b03957 100644 --- a/src/fs_path.c +++ b/src/fs_path.c @@ -1634,11 +1634,25 @@ static bool validate_component( return true; } +#ifdef GIT_WIN32 +GIT_INLINE(bool) validate_length( + const char *path, + size_t len, + size_t utf8_char_len) +{ + GIT_UNUSED(path); + GIT_UNUSED(len); + + return (utf8_char_len <= MAX_PATH); +} +#endif + bool git_fs_path_is_valid_str_ext( const git_str *path, unsigned int flags, bool (*validate_char_cb)(char ch, void *payload), bool (*validate_component_cb)(const char *component, size_t len, void *payload), + bool (*validate_length_cb)(const char *path, size_t len, size_t utf8_char_len), void *payload) { const char *start, *c; @@ -1683,6 +1697,21 @@ bool git_fs_path_is_valid_str_ext( !validate_component_cb(start, (c - start), payload)) return false; +#ifdef GIT_WIN32 + if ((flags & GIT_FS_PATH_REJECT_LONG_PATHS) != 0) { + size_t utf8_len = git_utf8_char_length(path->ptr, len); + + if (!validate_length(path->ptr, len, utf8_len)) + return false; + + if (validate_length_cb && + !validate_length_cb(path->ptr, len, utf8_len)) + return false; + } +#else + GIT_UNUSED(validate_length_cb); +#endif + return true; } diff --git a/src/fs_path.h b/src/fs_path.h index 275b3d857..40b4342f1 100644 --- a/src/fs_path.h +++ b/src/fs_path.h @@ -600,8 +600,9 @@ extern int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url #define GIT_FS_PATH_REJECT_TRAILING_COLON (1 << 6) #define GIT_FS_PATH_REJECT_DOS_PATHS (1 << 7) #define GIT_FS_PATH_REJECT_NT_CHARS (1 << 8) +#define GIT_FS_PATH_REJECT_LONG_PATHS (1 << 9) -#define GIT_FS_PATH_REJECT_MAX (1 << 8) +#define GIT_FS_PATH_REJECT_MAX (1 << 9) /* Default path safety for writing files to disk: since we use the * Win32 "File Namespace" APIs ("\\?\") we need to protect from @@ -632,6 +633,7 @@ extern bool git_fs_path_is_valid_str_ext( unsigned int flags, bool (*validate_char_cb)(char ch, void *payload), bool (*validate_component_cb)(const char *component, size_t len, void *payload), + bool (*validate_length_cb)(const char *component, size_t len, size_t utf8_char_len), void *payload); GIT_INLINE(bool) git_fs_path_is_valid_ext( @@ -639,6 +641,7 @@ GIT_INLINE(bool) git_fs_path_is_valid_ext( unsigned int flags, bool (*validate_char_cb)(char ch, void *payload), bool (*validate_component_cb)(const char *component, size_t len, void *payload), + bool (*validate_length_cb)(const char *component, size_t len, size_t utf8_char_len), void *payload) { const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX); @@ -647,6 +650,7 @@ GIT_INLINE(bool) git_fs_path_is_valid_ext( flags, validate_char_cb, validate_component_cb, + validate_length_cb, payload); } @@ -662,7 +666,7 @@ GIT_INLINE(bool) git_fs_path_is_valid( unsigned int flags) { const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX); - return git_fs_path_is_valid_str_ext(&str, flags, NULL, NULL, NULL); + return git_fs_path_is_valid_str_ext(&str, flags, NULL, NULL, NULL, NULL); } /** Validate a filesystem path in a `git_str`. */ @@ -670,7 +674,7 @@ GIT_INLINE(bool) git_fs_path_is_valid_str( const git_str *path, unsigned int flags) { - return git_fs_path_is_valid_str_ext(path, flags, NULL, NULL, NULL); + return git_fs_path_is_valid_str_ext(path, flags, NULL, NULL, NULL, NULL); } /** diff --git a/src/path.c b/src/path.c index d54bc5bfe..a6b396f6d 100644 --- a/src/path.c +++ b/src/path.c @@ -301,7 +301,7 @@ bool git_path_is_valid( data.file_mode = file_mode; data.flags = flags; - return git_fs_path_is_valid_ext(path, flags, NULL, validate_repo_component, &data); + return git_fs_path_is_valid_ext(path, flags, NULL, validate_repo_component, NULL, &data); } static const struct { -- cgit v1.2.1 From 315a43b2f16fab679126f519a5dce1c9e1e335af Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 1 Nov 2021 17:37:06 -0400 Subject: path: introduce `git_path_str_is_valid` Add a `git_str` based validity check; the existing `git_path_is_valid` defers to it. --- src/fs_path.c | 2 +- src/fs_path.h | 10 +++++----- src/path.c | 6 +++--- src/path.h | 14 ++++++++++++-- tests/path/core.c | 14 +++++++------- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/fs_path.c b/src/fs_path.c index de3b03957..9079c30c9 100644 --- a/src/fs_path.c +++ b/src/fs_path.c @@ -1647,7 +1647,7 @@ GIT_INLINE(bool) validate_length( } #endif -bool git_fs_path_is_valid_str_ext( +bool git_fs_path_str_is_valid_ext( const git_str *path, unsigned int flags, bool (*validate_char_cb)(char ch, void *payload), diff --git a/src/fs_path.h b/src/fs_path.h index 40b4342f1..947c4ae86 100644 --- a/src/fs_path.h +++ b/src/fs_path.h @@ -628,7 +628,7 @@ extern int git_fs_path_from_url_or_path(git_str *local_path_out, const char *url * Validate a filesystem path; with custom callbacks per-character and * per-path component. */ -extern bool git_fs_path_is_valid_str_ext( +extern bool git_fs_path_str_is_valid_ext( const git_str *path, unsigned int flags, bool (*validate_char_cb)(char ch, void *payload), @@ -645,7 +645,7 @@ GIT_INLINE(bool) git_fs_path_is_valid_ext( void *payload) { const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX); - return git_fs_path_is_valid_str_ext( + return git_fs_path_str_is_valid_ext( &str, flags, validate_char_cb, @@ -666,15 +666,15 @@ GIT_INLINE(bool) git_fs_path_is_valid( unsigned int flags) { const git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX); - return git_fs_path_is_valid_str_ext(&str, flags, NULL, NULL, NULL, NULL); + return git_fs_path_str_is_valid_ext(&str, flags, NULL, NULL, NULL, NULL); } /** Validate a filesystem path in a `git_str`. */ -GIT_INLINE(bool) git_fs_path_is_valid_str( +GIT_INLINE(bool) git_fs_path_str_is_valid( const git_str *path, unsigned int flags) { - return git_fs_path_is_valid_str_ext(path, flags, NULL, NULL, NULL, NULL); + return git_fs_path_str_is_valid_ext(path, flags, NULL, NULL, NULL, NULL); } /** diff --git a/src/path.c b/src/path.c index a6b396f6d..933444de2 100644 --- a/src/path.c +++ b/src/path.c @@ -285,9 +285,9 @@ GIT_INLINE(unsigned int) dotgit_flags( return flags; } -bool git_path_is_valid( +bool git_path_str_is_valid( git_repository *repo, - const char *path, + const git_str *path, uint16_t file_mode, unsigned int flags) { @@ -301,7 +301,7 @@ bool git_path_is_valid( data.file_mode = file_mode; data.flags = flags; - return git_fs_path_is_valid_ext(path, flags, NULL, validate_repo_component, NULL, &data); + return git_fs_path_str_is_valid_ext(path, flags, NULL, validate_repo_component, NULL, &data); } static const struct { diff --git a/src/path.h b/src/path.h index f874a16be..f2ac8484b 100644 --- a/src/path.h +++ b/src/path.h @@ -25,10 +25,20 @@ #define GIT_PATH_REJECT_INDEX_DEFAULTS \ GIT_FS_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT -extern bool git_path_is_valid( +extern bool git_path_str_is_valid( git_repository *repo, - const char *path, + const git_str *path, uint16_t file_mode, unsigned int flags); +GIT_INLINE(bool) git_path_is_valid( + git_repository *repo, + const char *path, + uint16_t file_mode, + unsigned int flags) +{ + git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX); + return git_path_str_is_valid(repo, &str, file_mode, flags); +} + #endif diff --git a/tests/path/core.c b/tests/path/core.c index ccb328b10..eb6e5b851 100644 --- a/tests/path/core.c +++ b/tests/path/core.c @@ -71,25 +71,25 @@ void test_path_core__isvalid_standard_str(void) unsigned int flags = GIT_FS_PATH_REJECT_EMPTY_COMPONENT; str.size = 0; - cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags)); + cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags)); str.size = 3; - cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, flags)); + cl_assert_equal_b(true, git_fs_path_str_is_valid(&str, flags)); str.size = 4; - cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags)); + cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags)); str.size = 5; - cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, flags)); + cl_assert_equal_b(true, git_fs_path_str_is_valid(&str, flags)); str.size = 7; - cl_assert_equal_b(true, git_fs_path_is_valid_str(&str, flags)); + cl_assert_equal_b(true, git_fs_path_str_is_valid(&str, flags)); str.size = 8; - cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags)); + cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags)); str.size = strlen(str.ptr); - cl_assert_equal_b(false, git_fs_path_is_valid_str(&str, flags)); + cl_assert_equal_b(false, git_fs_path_str_is_valid(&str, flags)); } void test_path_core__isvalid_empty_dir_component(void) -- cgit v1.2.1 From 1728e27c96a2e14328423554d3559166ebd1bab7 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 1 Nov 2021 18:19:56 -0400 Subject: path: length validation respecting core.longpaths Teach `git_path_is_valid` to respect `core.longpaths`. Add helper methods to validate length and set the error message appropriately. --- src/path.c | 26 ++++++++++++++++++++++++++ src/path.h | 24 ++++++++++++++++++++++++ tests/path/core.c | 37 +++++++++++++++++++------------------ 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/src/path.c b/src/path.c index 933444de2..05a3dc2cf 100644 --- a/src/path.c +++ b/src/path.c @@ -285,6 +285,28 @@ GIT_INLINE(unsigned int) dotgit_flags( return flags; } +GIT_INLINE(unsigned int) length_flags( + git_repository *repo, + unsigned int flags) +{ +#ifdef GIT_WIN32 + int allow = 0; + + if (repo && + git_repository__configmap_lookup(&allow, repo, GIT_CONFIGMAP_LONGPATHS) < 0) + allow = 0; + + if (allow) + flags &= ~GIT_FS_PATH_REJECT_LONG_PATHS; + +#else + GIT_UNUSED(repo); + flags &= ~GIT_FS_PATH_REJECT_LONG_PATHS; +#endif + + return flags; +} + bool git_path_str_is_valid( git_repository *repo, const git_str *path, @@ -297,6 +319,10 @@ bool git_path_str_is_valid( if ((flags & GIT_PATH_REJECT_DOT_GIT)) flags = dotgit_flags(repo, flags); + /* Update the length checks based on platform */ + if ((flags & GIT_FS_PATH_REJECT_LONG_PATHS)) + flags = length_flags(repo, flags); + data.repo = repo; data.file_mode = file_mode; data.flags = flags; diff --git a/src/path.h b/src/path.h index f2ac8484b..c4a2c4250 100644 --- a/src/path.h +++ b/src/path.h @@ -41,4 +41,28 @@ GIT_INLINE(bool) git_path_is_valid( return git_path_str_is_valid(repo, &str, file_mode, flags); } +GIT_INLINE(int) git_path_validate_str_length( + git_repository *repo, + const git_str *path) +{ + if (!git_path_str_is_valid(repo, path, 0, GIT_FS_PATH_REJECT_LONG_PATHS)) { + if (path->size == SIZE_MAX) + git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%s'", path->ptr); + else + git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%.*s'", (int)path->size, path->ptr); + + return -1; + } + + return 0; +} + +GIT_INLINE(int) git_path_validate_length( + git_repository *repo, + const char *path) +{ + git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX); + return git_path_validate_str_length(repo, &str); +} + #endif diff --git a/tests/path/core.c b/tests/path/core.c index eb6e5b851..9421941c0 100644 --- a/tests/path/core.c +++ b/tests/path/core.c @@ -1,5 +1,6 @@ #include "clar_libgit2.h" #include "fs_path.h" +#include "path.h" void test_path_core__cleanup(void) { @@ -281,30 +282,30 @@ void test_path_core__isvalid_nt_chars(void) void test_path_core__validate_workdir(void) { - cl_must_pass(git_fs_path_validate_workdir(NULL, "/foo/bar")); - cl_must_pass(git_fs_path_validate_workdir(NULL, "C:\\Foo\\Bar")); - cl_must_pass(git_fs_path_validate_workdir(NULL, "\\\\?\\C:\\Foo\\Bar")); - cl_must_pass(git_fs_path_validate_workdir(NULL, "\\\\?\\C:\\Foo\\Bar")); - cl_must_pass(git_fs_path_validate_workdir(NULL, "\\\\?\\UNC\\server\\C$\\folder")); + cl_must_pass(git_path_validate_length(NULL, "/foo/bar")); + cl_must_pass(git_path_validate_length(NULL, "C:\\Foo\\Bar")); + cl_must_pass(git_path_validate_length(NULL, "\\\\?\\C:\\Foo\\Bar")); + cl_must_pass(git_path_validate_length(NULL, "\\\\?\\C:\\Foo\\Bar")); + cl_must_pass(git_path_validate_length(NULL, "\\\\?\\UNC\\server\\C$\\folder")); #ifdef GIT_WIN32 /* * In the absense of a repo configuration, 259 character paths * succeed. >= 260 character paths fail. */ - cl_must_pass(git_fs_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\ok.txt")); - cl_must_pass(git_fs_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\260.txt")); - cl_must_fail(git_fs_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\longer_than_260.txt")); + cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\ok.txt")); + cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\260.txt")); + cl_must_fail(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\longer_than_260.txt")); /* count characters, not bytes */ - cl_must_pass(git_fs_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt")); - cl_must_fail(git_fs_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt")); + cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt")); + cl_must_fail(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt")); #else - cl_must_pass(git_fs_path_validate_workdir(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/ok.txt")); - cl_must_pass(git_fs_path_validate_workdir(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/260.txt")); - cl_must_pass(git_fs_path_validate_workdir(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); - cl_must_pass(git_fs_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt")); - cl_must_pass(git_fs_path_validate_workdir(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt")); + cl_must_pass(git_path_validate_length(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/ok.txt")); + cl_must_pass(git_path_validate_length(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/260.txt")); + cl_must_pass(git_path_validate_length(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); + cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt")); + cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt")); #endif } @@ -320,15 +321,15 @@ void test_path_core__validate_workdir_with_core_longpath(void) cl_git_pass(git_repository_config(&config, repo)); /* fail by default */ - cl_must_fail(git_fs_path_validate_workdir(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); + cl_must_fail(git_path_validate_length(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); /* set core.longpaths explicitly on */ cl_git_pass(git_config_set_bool(config, "core.longpaths", 1)); - cl_must_pass(git_fs_path_validate_workdir(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); + cl_must_pass(git_path_validate_length(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); /* set core.longpaths explicitly off */ cl_git_pass(git_config_set_bool(config, "core.longpaths", 0)); - cl_must_fail(git_fs_path_validate_workdir(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); + cl_must_fail(git_path_validate_length(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); git_config_free(config); git_repository_free(repo); -- cgit v1.2.1 From 91246ee5e0d8be8a15a669844f0893cd0f01c604 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 1 Nov 2021 20:14:34 -0400 Subject: path: use new length validation functions --- src/attrcache.c | 9 +++++++-- src/checkout.c | 6 +++--- src/filter.c | 3 ++- src/ignore.c | 5 +++-- src/iterator.c | 17 ++++++++++++----- src/mailmap.c | 3 ++- src/refdb_fs.c | 2 +- src/repository.c | 6 +++--- src/submodule.c | 2 +- src/worktree.c | 3 ++- 10 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/attrcache.c b/src/attrcache.c index 15c7fab48..b16d95c3c 100644 --- a/src/attrcache.c +++ b/src/attrcache.c @@ -12,6 +12,7 @@ #include "config.h" #include "sysdir.h" #include "ignore.h" +#include "path.h" GIT_INLINE(int) attr_cache_lock(git_attr_cache *cache) { @@ -43,6 +44,7 @@ int git_attr_cache__alloc_file_entry( const char *path, git_pool *pool) { + git_str fullpath_str = GIT_STR_INIT; size_t baselen = 0, pathlen = strlen(path); size_t cachesize = sizeof(git_attr_file_entry) + pathlen + 1; git_attr_file_entry *ce; @@ -66,7 +68,10 @@ int git_attr_cache__alloc_file_entry( } memcpy(&ce->fullpath[baselen], path, pathlen); - if (git_fs_path_validate_workdir_with_len(repo, ce->fullpath, pathlen + baselen) < 0) + fullpath_str.ptr = ce->fullpath; + fullpath_str.size = pathlen + baselen; + + if (git_path_validate_str_length(repo, &fullpath_str) < 0) return -1; ce->path = &ce->fullpath[baselen]; @@ -173,7 +178,7 @@ static int attr_cache_lookup( git_str *p = attr_session ? &attr_session->tmp : &path; if (git_str_joinpath(p, source->base, source->filename) < 0 || - git_fs_path_validate_workdir_buf(repo, p) < 0) + git_path_validate_str_length(repo, p) < 0) return -1; filename = p->ptr; diff --git a/src/checkout.c b/src/checkout.c index ad4edddd3..5733f4ab5 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -329,7 +329,7 @@ static int checkout_target_fullpath( if (path && git_str_puts(&data->target_path, path) < 0) return -1; - if (git_fs_path_validate_workdir_buf(data->repo, &data->target_path) < 0) + if (git_path_validate_str_length(data->repo, &data->target_path) < 0) return -1; *out = &data->target_path; @@ -2035,7 +2035,7 @@ static int checkout_merge_path( int error = 0; if ((error = git_str_joinpath(out, data->opts.target_directory, result->path)) < 0 || - (error = git_fs_path_validate_workdir_buf(data->repo, out)) < 0) + (error = git_path_validate_str_length(data->repo, out)) < 0) return error; /* Most conflicts simply use the filename in the index */ @@ -2338,7 +2338,7 @@ static int validate_target_directory(checkout_data *data) { int error; - if ((error = git_fs_path_validate_workdir(data->repo, data->opts.target_directory)) < 0) + if ((error = git_path_validate_length(data->repo, data->opts.target_directory)) < 0) return error; if (git_fs_path_isdir(data->opts.target_directory)) diff --git a/src/filter.c b/src/filter.c index 950296033..2712e8c60 100644 --- a/src/filter.c +++ b/src/filter.c @@ -18,6 +18,7 @@ #include "blob.h" #include "attr_file.h" #include "array.h" +#include "path.h" struct git_filter_source { git_repository *repo; @@ -1095,7 +1096,7 @@ int git_filter_list_stream_file( if ((error = stream_list_init( &stream_start, &filter_streams, filters, target)) < 0 || (error = git_fs_path_join_unrooted(&abspath, path, base, NULL)) < 0 || - (error = git_fs_path_validate_workdir_buf(repo, &abspath)) < 0) + (error = git_path_validate_str_length(repo, &abspath)) < 0) goto done; initialized = 1; diff --git a/src/ignore.c b/src/ignore.c index e7d8b799f..cee58d7f1 100644 --- a/src/ignore.c +++ b/src/ignore.c @@ -13,6 +13,7 @@ #include "fs_path.h" #include "config.h" #include "wildmatch.h" +#include "path.h" #define GIT_IGNORE_INTERNAL "[internal]exclude" @@ -320,14 +321,14 @@ int git_ignore__for_path( (error = git_fs_path_resolve_relative(&local, 0)) < 0 || (error = git_fs_path_to_dir(&local)) < 0 || (error = git_str_joinpath(&ignores->dir, workdir, local.ptr)) < 0 || - (error = git_fs_path_validate_workdir_buf(repo, &ignores->dir)) < 0) { + (error = git_path_validate_str_length(repo, &ignores->dir)) < 0) { /* Nothing, we just want to stop on the first error */ } git_str_dispose(&local); } else { if (!(error = git_str_joinpath(&ignores->dir, path, ""))) - error = git_fs_path_validate_filesystem(ignores->dir.ptr, ignores->dir.size); + error = git_path_validate_str_length(NULL, &ignores->dir); } if (error < 0) diff --git a/src/iterator.c b/src/iterator.c index a627e0f88..a4337bb9a 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -9,6 +9,7 @@ #include "tree.h" #include "index.h" +#include "path.h" #define GIT_ITERATOR_FIRST_ACCESS (1 << 15) #define GIT_ITERATOR_HONOR_IGNORES (1 << 16) @@ -1279,7 +1280,7 @@ static int filesystem_iterator_entry_hash( iter->base.repo, entry->path, GIT_OBJECT_BLOB, NULL); if (!(error = git_str_joinpath(&fullpath, iter->root, entry->path)) && - !(error = git_fs_path_validate_workdir_buf(iter->base.repo, &fullpath))) + !(error = git_path_validate_str_length(iter->base.repo, &fullpath))) error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB); git_str_dispose(&fullpath); @@ -1361,7 +1362,7 @@ static int filesystem_iterator_frame_push( git_str_puts(&root, iter->root); if (git_str_oom(&root) || - git_fs_path_validate_workdir_buf(iter->base.repo, &root) < 0) { + git_path_validate_str_length(iter->base.repo, &root) < 0) { error = -1; goto done; } @@ -1389,10 +1390,16 @@ static int filesystem_iterator_frame_push( while ((error = git_fs_path_diriter_next(&diriter)) == 0) { iterator_pathlist_search_t pathlist_match = ITERATOR_PATHLIST_FULL; + git_str path_str = GIT_STR_INIT; bool dir_expected = false; - if ((error = git_fs_path_diriter_fullpath(&path, &path_len, &diriter)) < 0 || - (error = git_fs_path_validate_workdir_with_len(iter->base.repo, path, path_len)) < 0) + if ((error = git_fs_path_diriter_fullpath(&path, &path_len, &diriter)) < 0) + goto done; + + path_str.ptr = (char *)path; + path_str.size = path_len; + + if ((error = git_path_validate_str_length(iter->base.repo, &path_str)) < 0) goto done; GIT_ASSERT(path_len > iter->root_len); @@ -1565,7 +1572,7 @@ static int filesystem_iterator_is_dir( } if ((error = git_str_joinpath(&fullpath, iter->root, entry->path)) < 0 || - (error = git_fs_path_validate_workdir_buf(iter->base.repo, &fullpath)) < 0 || + (error = git_path_validate_str_length(iter->base.repo, &fullpath)) < 0 || (error = p_stat(fullpath.ptr, &st)) < 0) goto done; diff --git a/src/mailmap.c b/src/mailmap.c index 4fbb1ae77..4336fe3e5 100644 --- a/src/mailmap.c +++ b/src/mailmap.c @@ -16,6 +16,7 @@ #include "git2/revparse.h" #include "blob.h" #include "parse.h" +#include "path.h" #define MM_FILE ".mailmap" #define MM_FILE_CONFIG "mailmap.file" @@ -331,7 +332,7 @@ static int mailmap_add_file_ondisk( if (error < 0) goto cleanup; - error = git_fs_path_validate_workdir_buf(repo, &fullpath); + error = git_path_validate_str_length(repo, &fullpath); if (error < 0) goto cleanup; diff --git a/src/refdb_fs.c b/src/refdb_fs.c index acd627091..dc291d0f5 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -1362,7 +1362,7 @@ static int refdb_fs_backend__prune_refs( git_str_cstr(&relative_path)); if (!error) - error = git_fs_path_validate_filesystem(base_path.ptr, base_path.size); + error = git_path_validate_str_length(NULL, &base_path); if (error < 0) goto cleanup; diff --git a/src/repository.c b/src/repository.c index 2f7ae9b3d..f564453db 100644 --- a/src/repository.c +++ b/src/repository.c @@ -32,7 +32,7 @@ #include "annotated_commit.h" #include "submodule.h" #include "worktree.h" - +#include "path.h" #include "strmap.h" #ifdef GIT_WIN32 @@ -2662,7 +2662,7 @@ int git_repository_workdir_path( } if (!(error = git_str_joinpath(out, repo->workdir, path))) - error = git_fs_path_validate_workdir_buf(repo, out); + error = git_path_validate_str_length(repo, out); return error; } @@ -2858,7 +2858,7 @@ int git_repository_hashfile( GIT_ASSERT_ARG(repo); if ((error = git_fs_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 || - (error = git_fs_path_validate_workdir_buf(repo, &full_path)) < 0) + (error = git_path_validate_str_length(repo, &full_path)) < 0) return error; /* diff --git a/src/submodule.c b/src/submodule.c index ffe29ccfb..0370ac82b 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -386,7 +386,7 @@ int git_submodule__lookup_with_cache( if (git_str_join3(&path, '/', git_repository_workdir(repo), name, DOT_GIT) < 0 || - git_fs_path_validate_workdir_buf(NULL, &path) < 0) + git_path_validate_str_length(NULL, &path) < 0) return -1; if (git_fs_path_exists(path.ptr)) diff --git a/src/worktree.c b/src/worktree.c index f0fc6d752..e08d6d401 100644 --- a/src/worktree.c +++ b/src/worktree.c @@ -9,6 +9,7 @@ #include "buf.h" #include "repository.h" +#include "path.h" #include "git2/branch.h" #include "git2/commit.h" @@ -136,7 +137,7 @@ static int open_worktree_dir(git_worktree **out, const char *parent, const char goto out; } - if ((error = git_fs_path_validate_workdir(NULL, dir)) < 0) + if ((error = git_path_validate_length(NULL, dir)) < 0) goto out; if ((wt = git__calloc(1, sizeof(*wt))) == NULL) { -- cgit v1.2.1 From 622514095fd1d731d35b0d69608911445ba3b0c4 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 1 Nov 2021 21:09:17 -0400 Subject: fs_path: add length with suffix validation --- src/fs_path.c | 23 +++++++++++++++++++++++ src/fs_path.h | 4 ++++ src/refdb_fs.c | 2 +- src/repository.c | 4 ++-- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/fs_path.c b/src/fs_path.c index 9079c30c9..56980148e 100644 --- a/src/fs_path.c +++ b/src/fs_path.c @@ -1715,6 +1715,29 @@ bool git_fs_path_str_is_valid_ext( return true; } +int git_fs_path_validate_str_length_with_suffix( + git_str *path, + size_t suffix_len) +{ +#ifdef GIT_WIN32 + size_t utf8_len = git_utf8_char_length(path->ptr, path->size); + size_t total_len; + + if (GIT_ADD_SIZET_OVERFLOW(&total_len, utf8_len, suffix_len) || + total_len > MAX_PATH) { + + git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%.*s'", + (int)path->size, path->ptr); + return -1; + } +#else + GIT_UNUSED(path); + GIT_UNUSED(suffix_len); +#endif + + return 0; +} + #ifdef GIT_WIN32 GIT_INLINE(bool) should_validate_longpaths(git_repository *repo) { diff --git a/src/fs_path.h b/src/fs_path.h index 947c4ae86..116e8f912 100644 --- a/src/fs_path.h +++ b/src/fs_path.h @@ -677,6 +677,10 @@ GIT_INLINE(bool) git_fs_path_str_is_valid( return git_fs_path_str_is_valid_ext(path, flags, NULL, NULL, NULL, NULL); } +extern int git_fs_path_validate_str_length_with_suffix( + git_str *path, + size_t suffix_len); + /** * Validate an on-disk path, taking into account that it will have a * suffix appended (eg, `.lock`). diff --git a/src/refdb_fs.c b/src/refdb_fs.c index dc291d0f5..097d2b38e 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -77,7 +77,7 @@ GIT_INLINE(int) loose_path( if (git_str_joinpath(out, base, refname) < 0) return -1; - return git_fs_path_validate_filesystem_with_suffix(out->ptr, out->size, + return git_fs_path_validate_str_length_with_suffix(out, CONST_STRLEN(".lock")); } diff --git a/src/repository.c b/src/repository.c index f564453db..3b3f7ca82 100644 --- a/src/repository.c +++ b/src/repository.c @@ -240,8 +240,8 @@ GIT_INLINE(int) validate_repo_path(git_str *path) CONST_STRLEN("objects/pack/pack-.pack.lock") + GIT_OID_HEXSZ; - return git_fs_path_validate_filesystem_with_suffix( - path->ptr, path->size, suffix_len); + return git_fs_path_validate_str_length_with_suffix( + path, suffix_len); } /* -- cgit v1.2.1 From 1217c5b232a2343f711ecf4c4ed38211ee6a268a Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 1 Nov 2021 21:12:23 -0400 Subject: fs_path: remove now-unused validation functions --- src/fs_path.c | 46 ---------------------------------------------- src/fs_path.h | 22 ---------------------- 2 files changed, 68 deletions(-) diff --git a/src/fs_path.c b/src/fs_path.c index 56980148e..957f389cc 100644 --- a/src/fs_path.c +++ b/src/fs_path.c @@ -1738,52 +1738,6 @@ int git_fs_path_validate_str_length_with_suffix( return 0; } -#ifdef GIT_WIN32 -GIT_INLINE(bool) should_validate_longpaths(git_repository *repo) -{ - int longpaths = 0; - - if (repo && - git_repository__configmap_lookup(&longpaths, repo, GIT_CONFIGMAP_LONGPATHS) < 0) - longpaths = 0; - - return (longpaths == 0); -} - -#else - -GIT_INLINE(bool) should_validate_longpaths(git_repository *repo) -{ - GIT_UNUSED(repo); - - return false; -} -#endif - -int git_fs_path_validate_workdir(git_repository *repo, const char *path) -{ - if (should_validate_longpaths(repo)) - return git_fs_path_validate_filesystem(path, strlen(path)); - - return 0; -} - -int git_fs_path_validate_workdir_with_len( - git_repository *repo, - const char *path, - size_t path_len) -{ - if (should_validate_longpaths(repo)) - return git_fs_path_validate_filesystem(path, path_len); - - return 0; -} - -int git_fs_path_validate_workdir_buf(git_repository *repo, git_str *path) -{ - return git_fs_path_validate_workdir_with_len(repo, path->ptr, path->size); -} - int git_fs_path_normalize_slashes(git_str *out, const char *path) { int error; diff --git a/src/fs_path.h b/src/fs_path.h index 116e8f912..dcedd5eb5 100644 --- a/src/fs_path.h +++ b/src/fs_path.h @@ -725,28 +725,6 @@ GIT_INLINE(int) git_fs_path_validate_filesystem( return git_fs_path_validate_filesystem_with_suffix(path, path_len, 0); } -/** - * Validate a path relative to the repo's worktree. This ensures that - * the given working tree path is valid for the operating system/platform. - * This will ensure that an absolute path is smaller than MAX_PATH on - * Windows, while keeping `core.longpaths` configuration settings in mind. - * - * This should be checked by mechamisms like `git_checkout` after - * contructing on-disk paths and before trying to write them. - * - * If the repository is null, no repository configuration is applied. - */ -extern int git_fs_path_validate_workdir( - git_repository *repo, - const char *path); -extern int git_fs_path_validate_workdir_with_len( - git_repository *repo, - const char *path, - size_t path_len); -extern int git_fs_path_validate_workdir_buf( - git_repository *repo, - git_str *buf); - /** * Convert any backslashes into slashes */ -- cgit v1.2.1 From 1a8b2922d953e78bd51fc6d5ef290e1f7e00af3a Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Tue, 9 Nov 2021 14:15:32 +0000 Subject: win32: include correct path header --- src/fs_path.h | 1 + src/win32/findfile.c | 2 +- src/win32/path_w32.c | 2 +- src/win32/posix_w32.c | 3 +-- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fs_path.h b/src/fs_path.h index dcedd5eb5..188dcf303 100644 --- a/src/fs_path.h +++ b/src/fs_path.h @@ -12,6 +12,7 @@ #include "posix.h" #include "str.h" #include "vector.h" +#include "utf8.h" #include "git2/sys/path.h" diff --git a/src/win32/findfile.c b/src/win32/findfile.c index 7578d960e..d4afc4acc 100644 --- a/src/win32/findfile.c +++ b/src/win32/findfile.c @@ -9,7 +9,7 @@ #include "path_w32.h" #include "utf-conv.h" -#include "path.h" +#include "fs_path.h" #define REG_MSYSGIT_INSTALL_LOCAL L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1" diff --git a/src/win32/path_w32.c b/src/win32/path_w32.c index 1f765f1de..5d7ad11f6 100644 --- a/src/win32/path_w32.c +++ b/src/win32/path_w32.c @@ -7,7 +7,7 @@ #include "path_w32.h" -#include "path.h" +#include "fs_path.h" #include "utf-conv.h" #include "posix.h" #include "reparse.h" diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index 398287f9e..ba46b5ea9 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -9,10 +9,9 @@ #include "../posix.h" #include "../futils.h" -#include "path.h" +#include "fs_path.h" #include "path_w32.h" #include "utf-conv.h" -#include "repository.h" #include "reparse.h" #include #include -- cgit v1.2.1 From 644c763b761eca2653b567515cc4b59262d58428 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Thu, 11 Nov 2021 00:30:40 +0100 Subject: Document that `git_odb` is thread-safe Commit 4ae41f9c639d246d34dac89c3f1d9451c9cfa8d3 made `git_odb` race-free, and added internal locking. Update `docs/threading.md` accordingly, so that APIs built atop libgit2 (e.g. language bindings) can count on this. --- docs/threading.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/threading.md b/docs/threading.md index ddfaf7ae5..de085c807 100644 --- a/docs/threading.md +++ b/docs/threading.md @@ -21,6 +21,9 @@ There are some objects which are read-only/immutable and are thus safe to share across threads, such as references and configuration snapshots. +The `git_odb` object uses locking internally, and is thread-safe to use from +multiple threads simultaneously. + Error messages -------------- -- cgit v1.2.1 From 08047ca0121f8e6d82ed4ed5fafa13127285050d Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 19:56:31 +0000 Subject: str: git_str_free is never a function --- src/str.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/str.c b/src/str.c index 7b50800c1..9d579f144 100644 --- a/src/str.c +++ b/src/str.c @@ -132,13 +132,6 @@ void git_str_dispose(git_str *buf) git_str_init(buf, 0); } -#ifndef GIT_DEPRECATE_HARD -void git_str_free(git_str *buf) -{ - git_str_dispose(buf); -} -#endif - void git_str_clear(git_str *buf) { buf->size = 0; -- cgit v1.2.1 From 9324d16e7356c1928d577a719eaaad264da58b13 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sat, 6 Nov 2021 16:14:47 -0400 Subject: cmake: standardize USE_THREADS and USE_NSEC Threading can now be disabled with `USE_THREADS=OFF` instead of `THREADSAFE=OFF` to better support the other cmake semantics. Nanosecond support is the default _if_ we can detect it. This should be our default always - like threads - and people can opt out explicitly. --- CMakeLists.txt | 25 ++++++++++++++----------- README.md | 2 +- cmake/FindStatNsec.cmake | 30 ++++++++++++------------------ docs/error-handling.md | 2 +- src/CMakeLists.txt | 6 +++--- src/thread.h | 4 ++-- 6 files changed, 33 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f7b2e71ca..2c442d2a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.5.1) project(libgit2 VERSION "1.3.0" LANGUAGES C) # Add find modules to the path -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake/") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake") # Modules @@ -30,12 +30,15 @@ include(EnableWarnings) # # Optional subsystems -option(THREADSAFE "Build libgit2 as threadsafe" ON) option(BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON) option(BUILD_TESTS "Build Tests using the Clar suite" ON) option(BUILD_EXAMPLES "Build library usage example apps" OFF) option(BUILD_FUZZERS "Build the fuzz targets" OFF) +# Suggested functionality that may not be available on a per-platform basis +option(USE_THREADS "Use threads for parallel processing when possible" ON) +option(USE_NSEC "Support nanosecond precision file mtimes and ctimes" ON) + # Backend selection option(USE_SSH "Link with libssh2 to enable SSH support" ON) option(USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON) @@ -55,7 +58,7 @@ option(DEBUG_STRICT_OPEN "Enable path validation in open" # Output options option(SONAME "Set the (SO)VERSION of the target" ON) option(LIBGIT2_FILENAME "Name of the produced binary" OFF) -option(DEPRECATE_HARD "Do not include deprecated functions in the library" OFF) +option(DEPRECATE_HARD "Do not include deprecated functions in the library" OFF) # Compilation options option(ENABLE_WERROR "Enable compilation with -Werror" OFF) @@ -63,35 +66,35 @@ option(ENABLE_WERROR "Enable compilation with -Werror" if(UNIX) # NTLM client requires crypto libraries from the system HTTPS stack if(NOT USE_HTTPS) - option(USE_NTLMCLIENT "Enable NTLM support on Unix." OFF) + option(USE_NTLMCLIENT "Enable NTLM support on Unix." OFF) else() - option(USE_NTLMCLIENT "Enable NTLM support on Unix." ON) + option(USE_NTLMCLIENT "Enable NTLM support on Unix." ON) endif() - option(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF) + option(ENABLE_REPRODUCIBLE_BUILDS "Enable reproducible builds" OFF) endif() if(APPLE) - option(USE_ICONV "Link with and use iconv library" ON) + option(USE_ICONV "Link with and use iconv library" ON) endif() if(MSVC) # This option must match the settings used in your program, in particular if you # are linking statically - option(STATIC_CRT "Link the static CRT libraries" ON) + option(STATIC_CRT "Link the static CRT libraries" ON) # If you want to embed a copy of libssh2 into libgit2, pass a # path to libssh2 - option(EMBED_SSH_PATH "Path to libssh2 to embed (Windows)" OFF) + option(EMBED_SSH_PATH "Path to libssh2 to embed (Windows)" OFF) # Enable leak checking using the debugging C runtime. - option(WIN32_LEAKCHECK "Enable leak reporting via crtdbg" OFF) + option(WIN32_LEAKCHECK "Enable leak reporting via crtdbg" OFF) endif() if(WIN32) # By default, libgit2 is built with WinHTTP. To use the built-in # HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument. - option(WINHTTP "Use Win32 WinHTTP routines" ON) + option(WINHTTP "Use Win32 WinHTTP routines" ON) endif() diff --git a/README.md b/README.md index 2a365df30..7ed5f6c80 100644 --- a/README.md +++ b/README.md @@ -279,7 +279,7 @@ The following CMake variables are declared: - `CMAKE_INSTALL_INCLUDEDIR`: Where to install headers to. - `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON) - `BUILD_TESTS`: Build the unit and integration test suites (defaults to ON) -- `THREADSAFE`: Build libgit2 with threading support (defaults to ON) +- `USE_THREADS`: Build libgit2 with threading support (defaults to ON) To list all build options and their current value, you can do the following: diff --git a/cmake/FindStatNsec.cmake b/cmake/FindStatNsec.cmake index a4a09fa81..9dfdf51c4 100644 --- a/cmake/FindStatNsec.cmake +++ b/cmake/FindStatNsec.cmake @@ -1,26 +1,20 @@ -INCLUDE(FeatureSummary) +include(FeatureSummary) -CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim "sys/types.h;sys/stat.h" +check_struct_has_member("struct stat" st_mtim "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C) -CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec "sys/types.h;sys/stat.h" +check_struct_has_member("struct stat" st_mtimespec "sys/types.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE C) -CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtime_nsec sys/stat.h +check_struct_has_member("struct stat" st_mtime_nsec sys/stat.h HAVE_STRUCT_STAT_MTIME_NSEC LANGUAGE C) -IF (HAVE_STRUCT_STAT_ST_MTIM) - CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h +if(HAVE_STRUCT_STAT_ST_MTIM) + check_struct_has_member("struct stat" st_mtim.tv_nsec sys/stat.h HAVE_STRUCT_STAT_NSEC LANGUAGE C) -ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC) - CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec sys/stat.h +elseif(HAVE_STRUCT_STAT_ST_MTIMESPEC) + check_struct_has_member("struct stat" st_mtimespec.tv_nsec sys/stat.h HAVE_STRUCT_STAT_NSEC LANGUAGE C) -ELSE () - SET( HAVE_STRUCT_STAT_NSEC ON ) -ENDIF() +else() + set(HAVE_STRUCT_STAT_NSEC ON ) +endif() -IF (HAVE_STRUCT_STAT_NSEC OR WIN32) - OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" ON ) -ELSE() - SET(USE_NSEC OFF) -ENDIF() - -ADD_FEATURE_INFO(nanoseconds USE_NSEC "whether to use sub-second file mtimes and ctimes") +add_feature_info(nanoseconds USE_NSEC "support nanosecond precision file mtimes and ctimes") diff --git a/docs/error-handling.md b/docs/error-handling.md index 05725f2ed..13ce78f5f 100644 --- a/docs/error-handling.md +++ b/docs/error-handling.md @@ -21,7 +21,7 @@ critical failures (such as a packfile being corrupted, a loose object having the wrong access permissions, etc.) all of which will return -1. When the object lookup is successful, it will return 0. -If libgit2 was compiled with threads enabled (`-DTHREADSAFE=ON` when using +If libgit2 was compiled with threads enabled (`-DUSE_THREADS=ON` when using CMake), then the error message will be kept in thread-local storage, so it will not be modified by other threads. If threads are not enabled, then the error message is in global data. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9812fc0e4..de8beefd8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -81,11 +81,11 @@ if(NEED_LIBRT) list(APPEND LIBGIT2_PC_LIBS "-lrt") endif() -if(THREADSAFE) +if(USE_THREADS) list(APPEND LIBGIT2_LIBS ${CMAKE_THREAD_LIBS_INIT}) list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT}) endif() -add_feature_info(threadsafe THREADSAFE "threadsafe support") +add_feature_info(threadsafe USE_THREADS "threadsafe support") if(WIN32 AND EMBED_SSH_PATH) @@ -277,7 +277,7 @@ endif() add_feature_info(iconv GIT_USE_ICONV "iconv encoding conversion support") -if(THREADSAFE) +if(USE_THREADS) if(NOT WIN32) find_package(Threads REQUIRED) endif() diff --git a/src/thread.h b/src/thread.h index 4b091c0a2..82eb7fcab 100644 --- a/src/thread.h +++ b/src/thread.h @@ -12,7 +12,7 @@ #if defined(__clang__) # if (__clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 1)) -# error Atomic primitives do not exist on this version of clang; configure libgit2 with -DTHREADSAFE=OFF +# error Atomic primitives do not exist on this version of clang; configure libgit2 with -DUSE_THREADS=OFF # else # define GIT_BUILTIN_ATOMIC # endif @@ -20,7 +20,7 @@ #elif defined(__GNUC__) # if (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 1)) -# error Atomic primitives do not exist on this version of gcc; configure libgit2 with -DTHREADSAFE=OFF +# error Atomic primitives do not exist on this version of gcc; configure libgit2 with -DUSE_THREADS=OFF # elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) # define GIT_BUILTIN_ATOMIC # else -- cgit v1.2.1 From 789ab915607c3d91d8c04fd217de9bf37c631f5f Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 10 Nov 2021 21:02:42 -0500 Subject: cmake: standardize USE_WINHTTP WinHTTP can now be disabled with `USE_WINHTTP=OFF` instead of `WINHTTP=OFF` to better support the other cmake semantics. --- CMakeLists.txt | 4 ++-- cmake/SelectHTTPSBackend.cmake | 2 +- src/CMakeLists.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c442d2a0..c8825e966 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,8 +93,8 @@ endif() if(WIN32) # By default, libgit2 is built with WinHTTP. To use the built-in - # HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument. - option(WINHTTP "Use Win32 WinHTTP routines" ON) + # HTTP transport, invoke CMake with the "-DUSE_WINHTTP=OFF" argument. + option(USE_WINHTTP "Use Win32 WinHTTP routines" ON) endif() diff --git a/cmake/SelectHTTPSBackend.cmake b/cmake/SelectHTTPSBackend.cmake index 4998f0f2a..4af747417 100644 --- a/cmake/SelectHTTPSBackend.cmake +++ b/cmake/SelectHTTPSBackend.cmake @@ -19,7 +19,7 @@ IF(USE_HTTPS) MESSAGE(STATUS "Security framework is too old, falling back to OpenSSL") SET(USE_HTTPS "OpenSSL") ENDIF() - ELSEIF (WINHTTP) + ELSEIF (USE_WINHTTP) SET(USE_HTTPS "WinHTTP") ELSEIF(OPENSSL_FOUND) SET(USE_HTTPS "OpenSSL") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index de8beefd8..eed04f8ee 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -98,7 +98,7 @@ if(WIN32 AND EMBED_SSH_PATH) set(GIT_SSH 1) endif() -if(WIN32 AND WINHTTP) +if(WIN32 AND USE_WINHTTP) set(GIT_WINHTTP 1) # Since MinGW does not come with headers or an import library for winhttp, -- cgit v1.2.1 From 6c00fcb767b38c1902c0b1ca15350e7c5766e23d Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 10 Nov 2021 17:32:41 -0500 Subject: cmake: USE_SSH is not on by default --- .github/workflows/main.yml | 14 +++++++------- .github/workflows/nightly.yml | 26 +++++++++++++------------- CMakeLists.txt | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e805b1bb8..6e342d116 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -91,7 +91,7 @@ jobs: env: CC: gcc CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DDEBUG_STRICT_ALLOC=ON -DDEBUG_STRICT_OPEN=ON + CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON -DDEBUG_STRICT_ALLOC=ON -DDEBUG_STRICT_OPEN=ON os: ubuntu-latest - # Xenial, GCC, mbedTLS container: @@ -99,7 +99,7 @@ jobs: env: CC: gcc CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON os: ubuntu-latest - # Xenial, Clang, OpenSSL container: @@ -107,14 +107,14 @@ jobs: env: CC: clang CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON os: ubuntu-latest - # Xenial, Clang, mbedTLS container: name: xenial env: CC: clang - CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON CMAKE_GENERATOR: Ninja os: ubuntu-latest - # Focal, Clang 10, mbedTLS, MemorySanitizer @@ -123,7 +123,7 @@ jobs: env: CC: clang-10 CFLAGS: -fsanitize=memory -fsanitize-memory-track-origins=2 -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer - CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local/msan -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON + CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local/msan -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON CMAKE_GENERATOR: Ninja SKIP_SSH_TESTS: true SKIP_NEGOTIATE_TESTS: true @@ -136,7 +136,7 @@ jobs: env: CC: clang-10 CFLAGS: -fsanitize=undefined,nullability -fno-sanitize-recover=undefined,nullability -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer - CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON + CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON CMAKE_GENERATOR: Ninja SKIP_SSH_TESTS: true SKIP_NEGOTIATE_TESTS: true @@ -149,7 +149,7 @@ jobs: env: CC: clang-10 CFLAGS: -fsanitize=thread -fno-optimize-sibling-calls -fno-omit-frame-pointer - CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON + CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON CMAKE_GENERATOR: Ninja SKIP_SSH_TESTS: true SKIP_NEGOTIATE_TESTS: true diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 47ebf464d..789f268f8 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -25,7 +25,7 @@ jobs: env: CC: gcc CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON os: ubuntu-latest - # Xenial, GCC, mbedTLS container: @@ -33,7 +33,7 @@ jobs: env: CC: gcc CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON os: ubuntu-latest - # Xenial, Clang, OpenSSL container: @@ -41,14 +41,14 @@ jobs: env: CC: clang CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON os: ubuntu-latest - # Xenial, Clang, mbedTLS container: name: xenial env: CC: clang - CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON CMAKE_GENERATOR: Ninja os: ubuntu-latest - # Xenial, GCC, thread-free @@ -56,7 +56,7 @@ jobs: name: xenial env: CC: gcc - CMAKE_OPTIONS: -DTHREADSAFE=OFF -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DTHREADSAFE=OFF -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON CMAKE_GENERATOR: Ninja os: ubuntu-latest - # Xenial, Clang, OpenSSL (dynamically loaded) @@ -64,7 +64,7 @@ jobs: name: xenial env: CC: clang - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON CMAKE_GENERATOR: Ninja os: ubuntu-latest - # Focal, Clang 10, mbedTLS, MemorySanitizer @@ -119,7 +119,7 @@ jobs: container: name: centos7 env: - CMAKE_OPTIONS: -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON PKG_CONFIG_PATH: /usr/local/lib/pkgconfig SKIP_NEGOTIATE_TESTS: true os: ubuntu-latest @@ -127,7 +127,7 @@ jobs: container: name: centos7 env: - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON PKG_CONFIG_PATH: /usr/local/lib/pkgconfig SKIP_NEGOTIATE_TESTS: true os: ubuntu-latest @@ -212,7 +212,7 @@ jobs: env: CC: gcc CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON RUN_INVASIVE_TESTS: true os: ubuntu-latest - # Bionic, x86, Clang, OpenSSL @@ -223,7 +223,7 @@ jobs: env: CC: clang CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON RUN_INVASIVE_TESTS: true os: ubuntu-latest - # Bionic, x86, GCC, OpenSSL @@ -233,7 +233,7 @@ jobs: env: CC: gcc CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON RUN_INVASIVE_TESTS: true os: ubuntu-latest - # Bionic, arm32, GCC, OpenSSL @@ -244,7 +244,7 @@ jobs: env: CC: gcc CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DUSE_SSH=ON RUN_INVASIVE_TESTS: true SKIP_PROXY_TESTS: true os: ubuntu-latest @@ -256,7 +256,7 @@ jobs: env: CC: gcc CMAKE_GENERATOR: Ninja - CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON + CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DUSE_SSH=ON RUN_INVASIVE_TESTS: true SKIP_PROXY_TESTS: true os: ubuntu-latest diff --git a/CMakeLists.txt b/CMakeLists.txt index c8825e966..040881f83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ option(USE_THREADS "Use threads for parallel processing when possibl option(USE_NSEC "Support nanosecond precision file mtimes and ctimes" ON) # Backend selection -option(USE_SSH "Link with libssh2 to enable SSH support" ON) +option(USE_SSH "Link with libssh2 to enable SSH support" OFF) option(USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON) option(USE_SHA1 "Enable SHA1. Can be set to CollisionDetection(ON)/HTTPS/Generic" ON) option(USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF) -- cgit v1.2.1 From 9f37457e17f1b1f9e899b757df3413180719005f Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sat, 6 Nov 2021 16:23:03 -0400 Subject: cmake: move cflag defaults into a separate module --- CMakeLists.txt | 189 +++++----------------------------------------- cmake/DefaultCFlags.cmake | 153 +++++++++++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+), 171 deletions(-) create mode 100644 cmake/DefaultCFlags.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 040881f83..f7f19468c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,23 +8,6 @@ project(libgit2 VERSION "1.3.0" LANGUAGES C) # Add find modules to the path set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake") -# Modules - -include(CheckLibraryExists) -include(CheckFunctionExists) -include(CheckSymbolExists) -include(CheckStructHasMember) -include(CheckPrototypeDefinition) -include(AddCFlagIfSupported) -include(FindPkgLibraries) -include(FindThreads) -include(FindStatNsec) -include(Findfutimens) -include(GNUInstallDirs) -include(IdeSplitSources) -include(FeatureSummary) -include(EnableWarnings) - # # Build options # @@ -98,6 +81,24 @@ if(WIN32) endif() +# Modules + +include(CheckLibraryExists) +include(CheckFunctionExists) +include(CheckSymbolExists) +include(CheckStructHasMember) +include(CheckPrototypeDefinition) +include(AddCFlagIfSupported) +include(FindPkgLibraries) +include(FindThreads) +include(FindStatNsec) +include(Findfutimens) +include(GNUInstallDirs) +include(IdeSplitSources) +include(FeatureSummary) +include(EnableWarnings) +include(DefaultCFlags) + # # Compiler / linker flags # @@ -106,160 +107,6 @@ if(DEPRECATE_HARD) add_definitions(-DGIT_DEPRECATE_HARD) endif() -# Platform specific compilation flags -if(MSVC) - add_definitions(-D_SCL_SECURE_NO_WARNINGS) - add_definitions(-D_CRT_SECURE_NO_DEPRECATE) - add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) - - string(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") - - # /GF - String pooling - # /MP - Parallel build - set(CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS}") - - # /Gd - explicitly set cdecl calling convention - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gd") - - if(NOT (MSVC_VERSION LESS 1900)) - # /guard:cf - Enable Control Flow Guard - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:cf") - endif() - - if(STATIC_CRT) - set(CRT_FLAG_DEBUG "/MTd") - set(CRT_FLAG_RELEASE "/MT") - else() - set(CRT_FLAG_DEBUG "/MDd") - set(CRT_FLAG_RELEASE "/MD") - endif() - - if(WIN32_LEAKCHECK) - set(GIT_WIN32_LEAKCHECK 1) - set(CRT_FLAG_DEBUG "${CRT_FLAG_DEBUG}") - set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} Dbghelp.lib") - endif() - - # /Zi - Create debugging information - # /Od - Disable optimization - # /D_DEBUG - #define _DEBUG - # /MTd - Statically link the multithreaded debug version of the CRT - # /MDd - Dynamically link the multithreaded debug version of the CRT - # /RTC1 - Run time checks - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG}") - - # /DNDEBUG - Disables asserts - # /MT - Statically link the multithreaded release version of the CRT - # /MD - Dynamically link the multithreaded release version of the CRT - # /O2 - Optimize for speed - # /Oy - Enable frame pointer omission (FPO) (otherwise CMake will automatically turn it off) - # /GL - Link time code generation (whole program optimization) - # /Gy - Function-level linking - set(CMAKE_C_FLAGS_RELEASE "/DNDEBUG /O2 /Oy /GL /Gy ${CRT_FLAG_RELEASE}") - - # /Oy- - Disable frame pointer omission (FPO) - set(CMAKE_C_FLAGS_RELWITHDEBINFO "/DNDEBUG /Zi /O2 /Oy- /GL /Gy ${CRT_FLAG_RELEASE}") - - # /O1 - Optimize for size - set(CMAKE_C_FLAGS_MINSIZEREL "/DNDEBUG /O1 /Oy /GL /Gy ${CRT_FLAG_RELEASE}") - - # /IGNORE:4221 - Ignore empty compilation units - set(CMAKE_STATIC_LINKER_FLAGS "/IGNORE:4221") - - # /DYNAMICBASE - Address space load randomization (ASLR) - # /NXCOMPAT - Data execution prevention (DEP) - # /LARGEADDRESSAWARE - >2GB user address space on x86 - # /VERSION - Embed version information in PE header - set(CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}") - - if(NOT (MSVC_VERSION LESS 1900)) - # /GUARD:CF - Enable Control Flow Guard - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /GUARD:CF") - endif() - - # /DEBUG - Create a PDB - # /LTCG - Link time code generation (whole program optimization) - # /OPT:REF /OPT:ICF - Fold out duplicate code at link step - # /INCREMENTAL:NO - Required to use /LTCG - # /DEBUGTYPE:cv,fixup - Additional data embedded in the PDB (requires /INCREMENTAL:NO, so not on for Debug) - set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG") - set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO") - set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup") - set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO") - - # Same linker settings for DLL as EXE - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") - set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") - set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") - set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}") - set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}") -else() - if(ENABLE_REPRODUCIBLE_BUILDS) - set(CMAKE_C_ARCHIVE_CREATE " Dqc ") - set(CMAKE_C_ARCHIVE_APPEND " Dq ") - set(CMAKE_C_ARCHIVE_FINISH " -D ") - endif() - - if(NOT BUILD_SHARED_LIBS) - set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") - endif() - - set(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}") - - enable_warnings(all) - enable_warnings(extra) - - if(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") - set(CMAKE_C_FLAGS "-D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}") - endif() - - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -O0") - - if(MINGW OR MSYS) # MinGW and MSYS always do PIC and complain if we tell them to - string(REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}") - elseif(BUILD_SHARED_LIBS) - add_c_flag_IF_SUPPORTED(-fvisibility=hidden) - - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - endif() - - if(MINGW) - # MinGW >= 3.14 uses the C99-style stdio functions - # automatically, but forks like mingw-w64 still want - # us to define this in order to use them - add_definitions(-D__USE_MINGW_ANSI_STDIO=1) - endif() - - enable_warnings(documentation) - disable_warnings(documentation-deprecated-sync) - disable_warnings(missing-field-initializers) - enable_warnings(strict-aliasing) - enable_warnings(strict-prototypes) - enable_warnings(declaration-after-statement) - enable_warnings(shift-count-overflow) - enable_warnings(unused-const-variable) - enable_warnings(unused-function) - enable_warnings(int-conversion) - enable_warnings(c11-extensions) - enable_warnings(c99-c11-compat) - - # MinGW uses gcc, which expects POSIX formatting for printf, but - # uses the Windows C library, which uses its own format specifiers. - # Disable format specifier warnings. - if(MINGW) - disable_warnings(format) - disable_warnings(format-security) - else() - enable_warnings(format) - enable_warnings(format-security) - endif() -endif() - -# Ensure that MinGW provides the correct header files. -if(WIN32 AND NOT CYGWIN) - add_definitions(-DWIN32 -D_WIN32_WINNT=0x0600) -endif() - if(NOT CMAKE_CONFIGURATION_TYPES) # Build Debug by default if(NOT CMAKE_BUILD_TYPE) diff --git a/cmake/DefaultCFlags.cmake b/cmake/DefaultCFlags.cmake new file mode 100644 index 000000000..d122f6c25 --- /dev/null +++ b/cmake/DefaultCFlags.cmake @@ -0,0 +1,153 @@ +# Platform specific compilation flags +if(MSVC) + add_definitions(-D_SCL_SECURE_NO_WARNINGS) + add_definitions(-D_CRT_SECURE_NO_DEPRECATE) + add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) + + string(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + + # /GF - String pooling + # /MP - Parallel build + set(CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS}") + + # /Gd - explicitly set cdecl calling convention + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gd") + + if(NOT (MSVC_VERSION LESS 1900)) + # /guard:cf - Enable Control Flow Guard + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:cf") + endif() + + if(STATIC_CRT) + set(CRT_FLAG_DEBUG "/MTd") + set(CRT_FLAG_RELEASE "/MT") + else() + set(CRT_FLAG_DEBUG "/MDd") + set(CRT_FLAG_RELEASE "/MD") + endif() + + if(WIN32_LEAKCHECK) + set(GIT_WIN32_LEAKCHECK 1) + set(CRT_FLAG_DEBUG "${CRT_FLAG_DEBUG}") + set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} Dbghelp.lib") + endif() + + # /Zi - Create debugging information + # /Od - Disable optimization + # /D_DEBUG - #define _DEBUG + # /MTd - Statically link the multithreaded debug version of the CRT + # /MDd - Dynamically link the multithreaded debug version of the CRT + # /RTC1 - Run time checks + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG}") + + # /DNDEBUG - Disables asserts + # /MT - Statically link the multithreaded release version of the CRT + # /MD - Dynamically link the multithreaded release version of the CRT + # /O2 - Optimize for speed + # /Oy - Enable frame pointer omission (FPO) (otherwise CMake will automatically turn it off) + # /GL - Link time code generation (whole program optimization) + # /Gy - Function-level linking + set(CMAKE_C_FLAGS_RELEASE "/DNDEBUG /O2 /Oy /GL /Gy ${CRT_FLAG_RELEASE}") + + # /Oy- - Disable frame pointer omission (FPO) + set(CMAKE_C_FLAGS_RELWITHDEBINFO "/DNDEBUG /Zi /O2 /Oy- /GL /Gy ${CRT_FLAG_RELEASE}") + + # /O1 - Optimize for size + set(CMAKE_C_FLAGS_MINSIZEREL "/DNDEBUG /O1 /Oy /GL /Gy ${CRT_FLAG_RELEASE}") + + # /IGNORE:4221 - Ignore empty compilation units + set(CMAKE_STATIC_LINKER_FLAGS "/IGNORE:4221") + + # /DYNAMICBASE - Address space load randomization (ASLR) + # /NXCOMPAT - Data execution prevention (DEP) + # /LARGEADDRESSAWARE - >2GB user address space on x86 + # /VERSION - Embed version information in PE header + set(CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}") + + if(NOT (MSVC_VERSION LESS 1900)) + # /GUARD:CF - Enable Control Flow Guard + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /GUARD:CF") + endif() + + # /DEBUG - Create a PDB + # /LTCG - Link time code generation (whole program optimization) + # /OPT:REF /OPT:ICF - Fold out duplicate code at link step + # /INCREMENTAL:NO - Required to use /LTCG + # /DEBUGTYPE:cv,fixup - Additional data embedded in the PDB (requires /INCREMENTAL:NO, so not on for Debug) + set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO") + set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup") + set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO") + + # Same linker settings for DLL as EXE + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") + set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") + set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") + set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}") + set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}") +else() + if(ENABLE_REPRODUCIBLE_BUILDS) + set(CMAKE_C_ARCHIVE_CREATE " Dqc ") + set(CMAKE_C_ARCHIVE_APPEND " Dq ") + set(CMAKE_C_ARCHIVE_FINISH " -D ") + endif() + + if(NOT BUILD_SHARED_LIBS) + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") + endif() + + set(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}") + + enable_warnings(all) + enable_warnings(extra) + + if(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") + set(CMAKE_C_FLAGS "-D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}") + endif() + + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -O0") + + if(MINGW OR MSYS) # MinGW and MSYS always do PIC and complain if we tell them to + string(REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}") + elseif(BUILD_SHARED_LIBS) + add_c_flag_IF_SUPPORTED(-fvisibility=hidden) + + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") + endif() + + if(MINGW) + # MinGW >= 3.14 uses the C99-style stdio functions + # automatically, but forks like mingw-w64 still want + # us to define this in order to use them + add_definitions(-D__USE_MINGW_ANSI_STDIO=1) + endif() + + enable_warnings(documentation) + disable_warnings(documentation-deprecated-sync) + disable_warnings(missing-field-initializers) + enable_warnings(strict-aliasing) + enable_warnings(strict-prototypes) + enable_warnings(declaration-after-statement) + enable_warnings(shift-count-overflow) + enable_warnings(unused-const-variable) + enable_warnings(unused-function) + enable_warnings(int-conversion) + enable_warnings(c11-extensions) + enable_warnings(c99-c11-compat) + + # MinGW uses gcc, which expects POSIX formatting for printf, but + # uses the Windows C library, which uses its own format specifiers. + # Disable format specifier warnings. + if(MINGW) + disable_warnings(format) + disable_warnings(format-security) + else() + enable_warnings(format) + enable_warnings(format-security) + endif() +endif() + +# Ensure that MinGW provides the correct header files. +if(WIN32 AND NOT CYGWIN) + add_definitions(-DWIN32 -D_WIN32_WINNT=0x0600) +endif() -- cgit v1.2.1 From 7b527c12bc07d61fb6d2f0d7bb0b35815dbae49d Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sat, 6 Nov 2021 16:38:11 -0400 Subject: cmake: move deprecation definition to src/ There's no need to add the deprecation at the top-level. Our tests add deprecation explicitly. --- CMakeLists.txt | 4 ---- src/CMakeLists.txt | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f7f19468c..46506590e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,10 +103,6 @@ include(DefaultCFlags) # Compiler / linker flags # -if(DEPRECATE_HARD) - add_definitions(-DGIT_DEPRECATE_HARD) -endif() - if(NOT CMAKE_CONFIGURATION_TYPES) # Build Debug by default if(NOT CMAKE_BUILD_TYPE) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eed04f8ee..e7801165e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,10 @@ add_library(git2internal OBJECT) set_target_properties(git2internal PROPERTIES C_STANDARD 90) +if(DEPRECATE_HARD) + add_definitions(-DGIT_DEPRECATE_HARD) +endif() + if(DEBUG_POOL) set(GIT_DEBUG_POOL 1) endif() -- cgit v1.2.1 From 4d2a6839dc5b020b26ab8209952d95411eb34da5 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sat, 6 Nov 2021 16:38:57 -0400 Subject: cmake: move fuzzer args to the fuzzer's cmake --- CMakeLists.txt | 17 ++--------------- fuzzers/CMakeLists.txt | 3 +++ 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 46506590e..5421bd731 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,14 +113,6 @@ else() # that uses CMAKE_CONFIGURATION_TYPES and not CMAKE_BUILD_TYPE endif() -IF(BUILD_FUZZERS AND NOT USE_STANDALONE_FUZZERS) - # The actual sanitizer link target will be added when linking the fuzz - # targets. - set(CMAKE_REQUIRED_FLAGS "-fsanitize=fuzzer-no-link") - add_c_flag(-fsanitize=fuzzer-no-link) - unset(CMAKE_REQUIRED_FLAGS) -endif() - # # Subdirectories # @@ -137,13 +129,8 @@ if(BUILD_EXAMPLES) endif() if(BUILD_FUZZERS) - if(NOT USE_STANDALONE_FUZZERS) - if(BUILD_EXAMPLES) - message(FATAL_ERROR "Cannot build the fuzzer targets and the examples together") - endif() - if(BUILD_TESTS) - message(FATAL_ERROR "Cannot build the fuzzer targets and the tests together") - endif() + if((BUILD_TESTS OR BUILD_EXAMPLES) AND NOT USE_STANDALONE_FUZZERS) + message(FATAL_ERROR "Cannot build the fuzzer and the tests or examples together") endif() add_subdirectory(fuzzers) endif() diff --git a/fuzzers/CMakeLists.txt b/fuzzers/CMakeLists.txt index 8cc61b751..1479a2af8 100644 --- a/fuzzers/CMakeLists.txt +++ b/fuzzers/CMakeLists.txt @@ -3,7 +3,10 @@ include_directories(${LIBGIT2_INCLUDES}) include_directories(SYSTEM ${LIBGIT2_SYSTEM_INCLUDES}) if(BUILD_FUZZERS AND NOT USE_STANDALONE_FUZZERS) + set(CMAKE_REQUIRED_FLAGS "-fsanitize=fuzzer-no-link") add_c_flag(-fsanitize=fuzzer) + add_c_flag(-fsanitize=fuzzer-no-link) + unset(CMAKE_REQUIRED_FLAGS) endif() file(GLOB SRC_FUZZ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *_fuzzer.c) -- cgit v1.2.1 From 207beff5414a44bcde41535a905e51d5b774330b Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sat, 6 Nov 2021 16:43:04 -0400 Subject: cmake: reorganize file --- CMakeLists.txt | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5421bd731..23d09682d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,6 +80,10 @@ if(WIN32) option(USE_WINHTTP "Use Win32 WinHTTP routines" ON) endif() +if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) +endif() + # Modules @@ -99,19 +103,6 @@ include(FeatureSummary) include(EnableWarnings) include(DefaultCFlags) -# -# Compiler / linker flags -# - -if(NOT CMAKE_CONFIGURATION_TYPES) - # Build Debug by default - if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) - endif() -else() - # Using a multi-configuration generator eg MSVC or Xcode - # that uses CMAKE_CONFIGURATION_TYPES and not CMAKE_BUILD_TYPE -endif() # # Subdirectories @@ -135,6 +126,7 @@ if(BUILD_FUZZERS) add_subdirectory(fuzzers) endif() + # Summary feature_summary(WHAT ENABLED_FEATURES DESCRIPTION "Enabled features:") -- cgit v1.2.1 From d3a7a352d59e4075e979bfe9aea73f0f531c32eb Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sat, 6 Nov 2021 16:44:07 -0400 Subject: cmake: move test enablement into test cmake --- CMakeLists.txt | 1 - tests/CMakeLists.txt | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23d09682d..ae0a5d685 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,7 +111,6 @@ include(DefaultCFlags) add_subdirectory(src) if(BUILD_TESTS) - enable_testing() add_subdirectory(tests) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b85cd6ed3..760925fcf 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -62,6 +62,8 @@ function(ADD_CLAR_TEST name) endif() endfunction(ADD_CLAR_TEST) +enable_testing() + add_clar_test(offline -v -xonline) add_clar_test(invasive -v -score::ftruncate -sfilter::stream::bigfile -sodb::largefiles -siterator::workdir::filesystem_gunk -srepo::init -srepo::init::at_filesystem_root) add_clar_test(online -v -sonline -xonline::customcert) -- cgit v1.2.1 From 19e99de0540f4117d5ffdfbc058a406b376ec5ad Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 10 Nov 2021 08:14:11 -0500 Subject: cmake: qsort detection in features.h --- src/CMakeLists.txt | 15 +++------------ src/features.h.in | 4 ++++ src/util.c | 16 ++++++++-------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e7801165e..f3830efe5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -50,22 +50,13 @@ add_feature_info(futimens GIT_USE_FUTIMENS "futimens support") check_prototype_definition(qsort_r "void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *))" - "" "stdlib.h" HAVE_QSORT_R_BSD) -if(HAVE_QSORT_R_BSD) - target_compile_definitions(git2internal PRIVATE HAVE_QSORT_R_BSD) -endif() + "" "stdlib.h" GIT_QSORT_R_BSD) check_prototype_definition(qsort_r "void qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg)" - "" "stdlib.h" HAVE_QSORT_R_GNU) -if(HAVE_QSORT_R_GNU) - target_compile_definitions(git2internal PRIVATE HAVE_QSORT_R_GNU) -endif() + "" "stdlib.h" GIT_QSORT_R_GNU) -check_function_exists(qsort_s HAVE_QSORT_S) -if(HAVE_QSORT_S) - target_compile_definitions(git2internal PRIVATE HAVE_QSORT_S) -endif() +check_function_exists(qsort_s GIT_QSORT_S) # Find required dependencies diff --git a/src/features.h.in b/src/features.h.in index a40b6085e..81a8ae023 100644 --- a/src/features.h.in +++ b/src/features.h.in @@ -24,6 +24,10 @@ #cmakedefine GIT_REGEX_PCRE2 #cmakedefine GIT_REGEX_BUILTIN 1 +#cmakedefine GIT_QSORT_R_BSD +#cmakedefine GIT_QSORT_R_GNU +#cmakedefine GIT_QSORT_S + #cmakedefine GIT_SSH 1 #cmakedefine GIT_SSH_MEMORY_CREDENTIALS 1 diff --git a/src/util.c b/src/util.c index 2b1dadfe8..e06d4ca09 100644 --- a/src/util.c +++ b/src/util.c @@ -18,7 +18,7 @@ # endif # include -# ifdef HAVE_QSORT_S +# ifdef GIT_QSORT_S # include # endif #endif @@ -673,7 +673,7 @@ size_t git__unescape(char *str) return (pos - str); } -#if defined(HAVE_QSORT_S) || defined(HAVE_QSORT_R_BSD) +#if defined(GIT_QSORT_S) || defined(GIT_QSORT_R_BSD) typedef struct { git__sort_r_cmp cmp; void *payload; @@ -688,9 +688,9 @@ static int GIT_LIBGIT2_CALL git__qsort_r_glue_cmp( #endif -#if !defined(HAVE_QSORT_R_BSD) && \ - !defined(HAVE_QSORT_R_GNU) && \ - !defined(HAVE_QSORT_S) +#if !defined(GIT_QSORT_R_BSD) && \ + !defined(GIT_QSORT_R_GNU) && \ + !defined(GIT_QSORT_S) static void swap(uint8_t *a, uint8_t *b, size_t elsize) { char tmp[256]; @@ -721,12 +721,12 @@ static void insertsort( void git__qsort_r( void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload) { -#if defined(HAVE_QSORT_R_BSD) +#if defined(GIT_QSORT_R_BSD) git__qsort_r_glue glue = { cmp, payload }; qsort_r(els, nel, elsize, &glue, git__qsort_r_glue_cmp); -#elif defined(HAVE_QSORT_R_GNU) +#elif defined(GIT_QSORT_R_GNU) qsort_r(els, nel, elsize, cmp, payload); -#elif defined(HAVE_QSORT_S) +#elif defined(GIT_QSORT_S) git__qsort_r_glue glue = { cmp, payload }; qsort_s(els, nel, elsize, git__qsort_r_glue_cmp, &glue); #else -- cgit v1.2.1 From 16b6e3a9c992c1c1f22fa15cbf8238389f211b1c Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 10 Nov 2021 21:33:28 -0500 Subject: cmake: HTTP_Parser is now HTTPParser --- cmake/FindHTTPParser.cmake | 39 +++++++++++++++++++++++++++++++++++++++ cmake/FindHTTP_Parser.cmake | 39 --------------------------------------- src/CMakeLists.txt | 2 +- 3 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 cmake/FindHTTPParser.cmake delete mode 100644 cmake/FindHTTP_Parser.cmake diff --git a/cmake/FindHTTPParser.cmake b/cmake/FindHTTPParser.cmake new file mode 100644 index 000000000..d92bf75cc --- /dev/null +++ b/cmake/FindHTTPParser.cmake @@ -0,0 +1,39 @@ +# - Try to find http-parser +# +# Defines the following variables: +# +# HTTP_PARSER_FOUND - system has http-parser +# HTTP_PARSER_INCLUDE_DIR - the http-parser include directory +# HTTP_PARSER_LIBRARIES - Link these to use http-parser +# HTTP_PARSER_VERSION_MAJOR - major version +# HTTP_PARSER_VERSION_MINOR - minor version +# HTTP_PARSER_VERSION_STRING - the version of http-parser found + +# Find the header and library +FIND_PATH(HTTP_PARSER_INCLUDE_DIR NAMES http_parser.h) +FIND_LIBRARY(HTTP_PARSER_LIBRARY NAMES http_parser libhttp_parser) + +# Found the header, read version +if (HTTP_PARSER_INCLUDE_DIR AND EXISTS "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h") + FILE(READ "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h" HTTP_PARSER_H) + IF (HTTP_PARSER_H) + STRING(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MAJOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MAJOR "${HTTP_PARSER_H}") + STRING(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MINOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MINOR "${HTTP_PARSER_H}") + SET(HTTP_PARSER_VERSION_STRING "${HTTP_PARSER_VERSION_MAJOR}.${HTTP_PARSER_VERSION_MINOR}") + ENDIF() + UNSET(HTTP_PARSER_H) +ENDIF() + +# Handle the QUIETLY and REQUIRED arguments and set HTTP_PARSER_FOUND +# to TRUE if all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(HTTP_Parser REQUIRED_VARS HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY) + +# Hide advanced variables +MARK_AS_ADVANCED(HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY) + +# Set standard variables +IF (HTTP_PARSER_FOUND) + SET(HTTP_PARSER_LIBRARIES ${HTTP_PARSER_LIBRARY}) + set(HTTP_PARSER_INCLUDE_DIRS ${HTTP_PARSER_INCLUDE_DIR}) +ENDIF() diff --git a/cmake/FindHTTP_Parser.cmake b/cmake/FindHTTP_Parser.cmake deleted file mode 100644 index d92bf75cc..000000000 --- a/cmake/FindHTTP_Parser.cmake +++ /dev/null @@ -1,39 +0,0 @@ -# - Try to find http-parser -# -# Defines the following variables: -# -# HTTP_PARSER_FOUND - system has http-parser -# HTTP_PARSER_INCLUDE_DIR - the http-parser include directory -# HTTP_PARSER_LIBRARIES - Link these to use http-parser -# HTTP_PARSER_VERSION_MAJOR - major version -# HTTP_PARSER_VERSION_MINOR - minor version -# HTTP_PARSER_VERSION_STRING - the version of http-parser found - -# Find the header and library -FIND_PATH(HTTP_PARSER_INCLUDE_DIR NAMES http_parser.h) -FIND_LIBRARY(HTTP_PARSER_LIBRARY NAMES http_parser libhttp_parser) - -# Found the header, read version -if (HTTP_PARSER_INCLUDE_DIR AND EXISTS "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h") - FILE(READ "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h" HTTP_PARSER_H) - IF (HTTP_PARSER_H) - STRING(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MAJOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MAJOR "${HTTP_PARSER_H}") - STRING(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MINOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MINOR "${HTTP_PARSER_H}") - SET(HTTP_PARSER_VERSION_STRING "${HTTP_PARSER_VERSION_MAJOR}.${HTTP_PARSER_VERSION_MINOR}") - ENDIF() - UNSET(HTTP_PARSER_H) -ENDIF() - -# Handle the QUIETLY and REQUIRED arguments and set HTTP_PARSER_FOUND -# to TRUE if all listed variables are TRUE -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(HTTP_Parser REQUIRED_VARS HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY) - -# Hide advanced variables -MARK_AS_ADVANCED(HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY) - -# Set standard variables -IF (HTTP_PARSER_FOUND) - SET(HTTP_PARSER_LIBRARIES ${HTTP_PARSER_LIBRARY}) - set(HTTP_PARSER_INCLUDE_DIRS ${HTTP_PARSER_INCLUDE_DIR}) -ENDIF() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f3830efe5..30abfefcb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -169,7 +169,7 @@ endif() # Optional external dependency: http-parser if(USE_HTTP_PARSER STREQUAL "system") - find_package(HTTP_Parser) + find_package(HTTPParser) if(HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2) list(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS}) -- cgit v1.2.1 From de178d36ffd01ca0ba4262becedbd36df8529088 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 10 Nov 2021 21:49:20 -0500 Subject: cmake: refactor http_parser selection Move http_parser selection into its own cmake module. --- cmake/SelectHTTPParser.cmake | 19 +++++++++++++++++++ src/CMakeLists.txt | 22 ++-------------------- 2 files changed, 21 insertions(+), 20 deletions(-) create mode 100644 cmake/SelectHTTPParser.cmake diff --git a/cmake/SelectHTTPParser.cmake b/cmake/SelectHTTPParser.cmake new file mode 100644 index 000000000..a1724a7c4 --- /dev/null +++ b/cmake/SelectHTTPParser.cmake @@ -0,0 +1,19 @@ +# Optional external dependency: http-parser +if(USE_HTTP_PARSER STREQUAL "system") + find_package(HTTP_Parser) + + if(HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2) + list(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS}) + list(APPEND LIBGIT2_LIBS ${HTTP_PARSER_LIBRARIES}) + list(APPEND LIBGIT2_PC_LIBS "-lhttp_parser") + add_feature_info(http-parser ON "http-parser support (system)") + else() + message(FATAL_ERROR "http-parser support was requested but not found") + endif() +else() + message(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.") + add_subdirectory("${libgit2_SOURCE_DIR}/deps/http-parser" "${libgit2_BINARY_DIR}/deps/http-parser") + list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/http-parser") + list(APPEND LIBGIT2_OBJECTS "$") + add_feature_info(http-parser ON "http-parser support (bundled)") +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 30abfefcb..72b22c82a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -113,6 +113,8 @@ endif() include(SelectHTTPSBackend) include(SelectHashes) +include(SelectHTTPParser) + target_sources(git2internal PRIVATE ${SRC_SHA1}) # Specify regular expression implementation @@ -167,26 +169,6 @@ else() message(FATAL_ERROR "The REGEX_BACKEND option provided is not supported") endif() -# Optional external dependency: http-parser -if(USE_HTTP_PARSER STREQUAL "system") - find_package(HTTPParser) - - if(HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2) - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS}) - list(APPEND LIBGIT2_LIBS ${HTTP_PARSER_LIBRARIES}) - list(APPEND LIBGIT2_PC_LIBS "-lhttp_parser") - add_feature_info(http-parser ON "http-parser support (system)") - else() - message(FATAL_ERROR "http-parser support was requested but not found") - endif() -else() - message(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.") - add_subdirectory("${libgit2_SOURCE_DIR}/deps/http-parser" "${libgit2_BINARY_DIR}/deps/http-parser") - list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/http-parser") - list(APPEND LIBGIT2_OBJECTS "$") - add_feature_info(http-parser ON "http-parser support (bundled)") -endif() - # Optional external dependency: zlib SanitizeBool(USE_BUNDLED_ZLIB) if(USE_BUNDLED_ZLIB STREQUAL ON) -- cgit v1.2.1 From f0cb3788db73716247f20a69469d353d1178d2a7 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 10 Nov 2021 21:51:55 -0500 Subject: cmake: refactor regex selection Move regex selection into its own cmake module. --- cmake/SelectRegex.cmake | 51 +++++++++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 53 +------------------------------------------------ 2 files changed, 52 insertions(+), 52 deletions(-) create mode 100644 cmake/SelectRegex.cmake diff --git a/cmake/SelectRegex.cmake b/cmake/SelectRegex.cmake new file mode 100644 index 000000000..900d7f150 --- /dev/null +++ b/cmake/SelectRegex.cmake @@ -0,0 +1,51 @@ +# Specify regular expression implementation +find_package(PCRE) + +if(REGEX_BACKEND STREQUAL "") + check_symbol_exists(regcomp_l "regex.h;xlocale.h" HAVE_REGCOMP_L) + + if(HAVE_REGCOMP_L) + set(REGEX_BACKEND "regcomp_l") + elseif(PCRE_FOUND) + set(REGEX_BACKEND "pcre") + else() + set(REGEX_BACKEND "builtin") + endif() +endif() + +if(REGEX_BACKEND STREQUAL "regcomp_l") + add_feature_info(regex ON "using system regcomp_l") + set(GIT_REGEX_REGCOMP_L 1) +elseif(REGEX_BACKEND STREQUAL "pcre2") + find_package(PCRE2) + + if(NOT PCRE2_FOUND) + MESSAGE(FATAL_ERROR "PCRE2 support was requested but not found") + endif() + + add_feature_info(regex ON "using system PCRE2") + set(GIT_REGEX_PCRE2 1) + + list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE2_INCLUDE_DIRS}) + list(APPEND LIBGIT2_LIBS ${PCRE2_LIBRARIES}) + list(APPEND LIBGIT2_PC_REQUIRES "libpcre2-8") +elseif(REGEX_BACKEND STREQUAL "pcre") + add_feature_info(regex ON "using system PCRE") + set(GIT_REGEX_PCRE 1) + + list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE_INCLUDE_DIRS}) + list(APPEND LIBGIT2_LIBS ${PCRE_LIBRARIES}) + list(APPEND LIBGIT2_PC_REQUIRES "libpcre") +elseif(REGEX_BACKEND STREQUAL "regcomp") + add_feature_info(regex ON "using system regcomp") + set(GIT_REGEX_REGCOMP 1) +elseif(REGEX_BACKEND STREQUAL "builtin") + add_feature_info(regex ON "using bundled PCRE") + set(GIT_REGEX_BUILTIN 1) + + add_subdirectory("${libgit2_SOURCE_DIR}/deps/pcre" "${libgit2_BINARY_DIR}/deps/pcre") + list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/pcre") + list(APPEND LIBGIT2_OBJECTS $) +else() + message(FATAL_ERROR "The REGEX_BACKEND option provided is not supported") +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 72b22c82a..5c2c5271d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -114,61 +114,10 @@ endif() include(SelectHTTPSBackend) include(SelectHashes) include(SelectHTTPParser) +include(SelectRegex) target_sources(git2internal PRIVATE ${SRC_SHA1}) -# Specify regular expression implementation -find_package(PCRE) - -if(REGEX_BACKEND STREQUAL "") - check_symbol_exists(regcomp_l "regex.h;xlocale.h" HAVE_REGCOMP_L) - - if(HAVE_REGCOMP_L) - set(REGEX_BACKEND "regcomp_l") - elseif(PCRE_FOUND) - set(REGEX_BACKEND "pcre") - else() - set(REGEX_BACKEND "builtin") - endif() -endif() - -if(REGEX_BACKEND STREQUAL "regcomp_l") - add_feature_info(regex ON "using system regcomp_l") - set(GIT_REGEX_REGCOMP_L 1) -elseif(REGEX_BACKEND STREQUAL "pcre2") - find_package(PCRE2) - - if(NOT PCRE2_FOUND) - MESSAGE(FATAL_ERROR "PCRE2 support was requested but not found") - endif() - - add_feature_info(regex ON "using system PCRE2") - set(GIT_REGEX_PCRE2 1) - - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE2_INCLUDE_DIRS}) - list(APPEND LIBGIT2_LIBS ${PCRE2_LIBRARIES}) - list(APPEND LIBGIT2_PC_REQUIRES "libpcre2-8") -elseif(REGEX_BACKEND STREQUAL "pcre") - add_feature_info(regex ON "using system PCRE") - set(GIT_REGEX_PCRE 1) - - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE_INCLUDE_DIRS}) - list(APPEND LIBGIT2_LIBS ${PCRE_LIBRARIES}) - list(APPEND LIBGIT2_PC_REQUIRES "libpcre") -elseif(REGEX_BACKEND STREQUAL "regcomp") - add_feature_info(regex ON "using system regcomp") - set(GIT_REGEX_REGCOMP 1) -elseif(REGEX_BACKEND STREQUAL "builtin") - add_feature_info(regex ON "using bundled PCRE") - set(GIT_REGEX_BUILTIN 1) - - add_subdirectory("${libgit2_SOURCE_DIR}/deps/pcre" "${libgit2_BINARY_DIR}/deps/pcre") - list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/pcre") - list(APPEND LIBGIT2_OBJECTS $) -else() - message(FATAL_ERROR "The REGEX_BACKEND option provided is not supported") -endif() - # Optional external dependency: zlib SanitizeBool(USE_BUNDLED_ZLIB) if(USE_BUNDLED_ZLIB STREQUAL ON) -- cgit v1.2.1 From e35a22a080ad8127c1b3f058e6eea99d50fcfc79 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 10 Nov 2021 21:55:23 -0500 Subject: cmake: refactor libssh2 selection Move SSH selection into its own cmake module. --- cmake/SelectSSH.cmake | 41 +++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 27 +-------------------------- 2 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 cmake/SelectSSH.cmake diff --git a/cmake/SelectSSH.cmake b/cmake/SelectSSH.cmake new file mode 100644 index 000000000..0356ee3e7 --- /dev/null +++ b/cmake/SelectSSH.cmake @@ -0,0 +1,41 @@ +# Optional external dependency: libssh2 +if(USE_SSH) + find_pkglibraries(LIBSSH2 libssh2) + if(NOT LIBSSH2_FOUND) + find_package(LibSSH2) + set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR}) + get_filename_component(LIBSSH2_LIBRARY_DIRS "${LIBSSH2_LIBRARY}" DIRECTORY) + set(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY}) + set(LIBSSH2_LDFLAGS "-lssh2") + endif() + + if(NOT LIBSSH2_FOUND) + message(FATAL_ERROR "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.") + endif() +endif() + +if(LIBSSH2_FOUND) + set(GIT_SSH 1) + list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS}) + list(APPEND LIBGIT2_LIBS ${LIBSSH2_LIBRARIES}) + list(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS}) + + check_library_exists("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS) + if(HAVE_LIBSSH2_MEMORY_CREDENTIALS) + set(GIT_SSH_MEMORY_CREDENTIALS 1) + endif() +else() + message(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.") +endif() + +if(WIN32 AND EMBED_SSH_PATH) + file(GLOB SSH_SRC "${EMBED_SSH_PATH}/src/*.c") + list(SORT SSH_SRC) + list(APPEND LIBGIT2_OBJECTS ${SSH_SRC}) + + list(APPEND LIBGIT2_INCLUDES "${EMBED_SSH_PATH}/include") + file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"") + set(GIT_SSH 1) +endif() + +add_feature_info(SSH GIT_SSH "SSH transport support") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5c2c5271d..819fc4246 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -115,6 +115,7 @@ include(SelectHTTPSBackend) include(SelectHashes) include(SelectHTTPParser) include(SelectRegex) +include(SelectSSH) target_sources(git2internal PRIVATE ${SRC_SHA1}) @@ -151,32 +152,6 @@ elseif(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND) add_feature_info(zlib ON "using bundled zlib") endif() -# Optional external dependency: libssh2 -if(USE_SSH) - find_pkglibraries(LIBSSH2 libssh2) - if(NOT LIBSSH2_FOUND) - find_package(LibSSH2) - set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR}) - get_filename_component(LIBSSH2_LIBRARY_DIRS "${LIBSSH2_LIBRARY}" DIRECTORY) - set(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY}) - set(LIBSSH2_LDFLAGS "-lssh2") - endif() -endif() -if(LIBSSH2_FOUND) - set(GIT_SSH 1) - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS}) - list(APPEND LIBGIT2_LIBS ${LIBSSH2_LIBRARIES}) - list(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS}) - - check_library_exists("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS) - if(HAVE_LIBSSH2_MEMORY_CREDENTIALS) - set(GIT_SSH_MEMORY_CREDENTIALS 1) - endif() -else() - message(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.") -endif() -add_feature_info(SSH GIT_SSH "SSH transport support") - # Optional external dependency: ntlmclient if(USE_NTLMCLIENT) set(GIT_NTLM 1) -- cgit v1.2.1 From 83fa548078b0b35030ba028676d6b5674d86ba18 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 10 Nov 2021 21:58:12 -0500 Subject: cmake: refactor WinHTTP selection Move WinHTTP selection into its own cmake module. --- cmake/SelectWinHTTP.cmake | 17 +++++++++++++++++ src/CMakeLists.txt | 19 +------------------ 2 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 cmake/SelectWinHTTP.cmake diff --git a/cmake/SelectWinHTTP.cmake b/cmake/SelectWinHTTP.cmake new file mode 100644 index 000000000..a4110045f --- /dev/null +++ b/cmake/SelectWinHTTP.cmake @@ -0,0 +1,17 @@ +if(WIN32 AND WINHTTP) + set(GIT_WINHTTP 1) + + # 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 + if(MINGW) + add_subdirectory("${libgit2_SOURCE_DIR}/deps/winhttp" "${libgit2_BINARY_DIR}/deps/winhttp") + list(APPEND LIBGIT2_LIBS winhttp) + list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/winhttp") + else() + list(APPEND LIBGIT2_LIBS "winhttp") + list(APPEND LIBGIT2_PC_LIBS "-lwinhttp") + endif() + + list(APPEND LIBGIT2_LIBS "rpcrt4" "crypt32" "ole32") + list(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32") +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 819fc4246..8a57b2345 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -93,29 +93,12 @@ if(WIN32 AND EMBED_SSH_PATH) set(GIT_SSH 1) endif() -if(WIN32 AND USE_WINHTTP) - set(GIT_WINHTTP 1) - - # 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 - if(MINGW) - add_subdirectory("${libgit2_SOURCE_DIR}/deps/winhttp" "${libgit2_BINARY_DIR}/deps/winhttp") - list(APPEND LIBGIT2_LIBS winhttp) - list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/winhttp") - else() - list(APPEND LIBGIT2_LIBS "winhttp") - list(APPEND LIBGIT2_PC_LIBS "-lwinhttp") - endif() - - list(APPEND LIBGIT2_LIBS "rpcrt4" "crypt32" "ole32") - list(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32") -endif() - include(SelectHTTPSBackend) include(SelectHashes) include(SelectHTTPParser) include(SelectRegex) include(SelectSSH) +include(SelectWinHTTP) target_sources(git2internal PRIVATE ${SRC_SHA1}) -- cgit v1.2.1 From 4e84ddd5b091b6e6e85ff6484e72d9f90da1c4b0 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 10 Nov 2021 21:59:46 -0500 Subject: cmake: refactor zlib selection Move zlib selection into its own cmake module. --- cmake/SelectZlib.cmake | 34 ++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 34 +--------------------------------- 2 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 cmake/SelectZlib.cmake diff --git a/cmake/SelectZlib.cmake b/cmake/SelectZlib.cmake new file mode 100644 index 000000000..2dfc6c86e --- /dev/null +++ b/cmake/SelectZlib.cmake @@ -0,0 +1,34 @@ +# Optional external dependency: zlib +include(SanitizeBool) + +SanitizeBool(USE_BUNDLED_ZLIB) +if(USE_BUNDLED_ZLIB STREQUAL ON) + set(USE_BUNDLED_ZLIB "Bundled") +endif() + +if(USE_BUNDLED_ZLIB STREQUAL "OFF") + find_package(ZLIB) + if(ZLIB_FOUND) + list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ZLIB_INCLUDE_DIRS}) + list(APPEND LIBGIT2_LIBS ${ZLIB_LIBRARIES}) + if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + list(APPEND LIBGIT2_PC_LIBS "-lz") + else() + list(APPEND LIBGIT2_PC_REQUIRES "zlib") + endif() + add_feature_info(zlib ON "using system zlib") + else() + message(STATUS "zlib was not found; using bundled 3rd-party sources." ) + endif() +endif() +if(USE_BUNDLED_ZLIB STREQUAL "Chromium") + add_subdirectory("${libgit2_SOURCE_DIR}/deps/chromium-zlib" "${libgit2_BINARY_DIR}/deps/chromium-zlib") + list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/chromium-zlib") + list(APPEND LIBGIT2_OBJECTS $) + add_feature_info(zlib ON "using (Chromium) bundled zlib") +elseif(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND) + add_subdirectory("${libgit2_SOURCE_DIR}/deps/zlib" "${libgit2_BINARY_DIR}/deps/zlib") + list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/zlib") + list(APPEND LIBGIT2_OBJECTS $) + add_feature_info(zlib ON "using bundled zlib") +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8a57b2345..ae02ef9aa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -99,42 +99,10 @@ include(SelectHTTPParser) include(SelectRegex) include(SelectSSH) include(SelectWinHTTP) +include(SelectZlib) target_sources(git2internal PRIVATE ${SRC_SHA1}) -# Optional external dependency: zlib -SanitizeBool(USE_BUNDLED_ZLIB) -if(USE_BUNDLED_ZLIB STREQUAL ON) - set(USE_BUNDLED_ZLIB "Bundled") -endif() - -if(USE_BUNDLED_ZLIB STREQUAL "OFF") - find_package(ZLIB) - if(ZLIB_FOUND) - list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ZLIB_INCLUDE_DIRS}) - list(APPEND LIBGIT2_LIBS ${ZLIB_LIBRARIES}) - if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") - list(APPEND LIBGIT2_PC_LIBS "-lz") - else() - list(APPEND LIBGIT2_PC_REQUIRES "zlib") - endif() - add_feature_info(zlib ON "using system zlib") - else() - message(STATUS "zlib was not found; using bundled 3rd-party sources." ) - endif() -endif() -if(USE_BUNDLED_ZLIB STREQUAL "Chromium") - add_subdirectory("${libgit2_SOURCE_DIR}/deps/chromium-zlib" "${libgit2_BINARY_DIR}/deps/chromium-zlib") - list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/chromium-zlib") - list(APPEND LIBGIT2_OBJECTS $) - add_feature_info(zlib ON "using (Chromium) bundled zlib") -elseif(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND) - add_subdirectory("${libgit2_SOURCE_DIR}/deps/zlib" "${libgit2_BINARY_DIR}/deps/zlib") - list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/zlib") - list(APPEND LIBGIT2_OBJECTS $) - add_feature_info(zlib ON "using bundled zlib") -endif() - # Optional external dependency: ntlmclient if(USE_NTLMCLIENT) set(GIT_NTLM 1) -- cgit v1.2.1 From cf522050bf904c0de92d5a0fc75f50db412ed59d Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 16:24:37 -0500 Subject: clar: emit `clar_suite.h` with test declarations We may want to have test function declarations; produce a header file with (only) the test declarations. Update clar to avoid overwriting the file unnecessarily to avoid bumping timestamps and potentially recompiling unnecessarily. --- tests/generate.py | 75 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 13 deletions(-) diff --git a/tests/generate.py b/tests/generate.py index 9ed6edef3..d2cdb684a 100644 --- a/tests/generate.py +++ b/tests/generate.py @@ -8,7 +8,7 @@ from __future__ import with_statement from string import Template -import re, fnmatch, os, sys, codecs, pickle +import re, fnmatch, os, sys, codecs, pickle, io class Module(object): class Template(object): @@ -147,7 +147,7 @@ class TestSuite(object): self.path = path self.output = output - def should_generate(self, path): + def maybe_generate(self, path): if not os.path.isfile(path): return True @@ -216,33 +216,82 @@ class TestSuite(object): return sum(len(module.callbacks) for module in self.modules.values()) def write(self): - output = os.path.join(self.output, 'clar.suite') + wrote_suite = self.write_suite() + wrote_header = self.write_header() - if not self.should_generate(output): + if wrote_suite or wrote_header: + self.save_cache() + return True + + return False + + def write_output(self, fn, data): + if not self.maybe_generate(fn): return False - with open(output, 'w') as data: + current = None + + try: + with open(fn, 'r') as input: + current = input.read() + except OSError: + pass + except IOError: + pass + + if current == data: + return False + + with open(fn, 'w') as output: + output.write(data) + + return True + + def write_suite(self): + suite_fn = os.path.join(self.output, 'clar.suite') + + with io.StringIO() as suite_file: modules = sorted(self.modules.values(), key=lambda module: module.name) for module in modules: t = Module.DeclarationTemplate(module) - data.write(t.render()) + suite_file.write(t.render()) for module in modules: t = Module.CallbacksTemplate(module) - data.write(t.render()) + suite_file.write(t.render()) suites = "static struct clar_suite _clar_suites[] = {" + ','.join( Module.InfoTemplate(module).render() for module in modules ) + "\n};\n" - data.write(suites) + suite_file.write(suites) - data.write("static const size_t _clar_suite_count = %d;\n" % self.suite_count()) - data.write("static const size_t _clar_callback_count = %d;\n" % self.callback_count()) + suite_file.write(u"static const size_t _clar_suite_count = %d;\n" % self.suite_count()) + suite_file.write(u"static const size_t _clar_callback_count = %d;\n" % self.callback_count()) - self.save_cache() - return True + return self.write_output(suite_fn, suite_file.getvalue()) + + return False + + def write_header(self): + header_fn = os.path.join(self.output, 'clar_suite.h') + + with io.StringIO() as header_file: + header_file.write(u"#ifndef _____clar_suite_h_____\n") + header_file.write(u"#define _____clar_suite_h_____\n") + + modules = sorted(self.modules.values(), key=lambda module: module.name) + + for module in modules: + t = Module.DeclarationTemplate(module) + header_file.write(t.render()) + + header_file.write(u"#endif\n") + + return self.write_output(header_fn, header_file.getvalue()) + + return False if __name__ == '__main__': from optparse import OptionParser @@ -263,5 +312,5 @@ if __name__ == '__main__': suite.load(options.force) suite.disable(options.excluded) if suite.write(): - print("Written `clar.suite` (%d tests in %d suites)" % (suite.callback_count(), suite.suite_count())) + print("Written `clar.suite`, `clar_suite.h` (%d tests in %d suites)" % (suite.callback_count(), suite.suite_count())) -- cgit v1.2.1 From 49f03c0305d89e4bcee6c12af956381f70e14753 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 16:53:33 -0500 Subject: tests: include test declarations for old gcc Older versions of gcc do not believe that we've adequately declared our test functions. Include `clar_suite.h` conditionally for those old versions. Do not do this on newer compilers to avoid unnecessary recompilation of the entire suite when we add or remove a test function. --- tests/CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 760925fcf..e109913ff 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -25,7 +25,7 @@ if(MSVC_IDE) endif() add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite ${CMAKE_CURRENT_BINARY_DIR}/clar_suite.h COMMAND ${PYTHON_EXECUTABLE} generate.py -o "${CMAKE_CURRENT_BINARY_DIR}" -f -xonline -xstress -xperf . DEPENDS ${SRC_TEST} WORKING_DIRECTORY ${CLAR_PATH} @@ -48,6 +48,14 @@ target_include_directories(libgit2_tests PRIVATE ../src PUBLIC ../include) target_link_libraries(libgit2_tests ${LIBGIT2_LIBS}) ide_split_sources(libgit2_tests) +# +# Old versions of gcc require us to declare our test functions; don't do +# this on newer compilers to avoid unnecessary recompilation. +# +if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0) + add_definitions(-include \"clar_suite.h\") +endif() + if(MSVC_IDE) # Precompiled headers set_target_properties(libgit2_tests PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h") -- cgit v1.2.1 From 0429894e0bd1eee077e07b22528d569c8636d6f1 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 12:28:07 -0500 Subject: tests: declare trace handler as static --- tests/clar_libgit2_trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/clar_libgit2_trace.c b/tests/clar_libgit2_trace.c index 8eb6d4e8d..ebb0f41dd 100644 --- a/tests/clar_libgit2_trace.c +++ b/tests/clar_libgit2_trace.c @@ -150,7 +150,7 @@ static cl_perf_timer s_timer_run = CL_PERF_TIMER_INIT; */ static cl_perf_timer s_timer_test = CL_PERF_TIMER_INIT; -void _cl_trace_cb__event_handler( +static void _cl_trace_cb__event_handler( cl_trace_event ev, const char *suite_name, const char *test_name, -- cgit v1.2.1 From 489aec44477181afa05db41bfd04bb0febe83f59 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 12:33:14 -0500 Subject: fuzzers: declare standalone functions --- fuzzers/commit_graph_fuzzer.c | 2 ++ fuzzers/config_file_fuzzer.c | 2 ++ fuzzers/download_refs_fuzzer.c | 2 ++ fuzzers/midx_fuzzer.c | 2 ++ fuzzers/objects_fuzzer.c | 2 ++ fuzzers/packfile_fuzzer.c | 2 ++ fuzzers/patch_parse_fuzzer.c | 2 ++ fuzzers/standalone_driver.c | 3 +-- fuzzers/standalone_driver.h | 14 ++++++++++++++ 9 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 fuzzers/standalone_driver.h diff --git a/fuzzers/commit_graph_fuzzer.c b/fuzzers/commit_graph_fuzzer.c index 05783a259..1c46d78c7 100644 --- a/fuzzers/commit_graph_fuzzer.c +++ b/fuzzers/commit_graph_fuzzer.c @@ -17,6 +17,8 @@ #include "hash.h" #include "commit_graph.h" +#include "standalone_driver.h" + int LLVMFuzzerInitialize(int *argc, char ***argv) { GIT_UNUSED(argc); diff --git a/fuzzers/config_file_fuzzer.c b/fuzzers/config_file_fuzzer.c index 526c93928..582d74aff 100644 --- a/fuzzers/config_file_fuzzer.c +++ b/fuzzers/config_file_fuzzer.c @@ -10,6 +10,8 @@ #include "git2.h" #include "config_backend.h" +#include "standalone_driver.h" + #define UNUSED(x) (void)(x) int foreach_cb(const git_config_entry *entry, void *payload) diff --git a/fuzzers/download_refs_fuzzer.c b/fuzzers/download_refs_fuzzer.c index c5726cba1..bdaa6aab6 100644 --- a/fuzzers/download_refs_fuzzer.c +++ b/fuzzers/download_refs_fuzzer.c @@ -15,6 +15,8 @@ #include "git2/sys/transport.h" #include "futils.h" +#include "standalone_driver.h" + #define UNUSED(x) (void)(x) struct fuzzer_buffer { diff --git a/fuzzers/midx_fuzzer.c b/fuzzers/midx_fuzzer.c index 3cd609063..4c3124e47 100644 --- a/fuzzers/midx_fuzzer.c +++ b/fuzzers/midx_fuzzer.c @@ -16,6 +16,8 @@ #include "hash.h" #include "midx.h" +#include "standalone_driver.h" + int LLVMFuzzerInitialize(int *argc, char ***argv) { GIT_UNUSED(argc); diff --git a/fuzzers/objects_fuzzer.c b/fuzzers/objects_fuzzer.c index 1feff778d..51b4a1ed4 100644 --- a/fuzzers/objects_fuzzer.c +++ b/fuzzers/objects_fuzzer.c @@ -10,6 +10,8 @@ #include "git2.h" #include "object.h" +#include "standalone_driver.h" + #define UNUSED(x) (void)(x) int LLVMFuzzerInitialize(int *argc, char ***argv) diff --git a/fuzzers/packfile_fuzzer.c b/fuzzers/packfile_fuzzer.c index f739b9563..8667cb9c5 100644 --- a/fuzzers/packfile_fuzzer.c +++ b/fuzzers/packfile_fuzzer.c @@ -14,6 +14,8 @@ #include "common.h" #include "str.h" +#include "standalone_driver.h" + static git_odb *odb = NULL; static git_odb_backend *mempack = NULL; diff --git a/fuzzers/patch_parse_fuzzer.c b/fuzzers/patch_parse_fuzzer.c index a9b02ad4d..2e65a01fd 100644 --- a/fuzzers/patch_parse_fuzzer.c +++ b/fuzzers/patch_parse_fuzzer.c @@ -11,6 +11,8 @@ #include "patch.h" #include "patch_parse.h" +#include "standalone_driver.h" + #define UNUSED(x) (void)(x) int LLVMFuzzerInitialize(int *argc, char ***argv) diff --git a/fuzzers/standalone_driver.c b/fuzzers/standalone_driver.c index c29102e65..cd4f71751 100644 --- a/fuzzers/standalone_driver.c +++ b/fuzzers/standalone_driver.c @@ -11,8 +11,7 @@ #include "futils.h" #include "path.h" -extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size); -extern int LLVMFuzzerInitialize(int *argc, char ***argv); +#include "standalone_driver.h" static int run_one_file(const char *filename) { diff --git a/fuzzers/standalone_driver.h b/fuzzers/standalone_driver.h new file mode 100644 index 000000000..507fcb9fd --- /dev/null +++ b/fuzzers/standalone_driver.h @@ -0,0 +1,14 @@ +/* + * Copyright (C) the libgit2 contributors. All rights reserved. + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ + +#ifndef INCLUDE_standalone_driver_h__ +#define INCLUDE_standalone_driver_h__ + +extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size); +extern int LLVMFuzzerInitialize(int *argc, char ***argv); + +#endif -- cgit v1.2.1 From 2374ba8d49ac9dfb084596259ec82c87b384fc32 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 17:15:47 -0500 Subject: fuzzers: declare static functions as static --- fuzzers/config_file_fuzzer.c | 2 +- fuzzers/download_refs_fuzzer.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fuzzers/config_file_fuzzer.c b/fuzzers/config_file_fuzzer.c index 582d74aff..890adbfc5 100644 --- a/fuzzers/config_file_fuzzer.c +++ b/fuzzers/config_file_fuzzer.c @@ -14,7 +14,7 @@ #define UNUSED(x) (void)(x) -int foreach_cb(const git_config_entry *entry, void *payload) +static int foreach_cb(const git_config_entry *entry, void *payload) { UNUSED(entry); UNUSED(payload); diff --git a/fuzzers/download_refs_fuzzer.c b/fuzzers/download_refs_fuzzer.c index bdaa6aab6..ff95cd107 100644 --- a/fuzzers/download_refs_fuzzer.c +++ b/fuzzers/download_refs_fuzzer.c @@ -132,7 +132,7 @@ static int fuzzer_subtransport_new( return 0; } -int fuzzer_subtransport_cb( +static int fuzzer_subtransport_cb( git_smart_subtransport **out, git_transport *owner, void *payload) @@ -147,7 +147,7 @@ int fuzzer_subtransport_cb( return 0; } -int fuzzer_transport_cb(git_transport **out, git_remote *owner, void *param) +static int fuzzer_transport_cb(git_transport **out, git_remote *owner, void *param) { git_smart_subtransport_definition def = { fuzzer_subtransport_cb, @@ -157,7 +157,7 @@ int fuzzer_transport_cb(git_transport **out, git_remote *owner, void *param) return git_transport_smart(out, owner, &def); } -void fuzzer_git_abort(const char *op) +static void fuzzer_git_abort(const char *op) { const git_error *err = git_error_last(); fprintf(stderr, "unexpected libgit error: %s: %s\n", -- cgit v1.2.1 From 8be226148f22559cb859a1c035243a7379465665 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 12:47:02 -0500 Subject: examples: remove unused function --- examples/add.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/examples/add.c b/examples/add.c index 542360ea9..5014bd71f 100644 --- a/examples/add.c +++ b/examples/add.c @@ -110,21 +110,6 @@ int print_matched_cb(const char *path, const char *matched_pathspec, void *paylo return ret; } -void init_array(git_strarray *array, int argc, char **argv) -{ - unsigned int i; - - array->count = argc; - array->strings = calloc(array->count, sizeof(char *)); - assert(array->strings != NULL); - - for (i = 0; i < array->count; i++) { - array->strings[i] = argv[i]; - } - - return; -} - void print_usage(void) { fprintf(stderr, "usage: add [options] [--] file-spec [file-spec] [...]\n\n"); -- cgit v1.2.1 From eabbee0454b74d149ba5f23f1141cc7492fb694f Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 12:48:19 -0500 Subject: example: declare print_usage function --- examples/add.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/add.c b/examples/add.c index 5014bd71f..4ff7c79e2 100644 --- a/examples/add.c +++ b/examples/add.c @@ -110,7 +110,7 @@ int print_matched_cb(const char *path, const char *matched_pathspec, void *paylo return ret; } -void print_usage(void) +static void print_usage(void) { fprintf(stderr, "usage: add [options] [--] file-spec [file-spec] [...]\n\n"); fprintf(stderr, "\t-n, --dry-run dry run\n"); -- cgit v1.2.1 From 3f024b6d5439eda83d8bebc197db062c4d6bdfeb Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 12:57:44 -0500 Subject: clar: declare summary functions as static --- tests/clar/summary.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/clar/summary.h b/tests/clar/summary.h index 1af110efa..6279f5057 100644 --- a/tests/clar/summary.h +++ b/tests/clar/summary.h @@ -2,7 +2,7 @@ #include #include -int clar_summary_close_tag( +static int clar_summary_close_tag( struct clar_summary *summary, const char *tag, int indent) { const char *indt; @@ -14,12 +14,12 @@ int clar_summary_close_tag( return fprintf(summary->fp, "%s\n", indt, tag); } -int clar_summary_testsuites(struct clar_summary *summary) +static int clar_summary_testsuites(struct clar_summary *summary) { return fprintf(summary->fp, "\n"); } -int clar_summary_testsuite(struct clar_summary *summary, +static int clar_summary_testsuite(struct clar_summary *summary, int idn, const char *name, const char *pkg, time_t timestamp, double elapsed, int test_count, int fail_count, int error_count) { @@ -42,7 +42,7 @@ int clar_summary_testsuite(struct clar_summary *summary, idn, name, pkg, iso_dt, elapsed, test_count, fail_count, error_count); } -int clar_summary_testcase(struct clar_summary *summary, +static int clar_summary_testcase(struct clar_summary *summary, const char *name, const char *classname, double elapsed) { return fprintf(summary->fp, @@ -50,7 +50,7 @@ int clar_summary_testcase(struct clar_summary *summary, name, classname, elapsed); } -int clar_summary_failure(struct clar_summary *summary, +static int clar_summary_failure(struct clar_summary *summary, const char *type, const char *message, const char *desc) { return fprintf(summary->fp, -- cgit v1.2.1 From ca14942e19788bd01334af64554c3095f3ff0d4a Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 13:28:08 -0500 Subject: tests: declare functions statically where appropriate --- tests/checkout/tree.c | 10 +- tests/clone/nonetwork.c | 2 +- tests/commit/commit.c | 4 +- tests/config/stress.c | 2 +- tests/core/copy.c | 4 +- tests/diff/binary.c | 2 +- tests/diff/rename.c | 2 +- tests/diff/tree.c | 2 +- tests/email/create.c.bak | 386 ++++++++++++++++++++++++++++++++++++++++++ tests/fetchhead/nonetwork.c | 4 +- tests/filter/custom_helpers.c | 2 +- tests/filter/file.c | 6 +- tests/merge/merge_helpers.c | 2 +- tests/network/fetchlocal.c | 4 +- tests/network/remote/push.c | 4 +- tests/notes/notes.c | 2 +- tests/object/tag/write.c | 2 +- tests/odb/loose.c | 2 +- tests/online/clone.c | 4 +- tests/online/push_util.c | 2 +- tests/pack/filelimit.c | 2 +- tests/patch/print.c | 2 +- tests/path/dotgit.c | 2 +- tests/path/win32.c | 16 +- tests/rebase/iterator.c | 2 +- tests/rebase/merge.c | 2 +- tests/rebase/sign.c | 2 +- tests/refs/shorthand.c | 2 +- tests/remote/fetch.c | 2 +- tests/remote/httpproxy.c | 6 +- tests/stash/apply.c | 6 +- tests/stash/drop.c | 2 +- tests/status/worktree.c | 2 +- tests/submodule/modify.c | 6 +- 34 files changed, 442 insertions(+), 60 deletions(-) create mode 100644 tests/email/create.c.bak diff --git a/tests/checkout/tree.c b/tests/checkout/tree.c index 2f54f4e3e..de7dd7d9a 100644 --- a/tests/checkout/tree.c +++ b/tests/checkout/tree.c @@ -509,7 +509,7 @@ void test_checkout_tree__can_disable_pattern_match(void) cl_assert(git_fs_path_isfile("testrepo/branch_file.txt")); } -void assert_conflict( +static void assert_conflict( const char *entry_path, const char *new_content, const char *parent_sha, @@ -1034,7 +1034,8 @@ void test_checkout_tree__filemode_preserved_in_index(void) git_index_free(index); } -mode_t read_filemode(const char *path) +#ifndef GIT_WIN32 +static mode_t read_filemode(const char *path) { git_str fullpath = GIT_STR_INIT; struct stat st; @@ -1050,6 +1051,7 @@ mode_t read_filemode(const char *path) return result; } +#endif void test_checkout_tree__filemode_preserved_in_workdir(void) { @@ -1267,7 +1269,7 @@ void test_checkout_tree__case_changing_rename(void) git_commit_free(master_commit); } -void perfdata_cb(const git_checkout_perfdata *in, void *payload) +static void perfdata_cb(const git_checkout_perfdata *in, void *payload) { memcpy(payload, in, sizeof(git_checkout_perfdata)); } @@ -1296,7 +1298,7 @@ void test_checkout_tree__can_collect_perfdata(void) git_object_free(obj); } -void update_attr_callback( +static void update_attr_callback( const char *path, size_t completed_steps, size_t total_steps, diff --git a/tests/clone/nonetwork.c b/tests/clone/nonetwork.c index c3515b53f..eab633635 100644 --- a/tests/clone/nonetwork.c +++ b/tests/clone/nonetwork.c @@ -109,7 +109,7 @@ void test_clone_nonetwork__fail_with_already_existing_but_non_empty_directory(vo cl_git_fail(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options)); } -int custom_origin_name_remote_create( +static int custom_origin_name_remote_create( git_remote **out, git_repository *repo, const char *name, diff --git a/tests/commit/commit.c b/tests/commit/commit.c index b03169bc8..d4e333b6a 100644 --- a/tests/commit/commit.c +++ b/tests/commit/commit.c @@ -111,7 +111,7 @@ void test_commit_commit__create_initial_commit_parent_not_current(void) git_signature_free(s); } -void assert_commit_summary(const char *expected, const char *given) +static void assert_commit_summary(const char *expected, const char *given) { git_commit *dummy; @@ -123,7 +123,7 @@ void assert_commit_summary(const char *expected, const char *given) git_commit__free(dummy); } -void assert_commit_body(const char *expected, const char *given) +static void assert_commit_body(const char *expected, const char *given) { git_commit *dummy; diff --git a/tests/config/stress.c b/tests/config/stress.c index c823284ff..69e6810fa 100644 --- a/tests/config/stress.c +++ b/tests/config/stress.c @@ -39,7 +39,7 @@ void test_config_stress__dont_break_on_invalid_input(void) git_config_free(config); } -void assert_config_value(git_config *config, const char *key, const char *value) +static void assert_config_value(git_config *config, const char *key, const char *value) { git_buf_dispose(&buf); cl_git_pass(git_config_get_string_buf(&buf, config, key)); diff --git a/tests/core/copy.c b/tests/core/copy.c index 2b90fb6bf..b03d71083 100644 --- a/tests/core/copy.c +++ b/tests/core/copy.c @@ -45,7 +45,8 @@ void test_core_copy__file_in_dir(void) cl_assert(!git_fs_path_isdir("an_dir")); } -void assert_hard_link(const char *path) +#ifndef GIT_WIN32 +static void assert_hard_link(const char *path) { /* we assert this by checking that there's more than one link to the file */ struct stat st; @@ -54,6 +55,7 @@ void assert_hard_link(const char *path) cl_git_pass(p_stat(path, &st)); cl_assert(st.st_nlink > 1); } +#endif void test_core_copy__tree(void) { diff --git a/tests/diff/binary.c b/tests/diff/binary.c index 24d2b22ef..4e71f39c6 100644 --- a/tests/diff/binary.c +++ b/tests/diff/binary.c @@ -17,7 +17,7 @@ void test_diff_binary__cleanup(void) cl_git_sandbox_cleanup(); } -void test_patch( +static void test_patch( const char *one, const char *two, const git_diff_options *opts, diff --git a/tests/diff/rename.c b/tests/diff/rename.c index d28a4d989..41dc95eb4 100644 --- a/tests/diff/rename.c +++ b/tests/diff/rename.c @@ -938,7 +938,7 @@ struct rename_expected size_t idx; }; -int test_names_expected(const git_diff_delta *delta, float progress, void *p) +static int test_names_expected(const git_diff_delta *delta, float progress, void *p) { struct rename_expected *expected = p; diff --git a/tests/diff/tree.c b/tests/diff/tree.c index dfe4d254c..e03ee7b22 100644 --- a/tests/diff/tree.c +++ b/tests/diff/tree.c @@ -320,7 +320,7 @@ void test_diff_tree__checks_options_version(void) err = git_error_last(); } -void process_tree_to_tree_diffing( +static void process_tree_to_tree_diffing( const char *old_commit, const char *new_commit) { diff --git a/tests/email/create.c.bak b/tests/email/create.c.bak new file mode 100644 index 000000000..3bb95a6f6 --- /dev/null +++ b/tests/email/create.c.bak @@ -0,0 +1,386 @@ +#include "clar.h" +#include "clar_libgit2.h" + +#include "buffer.h" +#include "diff_generate.h" + +static git_repository *repo; + +void test_email_create__initialize(void) +{ + repo = cl_git_sandbox_init("diff_format_email"); +} + +void test_email_create__cleanup(void) +{ + cl_git_sandbox_cleanup(); +} + +static void email_for_commit( + git_buf *out, + const char *commit_id, + git_email_create_options *opts) +{ + git_oid oid; + git_commit *commit = NULL; + git_diff *diff = NULL; + + git_oid_fromstr(&oid, commit_id); + + cl_git_pass(git_commit_lookup(&commit, repo, &oid)); + + cl_git_pass(git_email_create_from_commit(out, commit, opts)); + + git_diff_free(diff); + git_commit_free(commit); +} + +static void assert_email_match( + const char *expected, + const char *commit_id, + git_email_create_options *opts) +{ + git_buf buf = GIT_BUF_INIT; + + email_for_commit(&buf, commit_id, opts); + cl_assert_equal_s(expected, git_buf_cstr(&buf)); + + git_buf_dispose(&buf); +} + +static void assert_subject_match( + const char *expected, + const char *commit_id, + git_email_create_options *opts) +{ + git_buf buf = GIT_BUF_INIT; + const char *loc; + + email_for_commit(&buf, commit_id, opts); + + cl_assert((loc = strstr(buf.ptr, "\nSubject: ")) != NULL); + git_buf_consume(&buf, (loc + 10)); + git_buf_truncate_at_char(&buf, '\n'); + + cl_assert_equal_s(expected, git_buf_cstr(&buf)); + + git_buf_dispose(&buf); +} + +void test_email_create__commit(void) +{ + const char *expected = + "From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001\n" \ + "From: Jacques Germishuys \n" \ + "Date: Wed, 9 Apr 2014 20:57:01 +0200\n" \ + "Subject: [PATCH] Modify some content\n" \ + "\n" \ + "---\n" \ + " file1.txt | 8 +++++---\n" \ + " 1 file changed, 5 insertions(+), 3 deletions(-)\n" \ + "\n" \ + "diff --git a/file1.txt b/file1.txt\n" \ + "index 94aaae8..af8f41d 100644\n" \ + "--- a/file1.txt\n" \ + "+++ b/file1.txt\n" \ + "@@ -1,15 +1,17 @@\n" \ + " file1.txt\n" \ + " file1.txt\n" \ + "+_file1.txt_\n" \ + " file1.txt\n" \ + " file1.txt\n" \ + " file1.txt\n" \ + " file1.txt\n" \ + "+\n" \ + "+\n" \ + " file1.txt\n" \ + " file1.txt\n" \ + " file1.txt\n" \ + " file1.txt\n" \ + " file1.txt\n" \ + "-file1.txt\n" \ + "-file1.txt\n" \ + "-file1.txt\n" \ + "+_file1.txt_\n" \ + "+_file1.txt_\n" \ + " file1.txt\n" \ + "--\n" \ + "libgit2 " LIBGIT2_VERSION "\n" \ + "\n"; + + assert_email_match( + expected, "9264b96c6d104d0e07ae33d3007b6a48246c6f92", NULL); +} + +void test_email_create__custom_summary_and_body(void) +{ + const char *expected = "From 627e7e12d87e07a83fad5b6bfa25e86ead4a5270 Mon Sep 17 00:00:00 2001\n" \ + "From: Patrick Steinhardt \n" \ + "Date: Tue, 24 Nov 2015 13:34:39 +0100\n" \ + "Subject: [PPPPPATCH 2/4] This is a subject\n" \ + "\n" \ + "Modify content of file3.txt by appending a new line. Make this\n" \ + "commit message somewhat longer to test behavior with newlines\n" \ + "embedded in the message body.\n" \ + "\n" \ + "Also test if new paragraphs are included correctly.\n" \ + "---\n" \ + " file3.txt | 1 +\n" \ + " 1 file changed, 1 insertion(+)\n" \ + "\n" \ + "diff --git a/file3.txt b/file3.txt\n" \ + "index 9a2d780..7309653 100644\n" \ + "--- a/file3.txt\n" \ + "+++ b/file3.txt\n" \ + "@@ -3,3 +3,4 @@ file3!\n" \ + " file3\n" \ + " file3\n" \ + " file3\n" \ + "+file3\n" \ + "--\n" \ + "libgit2 " LIBGIT2_VERSION "\n" \ + "\n"; + + const char *summary = "This is a subject\nwith\nnewlines"; + const char *body = "Modify content of file3.txt by appending a new line. Make this\n" \ + "commit message somewhat longer to test behavior with newlines\n" \ + "embedded in the message body.\n" \ + "\n" \ + "Also test if new paragraphs are included correctly."; + + git_oid oid; + git_commit *commit = NULL; + git_diff *diff = NULL; + git_buf buf = GIT_BUF_INIT; + git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT; + + opts.subject_prefix = "PPPPPATCH"; + + git_oid_fromstr(&oid, "627e7e12d87e07a83fad5b6bfa25e86ead4a5270"); + cl_git_pass(git_commit_lookup(&commit, repo, &oid)); + cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); + cl_git_pass(git_email_create_from_diff(&buf, diff, 2, 4, &oid, summary, body, git_commit_author(commit), &opts)); + + cl_assert_equal_s(expected, git_buf_cstr(&buf)); + + git_diff_free(diff); + git_commit_free(commit); + git_buf_dispose(&buf); +} + +void test_email_create__mode_change(void) +{ + const char *expected = + "From 7ade76dd34bba4733cf9878079f9fd4a456a9189 Mon Sep 17 00:00:00 2001\n" \ + "From: Jacques Germishuys \n" \ + "Date: Thu, 10 Apr 2014 10:05:03 +0200\n" \ + "Subject: [PATCH] Update permissions\n" \ + "\n" \ + "---\n" \ + " file1.txt.renamed | 0\n" \ + " 1 file changed, 0 insertions(+), 0 deletions(-)\n" \ + " mode change 100644 => 100755 file1.txt.renamed\n" \ + "\n" \ + "diff --git a/file1.txt.renamed b/file1.txt.renamed\n" \ + "old mode 100644\n" \ + "new mode 100755\n" \ + "--\n" \ + "libgit2 " LIBGIT2_VERSION "\n" \ + "\n"; + + assert_email_match(expected, "7ade76dd34bba4733cf9878079f9fd4a456a9189", NULL); +} + +void test_email_create__rename(void) +{ + const char *expected = + "From 6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d Mon Sep 17 00:00:00 2001\n" \ + "From: Jacques Germishuys \n" \ + "Date: Wed, 9 Apr 2014 21:15:56 +0200\n" \ + "Subject: [PATCH] Renamed file1.txt -> file1.txt.renamed\n" \ + "\n" \ + "---\n" \ + " file1.txt => file1.txt.renamed | 4 ++--\n" \ + " 1 file changed, 2 insertions(+), 2 deletions(-)\n" \ + "\n" \ + "diff --git a/file1.txt b/file1.txt.renamed\n" \ + "similarity index 86%\n" \ + "rename from file1.txt\n" \ + "rename to file1.txt.renamed\n" \ + "index af8f41d..a97157a 100644\n" \ + "--- a/file1.txt\n" \ + "+++ b/file1.txt.renamed\n" \ + "@@ -3,13 +3,13 @@ file1.txt\n" \ + " _file1.txt_\n" \ + " file1.txt\n" \ + " file1.txt\n" \ + "-file1.txt\n" \ + "+file1.txt_renamed\n" \ + " file1.txt\n" \ + " \n" \ + " \n" \ + " file1.txt\n" \ + " file1.txt\n" \ + "-file1.txt\n" \ + "+file1.txt_renamed\n" \ + " file1.txt\n" \ + " file1.txt\n" \ + " _file1.txt_\n" \ + "--\n" \ + "libgit2 " LIBGIT2_VERSION "\n" \ + "\n"; + + assert_email_match(expected, "6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d", NULL); +} + +void test_email_create__rename_as_add_delete(void) +{ + const char *expected = + "From 6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d Mon Sep 17 00:00:00 2001\n" \ + "From: Jacques Germishuys \n" \ + "Date: Wed, 9 Apr 2014 21:15:56 +0200\n" \ + "Subject: [PATCH] Renamed file1.txt -> file1.txt.renamed\n" \ + "\n" \ + "---\n" \ + " file1.txt | 17 -----------------\n" \ + " file1.txt.renamed | 17 +++++++++++++++++\n" \ + " 2 files changed, 17 insertions(+), 17 deletions(-)\n" \ + " delete mode 100644 file1.txt\n" \ + " create mode 100644 file1.txt.renamed\n" \ + "\n" \ + "diff --git a/file1.txt b/file1.txt\n" \ + "deleted file mode 100644\n" \ + "index af8f41d..0000000\n" \ + "--- a/file1.txt\n" \ + "+++ /dev/null\n" \ + "@@ -1,17 +0,0 @@\n" \ + "-file1.txt\n" \ + "-file1.txt\n" \ + "-_file1.txt_\n" \ + "-file1.txt\n" \ + "-file1.txt\n" \ + "-file1.txt\n" \ + "-file1.txt\n" \ + "-\n" \ + "-\n" \ + "-file1.txt\n" \ + "-file1.txt\n" \ + "-file1.txt\n" \ + "-file1.txt\n" \ + "-file1.txt\n" \ + "-_file1.txt_\n" \ + "-_file1.txt_\n" \ + "-file1.txt\n" \ + "diff --git a/file1.txt.renamed b/file1.txt.renamed\n" \ + "new file mode 100644\n" \ + "index 0000000..a97157a\n" \ + "--- /dev/null\n" \ + "+++ b/file1.txt.renamed\n" \ + "@@ -0,0 +1,17 @@\n" \ + "+file1.txt\n" \ + "+file1.txt\n" \ + "+_file1.txt_\n" \ + "+file1.txt\n" \ + "+file1.txt\n" \ + "+file1.txt_renamed\n" \ + "+file1.txt\n" \ + "+\n" \ + "+\n" \ + "+file1.txt\n" \ + "+file1.txt\n" \ + "+file1.txt_renamed\n" \ + "+file1.txt\n" \ + "+file1.txt\n" \ + "+_file1.txt_\n" \ + "+_file1.txt_\n" \ + "+file1.txt\n" \ + "--\n" \ + "libgit2 " LIBGIT2_VERSION "\n" \ + "\n"; + + git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT; + opts.flags |= GIT_EMAIL_CREATE_NO_RENAMES; + + assert_email_match(expected, "6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d", &opts); +} + +void test_email_create__binary(void) +{ + const char *expected = + "From 8d7523f6fcb2404257889abe0d96f093d9f524f9 Mon Sep 17 00:00:00 2001\n" \ + "From: Jacques Germishuys \n" \ + "Date: Sun, 13 Apr 2014 18:10:18 +0200\n" \ + "Subject: [PATCH] Modified binary file\n" \ + "\n" \ + "---\n" \ + " binary.bin | Bin 3 -> 5 bytes\n" \ + " 1 file changed, 0 insertions(+), 0 deletions(-)\n" \ + "\n" \ + "diff --git a/binary.bin b/binary.bin\n" \ + "index bd474b2519cc15eab801ff851cc7d50f0dee49a1..9ac35ff15cd8864aeafd889e4826a3150f0b06c4 100644\n" \ + "GIT binary patch\n" \ + "literal 5\n" \ + "Mc${NkU}WL~000&M4gdfE\n" \ + "\n" \ + "literal 3\n" \ + "Kc${Nk-~s>u4FC%O\n" \ + "\n" \ + "--\n" \ + "libgit2 " LIBGIT2_VERSION "\n" \ + "\n"; + + assert_email_match(expected, "8d7523f6fcb2404257889abe0d96f093d9f524f9", NULL); +} + +void test_email_create__binary_not_included(void) +{ + const char *expected = + "From 8d7523f6fcb2404257889abe0d96f093d9f524f9 Mon Sep 17 00:00:00 2001\n" \ + "From: Jacques Germishuys \n" \ + "Date: Sun, 13 Apr 2014 18:10:18 +0200\n" \ + "Subject: [PATCH] Modified binary file\n" \ + "\n" \ + "---\n" \ + " binary.bin | Bin 3 -> 5 bytes\n" \ + " 1 file changed, 0 insertions(+), 0 deletions(-)\n" \ + "\n" \ + "diff --git a/binary.bin b/binary.bin\n" \ + "index bd474b2..9ac35ff 100644\n" \ + "Binary files a/binary.bin and b/binary.bin differ\n" \ + "--\n" \ + "libgit2 " LIBGIT2_VERSION "\n" \ + "\n"; + + git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT; + opts.diff_opts.flags &= ~GIT_DIFF_SHOW_BINARY; + + assert_email_match(expected, "8d7523f6fcb2404257889abe0d96f093d9f524f9", &opts); +} + +void test_email_create__commit_subjects(void) +{ + git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT; + + assert_subject_match("[PATCH] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); + + opts.reroll_number = 42; + assert_subject_match("[PATCH v42] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); + + opts.flags |= GIT_EMAIL_CREATE_ALWAYS_NUMBER; + assert_subject_match("[PATCH v42 1/1] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); + + opts.start_number = 9; + assert_subject_match("[PATCH v42 9/9] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); + + opts.subject_prefix = ""; + assert_subject_match("[v42 9/9] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); + + opts.reroll_number = 0; + assert_subject_match("[9/9] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); + + opts.start_number = 0; + assert_subject_match("[1/1] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); + + opts.flags = GIT_EMAIL_CREATE_OMIT_NUMBERS; + assert_subject_match("Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); +} diff --git a/tests/fetchhead/nonetwork.c b/tests/fetchhead/nonetwork.c index 334755cc3..0e446d94e 100644 --- a/tests/fetchhead/nonetwork.c +++ b/tests/fetchhead/nonetwork.c @@ -408,7 +408,7 @@ static bool found_master; static bool found_haacked; static bool find_master_haacked_called; -int find_master_haacked(const char *ref_name, const char *remote_url, const git_oid *oid, unsigned int is_merge, void *payload) +static int find_master_haacked(const char *ref_name, const char *remote_url, const git_oid *oid, unsigned int is_merge, void *payload) { GIT_UNUSED(remote_url); GIT_UNUSED(oid); @@ -466,7 +466,7 @@ struct prefix_count { int expected; }; -int count_refs(const char *ref_name, const char *remote_url, const git_oid *oid, unsigned int is_merge, void *payload) +static int count_refs(const char *ref_name, const char *remote_url, const git_oid *oid, unsigned int is_merge, void *payload) { int i; struct prefix_count *prefix_counts = (struct prefix_count *) payload; diff --git a/tests/filter/custom_helpers.c b/tests/filter/custom_helpers.c index 7aa3777e6..f98f65c22 100644 --- a/tests/filter/custom_helpers.c +++ b/tests/filter/custom_helpers.c @@ -128,7 +128,7 @@ git_filter *create_reverse_filter(const char *attrs) return filter; } -int erroneous_filter_stream( +static int erroneous_filter_stream( git_writestream **out, git_filter *self, void **payload, diff --git a/tests/filter/file.c b/tests/filter/file.c index 3b7ab19e2..14b33bab9 100644 --- a/tests/filter/file.c +++ b/tests/filter/file.c @@ -55,19 +55,19 @@ struct buf_writestream { git_str buf; }; -int buf_writestream_write(git_writestream *s, const char *buf, size_t len) +static int buf_writestream_write(git_writestream *s, const char *buf, size_t len) { struct buf_writestream *stream = (struct buf_writestream *)s; return git_str_put(&stream->buf, buf, len); } -int buf_writestream_close(git_writestream *s) +static int buf_writestream_close(git_writestream *s) { GIT_UNUSED(s); return 0; } -void buf_writestream_free(git_writestream *s) +static void buf_writestream_free(git_writestream *s) { struct buf_writestream *stream = (struct buf_writestream *)s; git_str_dispose(&stream->buf); diff --git a/tests/merge/merge_helpers.c b/tests/merge/merge_helpers.c index 73a1d852d..ce3cd229b 100644 --- a/tests/merge/merge_helpers.c +++ b/tests/merge/merge_helpers.c @@ -328,7 +328,7 @@ int merge_test_reuc(git_index *index, const struct merge_reuc_entry expected[], return 1; } -int dircount(void *payload, git_str *pathbuf) +static int dircount(void *payload, git_str *pathbuf) { size_t *entries = payload; size_t len = git_str_len(pathbuf); diff --git a/tests/network/fetchlocal.c b/tests/network/fetchlocal.c index 302d1544c..e299d3ec8 100644 --- a/tests/network/fetchlocal.c +++ b/tests/network/fetchlocal.c @@ -108,7 +108,7 @@ void test_network_fetchlocal__prune(void) git_repository_free(repo); } -int update_tips_fail_on_call(const char *ref, const git_oid *old, const git_oid *new, void *data) +static int update_tips_fail_on_call(const char *ref, const git_oid *old, const git_oid *new, void *data) { GIT_UNUSED(ref); GIT_UNUSED(old); @@ -119,7 +119,7 @@ int update_tips_fail_on_call(const char *ref, const git_oid *old, const git_oid return 0; } -void assert_ref_exists(git_repository *repo, const char *name) +static void assert_ref_exists(git_repository *repo, const char *name) { git_reference *ref; diff --git a/tests/network/remote/push.c b/tests/network/remote/push.c index 34860542e..3905debdf 100644 --- a/tests/network/remote/push.c +++ b/tests/network/remote/push.c @@ -29,7 +29,7 @@ void test_network_remote_push__cleanup(void) cl_fixture_cleanup("dummy.git"); } -int negotiation_cb(const git_push_update **updates, size_t len, void *payload) +static int negotiation_cb(const git_push_update **updates, size_t len, void *payload) { const git_push_update *expected = payload; @@ -69,7 +69,7 @@ void test_network_remote_push__delete_notification(void) } -void create_dummy_commit(git_reference **out, git_repository *repo) +static void create_dummy_commit(git_reference **out, git_repository *repo) { git_index *index; git_oid tree_id, commit_id; diff --git a/tests/notes/notes.c b/tests/notes/notes.c index dd9ad1e4b..a36cddb8a 100644 --- a/tests/notes/notes.c +++ b/tests/notes/notes.c @@ -103,7 +103,7 @@ static int note_list_create_cb( return 0; } -void assert_notes_seen(struct note_create_payload payload[], size_t n) +static void assert_notes_seen(struct note_create_payload payload[], size_t n) { size_t seen = 0, i; diff --git a/tests/object/tag/write.c b/tests/object/tag/write.c index 48c8bfd36..3c1a98956 100644 --- a/tests/object/tag/write.c +++ b/tests/object/tag/write.c @@ -221,7 +221,7 @@ void test_object_tag_write__deleting_with_an_invalid_name_returns_EINVALIDSPEC(v cl_assert_equal_i(GIT_EINVALIDSPEC, git_tag_delete(g_repo, "Inv@{id")); } -void create_annotation(git_oid *tag_id, const char *name) +static void create_annotation(git_oid *tag_id, const char *name) { git_object *target; git_oid target_id; diff --git a/tests/odb/loose.c b/tests/odb/loose.c index 5cf567cc2..dbbc1490e 100644 --- a/tests/odb/loose.c +++ b/tests/odb/loose.c @@ -187,7 +187,7 @@ void test_odb_loose__read_header(void) test_read_header(&some); } -void test_write_object_permission( +static void test_write_object_permission( mode_t dir_mode, mode_t file_mode, mode_t expected_dir_mode, mode_t expected_file_mode) { diff --git a/tests/online/clone.c b/tests/online/clone.c index ba88dff9c..8186dda16 100644 --- a/tests/online/clone.c +++ b/tests/online/clone.c @@ -361,7 +361,7 @@ void test_online_clone__cred_callback_called_again_on_auth_failure(void) cl_assert_equal_i(3, counter); } -int cred_default( +static int cred_default( git_credential **cred, const char *url, const char *user_from_url, @@ -618,7 +618,7 @@ void test_online_clone__ssh_cannot_change_username(void) cl_git_fail(git_clone(&g_repo, "ssh://git@github.com/libgit2/TestGitRepository", "./foo", &g_options)); } -int ssh_certificate_check(git_cert *cert, int valid, const char *host, void *payload) +static int ssh_certificate_check(git_cert *cert, int valid, const char *host, void *payload) { git_cert_hostkey *key; git_oid expected = {{0}}, actual = {{0}}; diff --git a/tests/online/push_util.c b/tests/online/push_util.c index 94e310f3d..cd1831d4c 100644 --- a/tests/online/push_util.c +++ b/tests/online/push_util.c @@ -10,7 +10,7 @@ void updated_tip_free(updated_tip *t) git__free(t); } -void push_status_free(push_status *s) +static void push_status_free(push_status *s) { git__free(s->ref); git__free(s->msg); diff --git a/tests/pack/filelimit.c b/tests/pack/filelimit.c index 2b7bf6e95..fa08485fb 100644 --- a/tests/pack/filelimit.c +++ b/tests/pack/filelimit.c @@ -47,7 +47,7 @@ void test_pack_filelimit__cleanup(void) * (README.md) has the same content in all commits, but the second one * (file.txt) has a different content in each commit. */ -void create_packfile_commit( +static void create_packfile_commit( git_repository *repo, git_oid *out_commit_id, git_oid *parent_id, diff --git a/tests/patch/print.c b/tests/patch/print.c index b0a933943..33cf27ddb 100644 --- a/tests/patch/print.c +++ b/tests/patch/print.c @@ -9,7 +9,7 @@ * and then print a variety of patch files. */ -void patch_print_from_patchfile(const char *data, size_t len) +static void patch_print_from_patchfile(const char *data, size_t len) { git_patch *patch; git_buf buf = GIT_BUF_INIT; diff --git a/tests/path/dotgit.c b/tests/path/dotgit.c index 9ac68b0ff..855145f42 100644 --- a/tests/path/dotgit.c +++ b/tests/path/dotgit.c @@ -120,7 +120,7 @@ void test_path_dotgit__dotgit_modules_symlink(void) cl_assert_equal_b(false, git_path_is_valid(NULL, ".gitmodules . .::$DATA", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS)); } -void test_core_path__git_fs_path_is_file(void) +void test_path_dotgit__git_fs_path_is_file(void) { cl_git_fail(git_path_is_gitfile("blob", 4, -1, GIT_PATH_FS_HFS)); cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITIGNORE, GIT_PATH_FS_HFS)); diff --git a/tests/path/win32.c b/tests/path/win32.c index 46b5c9f70..ff166395d 100644 --- a/tests/path/win32.c +++ b/tests/path/win32.c @@ -6,35 +6,27 @@ #include "win32/path_w32.h" #endif -void test_utf8_to_utf16(const char *utf8_in, const wchar_t *utf16_expected) -{ #ifdef GIT_WIN32 +static void test_utf8_to_utf16(const char *utf8_in, const wchar_t *utf16_expected) +{ git_win32_path path_utf16; int path_utf16len; cl_assert((path_utf16len = git_win32_path_from_utf8(path_utf16, utf8_in)) >= 0); cl_assert_equal_wcs(utf16_expected, path_utf16); cl_assert_equal_i(wcslen(utf16_expected), path_utf16len); -#else - GIT_UNUSED(utf8_in); - GIT_UNUSED(utf16_expected); -#endif } -void test_utf8_to_utf16_relative(const char* utf8_in, const wchar_t* utf16_expected) +static void test_utf8_to_utf16_relative(const char* utf8_in, const wchar_t* utf16_expected) { -#ifdef GIT_WIN32 git_win32_path path_utf16; int path_utf16len; cl_assert((path_utf16len = git_win32_path_relative_from_utf8(path_utf16, utf8_in)) >= 0); cl_assert_equal_wcs(utf16_expected, path_utf16); cl_assert_equal_i(wcslen(utf16_expected), path_utf16len); -#else - GIT_UNUSED(utf8_in); - GIT_UNUSED(utf16_expected); -#endif } +#endif void test_path_win32__utf8_to_utf16(void) { diff --git a/tests/rebase/iterator.c b/tests/rebase/iterator.c index 49a601243..a120f28ac 100644 --- a/tests/rebase/iterator.c +++ b/tests/rebase/iterator.c @@ -47,7 +47,7 @@ static void test_operations(git_rebase *rebase, size_t expected_current) } } -void test_iterator(bool inmemory) +static void test_iterator(bool inmemory) { git_rebase *rebase; git_rebase_options opts = GIT_REBASE_OPTIONS_INIT; diff --git a/tests/rebase/merge.c b/tests/rebase/merge.c index d24e4facf..5f730f750 100644 --- a/tests/rebase/merge.c +++ b/tests/rebase/merge.c @@ -729,7 +729,7 @@ void test_rebase_merge__copy_notes_disabled_in_config(void) test_copy_note(NULL, 0); } -void rebase_checkout_progress_cb( +static void rebase_checkout_progress_cb( const char *path, size_t completed_steps, size_t total_steps, diff --git a/tests/rebase/sign.c b/tests/rebase/sign.c index dc99407dd..4064cf79b 100644 --- a/tests/rebase/sign.c +++ b/tests/rebase/sign.c @@ -86,7 +86,7 @@ committer Rebaser 1405694510 +0000\n"; git_rebase_free(rebase); } -int create_cb_signed_gpg( +static int create_cb_signed_gpg( git_oid *out, const git_signature *author, const git_signature *committer, diff --git a/tests/refs/shorthand.c b/tests/refs/shorthand.c index f995d26ca..e008adc74 100644 --- a/tests/refs/shorthand.c +++ b/tests/refs/shorthand.c @@ -2,7 +2,7 @@ #include "repository.h" -void assert_shorthand(git_repository *repo, const char *refname, const char *shorthand) +static void assert_shorthand(git_repository *repo, const char *refname, const char *shorthand) { git_reference *ref; diff --git a/tests/remote/fetch.c b/tests/remote/fetch.c index 209c42993..370046267 100644 --- a/tests/remote/fetch.c +++ b/tests/remote/fetch.c @@ -62,7 +62,7 @@ void test_remote_fetch__cleanup(void) { * @param force Whether to use a spec with '+' prefixed to force the refs * to update */ -void do_time_travelling_fetch(git_oid *commit1id, git_oid *commit2id, +static void do_time_travelling_fetch(git_oid *commit1id, git_oid *commit2id, bool force) { char *refspec_strs = { force ? FORCE_FETCHSPEC : NON_FORCE_FETCHSPEC, diff --git a/tests/remote/httpproxy.c b/tests/remote/httpproxy.c index 8cd4371f5..f62a2545b 100644 --- a/tests/remote/httpproxy.c +++ b/tests/remote/httpproxy.c @@ -40,7 +40,7 @@ void test_remote_httpproxy__cleanup(void) cl_git_sandbox_cleanup(); } -void assert_proxy_is(const char *expected) +static void assert_proxy_is(const char *expected) { git_remote *remote; char *proxy; @@ -57,7 +57,7 @@ void assert_proxy_is(const char *expected) git__free(proxy); } -void assert_config_match(const char *config, const char *expected) +static void assert_config_match(const char *config, const char *expected) { git_remote *remote; char *proxy; @@ -106,7 +106,7 @@ void test_remote_httpproxy__config_empty_overrides(void) assert_config_match("remote.lg2.proxy", ""); } -void assert_global_config_match(const char *config, const char *expected) +static void assert_global_config_match(const char *config, const char *expected) { git_remote *remote; char *proxy; diff --git a/tests/stash/apply.c b/tests/stash/apply.c index c3d1ef0c2..5125ae639 100644 --- a/tests/stash/apply.c +++ b/tests/stash/apply.c @@ -316,7 +316,7 @@ struct seen_paths { bool when; }; -int checkout_notify( +static int checkout_notify( git_checkout_notify_t why, const char *path, const git_diff_file *baseline, @@ -368,7 +368,7 @@ void test_stash_apply__executes_notify_cb(void) cl_assert_equal_b(true, seen_paths.when); } -int progress_cb( +static int progress_cb( git_stash_apply_progress_t progress, void *payload) { @@ -393,7 +393,7 @@ void test_stash_apply__calls_progress_cb(void) cl_assert_equal_i(progress, GIT_STASH_APPLY_PROGRESS_DONE); } -int aborting_progress_cb( +static int aborting_progress_cb( git_stash_apply_progress_t progress, void *payload) { diff --git a/tests/stash/drop.c b/tests/stash/drop.c index 709ff0f9e..a57147172 100644 --- a/tests/stash/drop.c +++ b/tests/stash/drop.c @@ -140,7 +140,7 @@ void test_stash_drop__dropping_the_last_entry_removes_the_stash(void) git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE), GIT_ENOTFOUND); } -void retrieve_top_stash_id(git_oid *out) +static void retrieve_top_stash_id(git_oid *out) { git_object *top_stash; diff --git a/tests/status/worktree.c b/tests/status/worktree.c index 692ea93ef..00c6ec2d5 100644 --- a/tests/status/worktree.c +++ b/tests/status/worktree.c @@ -43,7 +43,7 @@ void test_status_worktree__whole_repository(void) cl_assert_equal_i(0, counts.wrong_sorted_path); } -void assert_show( +static void assert_show( const int entry_counts, const char *entry_paths[], const unsigned int entry_statuses[], diff --git a/tests/submodule/modify.c b/tests/submodule/modify.c index fd3b0f80b..7e7f0ca15 100644 --- a/tests/submodule/modify.c +++ b/tests/submodule/modify.c @@ -128,7 +128,7 @@ void test_submodule_modify__sync(void) git_submodule_free(sm3); } -void assert_ignore_change(git_submodule_ignore_t ignore) +static void assert_ignore_change(git_submodule_ignore_t ignore) { git_submodule *sm; @@ -146,7 +146,7 @@ void test_submodule_modify__set_ignore(void) assert_ignore_change(GIT_SUBMODULE_IGNORE_ALL); } -void assert_update_change(git_submodule_update_t update) +static void assert_update_change(git_submodule_update_t update) { git_submodule *sm; @@ -164,7 +164,7 @@ void test_submodule_modify__set_update(void) assert_update_change(GIT_SUBMODULE_UPDATE_CHECKOUT); } -void assert_recurse_change(git_submodule_recurse_t recurse) +static void assert_recurse_change(git_submodule_recurse_t recurse) { git_submodule *sm; -- cgit v1.2.1 From bfdc09714f07d4007c94dee6a9567cee6be9f290 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 13:32:00 -0500 Subject: test: correct test names --- tests/odb/loose.c | 2 +- tests/refs/branches/name.c | 2 +- tests/refs/tags/name.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/odb/loose.c b/tests/odb/loose.c index dbbc1490e..fe013a78c 100644 --- a/tests/odb/loose.c +++ b/tests/odb/loose.c @@ -228,7 +228,7 @@ void test_odb_loose__permissions_standard(void) test_write_object_permission(0, 0, GIT_OBJECT_DIR_MODE, GIT_OBJECT_FILE_MODE); } -void test_odb_loose_permissions_readonly(void) +void test_odb_loose__permissions_readonly(void) { test_write_object_permission(0777, 0444, 0777, 0444); } diff --git a/tests/refs/branches/name.c b/tests/refs/branches/name.c index 290916eec..efa68e32b 100644 --- a/tests/refs/branches/name.c +++ b/tests/refs/branches/name.c @@ -51,7 +51,7 @@ static int name_is_valid(const char *name) return valid; } -void test_refs_branches_is_name_valid(void) +void test_refs_branches_name__is_name_valid(void) { cl_assert_equal_i(true, name_is_valid("master")); cl_assert_equal_i(true, name_is_valid("test/master")); diff --git a/tests/refs/tags/name.c b/tests/refs/tags/name.c index 0ca5df7d6..1dd1760b9 100644 --- a/tests/refs/tags/name.c +++ b/tests/refs/tags/name.c @@ -7,7 +7,7 @@ static int name_is_valid(const char *name) return valid; } -void test_refs_tags_is_name_valid(void) +void test_refs_tags_name__is_name_valid(void) { cl_assert_equal_i(true, name_is_valid("sometag")); cl_assert_equal_i(true, name_is_valid("test/sometag")); -- cgit v1.2.1 From 8d2b31109d980462e1853bef3edf08ddecd094b2 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 19:58:49 +0000 Subject: tests: include function declarations --- tests/filter/custom_helpers.c | 1 + tests/merge/merge_helpers.h | 4 ++++ tests/refs/ref_helpers.c | 1 + tests/refs/reflog/reflog_helpers.c | 3 ++- tests/refs/reflog/reflog_helpers.h | 8 +++++--- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/filter/custom_helpers.c b/tests/filter/custom_helpers.c index f98f65c22..95a9f978e 100644 --- a/tests/filter/custom_helpers.c +++ b/tests/filter/custom_helpers.c @@ -2,6 +2,7 @@ #include "posix.h" #include "filter.h" #include "git2/sys/filter.h" +#include "custom_helpers.h" #define VERY_SECURE_ENCRYPTION(b) ((b) ^ 0xff) diff --git a/tests/merge/merge_helpers.h b/tests/merge/merge_helpers.h index 166b4eefd..339812ba5 100644 --- a/tests/merge/merge_helpers.h +++ b/tests/merge/merge_helpers.h @@ -65,4 +65,8 @@ int merge_test_reuc(git_index *index, const struct merge_reuc_entry expected[], int merge_test_workdir(git_repository *repo, const struct merge_index_entry expected[], size_t expected_len); +void merge__dump_names(git_index *index); +void merge__dump_index_entries(git_vector *index_entries); +void merge__dump_reuc(git_index *index); + #endif diff --git a/tests/refs/ref_helpers.c b/tests/refs/ref_helpers.c index 943d0f551..70d5d36d5 100644 --- a/tests/refs/ref_helpers.c +++ b/tests/refs/ref_helpers.c @@ -3,6 +3,7 @@ #include "common.h" #include "util.h" #include "path.h" +#include "ref_helpers.h" int reference_is_packed(git_reference *ref) { diff --git a/tests/refs/reflog/reflog_helpers.c b/tests/refs/reflog/reflog_helpers.c index 22619a4e3..2ea41ee06 100644 --- a/tests/refs/reflog/reflog_helpers.c +++ b/tests/refs/reflog/reflog_helpers.c @@ -2,8 +2,9 @@ #include "repository.h" #include "reflog.h" +#include "reflog_helpers.h" -static int reflog_entry_tostr(git_str *out, const git_reflog_entry *entry) +int reflog_entry_tostr(git_str *out, const git_reflog_entry *entry) { char old_oid[GIT_OID_HEXSZ], new_oid[GIT_OID_HEXSZ]; diff --git a/tests/refs/reflog/reflog_helpers.h b/tests/refs/reflog/reflog_helpers.h index 80814ea28..4cd92cadc 100644 --- a/tests/refs/reflog/reflog_helpers.h +++ b/tests/refs/reflog/reflog_helpers.h @@ -1,10 +1,12 @@ size_t reflog_entrycount(git_repository *repo, const char *name); #define cl_reflog_check_entry(repo, reflog, idx, old_spec, new_spec, email, message) \ - cl_reflog_check_entry_(repo, reflog, idx, old_spec, new_spec, email, message, __FILE__, __LINE__) + cl_reflog_check_entry_(repo, reflog, idx, old_spec, new_spec, email, message, __FILE__, __FUNCTION__, __LINE__) void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx, - const char *old_spec, const char *new_spec, - const char *email, const char *message, const char *file, int line); + const char *old_spec, const char *new_spec, + const char *email, const char *message, + const char *file, const char *func, int line); void reflog_print(git_repository *repo, const char *reflog_name); +int reflog_entry_tostr(git_str *out, const git_reflog_entry *entry); -- cgit v1.2.1 From 4a6ef5a4a6cabfaa7147aab28130da49e5b177ea Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 17:04:24 -0500 Subject: cmake: move missing-declarations warning to top-level We should enforce declarations throughout the code-base, including examples, fuzzers and tests, not just in the `src` tree. --- cmake/DefaultCFlags.cmake | 1 + src/CMakeLists.txt | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/cmake/DefaultCFlags.cmake b/cmake/DefaultCFlags.cmake index d122f6c25..fa59e1d97 100644 --- a/cmake/DefaultCFlags.cmake +++ b/cmake/DefaultCFlags.cmake @@ -125,6 +125,7 @@ else() enable_warnings(documentation) disable_warnings(documentation-deprecated-sync) disable_warnings(missing-field-initializers) + enable_warnings(missing-declarations) enable_warnings(strict-aliasing) enable_warnings(strict-prototypes) enable_warnings(declaration-after-statement) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ae02ef9aa..6a128cfa8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,8 +41,6 @@ set(LIBGIT2_INCLUDES set(LIBGIT2_SYSTEM_INCLUDES "") set(LIBGIT2_LIBS "") -enable_warnings(missing-declarations) - if(HAVE_FUTIMENS) set(GIT_USE_FUTIMENS 1) endif () -- cgit v1.2.1 From 709b1b62686d3526eb27169a4d80c0ed4e8f7e55 Mon Sep 17 00:00:00 2001 From: Jason Nader Date: Fri, 5 Nov 2021 02:28:37 +0900 Subject: repository: do not copy templates if dir nonexistent This mimics the behaviour of git which just prints a warning and continues with the repo initialisation. --- src/repository.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/repository.c b/src/repository.c index 29684e463..2002e1186 100644 --- a/src/repository.c +++ b/src/repository.c @@ -2032,9 +2032,15 @@ static int repo_init_structure( git_str_dispose(&template_buf); git_config_free(cfg); + /* If tdir does not exist, then do not error out. This matches the + * behaviour of git(1), which just prints a warning and continues. + * TODO: issue warning when warning API is available. + * `git` prints to stderr: 'warning: templates not found in /path/to/tdir' + */ if (error < 0) { - if (!default_template) + if (!default_template && error != GIT_ENOTFOUND) { return error; + } /* if template was default, ignore error and use internal */ git_error_clear(); -- cgit v1.2.1 From bc0d1ad21e17a610dd484a8970cb2765ae8b6c8e Mon Sep 17 00:00:00 2001 From: Jason Nader Date: Fri, 5 Nov 2021 03:08:43 +0900 Subject: tests: try to init with non-existent template path --- tests/repo/template.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/repo/template.c b/tests/repo/template.c index 6f369c6d6..99d4b6fd4 100644 --- a/tests/repo/template.c +++ b/tests/repo/template.c @@ -293,3 +293,13 @@ void test_repo_template__empty_template_path(void) setup_repo("foo", &opts); } + +void test_repo_template__nonexistent_template_path(void) +{ + git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; + + opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE; + opts.template_path = "/tmp/path/that/does/not/exist/for/libgit2/test"; + + setup_repo("bar", &opts); +} -- cgit v1.2.1 From 0c4d24dad2db95132568043bb086dff2af400eda Mon Sep 17 00:00:00 2001 From: lhchavez Date: Sun, 14 Nov 2021 02:24:39 -0800 Subject: Fix a gcc 11 warning in src/threadstate.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building under gcc 11, there is a warning about a misaligned guard clause because there were mixed spaces and tabs: ``` [128/634] Building C object src/CMakeFiles/git2internal.dir/threadstate.c.o ../src/threadstate.c: In function ‘threadstate_dispose’: ../src/threadstate.c:39:5: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation] 39 | if (threadstate->error_t.message != git_str__initstr) | ^~ ../src/threadstate.c:41:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’ 41 | threadstate->error_t.message = NULL; | ^~~~~~~~~~~ ../src/threadstate.c: At top level: ``` This change indents the code with tabs for consistency with the rest of the code, which makes the warning go away. --- src/threadstate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/threadstate.c b/src/threadstate.c index f67cf082b..9e3ef5818 100644 --- a/src/threadstate.c +++ b/src/threadstate.c @@ -36,8 +36,8 @@ static void threadstate_dispose(git_threadstate *threadstate) if (!threadstate) return; - if (threadstate->error_t.message != git_str__initstr) - git__free(threadstate->error_t.message); + if (threadstate->error_t.message != git_str__initstr) + git__free(threadstate->error_t.message); threadstate->error_t.message = NULL; } -- cgit v1.2.1 From 5675312e5aeb0c8b438df3ba9da7542673b2e0e7 Mon Sep 17 00:00:00 2001 From: lhchavez Date: Sun, 14 Nov 2021 02:27:10 -0800 Subject: Fix a gcc 11 warning in src/thread.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building under gcc 11, there is a warning about an incompatible pointer type, since [`__atomic_exchange`](https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html) does not take `volatile` pointers: ``` In file included from ../src/common.h:81, from ../src/transports/winhttp.c:8: ../src/thread-utils.h: In function ‘git___swap’: ../src/thread-utils.h:168:9: warning: argument 3 of ‘__atomic_exchange’ discards ‘volatile’ qualifier [-Wincompatible-pointer-types] 168 | __atomic_exchange(ptr, &newval, &foundval, __ATOMIC_SEQ_CST); | ^~~~~~~~~~~~~~~~~ ``` This change drops the `volatile` qualifier so that the pointer type matches what `__atomic_exchange` expects. --- src/thread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread.h b/src/thread.h index 82eb7fcab..4bbac9fd8 100644 --- a/src/thread.h +++ b/src/thread.h @@ -180,7 +180,7 @@ GIT_INLINE(volatile void *) git_atomic__swap( #if defined(GIT_WIN32) return InterlockedExchangePointer(ptr, newval); #elif defined(GIT_BUILTIN_ATOMIC) - void * volatile foundval = NULL; + void * foundval = NULL; __atomic_exchange(ptr, &newval, &foundval, __ATOMIC_SEQ_CST); return foundval; #elif defined(GIT_BUILTIN_SYNC) -- cgit v1.2.1 From c3fec45645e6939b3604d2d233be6f97ff629f87 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 22:37:36 -0500 Subject: cmake: reformat modules Apply the standard project cmake formatting to the modules. --- cmake/AddCFlagIfSupported.cmake | 42 ++-- cmake/EnableWarnings.cmake | 26 +-- cmake/FindCoreFoundation.cmake | 26 +-- cmake/FindGSSAPI.cmake | 456 +++++++++++++++------------------------- cmake/FindGSSFramework.cmake | 26 +-- cmake/FindHTTPParser.cmake | 34 +-- cmake/FindIconv.cmake | 54 ++--- cmake/FindLibSSH2.cmake | 10 +- cmake/FindPCRE.cmake | 26 +-- cmake/FindPCRE2.cmake | 24 +-- cmake/FindPkgLibraries.cmake | 38 ++-- cmake/FindSecurity.cmake | 28 +-- cmake/Findfutimens.cmake | 16 +- cmake/FindmbedTLS.cmake | 133 ++++++------ cmake/IdeSplitSources.cmake | 34 +-- cmake/PkgBuildConfig.cmake | 120 +++++------ cmake/SanitizeBool.cmake | 40 ++-- cmake/SelectGSSAPI.cmake | 74 +++---- cmake/SelectHTTPSBackend.cmake | 200 +++++++++--------- cmake/SelectHashes.cmake | 94 ++++----- 20 files changed, 689 insertions(+), 812 deletions(-) diff --git a/cmake/AddCFlagIfSupported.cmake b/cmake/AddCFlagIfSupported.cmake index b7aaa7910..685f26a00 100644 --- a/cmake/AddCFlagIfSupported.cmake +++ b/cmake/AddCFlagIfSupported.cmake @@ -3,28 +3,28 @@ # - the compiler flag to test # This internally calls the CHECK_C_COMPILER_FLAG macro. -INCLUDE(CheckCCompilerFlag) +include(CheckCCompilerFlag) -MACRO(ADD_C_FLAG _FLAG) - STRING(TOUPPER ${_FLAG} UPCASE) - STRING(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE}) - STRING(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY}) - CHECK_C_COMPILER_FLAG(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED) +macro(ADD_C_FLAG _FLAG) + string(TOUPPER ${_FLAG} UPCASE) + string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE}) + string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY}) + check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED) - IF(IS_${UPCASE_PRETTY}_SUPPORTED) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}") - ELSE() - MESSAGE(FATAL_ERROR "Required flag ${_FLAG} is not supported") - ENDIF() -ENDMACRO() + if(IS_${UPCASE_PRETTY}_SUPPORTED) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}") + else() + message(FATAL_ERROR "Required flag ${_FLAG} is not supported") + endif() +endmacro() -MACRO(ADD_C_FLAG_IF_SUPPORTED _FLAG) - STRING(TOUPPER ${_FLAG} UPCASE) - STRING(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE}) - STRING(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY}) - CHECK_C_COMPILER_FLAG(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED) +macro(ADD_C_FLAG_IF_SUPPORTED _FLAG) + string(TOUPPER ${_FLAG} UPCASE) + string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE}) + string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY}) + check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED) - IF(IS_${UPCASE_PRETTY}_SUPPORTED) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}") - ENDIF() -ENDMACRO() + if(IS_${UPCASE_PRETTY}_SUPPORTED) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}") + endif() +endmacro() diff --git a/cmake/EnableWarnings.cmake b/cmake/EnableWarnings.cmake index b61ed7e90..0700b521b 100644 --- a/cmake/EnableWarnings.cmake +++ b/cmake/EnableWarnings.cmake @@ -1,15 +1,15 @@ -MACRO(ENABLE_WARNINGS flag) - ADD_C_FLAG_IF_SUPPORTED(-W${flag}) -ENDMACRO() +macro(ENABLE_WARNINGS flag) + add_c_flag_if_supported(-W${flag}) +endmacro() -MACRO(DISABLE_WARNINGS flag) - ADD_C_FLAG_IF_SUPPORTED(-Wno-${flag}) -ENDMACRO() +macro(DISABLE_WARNINGS flag) + add_c_flag_if_supported(-Wno-${flag}) +endmacro() -IF(ENABLE_WERROR) - IF(MSVC) - ADD_COMPILE_OPTIONS(-WX) - ELSE() - ADD_C_FLAG_IF_SUPPORTED(-Werror) - ENDIF() -ENDIF() +if(ENABLE_WERROR) + if(MSVC) + add_compile_options(-WX) + else() + add_c_flag_if_supported(-Werror) + endif() +endif() diff --git a/cmake/FindCoreFoundation.cmake b/cmake/FindCoreFoundation.cmake index 191aa595c..b419ec9ab 100644 --- a/cmake/FindCoreFoundation.cmake +++ b/cmake/FindCoreFoundation.cmake @@ -6,21 +6,21 @@ # COREFOUNDATION_LDFLAGS # -FIND_PATH(COREFOUNDATION_INCLUDE_DIR NAMES CoreFoundation.h) -FIND_LIBRARY(COREFOUNDATION_LIBRARIES NAMES CoreFoundation) -IF (COREFOUNDATION_INCLUDE_DIR AND COREFOUNDATION_LIBRARIES) - IF (NOT CoreFoundation_FIND_QUIETLY) - MESSAGE(STATUS "Found CoreFoundation ${COREFOUNDATION_LIBRARIES}") - ENDIF() - SET(COREFOUNDATION_FOUND TRUE) - SET(COREFOUNDATION_LDFLAGS "-framework CoreFoundation") -ENDIF () +find_path(COREFOUNDATION_INCLUDE_DIR NAMES CoreFoundation.h) +find_library(COREFOUNDATION_LIBRARIES NAMES CoreFoundation) +if(COREFOUNDATION_INCLUDE_DIR AND COREFOUNDATION_LIBRARIES) + if(NOT CoreFoundation_FIND_QUIETLY) + message(STATUS "Found CoreFoundation ${COREFOUNDATION_LIBRARIES}") + endif() + set(COREFOUNDATION_FOUND TRUE) + set(COREFOUNDATION_LDFLAGS "-framework CoreFoundation") +endif() -IF (CoreFoundation_FIND_REQUIRED AND NOT COREFOUNDATION_FOUND) - MESSAGE(FATAL_ERROR "CoreFoundation not found") -ENDIF() +if(CoreFoundation_FIND_REQUIRED AND NOT COREFOUNDATION_FOUND) + message(FATAL_ERROR "CoreFoundation not found") +endif() -MARK_AS_ADVANCED( +mark_as_advanced( COREFOUNDATION_INCLUDE_DIR COREFOUNDATION_LIBRARIES ) diff --git a/cmake/FindGSSAPI.cmake b/cmake/FindGSSAPI.cmake index 37357c4cd..0f5932a22 100644 --- a/cmake/FindGSSAPI.cmake +++ b/cmake/FindGSSAPI.cmake @@ -25,300 +25,184 @@ # find_path(GSSAPI_ROOT_DIR - NAMES - include/gssapi.h - include/gssapi/gssapi.h - HINTS - ${_GSSAPI_ROOT_HINTS} - PATHS - ${_GSSAPI_ROOT_PATHS} -) + NAMES include/gssapi.h include/gssapi/gssapi.h + HINTS ${_GSSAPI_ROOT_HINTS} + PATHS ${_GSSAPI_ROOT_PATHS}) mark_as_advanced(GSSAPI_ROOT_DIR) -if (UNIX) - find_program(KRB5_CONFIG - NAMES - krb5-config - PATHS - ${GSSAPI_ROOT_DIR}/bin - /opt/local/bin) - mark_as_advanced(KRB5_CONFIG) - - if (KRB5_CONFIG) - # Check if we have MIT KRB5 - execute_process( - COMMAND - ${KRB5_CONFIG} --vendor - RESULT_VARIABLE - _GSSAPI_VENDOR_RESULT - OUTPUT_VARIABLE - _GSSAPI_VENDOR_STRING) - - if (_GSSAPI_VENDOR_STRING MATCHES ".*Massachusetts.*") - set(GSSAPI_FLAVOR_MIT TRUE) - else() - execute_process( - COMMAND - ${KRB5_CONFIG} --libs gssapi - RESULT_VARIABLE - _GSSAPI_LIBS_RESULT - OUTPUT_VARIABLE - _GSSAPI_LIBS_STRING) - - if (_GSSAPI_LIBS_STRING MATCHES ".*roken.*") - set(GSSAPI_FLAVOR_HEIMDAL TRUE) - endif() - endif() - - # Get the include dir - execute_process( - COMMAND - ${KRB5_CONFIG} --cflags gssapi - RESULT_VARIABLE - _GSSAPI_INCLUDE_RESULT - OUTPUT_VARIABLE - _GSSAPI_INCLUDE_STRING) - string(REGEX REPLACE "(\r?\n)+$" "" _GSSAPI_INCLUDE_STRING "${_GSSAPI_INCLUDE_STRING}") - string(REGEX REPLACE " *-I" "" _GSSAPI_INCLUDEDIR "${_GSSAPI_INCLUDE_STRING}") - endif() - - if (NOT GSSAPI_FLAVOR_MIT AND NOT GSSAPI_FLAVOR_HEIMDAL) - # Check for HEIMDAL - find_package(PkgConfig) - if (PKG_CONFIG_FOUND) - pkg_check_modules(_GSSAPI heimdal-gssapi) - endif (PKG_CONFIG_FOUND) - - if (_GSSAPI_FOUND) - set(GSSAPI_FLAVOR_HEIMDAL TRUE) - else() - find_path(_GSSAPI_ROKEN - NAMES - roken.h - PATHS - ${GSSAPI_ROOT_DIR}/include - ${_GSSAPI_INCLUDEDIR}) - if (_GSSAPI_ROKEN) - set(GSSAPI_FLAVOR_HEIMDAL TRUE) - endif() - endif () - endif() -endif (UNIX) +if(UNIX) + find_program(KRB5_CONFIG + NAMES krb5-config + PATHS ${GSSAPI_ROOT_DIR}/bin /opt/local/bin) + mark_as_advanced(KRB5_CONFIG) + + if(KRB5_CONFIG) + # Check if we have MIT KRB5 + execute_process( + COMMAND ${KRB5_CONFIG} --vendor + RESULT_VARIABLE _GSSAPI_VENDOR_RESULT + OUTPUT_VARIABLE _GSSAPI_VENDOR_STRING) + + if(_GSSAPI_VENDOR_STRING MATCHES ".*Massachusetts.*") + set(GSSAPI_FLAVOR_MIT TRUE) + else() + execute_process( + COMMAND ${KRB5_CONFIG} --libs gssapi + RESULT_VARIABLE _GSSAPI_LIBS_RESULT + OUTPUT_VARIABLE _GSSAPI_LIBS_STRING) + + if(_GSSAPI_LIBS_STRING MATCHES ".*roken.*") + set(GSSAPI_FLAVOR_HEIMDAL TRUE) + endif() + endif() + + # Get the include dir + execute_process( + COMMAND ${KRB5_CONFIG} --cflags gssapi + RESULT_VARIABLE _GSSAPI_INCLUDE_RESULT + OUTPUT_VARIABLE _GSSAPI_INCLUDE_STRING) + string(REGEX REPLACE "(\r?\n)+$" "" _GSSAPI_INCLUDE_STRING "${_GSSAPI_INCLUDE_STRING}") + string(REGEX REPLACE " *-I" "" _GSSAPI_INCLUDEDIR "${_GSSAPI_INCLUDE_STRING}") + endif() + + if(NOT GSSAPI_FLAVOR_MIT AND NOT GSSAPI_FLAVOR_HEIMDAL) + # Check for HEIMDAL + find_package(PkgConfig) + if(PKG_CONFIG_FOUND) + pkg_check_modules(_GSSAPI heimdal-gssapi) + endif() + + if(_GSSAPI_FOUND) + set(GSSAPI_FLAVOR_HEIMDAL TRUE) + else() + find_path(_GSSAPI_ROKEN + NAMES roken.h + PATHS ${GSSAPI_ROOT_DIR}/include ${_GSSAPI_INCLUDEDIR}) + if(_GSSAPI_ROKEN) + set(GSSAPI_FLAVOR_HEIMDAL TRUE) + endif() + endif() + endif() +endif() find_path(GSSAPI_INCLUDE_DIR - NAMES - gssapi.h - gssapi/gssapi.h - PATHS - ${GSSAPI_ROOT_DIR}/include - ${_GSSAPI_INCLUDEDIR} -) - -if (GSSAPI_FLAVOR_MIT) - find_library(GSSAPI_LIBRARY - NAMES - gssapi_krb5 - PATHS - ${GSSAPI_ROOT_DIR}/lib - ${_GSSAPI_LIBDIR} - ) - - find_library(KRB5_LIBRARY - NAMES - krb5 - PATHS - ${GSSAPI_ROOT_DIR}/lib - ${_GSSAPI_LIBDIR} - ) - - find_library(K5CRYPTO_LIBRARY - NAMES - k5crypto - PATHS - ${GSSAPI_ROOT_DIR}/lib - ${_GSSAPI_LIBDIR} - ) - - find_library(COM_ERR_LIBRARY - NAMES - com_err - PATHS - ${GSSAPI_ROOT_DIR}/lib - ${_GSSAPI_LIBDIR} - ) - - if (GSSAPI_LIBRARY) - set(GSSAPI_LIBRARIES - ${GSSAPI_LIBRARIES} - ${GSSAPI_LIBRARY} - ) - endif (GSSAPI_LIBRARY) - - if (KRB5_LIBRARY) - set(GSSAPI_LIBRARIES - ${GSSAPI_LIBRARIES} - ${KRB5_LIBRARY} - ) - endif (KRB5_LIBRARY) - - if (K5CRYPTO_LIBRARY) - set(GSSAPI_LIBRARIES - ${GSSAPI_LIBRARIES} - ${K5CRYPTO_LIBRARY} - ) - endif (K5CRYPTO_LIBRARY) - - if (COM_ERR_LIBRARY) - set(GSSAPI_LIBRARIES - ${GSSAPI_LIBRARIES} - ${COM_ERR_LIBRARY} - ) - endif (COM_ERR_LIBRARY) -endif (GSSAPI_FLAVOR_MIT) - -if (GSSAPI_FLAVOR_HEIMDAL) - find_library(GSSAPI_LIBRARY - NAMES - gssapi - PATHS - ${GSSAPI_ROOT_DIR}/lib - ${_GSSAPI_LIBDIR} - ) - - find_library(KRB5_LIBRARY - NAMES - krb5 - PATHS - ${GSSAPI_ROOT_DIR}/lib - ${_GSSAPI_LIBDIR} - ) - - find_library(HCRYPTO_LIBRARY - NAMES - hcrypto - PATHS - ${GSSAPI_ROOT_DIR}/lib - ${_GSSAPI_LIBDIR} - ) - - find_library(COM_ERR_LIBRARY - NAMES - com_err - PATHS - ${GSSAPI_ROOT_DIR}/lib - ${_GSSAPI_LIBDIR} - ) - - find_library(HEIMNTLM_LIBRARY - NAMES - heimntlm - PATHS - ${GSSAPI_ROOT_DIR}/lib - ${_GSSAPI_LIBDIR} - ) - - find_library(HX509_LIBRARY - NAMES - hx509 - PATHS - ${GSSAPI_ROOT_DIR}/lib - ${_GSSAPI_LIBDIR} - ) - - find_library(ASN1_LIBRARY - NAMES - asn1 - PATHS - ${GSSAPI_ROOT_DIR}/lib - ${_GSSAPI_LIBDIR} - ) - - find_library(WIND_LIBRARY - NAMES - wind - PATHS - ${GSSAPI_ROOT_DIR}/lib - ${_GSSAPI_LIBDIR} - ) - - find_library(ROKEN_LIBRARY - NAMES - roken - PATHS - ${GSSAPI_ROOT_DIR}/lib - ${_GSSAPI_LIBDIR} - ) - - if (GSSAPI_LIBRARY) - set(GSSAPI_LIBRARIES - ${GSSAPI_LIBRARIES} - ${GSSAPI_LIBRARY} - ) - endif (GSSAPI_LIBRARY) - - if (KRB5_LIBRARY) - set(GSSAPI_LIBRARIES - ${GSSAPI_LIBRARIES} - ${KRB5_LIBRARY} - ) - endif (KRB5_LIBRARY) - - if (HCRYPTO_LIBRARY) - set(GSSAPI_LIBRARIES - ${GSSAPI_LIBRARIES} - ${HCRYPTO_LIBRARY} - ) - endif (HCRYPTO_LIBRARY) - - if (COM_ERR_LIBRARY) - set(GSSAPI_LIBRARIES - ${GSSAPI_LIBRARIES} - ${COM_ERR_LIBRARY} - ) - endif (COM_ERR_LIBRARY) - - if (HEIMNTLM_LIBRARY) - set(GSSAPI_LIBRARIES - ${GSSAPI_LIBRARIES} - ${HEIMNTLM_LIBRARY} - ) - endif (HEIMNTLM_LIBRARY) - - if (HX509_LIBRARY) - set(GSSAPI_LIBRARIES - ${GSSAPI_LIBRARIES} - ${HX509_LIBRARY} - ) - endif (HX509_LIBRARY) - - if (ASN1_LIBRARY) - set(GSSAPI_LIBRARIES - ${GSSAPI_LIBRARIES} - ${ASN1_LIBRARY} - ) - endif (ASN1_LIBRARY) - - if (WIND_LIBRARY) - set(GSSAPI_LIBRARIES - ${GSSAPI_LIBRARIES} - ${WIND_LIBRARY} - ) - endif (WIND_LIBRARY) - - if (ROKEN_LIBRARY) - set(GSSAPI_LIBRARIES - ${GSSAPI_LIBRARIES} - ${WIND_LIBRARY} - ) - endif (ROKEN_LIBRARY) -endif (GSSAPI_FLAVOR_HEIMDAL) + NAMES gssapi.h gssapi/gssapi.h + PATHS ${GSSAPI_ROOT_DIR}/include ${_GSSAPI_INCLUDEDIR}) + +if(GSSAPI_FLAVOR_MIT) + find_library(GSSAPI_LIBRARY + NAMES gssapi_krb5 + PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) + + find_library(KRB5_LIBRARY + NAMES krb5 + PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) + + find_library(K5CRYPTO_LIBRARY + NAMES k5crypto + PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) + + find_library(COM_ERR_LIBRARY + NAMES com_err + PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) + + if(GSSAPI_LIBRARY) + set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${GSSAPI_LIBRARY}) + endif() + + if(KRB5_LIBRARY) + set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${KRB5_LIBRARY}) + endif() + + if(K5CRYPTO_LIBRARY) + set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${K5CRYPTO_LIBRARY}) + endif() + + if(COM_ERR_LIBRARY) + set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${COM_ERR_LIBRARY}) + endif() +endif() + +if(GSSAPI_FLAVOR_HEIMDAL) + find_library(GSSAPI_LIBRARY + NAMES gssapi + PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) + + find_library(KRB5_LIBRARY + NAMES krb5 + PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) + + find_library(HCRYPTO_LIBRARY + NAMES hcrypto + PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) + + find_library(COM_ERR_LIBRARY + NAMES com_err + PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) + + find_library(HEIMNTLM_LIBRARY + NAMES heimntlm + PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) + + find_library(HX509_LIBRARY + NAMES hx509 + PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) + + find_library(ASN1_LIBRARY + NAMES asn1 + PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) + + find_library(WIND_LIBRARY + NAMES wind + PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) + + find_library(ROKEN_LIBRARY + NAMES roken + PATHS ${GSSAPI_ROOT_DIR}/lib ${_GSSAPI_LIBDIR}) + + if(GSSAPI_LIBRARY) + set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${GSSAPI_LIBRARY}) + endif() + + if(KRB5_LIBRARY) + set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${KRB5_LIBRARY}) + endif() + + if(HCRYPTO_LIBRARY) + set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${HCRYPTO_LIBRARY}) + endif() + + if(COM_ERR_LIBRARY) + set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${COM_ERR_LIBRARY}) + endif() + + if(HEIMNTLM_LIBRARY) + set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${HEIMNTLM_LIBRARY}) + endif() + + if(HX509_LIBRARY) + set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${HX509_LIBRARY}) + endif() + + if(ASN1_LIBRARY) + set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${ASN1_LIBRARY}) + endif() + + if(WIND_LIBRARY) + set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${WIND_LIBRARY}) + endif() + + if(ROKEN_LIBRARY) + set(GSSAPI_LIBRARIES ${GSSAPI_LIBRARIES} ${WIND_LIBRARY}) + endif() +endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(GSSAPI DEFAULT_MSG GSSAPI_LIBRARIES GSSAPI_INCLUDE_DIR) -if (GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES) - set(GSSAPI_FOUND TRUE) -endif (GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES) +if(GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES) + set(GSSAPI_FOUND TRUE) +endif(GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES) # show the GSSAPI_INCLUDE_DIRS and GSSAPI_LIBRARIES variables only in the advanced view mark_as_advanced(GSSAPI_INCLUDE_DIRS GSSAPI_LIBRARIES) diff --git a/cmake/FindGSSFramework.cmake b/cmake/FindGSSFramework.cmake index dcf724916..1b0c936d7 100644 --- a/cmake/FindGSSFramework.cmake +++ b/cmake/FindGSSFramework.cmake @@ -7,21 +7,21 @@ # GSSFRAMEWORK_LDFLAGS # -FIND_PATH(GSSFRAMEWORK_INCLUDE_DIR NAMES GSS.h) -FIND_LIBRARY(GSSFRAMEWORK_LIBRARIES NAMES GSS) -IF (GSSFRAMEWORK_INCLUDE_DIR AND GSSFRAMEWORK_LIBRARIES) - IF (NOT CoreFoundation_FIND_QUIETLY) - MESSAGE(STATUS "Found GSS.framework ${GSSFRAMEWORK_LIBRARIES}") - ENDIF() - SET(GSSFRAMEWORK_FOUND TRUE) - SET(GSSFRAMEWORK_LDFLAGS "-framework GSS") -ENDIF () +find_path(GSSFRAMEWORK_INCLUDE_DIR NAMES GSS.h) +find_library(GSSFRAMEWORK_LIBRARIES NAMES GSS) +if(GSSFRAMEWORK_INCLUDE_DIR AND GSSFRAMEWORK_LIBRARIES) + if(NOT CoreFoundation_FIND_QUIETLY) + message(STATUS "Found GSS.framework ${GSSFRAMEWORK_LIBRARIES}") + endif() + set(GSSFRAMEWORK_FOUND TRUE) + set(GSSFRAMEWORK_LDFLAGS "-framework GSS") +endif() -IF (GSS_FIND_REQUIRED AND NOT GSSFRAMEWORK_FOUND) - MESSAGE(FATAL_ERROR "CoreFoundation not found") -ENDIF() +if(GSS_FIND_REQUIRED AND NOT GSSFRAMEWORK_FOUND) + message(FATAL_ERROR "CoreFoundation not found") +endif() -MARK_AS_ADVANCED( +mark_as_advanced( GSSFRAMEWORK_INCLUDE_DIR GSSFRAMEWORK_LIBRARIES GSSFRAMEWORK_LDFLAGS diff --git a/cmake/FindHTTPParser.cmake b/cmake/FindHTTPParser.cmake index d92bf75cc..3350190e0 100644 --- a/cmake/FindHTTPParser.cmake +++ b/cmake/FindHTTPParser.cmake @@ -10,30 +10,30 @@ # HTTP_PARSER_VERSION_STRING - the version of http-parser found # Find the header and library -FIND_PATH(HTTP_PARSER_INCLUDE_DIR NAMES http_parser.h) -FIND_LIBRARY(HTTP_PARSER_LIBRARY NAMES http_parser libhttp_parser) +find_path(HTTP_PARSER_INCLUDE_DIR NAMES http_parser.h) +find_library(HTTP_PARSER_LIBRARY NAMES http_parser libhttp_parser) # Found the header, read version -if (HTTP_PARSER_INCLUDE_DIR AND EXISTS "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h") - FILE(READ "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h" HTTP_PARSER_H) - IF (HTTP_PARSER_H) - STRING(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MAJOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MAJOR "${HTTP_PARSER_H}") - STRING(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MINOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MINOR "${HTTP_PARSER_H}") - SET(HTTP_PARSER_VERSION_STRING "${HTTP_PARSER_VERSION_MAJOR}.${HTTP_PARSER_VERSION_MINOR}") - ENDIF() - UNSET(HTTP_PARSER_H) -ENDIF() +if(HTTP_PARSER_INCLUDE_DIR AND EXISTS "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h") + file(READ "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h" HTTP_PARSER_H) + if(HTTP_PARSER_H) + string(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MAJOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MAJOR "${HTTP_PARSER_H}") + string(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MINOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MINOR "${HTTP_PARSER_H}") + set(HTTP_PARSER_VERSION_STRING "${HTTP_PARSER_VERSION_MAJOR}.${HTTP_PARSER_VERSION_MINOR}") + endif() + unset(HTTP_PARSER_H) +endif() # Handle the QUIETLY and REQUIRED arguments and set HTTP_PARSER_FOUND # to TRUE if all listed variables are TRUE -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(HTTP_Parser REQUIRED_VARS HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(HTTP_Parser REQUIRED_VARS HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY) # Hide advanced variables -MARK_AS_ADVANCED(HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY) +mark_as_advanced(HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY) # Set standard variables -IF (HTTP_PARSER_FOUND) - SET(HTTP_PARSER_LIBRARIES ${HTTP_PARSER_LIBRARY}) +if(HTTP_PARSER_FOUND) + set(HTTP_PARSER_LIBRARIES ${HTTP_PARSER_LIBRARY}) set(HTTP_PARSER_INCLUDE_DIRS ${HTTP_PARSER_INCLUDE_DIR}) -ENDIF() +endif() diff --git a/cmake/FindIconv.cmake b/cmake/FindIconv.cmake index 3c66cdad4..9e6ded99d 100644 --- a/cmake/FindIconv.cmake +++ b/cmake/FindIconv.cmake @@ -6,40 +6,40 @@ # ICONV_LIBRARIES - Link these to use Iconv # -IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) +if(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) # Already in cache, be silent - SET(ICONV_FIND_QUIETLY TRUE) -ENDIF() + set(ICONV_FIND_QUIETLY TRUE) +endif() -FIND_PATH(ICONV_INCLUDE_DIR iconv.h) -CHECK_FUNCTION_EXISTS(iconv_open libc_has_iconv) -FIND_LIBRARY(iconv_lib NAMES iconv libiconv libiconv-2 c) +find_path(ICONV_INCLUDE_DIR iconv.h) +check_function_exists(iconv_open libc_has_iconv) +find_library(iconv_lib NAMES iconv libiconv libiconv-2 c) -IF(ICONV_INCLUDE_DIR AND libc_has_iconv) - SET(ICONV_FOUND TRUE) - SET(ICONV_LIBRARIES "") - IF(NOT ICONV_FIND_QUIETLY) - MESSAGE(STATUS "Found Iconv: provided by libc") - ENDIF(NOT ICONV_FIND_QUIETLY) -ELSEIF(ICONV_INCLUDE_DIR AND iconv_lib) - SET(ICONV_FOUND TRUE) +if(ICONV_INCLUDE_DIR AND libc_has_iconv) + set(ICONV_FOUND TRUE) + set(ICONV_LIBRARIES "") + if(NOT ICONV_FIND_QUIETLY) + message(STATUS "Found Iconv: provided by libc") + endif(NOT ICONV_FIND_QUIETLY) +elseif(ICONV_INCLUDE_DIR AND iconv_lib) + set(ICONV_FOUND TRUE) # split iconv into -L and -l linker options, so we can # set them for pkg-config - GET_FILENAME_COMPONENT(iconv_path ${iconv_lib} PATH) - GET_FILENAME_COMPONENT(iconv_name ${iconv_lib} NAME_WE) - STRING(REGEX REPLACE "^lib" "" iconv_name ${iconv_name}) - SET(ICONV_LIBRARIES "-L${iconv_path} -l${iconv_name}") + get_filename_component(iconv_path ${iconv_lib} PATH) + get_filename_component(iconv_name ${iconv_lib} NAME_WE) + string(REGEX REPLACE "^lib" "" iconv_name ${iconv_name}) + set(ICONV_LIBRARIES "-L${iconv_path} -l${iconv_name}") - IF(NOT ICONV_FIND_QUIETLY) - MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}") - ENDIF(NOT ICONV_FIND_QUIETLY) -ELSE() - IF(Iconv_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find Iconv") - ENDIF(Iconv_FIND_REQUIRED) -ENDIF() + if(NOT ICONV_FIND_QUIETLY) + message(STATUS "Found Iconv: ${ICONV_LIBRARIES}") + endif() +else() + if(Iconv_FIND_REQUIRED) + message(FATAL_ERROR "Could not find Iconv") + endif(Iconv_FIND_REQUIRED) +endif() -MARK_AS_ADVANCED( +mark_as_advanced( ICONV_INCLUDE_DIR ICONV_LIBRARIES ) diff --git a/cmake/FindLibSSH2.cmake b/cmake/FindLibSSH2.cmake index ff5893525..c571997c4 100644 --- a/cmake/FindLibSSH2.cmake +++ b/cmake/FindLibSSH2.cmake @@ -2,12 +2,12 @@ # LIBSSH2_INCLUDE_DIR - the libssh2 include directory # LIBSSH2_LIBRARY - the libssh2 library name -FIND_PATH(LIBSSH2_INCLUDE_DIR libssh2.h) +find_path(LIBSSH2_INCLUDE_DIR libssh2.h) -FIND_LIBRARY(LIBSSH2_LIBRARY NAMES ssh2 libssh2) +find_library(LIBSSH2_LIBRARY NAMES ssh2 libssh2) -INCLUDE(FindPackageHandleStandardArgs) +include(FindPackageHandleStandardArgs) find_package_handle_standard_args(LibSSH2 - REQUIRED_VARS LIBSSH2_LIBRARY LIBSSH2_INCLUDE_DIR) + REQUIRED_VARS LIBSSH2_LIBRARY LIBSSH2_INCLUDE_DIR) -MARK_AS_ADVANCED(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY) +mark_as_advanced(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY) diff --git a/cmake/FindPCRE.cmake b/cmake/FindPCRE.cmake index 74ed61e53..3a7cfad91 100644 --- a/cmake/FindPCRE.cmake +++ b/cmake/FindPCRE.cmake @@ -16,23 +16,23 @@ # PCRE_FOUND - True if pcre found. # Look for the header file. -FIND_PATH(PCRE_INCLUDE_DIR NAMES pcreposix.h) +find_path(PCRE_INCLUDE_DIR NAMES pcreposix.h) # Look for the library. -FIND_LIBRARY(PCRE_LIBRARY NAMES pcre) -FIND_LIBRARY(PCRE_POSIX_LIBRARY NAMES pcreposix) +find_library(PCRE_LIBRARY NAMES pcre) +find_library(PCRE_POSIX_LIBRARY NAMES pcreposix) # Handle the QUIETLY and REQUIRED arguments and set PCRE_FOUND to TRUE if all listed variables are TRUE. -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_POSIX_LIBRARY PCRE_INCLUDE_DIR) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_POSIX_LIBRARY PCRE_INCLUDE_DIR) # Copy the results to the output variables. -IF(PCRE_FOUND) - SET(PCRE_LIBRARIES ${PCRE_LIBRARY} ${PCRE_POSIX_LIBRARY}) - SET(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR}) -ELSE(PCRE_FOUND) - SET(PCRE_LIBRARIES) - SET(PCRE_INCLUDE_DIRS) -ENDIF(PCRE_FOUND) +if(PCRE_FOUND) + set(PCRE_LIBRARIES ${PCRE_LIBRARY} ${PCRE_POSIX_LIBRARY}) + set(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR}) +else(PCRE_FOUND) + set(PCRE_LIBRARIES) + set(PCRE_INCLUDE_DIRS) +endif() -MARK_AS_ADVANCED(PCRE_INCLUDE_DIRS PCRE_LIBRARIES) +mark_as_advanced(PCRE_INCLUDE_DIRS PCRE_LIBRARIES) diff --git a/cmake/FindPCRE2.cmake b/cmake/FindPCRE2.cmake index f8c5639d5..d4b8e6761 100644 --- a/cmake/FindPCRE2.cmake +++ b/cmake/FindPCRE2.cmake @@ -16,22 +16,22 @@ # PCRE2_FOUND - True if pcre found. # Look for the header file. -FIND_PATH(PCRE2_INCLUDE_DIR NAMES pcre2posix.h) +find_path(PCRE2_INCLUDE_DIR NAMES pcre2posix.h) # Look for the library. -FIND_LIBRARY(PCRE2_LIBRARY NAMES pcre2-8) +find_library(PCRE2_LIBRARY NAMES pcre2-8) # Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE. -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_INCLUDE_DIR) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_INCLUDE_DIR) # Copy the results to the output variables. -IF(PCRE2_FOUND) - SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY}) - SET(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR}) -ELSE(PCRE2_FOUND) - SET(PCRE2_LIBRARIES) - SET(PCRE2_INCLUDE_DIRS) -ENDIF(PCRE2_FOUND) +if(PCRE2_FOUND) + set(PCRE2_LIBRARIES ${PCRE2_LIBRARY}) + set(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR}) +else(PCRE2_FOUND) + set(PCRE2_LIBRARIES) + set(PCRE2_INCLUDE_DIRS) +endif() -MARK_AS_ADVANCED(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES) +mark_as_advanced(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES) diff --git a/cmake/FindPkgLibraries.cmake b/cmake/FindPkgLibraries.cmake index 49311c382..220bb2ce2 100644 --- a/cmake/FindPkgLibraries.cmake +++ b/cmake/FindPkgLibraries.cmake @@ -1,28 +1,28 @@ -INCLUDE(FindPkgConfig) +include(FindPkgConfig) # This function will find and set up a pkg-config based module. # If a pc-file was found, it will resolve library paths to # absolute paths. Furthermore, the function will automatically # fall back to use static libraries in case no dynamic libraries # were found. -FUNCTION(FIND_PKGLIBRARIES prefix package) - PKG_CHECK_MODULES(${prefix} ${package}) - IF(NOT ${prefix}_FOUND) - RETURN() - ENDIF() +function(FIND_PKGLIBRARIES prefix package) + pkg_check_modules(${prefix} ${package}) + if(NOT ${prefix}_FOUND) + return() + endif() - FOREACH(LIBRARY ${${prefix}_LIBRARIES}) - FIND_LIBRARY(${LIBRARY}_RESOLVED ${LIBRARY} PATHS ${${prefix}_LIBRARY_DIRS}) - IF(${${LIBRARY}_RESOLVED} STREQUAL "${LIBRARY}_RESOLVED-NOTFOUND") - MESSAGE(FATAL_ERROR "could not resolve ${LIBRARY}") - ENDIF() - LIST(APPEND RESOLVED_LIBRARIES ${${LIBRARY}_RESOLVED}) - ENDFOREACH(LIBRARY) + foreach(LIBRARY ${${prefix}_LIBRARIES}) + find_library(${LIBRARY}_RESOLVED ${LIBRARY} PATHS ${${prefix}_LIBRARY_DIRS}) + if(${${LIBRARY}_RESOLVED} STREQUAL "${LIBRARY}_RESOLVED-NOTFOUND") + message(FATAL_ERROR "could not resolve ${LIBRARY}") + endif() + list(APPEND RESOLVED_LIBRARIES ${${LIBRARY}_RESOLVED}) + endforeach() - SET(${prefix}_FOUND 1 PARENT_SCOPE) - SET(${prefix}_LIBRARIES ${RESOLVED_LIBRARIES} PARENT_SCOPE) - SET(${prefix}_INCLUDE_DIRS ${${prefix}_INCLUDE_DIRS} PARENT_SCOPE) - SET(${prefix}_LDFLAGS ${${prefix}_LDFLAGS} PARENT_SCOPE) + set(${prefix}_FOUND 1 PARENT_SCOPE) + set(${prefix}_LIBRARIES ${RESOLVED_LIBRARIES} PARENT_SCOPE) + set(${prefix}_INCLUDE_DIRS ${${prefix}_INCLUDE_DIRS} PARENT_SCOPE) + set(${prefix}_LDFLAGS ${${prefix}_LDFLAGS} PARENT_SCOPE) - MESSAGE(STATUS " Resolved libraries: ${RESOLVED_LIBRARIES}") -ENDFUNCTION() + message(STATUS " Resolved libraries: ${RESOLVED_LIBRARIES}") +endfunction() diff --git a/cmake/FindSecurity.cmake b/cmake/FindSecurity.cmake index a538c02c1..14a2e2dd7 100644 --- a/cmake/FindSecurity.cmake +++ b/cmake/FindSecurity.cmake @@ -7,22 +7,22 @@ # SECURITY_HAS_SSLCREATECONTEXT # -FIND_PATH(SECURITY_INCLUDE_DIR NAMES Security/Security.h) -FIND_LIBRARY(SECURITY_LIBRARIES NAMES Security) -IF (SECURITY_INCLUDE_DIR AND SECURITY_LIBRARIES) - IF (NOT Security_FIND_QUIETLY) - MESSAGE(STATUS "Found Security ${SECURITY_LIBRARIES}") - ENDIF() - SET(SECURITY_FOUND TRUE) - SET(SECURITY_LDFLAGS "-framework Security") - CHECK_LIBRARY_EXISTS("${SECURITY_LIBRARIES}" SSLCreateContext "Security/SecureTransport.h" SECURITY_HAS_SSLCREATECONTEXT) -ENDIF () +find_path(SECURITY_INCLUDE_DIR NAMES Security/Security.h) +find_library(SECURITY_LIBRARIES NAMES Security) +if(SECURITY_INCLUDE_DIR AND SECURITY_LIBRARIES) + if(NOT Security_FIND_QUIETLY) + message(STATUS "Found Security ${SECURITY_LIBRARIES}") + endif() + set(SECURITY_FOUND TRUE) + set(SECURITY_LDFLAGS "-framework Security") + check_library_exists("${SECURITY_LIBRARIES}" SSLCreateContext "Security/SecureTransport.h" SECURITY_HAS_SSLCREATECONTEXT) +endif() -IF (Security_FIND_REQUIRED AND NOT SECURITY_FOUND) - MESSAGE(FATAL_ERROR "Security not found") -ENDIF() +if(Security_FIND_REQUIRED AND NOT SECURITY_FOUND) + message(FATAL_ERROR "Security not found") +endif() -MARK_AS_ADVANCED( +mark_as_advanced( SECURITY_INCLUDE_DIR SECURITY_LIBRARIES ) diff --git a/cmake/Findfutimens.cmake b/cmake/Findfutimens.cmake index 73b79528a..3449c9d54 100644 --- a/cmake/Findfutimens.cmake +++ b/cmake/Findfutimens.cmake @@ -1,14 +1,14 @@ -INCLUDE(EnableWarnings) +include(EnableWarnings) -IF (APPLE) +if(APPLE) # We cannot simply CHECK_FUNCTION_EXISTS on macOS because # MACOSX_DEPLOYMENT_TARGET may be set to a version in the past # that doesn't have futimens. Instead we need to enable warnings # as errors, then check for the symbol existing in `sys/stat.h`, # then reset warnings as errors. - ENABLE_WARNINGS(error) - CHECK_SYMBOL_EXISTS(futimens sys/stat.h HAVE_FUTIMENS) - DISABLE_WARNINGS(error) -ELSE () - CHECK_FUNCTION_EXISTS(futimens HAVE_FUTIMENS) -ENDIF () + enable_warnings(error) + check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS) + disable_warnings(error) +else() + check_function_exists(futimens HAVE_FUTIMENS) +endif() diff --git a/cmake/FindmbedTLS.cmake b/cmake/FindmbedTLS.cmake index 93297555e..a4a5487c2 100644 --- a/cmake/FindmbedTLS.cmake +++ b/cmake/FindmbedTLS.cmake @@ -13,81 +13,74 @@ # Hint # MBEDTLS_ROOT_DIR can be pointed to a local mbedTLS installation. -SET(_MBEDTLS_ROOT_HINTS - ${MBEDTLS_ROOT_DIR} - ENV MBEDTLS_ROOT_DIR -) +set(_MBEDTLS_ROOT_HINTS + ${MBEDTLS_ROOT_DIR} + ENV MBEDTLS_ROOT_DIR) -SET(_MBEDTLS_ROOT_HINTS_AND_PATHS - HINTS ${_MBEDTLS_ROOT_HINTS} - PATHS ${_MBEDTLS_ROOT_PATHS} -) +set(_MBEDTLS_ROOT_HINTS_AND_PATHS + HINTS ${_MBEDTLS_ROOT_HINTS} + PATHS ${_MBEDTLS_ROOT_PATHS}) -FIND_PATH(MBEDTLS_INCLUDE_DIR - NAMES mbedtls/version.h - ${_MBEDTLS_ROOT_HINTS_AND_PATHS} - PATH_SUFFIXES include -) +find_path(MBEDTLS_INCLUDE_DIR + NAMES mbedtls/version.h + ${_MBEDTLS_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES include) -IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES) - # Already in cache, be silent - SET(MBEDTLS_FIND_QUIETLY TRUE) -ENDIF() +if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES) + # Already in cache, be silent + set(MBEDTLS_FIND_QUIETLY TRUE) +endif() -FIND_LIBRARY(MBEDTLS_LIBRARY - NAMES mbedtls libmbedtls - ${_MBEDTLS_ROOT_HINTS_AND_PATHS} - PATH_SUFFIXES library -) -FIND_LIBRARY(MBEDX509_LIBRARY - NAMES mbedx509 libmbedx509 - ${_MBEDTLS_ROOT_HINTS_AND_PATHS} - PATH_SUFFIXES library -) -FIND_LIBRARY(MBEDCRYPTO_LIBRARY - NAMES mbedcrypto libmbedcrypto - ${_MBEDTLS_ROOT_HINTS_AND_PATHS} - PATH_SUFFIXES library -) +find_library(MBEDTLS_LIBRARY + NAMES mbedtls libmbedtls + ${_MBEDTLS_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES library) +find_library(MBEDX509_LIBRARY + NAMES mbedx509 libmbedx509 + ${_MBEDTLS_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES library) +find_library(MBEDCRYPTO_LIBRARY + NAMES mbedcrypto libmbedcrypto + ${_MBEDTLS_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES library) -IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY) - SET(MBEDTLS_FOUND TRUE) -ENDIF() +if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY) + set(MBEDTLS_FOUND TRUE) +endif() -IF(MBEDTLS_FOUND) - # split mbedTLS into -L and -l linker options, so we can set them for pkg-config - GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH) - GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE) - GET_FILENAME_COMPONENT(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE) - GET_FILENAME_COMPONENT(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE) - STRING(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE}) - STRING(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE}) - STRING(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE}) - SET(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}") +if(MBEDTLS_FOUND) + # split mbedTLS into -L and -l linker options, so we can set them for pkg-config + get_filename_component(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH) + get_filename_component(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE) + get_filename_component(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE) + get_filename_component(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE) + string(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE}) + string(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE}) + string(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE}) + set(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}") - IF(NOT MBEDTLS_FIND_QUIETLY) - MESSAGE(STATUS "Found mbedTLS:") - FILE(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT) - STRING(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT}) - IF (MBEDTLSMATCH) - STRING(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH}) - MESSAGE(STATUS " version ${MBEDTLS_VERSION}") - ENDIF(MBEDTLSMATCH) - MESSAGE(STATUS " TLS: ${MBEDTLS_LIBRARY}") - MESSAGE(STATUS " X509: ${MBEDX509_LIBRARY}") - MESSAGE(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}") - ENDIF(NOT MBEDTLS_FIND_QUIETLY) -ELSE(MBEDTLS_FOUND) - IF(MBEDTLS_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find mbedTLS") - ENDIF(MBEDTLS_FIND_REQUIRED) -ENDIF(MBEDTLS_FOUND) + if(NOT MBEDTLS_FIND_QUIETLY) + message(STATUS "Found mbedTLS:") + file(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT) + string(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT}) + if(MBEDTLSMATCH) + string(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH}) + message(STATUS " version ${MBEDTLS_VERSION}") + endif() + message(STATUS " TLS: ${MBEDTLS_LIBRARY}") + message(STATUS " X509: ${MBEDX509_LIBRARY}") + message(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}") + endif() +else(MBEDTLS_FOUND) + if(MBEDTLS_FIND_REQUIRED) + message(FATAL_ERROR "Could not find mbedTLS") + endif() +endif() -MARK_AS_ADVANCED( - MBEDTLS_INCLUDE_DIR - MBEDTLS_LIBRARY_DIR - MBEDTLS_LIBRARIES - MBEDTLS_LIBRARY - MBEDX509_LIBRARY - MBEDCRYPTO_LIBRARY -) +mark_as_advanced( + MBEDTLS_INCLUDE_DIR + MBEDTLS_LIBRARY_DIR + MBEDTLS_LIBRARIES + MBEDTLS_LIBRARY + MBEDX509_LIBRARY + MBEDCRYPTO_LIBRARY) diff --git a/cmake/IdeSplitSources.cmake b/cmake/IdeSplitSources.cmake index 396f18eb4..4a55d89b0 100644 --- a/cmake/IdeSplitSources.cmake +++ b/cmake/IdeSplitSources.cmake @@ -3,20 +3,20 @@ # Visual Studio, so that you can navigate into the libgit2_tests project, # and see the folders within the tests folder (instead of just seeing all # source and tests in a single folder.) -FUNCTION(IDE_SPLIT_SOURCES target) - IF(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode) - GET_TARGET_PROPERTY(sources ${target} SOURCES) - FOREACH(source ${sources}) - IF(source MATCHES ".*/") - STRING(REPLACE ${libgit2_SOURCE_DIR}/ "" rel ${source}) - IF(rel) - STRING(REGEX REPLACE "/([^/]*)$" "" rel ${rel}) - IF(rel) - STRING(REPLACE "/" "\\\\" rel ${rel}) - SOURCE_GROUP(${rel} FILES ${source}) - ENDIF() - ENDIF() - ENDIF() - ENDFOREACH() - ENDIF() -ENDFUNCTION() +function(IDE_SPLIT_SOURCES target) + if(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode) + get_target_property(sources ${target} SOURCES) + foreach(source ${sources}) + if(source MATCHES ".*/") + string(REPLACE ${libgit2_SOURCE_DIR}/ "" rel ${source}) + if(rel) + string(REGEX REPLACE "/([^/]*)$" "" rel ${rel}) + if(rel) + string(REPLACE "/" "\\\\" rel ${rel}) + source_group(${rel} FILES ${source}) + endif() + endif() + endif() + endforeach() + endif() +endfunction() diff --git a/cmake/PkgBuildConfig.cmake b/cmake/PkgBuildConfig.cmake index 54c5e294c..c8939e63a 100644 --- a/cmake/PkgBuildConfig.cmake +++ b/cmake/PkgBuildConfig.cmake @@ -2,76 +2,76 @@ # function(pkg_build_config) - set(options) - set(oneValueArgs NAME DESCRIPTION VERSION FILENAME LIBS_SELF) - set(multiValueArgs LIBS PRIVATE_LIBS REQUIRES CFLAGS) + set(options) + set(oneValueArgs NAME DESCRIPTION VERSION FILENAME LIBS_SELF) + set(multiValueArgs LIBS PRIVATE_LIBS REQUIRES CFLAGS) - cmake_parse_arguments(PKGCONFIG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + cmake_parse_arguments(PKGCONFIG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - if (NOT DEFINED PKGCONFIG_FILENAME AND DEFINED PKGCONFIG_NAME) - set(PKGCONFIG_FILENAME ${PKGCONFIG_NAME}) - endif() - if (NOT DEFINED PKGCONFIG_FILENAME) - message(FATAL_ERROR "Missing FILENAME argument") - endif() - set(PKGCONFIG_FILE "${PROJECT_BINARY_DIR}/${PKGCONFIG_FILENAME}.pc") + if (NOT DEFINED PKGCONFIG_FILENAME AND DEFINED PKGCONFIG_NAME) + set(PKGCONFIG_FILENAME ${PKGCONFIG_NAME}) + endif() + if (NOT DEFINED PKGCONFIG_FILENAME) + message(FATAL_ERROR "Missing FILENAME argument") + endif() + set(PKGCONFIG_FILE "${PROJECT_BINARY_DIR}/${PKGCONFIG_FILENAME}.pc") - if (NOT DEFINED PKGCONFIG_DESCRIPTION) - message(FATAL_ERROR "Missing DESCRIPTION argument") - endif() + if (NOT DEFINED PKGCONFIG_DESCRIPTION) + message(FATAL_ERROR "Missing DESCRIPTION argument") + endif() - if (NOT DEFINED PKGCONFIG_VERSION) - message(FATAL_ERROR "Missing VERSION argument") - endif() + if (NOT DEFINED PKGCONFIG_VERSION) + message(FATAL_ERROR "Missing VERSION argument") + endif() - # Write .pc "header" - file(WRITE "${PKGCONFIG_FILE}" - "prefix=\"${CMAKE_INSTALL_PREFIX}\"\n" - "libdir=\"${CMAKE_INSTALL_FULL_LIBDIR}\"\n" - "includedir=\"${CMAKE_INSTALL_FULL_INCLUDEDIR}\"\n" - "\n" - "Name: ${PKGCONFIG_NAME}\n" - "Description: ${PKGCONFIG_DESCRIPTION}\n" - "Version: ${PKGCONFIG_VERSION}\n" - ) + # Write .pc "header" + file(WRITE "${PKGCONFIG_FILE}" + "prefix=\"${CMAKE_INSTALL_PREFIX}\"\n" + "libdir=\"${CMAKE_INSTALL_FULL_LIBDIR}\"\n" + "includedir=\"${CMAKE_INSTALL_FULL_INCLUDEDIR}\"\n" + "\n" + "Name: ${PKGCONFIG_NAME}\n" + "Description: ${PKGCONFIG_DESCRIPTION}\n" + "Version: ${PKGCONFIG_VERSION}\n" + ) - # Prepare Libs - if(NOT DEFINED PKGCONFIG_LIBS_SELF) - set(PKGCONFIG_LIBS_SELF "${PKGCONFIG_FILE}") - endif() + # Prepare Libs + if(NOT DEFINED PKGCONFIG_LIBS_SELF) + set(PKGCONFIG_LIBS_SELF "${PKGCONFIG_FILE}") + endif() - if(NOT DEFINED PKGCONFIG_LIBS) - set(PKGCONFIG_LIBS "-l${PKGCONFIG_LIBS_SELF}") - else() - list(INSERT PKGCONFIG_LIBS 0 "-l${PKGCONFIG_LIBS_SELF}") - endif() + if(NOT DEFINED PKGCONFIG_LIBS) + set(PKGCONFIG_LIBS "-l${PKGCONFIG_LIBS_SELF}") + else() + list(INSERT PKGCONFIG_LIBS 0 "-l${PKGCONFIG_LIBS_SELF}") + endif() - list(REMOVE_DUPLICATES PKGCONFIG_LIBS) - string(REPLACE ";" " " PKGCONFIG_LIBS "${PKGCONFIG_LIBS}") - file(APPEND "${PKGCONFIG_FILE}" "Libs: -L\${libdir} ${PKGCONFIG_LIBS}\n") + list(REMOVE_DUPLICATES PKGCONFIG_LIBS) + string(REPLACE ";" " " PKGCONFIG_LIBS "${PKGCONFIG_LIBS}") + file(APPEND "${PKGCONFIG_FILE}" "Libs: -L\${libdir} ${PKGCONFIG_LIBS}\n") - # Prepare Libs.private - if(DEFINED PKGCONFIG_PRIVATE_LIBS) - list(REMOVE_DUPLICATES PKGCONFIG_PRIVATE_LIBS) - string(REPLACE ";" " " PKGCONFIG_PRIVATE_LIBS "${PKGCONFIG_PRIVATE_LIBS}") - file(APPEND "${PKGCONFIG_FILE}" "Libs.private: ${PKGCONFIG_PRIVATE_LIBS}\n") - endif() + # Prepare Libs.private + if(DEFINED PKGCONFIG_PRIVATE_LIBS) + list(REMOVE_DUPLICATES PKGCONFIG_PRIVATE_LIBS) + string(REPLACE ";" " " PKGCONFIG_PRIVATE_LIBS "${PKGCONFIG_PRIVATE_LIBS}") + file(APPEND "${PKGCONFIG_FILE}" "Libs.private: ${PKGCONFIG_PRIVATE_LIBS}\n") + endif() - # Prepare Requires.private - if(DEFINED PKGCONFIG_REQUIRES) - list(REMOVE_DUPLICATES PKGCONFIG_REQUIRES) - string(REPLACE ";" " " PKGCONFIG_REQUIRES "${PKGCONFIG_REQUIRES}") - file(APPEND "${PKGCONFIG_FILE}" "Requires.private: ${PKGCONFIG_REQUIRES}\n") - endif() + # Prepare Requires.private + if(DEFINED PKGCONFIG_REQUIRES) + list(REMOVE_DUPLICATES PKGCONFIG_REQUIRES) + string(REPLACE ";" " " PKGCONFIG_REQUIRES "${PKGCONFIG_REQUIRES}") + file(APPEND "${PKGCONFIG_FILE}" "Requires.private: ${PKGCONFIG_REQUIRES}\n") + endif() - # Prepare Cflags - if(DEFINED PKGCONFIG_CFLAGS) - string(REPLACE ";" " " PKGCONFIG_CFLAGS "${PKGCONFIG_CFLAGS}") - else() - set(PKGCONFIG_CFLAGS "") - endif() - file(APPEND "${PKGCONFIG_FILE}" "Cflags: -I\${includedir} ${PKGCONFIG_CFLAGS}\n") + # Prepare Cflags + if(DEFINED PKGCONFIG_CFLAGS) + string(REPLACE ";" " " PKGCONFIG_CFLAGS "${PKGCONFIG_CFLAGS}") + else() + set(PKGCONFIG_CFLAGS "") + endif() + file(APPEND "${PKGCONFIG_FILE}" "Cflags: -I\${includedir} ${PKGCONFIG_CFLAGS}\n") - # Install .pc file - install(FILES "${PKGCONFIG_FILE}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + # Install .pc file + install(FILES "${PKGCONFIG_FILE}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") endfunction() diff --git a/cmake/SanitizeBool.cmake b/cmake/SanitizeBool.cmake index b5b99a690..586c17d05 100644 --- a/cmake/SanitizeBool.cmake +++ b/cmake/SanitizeBool.cmake @@ -1,20 +1,20 @@ -FUNCTION(SanitizeBool VAR) - STRING(TOLOWER "${${VAR}}" VALUE) - IF(VALUE STREQUAL "on") - SET(${VAR} "ON" PARENT_SCOPE) - ELSEIF(VALUE STREQUAL "yes") - SET(${VAR} "ON" PARENT_SCOPE) - ELSEIF(VALUE STREQUAL "true") - SET(${VAR} "ON" PARENT_SCOPE) - ELSEIF(VALUE STREQUAL "1") - SET(${VAR} "ON" PARENT_SCOPE) - ELSEIF(VALUE STREQUAL "off") - SET(${VAR} "OFF" PARENT_SCOPE) - ELSEIF(VALUE STREQUAL "no") - SET(${VAR} "OFF" PARENT_SCOPE) - ELSEIF(VALUE STREQUAL "false") - SET(${VAR} "OFF" PARENT_SCOPE) - ELSEIF(VALUE STREQUAL "0") - SET(${VAR} "OFF" PARENT_SCOPE) - ENDIF() -ENDFUNCTION() +function(SanitizeBool VAR) + string(TOLOWER "${${VAR}}" VALUE) + if(VALUE STREQUAL "on") + set(${VAR} "ON" PARENT_SCOPE) + elseif(VALUE STREQUAL "yes") + set(${VAR} "ON" PARENT_SCOPE) + elseif(VALUE STREQUAL "true") + set(${VAR} "ON" PARENT_SCOPE) + elseif(VALUE STREQUAL "1") + set(${VAR} "ON" PARENT_SCOPE) + elseif(VALUE STREQUAL "off") + set(${VAR} "OFF" PARENT_SCOPE) + elseif(VALUE STREQUAL "no") + set(${VAR} "OFF" PARENT_SCOPE) + elseif(VALUE STREQUAL "false") + set(${VAR} "OFF" PARENT_SCOPE) + elseif(VALUE STREQUAL "0") + set(${VAR} "OFF" PARENT_SCOPE) + endif() +endfunction() diff --git a/cmake/SelectGSSAPI.cmake b/cmake/SelectGSSAPI.cmake index 0a42eeefd..e9c5c75c1 100644 --- a/cmake/SelectGSSAPI.cmake +++ b/cmake/SelectGSSAPI.cmake @@ -1,48 +1,48 @@ -INCLUDE(SanitizeBool) +include(SanitizeBool) # We try to find any packages our backends might use -FIND_PACKAGE(GSSAPI) -IF (CMAKE_SYSTEM_NAME MATCHES "Darwin") - INCLUDE(FindGSSFramework) -ENDIF() +find_package(GSSAPI) +if(CMAKE_SYSTEM_NAME MATCHES "Darwin") + include(FindGSSFramework) +endif() -IF(USE_GSSAPI) +if(USE_GSSAPI) # Auto-select GSS backend - SanitizeBool(USE_GSSAPI) - IF (USE_GSSAPI STREQUAL ON) - IF (GSSFRAMEWORK_FOUND) - SET(USE_GSSAPI "GSS.framework") - ELSEIF(GSSAPI_FOUND) - SET(USE_GSSAPI "gssapi") - ELSE() - MESSAGE(FATAL_ERROR "Unable to autodetect a usable GSS backend." + sanitizebool(USE_GSSAPI) + if(USE_GSSAPI STREQUAL ON) + if(GSSFRAMEWORK_FOUND) + set(USE_GSSAPI "GSS.framework") + elseif(GSSAPI_FOUND) + set(USE_GSSAPI "gssapi") + else() + message(FATAL_ERROR "Unable to autodetect a usable GSS backend." "Please pass the backend name explicitly (-DUSE_GSS=backend)") - ENDIF() - ENDIF() + endif() + endif() # Check that we can find what's required for the selected backend - IF (USE_GSSAPI STREQUAL "GSS.framework") - IF (NOT GSSFRAMEWORK_FOUND) - MESSAGE(FATAL_ERROR "Asked for GSS.framework backend, but it wasn't found") - ENDIF() + if(USE_GSSAPI STREQUAL "GSS.framework") + if(NOT GSSFRAMEWORK_FOUND) + message(FATAL_ERROR "Asked for GSS.framework backend, but it wasn't found") + endif() - LIST(APPEND LIBGIT2_LIBS ${GSSFRAMEWORK_LIBRARIES}) + list(APPEND LIBGIT2_LIBS ${GSSFRAMEWORK_LIBRARIES}) - SET(GIT_GSSFRAMEWORK 1) - ADD_FEATURE_INFO(SPNEGO GIT_GSSFRAMEWORK "SPNEGO authentication support (${USE_GSSAPI})") - ELSEIF (USE_GSSAPI STREQUAL "gssapi") - IF (NOT GSSAPI_FOUND) - MESSAGE(FATAL_ERROR "Asked for gssapi GSS backend, but it wasn't found") - ENDIF() + set(GIT_GSSFRAMEWORK 1) + add_feature_info(SPNEGO GIT_GSSFRAMEWORK "SPNEGO authentication support (${USE_GSSAPI})") + elseif(USE_GSSAPI STREQUAL "gssapi") + if(NOT GSSAPI_FOUND) + message(FATAL_ERROR "Asked for gssapi GSS backend, but it wasn't found") + endif() - LIST(APPEND LIBGIT2_LIBS ${GSSAPI_LIBRARIES}) + list(APPEND LIBGIT2_LIBS ${GSSAPI_LIBRARIES}) - SET(GIT_GSSAPI 1) - ADD_FEATURE_INFO(SPNEGO GIT_GSSAPI "SPNEGO authentication support (${USE_GSSAPI})") - ELSE() - MESSAGE(FATAL_ERROR "Asked for backend ${USE_GSSAPI} but it wasn't found") - ENDIF() -ELSE() - SET(GIT_GSSAPI 0) - ADD_FEATURE_INFO(SPNEGO NO "SPNEGO authentication support") -ENDIF() + set(GIT_GSSAPI 1) + add_feature_info(SPNEGO GIT_GSSAPI "SPNEGO authentication support (${USE_GSSAPI})") + else() + message(FATAL_ERROR "Asked for backend ${USE_GSSAPI} but it wasn't found") + endif() +else() + set(GIT_GSSAPI 0) + add_feature_info(SPNEGO NO "SPNEGO authentication support") +endif() diff --git a/cmake/SelectHTTPSBackend.cmake b/cmake/SelectHTTPSBackend.cmake index 4af747417..1c6bd6a59 100644 --- a/cmake/SelectHTTPSBackend.cmake +++ b/cmake/SelectHTTPSBackend.cmake @@ -1,124 +1,124 @@ -INCLUDE(SanitizeBool) +include(SanitizeBool) # We try to find any packages our backends might use -FIND_PACKAGE(OpenSSL) -FIND_PACKAGE(mbedTLS) -IF (CMAKE_SYSTEM_NAME MATCHES "Darwin") - FIND_PACKAGE(Security) - FIND_PACKAGE(CoreFoundation) -ENDIF() +find_package(OpenSSL) +find_package(mbedTLS) +if(CMAKE_SYSTEM_NAME MATCHES "Darwin") + find_package(Security) + find_package(CoreFoundation) +endif() -IF(USE_HTTPS) +if(USE_HTTPS) # Auto-select TLS backend - SanitizeBool(USE_HTTPS) - IF (USE_HTTPS STREQUAL ON) - IF (SECURITY_FOUND) - IF (SECURITY_HAS_SSLCREATECONTEXT) - SET(USE_HTTPS "SecureTransport") - ELSE() - MESSAGE(STATUS "Security framework is too old, falling back to OpenSSL") - SET(USE_HTTPS "OpenSSL") - ENDIF() - ELSEIF (USE_WINHTTP) - SET(USE_HTTPS "WinHTTP") - ELSEIF(OPENSSL_FOUND) - SET(USE_HTTPS "OpenSSL") - ELSEIF(MBEDTLS_FOUND) - SET(USE_HTTPS "mbedTLS") - ELSE() - MESSAGE(FATAL_ERROR "Unable to autodetect a usable HTTPS backend." + sanitizebool(USE_HTTPS) + if(USE_HTTPS STREQUAL ON) + if(SECURITY_FOUND) + if(SECURITY_HAS_SSLCREATECONTEXT) + set(USE_HTTPS "SecureTransport") + else() + message(STATUS "Security framework is too old, falling back to OpenSSL") + set(USE_HTTPS "OpenSSL") + endif() + elseif(USE_WINHTTP) + set(USE_HTTPS "WinHTTP") + elseif(OPENSSL_FOUND) + set(USE_HTTPS "OpenSSL") + elseif(MBEDTLS_FOUND) + set(USE_HTTPS "mbedTLS") + else() + message(FATAL_ERROR "Unable to autodetect a usable HTTPS backend." "Please pass the backend name explicitly (-DUSE_HTTPS=backend)") - ENDIF() - ENDIF() + endif() + endif() # Check that we can find what's required for the selected backend - IF (USE_HTTPS STREQUAL "SecureTransport") - IF (NOT COREFOUNDATION_FOUND) - MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, CoreFoundation.framework not found") - ENDIF() - IF (NOT SECURITY_FOUND) - MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, Security.framework not found") - ENDIF() - IF (NOT SECURITY_HAS_SSLCREATECONTEXT) - MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, SSLCreateContext not supported") - ENDIF() + if(USE_HTTPS STREQUAL "SecureTransport") + if(NOT COREFOUNDATION_FOUND) + message(FATAL_ERROR "Cannot use SecureTransport backend, CoreFoundation.framework not found") + endif() + if(NOT SECURITY_FOUND) + message(FATAL_ERROR "Cannot use SecureTransport backend, Security.framework not found") + endif() + if(NOT SECURITY_HAS_SSLCREATECONTEXT) + message(FATAL_ERROR "Cannot use SecureTransport backend, SSLCreateContext not supported") + endif() - SET(GIT_SECURE_TRANSPORT 1) - LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${SECURITY_INCLUDE_DIR}) - LIST(APPEND LIBGIT2_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) - LIST(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) - ELSEIF (USE_HTTPS STREQUAL "OpenSSL") - IF (NOT OPENSSL_FOUND) - MESSAGE(FATAL_ERROR "Asked for OpenSSL TLS backend, but it wasn't found") - ENDIF() + set(GIT_SECURE_TRANSPORT 1) + list(APPEND LIBGIT2_SYSTEM_INCLUDES ${SECURITY_INCLUDE_DIR}) + list(APPEND LIBGIT2_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) + list(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) + elseif(USE_HTTPS STREQUAL "OpenSSL") + if(NOT OPENSSL_FOUND) + message(FATAL_ERROR "Asked for OpenSSL TLS backend, but it wasn't found") + endif() - SET(GIT_OPENSSL 1) - LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${OPENSSL_INCLUDE_DIR}) - LIST(APPEND LIBGIT2_LIBS ${OPENSSL_LIBRARIES}) - LIST(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS}) - LIST(APPEND LIBGIT2_PC_REQUIRES "openssl") - ELSEIF(USE_HTTPS STREQUAL "mbedTLS") - IF (NOT MBEDTLS_FOUND) - MESSAGE(FATAL_ERROR "Asked for mbedTLS backend, but it wasn't found") - ENDIF() + set(GIT_OPENSSL 1) + list(APPEND LIBGIT2_SYSTEM_INCLUDES ${OPENSSL_INCLUDE_DIR}) + list(APPEND LIBGIT2_LIBS ${OPENSSL_LIBRARIES}) + list(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS}) + list(APPEND LIBGIT2_PC_REQUIRES "openssl") + elseif(USE_HTTPS STREQUAL "mbedTLS") + if(NOT MBEDTLS_FOUND) + message(FATAL_ERROR "Asked for mbedTLS backend, but it wasn't found") + endif() - IF(NOT CERT_LOCATION) - MESSAGE(STATUS "Auto-detecting default certificates location") - IF(CMAKE_SYSTEM_NAME MATCHES Darwin) + if(NOT CERT_LOCATION) + message(STATUS "Auto-detecting default certificates location") + if(CMAKE_SYSTEM_NAME MATCHES Darwin) # Check for an Homebrew installation - SET(OPENSSL_CMD "/usr/local/opt/openssl/bin/openssl") - ELSE() - SET(OPENSSL_CMD "openssl") - ENDIF() - EXECUTE_PROCESS(COMMAND ${OPENSSL_CMD} version -d OUTPUT_VARIABLE OPENSSL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) - IF(OPENSSL_DIR) - STRING(REGEX REPLACE "^OPENSSLDIR: \"(.*)\"$" "\\1/" OPENSSL_DIR ${OPENSSL_DIR}) + set(OPENSSL_CMD "/usr/local/opt/openssl/bin/openssl") + else() + set(OPENSSL_CMD "openssl") + endif() + execute_process(COMMAND ${OPENSSL_CMD} version -d OUTPUT_VARIABLE OPENSSL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) + if(OPENSSL_DIR) + string(REGEX REPLACE "^OPENSSLDIR: \"(.*)\"$" "\\1/" OPENSSL_DIR ${OPENSSL_DIR}) - SET(OPENSSL_CA_LOCATIONS + set(OPENSSL_CA_LOCATIONS "ca-bundle.pem" # OpenSUSE Leap 42.1 "cert.pem" # Ubuntu 14.04, FreeBSD "certs/ca-certificates.crt" # Ubuntu 16.04 "certs/ca.pem" # Debian 7 ) - FOREACH(SUFFIX IN LISTS OPENSSL_CA_LOCATIONS) - SET(LOC "${OPENSSL_DIR}${SUFFIX}") - IF(NOT CERT_LOCATION AND EXISTS "${OPENSSL_DIR}${SUFFIX}") - SET(CERT_LOCATION ${LOC}) - ENDIF() - ENDFOREACH() - ELSE() - MESSAGE(FATAL_ERROR "Unable to find OpenSSL executable. Please provide default certificate location via CERT_LOCATION") - ENDIF() - ENDIF() + foreach(SUFFIX IN LISTS OPENSSL_CA_LOCATIONS) + set(LOC "${OPENSSL_DIR}${SUFFIX}") + if(NOT CERT_LOCATION AND EXISTS "${OPENSSL_DIR}${SUFFIX}") + set(CERT_LOCATION ${LOC}) + endif() + endforeach() + else() + message(FATAL_ERROR "Unable to find OpenSSL executable. Please provide default certificate location via CERT_LOCATION") + endif() + endif() - IF(CERT_LOCATION) - IF(NOT EXISTS ${CERT_LOCATION}) - MESSAGE(FATAL_ERROR "Cannot use CERT_LOCATION=${CERT_LOCATION} as it doesn't exist") - ENDIF() - ADD_FEATURE_INFO(CERT_LOCATION ON "using certificates from ${CERT_LOCATION}") - ADD_DEFINITIONS(-DGIT_DEFAULT_CERT_LOCATION="${CERT_LOCATION}") - ENDIF() + if(CERT_LOCATION) + if(NOT EXISTS ${CERT_LOCATION}) + message(FATAL_ERROR "Cannot use CERT_LOCATION=${CERT_LOCATION} as it doesn't exist") + endif() + add_feature_info(CERT_LOCATION ON "using certificates from ${CERT_LOCATION}") + add_definitions(-DGIT_DEFAULT_CERT_LOCATION="${CERT_LOCATION}") + endif() - SET(GIT_MBEDTLS 1) - LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR}) - LIST(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES}) + set(GIT_MBEDTLS 1) + list(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR}) + list(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES}) # mbedTLS has no pkgconfig file, hence we can't require it # https://github.com/ARMmbed/mbedtls/issues/228 # For now, pass its link flags as our own - LIST(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES}) - ELSEIF (USE_HTTPS STREQUAL "WinHTTP") + list(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES}) + elseif(USE_HTTPS STREQUAL "WinHTTP") # WinHTTP setup was handled in the WinHTTP-specific block above - ELSEIF (USE_HTTPS STREQUAL "OpenSSL-Dynamic") - SET(GIT_OPENSSL 1) - SET(GIT_OPENSSL_DYNAMIC 1) - LIST(APPEND LIBGIT2_LIBS dl) - ELSE() - MESSAGE(FATAL_ERROR "Asked for backend ${USE_HTTPS} but it wasn't found") - ENDIF() + elseif(USE_HTTPS STREQUAL "OpenSSL-Dynamic") + set(GIT_OPENSSL 1) + set(GIT_OPENSSL_DYNAMIC 1) + list(APPEND LIBGIT2_LIBS dl) + else() + message(FATAL_ERROR "Asked for backend ${USE_HTTPS} but it wasn't found") + endif() - SET(GIT_HTTPS 1) - ADD_FEATURE_INFO(HTTPS GIT_HTTPS "using ${USE_HTTPS}") -ELSE() - SET(GIT_HTTPS 0) - ADD_FEATURE_INFO(HTTPS NO "") -ENDIF() + set(GIT_HTTPS 1) + add_feature_info(HTTPS GIT_HTTPS "using ${USE_HTTPS}") +else() + set(GIT_HTTPS 0) + add_feature_info(HTTPS NO "") +endif() diff --git a/cmake/SelectHashes.cmake b/cmake/SelectHashes.cmake index 092cdfd05..fee8b2902 100644 --- a/cmake/SelectHashes.cmake +++ b/cmake/SelectHashes.cmake @@ -1,62 +1,62 @@ # Select a hash backend -INCLUDE(SanitizeBool) +include(SanitizeBool) # USE_SHA1=CollisionDetection(ON)/HTTPS/Generic/OFF -SanitizeBool(USE_SHA1) -IF(USE_SHA1 STREQUAL ON) - SET(USE_SHA1 "CollisionDetection") -ELSEIF(USE_SHA1 STREQUAL "HTTPS") - IF(USE_HTTPS STREQUAL "SecureTransport") - SET(USE_SHA1 "CommonCrypto") - ELSEIF(USE_HTTPS STREQUAL "WinHTTP") - SET(USE_SHA1 "Win32") - ELSEIF(USE_HTTPS) - SET(USE_SHA1 ${USE_HTTPS}) - ELSE() - SET(USE_SHA1 "CollisionDetection") - ENDIF() -ENDIF() +sanitizebool(USE_SHA1) +if(USE_SHA1 STREQUAL ON) + set(USE_SHA1 "CollisionDetection") +elseif(USE_SHA1 STREQUAL "HTTPS") + if(USE_HTTPS STREQUAL "SecureTransport") + set(USE_SHA1 "CommonCrypto") + elseif(USE_HTTPS STREQUAL "WinHTTP") + set(USE_SHA1 "Win32") + elseif(USE_HTTPS) + set(USE_SHA1 ${USE_HTTPS}) + else() + set(USE_SHA1 "CollisionDetection") + endif() +endif() -IF(USE_SHA1 STREQUAL "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/sha1/collisiondetect.* hash/sha1/sha1dc/*) -ELSEIF(USE_SHA1 STREQUAL "OpenSSL") +if(USE_SHA1 STREQUAL "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/sha1/collisiondetect.* hash/sha1/sha1dc/*) +elseif(USE_SHA1 STREQUAL "OpenSSL") # OPENSSL_FOUND should already be set, we're checking USE_HTTPS - 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() - FILE(GLOB SRC_SHA1 hash/sha1/openssl.*) -ELSEIF(USE_SHA1 STREQUAL "CommonCrypto") - SET(GIT_SHA1_COMMON_CRYPTO 1) - FILE(GLOB SRC_SHA1 hash/sha1/common_crypto.*) -ELSEIF(USE_SHA1 STREQUAL "mbedTLS") - SET(GIT_SHA1_MBEDTLS 1) - FILE(GLOB SRC_SHA1 hash/sha1/mbedtls.*) - LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR}) - LIST(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES}) + 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() + file(GLOB SRC_SHA1 hash/sha1/openssl.*) +elseif(USE_SHA1 STREQUAL "CommonCrypto") + set(GIT_SHA1_COMMON_CRYPTO 1) + file(GLOB SRC_SHA1 hash/sha1/common_crypto.*) +elseif(USE_SHA1 STREQUAL "mbedTLS") + set(GIT_SHA1_MBEDTLS 1) + file(GLOB SRC_SHA1 hash/sha1/mbedtls.*) + list(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR}) + list(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES}) # mbedTLS has no pkgconfig file, hence we can't require it # https://github.com/ARMmbed/mbedtls/issues/228 # For now, pass its link flags as our own - LIST(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES}) -ELSEIF(USE_SHA1 STREQUAL "Win32") - SET(GIT_SHA1_WIN32 1) - FILE(GLOB SRC_SHA1 hash/sha1/win32.*) -ELSEIF(USE_SHA1 STREQUAL "Generic") - FILE(GLOB SRC_SHA1 hash/sha1/generic.*) -ELSE() - MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}") -ENDIF() + list(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES}) +elseif(USE_SHA1 STREQUAL "Win32") + set(GIT_SHA1_WIN32 1) + file(GLOB SRC_SHA1 hash/sha1/win32.*) +elseif(USE_SHA1 STREQUAL "Generic") + file(GLOB SRC_SHA1 hash/sha1/generic.*) +else() + message(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}") +endif() list(APPEND SRC_SHA1 "hash/sha1.h") list(SORT SRC_SHA1) -ADD_FEATURE_INFO(SHA ON "using ${USE_SHA1}") +add_feature_info(SHA ON "using ${USE_SHA1}") -- cgit v1.2.1 From 395b3dc403621f1ab3c400780b057cae91c6f6c1 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 22:10:51 -0500 Subject: cmake: refactor global variables Update the global variables `LIBGIT2_OBJECTS` to `LIBGIT2_DEPENDENCY_OBJECTS` for clarity and consistency. --- cmake/SelectGSSAPI.cmake | 4 ++-- cmake/SelectHTTPParser.cmake | 6 +++--- cmake/SelectHTTPSBackend.cmake | 8 ++++---- cmake/SelectHashes.cmake | 4 ++-- cmake/SelectRegex.cmake | 8 ++++---- cmake/SelectSSH.cmake | 6 +++--- cmake/SelectWinHTTP.cmake | 6 +++--- cmake/SelectZlib.cmake | 10 +++++----- examples/CMakeLists.txt | 9 +++++---- fuzzers/CMakeLists.txt | 14 +++++++------- src/CMakeLists.txt | 30 +++++++++++++++--------------- tests/CMakeLists.txt | 12 +++++------- 12 files changed, 58 insertions(+), 59 deletions(-) diff --git a/cmake/SelectGSSAPI.cmake b/cmake/SelectGSSAPI.cmake index e9c5c75c1..24e2d68b9 100644 --- a/cmake/SelectGSSAPI.cmake +++ b/cmake/SelectGSSAPI.cmake @@ -26,7 +26,7 @@ if(USE_GSSAPI) message(FATAL_ERROR "Asked for GSS.framework backend, but it wasn't found") endif() - list(APPEND LIBGIT2_LIBS ${GSSFRAMEWORK_LIBRARIES}) + list(APPEND LIBGIT2_SYSTEM_LIBS ${GSSFRAMEWORK_LIBRARIES}) set(GIT_GSSFRAMEWORK 1) add_feature_info(SPNEGO GIT_GSSFRAMEWORK "SPNEGO authentication support (${USE_GSSAPI})") @@ -35,7 +35,7 @@ if(USE_GSSAPI) message(FATAL_ERROR "Asked for gssapi GSS backend, but it wasn't found") endif() - list(APPEND LIBGIT2_LIBS ${GSSAPI_LIBRARIES}) + list(APPEND LIBGIT2_SYSTEM_LIBS ${GSSAPI_LIBRARIES}) set(GIT_GSSAPI 1) add_feature_info(SPNEGO GIT_GSSAPI "SPNEGO authentication support (${USE_GSSAPI})") diff --git a/cmake/SelectHTTPParser.cmake b/cmake/SelectHTTPParser.cmake index a1724a7c4..721f7fa9f 100644 --- a/cmake/SelectHTTPParser.cmake +++ b/cmake/SelectHTTPParser.cmake @@ -4,7 +4,7 @@ if(USE_HTTP_PARSER STREQUAL "system") if(HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2) list(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS}) - list(APPEND LIBGIT2_LIBS ${HTTP_PARSER_LIBRARIES}) + list(APPEND LIBGIT2_SYSTEM_LIBS ${HTTP_PARSER_LIBRARIES}) list(APPEND LIBGIT2_PC_LIBS "-lhttp_parser") add_feature_info(http-parser ON "http-parser support (system)") else() @@ -13,7 +13,7 @@ if(USE_HTTP_PARSER STREQUAL "system") else() message(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.") add_subdirectory("${libgit2_SOURCE_DIR}/deps/http-parser" "${libgit2_BINARY_DIR}/deps/http-parser") - list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/http-parser") - list(APPEND LIBGIT2_OBJECTS "$") + list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/http-parser") + list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$") add_feature_info(http-parser ON "http-parser support (bundled)") endif() diff --git a/cmake/SelectHTTPSBackend.cmake b/cmake/SelectHTTPSBackend.cmake index 1c6bd6a59..79319502e 100644 --- a/cmake/SelectHTTPSBackend.cmake +++ b/cmake/SelectHTTPSBackend.cmake @@ -45,7 +45,7 @@ if(USE_HTTPS) set(GIT_SECURE_TRANSPORT 1) list(APPEND LIBGIT2_SYSTEM_INCLUDES ${SECURITY_INCLUDE_DIR}) - list(APPEND LIBGIT2_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) + list(APPEND LIBGIT2_SYSTEM_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) list(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) elseif(USE_HTTPS STREQUAL "OpenSSL") if(NOT OPENSSL_FOUND) @@ -54,7 +54,7 @@ if(USE_HTTPS) set(GIT_OPENSSL 1) list(APPEND LIBGIT2_SYSTEM_INCLUDES ${OPENSSL_INCLUDE_DIR}) - list(APPEND LIBGIT2_LIBS ${OPENSSL_LIBRARIES}) + list(APPEND LIBGIT2_SYSTEM_LIBS ${OPENSSL_LIBRARIES}) list(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS}) list(APPEND LIBGIT2_PC_REQUIRES "openssl") elseif(USE_HTTPS STREQUAL "mbedTLS") @@ -101,7 +101,7 @@ if(USE_HTTPS) set(GIT_MBEDTLS 1) list(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR}) - list(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES}) + list(APPEND LIBGIT2_SYSTEM_LIBS ${MBEDTLS_LIBRARIES}) # mbedTLS has no pkgconfig file, hence we can't require it # https://github.com/ARMmbed/mbedtls/issues/228 # For now, pass its link flags as our own @@ -111,7 +111,7 @@ if(USE_HTTPS) elseif(USE_HTTPS STREQUAL "OpenSSL-Dynamic") set(GIT_OPENSSL 1) set(GIT_OPENSSL_DYNAMIC 1) - list(APPEND LIBGIT2_LIBS dl) + list(APPEND LIBGIT2_SYSTEM_LIBS dl) else() message(FATAL_ERROR "Asked for backend ${USE_HTTPS} but it wasn't found") endif() diff --git a/cmake/SelectHashes.cmake b/cmake/SelectHashes.cmake index fee8b2902..fdefb57fd 100644 --- a/cmake/SelectHashes.cmake +++ b/cmake/SelectHashes.cmake @@ -3,10 +3,10 @@ include(SanitizeBool) # USE_SHA1=CollisionDetection(ON)/HTTPS/Generic/OFF - sanitizebool(USE_SHA1) + if(USE_SHA1 STREQUAL ON) - set(USE_SHA1 "CollisionDetection") + SET(USE_SHA1 "CollisionDetection") elseif(USE_SHA1 STREQUAL "HTTPS") if(USE_HTTPS STREQUAL "SecureTransport") set(USE_SHA1 "CommonCrypto") diff --git a/cmake/SelectRegex.cmake b/cmake/SelectRegex.cmake index 900d7f150..1553d6587 100644 --- a/cmake/SelectRegex.cmake +++ b/cmake/SelectRegex.cmake @@ -27,14 +27,14 @@ elseif(REGEX_BACKEND STREQUAL "pcre2") set(GIT_REGEX_PCRE2 1) list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE2_INCLUDE_DIRS}) - list(APPEND LIBGIT2_LIBS ${PCRE2_LIBRARIES}) + list(APPEND LIBGIT2_SYSTEM_LIBS ${PCRE2_LIBRARIES}) list(APPEND LIBGIT2_PC_REQUIRES "libpcre2-8") elseif(REGEX_BACKEND STREQUAL "pcre") add_feature_info(regex ON "using system PCRE") set(GIT_REGEX_PCRE 1) list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE_INCLUDE_DIRS}) - list(APPEND LIBGIT2_LIBS ${PCRE_LIBRARIES}) + list(APPEND LIBGIT2_SYSTEM_LIBS ${PCRE_LIBRARIES}) list(APPEND LIBGIT2_PC_REQUIRES "libpcre") elseif(REGEX_BACKEND STREQUAL "regcomp") add_feature_info(regex ON "using system regcomp") @@ -44,8 +44,8 @@ elseif(REGEX_BACKEND STREQUAL "builtin") set(GIT_REGEX_BUILTIN 1) add_subdirectory("${libgit2_SOURCE_DIR}/deps/pcre" "${libgit2_BINARY_DIR}/deps/pcre") - list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/pcre") - list(APPEND LIBGIT2_OBJECTS $) + list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/pcre") + list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $) else() message(FATAL_ERROR "The REGEX_BACKEND option provided is not supported") endif() diff --git a/cmake/SelectSSH.cmake b/cmake/SelectSSH.cmake index 0356ee3e7..23dfc9785 100644 --- a/cmake/SelectSSH.cmake +++ b/cmake/SelectSSH.cmake @@ -17,7 +17,7 @@ endif() if(LIBSSH2_FOUND) set(GIT_SSH 1) list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS}) - list(APPEND LIBGIT2_LIBS ${LIBSSH2_LIBRARIES}) + list(APPEND LIBGIT2_SYSTEM_LIBS ${LIBSSH2_LIBRARIES}) list(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS}) check_library_exists("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS) @@ -31,9 +31,9 @@ endif() if(WIN32 AND EMBED_SSH_PATH) file(GLOB SSH_SRC "${EMBED_SSH_PATH}/src/*.c") list(SORT SSH_SRC) - list(APPEND LIBGIT2_OBJECTS ${SSH_SRC}) + list(APPEND LIBGIT2_DEPENDENCY_OBJECTS ${SSH_SRC}) - list(APPEND LIBGIT2_INCLUDES "${EMBED_SSH_PATH}/include") + list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${EMBED_SSH_PATH}/include") file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"") set(GIT_SSH 1) endif() diff --git a/cmake/SelectWinHTTP.cmake b/cmake/SelectWinHTTP.cmake index a4110045f..1d950c900 100644 --- a/cmake/SelectWinHTTP.cmake +++ b/cmake/SelectWinHTTP.cmake @@ -5,13 +5,13 @@ if(WIN32 AND WINHTTP) # we have to include a private header and generate our own import library if(MINGW) add_subdirectory("${libgit2_SOURCE_DIR}/deps/winhttp" "${libgit2_BINARY_DIR}/deps/winhttp") - list(APPEND LIBGIT2_LIBS winhttp) + list(APPEND LIBGIT2_SYSTEM_LIBS winhttp) list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/winhttp") else() - list(APPEND LIBGIT2_LIBS "winhttp") + list(APPEND LIBGIT2_SYSTEM_LIBS "winhttp") list(APPEND LIBGIT2_PC_LIBS "-lwinhttp") endif() - list(APPEND LIBGIT2_LIBS "rpcrt4" "crypt32" "ole32") + list(APPEND LIBGIT2_SYSTEM_LIBS "rpcrt4" "crypt32" "ole32") list(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32") endif() diff --git a/cmake/SelectZlib.cmake b/cmake/SelectZlib.cmake index 2dfc6c86e..e377d43b6 100644 --- a/cmake/SelectZlib.cmake +++ b/cmake/SelectZlib.cmake @@ -10,7 +10,7 @@ if(USE_BUNDLED_ZLIB STREQUAL "OFF") find_package(ZLIB) if(ZLIB_FOUND) list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ZLIB_INCLUDE_DIRS}) - list(APPEND LIBGIT2_LIBS ${ZLIB_LIBRARIES}) + list(APPEND LIBGIT2_SYSTEM_LIBS ${ZLIB_LIBRARIES}) if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD") list(APPEND LIBGIT2_PC_LIBS "-lz") else() @@ -23,12 +23,12 @@ if(USE_BUNDLED_ZLIB STREQUAL "OFF") endif() if(USE_BUNDLED_ZLIB STREQUAL "Chromium") add_subdirectory("${libgit2_SOURCE_DIR}/deps/chromium-zlib" "${libgit2_BINARY_DIR}/deps/chromium-zlib") - list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/chromium-zlib") - list(APPEND LIBGIT2_OBJECTS $) + list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/chromium-zlib") + list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $) add_feature_info(zlib ON "using (Chromium) bundled zlib") elseif(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND) add_subdirectory("${libgit2_SOURCE_DIR}/deps/zlib" "${libgit2_BINARY_DIR}/deps/zlib") - list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/zlib") - list(APPEND LIBGIT2_OBJECTS $) + list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/zlib") + list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $) add_feature_info(zlib ON "using bundled zlib") endif() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index a7970a6d0..235e72ada 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,13 +1,14 @@ -include_directories(${LIBGIT2_INCLUDES}) -include_directories(SYSTEM ${LIBGIT2_SYSTEM_INCLUDES}) +file(GLOB SRC_EXAMPLES *.c *.h) -file(GLOB LG2_SOURCES *.c *.h) -add_executable(lg2 ${LG2_SOURCES}) +add_executable(lg2 ${SRC_EXAMPLES}) set_target_properties(lg2 PROPERTIES C_STANDARD 90) # Ensure that we do not use deprecated functions internally add_definitions(-DGIT_DEPRECATE_HARD) +target_include_directories(lg2 PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES}) +target_include_directories(lg2 SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) + if(WIN32 OR ANDROID) target_link_libraries(lg2 git2) else() diff --git a/fuzzers/CMakeLists.txt b/fuzzers/CMakeLists.txt index 1479a2af8..eaa490fd9 100644 --- a/fuzzers/CMakeLists.txt +++ b/fuzzers/CMakeLists.txt @@ -1,7 +1,3 @@ -link_directories(${LIBGIT2_LIBDIRS}) -include_directories(${LIBGIT2_INCLUDES}) -include_directories(SYSTEM ${LIBGIT2_SYSTEM_INCLUDES}) - if(BUILD_FUZZERS AND NOT USE_STANDALONE_FUZZERS) set(CMAKE_REQUIRED_FLAGS "-fsanitize=fuzzer-no-link") add_c_flag(-fsanitize=fuzzer) @@ -9,8 +5,8 @@ if(BUILD_FUZZERS AND NOT USE_STANDALONE_FUZZERS) unset(CMAKE_REQUIRED_FLAGS) endif() -file(GLOB SRC_FUZZ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *_fuzzer.c) -foreach(fuzz_target_src ${SRC_FUZZ}) +file(GLOB SRC_FUZZERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *_fuzzer.c) +foreach(fuzz_target_src ${SRC_FUZZERS}) string(REPLACE ".c" "" fuzz_target_name ${fuzz_target_src}) string(REPLACE "_fuzzer" "" fuzz_name ${fuzz_target_name}) @@ -20,7 +16,11 @@ foreach(fuzz_target_src ${SRC_FUZZ}) endif() add_executable(${fuzz_target_name} ${${fuzz_target_name}_SOURCES}) set_target_properties(${fuzz_target_name} PROPERTIES C_STANDARD 90) - target_link_libraries(${fuzz_target_name} ${LIBGIT2_LIBS}) + + target_include_directories(${fuzz_target_name} PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES}) + target_include_directories(${fuzz_target_name} SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) + + target_link_libraries(${fuzz_target_name} ${LIBGIT2_SYSTEM_LIBS}) add_test(${fuzz_target_name} "${CMAKE_CURRENT_BINARY_DIR}/${fuzz_target_name}" "${CMAKE_CURRENT_SOURCE_DIR}/corpora/${fuzz_name}") endforeach() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6a128cfa8..b23b6a046 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,8 +38,6 @@ set(LIBGIT2_INCLUDES "${CMAKE_CURRENT_BINARY_DIR}" "${libgit2_SOURCE_DIR}/src" "${libgit2_SOURCE_DIR}/include") -set(LIBGIT2_SYSTEM_INCLUDES "") -set(LIBGIT2_LIBS "") if(HAVE_FUTIMENS) set(GIT_USE_FUTIMENS 1) @@ -59,23 +57,23 @@ check_function_exists(qsort_s GIT_QSORT_S) # Find required dependencies if(WIN32) - list(APPEND LIBGIT2_LIBS ws2_32) + list(APPEND LIBGIT2_SYSTEM_LIBS ws2_32) elseif(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") - list(APPEND LIBGIT2_LIBS socket nsl) + list(APPEND LIBGIT2_SYSTEM_LIBS socket nsl) list(APPEND LIBGIT2_PC_LIBS "-lsocket" "-lnsl") elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku") - list(APPEND LIBGIT2_LIBS network) + list(APPEND LIBGIT2_SYSTEM_LIBS network) list(APPEND LIBGIT2_PC_LIBS "-lnetwork") endif() check_library_exists(rt clock_gettime "time.h" NEED_LIBRT) if(NEED_LIBRT) - list(APPEND LIBGIT2_LIBS rt) + list(APPEND LIBGIT2_SYSTEM_LIBS rt) list(APPEND LIBGIT2_PC_LIBS "-lrt") endif() if(USE_THREADS) - list(APPEND LIBGIT2_LIBS ${CMAKE_THREAD_LIBS_INIT}) + list(APPEND LIBGIT2_SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT}) list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT}) endif() add_feature_info(threadsafe USE_THREADS "threadsafe support") @@ -105,8 +103,8 @@ target_sources(git2internal PRIVATE ${SRC_SHA1}) if(USE_NTLMCLIENT) set(GIT_NTLM 1) add_subdirectory("${libgit2_SOURCE_DIR}/deps/ntlmclient" "${libgit2_BINARY_DIR}/deps/ntlmclient") - list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/ntlmclient") - list(APPEND LIBGIT2_OBJECTS "$") + list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/ntlmclient") + list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$") endif() add_feature_info(ntlmclient GIT_NTLM "NTLM authentication support for Unix") @@ -121,7 +119,7 @@ endif() if(ICONV_FOUND) set(GIT_USE_ICONV 1) list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ICONV_INCLUDE_DIR}) - list(APPEND LIBGIT2_LIBS ${ICONV_LIBRARIES}) + list(APPEND LIBGIT2_SYSTEM_LIBS ${ICONV_LIBRARIES}) list(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES}) endif() add_feature_info(iconv GIT_USE_ICONV "iconv encoding conversion support") @@ -210,15 +208,17 @@ endif() configure_file(features.h.in git2/sys/features.h) ide_split_sources(git2internal) -list(APPEND LIBGIT2_OBJECTS $) +list(APPEND LIBGIT2_OBJECTS $ ${LIBGIT2_DEPENDENCY_OBJECTS}) -target_include_directories(git2internal PRIVATE ${LIBGIT2_INCLUDES} PUBLIC ${libgit2_SOURCE_DIR}/include) +target_include_directories(git2internal PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES} PUBLIC ${libgit2_SOURCE_DIR}/include) target_include_directories(git2internal SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) -set(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE) set(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE) +set(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE) +set(LIBGIT2_DEPENDENCY_INCLUDES ${LIBGIT2_DEPENDENCY_INCLUDES} PARENT_SCOPE) +set(LIBGIT2_DEPENDENCY_OBJECTS ${LIBGIT2_DEPENDENCY_OBJECTS} PARENT_SCOPE) set(LIBGIT2_SYSTEM_INCLUDES ${LIBGIT2_SYSTEM_INCLUDES} PARENT_SCOPE) -set(LIBGIT2_LIBS ${LIBGIT2_LIBS} PARENT_SCOPE) +set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE) if(XCODE_VERSION) # This is required for Xcode to actually link the libgit2 library @@ -229,7 +229,7 @@ endif() # Compile and link libgit2 add_library(git2 ${WIN_RC} ${LIBGIT2_OBJECTS}) -target_link_libraries(git2 ${LIBGIT2_LIBS}) +target_link_libraries(git2 ${LIBGIT2_SYSTEM_LIBS}) set_target_properties(git2 PROPERTIES C_STANDARD 90) set_target_properties(git2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e109913ff..072470350 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,7 +16,7 @@ add_definitions(-D_FILE_OFFSET_BITS=64) # Ensure that we do not use deprecated functions internally add_definitions(-DGIT_DEPRECATE_HARD) -include_directories(${CLAR_PATH} ${libgit2_BINARY_DIR}/src) +set(TEST_INCLUDES "${CLAR_PATH}" "${CMAKE_CURRENT_BINARY_DIR}") file(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h) set(SRC_CLAR "main.c" "clar_libgit2.c" "clar_libgit2_trace.c" "clar_libgit2_timer.c" "clar.c") @@ -30,22 +30,20 @@ add_custom_command( DEPENDS ${SRC_TEST} WORKING_DIRECTORY ${CLAR_PATH} ) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) set_source_files_properties( ${CLAR_PATH}/clar.c PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite) -include_directories(${LIBGIT2_INCLUDES}) -include_directories(SYSTEM ${LIBGIT2_SYSTEM_INCLUDES}) - add_executable(libgit2_tests ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS}) set_target_properties(libgit2_tests PROPERTIES C_STANDARD 90) set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR}) -target_include_directories(libgit2_tests PRIVATE ../src PUBLIC ../include) -target_link_libraries(libgit2_tests ${LIBGIT2_LIBS}) +target_include_directories(libgit2_tests PRIVATE ${TEST_INCLUDES} ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES}) +target_include_directories(libgit2_tests SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) +target_link_libraries(libgit2_tests ${LIBGIT2_SYSTEM_LIBS}) + ide_split_sources(libgit2_tests) # -- cgit v1.2.1 From c7f6ecb3911b5bc8052428a3605802403c673730 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 22:54:14 -0500 Subject: cmake: use a string not a boolean for LIBGIT2_FILENAME --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ae0a5d685..664abc0d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,7 @@ option(DEBUG_STRICT_OPEN "Enable path validation in open" # Output options option(SONAME "Set the (SO)VERSION of the target" ON) -option(LIBGIT2_FILENAME "Name of the produced binary" OFF) + set(LIBGIT2_FILENAME "git2" CACHE STRING "Name of the produced binary") option(DEPRECATE_HARD "Do not include deprecated functions in the library" OFF) # Compilation options -- cgit v1.2.1 From 2c154145a8f7ce3c01f1afc40e3934c1e43c377e Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 11 Nov 2021 23:09:44 -0500 Subject: cmake: move sha1 source selection into CMakeLists.txt The select hashes module selects the hash; the CMakeLists.txt selects the files to implement it. --- cmake/SelectHashes.cmake | 14 ++------------ src/CMakeLists.txt | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cmake/SelectHashes.cmake b/cmake/SelectHashes.cmake index fdefb57fd..bedd8c4e3 100644 --- a/cmake/SelectHashes.cmake +++ b/cmake/SelectHashes.cmake @@ -24,7 +24,6 @@ if(USE_SHA1 STREQUAL "CollisionDetection") 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/sha1/collisiondetect.* hash/sha1/sha1dc/*) elseif(USE_SHA1 STREQUAL "OpenSSL") # OPENSSL_FOUND should already be set, we're checking USE_HTTPS @@ -34,29 +33,20 @@ elseif(USE_SHA1 STREQUAL "OpenSSL") else() list(APPEND LIBGIT2_PC_REQUIRES "openssl") endif() - file(GLOB SRC_SHA1 hash/sha1/openssl.*) elseif(USE_SHA1 STREQUAL "CommonCrypto") set(GIT_SHA1_COMMON_CRYPTO 1) - file(GLOB SRC_SHA1 hash/sha1/common_crypto.*) elseif(USE_SHA1 STREQUAL "mbedTLS") set(GIT_SHA1_MBEDTLS 1) - file(GLOB SRC_SHA1 hash/sha1/mbedtls.*) list(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR}) - list(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES}) + list(APPEND LIBGIT2_SYSTEM_LIBS ${MBEDTLS_LIBRARIES}) # mbedTLS has no pkgconfig file, hence we can't require it # https://github.com/ARMmbed/mbedtls/issues/228 # For now, pass its link flags as our own list(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES}) elseif(USE_SHA1 STREQUAL "Win32") set(GIT_SHA1_WIN32 1) - file(GLOB SRC_SHA1 hash/sha1/win32.*) -elseif(USE_SHA1 STREQUAL "Generic") - file(GLOB SRC_SHA1 hash/sha1/generic.*) -else() +elseif(NOT (USE_SHA1 STREQUAL "Generic")) message(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}") endif() -list(APPEND SRC_SHA1 "hash/sha1.h") -list(SORT SRC_SHA1) - add_feature_info(SHA ON "using ${USE_SHA1}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b23b6a046..d6a103667 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -97,6 +97,21 @@ include(SelectSSH) include(SelectWinHTTP) include(SelectZlib) + +if(USE_SHA1 STREQUAL "CollisionDetection") + file(GLOB SRC_SHA1 hash/sha1/collisiondetect.* hash/sha1/sha1dc/*) +elseif(USE_SHA1 STREQUAL "OpenSSL") + file(GLOB SRC_SHA1 hash/sha1/openssl.*) +elseif(USE_SHA1 STREQUAL "CommonCrypto") + file(GLOB SRC_SHA1 hash/sha1/common_crypto.*) +elseif(USE_SHA1 STREQUAL "mbedTLS") + file(GLOB SRC_SHA1 hash/sha1/mbedtls.*) +elseif(USE_SHA1 STREQUAL "Win32") + file(GLOB SRC_SHA1 hash/sha1/win32.*) +elseif(USE_SHA1 STREQUAL "Generic") + file(GLOB SRC_SHA1 hash/sha1/generic.*) +endif() +list(APPEND SRC_SHA1 "hash/sha1.h") target_sources(git2internal PRIVATE ${SRC_SHA1}) # Optional external dependency: ntlmclient -- cgit v1.2.1 From 5221e1854846ac31dd2ada44fb29dc705104e851 Mon Sep 17 00:00:00 2001 From: Peter Pettersson Date: Sat, 2 Oct 2021 23:54:14 +0200 Subject: Add target for testing libgit2 headers --- tests/CMakeLists.txt | 14 +++++++++++++- tests/headertest.c | 13 +++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/headertest.c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 072470350..d42c6ad5b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -51,7 +51,7 @@ ide_split_sources(libgit2_tests) # this on newer compilers to avoid unnecessary recompilation. # if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0) - add_definitions(-include \"clar_suite.h\") + target_compile_options(libgit2_tests PRIVATE -include "clar_suite.h") endif() if(MSVC_IDE) @@ -79,3 +79,15 @@ add_clar_test(ssh -v -sonline::push -sonline::clone::ssh_cert -s add_clar_test(proxy -v -sonline::clone::proxy) add_clar_test(auth_clone -v -sonline::clone::cred) add_clar_test(auth_clone_and_push -v -sonline::clone::push -sonline::push) + +# Header file validation project +add_executable(headertest headertest.c) +set_target_properties(headertest PROPERTIES C_STANDARD 90) +set_target_properties(headertest PROPERTIES C_EXTENSIONS OFF) +target_include_directories(headertest PRIVATE ${LIBGIT2_INCLUDES}) + +if (MSVC) + target_compile_options(headertest PUBLIC /W4 /WX) +else() + target_compile_options(headertest PUBLIC -Wall -Wextra -pedantic -Werror) +endif() diff --git a/tests/headertest.c b/tests/headertest.c new file mode 100644 index 000000000..2af8a14ec --- /dev/null +++ b/tests/headertest.c @@ -0,0 +1,13 @@ +/* + * Dummy project to validate header files + * + * This project is not intended to be executed, it should only include all + * header files to make sure that they can be used with stricter compiler + * settings than the libgit2 source files generally supports. + */ +#include "git2.h" + +int main(void) +{ + return 0; +} -- cgit v1.2.1 From 38c3449822162e7b7669c1cc7ca778afccb59406 Mon Sep 17 00:00:00 2001 From: Peter Pettersson Date: Sun, 3 Oct 2021 00:12:52 +0200 Subject: Make enum in includes C90 compliant by removing trailing comma. --- include/git2/apply.h | 4 ++-- include/git2/attr.h | 2 +- include/git2/blame.h | 2 +- include/git2/blob.h | 2 +- include/git2/cert.h | 4 ++-- include/git2/checkout.h | 2 +- include/git2/clone.h | 2 +- include/git2/common.h | 2 +- include/git2/config.h | 2 +- include/git2/credential.h | 2 +- include/git2/deprecated.h | 2 +- include/git2/describe.h | 2 +- include/git2/diff.h | 14 +++++++------- include/git2/email.h | 2 +- include/git2/errors.h | 2 +- include/git2/filter.h | 4 ++-- include/git2/index.h | 10 +++++----- include/git2/merge.h | 10 +++++----- include/git2/odb_backend.h | 2 +- include/git2/pack.h | 2 +- include/git2/pathspec.h | 2 +- include/git2/proxy.h | 2 +- include/git2/rebase.h | 2 +- include/git2/refs.h | 2 +- include/git2/remote.h | 8 ++++---- include/git2/repository.h | 8 ++++---- include/git2/reset.h | 2 +- include/git2/revparse.h | 2 +- include/git2/revwalk.h | 2 +- include/git2/stash.h | 6 +++--- include/git2/status.h | 6 +++--- include/git2/submodule.h | 2 +- include/git2/sys/commit_graph.h | 2 +- include/git2/sys/stream.h | 2 +- include/git2/sys/transport.h | 4 ++-- include/git2/tree.h | 4 ++-- include/git2/types.h | 12 ++++++------ include/git2/worktree.h | 2 +- 38 files changed, 72 insertions(+), 72 deletions(-) diff --git a/include/git2/apply.h b/include/git2/apply.h index bc637df1c..814bc8f16 100644 --- a/include/git2/apply.h +++ b/include/git2/apply.h @@ -59,7 +59,7 @@ typedef enum { * Don't actually make changes, just test that the patch applies. * This is the equivalent of `git apply --check`. */ - GIT_APPLY_CHECK = (1 << 0), + GIT_APPLY_CHECK = (1 << 0) } git_apply_flags_t; /** @@ -127,7 +127,7 @@ typedef enum { * Apply the patch to both the working directory and the index. * This is the equivalent of `git apply --index`. */ - GIT_APPLY_LOCATION_BOTH = 2, + GIT_APPLY_LOCATION_BOTH = 2 } git_apply_location_t; /** diff --git a/include/git2/attr.h b/include/git2/attr.h index 3891a0c97..157192c9d 100644 --- a/include/git2/attr.h +++ b/include/git2/attr.h @@ -83,7 +83,7 @@ typedef enum { GIT_ATTR_VALUE_UNSPECIFIED = 0, /**< The attribute has been left unspecified */ GIT_ATTR_VALUE_TRUE, /**< The attribute has been set */ GIT_ATTR_VALUE_FALSE, /**< The attribute has been unset */ - GIT_ATTR_VALUE_STRING, /**< This attribute has a value */ + GIT_ATTR_VALUE_STRING /**< This attribute has a value */ } git_attr_value_t; /** diff --git a/include/git2/blame.h b/include/git2/blame.h index d193ce14e..33a9fbc98 100644 --- a/include/git2/blame.h +++ b/include/git2/blame.h @@ -73,7 +73,7 @@ typedef enum { GIT_BLAME_USE_MAILMAP = (1<<5), /** Ignore whitespace differences */ - GIT_BLAME_IGNORE_WHITESPACE = (1<<6), + GIT_BLAME_IGNORE_WHITESPACE = (1<<6) } git_blame_flag_t; /** diff --git a/include/git2/blob.h b/include/git2/blob.h index 8fc73919d..4922b087a 100644 --- a/include/git2/blob.h +++ b/include/git2/blob.h @@ -119,7 +119,7 @@ typedef enum { * When set, filters will be loaded from a `.gitattributes` file * in the specified commit. */ - GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT = (1 << 3), + GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT = (1 << 3) } git_blob_filter_flag_t; /** diff --git a/include/git2/cert.h b/include/git2/cert.h index 0ed38ffcd..05213a571 100644 --- a/include/git2/cert.h +++ b/include/git2/cert.h @@ -44,7 +44,7 @@ typedef enum git_cert_t { * information about the certificate. This is used when using * curl. */ - GIT_CERT_STRARRAY, + GIT_CERT_STRARRAY } git_cert_t; /** @@ -82,7 +82,7 @@ typedef enum { /** SHA-256 is available */ GIT_CERT_SSH_SHA256 = (1 << 2), /** Raw hostkey is available */ - GIT_CERT_SSH_RAW = (1 << 3), + GIT_CERT_SSH_RAW = (1 << 3) } git_cert_ssh_t; typedef enum { diff --git a/include/git2/checkout.h b/include/git2/checkout.h index c7aeee431..f026d5bc2 100644 --- a/include/git2/checkout.h +++ b/include/git2/checkout.h @@ -190,7 +190,7 @@ typedef enum { /** Recursively checkout submodules with same options (NOT IMPLEMENTED) */ GIT_CHECKOUT_UPDATE_SUBMODULES = (1u << 16), /** Recursively checkout submodules if HEAD moved in super repo (NOT IMPLEMENTED) */ - GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED = (1u << 17), + GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED = (1u << 17) } git_checkout_strategy_t; diff --git a/include/git2/clone.h b/include/git2/clone.h index 3c3ea260e..c517ec3d6 100644 --- a/include/git2/clone.h +++ b/include/git2/clone.h @@ -49,7 +49,7 @@ typedef enum { * Bypass the git-aware transport, but do not try to use * hardlinks. */ - GIT_CLONE_LOCAL_NO_LINKS, + GIT_CLONE_LOCAL_NO_LINKS } git_clone_local_t; /** diff --git a/include/git2/common.h b/include/git2/common.h index 2ee829025..d62d9be18 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -147,7 +147,7 @@ typedef enum { * If set, libgit2 was built with support for sub-second resolution in file * modification times. */ - GIT_FEATURE_NSEC = (1 << 3), + GIT_FEATURE_NSEC = (1 << 3) } git_feature_t; /** diff --git a/include/git2/config.h b/include/git2/config.h index 7c8e388b2..cad01ea49 100644 --- a/include/git2/config.h +++ b/include/git2/config.h @@ -55,7 +55,7 @@ typedef enum { /** Represents the highest level available config file (i.e. the most * specific config file available that actually is loaded) */ - GIT_CONFIG_HIGHEST_LEVEL = -1, + GIT_CONFIG_HIGHEST_LEVEL = -1 } git_config_level_t; /** diff --git a/include/git2/credential.h b/include/git2/credential.h index 9426a6ea2..a4e68e853 100644 --- a/include/git2/credential.h +++ b/include/git2/credential.h @@ -75,7 +75,7 @@ typedef enum { * * @see git_credential_ssh_key_memory_new */ - GIT_CREDENTIAL_SSH_MEMORY = (1u << 6), + GIT_CREDENTIAL_SSH_MEMORY = (1u << 6) } git_credential_t; /** diff --git a/include/git2/deprecated.h b/include/git2/deprecated.h index 37b9fa0e2..f73d7da61 100644 --- a/include/git2/deprecated.h +++ b/include/git2/deprecated.h @@ -313,7 +313,7 @@ typedef enum { GIT_DIFF_FORMAT_EMAIL_NONE = 0, /** Don't insert "[PATCH]" in the subject header*/ - GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER = (1 << 0), + GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER = (1 << 0) } git_diff_format_email_flags_t; diff --git a/include/git2/describe.h b/include/git2/describe.h index 1d2ca1496..e8afd6879 100644 --- a/include/git2/describe.h +++ b/include/git2/describe.h @@ -30,7 +30,7 @@ GIT_BEGIN_DECL typedef enum { GIT_DESCRIBE_DEFAULT, GIT_DESCRIBE_TAGS, - GIT_DESCRIBE_ALL, + GIT_DESCRIBE_ALL } git_describe_strategy_t; /** diff --git a/include/git2/diff.h b/include/git2/diff.h index b0119b9f7..c040cd190 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -170,7 +170,7 @@ typedef enum { /** Include the necessary deflate / delta information so that `git-apply` * can apply given diff information to binary files. */ - GIT_DIFF_SHOW_BINARY = (1u << 30), + GIT_DIFF_SHOW_BINARY = (1u << 30) } git_diff_option_t; /** @@ -207,7 +207,7 @@ typedef enum { GIT_DIFF_FLAG_BINARY = (1u << 0), /**< file(s) treated as binary data */ GIT_DIFF_FLAG_NOT_BINARY = (1u << 1), /**< file(s) treated as text data */ GIT_DIFF_FLAG_VALID_ID = (1u << 2), /**< `id` value is known correct */ - GIT_DIFF_FLAG_EXISTS = (1u << 3), /**< file exists at this side of the delta */ + GIT_DIFF_FLAG_EXISTS = (1u << 3) /**< file exists at this side of the delta */ } git_diff_flag_t; /** @@ -231,7 +231,7 @@ typedef enum { GIT_DELTA_UNTRACKED = 7, /**< entry is untracked item in workdir */ GIT_DELTA_TYPECHANGE = 8, /**< type of entry changed between old and new */ GIT_DELTA_UNREADABLE = 9, /**< entry is unreadable */ - GIT_DELTA_CONFLICTED = 10, /**< entry in the index is conflicted */ + GIT_DELTA_CONFLICTED = 10 /**< entry in the index is conflicted */ } git_delta_t; /** @@ -497,7 +497,7 @@ typedef enum { GIT_DIFF_BINARY_LITERAL, /** The binary data is the delta from one side to the other. */ - GIT_DIFF_BINARY_DELTA, + GIT_DIFF_BINARY_DELTA } git_diff_binary_t; /** The contents of one of the files in a binary diff. */ @@ -706,7 +706,7 @@ typedef enum { * GIT_DIFF_INCLUDE_UNMODIFIED flag. If you do not want UNMODIFIED * records in the final result, pass this flag to have them removed. */ - GIT_DIFF_FIND_REMOVE_UNMODIFIED = (1u << 16), + GIT_DIFF_FIND_REMOVE_UNMODIFIED = (1u << 16) } git_diff_find_t; /** @@ -1107,7 +1107,7 @@ typedef enum { GIT_DIFF_FORMAT_RAW = 3u, /**< like git diff --raw */ GIT_DIFF_FORMAT_NAME_ONLY = 4u, /**< like git diff --name-only */ GIT_DIFF_FORMAT_NAME_STATUS = 5u, /**< like git diff --name-status */ - GIT_DIFF_FORMAT_PATCH_ID = 6u, /**< git diff as used by git patch-id */ + GIT_DIFF_FORMAT_PATCH_ID = 6u /**< git diff as used by git patch-id */ } git_diff_format_t; /** @@ -1311,7 +1311,7 @@ typedef enum { GIT_DIFF_STATS_NUMBER = (1u << 2), /** Extended header information such as creations, renames and mode changes, equivalent of `--summary` */ - GIT_DIFF_STATS_INCLUDE_SUMMARY = (1u << 3), + GIT_DIFF_STATS_INCLUDE_SUMMARY = (1u << 3) } git_diff_stats_format_t; /** diff --git a/include/git2/email.h b/include/git2/email.h index b56be5d0e..20393653e 100644 --- a/include/git2/email.h +++ b/include/git2/email.h @@ -34,7 +34,7 @@ typedef enum { GIT_EMAIL_CREATE_ALWAYS_NUMBER = (1u << 1), /** Do not perform rename or similarity detection. */ - GIT_EMAIL_CREATE_NO_RENAMES = (1u << 2), + GIT_EMAIL_CREATE_NO_RENAMES = (1u << 2) } git_email_create_flags_t; /** diff --git a/include/git2/errors.h b/include/git2/errors.h index de51582d5..5a5f8c5a2 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -57,7 +57,7 @@ typedef enum { GIT_RETRY = -32, /**< Internal only */ GIT_EMISMATCH = -33, /**< Hashsum mismatch in object */ GIT_EINDEXDIRTY = -34, /**< Unsaved changes in the index would be overwritten */ - GIT_EAPPLYFAIL = -35, /**< Patch application failed */ + GIT_EAPPLYFAIL = -35 /**< Patch application failed */ } git_error_code; /** diff --git a/include/git2/filter.h b/include/git2/filter.h index 0465e5b14..632bb84e3 100644 --- a/include/git2/filter.h +++ b/include/git2/filter.h @@ -32,7 +32,7 @@ typedef enum { GIT_FILTER_TO_WORKTREE = 0, GIT_FILTER_SMUDGE = GIT_FILTER_TO_WORKTREE, GIT_FILTER_TO_ODB = 1, - GIT_FILTER_CLEAN = GIT_FILTER_TO_ODB, + GIT_FILTER_CLEAN = GIT_FILTER_TO_ODB } git_filter_mode_t; /** @@ -54,7 +54,7 @@ typedef enum { * Load attributes from `.gitattributes` in a given commit. * This can only be specified in a `git_filter_options`. */ - GIT_FILTER_ATTRIBUTES_FROM_COMMIT = (1u << 3), + GIT_FILTER_ATTRIBUTES_FROM_COMMIT = (1u << 3) } git_filter_flag_t; /** diff --git a/include/git2/index.h b/include/git2/index.h index 532a52091..5864791e6 100644 --- a/include/git2/index.h +++ b/include/git2/index.h @@ -86,7 +86,7 @@ typedef struct git_index_entry { */ typedef enum { GIT_INDEX_ENTRY_EXTENDED = (0x4000), - GIT_INDEX_ENTRY_VALID = (0x8000), + GIT_INDEX_ENTRY_VALID = (0x8000) } git_index_entry_flag_t; #define GIT_INDEX_ENTRY_STAGE(E) \ @@ -119,7 +119,7 @@ typedef enum { GIT_INDEX_ENTRY_EXTENDED_FLAGS = (GIT_INDEX_ENTRY_INTENT_TO_ADD | GIT_INDEX_ENTRY_SKIP_WORKTREE), - GIT_INDEX_ENTRY_UPTODATE = (1 << 2), + GIT_INDEX_ENTRY_UPTODATE = (1 << 2) } git_index_entry_extended_flag_t; /** Capabilities of system that affect index actions. */ @@ -127,7 +127,7 @@ typedef enum { GIT_INDEX_CAPABILITY_IGNORE_CASE = 1, GIT_INDEX_CAPABILITY_NO_FILEMODE = 2, GIT_INDEX_CAPABILITY_NO_SYMLINKS = 4, - GIT_INDEX_CAPABILITY_FROM_OWNER = -1, + GIT_INDEX_CAPABILITY_FROM_OWNER = -1 } git_index_capability_t; @@ -140,7 +140,7 @@ typedef enum { GIT_INDEX_ADD_DEFAULT = 0, GIT_INDEX_ADD_FORCE = (1u << 0), GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH = (1u << 1), - GIT_INDEX_ADD_CHECK_PATHSPEC = (1u << 2), + GIT_INDEX_ADD_CHECK_PATHSPEC = (1u << 2) } git_index_add_option_t; /** Git index stage states */ @@ -163,7 +163,7 @@ typedef enum { GIT_INDEX_STAGE_OURS = 2, /** The "theirs" side of a conflict. */ - GIT_INDEX_STAGE_THEIRS = 3, + GIT_INDEX_STAGE_THEIRS = 3 } git_index_stage_t; /** diff --git a/include/git2/merge.h b/include/git2/merge.h index fc27c9d1d..e32c53fcc 100644 --- a/include/git2/merge.h +++ b/include/git2/merge.h @@ -91,7 +91,7 @@ typedef enum { * instead simply use the first base. This flag provides a similar * merge base to `git-merge-resolve`. */ - GIT_MERGE_NO_RECURSIVE = (1 << 3), + GIT_MERGE_NO_RECURSIVE = (1 << 3) } git_merge_flag_t; /** @@ -127,7 +127,7 @@ typedef enum { * which has the result of combining both files. The index will not * record a conflict. */ - GIT_MERGE_FILE_FAVOR_UNION = 3, + GIT_MERGE_FILE_FAVOR_UNION = 3 } git_merge_file_favor_t; /** @@ -159,7 +159,7 @@ typedef enum { GIT_MERGE_FILE_DIFF_PATIENCE = (1 << 6), /** Take extra time to find minimal diff */ - GIT_MERGE_FILE_DIFF_MINIMAL = (1 << 7), + GIT_MERGE_FILE_DIFF_MINIMAL = (1 << 7) } git_merge_file_flag_t; #define GIT_MERGE_CONFLICT_MARKER_SIZE 7 @@ -341,7 +341,7 @@ typedef enum { * a valid commit. No merge can be performed, but the caller may wish * to simply set HEAD to the target commit(s). */ - GIT_MERGE_ANALYSIS_UNBORN = (1 << 3), + GIT_MERGE_ANALYSIS_UNBORN = (1 << 3) } git_merge_analysis_t; /** @@ -364,7 +364,7 @@ typedef enum { * There is a `merge.ff=only` configuration setting, suggesting that * the user only wants fast-forward merges. */ - GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY = (1 << 1), + GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY = (1 << 1) } git_merge_preference_t; /** diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h index c593bac26..5ad777b17 100644 --- a/include/git2/odb_backend.h +++ b/include/git2/odb_backend.h @@ -71,7 +71,7 @@ GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *inde typedef enum { GIT_STREAM_RDONLY = (1 << 1), GIT_STREAM_WRONLY = (1 << 2), - GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY), + GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY) } git_odb_stream_t; /** diff --git a/include/git2/pack.h b/include/git2/pack.h index 3b9beb665..cd28a4f5b 100644 --- a/include/git2/pack.h +++ b/include/git2/pack.h @@ -51,7 +51,7 @@ GIT_BEGIN_DECL */ typedef enum { GIT_PACKBUILDER_ADDING_OBJECTS = 0, - GIT_PACKBUILDER_DELTAFICATION = 1, + GIT_PACKBUILDER_DELTAFICATION = 1 } git_packbuilder_stage_t; /** diff --git a/include/git2/pathspec.h b/include/git2/pathspec.h index 329965789..acbd5cd1d 100644 --- a/include/git2/pathspec.h +++ b/include/git2/pathspec.h @@ -69,7 +69,7 @@ typedef enum { * just test if there were any matches at all or in combination with * GIT_PATHSPEC_FIND_FAILURES to validate a pathspec. */ - GIT_PATHSPEC_FAILURES_ONLY = (1u << 5), + GIT_PATHSPEC_FAILURES_ONLY = (1u << 5) } git_pathspec_flag_t; /** diff --git a/include/git2/proxy.h b/include/git2/proxy.h index 653425dee..cfc0c645f 100644 --- a/include/git2/proxy.h +++ b/include/git2/proxy.h @@ -32,7 +32,7 @@ typedef enum { /** * Connect via the URL given in the options */ - GIT_PROXY_SPECIFIED, + GIT_PROXY_SPECIFIED } git_proxy_t; /** diff --git a/include/git2/rebase.h b/include/git2/rebase.h index 11e452cbf..2a5dece7c 100644 --- a/include/git2/rebase.h +++ b/include/git2/rebase.h @@ -152,7 +152,7 @@ typedef enum { * No commit will be cherry-picked. The client should run the given * command and (if successful) continue. */ - GIT_REBASE_OPERATION_EXEC, + GIT_REBASE_OPERATION_EXEC } git_rebase_operation_t; #define GIT_REBASE_OPTIONS_VERSION 1 diff --git a/include/git2/refs.h b/include/git2/refs.h index 7ebb209b2..3a0095bb6 100644 --- a/include/git2/refs.h +++ b/include/git2/refs.h @@ -686,7 +686,7 @@ typedef enum { * so the `ONELEVEL` naming rules aren't enforced and 'master' * becomes a valid name. */ - GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND = (1u << 2), + GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND = (1u << 2) } git_reference_format_t; /** diff --git a/include/git2/remote.h b/include/git2/remote.h index 4d57eaaf7..088f528a6 100644 --- a/include/git2/remote.h +++ b/include/git2/remote.h @@ -49,7 +49,7 @@ typedef enum { GIT_REMOTE_CREATE_SKIP_INSTEADOF = (1 << 0), /** Don't build a fetchspec from the name if none is set */ - GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC = (1 << 1), + GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC = (1 << 1) } git_remote_create_flags; /** @@ -443,7 +443,7 @@ GIT_EXTERN(int) git_remote_list(git_strarray *out, git_repository *repo); typedef enum git_remote_completion_t { GIT_REMOTE_COMPLETION_DOWNLOAD, GIT_REMOTE_COMPLETION_INDEXING, - GIT_REMOTE_COMPLETION_ERROR, + GIT_REMOTE_COMPLETION_ERROR } git_remote_completion_t; /** Push network progress notification function */ @@ -665,7 +665,7 @@ typedef enum { /** * Force pruning off */ - GIT_FETCH_NO_PRUNE, + GIT_FETCH_NO_PRUNE } git_fetch_prune_t; /** @@ -690,7 +690,7 @@ typedef enum { /** * Ask for the all the tags. */ - GIT_REMOTE_DOWNLOAD_TAGS_ALL, + GIT_REMOTE_DOWNLOAD_TAGS_ALL } git_remote_autotag_option_t; /** diff --git a/include/git2/repository.h b/include/git2/repository.h index 8d1cffc9b..8bd877be4 100644 --- a/include/git2/repository.h +++ b/include/git2/repository.h @@ -141,7 +141,7 @@ typedef enum { * `git_repository_open_ext` with this flag will error out if either * $GIT_WORK_TREE or $GIT_COMMON_DIR is set. */ - GIT_REPOSITORY_OPEN_FROM_ENV = (1 << 4), + GIT_REPOSITORY_OPEN_FROM_ENV = (1 << 4) } git_repository_open_flag_t; /** @@ -267,7 +267,7 @@ typedef enum { * If an alternate workdir is specified, use relative paths for the gitdir * and core.worktree. */ - GIT_REPOSITORY_INIT_RELATIVE_GITLINK = (1u << 6), + GIT_REPOSITORY_INIT_RELATIVE_GITLINK = (1u << 6) } git_repository_init_flag_t; /** @@ -292,7 +292,7 @@ typedef enum { /** * Use "--shared=all" behavior, adding world readability. */ - GIT_REPOSITORY_INIT_SHARED_ALL = 0002777, + GIT_REPOSITORY_INIT_SHARED_ALL = 0002777 } git_repository_init_mode_t; /** @@ -876,7 +876,7 @@ typedef enum { GIT_REPOSITORY_STATE_REBASE_INTERACTIVE, GIT_REPOSITORY_STATE_REBASE_MERGE, GIT_REPOSITORY_STATE_APPLY_MAILBOX, - GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE, + GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE } git_repository_state_t; /** diff --git a/include/git2/reset.h b/include/git2/reset.h index be2541433..7a471bdd0 100644 --- a/include/git2/reset.h +++ b/include/git2/reset.h @@ -26,7 +26,7 @@ GIT_BEGIN_DECL typedef enum { GIT_RESET_SOFT = 1, /**< Move the head to the given commit */ GIT_RESET_MIXED = 2, /**< SOFT plus reset index to the commit */ - GIT_RESET_HARD = 3, /**< MIXED plus changes in working tree discarded */ + GIT_RESET_HARD = 3 /**< MIXED plus changes in working tree discarded */ } git_reset_t; /** diff --git a/include/git2/revparse.h b/include/git2/revparse.h index e14ddee96..51ea2dc13 100644 --- a/include/git2/revparse.h +++ b/include/git2/revparse.h @@ -74,7 +74,7 @@ typedef enum { /** The spec targeted a range of commits. */ GIT_REVSPEC_RANGE = 1 << 1, /** The spec used the '...' operator, which invokes special semantics. */ - GIT_REVSPEC_MERGE_BASE = 1 << 2, + GIT_REVSPEC_MERGE_BASE = 1 << 2 } git_revspec_t; /** diff --git a/include/git2/revwalk.h b/include/git2/revwalk.h index 98dcbf8d1..241479d56 100644 --- a/include/git2/revwalk.h +++ b/include/git2/revwalk.h @@ -49,7 +49,7 @@ typedef enum { * order; this sorting mode can be combined with * any of the above. */ - GIT_SORT_REVERSE = 1 << 2, + GIT_SORT_REVERSE = 1 << 2 } git_sort_t; /** diff --git a/include/git2/stash.h b/include/git2/stash.h index 795920ebc..32e6f9576 100644 --- a/include/git2/stash.h +++ b/include/git2/stash.h @@ -44,7 +44,7 @@ typedef enum { * All ignored files are also stashed and then cleaned up from * the working directory */ - GIT_STASH_INCLUDE_IGNORED = (1 << 2), + GIT_STASH_INCLUDE_IGNORED = (1 << 2) } git_stash_flags; /** @@ -78,7 +78,7 @@ typedef enum { /* Try to reinstate not only the working tree's changes, * but also the index's changes. */ - GIT_STASH_APPLY_REINSTATE_INDEX = (1 << 0), + GIT_STASH_APPLY_REINSTATE_INDEX = (1 << 0) } git_stash_apply_flags; /** Stash apply progression states */ @@ -104,7 +104,7 @@ typedef enum { GIT_STASH_APPLY_PROGRESS_CHECKOUT_MODIFIED, /** The stash was applied successfully. */ - GIT_STASH_APPLY_PROGRESS_DONE, + GIT_STASH_APPLY_PROGRESS_DONE } git_stash_apply_progress_t; /** diff --git a/include/git2/status.h b/include/git2/status.h index 543e3faa8..526df6399 100644 --- a/include/git2/status.h +++ b/include/git2/status.h @@ -48,7 +48,7 @@ typedef enum { GIT_STATUS_WT_UNREADABLE = (1u << 12), GIT_STATUS_IGNORED = (1u << 14), - GIT_STATUS_CONFLICTED = (1u << 15), + GIT_STATUS_CONFLICTED = (1u << 15) } git_status_t; /** @@ -87,7 +87,7 @@ typedef enum { * Only gives status based on index to working directory comparison, * not comparing the index to the HEAD. */ - GIT_STATUS_SHOW_WORKDIR_ONLY = 2, + GIT_STATUS_SHOW_WORKDIR_ONLY = 2 } git_status_show_t; /** @@ -204,7 +204,7 @@ typedef enum { * Unreadable files will be detected and given the status * untracked instead of unreadable. */ - GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED = (1u << 15), + GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED = (1u << 15) } git_status_opt_t; #define GIT_STATUS_OPT_DEFAULTS \ diff --git a/include/git2/submodule.h b/include/git2/submodule.h index 29d8bc1ce..c6eeb96dc 100644 --- a/include/git2/submodule.h +++ b/include/git2/submodule.h @@ -85,7 +85,7 @@ typedef enum { GIT_SUBMODULE_STATUS_WD_MODIFIED = (1u << 10), GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED = (1u << 11), GIT_SUBMODULE_STATUS_WD_WD_MODIFIED = (1u << 12), - GIT_SUBMODULE_STATUS_WD_UNTRACKED = (1u << 13), + GIT_SUBMODULE_STATUS_WD_UNTRACKED = (1u << 13) } git_submodule_status_t; #define GIT_SUBMODULE_STATUS__IN_FLAGS 0x000Fu diff --git a/include/git2/sys/commit_graph.h b/include/git2/sys/commit_graph.h index f6c0fc4b5..823c7ed57 100644 --- a/include/git2/sys/commit_graph.h +++ b/include/git2/sys/commit_graph.h @@ -94,7 +94,7 @@ typedef enum { * Do not split commit-graph files. The other split strategy-related option * fields are ignored. */ - GIT_COMMIT_GRAPH_SPLIT_STRATEGY_SINGLE_FILE = 0, + GIT_COMMIT_GRAPH_SPLIT_STRATEGY_SINGLE_FILE = 0 } git_commit_graph_split_strategy_t; /** diff --git a/include/git2/sys/stream.h b/include/git2/sys/stream.h index 6f93cc48c..e0e03a2d7 100644 --- a/include/git2/sys/stream.h +++ b/include/git2/sys/stream.h @@ -79,7 +79,7 @@ typedef enum { GIT_STREAM_STANDARD = 1, /** A TLS-encrypted socket. */ - GIT_STREAM_TLS = 2, + GIT_STREAM_TLS = 2 } git_stream_t; /** diff --git a/include/git2/sys/transport.h b/include/git2/sys/transport.h index fee34544f..76003ee84 100644 --- a/include/git2/sys/transport.h +++ b/include/git2/sys/transport.h @@ -30,7 +30,7 @@ GIT_BEGIN_DECL * Currently unused. */ typedef enum { - GIT_TRANSPORTFLAGS_NONE = 0, + GIT_TRANSPORTFLAGS_NONE = 0 } git_transport_flags_t; struct git_transport { @@ -289,7 +289,7 @@ typedef enum { GIT_SERVICE_UPLOADPACK_LS = 1, GIT_SERVICE_UPLOADPACK = 2, GIT_SERVICE_RECEIVEPACK_LS = 3, - GIT_SERVICE_RECEIVEPACK = 4, + GIT_SERVICE_RECEIVEPACK = 4 } git_smart_service_t; typedef struct git_smart_subtransport git_smart_subtransport; diff --git a/include/git2/tree.h b/include/git2/tree.h index f2289fc7e..db24bf6ed 100644 --- a/include/git2/tree.h +++ b/include/git2/tree.h @@ -386,7 +386,7 @@ typedef int GIT_CALLBACK(git_treewalk_cb)( /** Tree traversal modes */ typedef enum { GIT_TREEWALK_PRE = 0, /* Pre-order */ - GIT_TREEWALK_POST = 1, /* Post-order */ + GIT_TREEWALK_POST = 1 /* Post-order */ } git_treewalk_mode; /** @@ -428,7 +428,7 @@ typedef enum { /** Update or insert an entry at the specified path */ GIT_TREE_UPDATE_UPSERT, /** Remove an entry from the specified path */ - GIT_TREE_UPDATE_REMOVE, + GIT_TREE_UPDATE_REMOVE } git_tree_update_t; /** diff --git a/include/git2/types.h b/include/git2/types.h index aac8e42e2..34d8c99ef 100644 --- a/include/git2/types.h +++ b/include/git2/types.h @@ -78,7 +78,7 @@ typedef enum { GIT_OBJECT_BLOB = 3, /**< A file revision object. */ GIT_OBJECT_TAG = 4, /**< An annotated tag object. */ GIT_OBJECT_OFS_DELTA = 6, /**< A delta, base is given by an offset. */ - GIT_OBJECT_REF_DELTA = 7, /**< A delta, base is given by object id. */ + GIT_OBJECT_REF_DELTA = 7 /**< A delta, base is given by object id. */ } git_object_t; /** An open object database handle. */ @@ -208,14 +208,14 @@ typedef enum { GIT_REFERENCE_INVALID = 0, /**< Invalid reference */ GIT_REFERENCE_DIRECT = 1, /**< A reference that points at an object id */ GIT_REFERENCE_SYMBOLIC = 2, /**< A reference that points at another reference */ - GIT_REFERENCE_ALL = GIT_REFERENCE_DIRECT | GIT_REFERENCE_SYMBOLIC, + GIT_REFERENCE_ALL = GIT_REFERENCE_DIRECT | GIT_REFERENCE_SYMBOLIC } git_reference_t; /** Basic type of any Git branch. */ typedef enum { GIT_BRANCH_LOCAL = 1, GIT_BRANCH_REMOTE = 2, - GIT_BRANCH_ALL = GIT_BRANCH_LOCAL|GIT_BRANCH_REMOTE, + GIT_BRANCH_ALL = GIT_BRANCH_LOCAL|GIT_BRANCH_REMOTE } git_branch_t; /** Valid modes for index and tree entries. */ @@ -225,7 +225,7 @@ typedef enum { GIT_FILEMODE_BLOB = 0100644, GIT_FILEMODE_BLOB_EXECUTABLE = 0100755, GIT_FILEMODE_LINK = 0120000, - GIT_FILEMODE_COMMIT = 0160000, + GIT_FILEMODE_COMMIT = 0160000 } git_filemode_t; /** @@ -334,7 +334,7 @@ typedef enum { GIT_SUBMODULE_IGNORE_NONE = 1, /**< any change or untracked == dirty */ GIT_SUBMODULE_IGNORE_UNTRACKED = 2, /**< dirty if tracked files change */ GIT_SUBMODULE_IGNORE_DIRTY = 3, /**< only dirty if HEAD moved */ - GIT_SUBMODULE_IGNORE_ALL = 4, /**< never dirty */ + GIT_SUBMODULE_IGNORE_ALL = 4 /**< never dirty */ } git_submodule_ignore_t; /** @@ -350,7 +350,7 @@ typedef enum { typedef enum { GIT_SUBMODULE_RECURSE_NO = 0, GIT_SUBMODULE_RECURSE_YES = 1, - GIT_SUBMODULE_RECURSE_ONDEMAND = 2, + GIT_SUBMODULE_RECURSE_ONDEMAND = 2 } git_submodule_recurse_t; typedef struct git_writestream git_writestream; diff --git a/include/git2/worktree.h b/include/git2/worktree.h index 23084d8cd..85cf1a608 100644 --- a/include/git2/worktree.h +++ b/include/git2/worktree.h @@ -185,7 +185,7 @@ typedef enum { /* Prune working tree even if it is locked */ GIT_WORKTREE_PRUNE_LOCKED = 1u << 1, /* Prune checked out working tree */ - GIT_WORKTREE_PRUNE_WORKING_TREE = 1u << 2, + GIT_WORKTREE_PRUNE_WORKING_TREE = 1u << 2 } git_worktree_prune_t; /** -- cgit v1.2.1 From 43d9f0e3fe96823d88475fd9edae07732c84dbc8 Mon Sep 17 00:00:00 2001 From: Peter Pettersson Date: Fri, 22 Oct 2021 22:39:10 +0200 Subject: ntmlclient: make enum C90 compliant by removing trailing comma --- deps/ntlmclient/ntlm.h | 8 ++++---- deps/ntlmclient/ntlmclient.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/deps/ntlmclient/ntlm.h b/deps/ntlmclient/ntlm.h index 227f5bcba..4abfd7a85 100644 --- a/deps/ntlmclient/ntlm.h +++ b/deps/ntlmclient/ntlm.h @@ -30,7 +30,7 @@ typedef enum { NTLM_STATE_CHALLENGE = 1, NTLM_STATE_RESPONSE = 2, NTLM_STATE_ERROR = 3, - NTLM_STATE_COMPLETE = 4, + NTLM_STATE_COMPLETE = 4 } ntlm_state; typedef struct { @@ -122,7 +122,7 @@ struct ntlm_client { }; typedef enum { - NTLM_ENABLE_HOSTVERSION = (1 << 31), + NTLM_ENABLE_HOSTVERSION = (1 << 31) } ntlm_client_internal_flags; typedef enum { @@ -130,7 +130,7 @@ typedef enum { NTLM_TARGET_INFO_SERVER = 1, NTLM_TARGET_INFO_DOMAIN = 2, NTLM_TARGET_INFO_SERVER_DNS = 3, - NTLM_TARGET_INFO_DOMAIN_DNS = 4, + NTLM_TARGET_INFO_DOMAIN_DNS = 4 } ntlm_target_info_type_t; typedef enum { @@ -168,7 +168,7 @@ typedef enum { NTLM_NEGOTIATE_TARGET_INFO = 0x00800000, /* Version information should be provided */ - NTLM_NEGOTIATE_VERSION = 0x01000000, + NTLM_NEGOTIATE_VERSION = 0x01000000 } ntlm_negotiate_t; extern int ntlm_client_set_nonce(ntlm_client *ntlm, uint64_t nonce); diff --git a/deps/ntlmclient/ntlmclient.h b/deps/ntlmclient/ntlmclient.h index bf57b17c6..958b27e62 100644 --- a/deps/ntlmclient/ntlmclient.h +++ b/deps/ntlmclient/ntlmclient.h @@ -32,7 +32,7 @@ typedef enum { /** * The input provided to the function is missing or invalid. */ - NTLM_CLIENT_ERROR_INVALID_INPUT = -2, + NTLM_CLIENT_ERROR_INVALID_INPUT = -2 } ntlm_error_code; /* @@ -98,7 +98,7 @@ typedef enum { * its idea of its hostname in the challenge message. You may * then set the authentication target based on it. */ - NTLM_CLIENT_DISABLE_REQUEST_TARGET = (1 << 4), + NTLM_CLIENT_DISABLE_REQUEST_TARGET = (1 << 4) } ntlm_client_flags; -- cgit v1.2.1 From 7dcc29fc4652caeb09de39827cfd1a80726b5995 Mon Sep 17 00:00:00 2001 From: Peter Pettersson Date: Fri, 22 Oct 2021 22:51:59 +0200 Subject: Make enum in src,tests and examples C90 compliant by removing trailing comma. --- examples/add.c | 2 +- examples/remote.c | 2 +- examples/status.c | 2 +- src/annotated_commit.h | 2 +- src/checkout.c | 2 +- src/commit.h | 2 +- src/commit_graph.c | 2 +- src/crlf.c | 2 +- src/diff.h | 2 +- src/diff_driver.c | 2 +- src/diff_generate.h | 4 ++-- src/futils.h | 6 +++--- src/ignore.h | 2 +- src/index.c | 2 +- src/iterator.c | 2 +- src/iterator.h | 4 ++-- src/merge.h | 6 +++--- src/netops.h | 2 +- src/odb.h | 2 +- src/patch_generate.h | 2 +- src/patch_parse.c | 2 +- src/pathspec.h | 2 +- src/pqueue.h | 2 +- src/rebase.c | 2 +- src/refdb_fs.c | 2 +- src/repository.h | 4 ++-- src/submodule.c | 2 +- src/submodule.h | 2 +- src/sysdir.h | 2 +- src/trailer.c | 2 +- src/transaction.c | 2 +- src/transports/auth.h | 2 +- src/transports/smart.h | 2 +- src/transports/winhttp.c | 2 +- src/vector.h | 2 +- src/zstream.h | 2 +- tests/clar.h | 6 +++--- 37 files changed, 46 insertions(+), 46 deletions(-) diff --git a/examples/add.c b/examples/add.c index 4ff7c79e2..1c93b1140 100644 --- a/examples/add.c +++ b/examples/add.c @@ -28,7 +28,7 @@ enum index_mode { INDEX_NONE, - INDEX_ADD, + INDEX_ADD }; struct index_options { diff --git a/examples/remote.c b/examples/remote.c index 57f758c6c..14fac030c 100644 --- a/examples/remote.c +++ b/examples/remote.c @@ -27,7 +27,7 @@ enum subcmd { subcmd_remove, subcmd_rename, subcmd_seturl, - subcmd_show, + subcmd_show }; struct remote_opts { diff --git a/examples/status.c b/examples/status.c index 8cf922127..e659efb05 100644 --- a/examples/status.c +++ b/examples/status.c @@ -38,7 +38,7 @@ enum { FORMAT_DEFAULT = 0, FORMAT_LONG = 1, FORMAT_SHORT = 2, - FORMAT_PORCELAIN = 3, + FORMAT_PORCELAIN = 3 }; #define MAX_PATHSPEC 8 diff --git a/src/annotated_commit.h b/src/annotated_commit.h index b390066b2..444a2ed10 100644 --- a/src/annotated_commit.h +++ b/src/annotated_commit.h @@ -15,7 +15,7 @@ typedef enum { GIT_ANNOTATED_COMMIT_REAL = 1, - GIT_ANNOTATED_COMMIT_VIRTUAL = 2, + GIT_ANNOTATED_COMMIT_VIRTUAL = 2 } git_annotated_commit_t; /** diff --git a/src/checkout.c b/src/checkout.c index 5733f4ab5..11be2e84f 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -45,7 +45,7 @@ enum { CHECKOUT_ACTION__UPDATE_CONFLICT = 32, CHECKOUT_ACTION__MAX = 32, CHECKOUT_ACTION__REMOVE_AND_UPDATE = - (CHECKOUT_ACTION__UPDATE_BLOB | CHECKOUT_ACTION__REMOVE), + (CHECKOUT_ACTION__UPDATE_BLOB | CHECKOUT_ACTION__REMOVE) }; typedef struct { diff --git a/src/commit.h b/src/commit.h index 9378eab2d..7a2454e61 100644 --- a/src/commit.h +++ b/src/commit.h @@ -61,7 +61,7 @@ int git_commit__parse(void *commit, git_odb_object *obj); int git_commit__parse_raw(void *commit, const char *data, size_t size); typedef enum { - GIT_COMMIT_PARSE_QUICK = (1 << 0), /**< Only parse parents and committer info */ + GIT_COMMIT_PARSE_QUICK = (1 << 0) /**< Only parse parents and committer info */ } git_commit__parse_flags; int git_commit__parse_ext(git_commit *commit, git_odb_object *odb_obj, unsigned int flags); diff --git a/src/commit_graph.c b/src/commit_graph.c index f9a4bd2b2..924a3992b 100644 --- a/src/commit_graph.c +++ b/src/commit_graph.c @@ -754,7 +754,7 @@ enum generation_number_commit_state { GENERATION_NUMBER_COMMIT_STATE_UNVISITED = 0, GENERATION_NUMBER_COMMIT_STATE_ADDED = 1, GENERATION_NUMBER_COMMIT_STATE_EXPANDED = 2, - GENERATION_NUMBER_COMMIT_STATE_VISITED = 3, + GENERATION_NUMBER_COMMIT_STATE_VISITED = 3 }; static int compute_generation_numbers(git_vector *commits) diff --git a/src/crlf.c b/src/crlf.c index 7895ddec2..1e1f1e845 100644 --- a/src/crlf.c +++ b/src/crlf.c @@ -26,7 +26,7 @@ typedef enum { GIT_CRLF_TEXT_CRLF, GIT_CRLF_AUTO, GIT_CRLF_AUTO_INPUT, - GIT_CRLF_AUTO_CRLF, + GIT_CRLF_AUTO_CRLF } git_crlf_t; struct crlf_attrs { diff --git a/src/diff.h b/src/diff.h index 4b0339809..2cc35e65b 100644 --- a/src/diff.h +++ b/src/diff.h @@ -26,7 +26,7 @@ typedef enum { GIT_DIFF_TYPE_UNKNOWN = 0, GIT_DIFF_TYPE_GENERATED = 1, - GIT_DIFF_TYPE_PARSED = 2, + GIT_DIFF_TYPE_PARSED = 2 } git_diff_origin_t; struct git_diff { diff --git a/src/diff_driver.c b/src/diff_driver.c index f6b51d8ba..a20723fcc 100644 --- a/src/diff_driver.c +++ b/src/diff_driver.c @@ -21,7 +21,7 @@ typedef enum { DIFF_DRIVER_AUTO = 0, DIFF_DRIVER_BINARY = 1, DIFF_DRIVER_TEXT = 2, - DIFF_DRIVER_PATTERNLIST = 3, + DIFF_DRIVER_PATTERNLIST = 3 } git_diff_driver_t; typedef struct { diff --git a/src/diff_generate.h b/src/diff_generate.h index 5186d552c..f39bf6b2a 100644 --- a/src/diff_generate.h +++ b/src/diff_generate.h @@ -18,7 +18,7 @@ enum { GIT_DIFFCAPS_IGNORE_STAT = (1 << 1), /* use stat? */ GIT_DIFFCAPS_TRUST_MODE_BITS = (1 << 2), /* use st_mode? */ GIT_DIFFCAPS_TRUST_CTIME = (1 << 3), /* use st_ctime? */ - GIT_DIFFCAPS_USE_DEV = (1 << 4), /* use st_dev? */ + GIT_DIFFCAPS_USE_DEV = (1 << 4) /* use st_dev? */ }; #define DIFF_FLAGS_KNOWN_BINARY (GIT_DIFF_FLAG_BINARY|GIT_DIFF_FLAG_NOT_BINARY) @@ -36,7 +36,7 @@ enum { GIT_DIFF_FLAG__TO_SPLIT = (1 << 17), /* split entry during rename det. */ GIT_DIFF_FLAG__IS_RENAME_TARGET = (1 << 18), GIT_DIFF_FLAG__IS_RENAME_SOURCE = (1 << 19), - GIT_DIFF_FLAG__HAS_SELF_SIMILARITY = (1 << 20), + GIT_DIFF_FLAG__HAS_SELF_SIMILARITY = (1 << 20) }; #define GIT_DIFF_FLAG__CLEAR_INTERNAL(F) (F) = ((F) & 0x00FFFF) diff --git a/src/futils.h b/src/futils.h index 22098addf..1386dc482 100644 --- a/src/futils.h +++ b/src/futils.h @@ -96,7 +96,7 @@ typedef enum { GIT_MKDIR_SKIP_LAST2 = 32, GIT_MKDIR_VERIFY_DIR = 64, GIT_MKDIR_REMOVE_FILES = 128, - GIT_MKDIR_REMOVE_SYMLINKS = 256, + GIT_MKDIR_REMOVE_SYMLINKS = 256 } git_futils_mkdir_flags; struct git_futils_mkdir_perfdata @@ -159,7 +159,7 @@ typedef enum { GIT_RMDIR_SKIP_NONEMPTY = (1 << 1), GIT_RMDIR_EMPTY_PARENTS = (1 << 2), GIT_RMDIR_REMOVE_BLOCKERS = (1 << 3), - GIT_RMDIR_SKIP_ROOT = (1 << 4), + GIT_RMDIR_SKIP_ROOT = (1 << 4) } git_futils_rmdir_flags; /** @@ -224,7 +224,7 @@ typedef enum { GIT_CPDIR_OVERWRITE = (1u << 3), GIT_CPDIR_CHMOD_DIRS = (1u << 4), GIT_CPDIR_SIMPLE_TO_MODE = (1u << 5), - GIT_CPDIR_LINK_FILES = (1u << 6), + GIT_CPDIR_LINK_FILES = (1u << 6) } git_futils_cpdir_flags; /** diff --git a/src/ignore.h b/src/ignore.h index 799195258..aa5ca62b7 100644 --- a/src/ignore.h +++ b/src/ignore.h @@ -48,7 +48,7 @@ enum { GIT_IGNORE_UNCHECKED = -2, GIT_IGNORE_NOTFOUND = -1, GIT_IGNORE_FALSE = 0, - GIT_IGNORE_TRUE = 1, + GIT_IGNORE_TRUE = 1 }; extern int git_ignore__lookup(int *out, git_ignores *ign, const char *path, git_dir_flag dir_flag); diff --git a/src/index.c b/src/index.c index bd6ea8f03..7ade4341f 100644 --- a/src/index.c +++ b/src/index.c @@ -3386,7 +3386,7 @@ enum { INDEX_ACTION_NONE = 0, INDEX_ACTION_UPDATE = 1, INDEX_ACTION_REMOVE = 2, - INDEX_ACTION_ADDALL = 3, + INDEX_ACTION_ADDALL = 3 }; int git_index_add_all( diff --git a/src/iterator.c b/src/iterator.c index a4337bb9a..15bb63dc8 100644 --- a/src/iterator.c +++ b/src/iterator.c @@ -293,7 +293,7 @@ typedef enum { ITERATOR_PATHLIST_IS_FILE = 1, ITERATOR_PATHLIST_IS_DIR = 2, ITERATOR_PATHLIST_IS_PARENT = 3, - ITERATOR_PATHLIST_FULL = 4, + ITERATOR_PATHLIST_FULL = 4 } iterator_pathlist_search_t; static iterator_pathlist_search_t iterator_pathlist_search( diff --git a/src/iterator.h b/src/iterator.h index e55c1047a..6bb8489d0 100644 --- a/src/iterator.h +++ b/src/iterator.h @@ -21,7 +21,7 @@ typedef enum { GIT_ITERATOR_TREE = 1, GIT_ITERATOR_INDEX = 2, GIT_ITERATOR_WORKDIR = 3, - GIT_ITERATOR_FS = 4, + GIT_ITERATOR_FS = 4 } git_iterator_t; typedef enum { @@ -42,7 +42,7 @@ typedef enum { /** descend into symlinked directories */ GIT_ITERATOR_DESCEND_SYMLINKS = (1u << 7), /** hash files in workdir or filesystem iterators */ - GIT_ITERATOR_INCLUDE_HASH = (1u << 8), + GIT_ITERATOR_INCLUDE_HASH = (1u << 8) } git_iterator_flag_t; typedef enum { diff --git a/src/merge.h b/src/merge.h index 3e7f80c6e..632f2d8e3 100644 --- a/src/merge.h +++ b/src/merge.h @@ -29,12 +29,12 @@ /** Internal merge flags. */ enum { /** The merge is for a virtual base in a recursive merge. */ - GIT_MERGE__VIRTUAL_BASE = (1 << 31), + GIT_MERGE__VIRTUAL_BASE = (1 << 31) }; enum { /** Accept the conflict file, staging it as the merge result. */ - GIT_MERGE_FILE_FAVOR__CONFLICTED = 4, + GIT_MERGE_FILE_FAVOR__CONFLICTED = 4 }; @@ -83,7 +83,7 @@ typedef enum { GIT_MERGE_DIFF_DIRECTORY_FILE = (1 << 10), /* The child of a folder that is in a directory/file conflict. */ - GIT_MERGE_DIFF_DF_CHILD = (1 << 11), + GIT_MERGE_DIFF_DF_CHILD = (1 << 11) } git_merge_diff_t; typedef struct { diff --git a/src/netops.h b/src/netops.h index 7140b39bc..56f968534 100644 --- a/src/netops.h +++ b/src/netops.h @@ -42,7 +42,7 @@ typedef struct gitno_buffer { /* Flags to gitno_connect */ enum { /* Attempt to create an SSL connection. */ - GITNO_CONNECT_SSL = 1, + GITNO_CONNECT_SSL = 1 }; /** diff --git a/src/odb.h b/src/odb.h index 4a8ebff19..5aa4cc84a 100644 --- a/src/odb.h +++ b/src/odb.h @@ -53,7 +53,7 @@ struct git_odb { }; typedef enum { - GIT_ODB_CAP_FROM_OWNER = -1, + GIT_ODB_CAP_FROM_OWNER = -1 } git_odb_cap_t; /* diff --git a/src/patch_generate.h b/src/patch_generate.h index 20f78cbfa..0e09d27ca 100644 --- a/src/patch_generate.h +++ b/src/patch_generate.h @@ -21,7 +21,7 @@ enum { GIT_PATCH_GENERATED_DIFFABLE = (1 << 3), /* the difference between the two sides has been computed */ GIT_PATCH_GENERATED_DIFFED = (1 << 4), - GIT_PATCH_GENERATED_FLATTENED = (1 << 5), + GIT_PATCH_GENERATED_FLATTENED = (1 << 5) }; struct git_patch_generated { diff --git a/src/patch_parse.c b/src/patch_parse.c index 891cf79a3..37822fccc 100644 --- a/src/patch_parse.c +++ b/src/patch_parse.c @@ -382,7 +382,7 @@ typedef enum { STATE_RENAME, STATE_COPY, - STATE_END, + STATE_END } parse_header_state; typedef struct { diff --git a/src/pathspec.h b/src/pathspec.h index bfdcd48a7..0256cb927 100644 --- a/src/pathspec.h +++ b/src/pathspec.h @@ -25,7 +25,7 @@ struct git_pathspec { enum { PATHSPEC_DATATYPE_STRINGS = 0, - PATHSPEC_DATATYPE_DIFF = 1, + PATHSPEC_DATATYPE_DIFF = 1 }; typedef git_array_t(char *) git_pathspec_string_array_t; diff --git a/src/pqueue.h b/src/pqueue.h index c0a6cd49e..4db74ea03 100644 --- a/src/pqueue.h +++ b/src/pqueue.h @@ -15,7 +15,7 @@ typedef git_vector git_pqueue; enum { /* flag meaning: don't grow heap, keep highest values only */ - GIT_PQUEUE_FIXED_SIZE = (GIT_VECTOR_FLAG_MAX << 1), + GIT_PQUEUE_FIXED_SIZE = (GIT_VECTOR_FLAG_MAX << 1) }; /** diff --git a/src/rebase.c b/src/rebase.c index 26b03b38c..4ad37643b 100644 --- a/src/rebase.c +++ b/src/rebase.c @@ -53,7 +53,7 @@ typedef enum { GIT_REBASE_NONE = 0, GIT_REBASE_APPLY = 1, GIT_REBASE_MERGE = 2, - GIT_REBASE_INTERACTIVE = 3, + GIT_REBASE_INTERACTIVE = 3 } git_rebase_t; struct git_rebase { diff --git a/src/refdb_fs.c b/src/refdb_fs.c index 097d2b38e..055ca2559 100644 --- a/src/refdb_fs.c +++ b/src/refdb_fs.c @@ -35,7 +35,7 @@ enum { PACKREF_HAS_PEEL = 1, PACKREF_WAS_LOOSE = 2, PACKREF_CANNOT_PEEL = 4, - PACKREF_SHADOWED = 8, + PACKREF_SHADOWED = 8 }; enum { diff --git a/src/repository.h b/src/repository.h index 1ea5a44f7..3c3aa1e8e 100644 --- a/src/repository.h +++ b/src/repository.h @@ -118,14 +118,14 @@ typedef enum { /* core.fsyncObjectFiles */ GIT_FSYNCOBJECTFILES_DEFAULT = GIT_CONFIGMAP_FALSE, /* core.longpaths */ - GIT_LONGPATHS_DEFAULT = GIT_CONFIGMAP_FALSE, + GIT_LONGPATHS_DEFAULT = GIT_CONFIGMAP_FALSE } git_configmap_value; /* internal repository init flags */ enum { GIT_REPOSITORY_INIT__HAS_DOTGIT = (1u << 16), GIT_REPOSITORY_INIT__NATURAL_WD = (1u << 17), - GIT_REPOSITORY_INIT__IS_REINIT = (1u << 18), + GIT_REPOSITORY_INIT__IS_REINIT = (1u << 18) }; /** Internal structure for repository object */ diff --git a/src/submodule.c b/src/submodule.c index 0370ac82b..0f4f0726c 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -61,7 +61,7 @@ enum { }; enum { GITMODULES_EXISTING = 0, - GITMODULES_CREATE = 1, + GITMODULES_CREATE = 1 }; static int submodule_alloc(git_submodule **out, git_repository *repo, const char *name); diff --git a/src/submodule.h b/src/submodule.h index b01ff68a2..7fa982486 100644 --- a/src/submodule.h +++ b/src/submodule.h @@ -110,7 +110,7 @@ enum { GIT_SUBMODULE_STATUS__HEAD_NOT_SUBMODULE = (1u << 24), GIT_SUBMODULE_STATUS__INDEX_NOT_SUBMODULE = (1u << 25), GIT_SUBMODULE_STATUS__WD_NOT_SUBMODULE = (1u << 26), - GIT_SUBMODULE_STATUS__INDEX_MULTIPLE_ENTRIES = (1u << 27), + GIT_SUBMODULE_STATUS__INDEX_MULTIPLE_ENTRIES = (1u << 27) }; #define GIT_SUBMODULE_STATUS__CLEAR_INTERNAL(S) \ diff --git a/src/sysdir.h b/src/sysdir.h index d12bac9d9..43392a022 100644 --- a/src/sysdir.h +++ b/src/sysdir.h @@ -74,7 +74,7 @@ typedef enum { GIT_SYSDIR_XDG = 2, GIT_SYSDIR_PROGRAMDATA = 3, GIT_SYSDIR_TEMPLATE = 4, - GIT_SYSDIR__MAX = 5, + GIT_SYSDIR__MAX = 5 } git_sysdir_t; /** diff --git a/src/trailer.c b/src/trailer.c index 61cdd1ba1..4761c9922 100644 --- a/src/trailer.c +++ b/src/trailer.c @@ -286,7 +286,7 @@ enum trailer_state { S_VALUE = 4, S_VALUE_NL = 5, S_VALUE_END = 6, - S_IGNORE = 7, + S_IGNORE = 7 }; #define NEXT(st) { state = (st); ptr++; continue; } diff --git a/src/transaction.c b/src/transaction.c index 98fa1ba90..ccffa9984 100644 --- a/src/transaction.c +++ b/src/transaction.c @@ -23,7 +23,7 @@ typedef enum { TRANSACTION_NONE, TRANSACTION_REFS, - TRANSACTION_CONFIG, + TRANSACTION_CONFIG } transaction_t; typedef struct { diff --git a/src/transports/auth.h b/src/transports/auth.h index 824d7198c..64680cc53 100644 --- a/src/transports/auth.h +++ b/src/transports/auth.h @@ -15,7 +15,7 @@ typedef enum { GIT_HTTP_AUTH_BASIC = 1, GIT_HTTP_AUTH_NEGOTIATE = 2, - GIT_HTTP_AUTH_NTLM = 4, + GIT_HTTP_AUTH_NTLM = 4 } git_http_auth_t; typedef struct git_http_auth_context git_http_auth_context; diff --git a/src/transports/smart.h b/src/transports/smart.h index 225e64996..a9cab31ac 100644 --- a/src/transports/smart.h +++ b/src/transports/smart.h @@ -46,7 +46,7 @@ typedef enum { GIT_PKT_PROGRESS, GIT_PKT_OK, GIT_PKT_NG, - GIT_PKT_UNPACK, + GIT_PKT_UNPACK } git_pkt_type; /* Used for multi_ack and multi_ack_detailed */ diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c index efbaf0298..60f536fdb 100644 --- a/src/transports/winhttp.c +++ b/src/transports/winhttp.c @@ -99,7 +99,7 @@ typedef enum { GIT_WINHTTP_AUTH_BASIC = 1, GIT_WINHTTP_AUTH_NTLM = 2, GIT_WINHTTP_AUTH_NEGOTIATE = 4, - GIT_WINHTTP_AUTH_DIGEST = 8, + GIT_WINHTTP_AUTH_DIGEST = 8 } winhttp_authmechanism_t; typedef struct { diff --git a/src/vector.h b/src/vector.h index 3dcec3d13..ae3c79a4c 100644 --- a/src/vector.h +++ b/src/vector.h @@ -13,7 +13,7 @@ typedef int (*git_vector_cmp)(const void *, const void *); enum { GIT_VECTOR_SORTED = (1u << 0), - GIT_VECTOR_FLAG_MAX = (1u << 1), + GIT_VECTOR_FLAG_MAX = (1u << 1) }; typedef struct git_vector { diff --git a/src/zstream.h b/src/zstream.h index 3a59d9a36..3f8b1c72f 100644 --- a/src/zstream.h +++ b/src/zstream.h @@ -15,7 +15,7 @@ typedef enum { GIT_ZSTREAM_INFLATE, - GIT_ZSTREAM_DEFLATE, + GIT_ZSTREAM_DEFLATE } git_zstream_t; typedef struct { diff --git a/tests/clar.h b/tests/clar.h index 8c22382bd..3f659c2f6 100644 --- a/tests/clar.h +++ b/tests/clar.h @@ -13,12 +13,12 @@ enum cl_test_status { CL_TEST_OK, CL_TEST_FAILURE, CL_TEST_SKIP, - CL_TEST_NOTRUN, + CL_TEST_NOTRUN }; enum cl_output_format { CL_OUTPUT_CLAP, - CL_OUTPUT_TAP, + CL_OUTPUT_TAP }; /** Setup clar environment */ @@ -60,7 +60,7 @@ typedef enum cl_trace_event { CL_TRACE__TEST__END, CL_TRACE__TEST__RUN_BEGIN, CL_TRACE__TEST__RUN_END, - CL_TRACE__TEST__LONGJMP, + CL_TRACE__TEST__LONGJMP } cl_trace_event; typedef void (cl_trace_cb)( -- cgit v1.2.1 From 86685f8f1d586b0201ab51d8e5923379967f4e74 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Tue, 16 Nov 2021 17:10:08 -0500 Subject: cmake: better explain why headertests exists --- tests/CMakeLists.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d42c6ad5b..b42359a63 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -80,14 +80,19 @@ add_clar_test(proxy -v -sonline::clone::proxy) add_clar_test(auth_clone -v -sonline::clone::cred) add_clar_test(auth_clone_and_push -v -sonline::clone::push -sonline::push) -# Header file validation project +# +# Header file validation project: ensure that we do not publish any sloppy +# definitions in our headers and that a consumer can include +# even when they have aggressive C90 warnings enabled. +# + add_executable(headertest headertest.c) set_target_properties(headertest PROPERTIES C_STANDARD 90) set_target_properties(headertest PROPERTIES C_EXTENSIONS OFF) target_include_directories(headertest PRIVATE ${LIBGIT2_INCLUDES}) if (MSVC) - target_compile_options(headertest PUBLIC /W4 /WX) + target_compile_options(headertest PUBLIC /W4 /WX) else() - target_compile_options(headertest PUBLIC -Wall -Wextra -pedantic -Werror) + target_compile_options(headertest PUBLIC -Wall -Wextra -pedantic -Werror) endif() -- cgit v1.2.1 From 6b2ea90966fd090e3b134ec57b85a8adfe4b89be Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Tue, 16 Nov 2021 23:21:29 -0500 Subject: tag: set validity to 0 by default `git_tag_name_is_valid` needs to set validity to 0 when it short-circuits. --- src/tag.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tag.c b/src/tag.c index 7a155147d..837658a19 100644 --- a/src/tag.c +++ b/src/tag.c @@ -539,6 +539,8 @@ int git_tag_name_is_valid(int *valid, const char *name) GIT_ASSERT(valid); + *valid = 0; + /* * Discourage tag name starting with dash, * https://github.com/git/git/commit/4f0accd638b8d2 -- cgit v1.2.1 From 4a54d8e39e053377a877c65e897f2424b11a51e4 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 17 Nov 2021 07:27:39 -0500 Subject: cmake: enable testing at the top level Ensure that we `enable_testing()` at the top-level CMakeLists.txt or else we'll need to navigate within the build directory to the correct place in the hierarchy to run `ctest`. Now we can `ctest` at the top-level again. --- CMakeLists.txt | 1 + tests/CMakeLists.txt | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 664abc0d2..c414bbe3a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -111,6 +111,7 @@ include(DefaultCFlags) add_subdirectory(src) if(BUILD_TESTS) + enable_testing() add_subdirectory(tests) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b42359a63..84df92a45 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -68,8 +68,6 @@ function(ADD_CLAR_TEST name) endif() endfunction(ADD_CLAR_TEST) -enable_testing() - add_clar_test(offline -v -xonline) add_clar_test(invasive -v -score::ftruncate -sfilter::stream::bigfile -sodb::largefiles -siterator::workdir::filesystem_gunk -srepo::init -srepo::init::at_filesystem_root) add_clar_test(online -v -sonline -xonline::customcert) -- cgit v1.2.1 From 1b8d14ac2a31eb48665ffbf2a984399a77ea62d8 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 17 Nov 2021 08:25:56 -0500 Subject: cmake: use WINHTTP when USE_WINHTTP is specified --- cmake/SelectWinHTTP.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/SelectWinHTTP.cmake b/cmake/SelectWinHTTP.cmake index 1d950c900..667b4007e 100644 --- a/cmake/SelectWinHTTP.cmake +++ b/cmake/SelectWinHTTP.cmake @@ -1,4 +1,4 @@ -if(WIN32 AND WINHTTP) +if(WIN32 AND USE_WINHTTP) set(GIT_WINHTTP 1) # Since MinGW does not come with headers or an import library for winhttp, -- cgit v1.2.1 From b2c40314c7c8ae4b645f776f04dfe06983ad8ba3 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 18 Nov 2021 12:19:32 -0500 Subject: date: make it a proper `git_date` utility class Instead of `git__date`, just use `git_date`. --- src/date.c | 4 ++-- src/date.h | 33 +++++++++++++++++++++++++++++++++ src/email.c | 3 ++- src/revparse.c | 3 ++- src/util.h | 20 -------------------- tests/date/date.c | 6 +++--- tests/date/rfc2822.c | 10 +++++----- 7 files changed, 47 insertions(+), 32 deletions(-) create mode 100644 src/date.h diff --git a/src/date.c b/src/date.c index 2297ee66c..f7498e77f 100644 --- a/src/date.c +++ b/src/date.c @@ -857,7 +857,7 @@ static git_time_t approxidate_str(const char *date, return update_tm(&tm, &now, 0); } -int git__date_parse(git_time_t *out, const char *date) +int git_date_parse(git_time_t *out, const char *date) { time_t time_sec; git_time_t timestamp; @@ -875,7 +875,7 @@ int git__date_parse(git_time_t *out, const char *date) return error_ret; } -int git__date_rfc2822_fmt(char *out, size_t len, const git_time *date) +int git_date_rfc2822_fmt(char *out, size_t len, const git_time *date) { int written; struct tm gmt; diff --git a/src/date.h b/src/date.h new file mode 100644 index 000000000..133f20b37 --- /dev/null +++ b/src/date.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) the libgit2 contributors. All rights reserved. + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ +#ifndef INCLUDE_date_h__ +#define INCLUDE_date_h__ + +#include "util.h" +#include "str.h" + +/* + * Parse a string into a value as a git_time_t. + * + * Sample valid input: + * - "yesterday" + * - "July 17, 2003" + * - "2003-7-17 08:23" + */ +extern int git_date_parse(git_time_t *out, const char *date); + +/* + * Format a git_time as a RFC2822 string + * + * @param out buffer to store formatted date; a '\\0' terminator will automatically be added. + * @param len size of the buffer; should be atleast `GIT_DATE_RFC2822_SZ` in size; + * @param date the date to be formatted + * @return 0 if successful; -1 on error + */ +extern int git_date_rfc2822_fmt(char *out, size_t len, const git_time *date); + +#endif diff --git a/src/email.c b/src/email.c index 3459c0540..66ed2dd9f 100644 --- a/src/email.c +++ b/src/email.c @@ -12,6 +12,7 @@ #include "diff_generate.h" #include "diff_stats.h" #include "patch.h" +#include "date.h" #include "git2/email.h" #include "git2/patch.h" @@ -123,7 +124,7 @@ static int append_header( if ((error = git_oid_fmt(id, commit_id)) < 0 || (error = git_str_printf(out, "From %.*s %s\n", GIT_OID_HEXSZ, id, EMAIL_TIMESTAMP)) < 0 || (error = git_str_printf(out, "From: %s <%s>\n", author->name, author->email)) < 0 || - (error = git__date_rfc2822_fmt(date, sizeof(date), &author->when)) < 0 || + (error = git_date_rfc2822_fmt(date, sizeof(date), &author->when)) < 0 || (error = git_str_printf(out, "Date: %s\n", date)) < 0 || (error = append_subject(out, patch_idx, patch_count, summary, opts)) < 0) return error; diff --git a/src/revparse.c b/src/revparse.c index cf39936a5..52dd0720b 100644 --- a/src/revparse.c +++ b/src/revparse.c @@ -11,6 +11,7 @@ #include "tree.h" #include "refdb.h" #include "regexp.h" +#include "date.h" #include "git2.h" @@ -344,7 +345,7 @@ static int handle_at_syntax(git_object **out, git_reference **ref, const char *s goto cleanup; } - if (git__date_parse(×tamp, curly_braces_content) < 0) + if (git_date_parse(×tamp, curly_braces_content) < 0) goto cleanup; error = retrieve_revobject_from_reflog(out, ref, repo, git_str_cstr(&identifier), (size_t)timestamp); diff --git a/src/util.h b/src/util.h index 30cdd0ddf..3d6ee1207 100644 --- a/src/util.h +++ b/src/util.h @@ -294,26 +294,6 @@ GIT_INLINE(bool) git__isxdigit(int c) */ extern int git__parse_bool(int *out, const char *value); -/* - * Parse a string into a value as a git_time_t. - * - * Sample valid input: - * - "yesterday" - * - "July 17, 2003" - * - "2003-7-17 08:23" - */ -extern int git__date_parse(git_time_t *out, const char *date); - -/* - * Format a git_time as a RFC2822 string - * - * @param out buffer to store formatted date; a '\\0' terminator will automatically be added. - * @param len size of the buffer; should be atleast `GIT_DATE_RFC2822_SZ` in size; - * @param date the date to be formatted - * @return 0 if successful; -1 on error - */ -extern int git__date_rfc2822_fmt(char *out, size_t len, const git_time *date); - /* * Unescapes a string in-place. * diff --git a/tests/date/date.c b/tests/date/date.c index 88881d1e1..f70b4fea9 100644 --- a/tests/date/date.c +++ b/tests/date/date.c @@ -1,6 +1,6 @@ #include "clar_libgit2.h" -#include "util.h" +#include "date.h" void test_date_date__overflow(void) { @@ -8,8 +8,8 @@ void test_date_date__overflow(void) git_time_t d2038, d2039; /* This is expected to fail on a 32-bit machine. */ - cl_git_pass(git__date_parse(&d2038, "2038-1-1")); - cl_git_pass(git__date_parse(&d2039, "2039-1-1")); + cl_git_pass(git_date_parse(&d2038, "2038-1-1")); + cl_git_pass(git_date_parse(&d2039, "2039-1-1")); cl_assert(d2038 < d2039); #endif } diff --git a/tests/date/rfc2822.c b/tests/date/rfc2822.c index d98c1f05e..c94c8403f 100644 --- a/tests/date/rfc2822.c +++ b/tests/date/rfc2822.c @@ -1,13 +1,13 @@ #include "clar_libgit2.h" -#include "util.h" +#include "date.h" void test_date_rfc2822__format_rfc2822_no_offset(void) { git_time t = {1397031663, 0}; char buf[GIT_DATE_RFC2822_SZ]; - cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t)); + cl_git_pass(git_date_rfc2822_fmt(buf, sizeof(buf), &t)); cl_assert(strcmp(buf, "Wed, 9 Apr 2014 08:21:03 +0000") == 0); } @@ -16,7 +16,7 @@ void test_date_rfc2822__format_rfc2822_positive_offset(void) git_time t = {1397031663, 120}; char buf[GIT_DATE_RFC2822_SZ]; - cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t)); + cl_git_pass(git_date_rfc2822_fmt(buf, sizeof(buf), &t)); cl_assert(strcmp(buf, "Wed, 9 Apr 2014 10:21:03 +0200") == 0); } @@ -25,7 +25,7 @@ void test_date_rfc2822__format_rfc2822_negative_offset(void) git_time t = {1397031663, -120}; char buf[GIT_DATE_RFC2822_SZ]; - cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t)); + cl_git_pass(git_date_rfc2822_fmt(buf, sizeof(buf), &t)); cl_assert(strcmp(buf, "Wed, 9 Apr 2014 06:21:03 -0200") == 0); } @@ -35,6 +35,6 @@ void test_date_rfc2822__format_rfc2822_buffer_too_small(void) git_time t = {1397031663 + 86400, 0}; char buf[GIT_DATE_RFC2822_SZ-1]; - cl_git_fail(git__date_rfc2822_fmt(buf, sizeof(buf), &t)); + cl_git_fail(git_date_rfc2822_fmt(buf, sizeof(buf), &t)); } -- cgit v1.2.1 From add30a838867820788c871c1d034fcf68c2ad12c Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 18 Nov 2021 12:36:25 -0500 Subject: date: rfc2822 formatting uses a `git_buf` instead of a static string --- src/date.c | 20 +++++++------------- src/date.h | 8 ++++---- src/email.c | 17 ++++++++++++++--- src/util.h | 2 -- tests/date/rfc2822.c | 31 ++++++++++++++----------------- 5 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/date.c b/src/date.c index f7498e77f..52cc30824 100644 --- a/src/date.c +++ b/src/date.c @@ -13,6 +13,7 @@ #include "util.h" #include "cache.h" #include "posix.h" +#include "date.h" #include #include @@ -875,31 +876,24 @@ int git_date_parse(git_time_t *out, const char *date) return error_ret; } -int git_date_rfc2822_fmt(char *out, size_t len, const git_time *date) +int git_date_rfc2822_fmt(git_str *out, git_time_t time, int offset) { - int written; - struct tm gmt; time_t t; + struct tm gmt; GIT_ASSERT_ARG(out); - GIT_ASSERT_ARG(date); - t = (time_t) (date->time + date->offset * 60); + t = (time_t) (time + offset * 60); - if (p_gmtime_r (&t, &gmt) == NULL) + if (p_gmtime_r(&t, &gmt) == NULL) return -1; - written = p_snprintf(out, len, "%.3s, %u %.3s %.4u %02u:%02u:%02u %+03d%02d", + return git_str_printf(out, "%.3s, %u %.3s %.4u %02u:%02u:%02u %+03d%02d", weekday_names[gmt.tm_wday], gmt.tm_mday, month_names[gmt.tm_mon], gmt.tm_year + 1900, gmt.tm_hour, gmt.tm_min, gmt.tm_sec, - date->offset / 60, date->offset % 60); - - if (written < 0 || (written > (int) len - 1)) - return -1; - - return 0; + offset / 60, offset % 60); } diff --git a/src/date.h b/src/date.h index 133f20b37..7ebd3c30e 100644 --- a/src/date.h +++ b/src/date.h @@ -23,11 +23,11 @@ extern int git_date_parse(git_time_t *out, const char *date); /* * Format a git_time as a RFC2822 string * - * @param out buffer to store formatted date; a '\\0' terminator will automatically be added. - * @param len size of the buffer; should be atleast `GIT_DATE_RFC2822_SZ` in size; - * @param date the date to be formatted + * @param out buffer to store formatted date + * @param time the time to be formatted + * @param offset the timezone offset * @return 0 if successful; -1 on error */ -extern int git_date_rfc2822_fmt(char *out, size_t len, const git_time *date); +extern int git_date_rfc2822_fmt(git_str *out, git_time_t time, int offset); #endif diff --git a/src/email.c b/src/email.c index 66ed2dd9f..e19a2928c 100644 --- a/src/email.c +++ b/src/email.c @@ -73,6 +73,19 @@ static int append_prefix( return git_str_oom(out) ? -1 : 0; } +static int append_date( + git_str *out, + const git_time *date) +{ + int error; + + if ((error = git_str_printf(out, "Date: ")) == 0 && + (error = git_date_rfc2822_fmt(out, date->time, date->offset)) == 0) + error = git_str_putc(out, '\n'); + + return error; +} + static int append_subject( git_str *out, size_t patch_idx, @@ -118,14 +131,12 @@ static int append_header( git_email_create_options *opts) { char id[GIT_OID_HEXSZ]; - char date[GIT_DATE_RFC2822_SZ]; int error; if ((error = git_oid_fmt(id, commit_id)) < 0 || (error = git_str_printf(out, "From %.*s %s\n", GIT_OID_HEXSZ, id, EMAIL_TIMESTAMP)) < 0 || (error = git_str_printf(out, "From: %s <%s>\n", author->name, author->email)) < 0 || - (error = git_date_rfc2822_fmt(date, sizeof(date), &author->when)) < 0 || - (error = git_str_printf(out, "Date: %s\n", date)) < 0 || + (error = append_date(out, &author->when)) < 0 || (error = append_subject(out, patch_idx, patch_count, summary, opts)) < 0) return error; diff --git a/src/util.h b/src/util.h index 3d6ee1207..141779ade 100644 --- a/src/util.h +++ b/src/util.h @@ -37,8 +37,6 @@ # define GIT_CONTAINER_OF(ptr, type, member) (type *)(ptr) #endif -#define GIT_DATE_RFC2822_SZ 32 - /** * Return the length of a constant string. * We are aware that `strlen` performs the same task and is usually diff --git a/tests/date/rfc2822.c b/tests/date/rfc2822.c index c94c8403f..b0bbcfce5 100644 --- a/tests/date/rfc2822.c +++ b/tests/date/rfc2822.c @@ -5,36 +5,33 @@ void test_date_rfc2822__format_rfc2822_no_offset(void) { git_time t = {1397031663, 0}; - char buf[GIT_DATE_RFC2822_SZ]; + git_str buf = GIT_STR_INIT; - cl_git_pass(git_date_rfc2822_fmt(buf, sizeof(buf), &t)); - cl_assert(strcmp(buf, "Wed, 9 Apr 2014 08:21:03 +0000") == 0); + cl_git_pass(git_date_rfc2822_fmt(&buf, t.time, t.offset)); + cl_assert_equal_s("Wed, 9 Apr 2014 08:21:03 +0000", buf.ptr); + + git_str_dispose(&buf); } void test_date_rfc2822__format_rfc2822_positive_offset(void) { git_time t = {1397031663, 120}; - char buf[GIT_DATE_RFC2822_SZ]; + git_str buf = GIT_STR_INIT; + + cl_git_pass(git_date_rfc2822_fmt(&buf, t.time, t.offset)); + cl_assert_equal_s("Wed, 9 Apr 2014 10:21:03 +0200", buf.ptr); - cl_git_pass(git_date_rfc2822_fmt(buf, sizeof(buf), &t)); - cl_assert(strcmp(buf, "Wed, 9 Apr 2014 10:21:03 +0200") == 0); + git_str_dispose(&buf); } void test_date_rfc2822__format_rfc2822_negative_offset(void) { git_time t = {1397031663, -120}; - char buf[GIT_DATE_RFC2822_SZ]; + git_str buf = GIT_STR_INIT; - cl_git_pass(git_date_rfc2822_fmt(buf, sizeof(buf), &t)); - cl_assert(strcmp(buf, "Wed, 9 Apr 2014 06:21:03 -0200") == 0); -} - -void test_date_rfc2822__format_rfc2822_buffer_too_small(void) -{ - /* "Wed, 10 Apr 2014 08:21:03 +0000" */ - git_time t = {1397031663 + 86400, 0}; - char buf[GIT_DATE_RFC2822_SZ-1]; + cl_git_pass(git_date_rfc2822_fmt(&buf, t.time, t.offset)); + cl_assert_equal_s("Wed, 9 Apr 2014 06:21:03 -0200", buf.ptr); - cl_git_fail(git_date_rfc2822_fmt(buf, sizeof(buf), &t)); + git_str_dispose(&buf); } -- cgit v1.2.1 From 3461aaf77aad4240ec921697293dc681a8564023 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Mon, 22 Nov 2021 10:29:29 -0500 Subject: repo: minor formatting fix --- src/repository.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/repository.c b/src/repository.c index 2002e1186..fcdb1b3a9 100644 --- a/src/repository.c +++ b/src/repository.c @@ -2038,9 +2038,8 @@ static int repo_init_structure( * `git` prints to stderr: 'warning: templates not found in /path/to/tdir' */ if (error < 0) { - if (!default_template && error != GIT_ENOTFOUND) { + if (!default_template && error != GIT_ENOTFOUND) return error; - } /* if template was default, ignore error and use internal */ git_error_clear(); -- cgit v1.2.1