From d4ed9793fd981ea5a35ebaa8e337446bb29f6d55 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 16 Apr 2006 02:42:00 -0700 Subject: [PATCH 1/2] Simplify common default options setup for built-in log family. Signed-off-by: Junio C Hamano --- git.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/git.c b/git.c index a6cfd1d8aa..cc43bfcaba 100644 --- a/git.c +++ b/git.c @@ -286,6 +286,11 @@ static int cmd_log_wc(int argc, const char **argv, char **envp, const char *commit_prefix = "commit "; int shown = 0; + rev->abbrev = DEFAULT_ABBREV; + rev->commit_format = CMIT_FMT_DEFAULT; + rev->no_commit_id = 1; + argc = setup_revisions(argc, argv, rev, "HEAD"); + if (argc > 1) die("unrecognized argument: %s", argv[1]); if (rev->commit_format == CMIT_FMT_ONELINE) @@ -347,12 +352,8 @@ static int cmd_wc(int argc, const char **argv, char **envp) struct rev_info rev; init_revisions(&rev); - rev.abbrev = DEFAULT_ABBREV; - rev.no_commit_id = 1; - rev.commit_format = CMIT_FMT_DEFAULT; rev.diff = 1; rev.diffopt.recursive = 1; - argc = setup_revisions(argc, argv, &rev, "HEAD"); return cmd_log_wc(argc, argv, envp, &rev); } @@ -362,14 +363,11 @@ static int cmd_show(int argc, const char **argv, char **envp) init_revisions(&rev); rev.diff = 1; - rev.ignore_merges = 0; + rev.diffopt.recursive = 1; rev.combine_merges = 1; rev.dense_combined_merges = 1; - rev.abbrev = DEFAULT_ABBREV; - rev.commit_format = CMIT_FMT_DEFAULT; - rev.diffopt.recursive = 1; + rev.ignore_merges = 0; rev.no_walk = 1; - argc = setup_revisions(argc, argv, &rev, "HEAD"); return cmd_log_wc(argc, argv, envp, &rev); } @@ -378,10 +376,6 @@ static int cmd_log(int argc, const char **argv, char **envp) struct rev_info rev; init_revisions(&rev); - rev.abbrev = DEFAULT_ABBREV; - rev.no_commit_id = 1; - rev.commit_format = CMIT_FMT_DEFAULT; - argc = setup_revisions(argc, argv, &rev, "HEAD"); return cmd_log_wc(argc, argv, envp, &rev); } From cb8f64b4e3f263c113b7a2f156af74b810e969ff Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 16 Apr 2006 03:29:10 -0700 Subject: [PATCH 2/2] log/whatchanged/show - log formatting cleanup. This moves the decision to print the log message, while diff options are in effect, to log-tree. It gives behaviour closer to the traditional one. Signed-off-by: Junio C Hamano --- git.c | 41 ++++++++++++++++++++++++++--------------- log-tree.c | 3 +++ revision.h | 1 + 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/git.c b/git.c index cc43bfcaba..c5de8d3a12 100644 --- a/git.c +++ b/git.c @@ -288,7 +288,6 @@ static int cmd_log_wc(int argc, const char **argv, char **envp, rev->abbrev = DEFAULT_ABBREV; rev->commit_format = CMIT_FMT_DEFAULT; - rev->no_commit_id = 1; argc = setup_revisions(argc, argv, rev, "HEAD"); if (argc > 1) @@ -299,16 +298,20 @@ static int cmd_log_wc(int argc, const char **argv, char **envp, prepare_revision_walk(rev); setup_pager(); while ((commit = get_revision(rev)) != NULL) { + unsigned long ofs = 0; + if (shown && rev->diff && rev->commit_format != CMIT_FMT_ONELINE) putchar('\n'); - fputs(commit_prefix, stdout); + + ofs = sprintf(buf, "%s", commit_prefix); if (rev->abbrev_commit && rev->abbrev) - fputs(find_unique_abbrev(commit->object.sha1, - rev->abbrev), - stdout); + ofs += sprintf(buf + ofs, "%s", + find_unique_abbrev(commit->object.sha1, + rev->abbrev)); else - fputs(sha1_to_hex(commit->object.sha1), stdout); + ofs += sprintf(buf + ofs, "%s", + sha1_to_hex(commit->object.sha1)); if (rev->parents) { struct commit_list *parents = commit->parents; while (parents) { @@ -316,7 +319,8 @@ static int cmd_log_wc(int argc, const char **argv, char **envp, parents = parents->next; if (o->flags & TMP_MARK) continue; - printf(" %s", sha1_to_hex(o->sha1)); + ofs += sprintf(buf + ofs, " %s", + sha1_to_hex(o->sha1)); o->flags |= TMP_MARK; } /* TMP_MARK is a general purpose flag that can @@ -328,17 +332,20 @@ static int cmd_log_wc(int argc, const char **argv, char **envp, parents = parents->next) parents->item->object.flags &= ~TMP_MARK; } - if (rev->commit_format == CMIT_FMT_ONELINE) - putchar(' '); - else - putchar('\n'); - pretty_print_commit(rev->commit_format, commit, ~0, buf, - LOGSIZE, rev->abbrev); - printf("%s\n", buf); + buf[ofs++] = + (rev->commit_format == CMIT_FMT_ONELINE) ? ' ' : '\n'; + ofs += pretty_print_commit(rev->commit_format, commit, ~0, + buf + ofs, + LOGSIZE - ofs - 20, + rev->abbrev); + if (rev->diff) { - printf("---\n"); + rev->use_precomputed_header = buf; + strcpy(buf + ofs, "\n---\n"); log_tree_commit(rev, commit); } + else + printf("%s\n", buf); shown = 1; free(commit->buffer); commit->buffer = NULL; @@ -376,6 +383,10 @@ static int cmd_log(int argc, const char **argv, char **envp) struct rev_info rev; init_revisions(&rev); + rev.always_show_header = 1; + rev.diffopt.recursive = 1; + rev.combine_merges = 1; + rev.ignore_merges = 0; return cmd_log_wc(argc, argv, envp, &rev); } diff --git a/log-tree.c b/log-tree.c index 04a68e0f57..7d9f41ede1 100644 --- a/log-tree.c +++ b/log-tree.c @@ -54,6 +54,9 @@ static const char *generate_header(struct rev_info *opt, int abbrev = opt->diffopt.abbrev; const char *msg = commit->buffer; + if (opt->use_precomputed_header) + return opt->use_precomputed_header; + if (!opt->verbose_header) return sha1_to_hex(commit_sha1); diff --git a/revision.h b/revision.h index 7b854866b2..74dc5ef179 100644 --- a/revision.h +++ b/revision.h @@ -56,6 +56,7 @@ struct rev_info { enum cmit_fmt commit_format; const char *header_prefix; const char *header; + const char *use_precomputed_header; /* special limits */ int max_count;