From c6744349df5089133b7662e67aba28282b6a963f Mon Sep 17 00:00:00 2001 From: Timo Hirvonen Date: Sat, 24 Jun 2006 20:21:53 +0300 Subject: Merge with_raw, with_stat and summary variables to output_format DIFF_FORMAT_* are now bit-flags instead of enumerated values. Signed-off-by: Timo Hirvonen Signed-off-by: Junio C Hamano --- combine-diff.c | 55 ++++++++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 31 deletions(-) (limited to 'combine-diff.c') diff --git a/combine-diff.c b/combine-diff.c index 64b20cce24..3daa8cb13e 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -771,7 +771,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re if (rev->loginfo) show_log(rev, rev->loginfo, "\n"); - if (opt->output_format == DIFF_FORMAT_RAW) { + if (opt->output_format & DIFF_FORMAT_RAW) { offset = strlen(COLONS) - num_parent; if (offset < 0) offset = 0; @@ -791,8 +791,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re printf(" %s ", diff_unique_abbrev(p->sha1, opt->abbrev)); } - if (opt->output_format == DIFF_FORMAT_RAW || - opt->output_format == DIFF_FORMAT_NAME_STATUS) { + if (opt->output_format & (DIFF_FORMAT_RAW | DIFF_FORMAT_NAME_STATUS)) { for (i = 0; i < num_parent; i++) putchar(p->parent[i].status); putchar(inter_name_termination); @@ -818,17 +817,12 @@ void show_combined_diff(struct combine_diff_path *p, struct diff_options *opt = &rev->diffopt; if (!p->len) return; - switch (opt->output_format) { - case DIFF_FORMAT_RAW: - case DIFF_FORMAT_NAME_STATUS: - case DIFF_FORMAT_NAME: + if (opt->output_format & (DIFF_FORMAT_RAW | + DIFF_FORMAT_NAME | + DIFF_FORMAT_NAME_STATUS)) { show_raw_diff(p, num_parent, rev); - return; - case DIFF_FORMAT_PATCH: + } else if (opt->output_format & DIFF_FORMAT_PATCH) { show_patch_diff(p, num_parent, dense, rev); - return; - default: - return; } } @@ -842,13 +836,9 @@ void diff_tree_combined(const unsigned char *sha1, struct diff_options diffopts; struct combine_diff_path *p, *paths = NULL; int i, num_paths; - int do_diffstat; - do_diffstat = (opt->output_format == DIFF_FORMAT_DIFFSTAT || - opt->with_stat); diffopts = *opt; - diffopts.with_raw = 0; - diffopts.with_stat = 0; + diffopts.output_format &= ~(DIFF_FORMAT_RAW | DIFF_FORMAT_DIFFSTAT); diffopts.recursive = 1; /* find set of paths that everybody touches */ @@ -856,19 +846,18 @@ void diff_tree_combined(const unsigned char *sha1, /* show stat against the first parent even * when doing combined diff. */ - if (i == 0 && do_diffstat) - diffopts.output_format = DIFF_FORMAT_DIFFSTAT; + if (i == 0 && opt->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 (do_diffstat && rev->loginfo) - show_log(rev, rev->loginfo, - opt->with_stat ? "---\n" : "\n"); + if (opt->output_format & DIFF_FORMAT_DIFFSTAT && rev->loginfo) + show_log(rev, rev->loginfo, "---\n"); diff_flush(&diffopts); - if (opt->with_stat) + if (opt->output_format & DIFF_FORMAT_DIFFSTAT) putchar('\n'); } @@ -878,17 +867,21 @@ void diff_tree_combined(const unsigned char *sha1, num_paths++; } if (num_paths) { - if (opt->with_raw) { - int saved_format = opt->output_format; - opt->output_format = DIFF_FORMAT_RAW; + if (opt->output_format & (DIFF_FORMAT_RAW | + DIFF_FORMAT_NAME | + DIFF_FORMAT_NAME_STATUS)) { for (p = paths; p; p = p->next) { - show_combined_diff(p, num_parent, dense, rev); + if (p->len) + show_raw_diff(p, num_parent, rev); } - opt->output_format = saved_format; putchar(opt->line_termination); } - for (p = paths; p; p = p->next) { - show_combined_diff(p, num_parent, dense, rev); + if (opt->output_format & DIFF_FORMAT_PATCH) { + for (p = paths; p; p = p->next) { + if (p->len) + show_patch_diff(p, num_parent, dense, + rev); + } } } -- cgit v1.2.3 From 39bc9a6c2051a9fc31dc9b34b40bdd3dd94a8afb Mon Sep 17 00:00:00 2001 From: Timo Hirvonen Date: Sun, 25 Jun 2006 13:54:14 +0300 Subject: Add msg_sep to diff_options Add msg_sep variable to struct diff_options. msg_sep is printed after commit message. Default is "\n", format-patch sets it to "---\n". This also removes the second argument from show_log() because all callers derived it from the first argument: show_log(rev, rev->loginfo, ... Signed-off-by: Timo Hirvonen Signed-off-by: Junio C Hamano --- combine-diff.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'combine-diff.c') diff --git a/combine-diff.c b/combine-diff.c index 3daa8cb13e..39fb10c145 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -701,7 +701,7 @@ static int show_patch_diff(struct combine_diff_path *elem, int num_parent, const char *abb; if (rev->loginfo) - show_log(rev, rev->loginfo, "\n"); + show_log(rev, opt->msg_sep); dump_quoted_path(dense ? "diff --cc " : "diff --combined ", elem->path); printf("index "); for (i = 0; i < num_parent; i++) { @@ -769,7 +769,7 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re inter_name_termination = 0; if (rev->loginfo) - show_log(rev, rev->loginfo, "\n"); + show_log(rev, opt->msg_sep); if (opt->output_format & DIFF_FORMAT_RAW) { offset = strlen(COLONS) - num_parent; @@ -855,7 +855,8 @@ void diff_tree_combined(const unsigned char *sha1, paths = intersect_paths(paths, i, num_parent); if (opt->output_format & DIFF_FORMAT_DIFFSTAT && rev->loginfo) - show_log(rev, rev->loginfo, "---\n"); + show_log(rev, opt->msg_sep); + diff_flush(&diffopts); if (opt->output_format & DIFF_FORMAT_DIFFSTAT) putchar('\n'); -- cgit v1.2.3 From 3969cf7db1a13a78f3b7a36d8c1084bbe0a53459 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 27 Jun 2006 15:08:19 -0700 Subject: 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 --- combine-diff.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'combine-diff.c') diff --git a/combine-diff.c b/combine-diff.c index 39fb10c145..7178b25c53 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -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, -- cgit v1.2.3 From 2c0b4dfd5a2099bdbbdfad71c3193a25c9052f2d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 28 Jun 2006 01:46:41 -0700 Subject: combine-diff.c: type sanity. In diff_tree_combined(), show_log_first boolean is initialized with rev->loginfo (pointer to a string); the intention is that if we have some string to be emitted we would want to remember that fact. Picky compilers are offended by this, so make the expression a bit type-safer. Signed-off-by: Junio C Hamano --- combine-diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'combine-diff.c') diff --git a/combine-diff.c b/combine-diff.c index 7178b25c53..2fd0ced395 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -841,7 +841,7 @@ void diff_tree_combined(const unsigned char *sha1, diffopts.output_format = DIFF_FORMAT_NO_OUTPUT; diffopts.recursive = 1; - show_log_first = rev->loginfo; + show_log_first = !!rev->loginfo; needsep = 0; /* find set of paths that everybody touches */ for (i = 0; i < num_parent; i++) { -- cgit v1.2.3