diff options
| author | nulltoken <emeric.fermas@gmail.com> | 2012-11-17 06:46:42 -0800 |
|---|---|---|
| committer | nulltoken <emeric.fermas@gmail.com> | 2012-11-17 07:20:07 -0800 |
| commit | f5a0e734bc440ca6c89d15a894fea0ea3bf38f36 (patch) | |
| tree | ea5e0f82caae15648c1457834de338ad534f1a01 | |
| parent | 5df7207a674d1d4c41b300f6f0c5548d087f06b3 (diff) | |
| download | libgit2-f5a0e734bc440ca6c89d15a894fea0ea3bf38f36.tar.gz | |
tests: introduce cl_git_remove_placeholders()
| -rw-r--r-- | tests-clar/clar_helpers.c | 49 | ||||
| -rw-r--r-- | tests-clar/clar_libgit2.h | 3 |
2 files changed, 52 insertions, 0 deletions
diff --git a/tests-clar/clar_helpers.c b/tests-clar/clar_helpers.c index 3d09bd489..b718d4305 100644 --- a/tests-clar/clar_helpers.c +++ b/tests-clar/clar_helpers.c @@ -271,3 +271,52 @@ const char* cl_git_path_url(const char *path) git_buf_free(&path_buf); return url; } + +typedef struct { + const char *filename; + size_t filename_len; +} remove_data; + +static int remove_placeholders_recurs(void *_data, git_buf *path) +{ + remove_data *data = (remove_data *)_data; + size_t pathlen; + + if (git_path_isdir(path->ptr) == true) + return git_path_direach(path, remove_placeholders_recurs, data); + + pathlen = path->size; + + if (pathlen < data->filename_len) + return 0; + + /* if path ends in '/'+filename (or equals filename) */ + if (!strcmp(data->filename, path->ptr + pathlen - data->filename_len) && + (pathlen == data->filename_len || + path->ptr[pathlen - data->filename_len - 1] == '/')) + return p_unlink(path->ptr); + + return 0; +} + +int cl_git_remove_placeholders(const char *directory_path, const char *filename) +{ + int error; + remove_data data; + git_buf buffer = GIT_BUF_INIT; + + if (git_path_isdir(directory_path) == false) + return -1; + + if (git_buf_sets(&buffer, directory_path) < 0) + return -1; + + data.filename = filename; + data.filename_len = strlen(filename); + + error = remove_placeholders_recurs(&data, &buffer); + + git_buf_free(&buffer); + + return error; +} diff --git a/tests-clar/clar_libgit2.h b/tests-clar/clar_libgit2.h index fd20c1259..91a542654 100644 --- a/tests-clar/clar_libgit2.h +++ b/tests-clar/clar_libgit2.h @@ -61,4 +61,7 @@ void cl_git_sandbox_cleanup(void); const char* cl_git_fixture_url(const char *fixturename); const char* cl_git_path_url(const char *path); +/* Test repository cleaner */ +int cl_git_remove_placeholders(const char *directory_path, const char *filename); + #endif |
