{"thread":{"id":"10629","subject":"[PATCH] format-patch: Add configuration and off switch for --numbered","startedAt":"2007-11-04T03:38:24Z","lastAt":"2007-11-04T05:50:23Z","messageCount":4,"participants":["Brian Gernhardt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"58202","messageId":"20071104033824.GA56097@Hermes.local","threadId":"10629","inReplyTo":null,"subject":"[PATCH] format-patch: Add configuration and off switch for --numbered","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2007-11-04T03:38:24Z","receivedAt":"2007-11-04T03:38:24Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"format.numbered is a tri-state variable.  Boolean values enable or\ndisable numbering by default and \"auto\" enables number when outputting\nmore than one patch.\n\n--no-numbered (short: -N) will disable numbering.\n\nSigned-off-by: Brian Gernhardt <benji@silverinsanity.com>\n---\n\n Pick your own numbering adventure.  Should make everyone happy, but\n will probably do the exact opposite.  So it goes.\n\n Documentation/config.txt           |    6 ++++++\n Documentation/git-format-patch.txt |   12 ++++++++----\n builtin-log.c                      |   19 ++++++++++++++++++-\n 3 files changed, 32 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex edf50cd..c2f9f14 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -432,6 +432,12 @@ fetch.unpackLimit::\n \tpack from a push can make the push operation complete faster,\n \tespecially on slow filesystems.\n \n+format.numbered::\n+\tA boolean which can enable sequence numbers in patch subjects.\n+\tSeting this option to \"auto\" will enable it only if there is\n+\tmore than one patch.  See --numbered option in\n+\tgitlink:git-format-patch[1].\n+\n format.headers::\n \tAdditional email headers to include in a patch to be submitted\n \tby mail.  See gitlink:git-format-patch[1].\ndiff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt\nindex f0617ef..92c0ab6 100644\n--- a/Documentation/git-format-patch.txt\n+++ b/Documentation/git-format-patch.txt\n@@ -9,7 +9,7 @@ git-format-patch - Prepare patches for e-mail submission\n SYNOPSIS\n --------\n [verse]\n-'git-format-patch' [-n | -k] [-o <dir> | --stdout] [--thread]\n+'git-format-patch' [-n | -N | -k] [-o <dir> | --stdout] [--thread]\n                    [--attach[=<boundary>] | --inline[=<boundary>]]\n                    [-s | --signoff] [<common diff options>]\n                    [--start-number <n>] [--numbered-files]\n@@ -77,6 +77,9 @@ include::diff-options.txt[]\n -n|--numbered::\n \tName output in '[PATCH n/m]' format.\n \n+-N|--no-numbered::\n+\tName output in '[PATCH]' format.\n+\n --start-number <n>::\n \tStart numbering the patches at <n> instead of 1.\n \n@@ -142,15 +145,16 @@ not add any suffix.\n \n CONFIGURATION\n -------------\n-You can specify extra mail header lines to be added to each\n-message in the repository configuration.  You can also specify\n-new defaults for the subject prefix and file suffix.\n+You can specify extra mail header lines to be added to each message\n+in the repository configuration, new defaults for the subject prefix\n+and file suffix, and number patches when outputting more than one.\n \n ------------\n [format]\n         headers = \"Organization: git-foo\\n\"\n         subjectprefix = CHANGE\n         suffix = .txt\n+        numbered = auto\n ------------\n \n \ndiff --git a/builtin-log.c b/builtin-log.c\nindex e8b982d..22afa1a 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -273,6 +273,8 @@ static int istitlechar(char c)\n static char *extra_headers = NULL;\n static int extra_headers_size = 0;\n static const char *fmt_patch_suffix = \".patch\";\n+static int numbered = 0;\n+static int auto_number = 0;\n \n static int git_format_config(const char *var, const char *value)\n {\n@@ -297,6 +299,15 @@ static int git_format_config(const char *var, const char *value)\n \tif (!strcmp(var, \"diff.color\") || !strcmp(var, \"color.diff\")) {\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"format.numbered\")) {\n+\t\tif (!strcasecmp(value, \"auto\")) {\n+\t\t\tauto_number = 1;\n+\t\t\treturn 0;\n+\t\t}\n+\n+\t\tnumbered = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n \n \treturn git_log_config(var, value);\n }\n@@ -466,7 +477,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \tstruct rev_info rev;\n \tint nr = 0, total, i, j;\n \tint use_stdout = 0;\n-\tint numbered = 0;\n \tint start_number = -1;\n \tint keep_subject = 0;\n \tint numbered_files = 0;\t\t/* _just_ numbers */\n@@ -503,6 +513,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\telse if (!strcmp(argv[i], \"-n\") ||\n \t\t\t\t!strcmp(argv[i], \"--numbered\"))\n \t\t\tnumbered = 1;\n+\t\telse if (!strcmp(argv[i], \"-N\") ||\n+\t\t\t\t!strcmp(argv[i], \"--no-numbered\")) {\n+\t\t\tnumbered = 0;\n+\t\t\tauto_number = 0;\n+\t\t}\n \t\telse if (!prefixcmp(argv[i], \"--start-number=\"))\n \t\t\tstart_number = strtol(argv[i] + 15, NULL, 10);\n \t\telse if (!strcmp(argv[i], \"--numbered-files\"))\n@@ -642,6 +657,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\tlist[nr - 1] = commit;\n \t}\n \ttotal = nr;\n+\tif (!keep_subject && auto_number && total > 1)\n+\t\tnumbered = 1;\n \tif (numbered)\n \t\trev.total = total + start_number - 1;\n \trev.add_signoff = add_signoff;\n-- \n1.5.3.5.529.ge3d6d-dirty\n"},{"id":"58209","messageId":"7vejf6vd17.fsf@gitster.siamese.dyndns.org","threadId":"10629","inReplyTo":"20071104033824.GA56097@Hermes.local","subject":"Re: [PATCH] format-patch: Add configuration and off switch for --numbered","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-11-04T04:40:36Z","receivedAt":"2007-11-04T04:40:36Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The change looks good.  Tests needed.\n"},{"id":"58210","messageId":"C9FC46B6-AF2E-4E61-A272-2C46BFA33641@silverinsanity.com","threadId":"10629","inReplyTo":"7vejf6vd17.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] format-patch: Add configuration and off switch for --numbered","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2007-11-04T04:54:49Z","receivedAt":"2007-11-04T04:54:49Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"\nOn Nov 4, 2007, at 12:40 AM, Junio C Hamano wrote:\n\n> The change looks good.  Tests needed.\n\nThought so.  Somebody's not happy.  ;-)\n\nI was going to modify the existing tests for --numbered, but  \ndiscovered that there were none.  Having nothing to start with, I  \ndidn't add.\n\nThat said, I'll try to hack something up.\n\n~~ Brian\n"},{"id":"58219","messageId":"20071104055023.GA46329@Hermes.local","threadId":"10629","inReplyTo":"C9FC46B6-AF2E-4E61-A272-2C46BFA33641@silverinsanity.com","subject":"[PATCH 2/1] format-patch: Test --[no-]numbered and format.numbered","fromName":"Brian Gernhardt","fromEmail":"benji@silverinsanity.com","sentAt":"2007-11-04T05:50:23Z","receivedAt":"2007-11-04T05:50:23Z","isPatch":true,"sender":{"key":"benji@silverinsanity.com","avatar":"https://gravatar.com/avatar/e06c101dbc25c68114d859b4a9ec7cf8a2c52fd2b0270ef0eac0e2e63ff22311?d=mp&s=160"},"body":"Just because there wasn't a test for --numbered isn't a good reason\nnot to test format.numbered.  So now we test both.\n\nSigned-off-by: Brian Gernhardt <benji@silverinsanity.com>\n---\n\n And here's that something I hacked up.  Hmm... that doesn't sound\n sanitary.\n\n As a side note, send-email is hard to troubleshoot.  Is there a way to\n get it to give more than \"your setup doesn't work\"?  And is the pile of\n warnings (mostly \"Use of uninitialized value\") in Term::Readline just a\n problem in my setup?  I tried to use it instead of mutt and did not\n have a happy experience.\n\n t/t4021-format-patch-numbered.sh |  106 ++++++++++++++++++++++++++++++++++++++\n 1 files changed, 106 insertions(+), 0 deletions(-)\n create mode 100755 t/t4021-format-patch-numbered.sh\n\ndiff --git a/t/t4021-format-patch-numbered.sh b/t/t4021-format-patch-numbered.sh\nnew file mode 100755\nindex 0000000..43d64bb\n--- /dev/null\n+++ b/t/t4021-format-patch-numbered.sh\n@@ -0,0 +1,106 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2006 Brian C Gernhardt\n+#\n+\n+test_description='Format-patch numbering options'\n+\n+. ./test-lib.sh\n+\n+test_expect_success setup '\n+\n+\techo A > file &&\n+\tgit add file &&\n+\tgit commit -m First &&\n+\n+\techo B >> file &&\n+\tgit commit -a -m Second &&\n+\n+\techo C >> file &&\n+\tgit commit -a -m Third\n+\n+'\n+\n+# Each of these gets used multiple times.\n+\n+test_num_no_numbered() {\n+\tcnt=$(grep \"^Subject: \\[PATCH\\]\" $1 | wc -l) &&\n+\ttest $cnt = $2\n+}\n+\n+test_single_no_numbered() {\n+\ttest_num_no_numbered $1 1\n+}\n+\n+test_no_numbered() {\n+\ttest_num_no_numbered $1 2\n+}\n+\n+test_single_numbered() {\n+\tgrep \"^Subject: \\[PATCH 1/1\\]\" $1\n+}\n+\n+test_numbered() {\n+\tgrep \"^Subject: \\[PATCH 1/2\\]\" $1 &&\n+\tgrep \"^Subject: \\[PATCH 2/2\\]\" $1\n+}\n+\n+test_expect_success 'Default: no numbered' '\n+\n+\tgit format-patch --stdout HEAD~2 >patch0 &&\n+\ttest_no_numbered patch0\n+\n+'\n+\n+test_expect_success 'Use --numbered' '\n+\n+\tgit format-patch --numbered --stdout HEAD~2 >patch1 &&\n+\ttest_numbered patch1\n+\n+'\n+\n+test_expect_success 'format.numbered = true' '\n+\n+\tgit config format.numbered true &&\n+\tgit format-patch --stdout HEAD~2 >patch2 &&\n+\ttest_numbered patch2\n+\n+'\n+\n+test_expect_success 'format.numbered && single patch' '\n+\n+\tgit format-patch --stdout HEAD^ > patch3 &&\n+\ttest_single_numbered patch3\n+\n+'\n+\n+test_expect_success 'format.numbered && --no-numbered' '\n+\n+\tgit format-patch --no-numbered --stdout HEAD~2 >patch4 &&\n+\ttest_no_numbered patch4\n+\n+'\n+\n+test_expect_success 'format.numbered = auto' '\n+\n+\tgit config format.numbered auto\n+\tgit format-patch --stdout HEAD~2 > patch5 &&\n+\ttest_numbered patch5\n+\n+'\n+\n+test_expect_success 'format.numbered = auto && single patch' '\n+\n+\tgit format-patch --stdout HEAD^ > patch6 &&\n+\ttest_single_no_numbered patch6\n+\n+'\n+\n+test_expect_success 'format.numbered = auto && --no-numbered' '\n+\n+\tgit format-patch --no-numbered --stdout HEAD~2 > patch7 &&\n+\ttest_no_numbered patch7\n+\n+'\n+\n+test_done\n-- \n1.5.3.5.530.gcd7a\n"}]}