diff options
| -rw-r--r-- | include/git2.h | 81 | ||||
| -rw-r--r-- | src/commit.c | 2 | ||||
| -rw-r--r-- | src/indexer.c | 2 | ||||
| -rw-r--r-- | tests-clar/clar_libgit2.c | 2 | ||||
| -rw-r--r-- | tests-clar/clar_libgit2.h | 8 | ||||
| -rw-r--r-- | tests-clar/commit/parse.c | 185 |
6 files changed, 144 insertions, 136 deletions
diff --git a/include/git2.h b/include/git2.h index 73c11ad83..93049aad9 100644 --- a/include/git2.h +++ b/include/git2.h @@ -8,57 +8,50 @@ #ifndef INCLUDE_git_git_h__ #define INCLUDE_git_git_h__ -#include "git2/version.h" - -#include "git2/common.h" -#include "git2/threads.h" -#include "git2/errors.h" - -#include "git2/types.h" - -#include "git2/oid.h" -#include "git2/signature.h" -#include "git2/odb.h" - -#include "git2/repository.h" -#include "git2/revwalk.h" -#include "git2/merge.h" -#include "git2/graph.h" -#include "git2/refs.h" -#include "git2/reflog.h" -#include "git2/revparse.h" - -#include "git2/object.h" +#include "git2/attr.h" #include "git2/blob.h" +#include "git2/branch.h" +#include "git2/buffer.h" +#include "git2/checkout.h" +#include "git2/clone.h" #include "git2/commit.h" -#include "git2/tag.h" -#include "git2/tree.h" -#include "git2/diff.h" - -#include "git2/index.h" +#include "git2/common.h" #include "git2/config.h" -#include "git2/transport.h" -#include "git2/remote.h" -#include "git2/clone.h" -#include "git2/checkout.h" -#include "git2/push.h" - -#include "git2/attr.h" +#include "git2/diff.h" +#include "git2/errors.h" +#include "git2/filter.h" +#include "git2/graph.h" #include "git2/ignore.h" -#include "git2/branch.h" -#include "git2/refspec.h" -#include "git2/net.h" -#include "git2/status.h" +#include "git2/index.h" #include "git2/indexer.h" -#include "git2/submodule.h" -#include "git2/notes.h" -#include "git2/reset.h" +#include "git2/merge.h" #include "git2/message.h" +#include "git2/net.h" +#include "git2/notes.h" +#include "git2/object.h" +#include "git2/odb.h" +#include "git2/oid.h" #include "git2/pack.h" -#include "git2/stash.h" #include "git2/pathspec.h" - -#include "git2/buffer.h" -#include "git2/filter.h" +#include "git2/push.h" +#include "git2/refdb.h" +#include "git2/reflog.h" +#include "git2/refs.h" +#include "git2/refspec.h" +#include "git2/remote.h" +#include "git2/repository.h" +#include "git2/reset.h" +#include "git2/revparse.h" +#include "git2/revwalk.h" +#include "git2/signature.h" +#include "git2/stash.h" +#include "git2/status.h" +#include "git2/submodule.h" +#include "git2/tag.h" +#include "git2/threads.h" +#include "git2/transport.h" +#include "git2/tree.h" +#include "git2/types.h" +#include "git2/version.h" #endif diff --git a/src/commit.c b/src/commit.c index 15a195fe5..ab475a8f8 100644 --- a/src/commit.c +++ b/src/commit.c @@ -240,7 +240,7 @@ int git_commit__parse(void *_commit, git_odb_object *odb_obj) buffer_end = buffer + git_odb_object_size(odb_obj); buffer += header_len; - if (*buffer == '\n') + while (buffer < buffer_end && *buffer == '\n') ++buffer; /* extract commit message */ diff --git a/src/indexer.c b/src/indexer.c index ceb11f0b6..3b160df5d 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -426,7 +426,7 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz if (git_filebuf_write(&idx->pack_file, data, size) < 0) return -1; - hash_partially(idx, data, size); + hash_partially(idx, data, (int)size); /* Make sure we set the new size of the pack */ if (idx->opened_pack) { diff --git a/tests-clar/clar_libgit2.c b/tests-clar/clar_libgit2.c index 555af38db..6063bf91c 100644 --- a/tests-clar/clar_libgit2.c +++ b/tests-clar/clar_libgit2.c @@ -440,7 +440,7 @@ void clar__assert_equal_file( int ignore_cr, const char *path, const char *file, - size_t line) + int line) { char buf[4000]; ssize_t bytes, total_bytes = 0; diff --git a/tests-clar/clar_libgit2.h b/tests-clar/clar_libgit2.h index 9d4d63e6c..b9ef5627e 100644 --- a/tests-clar/clar_libgit2.h +++ b/tests-clar/clar_libgit2.h @@ -44,7 +44,7 @@ GIT_INLINE(void) clar__assert_in_range( } #define cl_assert_equal_sz(sz1,sz2) do { \ - size_t __sz1 = (sz1), __sz2 = (sz2); \ + size_t __sz1 = (size_t)(sz1), __sz2 = (size_t)(sz2); \ clar__assert_equal(__FILE__,__LINE__,#sz1 " != " #sz2, 1, "%"PRIuZ, __sz1, __sz2); \ } while (0) @@ -52,10 +52,10 @@ GIT_INLINE(void) clar__assert_in_range( clar__assert_in_range((L),(V),(H),__FILE__,__LINE__,"Range check: " #V " in [" #L "," #H "]", 1) #define cl_assert_equal_file(DATA,SIZE,PATH) \ - clar__assert_equal_file(DATA,SIZE,0,PATH,__FILE__,__LINE__) + clar__assert_equal_file(DATA,SIZE,0,PATH,__FILE__,(int)__LINE__) #define cl_assert_equal_file_ignore_cr(DATA,SIZE,PATH) \ - clar__assert_equal_file(DATA,SIZE,1,PATH,__FILE__,__LINE__) + clar__assert_equal_file(DATA,SIZE,1,PATH,__FILE__,(int)__LINE__) void clar__assert_equal_file( const char *expected_data, @@ -63,7 +63,7 @@ void clar__assert_equal_file( int ignore_cr, const char *path, const char *file, - size_t line); + int line); /* * Some utility macros for building long strings diff --git a/tests-clar/commit/parse.c b/tests-clar/commit/parse.c index 415860a6e..c191b3421 100644 --- a/tests-clar/commit/parse.c +++ b/tests-clar/commit/parse.c @@ -7,77 +7,77 @@ static git_repository *g_repo; void test_commit_parse__initialize(void) { - g_repo = cl_git_sandbox_init("testrepo"); + g_repo = cl_git_sandbox_init("testrepo"); } void test_commit_parse__cleanup(void) { - cl_git_sandbox_cleanup(); + cl_git_sandbox_cleanup(); } // Header parsing typedef struct { - const char *line; - const char *header; + const char *line; + const char *header; } parse_test_case; static parse_test_case passing_header_cases[] = { - { "parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "parent " }, - { "tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " }, - { "random_heading 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "random_heading " }, - { "stuck_heading05452d6349abcd67aa396dfb28660d765d8b2a36\n", "stuck_heading" }, - { "tree 5F4BEFFC0759261D015AA63A3A85613FF2F235DE\n", "tree " }, - { "tree 1A669B8AB81B5EB7D9DB69562D34952A38A9B504\n", "tree " }, - { "tree 5B20DCC6110FCC75D31C6CEDEBD7F43ECA65B503\n", "tree " }, - { "tree 173E7BF00EA5C33447E99E6C1255954A13026BE4\n", "tree " }, - { NULL, NULL } + { "parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "parent " }, + { "tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " }, + { "random_heading 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "random_heading " }, + { "stuck_heading05452d6349abcd67aa396dfb28660d765d8b2a36\n", "stuck_heading" }, + { "tree 5F4BEFFC0759261D015AA63A3A85613FF2F235DE\n", "tree " }, + { "tree 1A669B8AB81B5EB7D9DB69562D34952A38A9B504\n", "tree " }, + { "tree 5B20DCC6110FCC75D31C6CEDEBD7F43ECA65B503\n", "tree " }, + { "tree 173E7BF00EA5C33447E99E6C1255954A13026BE4\n", "tree " }, + { NULL, NULL } }; static parse_test_case failing_header_cases[] = { - { "parent 05452d6349abcd67aa396dfb28660d765d8b2a36", "parent " }, - { "05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " }, - { "parent05452d6349abcd67aa396dfb28660d765d8b2a6a\n", "parent " }, - { "parent 05452d6349abcd67aa396dfb280d765d8b2a6\n", "parent " }, - { "tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " }, - { "parent 0545xd6349abcd67aa396dfb28660d765d8b2a36\n", "parent " }, - { "parent 0545xd6349abcd67aa396dfb28660d765d8b2a36FF\n", "parent " }, - { "", "tree " }, - { "", "" }, - { NULL, NULL } + { "parent 05452d6349abcd67aa396dfb28660d765d8b2a36", "parent " }, + { "05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " }, + { "parent05452d6349abcd67aa396dfb28660d765d8b2a6a\n", "parent " }, + { "parent 05452d6349abcd67aa396dfb280d765d8b2a6\n", "parent " }, + { "tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " }, + { "parent 0545xd6349abcd67aa396dfb28660d765d8b2a36\n", "parent " }, + { "parent 0545xd6349abcd67aa396dfb28660d765d8b2a36FF\n", "parent " }, + { "", "tree " }, + { "", "" }, + { NULL, NULL } }; void test_commit_parse__header(void) { - git_oid oid; + git_oid oid; - parse_test_case *testcase; - for (testcase = passing_header_cases; testcase->line != NULL; testcase++) - { - const char *line = testcase->line; - const char *line_end = line + strlen(line); + parse_test_case *testcase; + for (testcase = passing_header_cases; testcase->line != NULL; testcase++) + { + const char *line = testcase->line; + const char *line_end = line + strlen(line); - cl_git_pass(git_oid__parse(&oid, &line, line_end, testcase->header)); - cl_assert(line == line_end); - } + cl_git_pass(git_oid__parse(&oid, &line, line_end, testcase->header)); + cl_assert(line == line_end); + } - for (testcase = failing_header_cases; testcase->line != NULL; testcase++) - { - const char *line = testcase->line; - const char *line_end = line + strlen(line); + for (testcase = failing_header_cases; testcase->line != NULL; testcase++) + { + const char *line = testcase->line; + const char *line_end = line + strlen(line); - cl_git_fail(git_oid__parse(&oid, &line, line_end, testcase->header)); - } + cl_git_fail(git_oid__parse(&oid, &line, line_end, testcase->header)); + } } // Signature parsing typedef struct { - const char *string; - const char *header; - const char *name; - const char *email; - git_time_t time; - int offset; + const char *string; + const char *header; + const char *name; + const char *email; + git_time_t time; + int offset; } passing_signature_test_case; passing_signature_test_case passing_signature_cases[] = { @@ -122,12 +122,12 @@ passing_signature_test_case passing_signature_cases[] = { {"author Vicent Marti <tanoku@gmail.com> 4294967296 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 4294967296, 0}, {"author Vicent Marti <tanoku@gmail.com> 8589934592 \n", "author ", "Vicent Marti", "tanoku@gmail.com", 8589934592, 0}, - {NULL,NULL,NULL,NULL,0,0} + {NULL,NULL,NULL,NULL,0,0} }; typedef struct { - const char *string; - const char *header; + const char *string; + const char *header; } failing_signature_test_case; failing_signature_test_case failing_signature_cases[] = { @@ -143,31 +143,31 @@ failing_signature_test_case failing_signature_cases[] = { void test_commit_parse__signature(void) { - passing_signature_test_case *passcase; - failing_signature_test_case *failcase; - - for (passcase = passing_signature_cases; passcase->string != NULL; passcase++) - { - const char *str = passcase->string; - size_t len = strlen(passcase->string); - struct git_signature person = {0}; - - cl_git_pass(git_signature__parse(&person, &str, str + len, passcase->header, '\n')); - cl_assert_equal_s(passcase->name, person.name); - cl_assert_equal_s(passcase->email, person.email); - cl_assert_equal_i((int)passcase->time, (int)person.when.time); - cl_assert_equal_i(passcase->offset, person.when.offset); - git__free(person.name); git__free(person.email); - } - - for (failcase = failing_signature_cases; failcase->string != NULL; failcase++) - { - const char *str = failcase->string; - size_t len = strlen(failcase->string); - git_signature person = {0}; - cl_git_fail(git_signature__parse(&person, &str, str + len, failcase->header, '\n')); - git__free(person.name); git__free(person.email); - } + passing_signature_test_case *passcase; + failing_signature_test_case *failcase; + + for (passcase = passing_signature_cases; passcase->string != NULL; passcase++) + { + const char *str = passcase->string; + size_t len = strlen(passcase->string); + struct git_signature person = {0}; + + cl_git_pass(git_signature__parse(&person, &str, str + len, passcase->header, '\n')); + cl_assert_equal_s(passcase->name, person.name); + cl_assert_equal_s(passcase->email, person.email); + cl_assert_equal_i((int)passcase->time, (int)person.when.time); + cl_assert_equal_i(passcase->offset, person.when.offset); + git__free(person.name); git__free(person.email); + } + + for (failcase = failing_signature_cases; failcase->string != NULL; failcase++) + { + const char *str = failcase->string; + size_t len = strlen(failcase->string); + git_signature person = {0}; + cl_git_fail(git_signature__parse(&person, &str, str + len, failcase->header, '\n')); + git__free(person.name); git__free(person.email); + } } @@ -312,17 +312,17 @@ void test_commit_parse__entire_commit(void) // query the details on a parsed commit void test_commit_parse__details0(void) { - static const char *commit_ids[] = { - "a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */ - "9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */ - "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", /* 2 */ - "c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */ - "8496071c1b46c854b31185ea97743be6a8774479", /* 4 */ - "5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */ - "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", /* 6 */ - }; + static const char *commit_ids[] = { + "a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */ + "9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */ + "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", /* 2 */ + "c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */ + "8496071c1b46c854b31185ea97743be6a8774479", /* 4 */ + "5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */ + "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", /* 6 */ + }; const size_t commit_count = sizeof(commit_ids) / sizeof(const char *); - unsigned int i; + unsigned int i; for (i = 0; i < commit_count; ++i) { git_oid id; @@ -349,7 +349,6 @@ void test_commit_parse__details0(void) { cl_assert_equal_s("Scott Chacon", committer->name); cl_assert_equal_s("schacon@gmail.com", committer->email); cl_assert(message != NULL); - cl_assert(strchr(message, '\n') != NULL); cl_assert(commit_time > 0); cl_assert(parents <= 2); for (p = 0;p < parents;p++) { @@ -382,9 +381,25 @@ committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\ \n\ This commit has a few LF at the start of the commit message"; const char *message = -"\n\ +"This commit has a few LF at the start of the commit message"; + + cl_git_pass(parse_commit(&commit, buffer)); + cl_assert_equal_s(message, git_commit_message(commit)); + git_commit__free(commit); +} + +void test_commit_parse__only_lf(void) +{ + git_commit *commit; + const char *buffer = +"tree 1810dff58d8a660512d4832e740f692884338ccd\n\ +parent e90810b8df3e80c413d903f631643c716887138d\n\ +author Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\ +committer Vicent Marti <tanoku@gmail.com> 1273848544 +0200\n\ \n\ -This commit has a few LF at the start of the commit message"; +\n\ +\n"; + const char *message = ""; cl_git_pass(parse_commit(&commit, buffer)); cl_assert_equal_s(message, git_commit_message(commit)); |
