{"thread":{"id":"21352","subject":"[PATCH 1/3] format-patch: Make implementation and documentation agree","startedAt":"2009-10-25T15:55:27Z","lastAt":"2009-10-25T15:55:27Z","messageCount":1,"participants":["Björn Gustavsson"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"125895","messageId":"4AE474EF.1050609@gmail.com","threadId":"21352","inReplyTo":null,"subject":"[PATCH 1/3] format-patch: Make implementation and documentation agree","fromName":"Björn Gustavsson","fromEmail":"bgustavsson@gmail.com","sentAt":"2009-10-25T15:55:27Z","receivedAt":"2009-10-25T15:55:27Z","isPatch":true,"sender":{"key":"bgustavsson@gmail.com","avatar":"https://avatars.githubusercontent.com/u/74840?v=4"},"body":"The documentation for the -p option for format-patch says:\n\"Generate patches without diffstat.\"\n\nStarting with commit 68daa64d, however, -p no longer suppresses the\ndiffstat and is a no-op *most* of the time. It is still needed when\n--stat (or one of the other 'stat' options) is given in order to\nproduce a patch at all.\n\nSince no-one seems to have noticed (or cared) that -p no longer\nsuppresses the diffstat (after more than a year), it makes most\nsense to fix the documentation (rather than the implementation).\nThe trouble is that -p is still sometimes needed, so to simplify\nthe documentation, it would be best to change the implementation\nas well.\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. They don't\n  make sense for format-patch anyway.\n\n* Remove the description of -p from 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* Remove the description of the options that are no longer\n  allowed (--name-only, --name-status, and --check).\n---\n Documentation/diff-options.txt |   19 ++++++++++++-------\n builtin-log.c                  |   12 +++++++++++-\n t/t4014-format-patch.sh        |   18 ++++++++++++++++++\n 3 files changed, 41 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt\nindex 9276fae..673fbb0 100644\n--- a/Documentation/diff-options.txt\n+++ b/Documentation/diff-options.txt\n@@ -12,11 +12,6 @@ endif::git-log[]\n endif::git-diff[]\n endif::git-format-patch[]\n \n-ifdef::git-format-patch[]\n--p::\n-\tGenerate patches without diffstat.\n-endif::git-format-patch[]\n-\n ifndef::git-format-patch[]\n -p::\n -u::\n@@ -27,14 +22,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 +71,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 +118,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 25e21ed..7b2cde2 100644\n--- a/builtin-log.c\n+++ b/builtin-log.c\n@@ -1027,9 +1027,19 @@ 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 (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 (!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+\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 531f5b7..f826348 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -515,4 +515,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"}]}