{"thread":{"id":"21512","subject":"[PATCH 1/4] format-patch: Always generate a patch","startedAt":"2009-11-07T09:51:56Z","lastAt":"2009-11-07T09:51:56Z","messageCount":1,"participants":["Björn Gustavsson"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"127033","messageId":"4AF5433C.8030309@gmail.com","threadId":"21512","inReplyTo":null,"subject":"[PATCH 1/4] format-patch: Always generate a patch","fromName":"Björn Gustavsson","fromEmail":"bgustavsson@gmail.com","sentAt":"2009-11-07T09:51:56Z","receivedAt":"2009-11-07T09:51:56Z","isPatch":true,"sender":{"key":"bgustavsson@gmail.com","avatar":"https://avatars.githubusercontent.com/u/74840?v=4"},"body":"Jeff King recently reinstated -p to suppress the default diffstat\n(as -p used to work before 68daa64, about 14 months ago).\n\nHowever, -p is also needed in combination with certain options\n(e.g. --stat or --numstat) in order to produce any patch at all.\nThe documentation does not mention this.\n\nSince the purpose of format-patch is to produce a patch that\ncan be emailed, it does not make sense that certain combination\nof options will suppress the generation of the patch itself.\n\nTherefore:\n\n* Update 'git format-patch' to always generate a patch.\n\n* Since the --name-only, --name-status, and --check suppresses\n  the generation of the patch, disallow those options,\n  and remove the description of them in the documentation.\n\n* Remove the reference to -p in the description of -U.\n\n* Remove the descriptions of the options that are synonyms for -p\n  plus another option (--patch-with-raw and --patch-with-stat).\n\n* While at it, slightly tweak the description of -p itself\n  to say that it generates \"plain patches\", so that you can\n  think of -p as \"plain patch\" as an mnemonic aid.\n\nSigned-off-by: Björn Gustavsson <bgustavsson@gmail.com>\n---\nCompared to my previous patch, most of the changes are in\nthe commit message. It was straightforward to combine my\nprevious changes in the code with Peff's version. In the\ndocumentation, -p is now included.\n\n Documentation/diff-options.txt |   16 +++++++++++++---\n builtin-log.c                  |   21 ++++++++++++++++-----\n t/t4014-format-patch.sh        |   18 ++++++++++++++++++\n 3 files changed, 47 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex 9276fae..c58d085 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -14,7 +14,7 @@ endif::git-format-patch[]\n \n ifdef::git-format-patch[]\n -p::\n-\tGenerate patches without diffstat.\n+\tGenerate plain patches without any diffstats.\n endif::git-format-patch[]\n \n ifndef::git-format-patch[]\n@@ -27,14 +27,19 @@ endif::git-format-patch[]\n -U<n>::\n --unified=<n>::\n \tGenerate diffs with <n> lines of context instead of\n-\tthe usual three. Implies \"-p\".\n+\tthe usual three.\n+ifndef::git-format-patch[]\n+\tImplies \"-p\".\n+endif::git-format-patch[]\n \n --raw::\n \tGenerate the raw format.\n \t{git-diff-core? This is the default.}\n \n+ifndef::git-format-patch[]\n --patch-with-raw::\n \tSynonym for \"-p --raw\".\n+endif::git-format-patch[]\n \n --patience::\n \tGenerate a diff using the \"patience diff\" algorithm.\n@@ -71,21 +76,24 @@ endif::git-format-patch[]\n \tOutput a condensed summary of extended header information\n \tsuch as creations, renames and mode changes.\n \n+ifndef::git-format-patch[]\n --patch-with-stat::\n \tSynonym for \"-p --stat\".\n-\t{git-format-patch? This is the default.}\n+endif::git-format-patch[]\n \n -z::\n \tNUL-line termination on output.  This affects the --raw\n \toutput field terminator.  Also output from commands such\n \tas \"git-log\" will be delimited with NUL between commits.\n \n+ifndef::git-format-patch[]\n --name-only::\n \tShow only names of changed files.\n \n --name-status::\n \tShow only names and status of changed files. See the description\n \tof the `--diff-filter` option on what the status letters mean.\n+endif::git-format-patch[]\n \n --color::\n \tShow colored diff.\n@@ -115,11 +123,13 @@ override configuration settings.\n \tTurn off rename detection, even when the configuration\n \tfile gives the default to do so.\n \n+ifndef::git-format-patch[]\n --check::\n \tWarn if changes introduce trailing whitespace\n \tor an indent that uses a space before a tab. Exits with\n \tnon-zero status if problems are found. Not compatible with\n \t--exit-code.\n+endif::git-format-patch[]\n \n --full-index::\n \tInstead of the first handful of characters, show the full\ndiff --git a/builtin-log.c b/builtin-log.c\nindex 7b91c91..9df8dac 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -925,6 +925,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\t\"show patch format instead of default (patch + stat)\"),\n \t\tOPT_BOOLEAN(0, \"ignore-if-in-upstream\", &ignore_if_in_upstream,\n \t\t\t    \"don't include a patch matching a commit upstream\"),\n+\t\tOPT_BOOLEAN('p', NULL, &use_patch_format,\n+\t\t\t\"show patch format instead of default (patch + stat)\"),\n \t\tOPT_GROUP(\"Messaging\"),\n \t\t{ OPTION_CALLBACK, 0, \"add-header\", NULL, \"header\",\n \t\t\t    \"add email header\", PARSE_OPT_NONEG,\n@@ -1030,11 +1032,20 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \tif (argc > 1)\n \t\tdie (\"unrecognized argument: %s\", argv[1]);\n \n-\tif (use_patch_format)\n-\t\trev.diffopt.output_format |= DIFF_FORMAT_PATCH;\n-\telse if (!rev.diffopt.output_format ||\n-\t\t  rev.diffopt.output_format == DIFF_FORMAT_PATCH)\n-\t\trev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY | DIFF_FORMAT_PATCH;\n+\tif (rev.diffopt.output_format & DIFF_FORMAT_NAME)\n+\t\tdie(\"--name-only does not make sense\");\n+\tif (rev.diffopt.output_format & DIFF_FORMAT_NAME_STATUS)\n+\t\tdie(\"--name-status does not make sense\");\n+\tif (rev.diffopt.output_format & DIFF_FORMAT_CHECKDIFF)\n+\t\tdie(\"--check does not make sense\");\n+\n+\tif (!use_patch_format &&\n+\t\t(!rev.diffopt.output_format ||\n+\t\t rev.diffopt.output_format == DIFF_FORMAT_PATCH))\n+\t\trev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_SUMMARY;\n+\n+\t/* Always generate a patch */\n+\trev.diffopt.output_format |= DIFF_FORMAT_PATCH;\n \n \tif (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff)\n \t\tDIFF_OPT_SET(&rev.diffopt, BINARY);\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex cab6ce2..5689d59 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -536,4 +536,22 @@ test_expect_success 'format-patch --signoff' '\n \tgrep \"^Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>\"\n '\n \n+echo \"fatal: --name-only does not make sense\" > expect.name-only\n+echo \"fatal: --name-status does not make sense\" > expect.name-status\n+echo \"fatal: --check does not make sense\" > expect.check\n+\n+test_expect_success 'options no longer allowed for format-patch' '\n+\ttest_must_fail git format-patch --name-only 2> output &&\n+\ttest_cmp expect.name-only output &&\n+\ttest_must_fail git format-patch --name-status 2> output &&\n+\ttest_cmp expect.name-status output &&\n+\ttest_must_fail git format-patch --check 2> output &&\n+\ttest_cmp expect.check output'\n+\n+test_expect_success 'format-patch --numstat should produce a patch' '\n+\tgit format-patch --numstat --stdout master..side |\n+\tgrep \"^diff --git a/\" |\n+\twc -l |\n+\txargs test 6 = '\n+\n test_done\n-- \n1.6.5.1.69.g36942\n"}]}