Skip to content

Commit e2ecd25

Browse files
committed
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
2 parents 8827a58 + 4ba258b commit e2ecd25

File tree

6 files changed

+75
-28
lines changed

6 files changed

+75
-28
lines changed

Documentation/diff-options.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ ifndef::git-format-patch[]
2626
{git-diff? This is the default.}
2727
endif::git-format-patch[]
2828

29+
-s::
30+
--no-patch::
31+
Suppress diff output. Useful for commands like `git show` that
32+
show the patch by default, or to cancel the effect of `--patch`.
33+
2934
-U<n>::
3035
--unified=<n>::
3136
Generate diffs with <n> lines of context instead of

Documentation/git-log.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ include::rev-list-options.txt[]
9797

9898
include::pretty-formats.txt[]
9999

100-
Common diff options
100+
COMMON DIFF OPTIONS
101101
-------------------
102102

103103
:git-log: 1
104104
include::diff-options.txt[]
105105

106106
include::diff-generate-patch.txt[]
107107

108-
Examples
108+
EXAMPLES
109109
--------
110110
`git log --no-merges`::
111111

@@ -161,12 +161,12 @@ Examples
161161
`git log -3`::
162162
Limits the number of commits to show to 3.
163163

164-
Discussion
164+
DISCUSSION
165165
----------
166166

167167
include::i18n.txt[]
168168

169-
Configuration
169+
CONFIGURATION
170170
-------------
171171

172172
See linkgit:git-config[1] for core variables and linkgit:git-diff[1]

Documentation/git-show.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ include::pretty-options.txt[]
4545
include::pretty-formats.txt[]
4646

4747

48+
COMMON DIFF OPTIONS
49+
-------------------
50+
51+
:git-log: 1
52+
include::diff-options.txt[]
53+
54+
include::diff-generate-patch.txt[]
55+
56+
4857
EXAMPLES
4958
--------
5059

Documentation/rev-list-options.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,4 @@ options may be given. See linkgit:git-diff-files[1] for more options.
849849
-t::
850850

851851
Show the tree objects in the diff output. This implies '-r'.
852-
853-
-s::
854-
Suppress diff output.
855852
endif::git-rev-list[]

diff.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3505,22 +3505,27 @@ static int parse_submodule_opt(struct diff_options *options, const char *value)
35053505
return 1;
35063506
}
35073507

3508+
static void enable_patch_output(int *fmt) {
3509+
*fmt &= ~DIFF_FORMAT_NO_OUTPUT;
3510+
*fmt |= DIFF_FORMAT_PATCH;
3511+
}
3512+
35083513
int diff_opt_parse(struct diff_options *options, const char **av, int ac)
35093514
{
35103515
const char *arg = av[0];
35113516
const char *optarg;
35123517
int argcount;
35133518

35143519
/* Output format options */
3515-
if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch"))
3516-
options->output_format |= DIFF_FORMAT_PATCH;
3517-
else if (opt_arg(arg, 'U', "unified", &options->context))
3518-
options->output_format |= DIFF_FORMAT_PATCH;
3520+
if (!strcmp(arg, "-p") || !strcmp(arg, "-u") || !strcmp(arg, "--patch")
3521+
|| opt_arg(arg, 'U', "unified", &options->context))
3522+
enable_patch_output(&options->output_format);
35193523
else if (!strcmp(arg, "--raw"))
35203524
options->output_format |= DIFF_FORMAT_RAW;
3521-
else if (!strcmp(arg, "--patch-with-raw"))
3522-
options->output_format |= DIFF_FORMAT_PATCH | DIFF_FORMAT_RAW;
3523-
else if (!strcmp(arg, "--numstat"))
3525+
else if (!strcmp(arg, "--patch-with-raw")) {
3526+
enable_patch_output(&options->output_format);
3527+
options->output_format |= DIFF_FORMAT_RAW;
3528+
} else if (!strcmp(arg, "--numstat"))
35243529
options->output_format |= DIFF_FORMAT_NUMSTAT;
35253530
else if (!strcmp(arg, "--shortstat"))
35263531
options->output_format |= DIFF_FORMAT_SHORTSTAT;
@@ -3542,13 +3547,14 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
35423547
options->output_format |= DIFF_FORMAT_CHECKDIFF;
35433548
else if (!strcmp(arg, "--summary"))
35443549
options->output_format |= DIFF_FORMAT_SUMMARY;
3545-
else if (!strcmp(arg, "--patch-with-stat"))
3546-
options->output_format |= DIFF_FORMAT_PATCH | DIFF_FORMAT_DIFFSTAT;
3547-
else if (!strcmp(arg, "--name-only"))
3550+
else if (!strcmp(arg, "--patch-with-stat")) {
3551+
enable_patch_output(&options->output_format);
3552+
options->output_format |= DIFF_FORMAT_DIFFSTAT;
3553+
} else if (!strcmp(arg, "--name-only"))
35483554
options->output_format |= DIFF_FORMAT_NAME;
35493555
else if (!strcmp(arg, "--name-status"))
35503556
options->output_format |= DIFF_FORMAT_NAME_STATUS;
3551-
else if (!strcmp(arg, "-s"))
3557+
else if (!strcmp(arg, "-s") || !strcmp(arg, "--no-patch"))
35523558
options->output_format |= DIFF_FORMAT_NO_OUTPUT;
35533559
else if (!prefixcmp(arg, "--stat"))
35543560
/* --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)
36213627

36223628
/* flags options */
36233629
else if (!strcmp(arg, "--binary")) {
3624-
options->output_format |= DIFF_FORMAT_PATCH;
3630+
enable_patch_output(&options->output_format);
36253631
DIFF_OPT_SET(options, BINARY);
36263632
}
36273633
else if (!strcmp(arg, "--full-index"))

t/t4000-diff-format.sh

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ line 3'
1515
cat path0 >path1
1616
chmod +x path1
1717

18-
test_expect_success \
19-
'update-index --add two files with and without +x.' \
20-
'git update-index --add path0 path1'
18+
test_expect_success 'update-index --add two files with and without +x.' '
19+
git update-index --add path0 path1
20+
'
2121

2222
mv path0 path0-
2323
sed -e 's/line/Line/' <path0- >path0
2424
chmod +x path0
2525
rm -f path1
26-
test_expect_success \
27-
'git diff-files -p after editing work tree.' \
28-
'git diff-files -p >current'
26+
test_expect_success 'git diff-files -p after editing work tree.' '
27+
git diff-files -p >actual
28+
'
2929

3030
# that's as far as it comes
3131
if [ "$(git config --get core.filemode)" = false ]
@@ -55,8 +55,38 @@ deleted file mode 100755
5555
-line 3
5656
EOF
5757

58-
test_expect_success \
59-
'validate git diff-files -p output.' \
60-
'compare_diff_patch current expected'
58+
test_expect_success 'validate git diff-files -p output.' '
59+
compare_diff_patch expected actual
60+
'
61+
62+
test_expect_success 'git diff-files -s after editing work tree' '
63+
git diff-files -s >actual 2>err &&
64+
test_must_be_empty actual &&
65+
test_must_be_empty err
66+
'
67+
68+
test_expect_success 'git diff-files --no-patch as synonym for -s' '
69+
git diff-files --no-patch >actual 2>err &&
70+
test_must_be_empty actual &&
71+
test_must_be_empty err
72+
'
73+
74+
test_expect_success 'git diff-files --no-patch --patch shows the patch' '
75+
git diff-files --no-patch --patch >actual &&
76+
compare_diff_patch expected actual
77+
'
78+
79+
test_expect_success 'git diff-files --no-patch --patch-with-raw shows the patch and raw data' '
80+
git diff-files --no-patch --patch-with-raw >actual &&
81+
grep -q "^:100644 100755 .* 0000000000000000000000000000000000000000 M path0\$" actual &&
82+
tail -n +4 actual >actual-patch &&
83+
compare_diff_patch expected actual-patch
84+
'
85+
86+
test_expect_success 'git diff-files --patch --no-patch does not show the patch' '
87+
git diff-files --patch --no-patch >actual 2>err &&
88+
test_must_be_empty actual &&
89+
test_must_be_empty err
90+
'
6191

6292
test_done

0 commit comments

Comments
 (0)