-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
* 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"); |
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 seems strange to me. Why are we looking for \r\n
and not \n
as a line terminator?
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.
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 ;)
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.
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.
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.
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
?
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.
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.
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.
c7c8fa3
to
254e0a3
Compare
As proposed in my comment I've created a new public function |
254e0a3
to
7f8fe1d
Compare
diff: include commit message when formatting patch
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.