Skip to content

Commit b449005

Browse files
committed
show -c: show patch text
Traditionally, "show" defaulted to "show --cc" (dense combined patch), but asking for combined patch with "show -c" didn't turn the patch output format on; the placement of this logic in setup_revisions() dates back to cd2bdc5 (Common option parsing for "git log --diff" and friends, 2006-04-14). This unfortunately cannot be done as a trivial change of "if dense combined is asked, default to patch format" done in setup_revisions() to "if any combined is asked, default to patch format", as "diff-tree -c" needs to default to raw, while "diff-tree --cc" needs to default to patch, and they share the codepath. These command specific defaults are now handled in the new "tweak" callback that can be customized by individual command implementations. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 32962c9 commit b449005

File tree

6 files changed

+62
-8
lines changed

6 files changed

+62
-8
lines changed

builtin-diff-tree.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,33 @@ static const char diff_tree_usage[] =
9292
" --root include the initial commit as diff against /dev/null\n"
9393
COMMON_DIFF_OPTIONS_HELP;
9494

95+
static void diff_tree_tweak_rev(struct rev_info *rev, struct setup_revision_opt *opt)
96+
{
97+
if (!rev->diffopt.output_format) {
98+
if (rev->dense_combined_merges)
99+
rev->diffopt.output_format = DIFF_FORMAT_PATCH;
100+
else
101+
rev->diffopt.output_format = DIFF_FORMAT_RAW;
102+
}
103+
}
104+
95105
int cmd_diff_tree(int argc, const char **argv, const char *prefix)
96106
{
97107
int nr_sha1;
98108
char line[1000];
99109
struct object *tree1, *tree2;
100110
static struct rev_info *opt = &log_tree_opt;
111+
struct setup_revision_opt s_r_opt;
101112
int read_stdin = 0;
102113

103114
init_revisions(opt, prefix);
104115
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
105116
opt->abbrev = 0;
106117
opt->diff = 1;
107118
opt->disable_stdin = 1;
108-
argc = setup_revisions(argc, argv, opt, NULL);
119+
memset(&s_r_opt, 0, sizeof(s_r_opt));
120+
s_r_opt.tweak = diff_tree_tweak_rev;
121+
argc = setup_revisions(argc, argv, opt, &s_r_opt);
109122

110123
while (--argc > 0) {
111124
const char *arg = *++argv;
@@ -117,9 +130,6 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
117130
usage(diff_tree_usage);
118131
}
119132

120-
if (!opt->diffopt.output_format)
121-
opt->diffopt.output_format = DIFF_FORMAT_RAW;
122-
123133
/*
124134
* NOTE! We expect "a ^b" to be equal to "a..b", so we
125135
* reverse the order of the objects if the second one

builtin-log.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ static int show_tree_object(const unsigned char *sha1,
327327
return 0;
328328
}
329329

330+
static void show_rev_tweak_rev(struct rev_info *rev, struct setup_revision_opt *opt)
331+
{
332+
if (!rev->diffopt.output_format)
333+
rev->diffopt.output_format = DIFF_FORMAT_PATCH;
334+
}
335+
330336
int cmd_show(int argc, const char **argv, const char *prefix)
331337
{
332338
struct rev_info rev;
@@ -348,6 +354,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
348354
rev.no_walk = 1;
349355
memset(&opt, 0, sizeof(opt));
350356
opt.def = "HEAD";
357+
opt.tweak = show_rev_tweak_rev;
351358
cmd_log_init(argc, argv, prefix, &rev, &opt);
352359

353360
count = rev.pending.nr;

revision.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
14631463

14641464
if (revs->def == NULL)
14651465
revs->def = opt ? opt->def : NULL;
1466+
if (opt && opt->tweak)
1467+
opt->tweak(revs, opt);
14661468
if (revs->show_merge)
14671469
prepare_show_merge(revs);
14681470
if (revs->def && !revs->pending.nr) {
@@ -1496,11 +1498,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
14961498
if (!revs->full_diff)
14971499
diff_tree_setup_paths(revs->prune_data, &revs->diffopt);
14981500
}
1499-
if (revs->combine_merges) {
1501+
if (revs->combine_merges)
15001502
revs->ignore_merges = 0;
1501-
if (revs->dense_combined_merges && !revs->diffopt.output_format)
1502-
revs->diffopt.output_format = DIFF_FORMAT_PATCH;
1503-
}
15041503
revs->diffopt.abbrev = revs->abbrev;
15051504
if (diff_setup_done(&revs->diffopt) < 0)
15061505
die("diff_setup_done failed");

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ extern volatile show_early_output_fn_t show_early_output;
139139

140140
struct setup_revision_opt {
141141
const char *def;
142+
void (*tweak)(struct rev_info *, struct setup_revision_opt *);
142143
};
143144

144145
extern void init_revisions(struct rev_info *revs, const char *prefix);

t/t4013-diff-various.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ show initial
238238
show --root initial
239239
show side
240240
show master
241+
show -c master
241242
show --stat side
242243
show --stat --summary side
243244
show --patch-with-stat side

t/t4013/diff.show_-c_master

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
$ git show -c master
2+
commit 59d314ad6f356dd08601a4cd5e530381da3e3c64
3+
Merge: 9a6d494 c7a2ab9
4+
Author: A U Thor <[email protected]>
5+
Date: Mon Jun 26 00:04:00 2006 +0000
6+
7+
Merge branch 'side'
8+
9+
diff --combined dir/sub
10+
index cead32e,7289e35..992913c
11+
--- a/dir/sub
12+
+++ b/dir/sub
13+
@@@ -1,6 -1,4 +1,8 @@@
14+
A
15+
B
16+
+C
17+
+D
18+
+E
19+
+F
20+
+ 1
21+
+ 2
22+
diff --combined file0
23+
index b414108,f4615da..10a8a9f
24+
--- a/file0
25+
+++ b/file0
26+
@@@ -1,6 -1,6 +1,9 @@@
27+
1
28+
2
29+
3
30+
+4
31+
+5
32+
+6
33+
+ A
34+
+ B
35+
+ C
36+
$

0 commit comments

Comments
 (0)