From a7b94309406c8f713a061ca8b930179483b12619 Mon Sep 17 00:00:00 2001 From: Sergey Organov Date: Fri, 28 Aug 2020 14:05:25 +0300 Subject: [PATCH 1/2] log_tree_diff: get rid of code duplication for first_parent_only Handle first_parent_only by breaking from generic loop early rather than by duplicating (part of) the loop body. Signed-off-by: Sergey Organov Signed-off-by: Junio C Hamano --- log-tree.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/log-tree.c b/log-tree.c index 55a68d0c61..c01932fa72 100644 --- a/log-tree.c +++ b/log-tree.c @@ -922,21 +922,10 @@ 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) { - /* - * Generate merge log entry only for the first - * parent, showing summary diff of the others - * we merged _in_. - */ - parse_commit_or_die(parents->item); - diff_tree_oid(get_commit_tree_oid(parents->item), - oid, "", &opt->diffopt); - log_tree_diff_flush(opt); - return !opt->loginfo; + else if (!opt->first_parent_only) { + /* If we show multiple diffs, show the parent info */ + log->parent = parents->item; } - - /* If we show individual diffs, show the parent info */ - log->parent = parents->item; } showed_log = 0; @@ -952,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) + if (!parents || opt->first_parent_only) break; log->parent = parents->item; opt->loginfo = log; From 793d37c17ffab46507e14c4547ad2edc9ba9e3fe Mon Sep 17 00:00:00 2001 From: Sergey Organov Date: Fri, 28 Aug 2020 14:05:26 +0300 Subject: [PATCH 2/2] log_tree_diff: get rid of extra check for NULL Get rid of needless check of 'parents' for NULL. The NULL case is already handled right above, and 'parents' is dereferenced without check below anyway. Signed-off-by: Sergey Organov Signed-off-by: Junio C Hamano --- log-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/log-tree.c b/log-tree.c index c01932fa72..8ac285a25a 100644 --- a/log-tree.c +++ b/log-tree.c @@ -917,7 +917,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log } /* More than one parent? */ - if (parents && parents->next) { + if (parents->next) { if (opt->ignore_merges) return 0; else if (opt->combine_merges)