-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Gather the reflog entry content tests #4298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git_buf_free missing here for the result buffer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
tests/refs/reflog/reflog_helpers.c
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And above, as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks better, thanks !
tests/refs/reflog/reflog_helpers.c
Outdated
| } | ||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for braces around single-line statements (lines 85 to 98)
tests/refs/reflog/reflog_helpers.c
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
tests/refs/reflog/reflog_helpers.c
Outdated
|
|
||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this comparison really be case-insensitive?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No breaces required around single-line statements.
tests/refs/reflog/messages.c
Outdated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The target is leaking.
|
|
||
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
tests/refs/reflog/messages.c
Outdated
| 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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
branch is also leaking
|
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.