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 1.2.3-korg 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 --- builtin-log.c | 1 + combine-diff.c | 7 ++++--- diff.c | 1 + diff.h | 1 + log-tree.c | 15 ++++++--------- log-tree.h | 2 +- 6 files changed, 14 insertions(+), 13 deletions(-) (limited to 'combine-diff.c') diff --git a/builtin-log.c b/builtin-log.c index 4e5273aecf..71ae6c98a5 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -175,6 +175,7 @@ int cmd_format_patch(int argc, const char **argv, char **envp) rev.diff = 1; rev.combine_merges = 0; rev.ignore_merges = 1; + rev.diffopt.msg_sep = "---\n"; git_config(git_format_config); rev.extra_headers = extra_headers; 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'); diff --git a/diff.c b/diff.c index 928345199d..491b846f62 100644 --- a/diff.c +++ b/diff.c @@ -1424,6 +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->change = diff_change; options->add_remove = diff_addremove; diff --git a/diff.h b/diff.h index 2b6dc0cbe4..729cd02510 100644 --- a/diff.h +++ b/diff.h @@ -57,6 +57,7 @@ struct diff_options { int rename_limit; int setup; int abbrev; + const char *msg_sep; const char *stat_sep; long xdl_opts; diff --git a/log-tree.c b/log-tree.c index 7d4c51f954..ab6b682223 100644 --- a/log-tree.c +++ b/log-tree.c @@ -43,9 +43,10 @@ static int append_signoff(char *buf, int buf_sz, int at, const char *signoff) return at; } -void show_log(struct rev_info *opt, struct log_info *log, const char *sep) +void show_log(struct rev_info *opt, const char *sep) { static char this_header[16384]; + struct log_info *log = opt->loginfo; struct commit *commit = log->commit, *parent = log->parent; int abbrev = opt->diffopt.abbrev; int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40; @@ -163,13 +164,9 @@ int log_tree_diff_flush(struct rev_info *opt) return 0; } - if (opt->loginfo && !opt->no_commit_id) { - if (opt->diffopt.output_format & DIFF_FORMAT_DIFFSTAT) { - show_log(opt, opt->loginfo, "---\n"); - } else { - show_log(opt, opt->loginfo, "\n"); - } - } + if (opt->loginfo && !opt->no_commit_id) + show_log(opt, opt->diffopt.msg_sep); + diff_flush(&opt->diffopt); return 1; } @@ -266,7 +263,7 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit) shown = log_tree_diff(opt, commit, &log); if (!shown && opt->loginfo && opt->always_show_header) { log.parent = NULL; - show_log(opt, opt->loginfo, ""); + show_log(opt, ""); shown = 1; } opt->loginfo = NULL; diff --git a/log-tree.h b/log-tree.h index a26e4841ff..e82b56a20d 100644 --- a/log-tree.h +++ b/log-tree.h @@ -11,6 +11,6 @@ void init_log_tree_opt(struct rev_info *); int log_tree_diff_flush(struct rev_info *); int log_tree_commit(struct rev_info *, struct commit *); int log_tree_opt_parse(struct rev_info *, const char **, int); -void show_log(struct rev_info *opt, struct log_info *log, const char *sep); +void show_log(struct rev_info *opt, const char *sep); #endif -- cgit 1.2.3-korg 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 --- builtin-diff-tree.c | 1 - combine-diff.c | 24 +++++++++++++++--------- diff.c | 15 ++++++++------- log-tree.c | 17 +++++++++++++++-- 4 files changed, 38 insertions(+), 19 deletions(-) (limited to 'combine-diff.c') diff --git a/builtin-diff-tree.c b/builtin-diff-tree.c index 1e66fcac21..ae1cde9d00 100644 --- a/builtin-diff-tree.c +++ b/builtin-diff-tree.c @@ -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) { 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, diff --git a/diff.c b/diff.c index 6d04be49de..1c131ff4dc 100644 --- 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) { diff --git a/log-tree.c b/log-tree.c index ab6b682223..9d8d46fa00 100644 --- a/log-tree.c +++ b/log-tree.c @@ -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; } -- cgit 1.2.3-korg 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 1.2.3-korg