[PATCH v2 1/4] Add format.coverletter option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When using --cover-letter, a cover letter is created even if the patch
series is only one patch long.

This patch cures that by making the behaviour configurable.
'format.coverletter' is an integer option, that tells git how long a
patch series needs to be for it to generate a cover letter.
If set to 0, git never creates a cover letter.

The default minimum patch series length is 2.

The --cover-letter option now accepts integer arguments (such as
--cover-letter=5), which have the same effect as setting the
'format.coverletter' option. 'never' instead of an integer has the
same effect as 0 has; it surpresses cover letter generation.
'always' has the same effect as setting the minimum length to 1.

Signed-off-by: Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx>
---
 builtin-log.c |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/builtin-log.c b/builtin-log.c
index 5eaec5d..157c8cf 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -436,6 +436,9 @@ static char **extra_cc;
 static int extra_cc_nr;
 static int extra_cc_alloc;
 
+static int cover_letter = 0;
+static int cover_letter_len = 2;
+
 static void add_header(const char *value)
 {
 	int len = strlen(value);
@@ -480,6 +483,10 @@ static int git_format_config(const char *var, const char *value, void *cb)
 	if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
 		return 0;
 	}
+	if (!strcmp(var, "format.coverletter")) {
+		cover_letter_len = git_config_int(var, value);
+		return 0;
+	}
 	if (!strcmp(var, "format.numbered")) {
 		if (value && !strcasecmp(value, "auto")) {
 			auto_number = 1;
@@ -752,7 +759,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	int numbered_files = 0;		/* _just_ numbers */
 	int subject_prefix = 0;
 	int ignore_if_in_upstream = 0;
-	int cover_letter = 0;
 	int boundary_count = 0;
 	int no_binary_diff = 0;
 	struct commit *origin = NULL, *head = NULL;
@@ -868,7 +874,15 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 			fmt_patch_suffix = argv[i] + 9;
 		else if (!strcmp(argv[i], "--cover-letter"))
 			cover_letter = 1;
-		else if (!strcmp(argv[i], "--no-binary"))
+		else if (!prefixcmp(argv[i], "--cover-letter=always")) {
+			cover_letter = 1;
+			cover_letter_len = 1;
+		} else if (!prefixcmp(argv[i], "--cover-letter=never"))
+			cover_letter = 0;
+		else if (!prefixcmp(argv[i], "--cover-letter=")) {
+			cover_letter = 1;
+			cover_letter_len = strtol(argv[i] + 15, NULL, 10);
+		} else if (!strcmp(argv[i], "--no-binary"))
 			no_binary_diff = 1;
 		else if (!prefixcmp(argv[i], "--add-header="))
 			add_header(argv[i] + 13);
@@ -877,6 +891,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	}
 	argc = j;
 
+	if (cover_letter_len <= 0)
+		cover_letter = 0;
+
 	if (do_signoff) {
 		const char *committer;
 		const char *endpos;
@@ -1010,6 +1027,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		list[nr - 1] = commit;
 	}
 	total = nr;
+	if (total < cover_letter_len)
+		cover_letter = 0;
 	if (!keep_subject && auto_number && total > 1)
 		numbered = 1;
 	if (numbered)
-- 
1.6.2.2.446.gfbdc0

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]