@matheusbsbs / matheus-bagliano / commits / b449005997
Fork 0

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 <gitster@pobox.com>

Junio C Hamano committed Mar 8, 2010 at 23:27 UTC b44900599710c700c1bf164d3753eb7f8eb6c18a
6 files changed +62 -8
builtin-diff-tree.c
+14 -4
@@ -92,12 +92,23 @@ static const char diff_tree_usage[] =
92 " --root include the initial commit as diff against /dev/null\n"
93 COMMON_DIFF_OPTIONS_HELP;
94
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 +
105 int cmd_diff_tree(int argc, const char **argv, const char *prefix)
106 {
107 int nr_sha1;
108 char line[1000];
109 struct object *tree1, *tree2;
110 static struct rev_info *opt = &log_tree_opt;
111 + struct setup_revision_opt s_r_opt;
112 int read_stdin = 0;
113
114 init_revisions(opt, prefix);
@@ -105,7 +116,9 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
116 opt->abbrev = 0;
117 opt->diff = 1;
118 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);
122
123 while (--argc > 0) {
124 const char *arg = *++argv;
@@ -117,9 +130,6 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
130 usage(diff_tree_usage);
131 }
132
120 - if (!opt->diffopt.output_format)
121 - opt->diffopt.output_format = DIFF_FORMAT_RAW;
122 -
133 /*
134 * NOTE! We expect "a ^b" to be equal to "a..b", so we
135 * reverse the order of the objects if the second one
builtin-log.c
+7
@@ -327,6 +327,12 @@ static int show_tree_object(const unsigned char *sha1,
327 return 0;
328 }
329
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 +
336 int cmd_show(int argc, const char **argv, const char *prefix)
337 {
338 struct rev_info rev;
@@ -348,6 +354,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
354 rev.no_walk = 1;
355 memset(&opt, 0, sizeof(opt));
356 opt.def = "HEAD";
357 + opt.tweak = show_rev_tweak_rev;
358 cmd_log_init(argc, argv, prefix, &rev, &opt);
359
360 count = rev.pending.nr;
revision.c
+3 -4
@@ -1463,6 +1463,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
1463
1464 if (revs->def == NULL)
1465 revs->def = opt ? opt->def : NULL;
1466 + if (opt && opt->tweak)
1467 + opt->tweak(revs, opt);
1468 if (revs->show_merge)
1469 prepare_show_merge(revs);
1470 if (revs->def && !revs->pending.nr) {
@@ -1496,11 +1498,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
1498 if (!revs->full_diff)
1499 diff_tree_setup_paths(revs->prune_data, &revs->diffopt);
1500 }
1499 - if (revs->combine_merges) {
1501 + if (revs->combine_merges)
1502 revs->ignore_merges = 0;
1501 - if (revs->dense_combined_merges && !revs->diffopt.output_format)
1502 - revs->diffopt.output_format = DIFF_FORMAT_PATCH;
1503 - }
1503 revs->diffopt.abbrev = revs->abbrev;
1504 if (diff_setup_done(&revs->diffopt) < 0)
1505 die("diff_setup_done failed");
revision.h
+1
@@ -139,6 +139,7 @@ extern volatile show_early_output_fn_t show_early_output;
139
140 struct setup_revision_opt {
141 const char *def;
142 + void (*tweak)(struct rev_info *, struct setup_revision_opt *);
143 };
144
145 extern void init_revisions(struct rev_info *revs, const char *prefix);
t/t4013-diff-various.sh
+1
@@ -238,6 +238,7 @@ show initial
238 show --root initial
239 show side
240 show master
241 +show -c master
242 show --stat side
243 show --stat --summary side
244 show --patch-with-stat side
t/t4013/diff.show_-c_master new
+36
@@ -0,0 +1,36 @@
1 +$ git show -c master
2 +commit 59d314ad6f356dd08601a4cd5e530381da3e3c64
3 +Merge: 9a6d494 c7a2ab9
4 +Author: A U Thor <author@example.com>
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 +$