Skip to contentSkip to conversation

git-log: implement new --diff-merge options

PATCH In review Sergey Organov 5 participants 232 messages Nov 1, 2020 – Jan 16, 2021 Page 2 of 2

Subsystems (2)
lore
Share & tools
lore
#166 lore raw

Re: [PATCH v2 26/33] diff-merges: let new options enable diff without -p

In reply to Sergey Organov
Quoted 33 lines · Sergey Organov

New options don't have any visible effect unless -p is either given or implied, as unlike -c/-cc we don't imply -p with --diff-merges. To fix this, this patch adds new functionality by letting new options enable output of diffs for merge commits only.

Add 'merges_need_diff' field and set it whenever diff output for merges is enabled by any of the new options.

Extend diff output logic accordingly, to output diffs for merges when 'merges_need_diff' is set even when no -p has been provided.

---
 diff-merges.c | 16 ++++++++++------
 log-tree.c    | 13 +++++++++----
 revision.h    |  1 +
 3 files changed, 20 insertions(+), 10 deletions(-)
diff-merges.c +1 -0
index 725db2312074..ffe20d8daa4a 100644
@@ -10,6 +10,7 @@ static void suppress(struct rev_info *revs)
        revs->dense_combined_merges = 0;
        revs->combined_all_paths = 0;
        revs->combined_imply_patch = 0;
+       revs->merges_need_diff = 0;
 }
 
 static void set_separate(struct rev_info *revs)
@@ -51,9 +52,11 @@ static void set_dense_combined(struct rev_info *revs)
 

diff-merges.c static void set_dense_combined(struct rev_info *revs) · line 57

Quoted 10 lines
diff-merges.c +4 -2
 static void set_diff_merges(struct rev_info *revs, const char *optarg)
 {
 
+       if (!strcmp(optarg, "off") || !strcmp(optarg, "none")) {
+               suppress(revs);
+               return;
+       }
        if (0) ;
-       else if (!strcmp(optarg, "off")   || !strcmp(optarg, "none"))
-               suppress(revs);

The "if (0) ;" is still really weird.

diff-merges.c static void set_diff_merges(struct rev_info *revs, const char *optarg) · line 70

Quoted 8 lines
diff-merges.c +0 -0
        else if (!strcmp(optarg, "first") || !strcmp(optarg, "first-parent"))
                set_first_parent(revs);
        else if (!strcmp(optarg, "sep")   || !strcmp(optarg, "separate"))
diff-merges.c +1 -0
@@ -64,6 +67,7 @@ static void set_diff_merges(struct rev_info *revs, const char *optarg)
                set_dense_combined(revs);
        else
                die(_("unknown value for --diff-merges: %s"), optarg);
+       revs->merges_need_diff = 1;

I'd put this above the if-else-else block, to make it clearer why you are returning early for the "off"/"none" case.

Quoted 9 lines
diff-merges.c +1 -1
 }
 
 /*
@@ -132,12 +136,12 @@ void diff_merges_setup_revs(struct rev_info *revs)
                revs->first_parent_merges = 0;
        if (revs->combined_all_paths && !revs->combine_merges)
                die("--combined-all-paths makes no sense without -c or --cc");
-       if (revs->combine_merges)
+

diff-merges.c void diff_merges_setup_revs(struct rev_info *revs) · line 142

Quoted 10 lines
diff-merges.c +3 -3
+       if (revs->combined_imply_patch)
                revs->diff = 1;
-       if (revs->combined_imply_patch) {
-               /* Turn --cc/-c into -p --cc/-c when -p was not given */
+
+       if (revs->combined_imply_patch || revs->merges_need_diff) {
                if (!revs->diffopt.output_format)
                        revs->diffopt.output_format = DIFF_FORMAT_PATCH;
        }
-

The random space changes squashed in here instead of being combined with the earlier patches that introduced the relevant areas break up the reading. Would be nice to clean this up.

log-tree.c static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log · line 903

Quoted 11 lines
diff-merges.c +0 -0
 }
log-tree.c +2 -0
index f9385b1dae6f..67060492ca0a 100644
@@ -899,15 +899,21 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
        int showed_log;
        struct commit_list *parents;
        struct object_id *oid;
+       int is_merge;
+       int regulars_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;

So rev_info.diff has changed in meaning from commits-need-to-show-a-diff, to non-merge-commits-need-to-show-a-diff. That's a somewhat subtle semantic shift. Perhaps it's worth adding a comment to the declaration of rev_info.diff to highlight this? (And perhaps even rename the flag?)

Quoted 40 lines
log-tree.c +7 -4
-       if (!opt->diff && !opt->diffopt.flags.exit_with_status)
+       if (!regulars_need_diff && !opt->merges_need_diff)
                return 0;
 
        parse_commit_or_die(commit);
        oid = get_commit_tree_oid(commit);
 
-       /* Root commit? */
        parents = get_saved_parents(opt, commit);
+       is_merge = parents && parents->next;
+       if(!is_merge && !regulars_need_diff)
+               return 0;
+
+       /* Root commit? */
        if (!parents) {
                if (opt->show_root_diff) {
                        diff_root_tree_oid(oid, "", &opt->diffopt);
@@ -916,8 +922,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
                return !opt->loginfo;
        }
 
-       /* More than one parent? */
-       if (parents->next) {
+       if (is_merge) {
                if (opt->combine_merges)
                        return do_diff_combined(opt, commit);
                if (opt->separate_merges) {
revision.h +1 -1
index bfbae526ad6e..494d86142454 100644
@@ -194,6 +194,7 @@ struct rev_info {
                        always_show_header:1,
                        /* Diff-merge flags */
                        explicit_diff_merges: 1,
+                       merges_need_diff: 1,
                        separate_merges: 1,
                        combine_merges:1,
                        combined_all_paths:1,
--
Quoted 1 line

2.25.1

The rest makes sense.

#167 lore raw

Re: [PATCH v2 26/33] diff-merges: let new options enable diff without -p

Quoted 45 lines · Elijah Newren
Quoted 33 lines · Sergey Organov

New options don't have any visible effect unless -p is either given or implied, as unlike -c/-cc we don't imply -p with --diff-merges. To fix this, this patch adds new functionality by letting new options enable output of diffs for merge commits only.

Add 'merges_need_diff' field and set it whenever diff output for merges is enabled by any of the new options.

Extend diff output logic accordingly, to output diffs for merges when 'merges_need_diff' is set even when no -p has been provided.

---
 diff-merges.c | 16 ++++++++++------
 log-tree.c    | 13 +++++++++----
 revision.h    |  1 +
 3 files changed, 20 insertions(+), 10 deletions(-)
diff-merges.c +1 -0
index 725db2312074..ffe20d8daa4a 100644
@@ -10,6 +10,7 @@ static void suppress(struct rev_info *revs)
        revs->dense_combined_merges = 0;
        revs->combined_all_paths = 0;
        revs->combined_imply_patch = 0;
+       revs->merges_need_diff = 0;
 }
 
 static void set_separate(struct rev_info *revs)
@@ -51,9 +52,11 @@ static void set_dense_combined(struct rev_info *revs)
 

diff-merges.c static void set_dense_combined(struct rev_info *revs) · line 57

Quoted 10 lines
diff-merges.c +4 -2
 static void set_diff_merges(struct rev_info *revs, const char *optarg)
 {
 
+       if (!strcmp(optarg, "off") || !strcmp(optarg, "none")) {
+               suppress(revs);
+               return;
+       }
        if (0) ;
-       else if (!strcmp(optarg, "off")   || !strcmp(optarg, "none"))
-               suppress(revs);
Quoted 1 line

The "if (0) ;" is still really weird.

An idiom (see my previous answer). I'm fine getting rid of it if you guys find it weird (that I'm not).

Quoted 12 lines

diff-merges.c static void set_diff_merges(struct rev_info *revs, const char *optarg) · line 70

Quoted 9 lines
diff-merges.c +0 -0
        else if (!strcmp(optarg, "first") || !strcmp(optarg, "first-parent"))
                set_first_parent(revs);
        else if (!strcmp(optarg, "sep")   || !strcmp(optarg, "separate"))
diff-merges.c +1 -0
@@ -64,6 +67,7 @@ static void set_diff_merges(struct rev_info *revs, const char *optarg)
                set_dense_combined(revs);
        else
                die(_("unknown value for --diff-merges: %s"), optarg);
+       revs->merges_need_diff = 1;

I'd put this above the if-else-else block, to make it clearer why you are returning early for the "off"/"none" case.

Yeah, makes sense, thanks!

Quoted 34 lines
Quoted 10 lines
diff-merges.c +1 -1
 }
 
 /*
@@ -132,12 +136,12 @@ void diff_merges_setup_revs(struct rev_info *revs)
                revs->first_parent_merges = 0;
        if (revs->combined_all_paths && !revs->combine_merges)
                die("--combined-all-paths makes no sense without -c or --cc");
-       if (revs->combine_merges)
+

diff-merges.c void diff_merges_setup_revs(struct rev_info *revs) · line 142

Quoted 10 lines
diff-merges.c +3 -3
+       if (revs->combined_imply_patch)
                revs->diff = 1;
-       if (revs->combined_imply_patch) {
-               /* Turn --cc/-c into -p --cc/-c when -p was not given */
+
+       if (revs->combined_imply_patch || revs->merges_need_diff) {
                if (!revs->diffopt.output_format)
                        revs->diffopt.output_format = DIFF_FORMAT_PATCH;
        }
-

The random space changes squashed in here instead of being combined with the earlier patches that introduced the relevant areas break up the reading. Would be nice to clean this up.

Quoted 9 lines
diff-merges.c +0 -0
 }
log-tree.c +0 -0
index f9385b1dae6f..67060492ca0a 100644
@@ -899,15 +899,21 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
        int showed_log;
        struct commit_list *parents;
        struct object_id *oid;
Quoted 8 lines

log-tree.c static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log · line 903

Quoted 2 lines
log-tree.c +2 -0
+       int is_merge;
+       int regulars_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;

So rev_info.diff has changed in meaning from commits-need-to-show-a-diff, to non-merge-commits-need-to-show-a-diff. That's a somewhat subtle semantic shift. Perhaps it's worth adding a comment to the declaration of rev_info.diff to highlight this? (And perhaps even rename the flag?)

No, the meaning of rev_info.diff hopefully didn't change. rev_info.diff still enables all the commits to pass further once set. It is still exactly the same old condition, just assigned to a variable for reuse. My aim was to avoid touching existing logic of this function and only add a new functionality when opt->merges_need_diff is set.

It looks like I rather choose confusing name for the variable, and it'd be more clear if I'd call this, say:

  int need_diff = opt->diff || opt->diffopt.flags.exit_with_status;

?

What do you think?

Quoted 36 lines
Quoted 36 lines
log-tree.c +7 -4
-       if (!opt->diff && !opt->diffopt.flags.exit_with_status)
+       if (!regulars_need_diff && !opt->merges_need_diff)
                return 0;
 
        parse_commit_or_die(commit);
        oid = get_commit_tree_oid(commit);
 
-       /* Root commit? */
        parents = get_saved_parents(opt, commit);
+       is_merge = parents && parents->next;
+       if(!is_merge && !regulars_need_diff)
+               return 0;
+
+       /* Root commit? */
        if (!parents) {
                if (opt->show_root_diff) {
                        diff_root_tree_oid(oid, "", &opt->diffopt);
@@ -916,8 +922,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
                return !opt->loginfo;
        }
 
-       /* More than one parent? */
-       if (parents->next) {
+       if (is_merge) {
                if (opt->combine_merges)
                        return do_diff_combined(opt, commit);
                if (opt->separate_merges) {
revision.h +0 -0
index bfbae526ad6e..494d86142454 100644
@@ -194,6 +194,7 @@ struct rev_info {
                        always_show_header:1,
                        /* Diff-merge flags */
                        explicit_diff_merges: 1,
Quoted 8 lines
Quoted 6 lines
revision.h +1 -1
+                       merges_need_diff: 1,
                        separate_merges: 1,
                        combine_merges:1,
                        combined_all_paths:1,
--

2.25.1

The rest makes sense.

Thanks,
-- Sergey

#168 lore raw

Re: [PATCH v2 26/33] diff-merges: let new options enable diff without -p

Quoted 48 lines · Sergey Organov
Quoted 45 lines · Elijah Newren
Quoted 43 lines · Sergey Organov

New options don't have any visible effect unless -p is either given or implied, as unlike -c/-cc we don't imply -p with --diff-merges. To fix this, this patch adds new functionality by letting new options enable output of diffs for merge commits only.

Add 'merges_need_diff' field and set it whenever diff output for merges is enabled by any of the new options.

Extend diff output logic accordingly, to output diffs for merges when 'merges_need_diff' is set even when no -p has been provided.

---
 diff-merges.c | 16 ++++++++++------
 log-tree.c    | 13 +++++++++----
 revision.h    |  1 +
 3 files changed, 20 insertions(+), 10 deletions(-)
diff-merges.c +5 -2
index 725db2312074..ffe20d8daa4a 100644
@@ -10,6 +10,7 @@ static void suppress(struct rev_info *revs)
        revs->dense_combined_merges = 0;
        revs->combined_all_paths = 0;
        revs->combined_imply_patch = 0;
+       revs->merges_need_diff = 0;
 }
 
 static void set_separate(struct rev_info *revs)
@@ -51,9 +52,11 @@ static void set_dense_combined(struct rev_info *revs)
 
 static void set_diff_merges(struct rev_info *revs, const char *optarg)
 {
 
+       if (!strcmp(optarg, "off") || !strcmp(optarg, "none")) {
+               suppress(revs);
+               return;
+       }
        if (0) ;
-       else if (!strcmp(optarg, "off")   || !strcmp(optarg, "none"))
-               suppress(revs);
Quoted 4 lines
Quoted 1 line

The "if (0) ;" is still really weird.

An idiom (see my previous answer). I'm fine getting rid of it if you guys find it weird (that I'm not).

I've never seen this idiom, and we apparently have no uses of it in the code. If it were near any code I was editing, I think I'd rip it out as a preliminary cleanup patch...but maybe others have other opinions.

Quoted 64 lines
Quoted 12 lines

diff-merges.c static void set_diff_merges(struct rev_info *revs, const char *optarg) · line 70

Quoted 9 lines
diff-merges.c +0 -0
        else if (!strcmp(optarg, "first") || !strcmp(optarg, "first-parent"))
                set_first_parent(revs);
        else if (!strcmp(optarg, "sep")   || !strcmp(optarg, "separate"))
diff-merges.c +1 -0
@@ -64,6 +67,7 @@ static void set_diff_merges(struct rev_info *revs, const char *optarg)
                set_dense_combined(revs);
        else
                die(_("unknown value for --diff-merges: %s"), optarg);
+       revs->merges_need_diff = 1;

I'd put this above the if-else-else block, to make it clearer why you are returning early for the "off"/"none" case.

Yeah, makes sense, thanks!

Quoted 34 lines
Quoted 10 lines
diff-merges.c +1 -1
 }
 
 /*
@@ -132,12 +136,12 @@ void diff_merges_setup_revs(struct rev_info *revs)
                revs->first_parent_merges = 0;
        if (revs->combined_all_paths && !revs->combine_merges)
                die("--combined-all-paths makes no sense without -c or --cc");
-       if (revs->combine_merges)
+

diff-merges.c void diff_merges_setup_revs(struct rev_info *revs) · line 142

Quoted 10 lines
diff-merges.c +3 -3
+       if (revs->combined_imply_patch)
                revs->diff = 1;
-       if (revs->combined_imply_patch) {
-               /* Turn --cc/-c into -p --cc/-c when -p was not given */
+
+       if (revs->combined_imply_patch || revs->merges_need_diff) {
                if (!revs->diffopt.output_format)
                        revs->diffopt.output_format = DIFF_FORMAT_PATCH;
        }
-

The random space changes squashed in here instead of being combined with the earlier patches that introduced the relevant areas break up the reading. Would be nice to clean this up.

Quoted 9 lines
diff-merges.c +0 -0
 }
log-tree.c +0 -0
index f9385b1dae6f..67060492ca0a 100644
@@ -899,15 +899,21 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
        int showed_log;
        struct commit_list *parents;
        struct object_id *oid;
Quoted 8 lines

log-tree.c static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log · line 903

Quoted 2 lines
log-tree.c +2 -0
+       int is_merge;
+       int regulars_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;

So rev_info.diff has changed in meaning from commits-need-to-show-a-diff, to non-merge-commits-need-to-show-a-diff. That's a somewhat subtle semantic shift. Perhaps it's worth adding a comment to the declaration of rev_info.diff to highlight this? (And perhaps even rename the flag?)

No, the meaning of rev_info.diff hopefully didn't change. rev_info.diff still enables all the commits to pass further once set. It is still exactly the same old condition, just assigned to a variable for reuse. My aim was to avoid touching existing logic of this function and only add a new functionality when opt->merges_need_diff is set.

Quoted 8 lines

It looks like I rather choose confusing name for the variable, and it'd be more clear if I'd call this, say:

  int need_diff = opt->diff || opt->diffopt.flags.exit_with_status;

?

What do you think?

I think need_diff would actually be confusing. It can be false when you need diffs (e.g. --diff-merges=cc with no -p, because then you'd need diffs for merge commits and not for non-merge commits). I'd stick with your original local variable name.

Perhaps opt->diff hasn't changed meaning and I just had a wrong mental model in my head for what it meant, but even then what seems like its obvious purpose given its name is mismatched with what it actually does. Since you are already changing struct rev_info in this series, this was more a note that a name change or at least a comment for opt->diff might be useful. I mean, you asked a couple times on the previous series for help trying to understand it, and I could only offer some flailing guesses and Junio responded with a couple bits of history. Clearly, it isn't very clear and this patch reminded me of that and made me wonder if we're possibly making it a little harder for others further down the road to figure out.

Quoted 46 lines
Quoted 35 lines
Quoted 35 lines
log-tree.c +7 -4
-       if (!opt->diff && !opt->diffopt.flags.exit_with_status)
+       if (!regulars_need_diff && !opt->merges_need_diff)
                return 0;
 
        parse_commit_or_die(commit);
        oid = get_commit_tree_oid(commit);
 
-       /* Root commit? */
        parents = get_saved_parents(opt, commit);
+       is_merge = parents && parents->next;
+       if(!is_merge && !regulars_need_diff)
+               return 0;
+
+       /* Root commit? */
        if (!parents) {
                if (opt->show_root_diff) {
                        diff_root_tree_oid(oid, "", &opt->diffopt);
@@ -916,8 +922,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
                return !opt->loginfo;
        }
 
-       /* More than one parent? */
-       if (parents->next) {
+       if (is_merge) {
                if (opt->combine_merges)
                        return do_diff_combined(opt, commit);
                if (opt->separate_merges) {
revision.h +0 -0
index bfbae526ad6e..494d86142454 100644
@@ -194,6 +194,7 @@ struct rev_info {
                        always_show_header:1,
                        /* Diff-merge flags */
                        explicit_diff_merges: 1,
Quoted 8 lines
Quoted 6 lines
revision.h +1 -1
+                       merges_need_diff: 1,
                        separate_merges: 1,
                        combine_merges:1,
                        combined_all_paths:1,
--

2.25.1

The rest makes sense.

Thanks,
-- Sergey

#169 lore raw

Re: [PATCH v2 26/33] diff-merges: let new options enable diff without -p

Quoted 5 lines · Elijah Newren
Quoted 4 lines · Sergey Organov
Quoted 1 line · Elijah Newren

On Wed, Dec 16, 2020 at 10:50 AM Sergey Organov <[email protected]> wrote:

[...]

Quoted 37 lines
Quoted 23 lines
Quoted 8 lines
Quoted 8 lines
log-tree.c +0 -0
index f9385b1dae6f..67060492ca0a 100644
@@ -899,15 +899,21 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
        int showed_log;
        struct commit_list *parents;
        struct object_id *oid;
Quoted 8 lines

log-tree.c static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log · line 903

Quoted 2 lines
log-tree.c +2 -0
+       int is_merge;
+       int regulars_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;

So rev_info.diff has changed in meaning from commits-need-to-show-a-diff, to non-merge-commits-need-to-show-a-diff. That's a somewhat subtle semantic shift. Perhaps it's worth adding a comment to the declaration of rev_info.diff to highlight this? (And perhaps even rename the flag?)

No, the meaning of rev_info.diff hopefully didn't change. rev_info.diff still enables all the commits to pass further once set. It is still exactly the same old condition, just assigned to a variable for reuse. My aim was to avoid touching existing logic of this function and only add a new functionality when opt->merges_need_diff is set.

Quoted 8 lines

It looks like I rather choose confusing name for the variable, and it'd be more clear if I'd call this, say:

  int need_diff = opt->diff || opt->diffopt.flags.exit_with_status;

?

What do you think?

I think need_diff would actually be confusing. It can be false when you need diffs (e.g. --diff-merges=cc with no -p, because then you'd need diffs for merge commits and not for non-merge commits). I'd stick with your original local variable name.

Quoted 11 lines

Perhaps opt->diff hasn't changed meaning and I just had a wrong mental model in my head for what it meant, but even then what seems like its obvious purpose given its name is mismatched with what it actually does. Since you are already changing struct rev_info in this series, this was more a note that a name change or at least a comment for opt->diff might be useful. I mean, you asked a couple times on the previous series for help trying to understand it, and I could only offer some flailing guesses and Junio responded with a couple bits of history. Clearly, it isn't very clear and this patch reminded me of that and made me wonder if we're possibly making it a little harder for others further down the road to figure out.

I still don't see why opt->diff is needed in the first place, and second, why opt->diffopt.flags.exit_with_status check is here? Why whoever sets opt->diffopt.flags.exit_with_status doesn't just set opt->diff as well (provided opt->diff is needed in the first place)?

From the aforementioned discussion it looks like opt->diff is an optimization (maybe a remnant from the times when diff was a separate script), and that apparently there is some code instance somewhere that actually relies on the fact that clearing opt->diff is enough to disable diff machinery (as followed from my experiment of removing the check altogether and then getting only single seemingly unrelated test failing.)

Overall, neither have I any idea how to clarify this, nor do I want to bother in this patch series. It'd be nice though if somebody who really does understand diff machinery in Git does the job.

Thanks,
-- Sergey

#170 lore raw

Re: [PATCH v2 26/33] diff-merges: let new options enable diff without -p

Quoted 73 lines · Sergey Organov
Quoted 5 lines · Elijah Newren
Quoted 4 lines · Sergey Organov
Quoted 1 line · Elijah Newren

On Wed, Dec 16, 2020 at 10:50 AM Sergey Organov <[email protected]> wrote:

[...]

Quoted 37 lines
Quoted 23 lines
Quoted 8 lines
Quoted 8 lines
log-tree.c +0 -0
index f9385b1dae6f..67060492ca0a 100644
@@ -899,15 +899,21 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
        int showed_log;
        struct commit_list *parents;
        struct object_id *oid;
Quoted 8 lines

log-tree.c static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log · line 903

Quoted 2 lines
log-tree.c +2 -0
+       int is_merge;
+       int regulars_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;

So rev_info.diff has changed in meaning from commits-need-to-show-a-diff, to non-merge-commits-need-to-show-a-diff. That's a somewhat subtle semantic shift. Perhaps it's worth adding a comment to the declaration of rev_info.diff to highlight this? (And perhaps even rename the flag?)

No, the meaning of rev_info.diff hopefully didn't change. rev_info.diff still enables all the commits to pass further once set. It is still exactly the same old condition, just assigned to a variable for reuse. My aim was to avoid touching existing logic of this function and only add a new functionality when opt->merges_need_diff is set.

Quoted 8 lines

It looks like I rather choose confusing name for the variable, and it'd be more clear if I'd call this, say:

  int need_diff = opt->diff || opt->diffopt.flags.exit_with_status;

?

What do you think?

I think need_diff would actually be confusing. It can be false when you need diffs (e.g. --diff-merges=cc with no -p, because then you'd need diffs for merge commits and not for non-merge commits). I'd stick with your original local variable name.

Quoted 11 lines

Perhaps opt->diff hasn't changed meaning and I just had a wrong mental model in my head for what it meant, but even then what seems like its obvious purpose given its name is mismatched with what it actually does. Since you are already changing struct rev_info in this series, this was more a note that a name change or at least a comment for opt->diff might be useful. I mean, you asked a couple times on the previous series for help trying to understand it, and I could only offer some flailing guesses and Junio responded with a couple bits of history. Clearly, it isn't very clear and this patch reminded me of that and made me wonder if we're possibly making it a little harder for others further down the road to figure out.

I still don't see why opt->diff is needed in the first place, and second, why opt->diffopt.flags.exit_with_status check is here? Why whoever sets opt->diffopt.flags.exit_with_status doesn't just set opt->diff as well (provided opt->diff is needed in the first place)?

From the aforementioned discussion it looks like opt->diff is an optimization (maybe a remnant from the times when diff was a separate script), and that apparently there is some code instance somewhere that actually relies on the fact that clearing opt->diff is enough to disable diff machinery (as followed from my experiment of removing the check altogether and then getting only single seemingly unrelated test failing.)

Quoted 3 lines

Overall, neither have I any idea how to clarify this, nor do I want to bother in this patch series. It'd be nice though if somebody who really does understand diff machinery in Git does the job.

Doh, I was hoping you had it all figured out. If not, then that's a fair enough argument not to attempt to clarify.

#171 lore raw

Re: [PATCH v2 26/33] diff-merges: let new options enable diff without -p

Quoted 77 lines · Elijah Newren
Quoted 76 lines · Sergey Organov
Quoted 6 lines · Elijah Newren
Quoted 5 lines · Sergey Organov
Quoted 2 lines · Elijah Newren

On Wed, Dec 16, 2020 at 10:50 AM Sergey Organov
<[email protected]> wrote:

[...]

Quoted 39 lines
Quoted 25 lines
Quoted 10 lines
Quoted 10 lines
log-tree.c +1 -0
index f9385b1dae6f..67060492ca0a 100644
@@ -899,15 +899,21 @@ static int log_tree_diff(struct rev_info
 *opt, struct commit *commit, struct log
        int showed_log;
        struct commit_list *parents;
        struct object_id *oid;
+       int is_merge;
Quoted 8 lines

log-tree.c static int log_tree_diff(struct rev_info · line 905

Quoted 2 lines
log-tree.c +1 -0
+ int regulars_need_diff = opt->diff ||
 opt->diffopt.flags.exit_with_status;

So rev_info.diff has changed in meaning from commits-need-to-show-a-diff, to non-merge-commits-need-to-show-a-diff. That's a somewhat subtle semantic shift. Perhaps it's worth adding a comment to the declaration of rev_info.diff to highlight this? (And perhaps even rename the flag?)

No, the meaning of rev_info.diff hopefully didn't change. rev_info.diff still enables all the commits to pass further once set. It is still exactly the same old condition, just assigned to a variable for reuse. My aim was to avoid touching existing logic of this function and only add a new functionality when opt->merges_need_diff is set.

Quoted 8 lines

It looks like I rather choose confusing name for the variable, and it'd be more clear if I'd call this, say:

  int need_diff = opt->diff || opt->diffopt.flags.exit_with_status;

?

What do you think?

I think need_diff would actually be confusing. It can be false when you need diffs (e.g. --diff-merges=cc with no -p, because then you'd need diffs for merge commits and not for non-merge commits). I'd stick with your original local variable name.

Quoted 11 lines

Perhaps opt->diff hasn't changed meaning and I just had a wrong mental model in my head for what it meant, but even then what seems like its obvious purpose given its name is mismatched with what it actually does. Since you are already changing struct rev_info in this series, this was more a note that a name change or at least a comment for opt->diff might be useful. I mean, you asked a couple times on the previous series for help trying to understand it, and I could only offer some flailing guesses and Junio responded with a couple bits of history. Clearly, it isn't very clear and this patch reminded me of that and made me wonder if we're possibly making it a little harder for others further down the road to figure out.

I still don't see why opt->diff is needed in the first place, and second, why opt->diffopt.flags.exit_with_status check is here? Why whoever sets opt->diffopt.flags.exit_with_status doesn't just set opt->diff as well (provided opt->diff is needed in the first place)?

From the aforementioned discussion it looks like opt->diff is an optimization (maybe a remnant from the times when diff was a separate script), and that apparently there is some code instance somewhere that actually relies on the fact that clearing opt->diff is enough to disable diff machinery (as followed from my experiment of removing the check altogether and then getting only single seemingly unrelated test failing.)

Quoted 5 lines
Quoted 3 lines

Overall, neither have I any idea how to clarify this, nor do I want to bother in this patch series. It'd be nice though if somebody who really does understand diff machinery in Git does the job.

Doh, I was hoping you had it all figured out.

I tried. I failed. :-)

Quoted 1 line

If not, then that's a fair enough argument not to attempt to clarify.

This.

Thanks,
-- Sergey

#172 lore raw

Re: [PATCH v2 26/33] diff-merges: let new options enable diff without -p

In reply to Elijah Newren
Quoted 51 lines · Elijah Newren
Quoted 50 lines · Sergey Organov
Quoted 46 lines · Elijah Newren
Quoted 33 lines · Sergey Organov

New options don't have any visible effect unless -p is either given or implied, as unlike -c/-cc we don't imply -p with --diff-merges. To fix this, this patch adds new functionality by letting new options enable output of diffs for merge commits only.

Add 'merges_need_diff' field and set it whenever diff output for merges is enabled by any of the new options.

Extend diff output logic accordingly, to output diffs for merges when 'merges_need_diff' is set even when no -p has been provided.

---
 diff-merges.c | 16 ++++++++++------
 log-tree.c    | 13 +++++++++----
 revision.h    |  1 +
 3 files changed, 20 insertions(+), 10 deletions(-)
diff-merges.c +1 -0
index 725db2312074..ffe20d8daa4a 100644
@@ -10,6 +10,7 @@ static void suppress(struct rev_info *revs)
        revs->dense_combined_merges = 0;
        revs->combined_all_paths = 0;
        revs->combined_imply_patch = 0;
+       revs->merges_need_diff = 0;
 }
 
 static void set_separate(struct rev_info *revs)
@@ -51,9 +52,11 @@ static void set_dense_combined(struct rev_info *revs)
 

diff-merges.c static void set_dense_combined(struct rev_info *revs) · line 57

Quoted 10 lines
diff-merges.c +4 -2
 static void set_diff_merges(struct rev_info *revs, const char *optarg)
 {
 
+       if (!strcmp(optarg, "off") || !strcmp(optarg, "none")) {
+               suppress(revs);
+               return;
+       }
        if (0) ;
-       else if (!strcmp(optarg, "off")   || !strcmp(optarg, "none"))
-               suppress(revs);

The "if (0) ;" is still really weird.

Quoted 7 lines
Quoted 2 lines

An idiom (see my previous answer). I'm fine getting rid of it if you guys find it weird (that I'm not).

I've never seen this idiom, and we apparently have no uses of it in the code. If it were near any code I was editing, I think I'd rip it out as a preliminary cleanup patch...but maybe others have other opinions.

Essentially, this is poor man replacement for non-existent:

    switch(s) {
      case "str11": case "str12":
         do_things1(); break;
      case "str21": case "str22":
         do_things2(); break;
      case "str31": case "str32":
         do_things3(); break;
      default:
         default(); break
    }

Notice that all the case statements, except the last one, look the same, while with bare "if() else" constructs you get the first one looking special:

    if (!strcmp(s, "str11") || !strcmp(s, "str12"))
       do_things1();
    else if (!strcmp(s, "str21") || !strcmp(s, "str22"))
       do_things2();
    else if (!strcmp(s, "str31") || !strcmp(s, "str32"))
       do_things3();
    else
       default();

Now, fixing it is as easy as:

    if (0);
    else if (!strcmp(s, "str11") || !strcmp(s, "str12"))
       do_things1();
    else if (!strcmp(s, "str21") || !strcmp(s, "str22"))
       do_things2();
    else if (!strcmp(s, "str31") || !strcmp(s, "str32"))
       do_things3();
    else
       default();

and it makes reordering and #ifdefing slightly less painful as well.

Just saying rather, than insisting on adopting or even accepting it for the Git codebase.

Thanks,
-- Sergey

#173 lore raw

Re: [PATCH v2 26/33] diff-merges: let new options enable diff without -p

In reply to Elijah Newren
Quoted 23 lines · Elijah Newren
Quoted 22 lines · Sergey Organov
Quoted 19 lines · Elijah Newren
Quoted 18 lines · Sergey Organov

New options don't have any visible effect unless -p is either given or implied, as unlike -c/-cc we don't imply -p with --diff-merges. To fix this, this patch adds new functionality by letting new options enable output of diffs for merge commits only.

Add 'merges_need_diff' field and set it whenever diff output for merges is enabled by any of the new options.

Extend diff output logic accordingly, to output diffs for merges when 'merges_need_diff' is set even when no -p has been provided.

---
 diff-merges.c | 16 ++++++++++------
 log-tree.c    | 13 +++++++++----
 revision.h    |  1 +
 3 files changed, 20 insertions(+), 10 deletions(-)

[...]

Quoted 28 lines
Quoted 28 lines
Quoted 8 lines
Quoted 8 lines
log-tree.c +0 -0
index f9385b1dae6f..67060492ca0a 100644
@@ -899,15 +899,21 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
        int showed_log;
        struct commit_list *parents;
        struct object_id *oid;
Quoted 8 lines

log-tree.c static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log · line 903

Quoted 2 lines
log-tree.c +2 -0
+       int is_merge;
+       int regulars_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;

So rev_info.diff has changed in meaning from commits-need-to-show-a-diff, to non-merge-commits-need-to-show-a-diff. That's a somewhat subtle semantic shift. Perhaps it's worth adding a comment to the declaration of rev_info.diff to highlight this? (And perhaps even rename the flag?)

No, the meaning of rev_info.diff hopefully didn't change. rev_info.diff still enables all the commits to pass further once set. It is still exactly the same old condition, just assigned to a variable for reuse. My aim was to avoid touching existing logic of this function and only add a new functionality when opt->merges_need_diff is set.

It looks like I rather choose confusing name for the variable, and it'd be more clear if I'd call this, say:

  int need_diff = opt->diff || opt->diffopt.flags.exit_with_status;
Quoted 8 lines
Quoted 3 lines

?

What do you think?

I think need_diff would actually be confusing. It can be false when you need diffs (e.g. --diff-merges=cc with no -p, because then you'd need diffs for merge commits and not for non-merge commits). I'd stick with your original local variable name.

The problem is that original name I've used lies to the reader, or, more precisely, tells half-truth. True meaning of the variable is "do run diff for any commit, no matter if it's merge or not". So "need_diff" is already better than "regulars_need_diff".

Maybe "diff_all_commits" will do?

Thanks,
-- Sergey

#174 lore raw

Re: [PATCH v2 26/33] diff-merges: let new options enable diff without -p

Quoted 6 lines · Sergey Organov

The problem is that original name I've used lies to the reader, or, more precisely, tells half-truth. True meaning of the variable is "do run diff for any commit, no matter if it's merge or not". So "need_diff" is already better than "regulars_need_diff".

Maybe "diff_all_commits" will do?

all_need_diff

Signature · 1 line
Felipe Contreras
#175 lore raw

Re: [PATCH v2 26/33] diff-merges: let new options enable diff without -p

Quoted 9 lines · Felipe Contreras
Quoted 6 lines · Sergey Organov

The problem is that original name I've used lies to the reader, or, more precisely, tells half-truth. True meaning of the variable is "do run diff for any commit, no matter if it's merge or not". So "need_diff" is already better than "regulars_need_diff".

Maybe "diff_all_commits" will do?

all_need_diff

Fine with me.

Thanks,
-- Sergey

#176 lore raw

Re: [PATCH v2 26/33] diff-merges: let new options enable diff without -p

In reply to Sergey Organov
Quoted 4 lines · Sergey Organov
Quoted 2 lines · Elijah Newren
Quoted 1 line · Sergey Organov

[...]

Quoted 13 lines
Quoted 12 lines

diff-merges.c static void set_diff_merges(struct rev_info *revs, const char *optarg) · line 70

Quoted 9 lines
        else if (!strcmp(optarg, "first") || !strcmp(optarg, "first-parent"))
                set_first_parent(revs);
        else if (!strcmp(optarg, "sep")   || !strcmp(optarg, "separate"))
diff-merges.c +1 -0
@@ -64,6 +67,7 @@ static void set_diff_merges(struct rev_info *revs, const char *optarg)
                set_dense_combined(revs);
        else
                die(_("unknown value for --diff-merges: %s"), optarg);
+       revs->merges_need_diff = 1;

I'd put this above the if-else-else block, to make it clearer why you are returning early for the "off"/"none" case.

Quoted 1 line

Yeah, makes sense, thanks!

In fact this can't be done as it changes the outcome, as set_xxx() functions clear the flag.

I rather added clarification comments to the code.

Thanks,
-- Sergey

#177 lore raw

RE: [PATCH v2 26/33] diff-merges: let new options enable diff without -p

In reply to Sergey Organov
Quoted 13 lines · Sergey Organov
log-tree.c +3 -1
index f9385b1dae6f..67060492ca0a 100644
@@ -899,15 +899,21 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
 	int showed_log;
 	struct commit_list *parents;
 	struct object_id *oid;
+	int is_merge;
+	int regulars_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;
 
-	if (!opt->diff && !opt->diffopt.flags.exit_with_status)
+	if (!regulars_need_diff && !opt->merges_need_diff)

log-tree.c static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log · line 914

Quoted 10 lines
log-tree.c +3 -1
 		return 0;
 
 	parse_commit_or_die(commit);
 	oid = get_commit_tree_oid(commit);
 
-	/* Root commit? */
 	parents = get_saved_parents(opt, commit);
+	is_merge = parents && parents->next;
+	if(!is_merge && !regulars_need_diff)
+		return 0;

Missed a space:

        if (!is_merge && !regulars_need_diff)
Signature · 1 line
Felipe Contreras
#178 lore raw

Re: [PATCH v2 26/33] diff-merges: let new options enable diff without -p

Quoted 27 lines · Felipe Contreras
Quoted 13 lines · Sergey Organov
log-tree.c +3 -1
index f9385b1dae6f..67060492ca0a 100644
@@ -899,15 +899,21 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
 	int showed_log;
 	struct commit_list *parents;
 	struct object_id *oid;
+	int is_merge;
+	int regulars_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;
 
-	if (!opt->diff && !opt->diffopt.flags.exit_with_status)
+	if (!regulars_need_diff && !opt->merges_need_diff)

log-tree.c static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log · line 914

Quoted 10 lines
log-tree.c +3 -1
 		return 0;
 
 	parse_commit_or_die(commit);
 	oid = get_commit_tree_oid(commit);
 
-	/* Root commit? */
 	parents = get_saved_parents(opt, commit);
+	is_merge = parents && parents->next;
+	if(!is_merge && !regulars_need_diff)
+		return 0;

Missed a space:

Quoted 1 line
        if (!is_merge && !regulars_need_diff)

Oops, thanks!

-- Sergey

#179 lore raw

PATCH v2 27/33 diff-merges: add old mnemonic counterparts to --diff-merges

In reply to Sergey Organov

This adds --diff-merges={m|c|cc} values that match mnemonics of old options, for those who are used to them.

Note that, say, --diff-meres=cc behaves differently than --cc, as the latter implies -p and therefore enables diffs for all the commits, while the former enables output of diffs for merge commits only.

---
 diff-merges.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff-merges.c +6 -3
index ffe20d8daa4a..9492cd2b871d 100644
@@ -59,11 +59,14 @@ static void set_diff_merges(struct rev_info *revs, const char *optarg)
 	if (0) ;
 	else if (!strcmp(optarg, "first") || !strcmp(optarg, "first-parent"))
 		set_first_parent(revs);
-	else if (!strcmp(optarg, "sep")   || !strcmp(optarg, "separate"))
+	else if (!strcmp(optarg, "sep")   || !strcmp(optarg, "separate") ||
+		 !strcmp(optarg, "m"))
 		set_separate(revs);
-	else if (!strcmp(optarg, "comb")  || !strcmp(optarg, "combined"))
+	else if (!strcmp(optarg, "comb")  || !strcmp(optarg, "combined") ||
+		 !strcmp(optarg, "c"))
 		set_combined(revs);
-	else if (!strcmp(optarg, "dense") || !strcmp(optarg, "dense-combined"))
+	else if (!strcmp(optarg, "dense") || !strcmp(optarg, "dense-combined") ||
+		 !strcmp(optarg, "cc"))
 		set_dense_combined(revs);
 	else
 		die(_("unknown value for --diff-merges: %s"), optarg);
Signature · 1 line
2.25.1
#180 lore raw

PATCH v2 28/33 diff-merges: add '--diff-merges=1' as synonym for 'first-parent'

In reply to Sergey Organov

As we now have --diff-merges={m|c|cc}, add --diff-merges=1 as synonym for --diff-merges=first-parent, to have shorter mnemonics for it as well.

---
 diff-merges.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff-merges.c +2 -1
index 9492cd2b871d..63a0d78b7730 100644
@@ -57,7 +57,8 @@ static void set_diff_merges(struct rev_info *revs, const char *optarg)
 		return;
 	}
 	if (0) ;
-	else if (!strcmp(optarg, "first") || !strcmp(optarg, "first-parent"))
+	else if (!strcmp(optarg, "first") || !strcmp(optarg, "first-parent") ||
+		 !strcmp(optarg, "1"))
 		set_first_parent(revs);
 	else if (!strcmp(optarg, "sep")   || !strcmp(optarg, "separate") ||
 		 !strcmp(optarg, "m"))
Signature · 1 line
2.25.1
#181 lore raw

Re: [PATCH v2 28/33] diff-merges: add '--diff-merges=1' as synonym for 'first-parent'

Quoted 4 lines · Sergey Organov

As we now have --diff-merges={m|c|cc}, add --diff-merges=1 as synonym for --diff-merges=first-parent, to have shorter mnemonics for it as well.

In all the other cases, --diff-merges=<short> is equivalent to -<short>. Here, --diff-merges=1 and -1 do _very_ different things. Is there any concern that might cause confusion? (My gut reaction is this is probably fine and people won't try to make such a connection, but it made me worry just enough that I thought I'd flag it for you and other reviewers to at least mull over and maybe comment on.)

Quoted 22 lines
---
 diff-merges.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff-merges.c +2 -2
index 9492cd2b871d..63a0d78b7730 100644
@@ -57,7 +57,8 @@ static void set_diff_merges(struct rev_info *revs, const char *optarg)
                return;
        }
        if (0) ;
-       else if (!strcmp(optarg, "first") || !strcmp(optarg, "first-parent"))
+       else if (!strcmp(optarg, "first") || !strcmp(optarg, "first-parent") ||
+                !strcmp(optarg, "1"))
                set_first_parent(revs);
        else if (!strcmp(optarg, "sep")   || !strcmp(optarg, "separate") ||
                 !strcmp(optarg, "m"))
--

2.25.1

#182 lore raw

Re: [PATCH v2 28/33] diff-merges: add '--diff-merges=1' as synonym for 'first-parent'

Quoted 6 lines · Elijah Newren
Quoted 4 lines · Sergey Organov

As we now have --diff-merges={m|c|cc}, add --diff-merges=1 as synonym for --diff-merges=first-parent, to have shorter mnemonics for it as well.

Quoted 6 lines

In all the other cases, --diff-merges=<short> is equivalent to -<short>. Here, --diff-merges=1 and -1 do _very_ different things. Is there any concern that might cause confusion? (My gut reaction is this is probably fine and people won't try to make such a connection, but it made me worry just enough that I thought I'd flag it for you and other reviewers to at least mull over and maybe comment on.)

I wasn't sure about this myself, and that was one reason to make this separate commit.

I think this one also came from the idea that one might want to have, say, --diff-merges=2 in the future and get diff with respect to the second parent.

Thanks,
-- Sergey

#183 lore raw

PATCH v2 29/33 doc/git-log: describe new --diff-merges options

In reply to Sergey Organov

Describe all the new --diff-merges options in the git-log.txt and adopt description of originals accordingly.

---
 Documentation/git-log.txt | 85 ++++++++++++++++++++++++---------------
 1 file changed, 52 insertions(+), 33 deletions(-)
Documentation/git-log.txt +52 -33
index 2b8ac5ff882a..27bc619490c6 100644
@@ -120,45 +120,64 @@ DIFF FORMATTING
 By default, `git log` does not generate any diff output. The options
 below can be used to show the changes made by each commit.
 
-Note that unless one of `-c`, `--cc`, or `-m` is given, merge commits
-will never show a diff, even if a diff format like `--patch` is
-selected, nor will they match search options like `-S`. The exception is
-when `--first-parent` is in use, in which merges are treated like normal
-single-parent commits (this can be overridden by providing a
-combined-diff option or with `--no-diff-merges`).
+Note that unless one of `--diff-merges` variants (including short
+`-m`, `-c`, and `--cc` options) is explicitly given, merge commits
+will not show a diff, even if a diff format like `--patch` is
+selected, nor will they match search options like `-S`. The exception
+is when `--first-parent` is in use, in which case `first-parent` is
+the default format.
 
--c::
-	With this option, diff output for a merge commit
-	shows the differences from each of the parents to the merge result
-	simultaneously instead of showing pairwise diff between a parent
-	and the result one at a time. Furthermore, it lists only files
-	which were modified from all parents.
-
---cc::
-	This flag implies the `-c` option and further compresses the
-	patch output by omitting uninteresting hunks whose contents in
-	the parents have only two variants and the merge result picks
-	one of them without modification.
+--diff-merges=(off|none|first-parent|1|separate|m|combined|c|dense-combined|cc)::
+--no-diff-merges::
+	Specify diff format to be used for merge commits. Default is
+	`off` unless `--first-parent` is in use, in which case
+	`first-parent` is the default.
++
+--diff-merges=(off|none):::
+--no-diff-merges:::
+	Disable output of diffs for merge commits. Useful to override
+	implied value.
++
+--diff-merges=first-parent:::
+--diff-merges=1:::
+	This option makes merge commits show the full diff with
+	respect to the first parent only.
++
+--diff-merges=separate:::
+--diff-merges=m:::
+-m:::
+	This makes merge commits show the full diff with respect to
+	each of the parents. Separate log entry and diff is generated
+	for each parent. `-m` is different in that it doesn't produce
+	any output without `-p`.
++
+--diff-merges=combined:::
+--diff-merges=c:::
+-c:::
+	With this option, diff output for a merge commit shows the
+	differences from each of the parents to the merge result
+	simultaneously instead of showing pairwise diff between a
+	parent and the result one at a time. Furthermore, it lists
+	only files which were modified from all parents. Historically,
+	`-c` enables diff output for non-merge commits as well.
++
+--diff-merges=dense-combined:::
+--diff-merges=cc:::
+--cc:::
+	With this option the output produced by
+	`--diff-merges=combined` is further compressed by omitting
+	uninteresting hunks whose contents in the parents have only
+	two variants and the merge result picks one of them without
+	modification.  Historically, `--c` enables diff output for
+	non-merge commits as well.
 
 --combined-all-paths::
 	This flag causes combined diffs (used for merge commits) to
 	list the name of the file from all parents.  It thus only has
-	effect when -c or --cc are specified, and is likely only
-	useful if filename changes are detected (i.e. when either
-	rename or copy detection have been requested).
+	effect when `--diff-merges=[dense-]combined` is in use, and
+	is likely only useful if filename changes are detected (i.e.
+	when either rename or copy detection have been requested).
 
--m::
-	This flag makes the merge commits show the full diff like
-	regular commits; for each merge parent, a separate log entry
-	and diff is generated. An exception is that only diff against
-	the first parent is shown when `--first-parent` option is given;
-	in that case, the output represents the changes the merge
-	brought _into_ the then-current branch.
-
---diff-merges=off::
---no-diff-merges::
-	Disable output of diffs for merge commits (default). Useful to
-	override `-m`, `-c`, or `--cc`.
 
 :git-log: 1
 include::diff-options.txt[]
Signature · 1 line
2.25.1
#184 lore raw

Re: [PATCH v2 29/33] doc/git-log: describe new --diff-merges options

Quoted 3 lines · Sergey Organov

Describe all the new --diff-merges options in the git-log.txt and adopt description of originals accordingly.

You also took care to explain interactions of options with -p that were previously undocumented, which is a nice bonus. That wording could still be improved a bit, though, as noted below.

Quoted 15 lines
---
 Documentation/git-log.txt | 85 ++++++++++++++++++++++++---------------
 1 file changed, 52 insertions(+), 33 deletions(-)
Documentation/git-log.txt +0 -2
index 2b8ac5ff882a..27bc619490c6 100644
@@ -120,45 +120,64 @@ DIFF FORMATTING
 By default, `git log` does not generate any diff output. The options
 below can be used to show the changes made by each commit.
 
-Note that unless one of `-c`, `--cc`, or `-m` is given, merge commits
-will never show a diff, even if a diff format like `--patch` is

Documentation/git-log.txt DIFF FORMATTING · line 128

Quoted 10 lines
Documentation/git-log.txt +6 -4
-selected, nor will they match search options like `-S`. The exception is
-when `--first-parent` is in use, in which merges are treated like normal
-single-parent commits (this can be overridden by providing a
-combined-diff option or with `--no-diff-merges`).
+Note that unless one of `--diff-merges` variants (including short
+`-m`, `-c`, and `--cc` options) is explicitly given, merge commits
+will not show a diff, even if a diff format like `--patch` is
+selected, nor will they match search options like `-S`. The exception
+is when `--first-parent` is in use, in which case `first-parent` is
+the default format.

Thanks for fixing this up. :-)

Quoted 18 lines
Documentation/git-log.txt +5 -12
--c::
-       With this option, diff output for a merge commit
-       shows the differences from each of the parents to the merge result
-       simultaneously instead of showing pairwise diff between a parent
-       and the result one at a time. Furthermore, it lists only files
-       which were modified from all parents.
-
---cc::
-       This flag implies the `-c` option and further compresses the
-       patch output by omitting uninteresting hunks whose contents in
-       the parents have only two variants and the merge result picks
-       one of them without modification.
+--diff-merges=(off|none|first-parent|1|separate|m|combined|c|dense-combined|cc)::
+--no-diff-merges::
+       Specify diff format to be used for merge commits. Default is
+       `off` unless `--first-parent` is in use, in which case
+       `first-parent` is the default.

Documentation/git-log.txt DIFF FORMATTING · line 144

Quoted 10 lines
Documentation/git-log.txt +10 -0
++
+--diff-merges=(off|none):::
+--no-diff-merges:::
+       Disable output of diffs for merge commits. Useful to override
+       implied value.
++
+--diff-merges=first-parent:::
+--diff-merges=1:::
+       This option makes merge commits show the full diff with
+       respect to the first parent only.

Does it imply -p?

Documentation/git-log.txt DIFF FORMATTING · line 152

Quoted 8 lines
Documentation/git-log.txt +8 -0
++
+--diff-merges=separate:::
+--diff-merges=m:::
+-m:::
+       This makes merge commits show the full diff with respect to
+       each of the parents. Separate log entry and diff is generated
+       for each parent. `-m` is different in that it doesn't produce
+       any output without `-p`.

Different from what? From --first-parent? From flags that haven't been covered yet? (-c and --cc show up below)

Documentation/git-log.txt DIFF FORMATTING · line 162

Quoted 10 lines
Documentation/git-log.txt +10 -0
++
+--diff-merges=combined:::
+--diff-merges=c:::
+-c:::
+       With this option, diff output for a merge commit shows the
+       differences from each of the parents to the merge result
+       simultaneously instead of showing pairwise diff between a
+       parent and the result one at a time. Furthermore, it lists
+       only files which were modified from all parents. Historically,
+       `-c` enables diff output for non-merge commits as well.

"Historically"? Does that mean it doesn't anymore? (Maybe, "The short form, -c, also enables diff output for non-merge commits as well." or something like that?)

Documentation/git-log.txt DIFF FORMATTING · line 172

Quoted 10 lines
Documentation/git-log.txt +10 -0
++
+--diff-merges=dense-combined:::
+--diff-merges=cc:::
+--cc:::
+       With this option the output produced by
+       `--diff-merges=combined` is further compressed by omitting
+       uninteresting hunks whose contents in the parents have only
+       two variants and the merge result picks one of them without
+       modification.  Historically, `--c` enables diff output for
+       non-merge commits as well.

Same note as above.

Quoted 26 lines
Documentation/git-log.txt +3 -16
 --combined-all-paths::
        This flag causes combined diffs (used for merge commits) to
        list the name of the file from all parents.  It thus only has
-       effect when -c or --cc are specified, and is likely only
-       useful if filename changes are detected (i.e. when either
-       rename or copy detection have been requested).
+       effect when `--diff-merges=[dense-]combined` is in use, and
+       is likely only useful if filename changes are detected (i.e.
+       when either rename or copy detection have been requested).
 
--m::
-       This flag makes the merge commits show the full diff like
-       regular commits; for each merge parent, a separate log entry
-       and diff is generated. An exception is that only diff against
-       the first parent is shown when `--first-parent` option is given;
-       in that case, the output represents the changes the merge
-       brought _into_ the then-current branch.
-
---diff-merges=off::
---no-diff-merges::
-       Disable output of diffs for merge commits (default). Useful to
-       override `-m`, `-c`, or `--cc`.
 
 :git-log: 1
 include::diff-options.txt[]
--
Quoted 1 line

2.25.1

The rest looks good.

#185 lore raw

Re: [PATCH v2 29/33] doc/git-log: describe new --diff-merges options

Quoted 22 lines · Elijah Newren
Quoted 3 lines · Sergey Organov

Describe all the new --diff-merges options in the git-log.txt and adopt description of originals accordingly.

You also took care to explain interactions of options with -p that were previously undocumented, which is a nice bonus. That wording could still be improved a bit, though, as noted below.

Quoted 13 lines
---
 Documentation/git-log.txt | 85 ++++++++++++++++++++++++---------------
 1 file changed, 52 insertions(+), 33 deletions(-)
Documentation/git-log.txt +0 -0
index 2b8ac5ff882a..27bc619490c6 100644
@@ -120,45 +120,64 @@ DIFF FORMATTING
 By default, `git log` does not generate any diff output. The options
 below can be used to show the changes made by each commit.
 
Quoted 14 lines

Documentation/git-log.txt DIFF FORMATTING · line 128

Quoted 12 lines
Documentation/git-log.txt +6 -6
-Note that unless one of `-c`, `--cc`, or `-m` is given, merge commits
-will never show a diff, even if a diff format like `--patch` is
-selected, nor will they match search options like `-S`. The exception is
-when `--first-parent` is in use, in which merges are treated like normal
-single-parent commits (this can be overridden by providing a
-combined-diff option or with `--no-diff-merges`).
+Note that unless one of `--diff-merges` variants (including short
+`-m`, `-c`, and `--cc` options) is explicitly given, merge commits
+will not show a diff, even if a diff format like `--patch` is
+selected, nor will they match search options like `-S`. The exception
+is when `--first-parent` is in use, in which case `first-parent` is
+the default format.

Thanks for fixing this up. :-)

Don't mention it :-)

Quoted 30 lines
Quoted 19 lines
Documentation/git-log.txt +5 -12
--c::
-       With this option, diff output for a merge commit
-       shows the differences from each of the parents to the merge result
-       simultaneously instead of showing pairwise diff between a parent
-       and the result one at a time. Furthermore, it lists only files
-       which were modified from all parents.
-
---cc::
-       This flag implies the `-c` option and further compresses the
-       patch output by omitting uninteresting hunks whose contents in
-       the parents have only two variants and the merge result picks
-       one of them without modification.
+--diff-merges=(off|none|first-parent|1|separate|m|combined|c|dense-combined|cc)::
+--no-diff-merges::
+       Specify diff format to be used for merge commits. Default is
+       `off` unless `--first-parent` is in use, in which case
+       `first-parent` is the default.

Documentation/git-log.txt DIFF FORMATTING · line 144

Quoted 10 lines
Documentation/git-log.txt +10 -0
++
+--diff-merges=(off|none):::
+--no-diff-merges:::
+       Disable output of diffs for merge commits. Useful to override
+       implied value.
++
+--diff-merges=first-parent:::
+--diff-merges=1:::
+       This option makes merge commits show the full diff with
+       respect to the first parent only.
Quoted 1 line

Does it imply -p?

No, none of --diff-merges options do. This one is not any special. Why the question?

Quoted 11 lines

Documentation/git-log.txt DIFF FORMATTING · line 152

Quoted 8 lines
Documentation/git-log.txt +8 -0
++
+--diff-merges=separate:::
+--diff-merges=m:::
+-m:::
+       This makes merge commits show the full diff with respect to
+       each of the parents. Separate log entry and diff is generated
+       for each parent. `-m` is different in that it doesn't produce
+       any output without `-p`.

Different from what? From --first-parent? From flags that haven't been covered yet? (-c and --cc show up below)

Well, from --diff-merges=m and --diff-merges=separate, that, as any other --diff-merge option, do produce output (for merge commits) even without -p.

Quoted 12 lines

Documentation/git-log.txt DIFF FORMATTING · line 162

Quoted 11 lines
Documentation/git-log.txt +10 -0
++
+--diff-merges=combined:::
+--diff-merges=c:::
+-c:::
+       With this option, diff output for a merge commit shows the
+       differences from each of the parents to the merge result
+       simultaneously instead of showing pairwise diff between a
+       parent and the result one at a time. Furthermore, it lists
+       only files which were modified from all parents. Historically,
+       `-c` enables diff output for non-merge commits as well.
Quoted 1 line

"Historically"? Does that mean it doesn't anymore?

Eh, I don't think "historically" means that, but I'm not sure, being non-native English speaker.

Quoted 2 lines

(Maybe, "The short form, -c, also enables diff output for non-merge commits as well." or something like that?)

... and then try to explain why this otherwise illogical behavior is there? I thought "historically" would cover that.

Quoted 12 lines

Documentation/git-log.txt DIFF FORMATTING · line 172

Quoted 11 lines
Documentation/git-log.txt +10 -0
++
+--diff-merges=dense-combined:::
+--diff-merges=cc:::
+--cc:::
+       With this option the output produced by
+       `--diff-merges=combined` is further compressed by omitting
+       uninteresting hunks whose contents in the parents have only
+       two variants and the merge result picks one of them without
+       modification.  Historically, `--c` enables diff output for
+       non-merge commits as well.
Quoted 1 line

Same note as above.

Yep.

Quoted 24 lines
Quoted 24 lines
Documentation/git-log.txt +3 -15
 --combined-all-paths::
        This flag causes combined diffs (used for merge commits) to
        list the name of the file from all parents.  It thus only has
-       effect when -c or --cc are specified, and is likely only
-       useful if filename changes are detected (i.e. when either
-       rename or copy detection have been requested).
+       effect when `--diff-merges=[dense-]combined` is in use, and
+       is likely only useful if filename changes are detected (i.e.
+       when either rename or copy detection have been requested).
 
--m::
-       This flag makes the merge commits show the full diff like
-       regular commits; for each merge parent, a separate log entry
-       and diff is generated. An exception is that only diff against
-       the first parent is shown when `--first-parent` option is given;
-       in that case, the output represents the changes the merge
-       brought _into_ the then-current branch.
-
---diff-merges=off::
---no-diff-merges::
-       Disable output of diffs for merge commits (default). Useful to
-       override `-m`, `-c`, or `--cc`.
 
Quoted 6 lines
Quoted 4 lines
Documentation/git-log.txt +0 -1
 :git-log: 1
 include::diff-options.txt[]
--

2.25.1

The rest looks good.

Thanks,
-- Sergey

#186 lore raw

Re: [PATCH v2 29/33] doc/git-log: describe new --diff-merges options

Quoted 72 lines · Sergey Organov
Quoted 22 lines · Elijah Newren
Quoted 3 lines · Sergey Organov

Describe all the new --diff-merges options in the git-log.txt and adopt description of originals accordingly.

You also took care to explain interactions of options with -p that were previously undocumented, which is a nice bonus. That wording could still be improved a bit, though, as noted below.

Quoted 13 lines
---
 Documentation/git-log.txt | 85 ++++++++++++++++++++++++---------------
 1 file changed, 52 insertions(+), 33 deletions(-)
Documentation/git-log.txt +0 -0
index 2b8ac5ff882a..27bc619490c6 100644
@@ -120,45 +120,64 @@ DIFF FORMATTING
 By default, `git log` does not generate any diff output. The options
 below can be used to show the changes made by each commit.
 
Quoted 14 lines

Documentation/git-log.txt DIFF FORMATTING · line 128

Quoted 12 lines
Documentation/git-log.txt +6 -6
-Note that unless one of `-c`, `--cc`, or `-m` is given, merge commits
-will never show a diff, even if a diff format like `--patch` is
-selected, nor will they match search options like `-S`. The exception is
-when `--first-parent` is in use, in which merges are treated like normal
-single-parent commits (this can be overridden by providing a
-combined-diff option or with `--no-diff-merges`).
+Note that unless one of `--diff-merges` variants (including short
+`-m`, `-c`, and `--cc` options) is explicitly given, merge commits
+will not show a diff, even if a diff format like `--patch` is
+selected, nor will they match search options like `-S`. The exception
+is when `--first-parent` is in use, in which case `first-parent` is
+the default format.

Thanks for fixing this up. :-)

Don't mention it :-)

Quoted 30 lines
Quoted 29 lines
Documentation/git-log.txt +15 -12
--c::
-       With this option, diff output for a merge commit
-       shows the differences from each of the parents to the merge result
-       simultaneously instead of showing pairwise diff between a parent
-       and the result one at a time. Furthermore, it lists only files
-       which were modified from all parents.
-
---cc::
-       This flag implies the `-c` option and further compresses the
-       patch output by omitting uninteresting hunks whose contents in
-       the parents have only two variants and the merge result picks
-       one of them without modification.
+--diff-merges=(off|none|first-parent|1|separate|m|combined|c|dense-combined|cc)::
+--no-diff-merges::
+       Specify diff format to be used for merge commits. Default is
+       `off` unless `--first-parent` is in use, in which case
+       `first-parent` is the default.
++
+--diff-merges=(off|none):::
+--no-diff-merges:::
+       Disable output of diffs for merge commits. Useful to override
+       implied value.
++
+--diff-merges=first-parent:::
+--diff-merges=1:::
+       This option makes merge commits show the full diff with
+       respect to the first parent only.
Quoted 4 lines
Quoted 1 line

Does it imply -p?

No, none of --diff-merges options do. This one is not any special. Why the question?

The documentation on -m was vague enough that it made me wonder. Fixing it would probably prevent me from having asked this question.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Documentation/git-log.txt +8 -0
++
+--diff-merges=separate:::
+--diff-merges=m:::
+-m:::
+       This makes merge commits show the full diff with respect to
+       each of the parents. Separate log entry and diff is generated
+       for each parent. `-m` is different in that it doesn't produce
+       any output without `-p`.
Quoted 6 lines
Quoted 2 lines

Different from what? From --first-parent? From flags that haven't been covered yet? (-c and --cc show up below)

Well, from --diff-merges=m and --diff-merges=separate, that, as any other --diff-merge option, do produce output (for merge commits) even without -p.

That wasn't at all clear to me as the intent of the last sentence.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Documentation/git-log.txt +10 -0
++
+--diff-merges=combined:::
+--diff-merges=c:::
+-c:::
+       With this option, diff output for a merge commit shows the
+       differences from each of the parents to the merge result
+       simultaneously instead of showing pairwise diff between a
+       parent and the result one at a time. Furthermore, it lists
+       only files which were modified from all parents. Historically,
+       `-c` enables diff output for non-merge commits as well.
Quoted 4 lines
Quoted 1 line

"Historically"? Does that mean it doesn't anymore?

Eh, I don't think "historically" means that, but I'm not sure, being non-native English speaker.

Sometimes non-native speakers use the language more accurately. This might be such a case, but that sentence did make me think you might be attempting to document past behavior as a way of helping people adjust to current/new behavior.

Quoted 5 lines
Quoted 2 lines

(Maybe, "The short form, -c, also enables diff output for non-merge commits as well." or something like that?)

... and then try to explain why this otherwise illogical behavior is there? I thought "historically" would cover that.

It doesn't seem like illogical behavior to me. Perhaps the view of
-c as a diff-merges option, reinforced by placing -c right next to --diff-merges in the documentation, is what causes you to think so? If so, maybe we should document -c (and --cc) separately after all the --diff-merges options, using something like the following:

-c:::
Implies both --patch and --diff-merges=combined, i.e. turn on
patches for normal commits and show a combined diff format for merges.

Quoted 49 lines
Quoted 12 lines

Documentation/git-log.txt DIFF FORMATTING · line 172

Quoted 11 lines
Documentation/git-log.txt +10 -0
++
+--diff-merges=dense-combined:::
+--diff-merges=cc:::
+--cc:::
+       With this option the output produced by
+       `--diff-merges=combined` is further compressed by omitting
+       uninteresting hunks whose contents in the parents have only
+       two variants and the merge result picks one of them without
+       modification.  Historically, `--c` enables diff output for
+       non-merge commits as well.
Quoted 1 line

Same note as above.

Yep.

Quoted 24 lines
Quoted 24 lines
Documentation/git-log.txt +3 -15
 --combined-all-paths::
        This flag causes combined diffs (used for merge commits) to
        list the name of the file from all parents.  It thus only has
-       effect when -c or --cc are specified, and is likely only
-       useful if filename changes are detected (i.e. when either
-       rename or copy detection have been requested).
+       effect when `--diff-merges=[dense-]combined` is in use, and
+       is likely only useful if filename changes are detected (i.e.
+       when either rename or copy detection have been requested).
 
--m::
-       This flag makes the merge commits show the full diff like
-       regular commits; for each merge parent, a separate log entry
-       and diff is generated. An exception is that only diff against
-       the first parent is shown when `--first-parent` option is given;
-       in that case, the output represents the changes the merge
-       brought _into_ the then-current branch.
-
---diff-merges=off::
---no-diff-merges::
-       Disable output of diffs for merge commits (default). Useful to
-       override `-m`, `-c`, or `--cc`.
 
Quoted 6 lines
Quoted 4 lines
Documentation/git-log.txt +0 -1
 :git-log: 1
 include::diff-options.txt[]
--

2.25.1

The rest looks good.

Thanks,
-- Sergey

#187 lore raw

Re: [PATCH v2 29/33] doc/git-log: describe new --diff-merges options

Quoted 73 lines · Elijah Newren
Quoted 72 lines · Sergey Organov
Quoted 22 lines · Elijah Newren
Quoted 3 lines · Sergey Organov

Describe all the new --diff-merges options in the git-log.txt and adopt description of originals accordingly.

You also took care to explain interactions of options with -p that were previously undocumented, which is a nice bonus. That wording could still be improved a bit, though, as noted below.

Quoted 13 lines
---
 Documentation/git-log.txt | 85 ++++++++++++++++++++++++---------------
 1 file changed, 52 insertions(+), 33 deletions(-)
Documentation/git-log.txt +0 -0
index 2b8ac5ff882a..27bc619490c6 100644
@@ -120,45 +120,64 @@ DIFF FORMATTING
 By default, `git log` does not generate any diff output. The options
 below can be used to show the changes made by each commit.
 
Quoted 14 lines

Documentation/git-log.txt DIFF FORMATTING · line 128

Quoted 12 lines
Documentation/git-log.txt +6 -6
-Note that unless one of `-c`, `--cc`, or `-m` is given, merge commits
-will never show a diff, even if a diff format like `--patch` is
-selected, nor will they match search options like `-S`. The exception is
-when `--first-parent` is in use, in which merges are treated like normal
-single-parent commits (this can be overridden by providing a
-combined-diff option or with `--no-diff-merges`).
+Note that unless one of `--diff-merges` variants (including short
+`-m`, `-c`, and `--cc` options) is explicitly given, merge commits
+will not show a diff, even if a diff format like `--patch` is
+selected, nor will they match search options like `-S`. The exception
+is when `--first-parent` is in use, in which case `first-parent` is
+the default format.

Thanks for fixing this up. :-)

Don't mention it :-)

Quoted 30 lines
Quoted 29 lines
Documentation/git-log.txt +15 -12
--c::
-       With this option, diff output for a merge commit
-       shows the differences from each of the parents to the merge result
-       simultaneously instead of showing pairwise diff between a parent
-       and the result one at a time. Furthermore, it lists only files
-       which were modified from all parents.
-
---cc::
-       This flag implies the `-c` option and further compresses the
-       patch output by omitting uninteresting hunks whose contents in
-       the parents have only two variants and the merge result picks
-       one of them without modification.
+--diff-merges=(off|none|first-parent|1|separate|m|combined|c|dense-combined|cc)::
+--no-diff-merges::
+       Specify diff format to be used for merge commits. Default is
+       `off` unless `--first-parent` is in use, in which case
+       `first-parent` is the default.
++
+--diff-merges=(off|none):::
+--no-diff-merges:::
+       Disable output of diffs for merge commits. Useful to override
+       implied value.
++
+--diff-merges=first-parent:::
+--diff-merges=1:::
+       This option makes merge commits show the full diff with
+       respect to the first parent only.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Does it imply -p?

No, none of --diff-merges options do. This one is not any special. Why the question?

The documentation on -m was vague enough that it made me wonder. Fixing it would probably prevent me from having asked this question.

OK, I see, so let's try to fix the cause, please see below.

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Documentation/git-log.txt +8 -0
++
+--diff-merges=separate:::
+--diff-merges=m:::
+-m:::
+       This makes merge commits show the full diff with respect to
+       each of the parents. Separate log entry and diff is generated
+       for each parent. `-m` is different in that it doesn't produce
+       any output without `-p`.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Different from what? From --first-parent? From flags that haven't been covered yet? (-c and --cc show up below)

Well, from --diff-merges=m and --diff-merges=separate, that, as any other --diff-merge option, do produce output (for merge commits) even without -p.

That wasn't at all clear to me as the intent of the last sentence.

Well, actually, the right answer to your question is: -m is different from *everything* ;-)

Maybe the confusion you got is not caused by the documentation, but rather by some of your expectations? In particular, I wonder, how comes --first-parent appeared in your question, that is entirely unrelated?

I mean I'm still unsure how to make this description more clear, maybe this will do:

--diff-merges=separate:::
--diff-merges=m:::
-m:::
This makes merge commits show the full diff with respect to each of the parents. Separate log entry and diff is generated for each parent. -m doesn't produce any output without -p.

Quoted 25 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Documentation/git-log.txt +10 -0
++
+--diff-merges=combined:::
+--diff-merges=c:::
+-c:::
+       With this option, diff output for a merge commit shows the
+       differences from each of the parents to the merge result
+       simultaneously instead of showing pairwise diff between a
+       parent and the result one at a time. Furthermore, it lists
+       only files which were modified from all parents. Historically,
+       `-c` enables diff output for non-merge commits as well.
Quoted 4 lines
Quoted 1 line

"Historically"? Does that mean it doesn't anymore?

Eh, I don't think "historically" means that, but I'm not sure, being non-native English speaker.

Sometimes non-native speakers use the language more accurately. This might be such a case, but that sentence did make me think you might be attempting to document past behavior as a way of helping people adjust to current/new behavior.

Quoted 3 lines
Quoted 2 lines

(Maybe, "The short form, -c, also enables diff output for non-merge commits as well." or something like that?)

Quoted 6 lines
Quoted 2 lines

... and then try to explain why this otherwise illogical behavior is there? I thought "historically" would cover that.

It doesn't seem like illogical behavior to me. Perhaps the view of
-c as a diff-merges option, reinforced by placing -c right next to --diff-merges in the documentation, is what causes you to think so?

-c, described as selecting specific format of representation of merge commits, suddenly enabling diff output of non-merge commits, is logical? No. Useful? Maybe. Logical? Not to me. Just saying, see below.

Quoted 6 lines

If so, maybe we should document -c (and --cc) separately after all the --diff-merges options, using something like the following:

-c:::
Implies both --patch and --diff-merges=combined, i.e. turn on
patches for normal commits and show a combined diff format for merges.

The problem with this is that it'd then be preferable to describe -m separately as well, and that's not that simple.

Overall, I'd rather change that in place, like this:

--diff-merges=combined:::
--diff-merges=c:::
-c:::
With this option, diff output for a merge commit shows the differences from each of the parents to the merge result simultaneously instead of showing pairwise diff between a parent and the result one at a time. Furthermore, it lists only files which were modified from all parents. -c implies --patch.

Thanks,
-- Sergey

#188 lore raw

Re: [PATCH v2 29/33] doc/git-log: describe new --diff-merges options

Quoted 78 lines · Sergey Organov
Quoted 75 lines · Elijah Newren
Quoted 74 lines · Sergey Organov
Quoted 22 lines · Elijah Newren
Quoted 3 lines · Sergey Organov

Describe all the new --diff-merges options in the git-log.txt and adopt description of originals accordingly.

You also took care to explain interactions of options with -p that were previously undocumented, which is a nice bonus. That wording could still be improved a bit, though, as noted below.

Quoted 13 lines
---
 Documentation/git-log.txt | 85 ++++++++++++++++++++++++---------------
 1 file changed, 52 insertions(+), 33 deletions(-)
Documentation/git-log.txt +0 -0
index 2b8ac5ff882a..27bc619490c6 100644
@@ -120,45 +120,64 @@ DIFF FORMATTING
 By default, `git log` does not generate any diff output. The options
 below can be used to show the changes made by each commit.
 
Quoted 14 lines

Documentation/git-log.txt DIFF FORMATTING · line 128

Quoted 12 lines
Documentation/git-log.txt +6 -6
-Note that unless one of `-c`, `--cc`, or `-m` is given, merge commits
-will never show a diff, even if a diff format like `--patch` is
-selected, nor will they match search options like `-S`. The exception is
-when `--first-parent` is in use, in which merges are treated like normal
-single-parent commits (this can be overridden by providing a
-combined-diff option or with `--no-diff-merges`).
+Note that unless one of `--diff-merges` variants (including short
+`-m`, `-c`, and `--cc` options) is explicitly given, merge commits
+will not show a diff, even if a diff format like `--patch` is
+selected, nor will they match search options like `-S`. The exception
+is when `--first-parent` is in use, in which case `first-parent` is
+the default format.

Thanks for fixing this up. :-)

Don't mention it :-)

Quoted 31 lines
Quoted 19 lines
Documentation/git-log.txt +5 -12
--c::
-       With this option, diff output for a merge commit
-       shows the differences from each of the parents to the merge result
-       simultaneously instead of showing pairwise diff between a parent
-       and the result one at a time. Furthermore, it lists only files
-       which were modified from all parents.
-
---cc::
-       This flag implies the `-c` option and further compresses the
-       patch output by omitting uninteresting hunks whose contents in
-       the parents have only two variants and the merge result picks
-       one of them without modification.
+--diff-merges=(off|none|first-parent|1|separate|m|combined|c|dense-combined|cc)::
+--no-diff-merges::
+       Specify diff format to be used for merge commits. Default is
+       `off` unless `--first-parent` is in use, in which case
+       `first-parent` is the default.

Documentation/git-log.txt DIFF FORMATTING · line 144

Quoted 10 lines
Documentation/git-log.txt +10 -0
++
+--diff-merges=(off|none):::
+--no-diff-merges:::
+       Disable output of diffs for merge commits. Useful to override
+       implied value.
++
+--diff-merges=first-parent:::
+--diff-merges=1:::
+       This option makes merge commits show the full diff with
+       respect to the first parent only.

Does it imply -p?

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

No, none of --diff-merges options do. This one is not any special. Why the question?

The documentation on -m was vague enough that it made me wonder. Fixing it would probably prevent me from having asked this question.

OK, I see, so let's try to fix the cause, please see below.

Sounds good.

Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 10 lines

Documentation/git-log.txt DIFF FORMATTING · line 152

Quoted 9 lines
Documentation/git-log.txt +8 -0
++
+--diff-merges=separate:::
+--diff-merges=m:::
+-m:::
+       This makes merge commits show the full diff with respect to
+       each of the parents. Separate log entry and diff is generated
+       for each parent. `-m` is different in that it doesn't produce
+       any output without `-p`.
Quoted 2 lines

Different from what? From --first-parent? From flags that haven't been covered yet? (-c and --cc show up below)

Well, from --diff-merges=m and --diff-merges=separate, that, as any other --diff-merge option, do produce output (for merge commits) even without -p.

Quoted 8 lines
Quoted 1 line

That wasn't at all clear to me as the intent of the last sentence.

Well, actually, the right answer to your question is: -m is different from *everything* ;-)

Maybe the confusion you got is not caused by the documentation, but rather by some of your expectations? In particular, I wonder, how comes --first-parent appeared in your question, that is entirely unrelated?

When you said "-m is different" it was not clear what you were contrasting to. The fact that you were contrasting to the other values in the set of three being described by this paragraph may seem obvious to you, and I suspect many other readers may catch on to that, but that really honestly did not occur to me while reading it. Maybe I'm weird. Maybe some subset of users will be like me and we should tighten up the wording. Hard to say.

Quoted 9 lines

I mean I'm still unsure how to make this description more clear, maybe this will do:

--diff-merges=separate:::
--diff-merges=m:::
-m:::
This makes merge commits show the full diff with respect to each of the parents. Separate log entry and diff is generated for each parent. -m doesn't produce any output without -p.

Works for me. :-)

Quoted 28 lines
Quoted 28 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
Documentation/git-log.txt +10 -0
++
+--diff-merges=combined:::
+--diff-merges=c:::
+-c:::
+       With this option, diff output for a merge commit shows the
+       differences from each of the parents to the merge result
+       simultaneously instead of showing pairwise diff between a
+       parent and the result one at a time. Furthermore, it lists
+       only files which were modified from all parents. Historically,
+       `-c` enables diff output for non-merge commits as well.
Quoted 4 lines
Quoted 1 line

"Historically"? Does that mean it doesn't anymore?

Eh, I don't think "historically" means that, but I'm not sure, being non-native English speaker.

Sometimes non-native speakers use the language more accurately. This might be such a case, but that sentence did make me think you might be attempting to document past behavior as a way of helping people adjust to current/new behavior.

Quoted 5 lines
Quoted 2 lines

(Maybe, "The short form, -c, also enables diff output for non-merge commits as well." or something like that?)

... and then try to explain why this otherwise illogical behavior is there? I thought "historically" would cover that.

Quoted 7 lines
Quoted 3 lines

It doesn't seem like illogical behavior to me. Perhaps the view of
-c as a diff-merges option, reinforced by placing -c right next to --diff-merges in the documentation, is what causes you to think so?

-c, described as selecting specific format of representation of merge commits, suddenly enabling diff output of non-merge commits, is logical? No. Useful? Maybe. Logical? Not to me. Just saying, see below.

:-)

I didn't say the former documentation was correct, or that the behavior logically flowed from the documentation's claims. And you do bring up good points that the past documentation should have been updated when -c and --cc were made to imply -p. I only claimed that -c and --cc provide logical behaviors (I want diffs for everything, for merges do it this way...all expressed in a nice compact bundle).

Quoted 12 lines
Quoted 6 lines

If so, maybe we should document -c (and --cc) separately after all the --diff-merges options, using something like the following:

-c:::
Implies both --patch and --diff-merges=combined, i.e. turn on
patches for normal commits and show a combined diff format for merges.

The problem with this is that it'd then be preferable to describe -m separately as well, and that's not that simple.

Overall, I'd rather change that in place, like this:

Quoted 9 lines

--diff-merges=combined:::
--diff-merges=c:::
-c:::
With this option, diff output for a merge commit shows the differences from each of the parents to the merge result simultaneously instead of showing pairwise diff between a parent and the result one at a time. Furthermore, it lists only files which were modified from all parents. -c implies --patch.

Works for me. --cc needs a similar change, obviously.

#189 lore raw

PATCH v2 30/33 doc/diff-generate-patch: mention new --diff-merges option

In reply to Sergey Organov

Mention --diff-merges instead of -m in a note to merge formats to aid discoverability, as -m is now described among --diff-merges options anyway.

---
 Documentation/diff-generate-patch.txt | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/diff-generate-patch.txt +3 -3
index b10ff4caa6c5..2db8eacc3ec7 100644
@@ -81,9 +81,9 @@ Combined diff format
 Any diff-generating command can take the `-c` or `--cc` option to
 produce a 'combined diff' when showing a merge. This is the default
 format when showing merges with linkgit:git-diff[1] or
-linkgit:git-show[1]. Note also that you can give the `-m` option to any
-of these commands to force generation of diffs with individual parents
-of a merge.
+linkgit:git-show[1]. Note also that you can give suitable
+`--diff-merges` option to any of these commands to force generation of
+diffs in specific format.
 
 A "combined diff" format looks like this:
 
Signature · 1 line
2.25.1
#190 lore raw

PATCH v2 31/33 doc/rev-list-options: document --first-parent changes merges format

In reply to Sergey Organov

After introduction of the --diff-merges=first-parent, the --first-parent sets the default format for merges to the same value as this new option. Document this behavior and add corresponding reference to --diff-merges.

---
 Documentation/rev-list-options.txt | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/rev-list-options.txt +5 -0
index 002379056a07..96cc89d157d2 100644
@@ -130,6 +130,11 @@ parents) and `--max-parents=-1` (negative numbers denote no upper limit).
 	this option allows you to ignore the individual commits
 	brought in to your history by such a merge.
 
+ifdef::git-log[]
+	This option also changes default diff format for merge commits
+	to `first-parent`, see `--diff-merges=first-parent` for details.
+endif::git-log[]
+
 --not::
 	Reverses the meaning of the '{caret}' prefix (or lack thereof)
 	for all following revision specifiers, up to the next `--not`.
Signature · 1 line
2.25.1
#191 lore raw

PATCH v2 32/33 doc/git-show: include --diff-merges description

In reply to Sergey Organov

Move description of --diff-merges option from git-log.txt to diff-options.txt so that it is included in the git-show help.

---
 Documentation/diff-options.txt | 53 ++++++++++++++++++++++++++++++++++
 Documentation/git-log.txt      | 53 +---------------------------------
 Documentation/git-show.txt     |  7 +++--
 3 files changed, 59 insertions(+), 54 deletions(-)
Documentation/diff-options.txt +53 -0
index 573fb9bb71e2..98db2be423dc 100644
@@ -33,6 +33,59 @@ endif::git-diff[]
 	show the patch by default, or to cancel the effect of `--patch`.
 endif::git-format-patch[]
 
+ifdef::git-log[]
+--diff-merges=(off|none|first-parent|1|separate|m|combined|c|dense-combined|cc)::
+--no-diff-merges::
+	Specify diff format to be used for merge commits. Default is
+	{diff-merges-default} unless `--first-parent` is in use, in which case
+	`first-parent` is the default.
++
+--diff-merges=(off|none):::
+--no-diff-merges:::
+	Disable output of diffs for merge commits. Useful to override
+	implied value.
++
+--diff-merges=first-parent:::
+--diff-merges=1:::
+	This option makes merge commits show the full diff with
+	respect to the first parent only.
++
+--diff-merges=separate:::
+--diff-merges=m:::
+-m:::
+	This makes merge commits show the full diff with respect to
+	each of the parents. Separate log entry and diff is generated
+	for each parent. `-m` is different in that it doesn't produce
+	any output without `-p`.
++
+--diff-merges=combined:::
+--diff-merges=c:::
+-c:::
+	With this option, diff output for a merge commit shows the
+	differences from each of the parents to the merge result
+	simultaneously instead of showing pairwise diff between a
+	parent and the result one at a time. Furthermore, it lists
+	only files which were modified from all parents. Historically,
+	`-c` enables diff output for non-merge commits as well.
++
+--diff-merges=dense-combined:::
+--diff-merges=cc:::
+--cc:::
+	With this option the output produced by
+	`--diff-merges=combined` is further compressed by omitting
+	uninteresting hunks whose contents in the parents have only
+	two variants and the merge result picks one of them without
+	modification.  Historically, `--c` enables diff output for
+	non-merge commits as well.
+
+--combined-all-paths::
+	This flag causes combined diffs (used for merge commits) to
+	list the name of the file from all parents.  It thus only has
+	effect when `--diff-merges=[dense-]combined` is in use, and
+	is likely only useful if filename changes are detected (i.e.
+	when either rename or copy detection have been requested).
+endif::git-log[]
+
 -U<n>::
 --unified=<n>::
 	Generate diffs with <n> lines of context instead of
Documentation/git-log.txt +1 -52

60 lines not on this page · raw message

Documentation/git-show.txt +5 -2
index fcf528c1b30d..2b1bc7288d5f 100644
@@ -45,10 +45,13 @@ include::pretty-options.txt[]
 include::pretty-formats.txt[]
 
 
-COMMON DIFF OPTIONS
--------------------
+DIFF FORMATTING
+---------------
+The options below can be used to change the way `git show` generates
+diff output.
 
 :git-log: 1
+:diff-merges-default: `dense-combined`
 include::diff-options.txt[]
 
 include::diff-generate-patch.txt[]
Signature · 1 line
2.25.1
#192 lore raw

PATCH v2 33/33 t4013: add tests for --diff-merges=first-parent

In reply to Sergey Organov

This new option provides essential new functionality, changing diff output to first parent only, without changing history traversal mode, so it deserves its own test.

As we do it, add additional test that --diff-merges=first-parent by itself doesn't imply -p and only outputs diffs for merge commits.

---
 t/t4013-diff-various.sh                       |   2 +
 ...diff.log_--diff-merges=first-parent_master |  56 +++++++
 ...f.log_-p_--diff-merges=first-parent_master | 137 ++++++++++++++++++
 3 files changed, 195 insertions(+)
 create mode 100644 t/t4013/diff.log_--diff-merges=first-parent_master
 create mode 100644 t/t4013/diff.log_-p_--diff-merges=first-parent_master
t/t4013-diff-various.sh +2 -0
index 8d8178a8a616..fa82b5a8eed4 100755
@@ -327,6 +327,8 @@ log --no-diff-merges -p --first-parent master
 log --diff-merges=off -p --first-parent master
 log --first-parent --diff-merges=off -p master
 log -p --first-parent master
+log -p --diff-merges=first-parent master
+log --diff-merges=first-parent master
 log -m -p --first-parent master
 log -m -p master
 log --cc -m -p master
t/t4013/diff.log_--diff-merges=first-parent_master new file +56 -0

56 lines not on this page · raw message

t/t4013/diff.log_-p_--diff-merges=first-parent_master new file +137 -0

137 lines not on this page · raw message

Signature · 1 line
2.25.1
#193 lore raw
In reply to Sergey Organov
Quoted 4 lines · Sergey Organov

These patch series implement new set of options governing diff output of merge commits, all under the umbrella of single --diff-merges=<mode> option.

With this round, I was hoping to get a range-diff (using the --range-diff option to format-patch), so I could more easily see what was new. Since I've been updating frequently enough, I was able to generate this locally using Junio's published so/log-diff-merge topic, but it'd be helpful if you could include it in any future rounds.

With your previous patch series, I scanned most the patches somewhat briefly but looked at the final patches more closely (the series is kind of long, and I noticed Junio had started reviewing the early part of the series, so I figured it might be most helpful to jump in and cover the end in case he didn't get that far). With this round, I read through the range-diff, and then looked at all the new patches and have left a number of comments. I think Junio reviewed the first 8 or so patches of an earlier round, so patches 9-21 probably could benefit from someone reviewing more closely.

Overall, I like the direction of the series. I think it'll make it easier to add --remerge-diff later since it simplifies getting the interaction between it and -m/-c/--cc/--first-parent right. It also adds some new capabilities you want (--diff-merges=first-parent, to show merges as diff against first parent without only traversing first parents), and that Junio wants (--diff-merges=dense-combined, to only show merges for diffs without showing diffs for non-merge commits).

Quoted 162 lines

Unlike original -c/--cc options, these new options do not imply -p, thus allowing for getting diffs for merge commits without provoking of diff output for regular, non-merge commits. E.g.:

  git log --diff-merges=cc

will output diffs (in dense-combined format) only for merge commits, whereas:

  git log --cc

enables diffs for all the commits being output, either merges or simple ones.

There is also another additional functionality provided, allowing to get the format of "-p --first-parent" without change in history traversal that --first-parent option causes, like this:

  git log --diff-merges=first-parent

The net result of these series are the following new options:

--diff-merges= | rough original equivalent
------------------+----------------

1|first-parent    | --first-parent (only diff format implications)
m|separate        | -m and enable diff for merges
c|combined        | -c and enable diff for merges, but not for regulars
cc|dense-combined | --cc and enable diff for merges, but not for
                  |      regulars

The series also cleanup logic of handling of diff merges options and fix an issue found in the original implementation where logically mutually exclusive options -m/-c/--cc failed to actually override each other. Neither semantics of these old options nor their interactions with other options, such as --first-parent and -p, is supposed to be changed.

The series start with the set of pure refactoring commits that are expected to introduce no functional changes. These are all commits up to and including:

"diff-merges: revise revs->diff flag handling"

The aim of these commits is to isolate options handling for diff merges so that it could be easily understood and tweaked to ease introduction of the new options.

Then the fix of -m/-c/-cc overriding issue follows, starting with a failing test and followed by the fix.

Then follows a little bit of additional refactoring in order to prepare for introduction of the new options, and finally the series are finished by the implementation, documentation updates, and some testing for the new options.

Updates in v2:

* Move logic of "-c/--cc imply -p" to this module and do not imply -p by new --diff-merges options. Instead enable corresponding diff output without affecting non-merge commits. This is the most significant change with respect to v1 and it starts at 24/33.

* Add support for old mnemonics: --diff-merges=(m|c|cc) to help those who are used to them, and add --diff-merges=1 to cover all variants with short mnemonics.

* Fixed functions definitions style to have open curly brace on its own line, pointed to by Junio C Hamano.

* Tweak --diff-merges=first-parent description, requested by Elijah Newren.

* Fixed git-show documentation not to include description chunk relevant to git-log only, noticed by Elijah Newren.

* Fixed documentation mistake claiming that -p is needed for diff-merges options to take effect, noticed by Elijah Newren.

* Fixed a case where a change was put into wrong commit. The change moved to 11/27 form 10/27. Didn't affect end-result in any way.

* Added short module description to diff-merges.h, as suggested by Junio C Hamano.

* Fixed not returning "argcount" from diff_merges_parse_opts(), noticed by Junio C Hamano.

Updates in v1:

* Added documentation fix for git-show to include --diff-merges.

* Fixed typos in commit messages noticed by Philip Oakley.

Sergey Organov (33):
revision: factor out parsing of diff-merge related options
revision: factor out setup of diff-merge related settings
revision: factor out initialization of diff-merge related settings
revision: provide implementation for diff merges tweaks
revision: move diff merges functions to its own diff-merges.c
diff-merges: rename all functions to have common prefix
diff-merges: move checks for first_parent_only out of the module
diff-merges: rename diff_merges_default_to_enable() to match semantics
diff-merges: re-arrange functions to match the order they are called
in
diff-merges: new function diff_merges_suppress()
diff-merges: new function diff_merges_set_dense_combined_if_unset()
diff-merges: introduce revs->first_parent_merges flag
diff-merges: revise revs->diff flag handling
t4013: support test_expect_failure through ':failure' magic
t4013: add tests for -m failing to override -c/--cc
diff-merges: fix -m to properly override -c/--cc
diff-merges: split 'ignore_merges' field
diff-merges: group diff-merge flags next to each other inside

    'rev_info'

diff-merges: get rid of now empty diff_merges_init_revs()
diff-merges: refactor opt settings into separate functions
diff-merges: make -m/-c/--cc explicitly mutually exclusive
diff-merges: implement new values for --diff-merges
diff-merges: fix style of functions definitions
diff-merges: handle imply -p on -c/--cc logic for log.c
diff-merges: do not imply -p for new options
diff-merges: let new options enable diff without -p
diff-merges: add old mnemonic counterparts to --diff-merges
diff-merges: add '--diff-merges=1' as synonym for 'first-parent' doc/git-log: describe new --diff-merges options doc/diff-generate-patch: mention new --diff-merges option doc/rev-list-options: document --first-parent changes merges format doc/git-show: include --diff-merges description
t4013: add tests for --diff-merges=first-parent

 Documentation/diff-generate-patch.txt         |   6 +-
 Documentation/diff-options.txt                |  53 +++++
 Documentation/git-log.txt                     |  46 +---
 Documentation/git-show.txt                    |   7 +-
 Documentation/rev-list-options.txt            |   5 +
 Makefile                                      |   1 +
 builtin/diff-files.c                          |   5 +-
 builtin/diff.c                                |   9 +-
 builtin/log.c                                 |  22 +-
 builtin/merge.c                               |   3 +-
 diff-merges.c                                 | 151 +++++++++++++
 diff-merges.h                                 |  24 +++
 fmt-merge-msg.c                               |   3 +-
 log-tree.c                                    |  30 +--
 revision.c                                    |  38 +---
 revision.h                                    |   9 +-
 t/t4013-diff-various.sh                       |  11 +-
 t/t4013/diff.log_--cc_-m_-p_master            | 200 ++++++++++++++++++
 ...diff.log_--diff-merges=first-parent_master |  56 +++++
 t/t4013/diff.log_-c_-m_-p_master              | 200 ++++++++++++++++++
 ...f.log_-p_--diff-merges=first-parent_master | 137 ++++++++++++
 21 files changed, 900 insertions(+), 116 deletions(-)
 create mode 100644 diff-merges.c
 create mode 100644 diff-merges.h
 create mode 100644 t/t4013/diff.log_--cc_-m_-p_master
 create mode 100644 t/t4013/diff.log_--diff-merges=first-parent_master
 create mode 100644 t/t4013/diff.log_-c_-m_-p_master
 create mode 100644 t/t4013/diff.log_-p_--diff-merges=first-parent_master

--
2.25.1

#194 lore raw

Hi Elijah,

Thanks a lot for reviewing the series!

Quoted 11 lines · Elijah Newren
Quoted 4 lines · Sergey Organov

These patch series implement new set of options governing diff output of merge commits, all under the umbrella of single --diff-merges=<mode> option.

With this round, I was hoping to get a range-diff (using the --range-diff option to format-patch), so I could more easily see what was new. Since I've been updating frequently enough, I was able to generate this locally using Junio's published so/log-diff-merge topic, but it'd be helpful if you could include it in any future rounds.

Well, documentation on contributing doesn't seem to mention this. I'll try to learn it for the future though, thanks!

Quoted 11 lines

With your previous patch series, I scanned most the patches somewhat briefly but looked at the final patches more closely (the series is kind of long, and I noticed Junio had started reviewing the early part of the series, so I figured it might be most helpful to jump in and cover the end in case he didn't get that far). With this round, I read through the range-diff, and then looked at all the new patches and have left a number of comments. I think Junio reviewed the first 8 or so patches of an earlier round, so patches 9-21 probably could benefit from someone reviewing more closely.

Quoted 7 lines

Overall, I like the direction of the series. I think it'll make it easier to add --remerge-diff later since it simplifies getting the interaction between it and -m/-c/--cc/--first-parent right. It also adds some new capabilities you want (--diff-merges=first-parent, to show merges as diff against first parent without only traversing first parents), and that Junio wants (--diff-merges=dense-combined, to only show merges for diffs without showing diffs for non-merge commits).

Yeah, I hoped to address everything that has been discussed.

[...]

Thanks,
-- Sergey

#195 lore raw

v3 cover git-log: implement new --diff-merge options

In reply to Sergey Organov

These patch series implement new set of options governing diff output of merge commits, all under the umbrella of single --diff-merges=<mode> option.

Unlike original -c/--cc options, these new options do not imply -p, thus allowing for getting diffs for merge commits without provoking of diff output for regular, non-merge commits. E.g.:

  git log --diff-merges=cc

will output diffs (in dense-combined format) only for merge commits, whereas:

  git log --cc

enables diffs for all the commits being output, either merges or simple ones.

There is also another additional functionality provided, allowing to get the format of "-p --first-parent" without change in history traversal that --first-parent option causes, like this:

  git log --diff-merges=first-parent

The net result of these series are the following new options:

--diff-merges= | rough original equivalent
------------------+----------------

1|first-parent    | --first-parent (only diff format implications)
m|separate        | -m and enable diff for merges
c|combined        | -c and enable diff for merges, but not for regulars
cc|dense-combined | --cc and enable diff for merges, but not for

| regulars

The series also cleanup logic of handling of diff merges options and fix an issue found in the original implementation where logically mutually exclusive options -m/-c/--cc failed to actually override each other. Neither semantics of these old options nor their interactions with other options, such as --first-parent and -p, is supposed to be changed.

The series start with the set of pure refactoring commits that are expected to introduce no functional changes. These are all commits up to and including:

"diff-merges: revise revs->diff flag handling"

The aim of these commits is to isolate options handling for diff merges so that it could be easily understood and tweaked to ease introduction of the new options.

Then the fix of -m/-c/-cc overriding issue follows, starting with a failing test and followed by the fix.

Then follows a little bit of additional refactoring in order to prepare for introduction of the new options, and finally the series are finished by the implementation, documentation updates, and some testing for the new options.

Updates in v3:

* Fixed all the known style issues

* Revised -m, -c, and -cc description as suggested by Elijah Newren

* Removed manual abbrevs for diff-merge options

* Got rid of if(0) ; idiom

* Renamed regulars_need_diff to all_need_diff to better reflect the meaning of the variable.

* Moved "diff-merges: handle imply -p on -c/--cc logic for log.c" closer to the beginning of the series, where it belongs as being pure refactoring of the old code.

* Added code clarification comments to set_diff_merges()

Updates in v2:

* Move logic of "-c/--cc imply -p" to this module and do not imply -p by new --diff-merges options. Instead enable corresponding diff output without affecting non-merge commits. This is the most significant change with respect to v1 and it starts at 24/33.

* Add support for old mnemonics: --diff-merges=(m|c|cc) to help those who are used to them, and add --diff-merges=1 to cover all variants with short mnemonics.

* Fixed functions definitions style to have open curly brace on its own line, pointed to by Junio C Hamano.

* Tweak --diff-merges=first-parent description, requested by Elijah Newren.

* Fixed git-show documentation not to include description chunk relevant to git-log only, noticed by Elijah Newren.

* Fixed documentation mistake claiming that -p is needed for diff-merges options to take effect, noticed by Elijah Newren.

* Fixed a case where a change was put into wrong commit. The change moved to 11/27 form 10/27. Didn't affect end-result in any way.

* Added short module description to diff-merges.h, as suggested by Junio C Hamano.

* Fixed not returning "argcount" from diff_merges_parse_opts(),
noticed by Junio C Hamano.

Updates in v1:

* Added documentation fix for git-show to include --diff-merges.

* Fixed typos in commit messages noticed by Philip Oakley.

Sergey Organov (32):
revision: factor out parsing of diff-merge related options
revision: factor out setup of diff-merge related settings
revision: factor out initialization of diff-merge related settings
revision: provide implementation for diff merges tweaks
revision: move diff merges functions to its own diff-merges.c
diff-merges: rename all functions to have common prefix
diff-merges: move checks for first_parent_only out of the module
diff-merges: rename diff_merges_default_to_enable() to match semantics
diff-merges: re-arrange functions to match the order they are called
in
diff-merges: new function diff_merges_suppress()
diff-merges: new function diff_merges_set_dense_combined_if_unset()
diff-merges: introduce revs->first_parent_merges flag
diff-merges: handle imply -p on -c/--cc logic for log.c
diff-merges: revise revs->diff flag handling
t4013: support test_expect_failure through ':failure' magic
t4013: add tests for -m failing to override -c/--cc
diff-merges: fix -m to properly override -c/--cc
diff-merges: split 'ignore_merges' field
diff-merges: group diff-merge flags next to each other inside

    'rev_info'

diff-merges: get rid of now empty diff_merges_init_revs()
diff-merges: refactor opt settings into separate functions
diff-merges: make -m/-c/--cc explicitly mutually exclusive
diff-merges: implement new values for --diff-merges
diff-merges: do not imply -p for new options
diff-merges: let new options enable diff without -p
diff-merges: add old mnemonic counterparts to --diff-merges
diff-merges: add '--diff-merges=1' as synonym for 'first-parent' doc/git-log: describe new --diff-merges options doc/diff-generate-patch: mention new --diff-merges option doc/rev-list-options: document --first-parent changes merges format doc/git-show: include --diff-merges description
t4013: add tests for --diff-merges=first-parent

 Documentation/diff-generate-patch.txt         |   6 +-
 Documentation/diff-options.txt                |  51 +++++
 Documentation/git-log.txt                     |  46 +---
 Documentation/git-show.txt                    |   7 +-
 Documentation/rev-list-options.txt            |   5 +
 Makefile                                      |   1 +
 builtin/diff-files.c                          |   5 +-
 builtin/diff.c                                |   9 +-
 builtin/log.c                                 |  22 +-
 builtin/merge.c                               |   3 +-
 diff-merges.c                                 | 146 +++++++++++++
 diff-merges.h                                 |  24 +++
 fmt-merge-msg.c                               |   3 +-
 log-tree.c                                    |  30 +--
 revision.c                                    |  38 +---
 revision.h                                    |   9 +-
 t/t4013-diff-various.sh                       |  11 +-
 t/t4013/diff.log_--cc_-m_-p_master            | 200 ++++++++++++++++++
 ...diff.log_--diff-merges=first-parent_master |  56 +++++
 t/t4013/diff.log_-c_-m_-p_master              | 200 ++++++++++++++++++
 ...f.log_-p_--diff-merges=first-parent_master | 137 ++++++++++++
 21 files changed, 893 insertions(+), 116 deletions(-)
 create mode 100644 diff-merges.c
 create mode 100644 diff-merges.h
 create mode 100644 t/t4013/diff.log_--cc_-m_-p_master
 create mode 100644 t/t4013/diff.log_--diff-merges=first-parent_master
 create mode 100644 t/t4013/diff.log_-c_-m_-p_master
 create mode 100644 t/t4013/diff.log_-p_--diff-merges=first-parent_master

Interdiff against v2:

Documentation/diff-options.txt +4 -6
index 98db2be423dc..c995e82584f3 100644
@@ -55,8 +55,7 @@ ifdef::git-log[]
 -m:::
 	This makes merge commits show the full diff with respect to
 	each of the parents. Separate log entry and diff is generated
-	for each parent. `-m` is different in that it doesn't produce
-	any output without `-p`.
+	for each parent. `-m` doesn't produce any output without `-p`.
 +
 --diff-merges=combined:::
 --diff-merges=c:::
@@ -65,8 +64,8 @@ ifdef::git-log[]
 	differences from each of the parents to the merge result
 	simultaneously instead of showing pairwise diff between a
 	parent and the result one at a time. Furthermore, it lists
-	only files which were modified from all parents. Historically,
-	`-c` enables diff output for non-merge commits as well.
+	only files which were modified from all parents. `-c` implies
+	`-p`.
 +
 --diff-merges=dense-combined:::
 --diff-merges=cc:::
@@ -75,8 +74,7 @@ ifdef::git-log[]
 	`--diff-merges=combined` is further compressed by omitting
 	uninteresting hunks whose contents in the parents have only
 	two variants and the merge result picks one of them without
-	modification.  Historically, `--c` enables diff output for
-	non-merge commits as well.
+	modification.  `--cc` implies `-p`.
 
 --combined-all-paths::
 	This flag causes combined diffs (used for merge commits) to
diff-merges.c +15 -20
index 63a0d78b7730..146bb50316a6 100644
@@ -54,23 +54,22 @@ static void set_diff_merges(struct rev_info *revs, const char *optarg)
 {
 	if (!strcmp(optarg, "off") || !strcmp(optarg, "none")) {
 		suppress(revs);
+		/* Return early to leave revs->merges_need_diff unset */
 		return;
 	}
-	if (0) ;
-	else if (!strcmp(optarg, "first") || !strcmp(optarg, "first-parent") ||
-		 !strcmp(optarg, "1"))
+
+	if (!strcmp(optarg, "1") || !strcmp(optarg, "first-parent"))
 		set_first_parent(revs);
-	else if (!strcmp(optarg, "sep")   || !strcmp(optarg, "separate") ||
-		 !strcmp(optarg, "m"))
+	else if (!strcmp(optarg, "m") || !strcmp(optarg, "separate"))
 		set_separate(revs);
-	else if (!strcmp(optarg, "comb")  || !strcmp(optarg, "combined") ||
-		 !strcmp(optarg, "c"))
+	else if (!strcmp(optarg, "c") || !strcmp(optarg, "combined"))
 		set_combined(revs);
-	else if (!strcmp(optarg, "dense") || !strcmp(optarg, "dense-combined") ||
-		 !strcmp(optarg, "cc"))
+	else if (!strcmp(optarg, "cc") || !strcmp(optarg, "dense-combined"))
 		set_dense_combined(revs);
 	else
 		die(_("unknown value for --diff-merges: %s"), optarg);
+
+	/* The flag is cleared by set_xxx() functions, so don't move this up */
 	revs->merges_need_diff = 1;
 }
 
@@ -84,23 +83,21 @@ int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
 	const char *optarg;
 	const char *arg = argv[0];
 
-	if (!strcmp(arg, "-m"))
+	if (!strcmp(arg, "-m")) {
 		set_m(revs);
-	else if (!strcmp(arg, "-c")) {
+	} else if (!strcmp(arg, "-c")) {
 		set_combined(revs);
 		revs->combined_imply_patch = 1;
-	}
-	else if (!strcmp(arg, "--cc")) {
+	} else if (!strcmp(arg, "--cc")) {
 		set_dense_combined(revs);
 		revs->combined_imply_patch = 1;
-	}
-	else if (!strcmp(arg, "--no-diff-merges"))
+	} else if (!strcmp(arg, "--no-diff-merges")) {
 		suppress(revs);
-	else if (!strcmp(arg, "--combined-all-paths"))
+	} else if (!strcmp(arg, "--combined-all-paths")) {
 		revs->combined_all_paths = 1;
-	else if ((argcount = parse_long_opt("diff-merges", argv, &optarg)))
+	} else if ((argcount = parse_long_opt("diff-merges", argv, &optarg))) {
 		set_diff_merges(revs, optarg);
-	else
+	} else
 		return 0;
 
 	revs->explicit_diff_merges = 1;
@@ -140,10 +137,8 @@ void diff_merges_setup_revs(struct rev_info *revs)
 		revs->first_parent_merges = 0;
 	if (revs->combined_all_paths && !revs->combine_merges)
 		die("--combined-all-paths makes no sense without -c or --cc");
-
 	if (revs->combined_imply_patch)
 		revs->diff = 1;
-
 	if (revs->combined_imply_patch || revs->merges_need_diff) {
 		if (!revs->diffopt.output_format)
 			revs->diffopt.output_format = DIFF_FORMAT_PATCH;
log-tree.c +3 -3
index 67060492ca0a..9f50a81e537e 100644
@@ -900,9 +900,9 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
 	struct commit_list *parents;
 	struct object_id *oid;
 	int is_merge;
-	int regulars_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;
+	int all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;
 
-	if (!regulars_need_diff && !opt->merges_need_diff)
+	if (!all_need_diff && !opt->merges_need_diff)
 		return 0;
 
 	parse_commit_or_die(commit);
@@ -910,7 +910,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
 
 	parents = get_saved_parents(opt, commit);
 	is_merge = parents && parents->next;
-	if(!is_merge && !regulars_need_diff)
+	if (!is_merge && !all_need_diff)
 		return 0;
 
 	/* Root commit? */
Signature · 1 line
2.25.1
#196 lore raw

PATCH v3 1/32 revision: factor out parsing of diff-merge related options

Move all the parsing code related to diffing merges into new parse_diff_merge_opts() function.

---
 revision.c | 67 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 40 insertions(+), 27 deletions(-)
revision.c +40 -27
index aa6221204081..8b17cfd754fe 100644
@@ -2153,6 +2153,45 @@ static void add_message_grep(struct rev_info *revs, const char *pattern)
 	add_grep(revs, pattern, GREP_PATTERN_BODY);
 }
 
+static int parse_diff_merge_opts(struct rev_info *revs, const char **argv)
+{
+	int argcount = 1;
+	const char *optarg;
+	const char *arg = argv[0];
+
+	if (!strcmp(arg, "-m")) {
+		/*
+		 * To "diff-index", "-m" means "match missing", and to the "log"
+		 * family of commands, it means "show full diff for merges". Set
+		 * both fields appropriately.
+		 */
+		revs->ignore_merges = 0;
+		revs->match_missing = 1;
+	} else if (!strcmp(arg, "-c")) {
+		revs->diff = 1;
+		revs->dense_combined_merges = 0;
+		revs->combine_merges = 1;
+	} else if (!strcmp(arg, "--cc")) {
+		revs->diff = 1;
+		revs->dense_combined_merges = 1;
+		revs->combine_merges = 1;
+	} else if (!strcmp(arg, "--no-diff-merges")) {
+		revs->ignore_merges = 1;
+	} else if (!strcmp(arg, "--combined-all-paths")) {
+		revs->diff = 1;
+		revs->combined_all_paths = 1;
+	} else if ((argcount = parse_long_opt("diff-merges", argv, &optarg))) {
+		if (!strcmp(optarg, "off")) {
+			revs->ignore_merges = 1;
+		} else {
+			die(_("unknown value for --diff-merges: %s"), optarg);
+		}
+	} else
+		argcount = 0;
+
+	return argcount;
+}
+
 static int handle_revision_opt(struct rev_info *revs, int argc, const char **argv,
 			       int *unkc, const char **unkv,
 			       const struct setup_revision_opt* opt)
@@ -2349,34 +2388,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		revs->diff = 1;
 		revs->diffopt.flags.recursive = 1;
 		revs->diffopt.flags.tree_in_recursive = 1;
-	} else if (!strcmp(arg, "-m")) {
-		/*
-		 * To "diff-index", "-m" means "match missing", and to the "log"
-		 * family of commands, it means "show full diff for merges". Set
-		 * both fields appropriately.
-		 */
-		revs->ignore_merges = 0;
-		revs->match_missing = 1;
-	} else if ((argcount = parse_long_opt("diff-merges", argv, &optarg))) {
-		if (!strcmp(optarg, "off")) {
-			revs->ignore_merges = 1;
-		} else {
-			die(_("unknown value for --diff-merges: %s"), optarg);
-		}
+	} else if ((argcount = parse_diff_merge_opts(revs, argv))) {
 		return argcount;
-	} else if (!strcmp(arg, "--no-diff-merges")) {
-		revs->ignore_merges = 1;
-	} else if (!strcmp(arg, "-c")) {
-		revs->diff = 1;
-		revs->dense_combined_merges = 0;
-		revs->combine_merges = 1;
-	} else if (!strcmp(arg, "--combined-all-paths")) {
-		revs->diff = 1;
-		revs->combined_all_paths = 1;
-	} else if (!strcmp(arg, "--cc")) {
-		revs->diff = 1;
-		revs->dense_combined_merges = 1;
-		revs->combine_merges = 1;
 	} else if (!strcmp(arg, "-v")) {
 		revs->verbose_header = 1;
 	} else if (!strcmp(arg, "--pretty")) {
Signature · 1 line
2.25.1
#197 lore raw

PATCH v3 2/32 revision: factor out setup of diff-merge related settings

In reply to Sergey Organov

Move all the setting code related to diffing merges into new setup_diff_merge_revs() function.

---
 revision.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
revision.c +12 -6
index 8b17cfd754fe..d818e0b18bbc 100644
@@ -2192,6 +2192,16 @@ static int parse_diff_merge_opts(struct rev_info *revs, const char **argv)
 	return argcount;
 }
 
+static void setup_diff_merges_revs(struct rev_info *revs)
+{
+	if (revs->combine_merges && revs->ignore_merges < 0)
+		revs->ignore_merges = 0;
+	if (revs->ignore_merges < 0)
+		revs->ignore_merges = 1;
+	if (revs->combined_all_paths && !revs->combine_merges)
+		die("--combined-all-paths makes no sense without -c or --cc");
+}
+
 static int handle_revision_opt(struct rev_info *revs, int argc, const char **argv,
 			       int *unkc, const char **unkv,
 			       const struct setup_revision_opt* opt)
@@ -2886,12 +2896,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 			copy_pathspec(&revs->diffopt.pathspec,
 				      &revs->prune_data);
 	}
-	if (revs->combine_merges && revs->ignore_merges < 0)
-		revs->ignore_merges = 0;
-	if (revs->ignore_merges < 0)
-		revs->ignore_merges = 1;
-	if (revs->combined_all_paths && !revs->combine_merges)
-		die("--combined-all-paths makes no sense without -c or --cc");
+
+	setup_diff_merges_revs(revs);
 
 	revs->diffopt.abbrev = revs->abbrev;
 
Signature · 1 line
2.25.1
#198 lore raw

PATCH v3 3/32 revision: factor out initialization of diff-merge related settings

In reply to Sergey Organov

Move initialization code related to diffing merges into new init_diff_merge_revs() function.

---
 revision.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
revision.c +8 -1
index d818e0b18bbc..3250b2d7e112 100644
@@ -1805,6 +1805,8 @@ static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
 	return 1;
 }
 
+static void init_diff_merge_revs(struct rev_info *revs);
+
 void repo_init_revisions(struct repository *r,
 			 struct rev_info *revs,
 			 const char *prefix)
@@ -1813,7 +1815,7 @@ void repo_init_revisions(struct repository *r,
 
 	revs->repo = r;
 	revs->abbrev = DEFAULT_ABBREV;
-	revs->ignore_merges = -1;
+	init_diff_merge_revs(revs);
 	revs->simplify_history = 1;
 	revs->pruning.repo = r;
 	revs->pruning.flags.recursive = 1;
@@ -2153,6 +2155,11 @@ static void add_message_grep(struct rev_info *revs, const char *pattern)
 	add_grep(revs, pattern, GREP_PATTERN_BODY);
 }
 
+static void init_diff_merge_revs(struct rev_info *revs)
+{
+	revs->ignore_merges = -1;
+}
+
 static int parse_diff_merge_opts(struct rev_info *revs, const char **argv)
 {
 	int argcount = 1;
Signature · 1 line
2.25.1
#199 lore raw

PATCH v3 4/32 revision: provide implementation for diff merges tweaks

In reply to Sergey Organov

Use these implementations from show_setup_revisions_tweak() and log_setup_revisions_tweak() in builtin/log.c.

This completes moving of management of diff merges parameters to a single place, where we can finally observe them simultaneously.

---
 builtin/log.c | 13 ++-----------
 revision.c    | 19 +++++++++++++++++++
 revision.h    |  3 +++
 3 files changed, 24 insertions(+), 11 deletions(-)
builtin/log.c +2 -11
index 0a7ed4bef92b..717855a49e90 100644
@@ -598,15 +598,7 @@ static int show_tree_object(const struct object_id *oid,
 static void show_setup_revisions_tweak(struct rev_info *rev,
 				       struct setup_revision_opt *opt)
 {
-	if (rev->ignore_merges < 0) {
-		/* There was no "-m" variant on the command line */
-		rev->ignore_merges = 0;
-		if (!rev->first_parent_only && !rev->combine_merges) {
-			/* No "--first-parent", "-c", or "--cc" */
-			rev->combine_merges = 1;
-			rev->dense_combined_merges = 1;
-		}
-	}
+	rev_diff_merges_default_to_dense_combined(rev);
 	if (!rev->diffopt.output_format)
 		rev->diffopt.output_format = DIFF_FORMAT_PATCH;
 }
@@ -731,8 +723,7 @@ static void log_setup_revisions_tweak(struct rev_info *rev,
 	if (!rev->diffopt.output_format && rev->combine_merges)
 		rev->diffopt.output_format = DIFF_FORMAT_PATCH;
 
-	if (rev->first_parent_only && rev->ignore_merges < 0)
-		rev->ignore_merges = 0;
+	rev_diff_merges_first_parent_defaults_to_enable(rev);
 }
 
 int cmd_log(int argc, const char **argv, const char *prefix)
revision.c +19 -0
index 3250b2d7e112..1c224d276474 100644
@@ -2209,6 +2209,25 @@ static void setup_diff_merges_revs(struct rev_info *revs)
 		die("--combined-all-paths makes no sense without -c or --cc");
 }
 
+void rev_diff_merges_first_parent_defaults_to_enable(struct rev_info *revs)
+{
+	if (revs->first_parent_only && revs->ignore_merges < 0)
+		revs->ignore_merges = 0;
+}
+
+void rev_diff_merges_default_to_dense_combined(struct rev_info *revs)
+{
+	if (revs->ignore_merges < 0) {
+		/* There was no "-m" variant on the command line */
+		revs->ignore_merges = 0;
+		if (!revs->first_parent_only && !revs->combine_merges) {
+			/* No "--first-parent", "-c", or "--cc" */
+			revs->combine_merges = 1;
+			revs->dense_combined_merges = 1;
+		}
+	}
+}
+
 static int handle_revision_opt(struct rev_info *revs, int argc, const char **argv,
 			       int *unkc, const char **unkv,
 			       const struct setup_revision_opt* opt)
revision.h +3 -0
index f6bf860d19e5..3dd0229f4edc 100644
@@ -456,4 +456,7 @@ int rewrite_parents(struct rev_info *revs,
  */
 struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit);
 
+void rev_diff_merges_default_to_dense_combined(struct rev_info *revs);
+void rev_diff_merges_first_parent_defaults_to_enable(struct rev_info *revs);
+
 #endif
Signature · 1 line
2.25.1
#200 lore raw

PATCH v3 5/32 revision: move diff merges functions to its own diff-merges.c

In reply to Sergey Organov

Create separate diff-merges.c and diff-merges.h files, and move all the code related to handling of diff merges there.

---
 Makefile      |  1 +
 builtin/log.c |  1 +
 diff-merges.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++
 diff-merges.h | 18 ++++++++++++
 revision.c    | 76 +--------------------------------------------------
 revision.h    |  3 --
 6 files changed, 97 insertions(+), 78 deletions(-)
 create mode 100644 diff-merges.c
 create mode 100644 diff-merges.h
Makefile +1 -0
index 1fb0ec17059a..d1347ef262cf 100644
@@ -872,6 +872,7 @@ LIB_OBJS += date.o
 LIB_OBJS += decorate.o
 LIB_OBJS += delta-islands.o
 LIB_OBJS += diff-delta.o
+LIB_OBJS += diff-merges.o
 LIB_OBJS += diff-lib.o
 LIB_OBJS += diff-no-index.o
 LIB_OBJS += diff.o
builtin/log.c +1 -0
index 717855a49e90..ad3092fdd854 100644
@@ -12,6 +12,7 @@
 #include "color.h"
 #include "commit.h"
 #include "diff.h"
+#include "diff-merges.h"
 #include "revision.h"
 #include "log-tree.h"
 #include "builtin.h"
diff-merges.c new file +76 -0

76 lines not on this page · raw message

diff-merges.h new file +18 -0
new file mode 100644
index 000000000000..7e970b266cf5
@@ -0,0 +1,18 @@
+#ifndef DIFF_MERGES_H
+#define DIFF_MERGES_H
+
+/*
+ * diff-merges - utility module to handle command-line options for
+ * selection of particular diff format of merge commits
+ * representation.
+ */
+
+struct rev_info;
+
+void init_diff_merge_revs(struct rev_info *revs);
+int parse_diff_merge_opts(struct rev_info *revs, const char **argv);
+void setup_diff_merges_revs(struct rev_info *revs);
+void rev_diff_merges_default_to_dense_combined(struct rev_info *revs);
+void rev_diff_merges_first_parent_defaults_to_enable(struct rev_info *revs);
+
+#endif
revision.c +1 -75

94 lines not on this page · raw message

revision.h +0 -3
index 3dd0229f4edc..f6bf860d19e5 100644
@@ -456,7 +456,4 @@ int rewrite_parents(struct rev_info *revs,
  */
 struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit);
 
-void rev_diff_merges_default_to_dense_combined(struct rev_info *revs);
-void rev_diff_merges_first_parent_defaults_to_enable(struct rev_info *revs);
-
 #endif
Signature · 1 line
2.25.1
#201 lore raw

PATCH v3 6/32 diff-merges: rename all functions to have common prefix

In reply to Sergey Organov

Use the same "diff_merges" prefix for all the diff merges function names.

---
 builtin/log.c |  4 ++--
 diff-merges.c | 10 +++++-----
 diff-merges.h | 15 ++++++++++-----
 revision.c    |  6 +++---
 4 files changed, 20 insertions(+), 15 deletions(-)
builtin/log.c +2 -2
index ad3092fdd854..77a7bba543ad 100644
@@ -599,7 +599,7 @@ static int show_tree_object(const struct object_id *oid,
 static void show_setup_revisions_tweak(struct rev_info *rev,
 				       struct setup_revision_opt *opt)
 {
-	rev_diff_merges_default_to_dense_combined(rev);
+	diff_merges_default_to_dense_combined(rev);
 	if (!rev->diffopt.output_format)
 		rev->diffopt.output_format = DIFF_FORMAT_PATCH;
 }
@@ -724,7 +724,7 @@ static void log_setup_revisions_tweak(struct rev_info *rev,
 	if (!rev->diffopt.output_format && rev->combine_merges)
 		rev->diffopt.output_format = DIFF_FORMAT_PATCH;
 
-	rev_diff_merges_first_parent_defaults_to_enable(rev);
+	diff_merges_first_parent_defaults_to_enable(rev);
 }
 
 int cmd_log(int argc, const char **argv, const char *prefix)
diff-merges.c +5 -5
index 0204292aa9bb..9286dbbd4dfd 100644
@@ -2,12 +2,12 @@
 
 #include "revision.h"
 
-void init_diff_merge_revs(struct rev_info *revs)
+void diff_merges_init_revs(struct rev_info *revs)
 {
 	revs->ignore_merges = -1;
 }
 
-int parse_diff_merge_opts(struct rev_info *revs, const char **argv)
+int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
 {
 	int argcount = 1;
 	const char *optarg;
@@ -46,7 +46,7 @@ int parse_diff_merge_opts(struct rev_info *revs, const char **argv)
 	return argcount;
 }
 
-void setup_diff_merges_revs(struct rev_info *revs)
+void diff_merges_setup_revs(struct rev_info *revs)
 {
 	if (revs->combine_merges && revs->ignore_merges < 0)
 		revs->ignore_merges = 0;
@@ -56,13 +56,13 @@ void setup_diff_merges_revs(struct rev_info *revs)
 		die("--combined-all-paths makes no sense without -c or --cc");
 }
 
-void rev_diff_merges_first_parent_defaults_to_enable(struct rev_info *revs)
+void diff_merges_first_parent_defaults_to_enable(struct rev_info *revs)
 {
 	if (revs->first_parent_only && revs->ignore_merges < 0)
 		revs->ignore_merges = 0;
 }
 
-void rev_diff_merges_default_to_dense_combined(struct rev_info *revs)
+void diff_merges_default_to_dense_combined(struct rev_info *revs)
 {
 	if (revs->ignore_merges < 0) {
 		/* There was no "-m" variant on the command line */
diff-merges.h +10 -5
index 7e970b266cf5..4ced909b795e 100644
@@ -9,10 +9,15 @@
 
 struct rev_info;
 
-void init_diff_merge_revs(struct rev_info *revs);
-int parse_diff_merge_opts(struct rev_info *revs, const char **argv);
-void setup_diff_merges_revs(struct rev_info *revs);
-void rev_diff_merges_default_to_dense_combined(struct rev_info *revs);
-void rev_diff_merges_first_parent_defaults_to_enable(struct rev_info *revs);
+void diff_merges_init_revs(struct rev_info *revs);
+
+int diff_merges_parse_opts(struct rev_info *revs, const char **argv);
+
+void diff_merges_setup_revs(struct rev_info *revs);
+
+void diff_merges_default_to_dense_combined(struct rev_info *revs);
+
+void diff_merges_first_parent_defaults_to_enable(struct rev_info *revs);
+
 
 #endif
revision.c +3 -3
index 4bc14a08a624..5a0e3d6ad542 100644
@@ -1814,7 +1814,7 @@ void repo_init_revisions(struct repository *r,
 
 	revs->repo = r;
 	revs->abbrev = DEFAULT_ABBREV;
-	init_diff_merge_revs(revs);
+	diff_merges_init_revs(revs);
 	revs->simplify_history = 1;
 	revs->pruning.repo = r;
 	revs->pruning.flags.recursive = 1;
@@ -2350,7 +2350,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		revs->diff = 1;
 		revs->diffopt.flags.recursive = 1;
 		revs->diffopt.flags.tree_in_recursive = 1;
-	} else if ((argcount = parse_diff_merge_opts(revs, argv))) {
+	} else if ((argcount = diff_merges_parse_opts(revs, argv))) {
 		return argcount;
 	} else if (!strcmp(arg, "-v")) {
 		revs->verbose_header = 1;
@@ -2849,7 +2849,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 				      &revs->prune_data);
 	}
 
-	setup_diff_merges_revs(revs);
+	diff_merges_setup_revs(revs);
 
 	revs->diffopt.abbrev = revs->abbrev;
 
Signature · 1 line
2.25.1
#202 lore raw

PATCH v3 7/32 diff-merges: move checks for first_parent_only out of the module

In reply to Sergey Organov

The checks for first_parent_only don't in fact belong to this module, as the primary purpose of this flag is history traversal limiting, so get it out of this module and rename the

diff_merges_first_parent_defaults_to_enable()

to

diff_merges_default_to_enable()

to match new semantics.

---
 builtin/log.c |  8 ++++++--
 diff-merges.c | 10 ++++------
 diff-merges.h |  2 +-
 3 files changed, 11 insertions(+), 9 deletions(-)
builtin/log.c +6 -2
index 77a7bba543ad..a7791c003c91 100644
@@ -599,7 +599,10 @@ static int show_tree_object(const struct object_id *oid,
 static void show_setup_revisions_tweak(struct rev_info *rev,
 				       struct setup_revision_opt *opt)
 {
-	diff_merges_default_to_dense_combined(rev);
+	if (rev->first_parent_only)
+		diff_merges_default_to_enable(rev);
+	else
+		diff_merges_default_to_dense_combined(rev);
 	if (!rev->diffopt.output_format)
 		rev->diffopt.output_format = DIFF_FORMAT_PATCH;
 }
@@ -724,7 +727,8 @@ static void log_setup_revisions_tweak(struct rev_info *rev,
 	if (!rev->diffopt.output_format && rev->combine_merges)
 		rev->diffopt.output_format = DIFF_FORMAT_PATCH;
 
-	diff_merges_first_parent_defaults_to_enable(rev);
+	if (rev->first_parent_only)
+		diff_merges_default_to_enable(rev);
 }
 
 int cmd_log(int argc, const char **argv, const char *prefix)
diff-merges.c +4 -6
index 9286dbbd4dfd..a3bafa92f3e1 100644
@@ -56,19 +56,17 @@ void diff_merges_setup_revs(struct rev_info *revs)
 		die("--combined-all-paths makes no sense without -c or --cc");
 }
 
-void diff_merges_first_parent_defaults_to_enable(struct rev_info *revs)
+void diff_merges_default_to_enable(struct rev_info *revs)
 {
-	if (revs->first_parent_only && revs->ignore_merges < 0)
+	if (revs->ignore_merges < 0)		/* No -m */
 		revs->ignore_merges = 0;
 }
 
 void diff_merges_default_to_dense_combined(struct rev_info *revs)
 {
-	if (revs->ignore_merges < 0) {
-		/* There was no "-m" variant on the command line */
+	if (revs->ignore_merges < 0) {		/* No -m */
 		revs->ignore_merges = 0;
-		if (!revs->first_parent_only && !revs->combine_merges) {
-			/* No "--first-parent", "-c", or "--cc" */
+		if (!revs->combine_merges) {	/* No -c/--cc" */
 			revs->combine_merges = 1;
 			revs->dense_combined_merges = 1;
 		}
diff-merges.h +1 -1
index 4ced909b795e..6937d46219f1 100644
@@ -17,7 +17,7 @@ void diff_merges_setup_revs(struct rev_info *revs);
 
 void diff_merges_default_to_dense_combined(struct rev_info *revs);
 
-void diff_merges_first_parent_defaults_to_enable(struct rev_info *revs);
+void diff_merges_default_to_enable(struct rev_info *revs);
 
 
 #endif
Signature · 1 line
2.25.1
#203 lore raw

PATCH v3 8/32 diff-merges: rename diff_merges_default_to_enable() to match semantics

In reply to Sergey Organov

Rename diff_merges_default_to_enable() to diff_merges_default_to_first_parent() to match its semantics.

---
 builtin/log.c | 4 ++--
 diff-merges.c | 2 +-
 diff-merges.h | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
builtin/log.c +2 -2
index a7791c003c91..63875c3aeec9 100644
@@ -600,7 +600,7 @@ static void show_setup_revisions_tweak(struct rev_info *rev,
 				       struct setup_revision_opt *opt)
 {
 	if (rev->first_parent_only)
-		diff_merges_default_to_enable(rev);
+		diff_merges_default_to_first_parent(rev);
 	else
 		diff_merges_default_to_dense_combined(rev);
 	if (!rev->diffopt.output_format)
@@ -728,7 +728,7 @@ static void log_setup_revisions_tweak(struct rev_info *rev,
 		rev->diffopt.output_format = DIFF_FORMAT_PATCH;
 
 	if (rev->first_parent_only)
-		diff_merges_default_to_enable(rev);
+		diff_merges_default_to_first_parent(rev);
 }
 
 int cmd_log(int argc, const char **argv, const char *prefix)
diff-merges.c +1 -1
index a3bafa92f3e1..76c804579758 100644
@@ -56,7 +56,7 @@ void diff_merges_setup_revs(struct rev_info *revs)
 		die("--combined-all-paths makes no sense without -c or --cc");
 }
 
-void diff_merges_default_to_enable(struct rev_info *revs)
+void diff_merges_default_to_first_parent(struct rev_info *revs)
 {
 	if (revs->ignore_merges < 0)		/* No -m */
 		revs->ignore_merges = 0;
diff-merges.h +1 -1
index 6937d46219f1..18861dc5480e 100644
@@ -17,7 +17,7 @@ void diff_merges_setup_revs(struct rev_info *revs);
 
 void diff_merges_default_to_dense_combined(struct rev_info *revs);
 
-void diff_merges_default_to_enable(struct rev_info *revs);
+void diff_merges_default_to_first_parent(struct rev_info *revs);
 
 
 #endif
Signature · 1 line
2.25.1
#204 lore raw

PATCH v3 9/32 diff-merges: re-arrange functions to match the order they are called in

In reply to Sergey Organov

For clarity, define public functions in the order they are called, to make logic inter-dependencies easier to grok.

---
 diff-merges.c | 24 ++++++++++++++----------
 diff-merges.h |  7 +++----
 2 files changed, 17 insertions(+), 14 deletions(-)
diff-merges.c +14 -10
index 76c804579758..8325ab880166 100644
@@ -2,6 +2,10 @@
 
 #include "revision.h"
 
+/*
+ * Public functions. They are in the order they are called.
+ */
+
 void diff_merges_init_revs(struct rev_info *revs)
 {
 	revs->ignore_merges = -1;
@@ -46,16 +50,6 @@ int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
 	return argcount;
 }
 
-void diff_merges_setup_revs(struct rev_info *revs)
-{
-	if (revs->combine_merges && revs->ignore_merges < 0)
-		revs->ignore_merges = 0;
-	if (revs->ignore_merges < 0)
-		revs->ignore_merges = 1;
-	if (revs->combined_all_paths && !revs->combine_merges)
-		die("--combined-all-paths makes no sense without -c or --cc");
-}
-
 void diff_merges_default_to_first_parent(struct rev_info *revs)
 {
 	if (revs->ignore_merges < 0)		/* No -m */
@@ -72,3 +66,13 @@ void diff_merges_default_to_dense_combined(struct rev_info *revs)
 		}
 	}
 }
+
+void diff_merges_setup_revs(struct rev_info *revs)
+{
+	if (revs->combine_merges && revs->ignore_merges < 0)
+		revs->ignore_merges = 0;
+	if (revs->ignore_merges < 0)
+		revs->ignore_merges = 1;
+	if (revs->combined_all_paths && !revs->combine_merges)
+		die("--combined-all-paths makes no sense without -c or --cc");
+}
diff-merges.h +3 -4
index 18861dc5480e..243ef915c4cd 100644
@@ -13,11 +13,10 @@ void diff_merges_init_revs(struct rev_info *revs);
 
 int diff_merges_parse_opts(struct rev_info *revs, const char **argv);
 
-void diff_merges_setup_revs(struct rev_info *revs);
-
-void diff_merges_default_to_dense_combined(struct rev_info *revs);
-
 void diff_merges_default_to_first_parent(struct rev_info *revs);
 
+void diff_merges_default_to_dense_combined(struct rev_info *revs);
+
+void diff_merges_setup_revs(struct rev_info *revs);
 
 #endif
Signature · 1 line
2.25.1
#205 lore raw

PATCH v3 10/32 diff-merges: new function diff_merges_suppress()

In reply to Sergey Organov

This function sets all the relevant flags to disabled state, so that no code that checks only one of them get it wrong.

Then we call this new function everywhere where diff merges output suppression is needed.

---
 builtin/merge.c |  3 ++-
 diff-merges.c   | 17 +++++++++++++++--
 diff-merges.h   |  2 ++
 fmt-merge-msg.c |  3 ++-
 4 files changed, 21 insertions(+), 4 deletions(-)
builtin/merge.c +2 -1
index 9d5359edc2f7..1f7b69982b40 100644
@@ -14,6 +14,7 @@
 #include "lockfile.h"
 #include "run-command.h"
 #include "diff.h"
+#include "diff-merges.h"
 #include "refs.h"
 #include "refspec.h"
 #include "commit.h"
@@ -400,7 +401,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead
 	printf(_("Squash commit -- not updating HEAD\n"));
 
 	repo_init_revisions(the_repository, &rev, NULL);
-	rev.ignore_merges = 1;
+	diff_merges_suppress(&rev);
 	rev.commit_format = CMIT_FMT_MEDIUM;
 
 	commit->object.flags |= UNINTERESTING;
diff-merges.c +15 -2
index 8325ab880166..23e6cb11d1ad 100644
@@ -2,6 +2,14 @@
 
 #include "revision.h"
 
+static void suppress(struct rev_info *revs)
+{
+	revs->ignore_merges = 1;
+	revs->first_parent_merges = 0;
+	revs->combine_merges = 0;
+	revs->dense_combined_merges = 0;
+}
+
 /*
  * Public functions. They are in the order they are called.
  */
@@ -34,13 +42,13 @@ int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
 		revs->dense_combined_merges = 1;
 		revs->combine_merges = 1;
 	} else if (!strcmp(arg, "--no-diff-merges")) {
-		revs->ignore_merges = 1;
+		suppress(revs);
 	} else if (!strcmp(arg, "--combined-all-paths")) {
 		revs->diff = 1;
 		revs->combined_all_paths = 1;
 	} else if ((argcount = parse_long_opt("diff-merges", argv, &optarg))) {
 		if (!strcmp(optarg, "off")) {
-			revs->ignore_merges = 1;
+			suppress(revs);
 		} else {
 			die(_("unknown value for --diff-merges: %s"), optarg);
 		}
@@ -50,6 +58,11 @@ int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
 	return argcount;
 }
 
+void diff_merges_suppress(struct rev_info *revs)
+{
+	suppress(revs);
+}
+
 void diff_merges_default_to_first_parent(struct rev_info *revs)
 {
 	if (revs->ignore_merges < 0)		/* No -m */
diff-merges.h +2 -0
index 243ef915c4cd..a031240576f7 100644
@@ -13,6 +13,8 @@ void diff_merges_init_revs(struct rev_info *revs);
 
 int diff_merges_parse_opts(struct rev_info *revs, const char **argv);
 
+void diff_merges_suppress(struct rev_info *revs);
+
 void diff_merges_default_to_first_parent(struct rev_info *revs);
 
 void diff_merges_default_to_dense_combined(struct rev_info *revs);
fmt-merge-msg.c +2 -1
index bd22e1ea8865..abc3403fb820 100644
@@ -2,6 +2,7 @@
 #include "refs.h"
 #include "object-store.h"
 #include "diff.h"
+#include "diff-merges.h"
 #include "revision.h"
 #include "tag.h"
 #include "string-list.h"
@@ -668,7 +669,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,
 		head = lookup_commit_or_die(&head_oid, "HEAD");
 		repo_init_revisions(the_repository, &rev, NULL);
 		rev.commit_format = CMIT_FMT_ONELINE;
-		rev.ignore_merges = 1;
+		diff_merges_suppress(&rev);
 		rev.limited = 1;
 
 		strbuf_complete_line(out);
Signature · 1 line
2.25.1
#206 lore raw

PATCH v3 11/32 diff-merges: new function diff_merges_set_dense_combined_if_unset()

In reply to Sergey Organov

Call it where given functionality is needed instead of direct checking/tweaking of diff merges related fields.

---
 builtin/diff-files.c |  5 +++--
 builtin/diff.c       |  9 +++++----
 diff-merges.c        | 16 ++++++++++++++--
 diff-merges.h        |  2 ++
 4 files changed, 24 insertions(+), 8 deletions(-)
builtin/diff-files.c +3 -2
index 1e352dd8f77c..4742a4559b21 100644
@@ -7,6 +7,7 @@
 #include "cache.h"
 #include "config.h"
 #include "diff.h"
+#include "diff-merges.h"
 #include "commit.h"
 #include "revision.h"
 #include "builtin.h"
@@ -69,9 +70,9 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
 	 * was not asked to.  "diff-files -c -p" should not densify
 	 * (the user should ask with "diff-files --cc" explicitly).
 	 */
-	if (rev.max_count == -1 && !rev.combine_merges &&
+	if (rev.max_count == -1 &&
 	    (rev.diffopt.output_format & DIFF_FORMAT_PATCH))
-		rev.combine_merges = rev.dense_combined_merges = 1;
+		diff_merges_set_dense_combined_if_unset(&rev);
 
 	if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
 		perror("read_cache_preload");
builtin/diff.c +5 -4
index cd4083fed96e..2f570a3131cb 100644
@@ -13,6 +13,7 @@
 #include "blob.h"
 #include "tag.h"
 #include "diff.h"
+#include "diff-merges.h"
 #include "diffcore.h"
 #include "revision.h"
 #include "log-tree.h"
@@ -199,8 +200,8 @@ static int builtin_diff_combined(struct rev_info *revs,
 	if (argc > 1)
 		usage(builtin_diff_usage);
 
-	if (!revs->dense_combined_merges && !revs->combine_merges)
-		revs->dense_combined_merges = revs->combine_merges = 1;
+	diff_merges_set_dense_combined_if_unset(revs);
+
 	for (i = 1; i < ents; i++)
 		oid_array_append(&parents, &ent[i].item->oid);
 	diff_tree_combined(&ent[0].item->oid, &parents, revs);
@@ -248,9 +249,9 @@ static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv
 	 * dense one, --cc can be explicitly asked for, or just rely
 	 * on the default).
 	 */
-	if (revs->max_count == -1 && !revs->combine_merges &&
+	if (revs->max_count == -1 &&
 	    (revs->diffopt.output_format & DIFF_FORMAT_PATCH))
-		revs->combine_merges = revs->dense_combined_merges = 1;
+		diff_merges_set_dense_combined_if_unset(revs);
 
 	setup_work_tree();
 	if (read_cache_preload(&revs->diffopt.pathspec) < 0) {
diff-merges.c +14 -2
index 23e6cb11d1ad..24f922cf8a0f 100644
@@ -10,6 +10,13 @@ static void suppress(struct rev_info *revs)
 	revs->dense_combined_merges = 0;
 }
 
+static void set_dense_combined(struct rev_info *revs)
+{
+	revs->combine_merges = 1;
+	revs->dense_combined_merges = 1;
+}
+
+
 /*
  * Public functions. They are in the order they are called.
  */
@@ -39,8 +46,7 @@ int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
 		revs->combine_merges = 1;
 	} else if (!strcmp(arg, "--cc")) {
 		revs->diff = 1;
-		revs->dense_combined_merges = 1;
-		revs->combine_merges = 1;
+		set_dense_combined(revs);
 	} else if (!strcmp(arg, "--no-diff-merges")) {
 		suppress(revs);
 	} else if (!strcmp(arg, "--combined-all-paths")) {
@@ -80,6 +86,12 @@ void diff_merges_default_to_dense_combined(struct rev_info *revs)
 	}
 }
 
+void diff_merges_set_dense_combined_if_unset(struct rev_info *revs)
+{
+	if (!revs->combine_merges)
+		set_dense_combined(revs);
+}
+
 void diff_merges_setup_revs(struct rev_info *revs)
 {
 	if (revs->combine_merges && revs->ignore_merges < 0)
diff-merges.h +2 -0
index a031240576f7..f92de137d3a0 100644
@@ -19,6 +19,8 @@ void diff_merges_default_to_first_parent(struct rev_info *revs);
 
 void diff_merges_default_to_dense_combined(struct rev_info *revs);
 
+void diff_merges_set_dense_combined_if_unset(struct rev_info *revs);
+
 void diff_merges_setup_revs(struct rev_info *revs);
 
 #endif
Signature · 1 line
2.25.1
#207 lore raw

PATCH v3 12/32 diff-merges: introduce revs->first_parent_merges flag

In reply to Sergey Organov

This new field allows us to separate format of diff for merges from 'first_parent_only' flag which primary purpose is limiting history traversal.

This change further localizes diff format selection logic into the diff-merges.c file.

---
 diff-merges.c | 2 ++
 log-tree.c    | 4 ++--
 revision.h    | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)
diff-merges.c +2 -0
index 24f922cf8a0f..fb591a933959 100644
@@ -73,6 +73,8 @@ void diff_merges_default_to_first_parent(struct rev_info *revs)
 {
 	if (revs->ignore_merges < 0)		/* No -m */
 		revs->ignore_merges = 0;
+	if (!revs->combine_merges)		/* No -c/--cc" */
+		revs->first_parent_merges = 1;
 }
 
 void diff_merges_default_to_dense_combined(struct rev_info *revs)
log-tree.c +2 -2
index 1927f917ce94..3fdc0fc64bfb 100644
@@ -922,7 +922,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
 			return 0;
 		else if (opt->combine_merges)
 			return do_diff_combined(opt, commit);
-		else if (!opt->first_parent_only) {
+		else if (!opt->first_parent_merges) {
 			/* If we show multiple diffs, show the parent info */
 			log->parent = parents->item;
 		}
@@ -941,7 +941,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
 
 		/* Set up the log info for the next parent, if any.. */
 		parents = parents->next;
-		if (!parents || opt->first_parent_only)
+		if (!parents || opt->first_parent_merges)
 			break;
 		log->parent = parents->item;
 		opt->loginfo = log;
revision.h +1 -0
index f6bf860d19e5..ba2aef79215e 100644
@@ -194,6 +194,7 @@ struct rev_info {
 			combine_merges:1,
 			combined_all_paths:1,
 			dense_combined_merges:1,
+			first_parent_merges:1,
 			always_show_header:1;
 	int             ignore_merges:2;
 
Signature · 1 line
2.25.1
#208 lore raw

PATCH v3 13/32 diff-merges: handle imply -p on -c/--cc logic for log.c

In reply to Sergey Organov

Move logic that handles implying -p on -c/--cc from log_setup_revisions_tweak() to diff_merges_setup_revs(), where it belongs.

---
 builtin/log.c | 4 ----
 diff-merges.c | 5 +++++
 2 files changed, 5 insertions(+), 4 deletions(-)
builtin/log.c +0 -4
index 63875c3aeec9..c3caf0955b2b 100644
@@ -723,10 +723,6 @@ static void log_setup_revisions_tweak(struct rev_info *rev,
 	    rev->prune_data.nr == 1)
 		rev->diffopt.flags.follow_renames = 1;
 
-	/* 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;
-
 	if (rev->first_parent_only)
 		diff_merges_default_to_first_parent(rev);
 }
diff-merges.c +5 -0
index fb591a933959..c48a65f8de64 100644
@@ -102,4 +102,9 @@ void diff_merges_setup_revs(struct rev_info *revs)
 		revs->ignore_merges = 1;
 	if (revs->combined_all_paths && !revs->combine_merges)
 		die("--combined-all-paths makes no sense without -c or --cc");
+	if (revs->combine_merges) {
+		/* Turn --cc/-c into -p --cc/-c when -p was not given */
+		if (!revs->diffopt.output_format)
+			revs->diffopt.output_format = DIFF_FORMAT_PATCH;
+	}
 }
Signature · 1 line
2.25.1
#209 lore raw

PATCH v3 14/32 diff-merges: revise revs->diff flag handling

In reply to Sergey Organov

Do not set revs->diff when we encounter an option that needs it, as it'd be impossible to undo later. Besides, some other options than what we handle here set this flag as well, and we'd interfere with them trying to clear this flag later.

Rather set revs->diff, if finally needed, in diff_merges_setup_revs().

As an additional bonus, this also makes our code shorter.

---
 diff-merges.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
diff-merges.c +1 -3
index c48a65f8de64..225edd293b43 100644
@@ -41,16 +41,13 @@ int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
 		revs->ignore_merges = 0;
 		revs->match_missing = 1;
 	} else if (!strcmp(arg, "-c")) {
-		revs->diff = 1;
 		revs->dense_combined_merges = 0;
 		revs->combine_merges = 1;
 	} else if (!strcmp(arg, "--cc")) {
-		revs->diff = 1;
 		set_dense_combined(revs);
 	} else if (!strcmp(arg, "--no-diff-merges")) {
 		suppress(revs);
 	} else if (!strcmp(arg, "--combined-all-paths")) {
-		revs->diff = 1;
 		revs->combined_all_paths = 1;
 	} else if ((argcount = parse_long_opt("diff-merges", argv, &optarg))) {
 		if (!strcmp(optarg, "off")) {
@@ -103,6 +100,7 @@ void diff_merges_setup_revs(struct rev_info *revs)
 	if (revs->combined_all_paths && !revs->combine_merges)
 		die("--combined-all-paths makes no sense without -c or --cc");
 	if (revs->combine_merges) {
+		revs->diff = 1;
 		/* Turn --cc/-c into -p --cc/-c when -p was not given */
 		if (!revs->diffopt.output_format)
 			revs->diffopt.output_format = DIFF_FORMAT_PATCH;
Signature · 1 line
2.25.1
#210 lore raw

PATCH v3 15/32 t4013: support test_expect_failure through ':failure' magic

In reply to Sergey Organov

Add support to be able to specify expected failure, through :failure magic, like this:

:failure cmd args

---
 t/t4013-diff-various.sh | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
t/t4013-diff-various.sh +6 -1
index 5c7b0122b4f1..935d10ac0572 100755
@@ -174,6 +174,7 @@ process_diffs () {
 V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g')
 while read magic cmd
 do
+	status=success
 	case "$magic" in
 	'' | '#'*)
 		continue ;;
@@ -182,6 +183,10 @@ do
 		label="$magic-$cmd"
 		case "$magic" in
 		noellipses) ;;
+		failure)
+			status=failure
+			magic=
+			label="$cmd" ;;
 		*)
 			BUG "unknown magic $magic" ;;
 		esac ;;
@@ -194,7 +199,7 @@ do
 	expect="$TEST_DIRECTORY/t4013/diff.$test"
 	actual="$pfx-diff.$test"
 
-	test_expect_success "git $cmd # magic is ${magic:-(not used)}" '
+	test_expect_$status "git $cmd # magic is ${magic:-(not used)}" '
 		{
 			echo "$ git $cmd"
 			case "$magic" in
Signature · 1 line
2.25.1
#211 lore raw

PATCH v3 16/32 t4013: add tests for -m failing to override -c/--cc

In reply to Sergey Organov

Logically, -m, -c, --cc specify 3 different formats for representing merge commits, yet -m doesn't in fact override -c or --cc, that makes no sense.

Add 2 expected to fail tests that demonstrate the problem.

---
 t/t4013-diff-various.sh            |   2 +
 t/t4013/diff.log_--cc_-m_-p_master | 200 +++++++++++++++++++++++++++++
 t/t4013/diff.log_-c_-m_-p_master   | 200 +++++++++++++++++++++++++++++
 3 files changed, 402 insertions(+)
 create mode 100644 t/t4013/diff.log_--cc_-m_-p_master
 create mode 100644 t/t4013/diff.log_-c_-m_-p_master
t/t4013-diff-various.sh +2 -0
index 935d10ac0572..64d9fce44614 100755
@@ -329,6 +329,8 @@ log --first-parent --diff-merges=off -p master
 log -p --first-parent master
 log -m -p --first-parent master
 log -m -p master
+:failure log --cc -m -p master
+:failure log -c -m -p master
 log -SF master
 log -S F master
 log -SF -p master
t/t4013/diff.log_--cc_-m_-p_master new file +200 -0

200 lines not on this page · raw message

t/t4013/diff.log_-c_-m_-p_master new file +200 -0

200 lines not on this page · raw message

Signature · 1 line
2.25.1
#212 lore raw

PATCH v3 17/32 diff-merges: fix -m to properly override -c/--cc

In reply to Sergey Organov

Logically, -m, -c, --cc specify 3 different formats for representing merge commits, yet -m doesn't in fact override -c or --cc, that makes no sense.

Fix -m to properly override -c/--cc, and change the tests accordingly.

---
 diff-merges.c           | 1 +
 t/t4013-diff-various.sh | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
diff-merges.c +1 -0
index 225edd293b43..047bf81e6777 100644
@@ -33,6 +33,7 @@ int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
 	const char *arg = argv[0];
 
 	if (!strcmp(arg, "-m")) {
+		suppress(revs);
 		/*
 		 * To "diff-index", "-m" means "match missing", and to the "log"
 		 * family of commands, it means "show full diff for merges". Set
t/t4013-diff-various.sh +2 -2
index 64d9fce44614..8d8178a8a616 100755
@@ -329,8 +329,8 @@ log --first-parent --diff-merges=off -p master
 log -p --first-parent master
 log -m -p --first-parent master
 log -m -p master
-:failure log --cc -m -p master
-:failure log -c -m -p master
+log --cc -m -p master
+log -c -m -p master
 log -SF master
 log -S F master
 log -SF -p master
Signature · 1 line
2.25.1
#213 lore raw

PATCH v3 18/32 diff-merges: split 'ignore_merges' field

In reply to Sergey Organov

'ignore_merges' was 3-way field that served two distinct purposes that we now assign to 2 new independent flags: 'separate_merges', and 'explicit_diff_merges'.

'separate_merges' tells that we need to output diff format containing separate diff for every parent (as opposed to 'combine_merges').

'explicit_diff_merges' tells that at least one of diff-merges options has been explicitly specified on the command line, so no defaults should apply.

---
 diff-merges.c | 31 +++++++++++++------------------
 log-tree.c    | 15 ++++++++-------
 revision.h    |  3 ++-
 3 files changed, 23 insertions(+), 26 deletions(-)
diff-merges.c +13 -18
index 047bf81e6777..eff54cca8287 100644
@@ -4,7 +4,7 @@
 
 static void suppress(struct rev_info *revs)
 {
-	revs->ignore_merges = 1;
+	revs->separate_merges = 0;
 	revs->first_parent_merges = 0;
 	revs->combine_merges = 0;
 	revs->dense_combined_merges = 0;
@@ -23,7 +23,6 @@ static void set_dense_combined(struct rev_info *revs)
 
 void diff_merges_init_revs(struct rev_info *revs)
 {
-	revs->ignore_merges = -1;
 }
 
 int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
@@ -39,7 +38,7 @@ int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
 		 * family of commands, it means "show full diff for merges". Set
 		 * both fields appropriately.
 		 */
-		revs->ignore_merges = 0;
+		revs->separate_merges = 1;
 		revs->match_missing = 1;
 	} else if (!strcmp(arg, "-c")) {
 		revs->dense_combined_merges = 0;
@@ -57,8 +56,9 @@ int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
 			die(_("unknown value for --diff-merges: %s"), optarg);
 		}
 	} else
-		argcount = 0;
+		return 0;
 
+	revs->explicit_diff_merges = 1;
 	return argcount;
 }
 
@@ -69,21 +69,16 @@ void diff_merges_suppress(struct rev_info *revs)
 
 void diff_merges_default_to_first_parent(struct rev_info *revs)
 {
-	if (revs->ignore_merges < 0)		/* No -m */
-		revs->ignore_merges = 0;
-	if (!revs->combine_merges)		/* No -c/--cc" */
+	if (!revs->explicit_diff_merges)
+		revs->separate_merges = 1;
+	if (revs->separate_merges)
 		revs->first_parent_merges = 1;
 }
 
 void diff_merges_default_to_dense_combined(struct rev_info *revs)
 {
-	if (revs->ignore_merges < 0) {		/* No -m */
-		revs->ignore_merges = 0;
-		if (!revs->combine_merges) {	/* No -c/--cc" */
-			revs->combine_merges = 1;
-			revs->dense_combined_merges = 1;
-		}
-	}
+	if (!revs->explicit_diff_merges)
+		set_dense_combined(revs);
 }
 
 void diff_merges_set_dense_combined_if_unset(struct rev_info *revs)
@@ -94,10 +89,10 @@ void diff_merges_set_dense_combined_if_unset(struct rev_info *revs)
 
 void diff_merges_setup_revs(struct rev_info *revs)
 {
-	if (revs->combine_merges && revs->ignore_merges < 0)
-		revs->ignore_merges = 0;
-	if (revs->ignore_merges < 0)
-		revs->ignore_merges = 1;
+	if (revs->combine_merges == 0)
+		revs->dense_combined_merges = 0;
+	if (revs->separate_merges == 0)
+		revs->first_parent_merges = 0;
 	if (revs->combined_all_paths && !revs->combine_merges)
 		die("--combined-all-paths makes no sense without -c or --cc");
 	if (revs->combine_merges) {
log-tree.c +8 -7
index 3fdc0fc64bfb..f9385b1dae6f 100644
@@ -918,14 +918,15 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
 
 	/* More than one parent? */
 	if (parents->next) {
-		if (opt->ignore_merges)
-			return 0;
-		else if (opt->combine_merges)
+		if (opt->combine_merges)
 			return do_diff_combined(opt, commit);
-		else if (!opt->first_parent_merges) {
-			/* If we show multiple diffs, show the parent info */
-			log->parent = parents->item;
-		}
+		if (opt->separate_merges) {
+			if (!opt->first_parent_merges) {
+				/* Show parent info for multiple diffs */
+				log->parent = parents->item;
+			}
+		} else
+			return 0;
 	}
 
 	showed_log = 0;
revision.h +2 -1
index ba2aef79215e..fcc532c873d1 100644
@@ -191,12 +191,13 @@ struct rev_info {
 			match_missing:1,
 			no_commit_id:1,
 			verbose_header:1,
+			explicit_diff_merges: 1,
+			separate_merges: 1,
 			combine_merges:1,
 			combined_all_paths:1,
 			dense_combined_merges:1,
 			first_parent_merges:1,
 			always_show_header:1;
-	int             ignore_merges:2;
 
 	/* Format info */
 	int		show_notes;
Signature · 1 line
2.25.1
#214 lore raw

PATCH v3 19/32 diff-merges: group diff-merge flags next to each other inside 'rev_info'

In reply to Sergey Organov

The relevant flags were somewhat scattered over definition of 'struct rev_info'. Rearrange them to group them together.

---
 revision.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
revision.h +3 -2
index fcc532c873d1..dcfa14454a55 100644
@@ -191,13 +191,14 @@ struct rev_info {
 			match_missing:1,
 			no_commit_id:1,
 			verbose_header:1,
+			always_show_header:1,
+			/* Diff-merge flags */
 			explicit_diff_merges: 1,
 			separate_merges: 1,
 			combine_merges:1,
 			combined_all_paths:1,
 			dense_combined_merges:1,
-			first_parent_merges:1,
-			always_show_header:1;
+			first_parent_merges:1;
 
 	/* Format info */
 	int		show_notes;
Signature · 1 line
2.25.1
#215 lore raw

PATCH v3 20/32 diff-merges: get rid of now empty diff_merges_init_revs()

In reply to Sergey Organov

After getting rid of 'ignore_merges' field, the diff_merges_init_revs() function became empty. Get rid of it.

---
 diff-merges.c | 4 ----
 diff-merges.h | 2 --
 revision.c    | 1 -
 3 files changed, 7 deletions(-)
diff-merges.c +0 -4
index eff54cca8287..34d7ed7c70b7 100644
@@ -21,10 +21,6 @@ static void set_dense_combined(struct rev_info *revs)
  * Public functions. They are in the order they are called.
  */
 
-void diff_merges_init_revs(struct rev_info *revs)
-{
-}
-
 int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
 {
 	int argcount = 1;
diff-merges.h +0 -2
index f92de137d3a0..659467c99a4f 100644
@@ -9,8 +9,6 @@
 
 struct rev_info;
 
-void diff_merges_init_revs(struct rev_info *revs);
-
 int diff_merges_parse_opts(struct rev_info *revs, const char **argv);
 
 void diff_merges_suppress(struct rev_info *revs);
revision.c +0 -1
index 5a0e3d6ad542..46645ca0b6df 100644
@@ -1814,7 +1814,6 @@ void repo_init_revisions(struct repository *r,
 
 	revs->repo = r;
 	revs->abbrev = DEFAULT_ABBREV;
-	diff_merges_init_revs(revs);
 	revs->simplify_history = 1;
 	revs->pruning.repo = r;
 	revs->pruning.flags.recursive = 1;
Signature · 1 line
2.25.1
#216 lore raw

PATCH v3 21/32 diff-merges: refactor opt settings into separate functions

In reply to Sergey Organov

To prepare introduction of new options some of which will be synonyms to existing options, let every option handling code just call corresponding function.

---
 diff-merges.c | 63 +++++++++++++++++++++++++++++++++------------------
 1 file changed, 41 insertions(+), 22 deletions(-)
diff-merges.c +41 -22
index 34d7ed7c70b7..b8fd92adcf16 100644
@@ -10,12 +10,43 @@ static void suppress(struct rev_info *revs)
 	revs->dense_combined_merges = 0;
 }
 
+static void set_separate(struct rev_info *revs)
+{
+	suppress(revs);
+	revs->separate_merges = 1;
+}
+
+static void set_m(struct rev_info *revs)
+{
+	/*
+	 * To "diff-index", "-m" means "match missing", and to the "log"
+	 * family of commands, it means "show full diff for merges". Set
+	 * both fields appropriately.
+	 */
+	set_separate(revs);
+	revs->match_missing = 1;
+}
+
+static void set_combined(struct rev_info *revs)
+{
+	revs->combine_merges = 1;
+	revs->dense_combined_merges = 0;
+}
+
 static void set_dense_combined(struct rev_info *revs)
 {
 	revs->combine_merges = 1;
 	revs->dense_combined_merges = 1;
 }
 
+static void set_diff_merges(struct rev_info *revs, const char *optarg)
+{
+	if (!strcmp(optarg, "off")) {
+		suppress(revs);
+	} else {
+		die(_("unknown value for --diff-merges: %s"), optarg);
+	}
+}
 
 /*
  * Public functions. They are in the order they are called.
@@ -27,31 +58,19 @@ int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
 	const char *optarg;
 	const char *arg = argv[0];
 
-	if (!strcmp(arg, "-m")) {
-		suppress(revs);
-		/*
-		 * To "diff-index", "-m" means "match missing", and to the "log"
-		 * family of commands, it means "show full diff for merges". Set
-		 * both fields appropriately.
-		 */
-		revs->separate_merges = 1;
-		revs->match_missing = 1;
-	} else if (!strcmp(arg, "-c")) {
-		revs->dense_combined_merges = 0;
-		revs->combine_merges = 1;
-	} else if (!strcmp(arg, "--cc")) {
+	if (!strcmp(arg, "-m"))
+		set_m(revs);
+	else if (!strcmp(arg, "-c"))
+		set_combined(revs);
+	else if (!strcmp(arg, "--cc"))
 		set_dense_combined(revs);
-	} else if (!strcmp(arg, "--no-diff-merges")) {
+	else if (!strcmp(arg, "--no-diff-merges"))
 		suppress(revs);
-	} else if (!strcmp(arg, "--combined-all-paths")) {
+	else if (!strcmp(arg, "--combined-all-paths"))
 		revs->combined_all_paths = 1;
-	} else if ((argcount = parse_long_opt("diff-merges", argv, &optarg))) {
-		if (!strcmp(optarg, "off")) {
-			suppress(revs);
-		} else {
-			die(_("unknown value for --diff-merges: %s"), optarg);
-		}
-	} else
+	else if ((argcount = parse_long_opt("diff-merges", argv, &optarg)))
+		set_diff_merges(revs, optarg);
+	else
 		return 0;
 
 	revs->explicit_diff_merges = 1;
Signature · 1 line
2.25.1
#217 lore raw

PATCH v3 22/32 diff-merges: make -m/-c/--cc explicitly mutually exclusive

In reply to Sergey Organov

-c/--cc got precedence over -m only because of external logic where corresponding flags are checked before that for -m. This is too error-prone, so add code that explicitly makes these 3 options mutually exclusive, so that the last option specified on the command-line gets precedence.

---
 diff-merges.c | 3 +++
 1 file changed, 3 insertions(+)
diff-merges.c +3 -0
index b8fd92adcf16..e3c0190ebd95 100644
@@ -8,6 +8,7 @@ static void suppress(struct rev_info *revs)
 	revs->first_parent_merges = 0;
 	revs->combine_merges = 0;
 	revs->dense_combined_merges = 0;
+	revs->combined_all_paths = 0;
 }
 
 static void set_separate(struct rev_info *revs)
@@ -29,12 +30,14 @@ static void set_m(struct rev_info *revs)
 
 static void set_combined(struct rev_info *revs)
 {
+	suppress(revs);
 	revs->combine_merges = 1;
 	revs->dense_combined_merges = 0;
 }
 
 static void set_dense_combined(struct rev_info *revs)
 {
+	suppress(revs);
 	revs->combine_merges = 1;
 	revs->dense_combined_merges = 1;
 }
Signature · 1 line
2.25.1
#218 lore raw

PATCH v3 23/32 diff-merges: implement new values for --diff-merges

In reply to Sergey Organov

We first implement new options as exact synonyms for their original counterparts, to get all the infrastructure right, and keep functional improvements for later commits.

The following values are implemented:

--diff-merges= old equivalent

first|first-parent    = --first-parent (only format implications)
sep|separate          = -m
comb|combined         = -c

dense| dense-combined = --cc

---
 diff-merges.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
diff-merges.c +16 -3
index e3c0190ebd95..4d22da179577 100644
@@ -17,6 +17,12 @@ static void set_separate(struct rev_info *revs)
 	revs->separate_merges = 1;
 }
 
+static void set_first_parent(struct rev_info *revs)
+{
+	set_separate(revs);
+	revs->first_parent_merges = 1;
+}
+
 static void set_m(struct rev_info *revs)
 {
 	/*
@@ -44,11 +50,18 @@ static void set_dense_combined(struct rev_info *revs)
 
 static void set_diff_merges(struct rev_info *revs, const char *optarg)
 {
-	if (!strcmp(optarg, "off")) {
+	if (!strcmp(optarg, "off") || !strcmp(optarg, "none"))
 		suppress(revs);
-	} else {
+	else if (!strcmp(optarg, "first-parent"))
+		set_first_parent(revs);
+	else if (!strcmp(optarg, "separate"))
+		set_separate(revs);
+	else if (!strcmp(optarg, "combined"))
+		set_combined(revs);
+	else if (!strcmp(optarg, "dense-combined"))
+		set_dense_combined(revs);
+	else
 		die(_("unknown value for --diff-merges: %s"), optarg);
-	}
 }
 
 /*
Signature · 1 line
2.25.1
#219 lore raw

PATCH v3 24/32 diff-merges: do not imply -p for new options

In reply to Sergey Organov

Add 'combined_imply_patch' field and set it only for old --cc/-c options, then imply -p if this flag is set instead of implying -p whenever 'combined_merge' flag is set.

We don't want new --diff-merge options to imply -p, to make it possible to enable output of diffs for merges independently from non-merge commits. At the same time we want to preserve behavior of old --c/-c/-m options and their interactions with --first-parent, to stay backward-compatible.

This patch is first step in this direction: it separates old "--cc/-c imply -p" logic from the rest of the options.

---
 diff-merges.c | 20 ++++++++++++--------
 revision.h    |  1 +
 2 files changed, 13 insertions(+), 8 deletions(-)
diff-merges.c +12 -8
index 4d22da179577..6d48ac5ab93d 100644
@@ -9,6 +9,7 @@ static void suppress(struct rev_info *revs)
 	revs->combine_merges = 0;
 	revs->dense_combined_merges = 0;
 	revs->combined_all_paths = 0;
+	revs->combined_imply_patch = 0;
 }
 
 static void set_separate(struct rev_info *revs)
@@ -74,19 +75,21 @@ int diff_merges_parse_opts(struct rev_info *revs, const char **argv)
 	const char *optarg;
 	const char *arg = argv[0];
 
-	if (!strcmp(arg, "-m"))
+	if (!strcmp(arg, "-m")) {
 		set_m(revs);
-	else if (!strcmp(arg, "-c"))
+	} else if (!strcmp(arg, "-c")) {
 		set_combined(revs);
-	else if (!strcmp(arg, "--cc"))
+		revs->combined_imply_patch = 1;
+	} else if (!strcmp(arg, "--cc")) {
 		set_dense_combined(revs);
-	else if (!strcmp(arg, "--no-diff-merges"))
+		revs->combined_imply_patch = 1;
+	} else if (!strcmp(arg, "--no-diff-merges")) {
 		suppress(revs);
-	else if (!strcmp(arg, "--combined-all-paths"))
+	} else if (!strcmp(arg, "--combined-all-paths")) {
 		revs->combined_all_paths = 1;
-	else if ((argcount = parse_long_opt("diff-merges", argv, &optarg)))
+	} else if ((argcount = parse_long_opt("diff-merges", argv, &optarg))) {
 		set_diff_merges(revs, optarg);
-	else
+	} else
 		return 0;
 
 	revs->explicit_diff_merges = 1;
@@ -126,8 +129,9 @@ void diff_merges_setup_revs(struct rev_info *revs)
 		revs->first_parent_merges = 0;
 	if (revs->combined_all_paths && !revs->combine_merges)
 		die("--combined-all-paths makes no sense without -c or --cc");
-	if (revs->combine_merges) {
+	if (revs->combine_merges)
 		revs->diff = 1;
+	if (revs->combined_imply_patch) {
 		/* Turn --cc/-c into -p --cc/-c when -p was not given */
 		if (!revs->diffopt.output_format)
 			revs->diffopt.output_format = DIFF_FORMAT_PATCH;
revision.h +1 -0
index dcfa14454a55..bfbae526ad6e 100644
@@ -197,6 +197,7 @@ struct rev_info {
 			separate_merges: 1,
 			combine_merges:1,
 			combined_all_paths:1,
+			combined_imply_patch:1,
 			dense_combined_merges:1,
 			first_parent_merges:1;
 
Signature · 1 line
2.25.1
#220 lore raw

PATCH v3 25/32 diff-merges: let new options enable diff without -p

In reply to Sergey Organov

New options don't have any visible effect unless -p is either given or implied, as unlike -c/-cc we don't imply -p with --diff-merges. To fix this, this patch adds new functionality by letting new options enable output of diffs for merge commits only.

Add 'merges_need_diff' field and set it whenever diff output for merges is enabled by any of the new options.

Extend diff output logic accordingly, to output diffs for merges when 'merges_need_diff' is set even when no -p has been provided.

---
 diff-merges.c | 17 ++++++++++++-----
 log-tree.c    | 13 +++++++++----
 revision.h    |  1 +
 3 files changed, 22 insertions(+), 9 deletions(-)
diff-merges.c +12 -5
index 6d48ac5ab93d..ee91ed0db409 100644
@@ -10,6 +10,7 @@ static void suppress(struct rev_info *revs)
 	revs->dense_combined_merges = 0;
 	revs->combined_all_paths = 0;
 	revs->combined_imply_patch = 0;
+	revs->merges_need_diff = 0;
 }
 
 static void set_separate(struct rev_info *revs)
@@ -51,9 +52,13 @@ static void set_dense_combined(struct rev_info *revs)
 
 static void set_diff_merges(struct rev_info *revs, const char *optarg)
 {
-	if (!strcmp(optarg, "off") || !strcmp(optarg, "none"))
+	if (!strcmp(optarg, "off") || !strcmp(optarg, "none")) {
 		suppress(revs);
-	else if (!strcmp(optarg, "first-parent"))
+		/* Return early to leave revs->merges_need_diff unset */
+		return;
+	}
+
+	if (!strcmp(optarg, "first-parent"))
 		set_first_parent(revs);
 	else if (!strcmp(optarg, "separate"))
 		set_separate(revs);
@@ -63,6 +68,9 @@ static void set_diff_merges(struct rev_info *revs, const char *optarg)
 		set_dense_combined(revs);
 	else
 		die(_("unknown value for --diff-merges: %s"), optarg);
+
+	/* The flag is cleared by set_xxx() functions, so don't move this up */
+	revs->merges_need_diff = 1;
 }
 
 /*
@@ -129,10 +137,9 @@ void diff_merges_setup_revs(struct rev_info *revs)
 		revs->first_parent_merges = 0;
 	if (revs->combined_all_paths && !revs->combine_merges)
 		die("--combined-all-paths makes no sense without -c or --cc");
-	if (revs->combine_merges)
+	if (revs->combined_imply_patch)
 		revs->diff = 1;
-	if (revs->combined_imply_patch) {
-		/* Turn --cc/-c into -p --cc/-c when -p was not given */
+	if (revs->combined_imply_patch || revs->merges_need_diff) {
 		if (!revs->diffopt.output_format)
 			revs->diffopt.output_format = DIFF_FORMAT_PATCH;
 	}
log-tree.c +9 -4
index f9385b1dae6f..9f50a81e537e 100644
@@ -899,15 +899,21 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
 	int showed_log;
 	struct commit_list *parents;
 	struct object_id *oid;
+	int is_merge;
+	int all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;
 
-	if (!opt->diff && !opt->diffopt.flags.exit_with_status)
+	if (!all_need_diff && !opt->merges_need_diff)
 		return 0;
 
 	parse_commit_or_die(commit);
 	oid = get_commit_tree_oid(commit);
 
-	/* Root commit? */
 	parents = get_saved_parents(opt, commit);
+	is_merge = parents && parents->next;
+	if (!is_merge && !all_need_diff)
+		return 0;
+
+	/* Root commit? */
 	if (!parents) {
 		if (opt->show_root_diff) {
 			diff_root_tree_oid(oid, "", &opt->diffopt);
@@ -916,8 +922,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
 		return !opt->loginfo;
 	}
 
-	/* More than one parent? */
-	if (parents->next) {
+	if (is_merge) {
 		if (opt->combine_merges)
 			return do_diff_combined(opt, commit);
 		if (opt->separate_merges) {
revision.h +1 -0
index bfbae526ad6e..494d86142454 100644
@@ -194,6 +194,7 @@ struct rev_info {
 			always_show_header:1,
 			/* Diff-merge flags */
 			explicit_diff_merges: 1,
+			merges_need_diff: 1,
 			separate_merges: 1,
 			combine_merges:1,
 			combined_all_paths:1,
Signature · 1 line
2.25.1
#221 lore raw

RE: [PATCH v3 25/32] diff-merges: let new options enable diff without -p

Quoted 18 lines · Sergey Organov
log-tree.c +3 -1
index f9385b1dae6f..9f50a81e537e 100644
@@ -899,15 +899,21 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
 	int showed_log;
 	struct commit_list *parents;
 	struct object_id *oid;
+	int is_merge;
+	int all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;
 
-	if (!opt->diff && !opt->diffopt.flags.exit_with_status)
+	if (!all_need_diff && !opt->merges_need_diff)
 		return 0;
 
 	parse_commit_or_die(commit);
 	oid = get_commit_tree_oid(commit);
 

log-tree.c static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log · line 919

Quoted 10 lines
log-tree.c +5 -1
-	/* Root commit? */
 	parents = get_saved_parents(opt, commit);
+	is_merge = parents && parents->next;
+	if (!is_merge && !all_need_diff)
+		return 0;
+
+	/* Root commit? */
 	if (!parents) {
 		if (opt->show_root_diff) {
 			diff_root_tree_oid(oid, "", &opt->diffopt);

FWIW this logic does make sense to me.

Signature · 1 line
Felipe Contreras
#222 lore raw

Re: [PATCH v3 25/32] diff-merges: let new options enable diff without -p

Quoted 19 lines · Felipe Contreras
Quoted 18 lines · Sergey Organov
log-tree.c +3 -1
index f9385b1dae6f..9f50a81e537e 100644
@@ -899,15 +899,21 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
 	int showed_log;
 	struct commit_list *parents;
 	struct object_id *oid;
+	int is_merge;
+	int all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;
 
-	if (!opt->diff && !opt->diffopt.flags.exit_with_status)
+	if (!all_need_diff && !opt->merges_need_diff)
 		return 0;
 
 	parse_commit_or_die(commit);
 	oid = get_commit_tree_oid(commit);
 
Quoted 12 lines

log-tree.c static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log · line 919

Quoted 10 lines
log-tree.c +5 -1
-	/* Root commit? */
 	parents = get_saved_parents(opt, commit);
+	is_merge = parents && parents->next;
+	if (!is_merge && !all_need_diff)
+		return 0;
+
+	/* Root commit? */
 	if (!parents) {
 		if (opt->show_root_diff) {
 			diff_root_tree_oid(oid, "", &opt->diffopt);

FWIW this logic does make sense to me.

Thanks for reviewing!

-- Sergey

#223 lore raw

PATCH v3 26/32 diff-merges: add old mnemonic counterparts to --diff-merges

In reply to Sergey Organov

This adds --diff-merges={m|c|cc} values that match mnemonics of old options, for those who are used to them.

Note that, say, --diff-meres=cc behaves differently than --cc, as the latter implies -p and therefore enables diffs for all the commits, while the former enables output of diffs for merge commits only.

---
 diff-merges.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff-merges.c +3 -3
index ee91ed0db409..011bfff1f135 100644
@@ -60,11 +60,11 @@ static void set_diff_merges(struct rev_info *revs, const char *optarg)
 
 	if (!strcmp(optarg, "first-parent"))
 		set_first_parent(revs);
-	else if (!strcmp(optarg, "separate"))
+	else if (!strcmp(optarg, "m") || !strcmp(optarg, "separate"))
 		set_separate(revs);
-	else if (!strcmp(optarg, "combined"))
+	else if (!strcmp(optarg, "c") || !strcmp(optarg, "combined"))
 		set_combined(revs);
-	else if (!strcmp(optarg, "dense-combined"))
+	else if (!strcmp(optarg, "cc") || !strcmp(optarg, "dense-combined"))
 		set_dense_combined(revs);
 	else
 		die(_("unknown value for --diff-merges: %s"), optarg);
Signature · 1 line
2.25.1
#224 lore raw

PATCH v3 27/32 diff-merges: add '--diff-merges=1' as synonym for 'first-parent'

In reply to Sergey Organov

As we now have --diff-merges={m|c|cc}, add --diff-merges=1 as synonym for --diff-merges=first-parent, to have shorter mnemonics for it as well.

---
 diff-merges.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff-merges.c +1 -1
index 011bfff1f135..146bb50316a6 100644
@@ -58,7 +58,7 @@ static void set_diff_merges(struct rev_info *revs, const char *optarg)
 		return;
 	}
 
-	if (!strcmp(optarg, "first-parent"))
+	if (!strcmp(optarg, "1") || !strcmp(optarg, "first-parent"))
 		set_first_parent(revs);
 	else if (!strcmp(optarg, "m") || !strcmp(optarg, "separate"))
 		set_separate(revs);
Signature · 1 line
2.25.1
#225 lore raw

PATCH v3 28/32 doc/git-log: describe new --diff-merges options

In reply to Sergey Organov

Describe all the new --diff-merges options in the git-log.txt and adopt description of originals accordingly.

---
 Documentation/git-log.txt | 83 +++++++++++++++++++++++----------------
 1 file changed, 50 insertions(+), 33 deletions(-)
Documentation/git-log.txt +50 -33
index 2b8ac5ff882a..ff83dff14dd6 100644
@@ -120,45 +120,62 @@ DIFF FORMATTING
 By default, `git log` does not generate any diff output. The options
 below can be used to show the changes made by each commit.
 
-Note that unless one of `-c`, `--cc`, or `-m` is given, merge commits
-will never show a diff, even if a diff format like `--patch` is
-selected, nor will they match search options like `-S`. The exception is
-when `--first-parent` is in use, in which merges are treated like normal
-single-parent commits (this can be overridden by providing a
-combined-diff option or with `--no-diff-merges`).
+Note that unless one of `--diff-merges` variants (including short
+`-m`, `-c`, and `--cc` options) is explicitly given, merge commits
+will not show a diff, even if a diff format like `--patch` is
+selected, nor will they match search options like `-S`. The exception
+is when `--first-parent` is in use, in which case `first-parent` is
+the default format.
 
--c::
-	With this option, diff output for a merge commit
-	shows the differences from each of the parents to the merge result
-	simultaneously instead of showing pairwise diff between a parent
-	and the result one at a time. Furthermore, it lists only files
-	which were modified from all parents.
-
---cc::
-	This flag implies the `-c` option and further compresses the
-	patch output by omitting uninteresting hunks whose contents in
-	the parents have only two variants and the merge result picks
-	one of them without modification.
+--diff-merges=(off|none|first-parent|1|separate|m|combined|c|dense-combined|cc)::
+--no-diff-merges::
+	Specify diff format to be used for merge commits. Default is
+	`off` unless `--first-parent` is in use, in which case
+	`first-parent` is the default.
++
+--diff-merges=(off|none):::
+--no-diff-merges:::
+	Disable output of diffs for merge commits. Useful to override
+	implied value.
++
+--diff-merges=first-parent:::
+--diff-merges=1:::
+	This option makes merge commits show the full diff with
+	respect to the first parent only.
++
+--diff-merges=separate:::
+--diff-merges=m:::
+-m:::
+	This makes merge commits show the full diff with respect to
+	each of the parents. Separate log entry and diff is generated
+	for each parent. `-m` doesn't produce any output without `-p`.
++
+--diff-merges=combined:::
+--diff-merges=c:::
+-c:::
+	With this option, diff output for a merge commit shows the
+	differences from each of the parents to the merge result
+	simultaneously instead of showing pairwise diff between a
+	parent and the result one at a time. Furthermore, it lists
+	only files which were modified from all parents. `-c` implies
+	`-p`.
++
+--diff-merges=dense-combined:::
+--diff-merges=cc:::
+--cc:::
+	With this option the output produced by
+	`--diff-merges=combined` is further compressed by omitting
+	uninteresting hunks whose contents in the parents have only
+	two variants and the merge result picks one of them without
+	modification.  `--cc` implies `-p`.
 
 --combined-all-paths::
 	This flag causes combined diffs (used for merge commits) to
 	list the name of the file from all parents.  It thus only has
-	effect when -c or --cc are specified, and is likely only
-	useful if filename changes are detected (i.e. when either
-	rename or copy detection have been requested).
+	effect when `--diff-merges=[dense-]combined` is in use, and
+	is likely only useful if filename changes are detected (i.e.
+	when either rename or copy detection have been requested).
 
--m::
-	This flag makes the merge commits show the full diff like
-	regular commits; for each merge parent, a separate log entry
-	and diff is generated. An exception is that only diff against
-	the first parent is shown when `--first-parent` option is given;
-	in that case, the output represents the changes the merge
-	brought _into_ the then-current branch.
-
---diff-merges=off::
---no-diff-merges::
-	Disable output of diffs for merge commits (default). Useful to
-	override `-m`, `-c`, or `--cc`.
 
 :git-log: 1
 include::diff-options.txt[]
Signature · 1 line
2.25.1
#226 lore raw

PATCH v3 29/32 doc/diff-generate-patch: mention new --diff-merges option

In reply to Sergey Organov

Mention --diff-merges instead of -m in a note to merge formats to aid discoverability, as -m is now described among --diff-merges options anyway.

---
 Documentation/diff-generate-patch.txt | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/diff-generate-patch.txt +3 -3
index b10ff4caa6c5..2db8eacc3ec7 100644
@@ -81,9 +81,9 @@ Combined diff format
 Any diff-generating command can take the `-c` or `--cc` option to
 produce a 'combined diff' when showing a merge. This is the default
 format when showing merges with linkgit:git-diff[1] or
-linkgit:git-show[1]. Note also that you can give the `-m` option to any
-of these commands to force generation of diffs with individual parents
-of a merge.
+linkgit:git-show[1]. Note also that you can give suitable
+`--diff-merges` option to any of these commands to force generation of
+diffs in specific format.
 
 A "combined diff" format looks like this:
 
Signature · 1 line
2.25.1
#227 lore raw

PATCH v3 30/32 doc/rev-list-options: document --first-parent changes merges format

In reply to Sergey Organov

After introduction of the --diff-merges=first-parent, the --first-parent sets the default format for merges to the same value as this new option. Document this behavior and add corresponding reference to --diff-merges.

---
 Documentation/rev-list-options.txt | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/rev-list-options.txt +5 -0
index 002379056a07..96cc89d157d2 100644
@@ -130,6 +130,11 @@ parents) and `--max-parents=-1` (negative numbers denote no upper limit).
 	this option allows you to ignore the individual commits
 	brought in to your history by such a merge.
 
+ifdef::git-log[]
+	This option also changes default diff format for merge commits
+	to `first-parent`, see `--diff-merges=first-parent` for details.
+endif::git-log[]
+
 --not::
 	Reverses the meaning of the '{caret}' prefix (or lack thereof)
 	for all following revision specifiers, up to the next `--not`.
Signature · 1 line
2.25.1
#228 lore raw

PATCH v3 31/32 doc/git-show: include --diff-merges description

In reply to Sergey Organov

Move description of --diff-merges option from git-log.txt to diff-options.txt so that it is included in the git-show help.

---
 Documentation/diff-options.txt | 51 ++++++++++++++++++++++++++++++++++
 Documentation/git-log.txt      | 51 +---------------------------------
 Documentation/git-show.txt     |  7 +++--
 3 files changed, 57 insertions(+), 52 deletions(-)
Documentation/diff-options.txt +51 -0
index 573fb9bb71e2..c995e82584f3 100644
@@ -33,6 +33,57 @@ endif::git-diff[]
 	show the patch by default, or to cancel the effect of `--patch`.
 endif::git-format-patch[]
 
+ifdef::git-log[]
+--diff-merges=(off|none|first-parent|1|separate|m|combined|c|dense-combined|cc)::
+--no-diff-merges::
+	Specify diff format to be used for merge commits. Default is
+	{diff-merges-default} unless `--first-parent` is in use, in which case
+	`first-parent` is the default.
++
+--diff-merges=(off|none):::
+--no-diff-merges:::
+	Disable output of diffs for merge commits. Useful to override
+	implied value.
++
+--diff-merges=first-parent:::
+--diff-merges=1:::
+	This option makes merge commits show the full diff with
+	respect to the first parent only.
++
+--diff-merges=separate:::
+--diff-merges=m:::
+-m:::
+	This makes merge commits show the full diff with respect to
+	each of the parents. Separate log entry and diff is generated
+	for each parent. `-m` doesn't produce any output without `-p`.
++
+--diff-merges=combined:::
+--diff-merges=c:::
+-c:::
+	With this option, diff output for a merge commit shows the
+	differences from each of the parents to the merge result
+	simultaneously instead of showing pairwise diff between a
+	parent and the result one at a time. Furthermore, it lists
+	only files which were modified from all parents. `-c` implies
+	`-p`.
++
+--diff-merges=dense-combined:::
+--diff-merges=cc:::
+--cc:::
+	With this option the output produced by
+	`--diff-merges=combined` is further compressed by omitting
+	uninteresting hunks whose contents in the parents have only
+	two variants and the merge result picks one of them without
+	modification.  `--cc` implies `-p`.
+
+--combined-all-paths::
+	This flag causes combined diffs (used for merge commits) to
+	list the name of the file from all parents.  It thus only has
+	effect when `--diff-merges=[dense-]combined` is in use, and
+	is likely only useful if filename changes are detected (i.e.
+	when either rename or copy detection have been requested).
+endif::git-log[]
+
 -U<n>::
 --unified=<n>::
 	Generate diffs with <n> lines of context instead of
Documentation/git-log.txt +1 -50

58 lines not on this page · raw message

Documentation/git-show.txt +5 -2
index fcf528c1b30d..2b1bc7288d5f 100644
@@ -45,10 +45,13 @@ include::pretty-options.txt[]
 include::pretty-formats.txt[]
 
 
-COMMON DIFF OPTIONS
--------------------
+DIFF FORMATTING
+---------------
+The options below can be used to change the way `git show` generates
+diff output.
 
 :git-log: 1
+:diff-merges-default: `dense-combined`
 include::diff-options.txt[]
 
 include::diff-generate-patch.txt[]
Signature · 1 line
2.25.1
#229 lore raw

PATCH v3 32/32 t4013: add tests for --diff-merges=first-parent

In reply to Sergey Organov

This new option provides essential new functionality, changing diff output to first parent only, without changing history traversal mode, so it deserves its own test.

As we do it, add additional test that --diff-merges=first-parent by itself doesn't imply -p and only outputs diffs for merge commits.

---
 t/t4013-diff-various.sh                       |   2 +
 ...diff.log_--diff-merges=first-parent_master |  56 +++++++
 ...f.log_-p_--diff-merges=first-parent_master | 137 ++++++++++++++++++
 3 files changed, 195 insertions(+)
 create mode 100644 t/t4013/diff.log_--diff-merges=first-parent_master
 create mode 100644 t/t4013/diff.log_-p_--diff-merges=first-parent_master
t/t4013-diff-various.sh +2 -0
index 8d8178a8a616..fa82b5a8eed4 100755
@@ -327,6 +327,8 @@ log --no-diff-merges -p --first-parent master
 log --diff-merges=off -p --first-parent master
 log --first-parent --diff-merges=off -p master
 log -p --first-parent master
+log -p --diff-merges=first-parent master
+log --diff-merges=first-parent master
 log -m -p --first-parent master
 log -m -p master
 log --cc -m -p master
t/t4013/diff.log_--diff-merges=first-parent_master new file +56 -0

56 lines not on this page · raw message

t/t4013/diff.log_-p_--diff-merges=first-parent_master new file +137 -0

137 lines not on this page · raw message

Signature · 1 line
2.25.1
#230 lore raw
In reply to Sergey Organov
Quoted 3 lines · Sergey Organov

These patch series implement new set of options governing diff output of merge commits, all under the umbrella of single --diff-merges=<mode> option.

This latest round hasn't seen much review reactions, so I gave it a read-thru with fresh eyes. I didn't spot anything objectionable, so let's start merging it down to 'next'.

Thanks.

#231 lore raw
Quoted 9 lines · Junio C Hamano
Quoted 3 lines · Sergey Organov

These patch series implement new set of options governing diff output of merge commits, all under the umbrella of single --diff-merges=<mode> option.

This latest round hasn't seen much review reactions, so I gave it a read-thru with fresh eyes. I didn't spot anything objectionable, so let's start merging it down to 'next'.

Thanks, Junio!

In fact I'm planning to propose a few further improvements on top of this, and wanted to wait till these patches are settled.

-- Sergey Organov