Thanks to visit codestin.com
Credit goes to github.com

Skip to content

diff: include commit message when formatting patch #3522

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

Merged
merged 2 commits into from
Dec 10, 2015

Conversation

pks-t
Copy link
Member

@pks-t pks-t commented Nov 24, 2015

When formatting a patch as email we do not include the commit's
message in the formatted patch output. Implement this and add a
test that verifies behavior.

Fixes #3371.

* the summary and thus needs to be skipped */
if ((ptr = git_commit_message(commit)) != NULL) {
/* Find end of first line */
ptr = strpbrk(ptr, "\r\n");
Copy link
Member

Choose a reason for hiding this comment

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

This seems strange to me. Why are we looking for \r\n and not \n as a line terminator?

Copy link
Member

Choose a reason for hiding this comment

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

Fun fact: the second argument to strpbrk() is a list of chars to find, in string form (because how else would you represent a list of characters ;)

Copy link
Member

Choose a reason for hiding this comment

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

However, note that what we want to find is the end of the first paragraph, not the first line. That is, we're looking for the first "\n\n" (or, I suppose maybe also "\r\n\r\n", though I don't know if any editor will actually use CRLF for the commit message) as a separator between the subject and the body.

Copy link
Member

Choose a reason for hiding this comment

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

Right you are. In that case, why are we looking for \r? Does Git actually allow \r as a line terminator? Or is the goal to find the \n but back up over the \r if the line was terminated with \r\n?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, actually I'm not sure about this. Just searched git-am(1), git-format-patch(1) and git-apply(1), but there was no mention of line endings. There are some platforms that use \r as line endings, that's why I used this.

I think it might make sense to expose a new function git_commit_body, that will return a pointer to the commit message excluding the summary. This could be used here, then, and might prove useful for others.

pks-t added 2 commits December 1, 2015 10:07
It is already possible to get a commit's summary with the
`git_commit_summary` function. It is not possible to get the
remaining part of the commit message, that is the commit
message's body.

Fix this by introducing a new function `git_commit_body`.
When formatting a patch as email we do not include the commit's
message in the formatted patch output. Implement this and add a
test that verifies behavior.
@pks-t pks-t force-pushed the email-format-commit-message branch from c7c8fa3 to 254e0a3 Compare December 1, 2015 09:13
@pks-t
Copy link
Member Author

pks-t commented Dec 1, 2015

As proposed in my comment I've created a new public function git_commit_body, which is used by the format-email code.

@pks-t pks-t force-pushed the email-format-commit-message branch from 254e0a3 to 7f8fe1d Compare December 8, 2015 10:53
carlosmn added a commit that referenced this pull request Dec 10, 2015
diff: include commit message when formatting patch
@carlosmn carlosmn merged commit 6aa06b6 into libgit2:master Dec 10, 2015
@pks-t pks-t deleted the email-format-commit-message branch June 21, 2016 05:48
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.

3 participants