]> asedeno.scripts.mit.edu Git - git.git/commitdiff
Fix some more diff options changes.
authorJunio C Hamano <junkio@cox.net>
Tue, 27 Jun 2006 22:08:19 +0000 (15:08 -0700)
committerJunio C Hamano <junkio@cox.net>
Tue, 27 Jun 2006 22:33:40 +0000 (15:33 -0700)
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>
builtin-diff-tree.c
combine-diff.c
diff.c
log-tree.c

index 1e66fcac2186d0946b5d15a5825eb400b2e67003..ae1cde9d005cb64ca2b1a5de45750abff04d444d 100644 (file)
@@ -72,7 +72,6 @@ int cmd_diff_tree(int argc, const char **argv, char **envp)
        init_revisions(opt);
        opt->abbrev = 0;
        opt->diff = 1;
-       opt->diffopt.msg_sep = "---\n";
        argc = setup_revisions(argc, argv, opt, NULL);
 
        while (--argc > 0) {
index 39fb10c1457c96fd86dd25443b49a4a7cafa0134..7178b25c53551271f869e182611bb1c705c0de76 100644 (file)
@@ -835,31 +835,33 @@ void diff_tree_combined(const unsigned char *sha1,
        struct diff_options *opt = &rev->diffopt;
        struct diff_options diffopts;
        struct combine_diff_path *p, *paths = NULL;
-       int i, num_paths;
+       int i, num_paths, needsep, show_log_first;
 
        diffopts = *opt;
-       diffopts.output_format &= ~(DIFF_FORMAT_RAW | DIFF_FORMAT_DIFFSTAT);
+       diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
        diffopts.recursive = 1;
 
+       show_log_first = rev->loginfo;
+       needsep = 0;
        /* find set of paths that everybody touches */
        for (i = 0; i < num_parent; i++) {
                /* show stat against the first parent even
                 * when doing combined diff.
                 */
                if (i == 0 && opt->output_format & DIFF_FORMAT_DIFFSTAT)
-                       diffopts.output_format |= DIFF_FORMAT_DIFFSTAT;
+                       diffopts.output_format = DIFF_FORMAT_DIFFSTAT;
                else
-                       diffopts.output_format |= DIFF_FORMAT_NO_OUTPUT;
+                       diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
                diff_tree_sha1(parent[i], sha1, "", &diffopts);
                diffcore_std(&diffopts);
                paths = intersect_paths(paths, i, num_parent);
 
-               if (opt->output_format & DIFF_FORMAT_DIFFSTAT && rev->loginfo)
+               if (show_log_first && i == 0) {
                        show_log(rev, opt->msg_sep);
-
+                       if (rev->verbose_header && opt->output_format)
+                               putchar(opt->line_termination);
+               }
                diff_flush(&diffopts);
-               if (opt->output_format & DIFF_FORMAT_DIFFSTAT)
-                       putchar('\n');
        }
 
        /* find out surviving paths */
@@ -875,9 +877,13 @@ void diff_tree_combined(const unsigned char *sha1,
                                if (p->len)
                                        show_raw_diff(p, num_parent, rev);
                        }
-                       putchar(opt->line_termination);
+                       needsep = 1;
                }
+               else if (opt->output_format & DIFF_FORMAT_DIFFSTAT)
+                       needsep = 1;
                if (opt->output_format & DIFF_FORMAT_PATCH) {
+                       if (needsep)
+                               putchar(opt->line_termination);
                        for (p = paths; p; p = p->next) {
                                if (p->len)
                                        show_patch_diff(p, num_parent, dense,
diff --git a/diff.c b/diff.c
index 6d04be49dea83d319c68257d25dde6587179bdc5..1c131ff4dcdab52abec6f182e1a9310820532189 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1424,7 +1424,7 @@ void diff_setup(struct diff_options *options)
        options->break_opt = -1;
        options->rename_limit = -1;
        options->context = 3;
-       options->msg_sep = "\n";
+       options->msg_sep = "";
 
        options->change = diff_change;
        options->add_remove = diff_addremove;
@@ -1455,6 +1455,11 @@ int diff_setup_done(struct diff_options *options)
                                      DIFF_FORMAT_DIFFSTAT |
                                      DIFF_FORMAT_CHECKDIFF))
                options->recursive = 1;
+       /*
+        * Also pickaxe would not work very well if you do not say recursive
+        */
+       if (options->pickaxe)
+               options->recursive = 1;
 
        if (options->detect_rename && options->rename_limit < 0)
                options->rename_limit = diff_rename_limit_default;
@@ -2143,9 +2148,6 @@ void diff_flush(struct diff_options *options)
        if (output_format & DIFF_FORMAT_DIFFSTAT) {
                struct diffstat_t diffstat;
 
-               if (separator++)
-                       putchar('\n');
-
                memset(&diffstat, 0, sizeof(struct diffstat_t));
                diffstat.xm.consume = diffstat_consume;
                for (i = 0; i < q->nr; i++) {
@@ -2154,14 +2156,13 @@ void diff_flush(struct diff_options *options)
                                diff_flush_stat(p, options, &diffstat);
                }
                show_stats(&diffstat);
+               separator++;
        }
 
        if (output_format & DIFF_FORMAT_SUMMARY && !is_summary_empty(q)) {
-               if (separator++)
-                       putchar('\n');
-
                for (i = 0; i < q->nr; i++)
                        diff_summary(q->queue[i]);
+               separator++;
        }
 
        if (output_format & DIFF_FORMAT_PATCH) {
index ab6b6822237c2e0fc520092344854d7b13f4a24d..9d8d46fa0038202bd49dee9cf5d1a60f781e5d7d 100644 (file)
@@ -164,9 +164,22 @@ int log_tree_diff_flush(struct rev_info *opt)
                return 0;
        }
 
-       if (opt->loginfo && !opt->no_commit_id)
+       if (opt->loginfo && !opt->no_commit_id) {
+               /* When showing a verbose header (i.e. log message),
+                * and not in --pretty=oneline format, we would want
+                * an extra newline between the end of log and the
+                * output for readability.
+                */
                show_log(opt, opt->diffopt.msg_sep);
-
+               if (opt->verbose_header &&
+                   opt->commit_format != CMIT_FMT_ONELINE) {
+                       int pch = DIFF_FORMAT_DIFFSTAT | DIFF_FORMAT_PATCH;
+                       if ((pch & opt->diffopt.output_format) == pch)
+                               printf("---%c", opt->diffopt.line_termination);
+                       else
+                               putchar(opt->diffopt.line_termination);
+               }
+       }
        diff_flush(&opt->diffopt);
        return 1;
 }