Skip to content

Commit f407d3f

Browse files
committed
diff_commit_as_email: use email_create
Move the `git_diff_commit_as_email` function to use `email_create`.
1 parent 3f13d2e commit f407d3f

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/diff.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "diff.h"
99

1010
#include "git2/version.h"
11+
#include "git2/email.h"
1112
#include "diff_generate.h"
1213
#include "patch.h"
1314
#include "commit.h"
@@ -323,26 +324,28 @@ int git_diff_commit_as_email(
323324
const git_diff_options *diff_opts)
324325
{
325326
git_diff *diff = NULL;
326-
git_diff_format_email_options opts =
327-
GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT;
327+
git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT;
328+
const git_oid *commit_id;
329+
const char *summary, *body;
330+
const git_signature *author;
328331
int error;
329332

330333
GIT_ASSERT_ARG(out);
331334
GIT_ASSERT_ARG(repo);
332335
GIT_ASSERT_ARG(commit);
333336

334-
opts.flags = flags;
335-
opts.patch_no = patch_no;
336-
opts.total_patches = total_patches;
337-
opts.id = git_commit_id(commit);
338-
opts.summary = git_commit_summary(commit);
339-
opts.body = git_commit_body(commit);
340-
opts.author = git_commit_author(commit);
337+
commit_id = git_commit_id(commit);
338+
summary = git_commit_summary(commit);
339+
body = git_commit_body(commit);
340+
author = git_commit_author(commit);
341+
342+
if ((flags & GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER) != 0)
343+
opts.subject_prefix = "";
341344

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

345-
error = git_diff_format_email(out, diff, &opts);
348+
error = git_email_create_from_diff(out, diff, patch_no, total_patches, commit_id, summary, body, author, &opts);
346349

347350
git_diff_free(diff);
348351
return error;

0 commit comments

Comments
 (0)