Merge branch 'mm/diff-no-patch-synonym-to-s'

"git show -s" was less discoverable than it should be.

* mm/diff-no-patch-synonym-to-s:
  Documentation/git-log.txt: capitalize section names
  Documentation: move description of -s, --no-patch to diff-options.txt
  Documentation/git-show.txt: include common diff options, like git-log.txt
  diff: allow --patch & cie to override -s/--no-patch
  diff: allow --no-patch as synonym for -s
  t4000-diff-format.sh: modernize style
This commit is contained in:
Junio C Hamano 2013-07-22 11:23:27 -07:00
commit e2ecd252b5
6 changed files with 75 additions and 28 deletions

View File

@ -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<n>::
--unified=<n>::
Generate diffs with <n> lines of context instead of

View File

@ -97,7 +97,7 @@ include::rev-list-options.txt[]
include::pretty-formats.txt[]
Common diff options
COMMON DIFF OPTIONS
-------------------
:git-log: 1
@ -105,7 +105,7 @@ include::diff-options.txt[]
include::diff-generate-patch.txt[]
Examples
EXAMPLES
--------
`git log --no-merges`::
@ -161,12 +161,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]

View File

@ -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
--------

View File

@ -849,7 +849,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::
Suppress diff output.
endif::git-rev-list[]

30
diff.c
View File

@ -3505,6 +3505,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];
@ -3512,15 +3517,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;
@ -3542,13 +3547,14 @@ 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;
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 */
@ -3621,7 +3627,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"))

View File

@ -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- >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,38 @@ 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_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_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