Fix some more diff options changes.
This fixes various problems in the new diff options code. - Fix --cc/-c --patch; it showed two-tree diff used internally. - Use "---\n" only where it matters -- that is, use it immediately after the commit log text when we show a commit log and something else before the patch text. - Do not output spurious extra "\n"; have an extra newline after the commit log text always when we have diff output and we are not doing oneline. - When running a pickaxe you need to go recursive. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jun 27, 2006 at 15:08 UTC
3969cf7db1a13a78f3b7a36d8c1084bbe0a53459
4 files changed
+38
-19
builtin-diff-tree.c
-1
@@ -72,7 +72,6 @@ int cmd_diff_tree(int argc, const char **argv, char **envp)
72
init_revisions(opt);
73
opt->abbrev = 0;
74
opt->diff = 1;
75
- opt->diffopt.msg_sep = "---\n";
75
argc = setup_revisions(argc, argv, opt, NULL);
76
77
while (--argc > 0) {
combine-diff.c
+15
-9
@@ -835,31 +835,33 @@ void diff_tree_combined(const unsigned char *sha1,
835
struct diff_options *opt = &rev->diffopt;
836
struct diff_options diffopts;
837
struct combine_diff_path *p, *paths = NULL;
838
- int i, num_paths;
838
+ int i, num_paths, needsep, show_log_first;
839
840
diffopts = *opt;
841
- diffopts.output_format &= ~(DIFF_FORMAT_RAW | DIFF_FORMAT_DIFFSTAT);
841
+ diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
842
diffopts.recursive = 1;
843
844
+ show_log_first = rev->loginfo;
845
+ needsep = 0;
846
/* find set of paths that everybody touches */
847
for (i = 0; i < num_parent; i++) {
848
/* show stat against the first parent even
849
* when doing combined diff.
850
*/
851
if (i == 0 && opt->output_format & DIFF_FORMAT_DIFFSTAT)
850
- diffopts.output_format |= DIFF_FORMAT_DIFFSTAT;
852
+ diffopts.output_format = DIFF_FORMAT_DIFFSTAT;
853
else
852
- diffopts.output_format |= DIFF_FORMAT_NO_OUTPUT;
854
+ diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
855
diff_tree_sha1(parent[i], sha1, "", &diffopts);
856
diffcore_std(&diffopts);
857
paths = intersect_paths(paths, i, num_parent);
858
857
- if (opt->output_format & DIFF_FORMAT_DIFFSTAT && rev->loginfo)
859
+ if (show_log_first && i == 0) {
860
show_log(rev, opt->msg_sep);
859
-
861
+ if (rev->verbose_header && opt->output_format)
862
+ putchar(opt->line_termination);
863
+ }
864
diff_flush(&diffopts);
861
- if (opt->output_format & DIFF_FORMAT_DIFFSTAT)
862
- putchar('\n');
865
}
866
867
/* find out surviving paths */
@@ -875,9 +877,13 @@ void diff_tree_combined(const unsigned char *sha1,
877
if (p->len)
878
show_raw_diff(p, num_parent, rev);
879
}
878
- putchar(opt->line_termination);
880
+ needsep = 1;
881
}
882
+ else if (opt->output_format & DIFF_FORMAT_DIFFSTAT)
883
+ needsep = 1;
884
if (opt->output_format & DIFF_FORMAT_PATCH) {
885
+ if (needsep)
886
+ putchar(opt->line_termination);
887
for (p = paths; p; p = p->next) {
888
if (p->len)
889
show_patch_diff(p, num_parent, dense,
diff.c
+8
-7
@@ -1424,7 +1424,7 @@ void diff_setup(struct diff_options *options)
1424
options->break_opt = -1;
1425
options->rename_limit = -1;
1426
options->context = 3;
1427
- options->msg_sep = "\n";
1427
+ options->msg_sep = "";
1428
1429
options->change = diff_change;
1430
options->add_remove = diff_addremove;
@@ -1455,6 +1455,11 @@ int diff_setup_done(struct diff_options *options)
1455
DIFF_FORMAT_DIFFSTAT |
1456
DIFF_FORMAT_CHECKDIFF))
1457
options->recursive = 1;
1458
+ /*
1459
+ * Also pickaxe would not work very well if you do not say recursive
1460
+ */
1461
+ if (options->pickaxe)
1462
+ options->recursive = 1;
1463
1464
if (options->detect_rename && options->rename_limit < 0)
1465
options->rename_limit = diff_rename_limit_default;
@@ -2143,9 +2148,6 @@ void diff_flush(struct diff_options *options)
2148
if (output_format & DIFF_FORMAT_DIFFSTAT) {
2149
struct diffstat_t diffstat;
2150
2146
- if (separator++)
2147
- putchar('\n');
2148
-
2151
memset(&diffstat, 0, sizeof(struct diffstat_t));
2152
diffstat.xm.consume = diffstat_consume;
2153
for (i = 0; i < q->nr; i++) {
@@ -2154,14 +2156,13 @@ void diff_flush(struct diff_options *options)
2156
diff_flush_stat(p, options, &diffstat);
2157
}
2158
show_stats(&diffstat);
2159
+ separator++;
2160
}
2161
2162
if (output_format & DIFF_FORMAT_SUMMARY && !is_summary_empty(q)) {
2160
- if (separator++)
2161
- putchar('\n');
2162
-
2163
for (i = 0; i < q->nr; i++)
2164
diff_summary(q->queue[i]);
2165
+ separator++;
2166
}
2167
2168
if (output_format & DIFF_FORMAT_PATCH) {
log-tree.c
+15
-2
@@ -164,9 +164,22 @@ int log_tree_diff_flush(struct rev_info *opt)
164
return 0;
165
}
166
167
- if (opt->loginfo && !opt->no_commit_id)
167
+ if (opt->loginfo && !opt->no_commit_id) {
168
+ /* When showing a verbose header (i.e. log message),
169
+ * and not in --pretty=oneline format, we would want
170
+ * an extra newline between the end of log and the
171
+ * output for readability.
172
+ */
173
show_log(opt, opt->diffopt.msg_sep);
169
-
174
+ if (opt->verbose_header &&
175
+ opt->commit_format != CMIT_FMT_ONELINE) {
176
+ int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
177
+ if ((pch & opt->diffopt.output_format) == pch)
178
+ printf("---%c", opt->diffopt.line_termination);
179
+ else
180
+ putchar(opt->diffopt.line_termination);
181
+ }
182
+ }
183
diff_flush(&opt->diffopt);
184
return 1;
185
}