From 8ade9b140f099540bcdec5bcf660faaf05b5e3ee Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Tue, 16 Jul 2013 10:05:35 +0200 Subject: t4000-diff-format.sh: modernize style Signed-off-by: Matthieu Moy Reviewed-by: Jonathan Nieder Signed-off-by: Junio C Hamano diff --git a/t/t4000-diff-format.sh b/t/t4000-diff-format.sh index 6ddd469..2b5dffc 100755 --- a/t/t4000-diff-format.sh +++ b/t/t4000-diff-format.sh @@ -15,17 +15,17 @@ line 3' cat path0 >path1 chmod +x path1 -test_expect_success \ - 'update-index --add two files with and without +x.' \ - 'git update-index --add path0 path1' +test_expect_success 'update-index --add two files with and without +x.' ' + git update-index --add path0 path1 +' mv path0 path0- sed -e 's/line/Line/' path0 chmod +x path0 rm -f path1 -test_expect_success \ - 'git diff-files -p after editing work tree.' \ - 'git diff-files -p >current' +test_expect_success 'git diff-files -p after editing work tree.' ' + git diff-files -p >actual +' # that's as far as it comes if [ "$(git config --get core.filemode)" = false ] @@ -55,8 +55,8 @@ deleted file mode 100755 -line 3 EOF -test_expect_success \ - 'validate git diff-files -p output.' \ - 'compare_diff_patch current expected' +test_expect_success 'validate git diff-files -p output.' ' + compare_diff_patch expected actual +' test_done -- cgit v0.10.2-6-g49f6 From d09cd15d19de23aca532a85f6d27a71b2baceb3f Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Tue, 16 Jul 2013 10:05:36 +0200 Subject: diff: allow --no-patch as synonym for -s This follows the usual convention of having a --no-foo option to negate --foo. Signed-off-by: Matthieu Moy Reviewed-by: Jonathan Nieder Signed-off-by: Junio C Hamano diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index 3bdbf5e..1acef37 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -839,5 +839,6 @@ options may be given. See linkgit:git-diff-files[1] for more options. Show the tree objects in the diff output. This implies '-r'. -s:: +--no-patch:: Suppress diff output. endif::git-rev-list[] diff --git a/diff.c b/diff.c index f0b3e7c..cc41d88 100644 --- a/diff.c +++ b/diff.c @@ -3540,7 +3540,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) options->output_format |= DIFF_FORMAT_NAME; else if (!strcmp(arg, "--name-status")) options->output_format |= DIFF_FORMAT_NAME_STATUS; - else if (!strcmp(arg, "-s")) + else if (!strcmp(arg, "-s") || !strcmp(arg, "--no-patch")) options->output_format |= DIFF_FORMAT_NO_OUTPUT; else if (!prefixcmp(arg, "--stat")) /* --stat, --stat-width, --stat-name-width, or --stat-count */ diff --git a/t/t4000-diff-format.sh b/t/t4000-diff-format.sh index 2b5dffc..3b9a9ae 100755 --- a/t/t4000-diff-format.sh +++ b/t/t4000-diff-format.sh @@ -59,4 +59,16 @@ test_expect_success 'validate git diff-files -p output.' ' compare_diff_patch expected actual ' +test_expect_success 'git diff-files -s after editing work tree' ' + git diff-files -s >actual 2>err && + test_must_be_empty actual && + test_must_be_empty err +' + +test_expect_success 'git diff-files --no-patch as synonym for -s' ' + git diff-files --no-patch >actual 2>err && + test_must_be_empty actual && + test_must_be_empty err +' + test_done -- cgit v0.10.2-6-g49f6 From 71482d389d0b214d2cfc2adf788ba1011a7dcb18 Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Tue, 16 Jul 2013 10:05:37 +0200 Subject: diff: allow --patch & cie to override -s/--no-patch All options that trigger a patch output now override --no-patch. The case of --binary deserves extra attention: the name may suggest that it turns a normal patch into a binary patch, but it actually already enables patch output when normally disabled (e.g. "git log --binary" displays a patch), hence it makes sense for "git show --no-patch --binary" to display the binary patch. Signed-off-by: Matthieu Moy Reviewed-by: Jonathan Nieder Signed-off-by: Junio C Hamano diff --git a/diff.c b/diff.c index cc41d88..5290306 100644 --- a/diff.c +++ b/diff.c @@ -3497,6 +3497,11 @@ static int parse_submodule_opt(struct diff_options *options, const char *value) return 1; } +static void enable_patch_output(int *fmt) { + *fmt &= ~DIFF_FORMAT_NO_OUTPUT; + *fmt |= DIFF_FORMAT_PATCH; +} + int diff_opt_parse(struct diff_options *options, const char **av, int ac) { const char *arg = av[0]; @@ -3504,15 +3509,15 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) int argcount; /* Output format options */ - if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch")) - options->output_format |= DIFF_FORMAT_PATCH; - else if (opt_arg(arg, 'U', "unified", &options->context)) - options->output_format |= DIFF_FORMAT_PATCH; + if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch") + || opt_arg(arg, 'U', "unified", &options->context)) + enable_patch_output(&options->output_format); else if (!strcmp(arg, "--raw")) options->output_format |= DIFF_FORMAT_RAW; - else if (!strcmp(arg, "--patch-with-raw")) - options->output_format |= DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW; - else if (!strcmp(arg, "--numstat")) + else if (!strcmp(arg, "--patch-with-raw")) { + enable_patch_output(&options->output_format); + options->output_format |= DIFF_FORMAT_RAW; + } else if (!strcmp(arg, "--numstat")) options->output_format |= DIFF_FORMAT_NUMSTAT; else if (!strcmp(arg, "--shortstat")) options->output_format |= DIFF_FORMAT_SHORTSTAT; @@ -3534,9 +3539,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) options->output_format |= DIFF_FORMAT_CHECKDIFF; else if (!strcmp(arg, "--summary")) options->output_format |= DIFF_FORMAT_SUMMARY; - else if (!strcmp(arg, "--patch-with-stat")) - options->output_format |= DIFF_FORMAT_PATCH | DIFF_FORMAT_DIFFSTAT; - else if (!strcmp(arg, "--name-only")) + else if (!strcmp(arg, "--patch-with-stat")) { + enable_patch_output(&options->output_format); + options->output_format |= DIFF_FORMAT_DIFFSTAT; + } else if (!strcmp(arg, "--name-only")) options->output_format |= DIFF_FORMAT_NAME; else if (!strcmp(arg, "--name-status")) options->output_format |= DIFF_FORMAT_NAME_STATUS; @@ -3611,7 +3617,7 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac) /* flags options */ else if (!strcmp(arg, "--binary")) { - options->output_format |= DIFF_FORMAT_PATCH; + enable_patch_output(&options->output_format); DIFF_OPT_SET(options, BINARY); } else if (!strcmp(arg, "--full-index")) diff --git a/t/t4000-diff-format.sh b/t/t4000-diff-format.sh index 3b9a9ae..8de36b7 100755 --- a/t/t4000-diff-format.sh +++ b/t/t4000-diff-format.sh @@ -71,4 +71,22 @@ test_expect_success 'git diff-files --no-patch as synonym for -s' ' test_must_be_empty err ' +test_expect_success 'git diff-files --no-patch --patch shows the patch' ' + git diff-files --no-patch --patch >actual && + compare_diff_patch expected actual +' + +test_expect_success 'git diff-files --no-patch --patch-with-raw shows the patch and raw data' ' + git diff-files --no-patch --patch-with-raw >actual && + grep -q "^:100644 100755 .* 0000000000000000000000000000000000000000 M path0\$" actual && + tail -n +4 actual >actual-patch && + compare_diff_patch expected actual-patch +' + +test_expect_success 'git diff-files --patch --no-patch does not show the patch' ' + git diff-files --patch --no-patch >actual 2>err && + test_must_be_empty actual && + test_must_be_empty err +' + test_done -- cgit v0.10.2-6-g49f6 From 0791ab02c2e81e3d3c6815ce36085072d2c4cb4d Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Tue, 16 Jul 2013 10:05:38 +0200 Subject: Documentation/git-show.txt: include common diff options, like git-log.txt Signed-off-by: Matthieu Moy Reviewed-by: Jonathan Nieder Signed-off-by: Junio C Hamano diff --git a/Documentation/git-show.txt b/Documentation/git-show.txt index ae4edcc..4e617e6 100644 --- a/Documentation/git-show.txt +++ b/Documentation/git-show.txt @@ -45,6 +45,15 @@ include::pretty-options.txt[] include::pretty-formats.txt[] +COMMON DIFF OPTIONS +------------------- + +:git-log: 1 +include::diff-options.txt[] + +include::diff-generate-patch.txt[] + + EXAMPLES -------- -- cgit v0.10.2-6-g49f6 From 7b02c834638f6bea4cf14e4981702103b478ff4d Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Tue, 16 Jul 2013 10:05:39 +0200 Subject: Documentation: move description of -s, --no-patch to diff-options.txt Technically, "-s, --no-patch" is implemented in diff.c ("git diff --no-patch" is essentially useless, but valid). From the user point of view, this allows the documentation to show up in "git show --help", which is one of the most useful use of the option. While we're there, add a sentence explaining why the option can be useful. Signed-off-by: Matthieu Moy Reviewed-by: Jonathan Nieder Signed-off-by: Junio C Hamano diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index 104579d..fe6a1cb 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -26,6 +26,11 @@ ifndef::git-format-patch[] {git-diff? This is the default.} endif::git-format-patch[] +-s:: +--no-patch:: + Suppress diff output. Useful for commands like `git show` that + show the patch by default, or to cancel the effect of `--patch`. + -U:: --unified=:: Generate diffs with lines of context instead of diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index 1acef37..c23688a 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -837,8 +837,4 @@ options may be given. See linkgit:git-diff-files[1] for more options. -t:: Show the tree objects in the diff output. This implies '-r'. - --s:: ---no-patch:: - Suppress diff output. endif::git-rev-list[] -- cgit v0.10.2-6-g49f6 From 4ba258b7e1020e8e3f321ca2df01e34cd71bee88 Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Tue, 16 Jul 2013 10:05:40 +0200 Subject: Documentation/git-log.txt: capitalize section names This is the convention in most other files and even at the beginning of git-log.txt Signed-off-by: Matthieu Moy Reviewed-by: Jonathan Nieder Signed-off-by: Junio C Hamano diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index a976534..88f90ed 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -84,7 +84,7 @@ include::rev-list-options.txt[] include::pretty-formats.txt[] -Common diff options +COMMON DIFF OPTIONS ------------------- :git-log: 1 @@ -92,7 +92,7 @@ include::diff-options.txt[] include::diff-generate-patch.txt[] -Examples +EXAMPLES -------- `git log --no-merges`:: @@ -143,12 +143,12 @@ Examples `git log -3`:: Limits the number of commits to show to 3. -Discussion +DISCUSSION ---------- include::i18n.txt[] -Configuration +CONFIGURATION ------------- See linkgit:git-config[1] for core variables and linkgit:git-diff[1] -- cgit v0.10.2-6-g49f6