Gather the reflog entry content tests - #4298
Conversation
|
@pks-t I took care of your review comments, apart from the header thing : AFAICT we don't have headers on test files. |
|
Two issues:
Looks fine otherwise, thanks! |
d41c3a0 to
fe92535
Compare
|
Good to go ! Travis tripped up on proxy things. Again 😉. |
pks-t
left a comment
There was a problem hiding this comment.
Thanks for your adjustments and sorry for another batch of change requests 😅
| clar__fail(file, line, "Reflog entry mismatch", git_buf_cstr(&result), 1); | ||
| } | ||
|
|
||
| git_reflog_free(log); |
There was a problem hiding this comment.
git_buf_free missing here for the result buffer
| git_oid_fmt(&err[1], git_object_id(obj)); | ||
| git_oid_fmt(&err[47], git_reflog_entry_id_new(entry)); | ||
|
|
||
| git_buf_printf(&result, "\tNew OID: %s\n", err); |
There was a problem hiding this comment.
Huh, this seems a bit fragile. How about
git_oid__writebuf(&result, "\tNew OID: \"", git_object_id(obj));
git_oid__writebuf(&result, "\" != \", git_reflog_entry_id_new(entry));
git_buf_puts(&result, '"\n');
This would save us from the hardcoded indices. Same applies below.
There was a problem hiding this comment.
Looks better, thanks !
| } | ||
| if (git_buf_len(&result) != 0) { | ||
| clar__fail(file, line, "Reflog entry mismatch", git_buf_cstr(&result), 1); | ||
| } |
There was a problem hiding this comment.
No need for braces around single-line statements (lines 85 to 98)
| git_buf_printf(&buf, "%ld: %s %s %s %s\n", idx, old_oid, new_oid, "somesig", git_reflog_entry_message(entry)); | ||
| fprintf(stderr, "%s", git_buf_cstr(&buf)); | ||
| git_buf_free(&buf); | ||
| fprintf(stderr, "%s\n", reflog_entry_tostr(entry)); |
There was a problem hiding this comment.
This is a memory leak as reflog_entry_tostr returns a string detached from its buffer. I would instead propose an interface int reflog_entry_tostr(git_buf *out, const git_reflog_entry *entry), which makes the need for memory management more obvious.
|
|
||
| if (email) { | ||
| cl_assert_equal_s(email, git_reflog_entry_committer(entry)->email); | ||
| if (email && strcasecmp(email, git_reflog_entry_committer(entry)->email) != 0) { |
There was a problem hiding this comment.
Should this comparison really be case-insensitive?
There was a problem hiding this comment.
It should not. Fixed the other occurrence below too.
| if (entry == NULL) { | ||
| clar__fail(file, line, "Reflog has no such entry", NULL, 1); | ||
| } | ||
|
|
There was a problem hiding this comment.
No breaces required around single-line statements.
| cl_git_pass(git_repository_set_head(g_repo, "refs/tags/test")); /* 1 */ | ||
| cl_git_pass(git_repository_set_head(g_repo, "refs/remotes/test/master")); /* 0 */ | ||
|
|
||
| reflog_check_entry(g_repo, GIT_HEAD_FILE, 4, |
There was a problem hiding this comment.
I'd prefer if these whitespace changes were put inside another commit, which only changes indentantion. Furthermore, instead of adding more indentation, I'd break with our usual style here and decrease indentation to only one tab on the newline. Otherwise, lines get very long and the statements become quite unreadable.
There was a problem hiding this comment.
Good idea. Folded the indentation change inside the "gathering" step.
fe92535 to
9a810e8
Compare
|
Rebased, squashing review fixups inside their respective commits. |
b653e27 to
2ec6668
Compare
2ec6668 to
6820799
Compare
6820799 to
ebe5d8e
Compare
|
@pks-t Just rebased, ready when you are 😉. |
pks-t
left a comment
There was a problem hiding this comment.
Just two small memory leaks. Otherwise this looks good to go for me. 👍
| git_reference *branch; | ||
|
|
||
| cl_git_pass(git_revparse_single(&obj, g_repo, "e90810b8df3")); | ||
| cl_git_pass(git_commit_lookup(&target, g_repo, git_object_id(obj))); |
|
|
||
| cl_git_pass(git_revparse_single(&obj, g_repo, "e90810b8df3")); | ||
| cl_git_pass(git_commit_lookup(&target, g_repo, git_object_id(obj))); | ||
| git_object_free(obj); |
There was a problem hiding this comment.
I'd prefer if you moved all freeing functions to the end. It makes it a lot easier to see if everything has been taken care of by just comparing the list of declarations and free's at the end (at least in most cases).
| git_buf_clear(&buf); | ||
|
|
||
| cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "e90810b8df3")); | ||
| cl_git_pass(git_branch_create_from_annotated(&branch, g_repo, NEW_BRANCH_NAME, annotated, true)); |
|
Fixed. I had to append some numbers so there was no variable reused, but I like how clearer it makes those lifetimes. |
|
Thanks a lot for this, @tiennou! |
This is is splitted from #4294 with just the test case wrangling.