Skip to content

Commit 2ba6183

Browse files
committed
Merge branch 'jc/log-p-cc'
"git log --cc" did not show any patch, even though most of the time the user meant "git log --cc -p -m" to see patch output for commits with a single parent, and combined diff for merge commits. The command is taught to DWIM "--cc" (without "--raw" and other forms of output specification) to "--cc -p -m". * jc/log-p-cc: builtin/log.c: minor reformat log: show merge commit when --cc is given log: when --cc is given, default to -p unless told otherwise log: rename "tweak" helpers
2 parents 7b7c10b + 3acf8dd commit 2ba6183

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

builtin/log.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ static int cmd_log_walk(struct rev_info *rev)
342342
* retain that state information if replacing rev->diffopt in this loop
343343
*/
344344
while ((commit = get_revision(rev)) != NULL) {
345-
if (!log_tree_commit(rev, commit) &&
346-
rev->max_count >= 0)
345+
if (!log_tree_commit(rev, commit) && rev->max_count >= 0)
347346
/*
348347
* We decremented max_count in get_revision,
349348
* but we didn't actually show the commit.
@@ -504,7 +503,8 @@ static int show_tree_object(const unsigned char *sha1,
504503
return 0;
505504
}
506505

507-
static void show_rev_tweak_rev(struct rev_info *rev, struct setup_revision_opt *opt)
506+
static void show_setup_revisions_tweak(struct rev_info *rev,
507+
struct setup_revision_opt *opt)
508508
{
509509
if (rev->ignore_merges) {
510510
/* There was no "-m" on the command line */
@@ -539,7 +539,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
539539

540540
memset(&opt, 0, sizeof(opt));
541541
opt.def = "HEAD";
542-
opt.tweak = show_rev_tweak_rev;
542+
opt.tweak = show_setup_revisions_tweak;
543543
cmd_log_init(argc, argv, prefix, &rev, &opt);
544544

545545
if (!rev.no_walk)
@@ -626,12 +626,20 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
626626
return cmd_log_walk(&rev);
627627
}
628628

629-
static void default_follow_tweak(struct rev_info *rev,
630-
struct setup_revision_opt *opt)
629+
static void log_setup_revisions_tweak(struct rev_info *rev,
630+
struct setup_revision_opt *opt)
631631
{
632632
if (DIFF_OPT_TST(&rev->diffopt, DEFAULT_FOLLOW_RENAMES) &&
633633
rev->prune_data.nr == 1)
634634
DIFF_OPT_SET(&rev->diffopt, FOLLOW_RENAMES);
635+
636+
/* Turn --cc/-c into -p --cc/-c when -p was not given */
637+
if (!rev->diffopt.output_format && rev->combine_merges)
638+
rev->diffopt.output_format = DIFF_FORMAT_PATCH;
639+
640+
/* Turn -m on when --cc/-c was given */
641+
if (rev->combine_merges)
642+
rev->ignore_merges = 0;
635643
}
636644

637645
int cmd_log(int argc, const char **argv, const char *prefix)
@@ -647,7 +655,7 @@ int cmd_log(int argc, const char **argv, const char *prefix)
647655
memset(&opt, 0, sizeof(opt));
648656
opt.def = "HEAD";
649657
opt.revarg_opt = REVARG_COMMITTISH;
650-
opt.tweak = default_follow_tweak;
658+
opt.tweak = log_setup_revisions_tweak;
651659
cmd_log_init(argc, argv, prefix, &rev, &opt);
652660
return cmd_log_walk(&rev);
653661
}
@@ -1455,8 +1463,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
14551463
continue;
14561464
}
14571465

1458-
if (ignore_if_in_upstream &&
1459-
has_commit_patch_id(commit, &ids))
1466+
if (ignore_if_in_upstream && has_commit_patch_id(commit, &ids))
14601467
continue;
14611468

14621469
nr++;

0 commit comments

Comments
 (0)