From 307c4a2b6d1e3b403225b3d5b7f9894b940b24bd Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Wed, 21 Oct 2015 11:58:44 +0200 Subject: [PATCH 1/3] signature: Strip crud just like Git does --- src/signature.c | 18 ++++++++++++++++-- tests/commit/signature.c | 7 +++++++ tests/revwalk/signatureparsing.c | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/signature.c b/src/signature.c index 818cd300e..109476efe 100644 --- a/src/signature.c +++ b/src/signature.c @@ -34,13 +34,27 @@ static bool contains_angle_brackets(const char *input) return strchr(input, '<') != NULL || strchr(input, '>') != NULL; } +static bool is_crud(unsigned char c) +{ + return c <= 32 || + c == '.' || + c == ',' || + c == ':' || + c == ';' || + c == '<' || + c == '>' || + c == '"' || + c == '\\' || + c == '\''; +} + static char *extract_trimmed(const char *ptr, size_t len) { - while (len && git__isspace(ptr[0])) { + while (len && is_crud((unsigned char)ptr[0])) { ptr++; len--; } - while (len && git__isspace(ptr[len - 1])) { + while (len && is_crud((unsigned char)ptr[len - 1])) { len--; } diff --git a/tests/commit/signature.c b/tests/commit/signature.c index 41a74b999..0070320ae 100644 --- a/tests/commit/signature.c +++ b/tests/commit/signature.c @@ -35,6 +35,13 @@ void test_commit_signature__leading_and_trailing_spaces_are_trimmed(void) assert_name_and_email("nulltoken", "emeric.fermas@gmail.com", " \t nulltoken \n", " \n emeric.fermas@gmail.com \n"); } +void test_commit_signature__leading_and_trailing_crud_is_trimmed(void) +{ + assert_name_and_email("nulltoken", "emeric.fermas@gmail.com", "\"nulltoken\"", "\"emeric.fermas@gmail.com\""); + assert_name_and_email("nulltoken w", "emeric.fermas@gmail.com", "nulltoken w.", "emeric.fermas@gmail.com"); + assert_name_and_email("nulltoken \xe2\x98\xba", "emeric.fermas@gmail.com", "nulltoken \xe2\x98\xba", "emeric.fermas@gmail.com"); +} + void test_commit_signature__angle_brackets_in_names_are_not_supported(void) { cl_git_fail(try_build_signature("email); - cl_assert_equal_s("", signature->name); + cl_assert_equal_s("Yu V. Bin Haacked", signature->name); cl_assert_equal_i(1323847743, (int)signature->when.time); cl_assert_equal_i(60, signature->when.offset); From 128e94bbbb1f1af539be7fb2844e261bfdb28fed Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Wed, 21 Oct 2015 12:04:53 +0200 Subject: [PATCH 2/3] index: Remove unneeded consts --- src/index.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/index.c b/src/index.c index c0be5b90d..334a13135 100644 --- a/src/index.c +++ b/src/index.c @@ -1193,13 +1193,13 @@ static int index_no_dups(void **old, void *new) } static void index_existing_and_best( - const git_index_entry **existing, + git_index_entry **existing, size_t *existing_position, - const git_index_entry **best, + git_index_entry **best, git_index *index, const git_index_entry *entry) { - const git_index_entry *e; + git_index_entry *e; size_t pos; int error; From bbe1957b8c75760c81ce04c7edf6d203513b39f8 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Wed, 21 Oct 2015 12:09:29 +0200 Subject: [PATCH 3/3] tests: Fix warnings --- tests/diff/workdir.c | 2 +- tests/revwalk/basic.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c index 89f9483a6..dac32453b 100644 --- a/tests/diff/workdir.c +++ b/tests/diff/workdir.c @@ -2080,7 +2080,7 @@ void test_diff_workdir__to_index_pathlist(void) cl_git_pass(git_repository_index(&index, g_repo)); opts.flags = GIT_DIFF_INCLUDE_IGNORED; - opts.pathspec.strings = pathlist.contents; + opts.pathspec.strings = (char **)pathlist.contents; opts.pathspec.count = pathlist.length; cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, index, &opts)); diff --git a/tests/revwalk/basic.c b/tests/revwalk/basic.c index d8236ce72..5ed7da4eb 100644 --- a/tests/revwalk/basic.c +++ b/tests/revwalk/basic.c @@ -456,7 +456,8 @@ void test_revwalk_basic__big_timestamp(void) cl_git_pass(git_signature_new(&sig, "Joe", "joe@example.com", 2399662595, 0)); cl_git_pass(git_commit_tree(&tree, tip)); - cl_git_pass(git_commit_create(&id, _repo, "HEAD", sig, sig, NULL, "some message", tree, 1, &tip)); + cl_git_pass(git_commit_create(&id, _repo, "HEAD", sig, sig, NULL, "some message", tree, 1, + (const git_commit **)&tip)); cl_git_pass(git_revwalk_push_head(_walk));