From b130c706ecfaa370259a476c2b754fb4c4a1a180 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 20 Aug 2015 14:14:46 -0700 Subject: [PATCH 1/4] log: rename "tweak" helpers The revision walking API allows the callers to tweak its configuration at the last minute, immediately after all the revision and pathspec parameters are parsed from the command line but before the default actions are decided based on them, by defining a "tweak" callback function when calling setup_revisions(). Traditionally, this facility was used by "git show" to turn on the patch output "-p" by default when no diff output option (e.g. "--raw" or "-s" to squelch the output altogether) is given on the command line, and further give dense combined diffs "--cc" for merge commits when no option to countermand it (e.g. "-m" to show pairwise patches). Recently, "git log" started using the same facility, but we named the callback function "default_follow_tweak()", as if the only kind of tweaking we would want for "git log" will forever be limited to turning "--follow" on by default when told by a configuration variable. That was myopic. Rename it to more generic name "log_setup_revisions_tweak()", and match the one used by show "show_setup_revisions_tweak()". Signed-off-by: Junio C Hamano --- builtin/log.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index b50ef7510..865110534 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -504,7 +504,8 @@ static int show_tree_object(const unsigned char *sha1, return 0; } -static void show_rev_tweak_rev(struct rev_info *rev, struct setup_revision_opt *opt) +static void show_setup_revisions_tweak(struct rev_info *rev, + struct setup_revision_opt *opt) { if (rev->ignore_merges) { /* There was no "-m" on the command line */ @@ -539,7 +540,7 @@ int cmd_show(int argc, const char **argv, const char *prefix) memset(&opt, 0, sizeof(opt)); opt.def = "HEAD"; - opt.tweak = show_rev_tweak_rev; + opt.tweak = show_setup_revisions_tweak; cmd_log_init(argc, argv, prefix, &rev, &opt); if (!rev.no_walk) @@ -626,8 +627,8 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix) return cmd_log_walk(&rev); } -static void default_follow_tweak(struct rev_info *rev, - struct setup_revision_opt *opt) +static void log_setup_revisions_tweak(struct rev_info *rev, + struct setup_revision_opt *opt) { if (DIFF_OPT_TST(&rev->diffopt, DEFAULT_FOLLOW_RENAMES) && rev->prune_data.nr == 1) @@ -647,7 +648,7 @@ int cmd_log(int argc, const char **argv, const char *prefix) memset(&opt, 0, sizeof(opt)); opt.def = "HEAD"; opt.revarg_opt = REVARG_COMMITTISH; - opt.tweak = default_follow_tweak; + opt.tweak = log_setup_revisions_tweak; cmd_log_init(argc, argv, prefix, &rev, &opt); return cmd_log_walk(&rev); } From c7eaf8b4c3085fd2db2a47b83b828e363dcf5fd0 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 20 Aug 2015 14:36:49 -0700 Subject: [PATCH 2/4] log: when --cc is given, default to -p unless told otherwise The "--cc" option to "git log" is clearly a request to show some sort of combined diff (be it --patch or --raw), but traditionally we required the command line to explicitly ask for "git log -p --cc". Teach the command line parser to treat a lone "--cc" as if the user specified "-p --cc". Formats that do ask for other forms of diff output, e.g. "log --raw --cc", are not overriden. Signed-off-by: Junio C Hamano --- builtin/log.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/builtin/log.c b/builtin/log.c index 865110534..e37c27ab7 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -633,6 +633,10 @@ static void log_setup_revisions_tweak(struct rev_info *rev, if (DIFF_OPT_TST(&rev->diffopt, DEFAULT_FOLLOW_RENAMES) && rev->prune_data.nr == 1) DIFF_OPT_SET(&rev->diffopt, FOLLOW_RENAMES); + + /* Turn --cc/-c into -p --cc/-c when -p was not given */ + if (!rev->diffopt.output_format && rev->combine_merges) + rev->diffopt.output_format = DIFF_FORMAT_PATCH; } int cmd_log(int argc, const char **argv, const char *prefix) From 82dee4160cc6d1b0d792c9f07b5803cd42abc610 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 20 Aug 2015 14:36:49 -0700 Subject: [PATCH 3/4] log: show merge commit when --cc is given We defaulted to ignoring merge diffs because long long ago, in a galaxy far away, we didn't have a great way to show the diffs. The whole "--cc" option goes back to January '06 and commit d8f4790e6fe7 ("diff-tree --cc: denser combined diff output for a merge commit"). And before that option - so for about 8 months - we had no good way to show the diffs of merges in a good dense way. So the whole "don't show diffs for merges by default" actually made a lot of sense originally, because our merge diffs were not very useful. And this was carried forward to this day. "git log --cc" still ignores merge commits, and you need to say "git log -m --cc" to view a sensible rendition of merge and non-merge commits, even with the previous change to make "--cc" imply "-p". Teach "git log" that "--cc" means the user wants to see interesting changes in merge commits by turning "-m" on. Signed-off-by: Junio C Hamano --- builtin/log.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/builtin/log.c b/builtin/log.c index e37c27ab7..0cdd88971 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -637,6 +637,10 @@ static void log_setup_revisions_tweak(struct rev_info *rev, /* Turn --cc/-c into -p --cc/-c when -p was not given */ if (!rev->diffopt.output_format && rev->combine_merges) rev->diffopt.output_format = DIFF_FORMAT_PATCH; + + /* Turn -m on when --cc/-c was given */ + if (rev->combine_merges) + rev->ignore_merges = 0; } int cmd_log(int argc, const char **argv, const char *prefix) From 3acf8dd8879c638a517e3810d1df872adfbaaf30 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 20 Aug 2015 15:51:45 -0700 Subject: [PATCH 4/4] builtin/log.c: minor reformat Two logical lines that were not overly long was split in the middle, which made them read worse. Signed-off-by: Junio C Hamano --- builtin/log.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 0cdd88971..a491d3dea 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -342,8 +342,7 @@ static int cmd_log_walk(struct rev_info *rev) * retain that state information if replacing rev->diffopt in this loop */ while ((commit = get_revision(rev)) != NULL) { - if (!log_tree_commit(rev, commit) && - rev->max_count >= 0) + if (!log_tree_commit(rev, commit) && rev->max_count >= 0) /* * We decremented max_count in get_revision, * but we didn't actually show the commit. @@ -1464,8 +1463,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) continue; } - if (ignore_if_in_upstream && - has_commit_patch_id(commit, &ids)) + if (ignore_if_in_upstream && has_commit_patch_id(commit, &ids)) continue; nr++;