Skip to content

Gather the reflog entry content tests - #4298

Merged
pks-t merged 5 commits into
libgit2:masterfrom
tiennou:gather-reflog-messages-tests
Nov 24, 2017
Merged

Gather the reflog entry content tests#4298
pks-t merged 5 commits into
libgit2:masterfrom
tiennou:gather-reflog-messages-tests

Conversation

@tiennou

@tiennou tiennou commented Jul 7, 2017

Copy link
Copy Markdown
Contributor

This is is splitted from #4294 with just the test case wrangling.

@tiennou

tiennou commented Jul 7, 2017

Copy link
Copy Markdown
Contributor Author

@pks-t I took care of your review comments, apart from the header thing : AFAICT we don't have headers on test files.

@pks-t

pks-t commented Jul 10, 2017

Copy link
Copy Markdown
Member

Two issues:

  • there's one use of C99-style comments in "tests/refs/reflog/messages.c", which we usually avoid
  • there's a declaration after code in reflog_print

Looks fine otherwise, thanks!

@tiennou
tiennou force-pushed the gather-reflog-messages-tests branch 2 times, most recently from d41c3a0 to fe92535 Compare July 17, 2017 20:41
@tiennou

tiennou commented Jul 17, 2017

Copy link
Copy Markdown
Contributor Author

Good to go ! Travis tripped up on proxy things. Again 😉.

@pks-t pks-t left a comment

Copy link
Copy Markdown
Member

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);

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread 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);

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And above, as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better, thanks !

Comment thread 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);
}

Copy link
Copy Markdown
Member

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)

Comment thread 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));

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment thread 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) {

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Contributor Author

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);
}

Copy link
Copy Markdown
Member

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.

Comment thread 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,

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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.

@tiennou
tiennou force-pushed the gather-reflog-messages-tests branch from fe92535 to 9a810e8 Compare July 21, 2017 17:52
@tiennou

tiennou commented Jul 21, 2017

Copy link
Copy Markdown
Contributor Author

Rebased, squashing review fixups inside their respective commits.

@tiennou
tiennou force-pushed the gather-reflog-messages-tests branch from b653e27 to 2ec6668 Compare July 21, 2017 20:02
@tiennou
tiennou force-pushed the gather-reflog-messages-tests branch from 2ec6668 to 6820799 Compare September 16, 2017 22:05
@tiennou
tiennou force-pushed the gather-reflog-messages-tests branch from 6820799 to ebe5d8e Compare November 14, 2017 23:37
@tiennou

tiennou commented Nov 14, 2017

Copy link
Copy Markdown
Contributor Author

@pks-t Just rebased, ready when you are 😉.

@pks-t pks-t left a comment

Copy link
Copy Markdown
Member

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)));

Copy link
Copy Markdown
Member

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);

Copy link
Copy Markdown
Member

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).

Comment thread 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));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

branch is also leaking

@tiennou

tiennou commented Nov 22, 2017

Copy link
Copy Markdown
Contributor Author

Fixed. I had to append some numbers so there was no variable reused, but I like how clearer it makes those lifetimes.

@pks-t
pks-t merged commit 59ffb51 into libgit2:master Nov 24, 2017
@pks-t

pks-t commented Nov 24, 2017

Copy link
Copy Markdown
Member

Thanks a lot for this, @tiennou!

@tiennou
tiennou deleted the gather-reflog-messages-tests branch November 26, 2017 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants