1 /* 2 * Copyright (C) the libgit2 contributors. All rights reserved. 3 * 4 * This file is part of libgit2, distributed under the GNU GPL v2 with 5 * a Linking Exception. For full terms see the included COPYING file. 6 */ 7 /** 8 * License: GPL-2.0(Linking Exception) 9 */ 10 module libgit2.email; 11 12 13 private static import libgit2.buffer; 14 private static import libgit2.diff; 15 private static import libgit2.diff; 16 private static import libgit2.oid; 17 private static import libgit2.types; 18 private import libgit2.common: GIT_EXTERN; 19 20 /* 21 * @file git2/email.h 22 * @brief Git email formatting and application routines. 23 * @ingroup Git 24 * @{ 25 */ 26 extern (C): 27 nothrow @nogc: 28 29 /** 30 * Formatting options for diff e-mail generation 31 */ 32 enum git_email_create_flags_t 33 { 34 /** 35 * Normal patch, the default 36 */ 37 GIT_EMAIL_CREATE_DEFAULT = 0, 38 39 /** 40 * Do not include patch numbers in the subject prefix. 41 */ 42 GIT_EMAIL_CREATE_OMIT_NUMBERS = 1u << 0, 43 44 /** 45 * Include numbers in the subject prefix even when the 46 * patch is for a single commit (1/1). 47 */ 48 GIT_EMAIL_CREATE_ALWAYS_NUMBER = 1u << 1, 49 50 /** Do not perform rename or similarity detection. */ 51 GIT_EMAIL_CREATE_NO_RENAMES = 1u << 2, 52 } 53 54 /** 55 * Options for controlling the formatting of the generated e-mail. 56 */ 57 struct git_email_create_options 58 { 59 uint version_; 60 61 /** 62 * see `git_email_create_flags_t` above 63 */ 64 uint flags; 65 66 /** 67 * Options to use when creating diffs 68 */ 69 libgit2.diff.git_diff_options diff_opts; 70 71 /** 72 * Options for finding similarities within diffs 73 */ 74 libgit2.diff.git_diff_find_options diff_find_opts; 75 76 /** 77 * The subject prefix, by default "PATCH". If set to an empty 78 * string ("") then only the patch numbers will be shown in the 79 * prefix. If the subject_prefix is empty and patch numbers 80 * are not being shown, the prefix will be omitted entirely. 81 */ 82 const (char)* subject_prefix; 83 84 /** 85 * The starting patch number; this cannot be 0. By default, 86 * this is 1. 87 */ 88 size_t start_number; 89 90 /** The "re-roll" number. By default, there is no re-roll. */ 91 size_t reroll_number; 92 } 93 94 /* 95 * By default, our options include rename detection and binary 96 * diffs to match `git format-patch`. 97 */ 98 enum GIT_EMAIL_CREATE_OPTIONS_VERSION = 1; 99 100 pragma(inline, true) 101 pure nothrow @safe @nogc @live 102 .git_email_create_options GIT_EMAIL_CREATE_OPTIONS_INIT() 103 104 do 105 { 106 .git_email_create_options OUTPUT = 107 { 108 version_: .GIT_EMAIL_CREATE_OPTIONS_VERSION, 109 flags: .git_email_create_flags_t.GIT_EMAIL_CREATE_DEFAULT, 110 diff_opts: 111 { 112 version_: libgit2.diff.GIT_DIFF_OPTIONS_VERSION, 113 flags: libgit2.diff.git_diff_option_t.GIT_DIFF_SHOW_BINARY, 114 ignore_submodules: libgit2.types.git_submodule_ignore_t.GIT_SUBMODULE_IGNORE_UNSPECIFIED, 115 pathspec: 116 { 117 strings: null, 118 count: 0, 119 }, 120 notify_cb: null, 121 progress_cb: null, 122 payload: null, 123 context_lines: 3, 124 }, 125 diff_find_opts: libgit2.diff.GIT_DIFF_FIND_OPTIONS_INIT, 126 }; 127 128 return OUTPUT; 129 } 130 131 /** 132 * Create a diff for a commit in mbox format for sending via email. 133 * 134 * Params: 135 * out_ = buffer to store the e-mail patch in 136 * diff = the changes to include in the email 137 * patch_idx = the patch index 138 * patch_count = the total number of patches that will be included 139 * commit_id = the commit id for this change 140 * summary = the commit message for this change 141 * body_ = optional text to include above the diffstat 142 * author = the person who authored this commit 143 * opts = email creation options 144 */ 145 @GIT_EXTERN 146 int git_email_create_from_diff(libgit2.buffer.git_buf* out_, libgit2.diff.git_diff* diff, size_t patch_idx, size_t patch_count, const (libgit2.oid.git_oid)* commit_id, const (char)* summary, const (char)* body_, const (libgit2.types.git_signature)* author, const (.git_email_create_options)* opts); 147 148 /** 149 * Create a diff for a commit in mbox format for sending via email. 150 * The commit must not be a merge commit. 151 * 152 * Params: 153 * out_ = buffer to store the e-mail patch in 154 * commit = commit to create a patch for 155 * opts = email creation options 156 */ 157 @GIT_EXTERN 158 int git_email_create_from_commit(libgit2.buffer.git_buf* out_, libgit2.types.git_commit* commit, const (.git_email_create_options)* opts); 159 160 /* @} */