From d2e38d3bc30d3b1e407cbf9c69424b84244a5f9d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 15 Apr 2006 03:54:32 -0700 Subject: [PATCH 1/2] whatchanged options parser fix. We need to have two sets of diff_options structure and abbrev settings, but there is no point having two separate commit format setting. Fix the confusion. Also properly initialize the command options structure. Signed-off-by: Junio C Hamano --- git.c | 11 ++++++----- log-tree.h | 1 - 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/git.c b/git.c index 0741c5a36d..22fec3d79f 100644 --- a/git.c +++ b/git.c @@ -288,19 +288,20 @@ static int cmd_log(int argc, const char **argv, char **envp) struct rev_info *rev = &wcopt.revopt; struct log_tree_opt *opt = &wcopt.logopt; + memset(&wcopt, 0, sizeof(wcopt)); init_log_tree_opt(&wcopt.logopt); - wcopt.commit_format = CMIT_FMT_DEFAULT; + opt->commit_format = CMIT_FMT_DEFAULT; wcopt.abbrev = DEFAULT_ABBREV; argc = parse_whatchanged_opt(argc, argv, &wcopt); - if (wcopt.logopt.commit_format == CMIT_FMT_ONELINE) + if (opt->commit_format == CMIT_FMT_ONELINE) commit_prefix = ""; prepare_revision_walk(rev); setup_pager(); while ((commit = get_revision(rev)) != NULL) { if (shown && wcopt.do_diff && - wcopt.commit_format != CMIT_FMT_ONELINE) + opt->commit_format != CMIT_FMT_ONELINE) putchar('\n'); fputs(commit_prefix, stdout); if (wcopt.abbrev_commit && wcopt.abbrev) @@ -327,11 +328,11 @@ static int cmd_log(int argc, const char **argv, char **envp) parents = parents->next) parents->item->object.flags &= ~TMP_MARK; } - if (wcopt.commit_format == CMIT_FMT_ONELINE) + if (opt->commit_format == CMIT_FMT_ONELINE) putchar(' '); else putchar('\n'); - pretty_print_commit(wcopt.commit_format, commit, ~0, buf, + pretty_print_commit(opt->commit_format, commit, ~0, buf, LOGSIZE, wcopt.abbrev); printf("%s\n", buf); if (wcopt.do_diff) diff --git a/log-tree.h b/log-tree.h index 50cbfb3012..8d8f6f1458 100644 --- a/log-tree.h +++ b/log-tree.h @@ -25,7 +25,6 @@ int log_tree_opt_parse(struct log_tree_opt *, const char **, int); struct whatchanged_opt { struct rev_info revopt; struct log_tree_opt logopt; - enum cmit_fmt commit_format; int abbrev; int abbrev_commit; int do_diff; From 1fc70b60bfda67205253595ad9dc040019c2efe5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 15 Apr 2006 04:15:07 -0700 Subject: [PATCH 2/2] Built-in git-whatchanged Now "git log" is in reusable shape, add "git whatchanged" which essentially is a synonym with different default for people whose fingers are already trained. There is a subtle difference from the shell-script version; the first line of each entry is now "commit ", instead of "diff-tree (from )." I suspect that showing the parent name that way is useful, so this may be something we would want to fix (the user can say --pretty=raw to get that information but that is a bit ugly). Signed-off-by: Junio C Hamano --- git.c | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/git.c b/git.c index 22fec3d79f..939a34caf9 100644 --- a/git.c +++ b/git.c @@ -278,21 +278,19 @@ static int cmd_help(int argc, const char **argv, char **envp) #define LOGSIZE (65536) -static int cmd_log(int argc, const char **argv, char **envp) +static int cmd_log_wc(int argc, const char **argv, char **envp, + struct whatchanged_opt *wcopt) { - struct whatchanged_opt wcopt; struct commit *commit; char *buf = xmalloc(LOGSIZE); const char *commit_prefix = "commit "; int shown = 0; - struct rev_info *rev = &wcopt.revopt; - struct log_tree_opt *opt = &wcopt.logopt; + struct rev_info *rev = &wcopt->revopt; + struct log_tree_opt *opt = &wcopt->logopt; - memset(&wcopt, 0, sizeof(wcopt)); - init_log_tree_opt(&wcopt.logopt); opt->commit_format = CMIT_FMT_DEFAULT; - wcopt.abbrev = DEFAULT_ABBREV; - argc = parse_whatchanged_opt(argc, argv, &wcopt); + wcopt->abbrev = DEFAULT_ABBREV; + argc = parse_whatchanged_opt(argc, argv, wcopt); if (opt->commit_format == CMIT_FMT_ONELINE) commit_prefix = ""; @@ -300,12 +298,12 @@ static int cmd_log(int argc, const char **argv, char **envp) prepare_revision_walk(rev); setup_pager(); while ((commit = get_revision(rev)) != NULL) { - if (shown && wcopt.do_diff && + if (shown && wcopt->do_diff && opt->commit_format != CMIT_FMT_ONELINE) putchar('\n'); fputs(commit_prefix, stdout); - if (wcopt.abbrev_commit && wcopt.abbrev) - fputs(find_unique_abbrev(commit->object.sha1, wcopt.abbrev), + if (wcopt->abbrev_commit && wcopt->abbrev) + fputs(find_unique_abbrev(commit->object.sha1, wcopt->abbrev), stdout); else fputs(sha1_to_hex(commit->object.sha1), stdout); @@ -333,9 +331,9 @@ static int cmd_log(int argc, const char **argv, char **envp) else putchar('\n'); pretty_print_commit(opt->commit_format, commit, ~0, buf, - LOGSIZE, wcopt.abbrev); + LOGSIZE, wcopt->abbrev); printf("%s\n", buf); - if (wcopt.do_diff) + if (wcopt->do_diff) log_tree_commit(opt, commit); shown = 1; free(commit->buffer); @@ -345,6 +343,26 @@ static int cmd_log(int argc, const char **argv, char **envp) return 0; } +static int cmd_log(int ac, const char **av, char **ep) +{ + struct whatchanged_opt wcopt; + + memset(&wcopt, 0, sizeof(wcopt)); + init_log_tree_opt(&wcopt.logopt); + return cmd_log_wc(ac, av, ep, &wcopt); +} + +static int cmd_whatchanged(int ac, const char **av, char **ep) +{ + struct whatchanged_opt wcopt; + + memset(&wcopt, 0, sizeof(wcopt)); + wcopt.do_diff = 1; + init_log_tree_opt(&wcopt.logopt); + wcopt.logopt.diffopt.recursive = 1; + return cmd_log_wc(ac, av, ep, &wcopt); +} + static void handle_internal_command(int argc, const char **argv, char **envp) { const char *cmd = argv[0]; @@ -355,6 +373,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "version", cmd_version }, { "help", cmd_help }, { "log", cmd_log }, + { "whatchanged", cmd_whatchanged }, }; int i;