Commit 971ed7537cae0b7f27dab7fa310d71a4cce3db27

Edward Thomson 2021-09-13T13:26:55

email: introduce 'append_from_diff' Introduce `git_email__append_from_diff` so that we don't always overwrite the input buffer.

diff --git a/src/email.c b/src/email.c
index b238f5b..0bec515 100644
--- a/src/email.c
+++ b/src/email.c
@@ -5,6 +5,8 @@
  * a Linking Exception. For full terms see the included COPYING file.
  */
 
+#include "email.h"
+
 #include "buffer.h"
 #include "common.h"
 #include "diff_generate.h"
@@ -187,7 +189,7 @@ static int append_patches(git_buf *out, git_diff *diff)
 	return error;
 }
 
-int git_email_create_from_diff(
+int git_email__append_from_diff(
 	git_buf *out,
 	git_diff *diff,
 	size_t patch_idx,
@@ -227,6 +229,29 @@ int git_email_create_from_diff(
 	return error;
 }
 
+int git_email_create_from_diff(
+	git_buf *out,
+	git_diff *diff,
+	size_t patch_idx,
+	size_t patch_count,
+	const git_oid *commit_id,
+	const char *summary,
+	const char *body,
+	const git_signature *author,
+	const git_email_create_options *given_opts)
+{
+	int error;
+
+	git_buf_sanitize(out);
+	git_buf_clear(out);
+
+	error = git_email__append_from_diff(out, diff, patch_idx,
+		patch_count, commit_id, summary, body, author,
+		given_opts);
+
+	return error;
+}
+
 int git_email_create_from_commit(
 	git_buf *out,
 	git_commit *commit,
diff --git a/src/email.h b/src/email.h
new file mode 100644
index 0000000..7aeb462
--- /dev/null
+++ b/src/email.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_email_h__
+#define INCLUDE_email_h__
+
+#include "common.h"
+
+#include "git2/email.h"
+
+extern int git_email__append_from_diff(
+	git_buf *out,
+	git_diff *diff,
+	size_t patch_idx,
+	size_t patch_count,
+	const git_oid *commit_id,
+	const char *summary,
+	const char *body,
+	const git_signature *author,
+	const git_email_create_options *given_opts);
+
+#endif