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

Skip to content

When formatting patch as mbox, commit.message isn't added #3371

Closed
@ghost

Description

When trying to format a commit as an email, libgit2 will not add the commit.message to the output leaving out rather crucial information about what author thought s/he was doing.

The original git format-patch adds the commit message to mbox, so users have come to expect that when generating mbox versions of commits.

I have written a patch (yet to test, only build-tested so far) which would add commit.message to the final mbox, after testing I could send a pull request, assuming the community agrees with the need.

    diff: add commit.message to git_diff_commit_as_email()

    The original git format-patch command, will also
    add git commit message, in order to be compatible
    with users' expectations, let's also add commit.message
    when generating commit as email.

    Signed-off-by: Felipe Balbi <[email protected]>

diff --git a/include/git2/diff.h b/include/git2/diff.h
index 0abbc7f06f85..cd8389170969 100644
--- a/include/git2/diff.h
+++ b/include/git2/diff.h
@@ -1263,6 +1263,9 @@ typedef struct {
        /** Summary of the change */
        const char *summary;

+       /** Commit message */
+       const char *message;
+
        /** Author of the change */
        const git_signature *author;
 } git_diff_format_email_options;
diff --git a/src/diff.c b/src/diff.c
index 44f62788086f..759c1a5de626 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -1743,6 +1743,8 @@ int git_diff_format_email(
        if (error < 0)
                goto on_error;

+       error = git_buf_puts(out, opts->message);
+
        format_flags = GIT_DIFF_STATS_FULL | GIT_DIFF_STATS_INCLUDE_SUMMARY;

        if ((error = git_buf_puts(out, "---\n")) < 0 ||
@@ -1782,6 +1784,7 @@ int git_diff_commit_as_email(
        opts.id = git_commit_id(commit);
        opts.summary = git_commit_summary(commit);
        opts.author = git_commit_author(commit);
+       opts.message = git_commit_message(commit);

        if ((error = git_diff__commit(&diff, repo, commit, diff_opts)) < 0)
                return error;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions