Parse ref oids without trailing newline
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
diff --git a/src/refs.c b/src/refs.c
index 0e0a491..2f1292b 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -173,8 +173,8 @@ static int loose_parse_oid(git_oid *oid, git_buf *file_content)
buffer = (char *)file_content->ptr;
- /* File format: 40 chars (OID) + newline */
- if (git_buf_len(file_content) < GIT_OID_HEXSZ + 1)
+ /* File format: 40 chars (OID) */
+ if (git_buf_len(file_content) < GIT_OID_HEXSZ)
goto corrupt;
if (git_oid_fromstr(oid, buffer) < 0)
@@ -184,7 +184,10 @@ static int loose_parse_oid(git_oid *oid, git_buf *file_content)
if (*buffer == '\r')
buffer++;
- if (*buffer != '\n')
+ if (*buffer == '\n')
+ buffer++;
+
+ if (*buffer != '\0')
goto corrupt;
return 0;
diff --git a/tests-clar/network/remotelocal.c b/tests-clar/network/remotelocal.c
index 16e3fe2..9c8ce35 100644
--- a/tests-clar/network/remotelocal.c
+++ b/tests-clar/network/remotelocal.c
@@ -107,7 +107,7 @@ void test_network_remotelocal__retrieve_advertised_references(void)
cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
- cl_assert_equal_i(how_many_refs, 23);
+ cl_assert_equal_i(how_many_refs, 24);
}
void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void)
@@ -121,7 +121,7 @@ void test_network_remotelocal__retrieve_advertised_references_from_spaced_reposi
cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
- cl_assert_equal_i(how_many_refs, 23);
+ cl_assert_equal_i(how_many_refs, 24);
git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */
remote = NULL;
diff --git a/tests-clar/refs/branches/foreach.c b/tests-clar/refs/branches/foreach.c
index 79c7e59..ca1393b 100644
--- a/tests-clar/refs/branches/foreach.c
+++ b/tests-clar/refs/branches/foreach.c
@@ -47,7 +47,7 @@ static void assert_retrieval(unsigned int flags, unsigned int expected_count)
void test_refs_branches_foreach__retrieve_all_branches(void)
{
- assert_retrieval(GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE, 11);
+ assert_retrieval(GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE, 12);
}
void test_refs_branches_foreach__retrieve_remote_branches(void)
@@ -57,7 +57,7 @@ void test_refs_branches_foreach__retrieve_remote_branches(void)
void test_refs_branches_foreach__retrieve_local_branches(void)
{
- assert_retrieval(GIT_BRANCH_LOCAL, 9);
+ assert_retrieval(GIT_BRANCH_LOCAL, 10);
}
struct expectations {
diff --git a/tests-clar/refs/foreachglob.c b/tests-clar/refs/foreachglob.c
index 66827e5..ba58c20 100644
--- a/tests-clar/refs/foreachglob.c
+++ b/tests-clar/refs/foreachglob.c
@@ -45,8 +45,8 @@ static void assert_retrieval(const char *glob, unsigned int flags, int expected_
void test_refs_foreachglob__retrieve_all_refs(void)
{
- /* 7 heads (including one packed head) + 1 note + 2 remotes + 6 tags */
- assert_retrieval("*", GIT_REF_LISTALL, 18);
+ /* 8 heads (including one packed head) + 1 note + 2 remotes + 6 tags */
+ assert_retrieval("*", GIT_REF_LISTALL, 19);
}
void test_refs_foreachglob__retrieve_remote_branches(void)
@@ -56,7 +56,7 @@ void test_refs_foreachglob__retrieve_remote_branches(void)
void test_refs_foreachglob__retrieve_local_branches(void)
{
- assert_retrieval("refs/heads/*", GIT_REF_LISTALL, 9);
+ assert_retrieval("refs/heads/*", GIT_REF_LISTALL, 10);
}
void test_refs_foreachglob__retrieve_partially_named_references(void)
diff --git a/tests-clar/refs/read.c b/tests-clar/refs/read.c
index 1948e0a..395225b 100644
--- a/tests-clar/refs/read.c
+++ b/tests-clar/refs/read.c
@@ -193,6 +193,18 @@ void test_refs_read__loose_first(void)
git_reference_free(reference);
}
+void test_refs_read__chomped(void)
+{
+ git_reference *test, *chomped;
+
+ cl_git_pass(git_reference_lookup(&test, g_repo, "refs/heads/test"));
+ cl_git_pass(git_reference_lookup(&chomped, g_repo, "refs/heads/chomped"));
+ cl_git_pass(git_oid_cmp(git_reference_oid(test), git_reference_oid(chomped)));
+
+ git_reference_free(test);
+ git_reference_free(chomped);
+}
+
void test_refs_read__unfound_return_ENOTFOUND(void)
{
git_reference *reference;
diff --git a/tests-clar/resources/testrepo.git/refs/heads/chomped b/tests-clar/resources/testrepo.git/refs/heads/chomped
new file mode 100644
index 0000000..0166a7f
--- /dev/null
+++ b/tests-clar/resources/testrepo.git/refs/heads/chomped
@@ -0,0 +1 @@
+e90810b8df3e80c413d903f631643c716887138d
\ No newline at end of file