From ce48a6bbac600732af0cb3411b5ac672ea6a32e6 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Tue, 14 Dec 2010 21:39:28 +0100 Subject: [PATCH] log and friends: --second-parent Introduce an option '--second-parent' to the revision walker which walks the second parent if present, or else the first parent. This is useful for walking a side branch from the merge point downwards. --- builtin/log.c | 2 +- graph.c | 3 +++ log-tree.c | 2 +- revision.c | 7 +++++++ revision.h | 2 +- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/builtin/log.c b/builtin/log.c index 59de484bc2..e1e0847bbd 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -449,7 +449,7 @@ static void show_rev_tweak_rev(struct rev_info *rev, struct setup_revision_opt * /* There was no "-m" on the command line */ rev->ignore_merges = 0; if (!rev->first_parent_only && !rev->combine_merges) { - /* No "--first-parent", "-c", nor "--cc" */ + /* No "--first/second-parent", "-c", nor "--cc" */ rev->combine_merges = 1; rev->dense_combined_merges = 1; } diff --git a/graph.c b/graph.c index b24d04c406..d38ee9b17f 100644 --- a/graph.c +++ b/graph.c @@ -335,6 +335,9 @@ static struct commit_list *first_interesting_parent(struct git_graph *graph) if (!parents) return NULL; + if ((graph->revs->first_parent_only == 2) && parents->next && + graph_is_interesting(graph, parents->next->item)) + return parents->next; /* * If the first parent is interesting, return it */ diff --git a/log-tree.c b/log-tree.c index 92bb2bf48e..010f715b99 100644 --- a/log-tree.c +++ b/log-tree.c @@ -736,7 +736,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log * parent, showing summary diff of the others * we merged _in_. */ - diff_tree_sha1(parents->item->object.sha1, sha1, "", &opt->diffopt); + diff_tree_sha1(((opt->first_parent_only == 2) ? parents->next : parents)->item->object.sha1, sha1, "", &opt->diffopt); log_tree_diff_flush(opt); return !opt->loginfo; } diff --git a/revision.c b/revision.c index 78397d6486..5e863e19c8 100644 --- a/revision.c +++ b/revision.c @@ -593,6 +593,10 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, if (parse_commit(p) < 0) return -1; + /* skip 1st prnt if there is a 2nd one for --second-parent */ + if ((revs->first_parent_only == 2) && (parent->next) && + (parent == commit->parents)) + continue; if (revs->show_source && !p->util) p->util = commit->util; p->object.flags |= left_flag; @@ -600,6 +604,7 @@ static int add_parents_to_list(struct rev_info *revs, struct commit *commit, p->object.flags |= SEEN; commit_list_insert_by_date_cached(p, list, cached_base, cache_ptr); } + /* only use 1 parent for --first/second-parent */ if (revs->first_parent_only) break; } @@ -1359,6 +1364,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg return argcount; } else if (!strcmp(arg, "--first-parent")) { revs->first_parent_only = 1; + } else if (!strcmp(arg, "--second-parent")) { + revs->first_parent_only = 2; } else if (!strcmp(arg, "--ancestry-path")) { revs->ancestry_path = 1; revs->simplify_history = 0; diff --git a/revision.h b/revision.h index 01bd2b7c07..b4174434e2 100644 --- a/revision.h +++ b/revision.h @@ -96,7 +96,7 @@ struct rev_info { cherry_mark:1, bisect:1, ancestry_path:1, - first_parent_only:1; + first_parent_only:2; /* Diff flags */ unsigned int diff:1, -- 2.11.4.GIT