summaryrefslogtreecommitdiff
path: root/builtin/log.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2013-02-21 12:05:02 -0800
committerJunio C Hamano <gitster@pobox.com>2013-04-22 07:59:22 -0700
commitbe1a07fe27695081537d31748b989f86c82383cc (patch)
tree36bec251b5259cf89c85a47158e6f75070726d43 /builtin/log.c
parent47d6c5f2c112df55997742eab8d974bfa1cf7b3e (diff)
downloadgit-jc/format-patch.tar.gz
format-patch: --inline-singlejc/format-patch
Some people may find it convenient to append a simple patch at the bottom of a discussion e-mail separated by a "scissors" mark, ready to be applied with "git am -c". Introduce "--inline-single" option to format-patch to do so. A typical usage example might be to start 'f'ollow-up to a discussion, write your message, conclude with "a patch to do so may look like this.", and then \C-u M-! git format-patch --inline-single -1 HEAD <ENTER> if you are an Emacs user. Users of other MUA's may want to consult their manuals to find an equivalent command to append output from an external command to the message being composed. It does not make any sense to use this mode when formatting multiple patches, or to combine this with options such as --attach, --inline, and --cover-letter, so some of such uses are forbidden. There may be more insane combination the check in this patch may not even bother to reject. Caveat emptor. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/log.c')
-rw-r--r--builtin/log.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/builtin/log.c b/builtin/log.c
index f2a11f4853..5696c6764e 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1051,6 +1051,19 @@ static int inline_callback(const struct option *opt, const char *arg, int unset)
return 0;
}
+static int inline_single_callback(const struct option *opt, const char *arg, int unset)
+{
+ struct rev_info *rev = (struct rev_info *)opt->value;
+ rev->mime_boundary = NULL;
+ rev->inline_single = 1;
+
+ /* defeat configured format.attach, format.thread, etc. */
+ free(default_attach);
+ default_attach = NULL;
+ thread = 0;
+ return 0;
+}
+
static int header_callback(const struct option *opt, const char *arg, int unset)
{
if (unset) {
@@ -1160,6 +1173,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
PARSE_OPT_OPTARG, thread_callback },
OPT_STRING(0, "signature", &signature, N_("signature"),
N_("add a signature")),
+ { OPTION_CALLBACK, 0, "inline-single", &rev, NULL,
+ N_("single patch appendable to the end of an e-mail body"),
+ PARSE_OPT_NOARG | PARSE_OPT_NONEG,
+ inline_single_callback },
OPT_BOOLEAN(0, "quiet", &quiet,
N_("don't print the patch filenames")),
OPT_END()
@@ -1196,6 +1213,15 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN |
PARSE_OPT_KEEP_DASHDASH);
+ /* Set defaults and check incompatible options */
+ if (rev.inline_single) {
+ use_stdout = 1;
+ if (thread)
+ die(_("inline-single and thread are incompatible."));
+ if (output_directory)
+ die(_("inline-single and output-directory are incompatible."));
+ }
+
if (0 < reroll_count) {
struct strbuf sprefix = STRBUF_INIT;
strbuf_addf(&sprefix, "%s v%d",
@@ -1362,6 +1388,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
/* nothing to do */
return 0;
total = nr;
+
+ if (rev.inline_single && total != 1)
+ die(_("inline-single is only for a single commit"));
+
if (!keep_subject && auto_number && total > 1)
numbered = 1;
if (numbered)
@@ -1372,6 +1402,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
else
cover_letter = (config_cover_letter == COVER_ON);
}
+ if (cover_letter > 0 && rev.inline_single)
+ die(_("inline-single and cover-letter are incompatible."));
if (in_reply_to || thread || cover_letter)
rev.ref_message_ids = xcalloc(1, sizeof(struct string_list));