diff mbox series

[5/6] revision: rename add_parents_only() to add_nth_parent()

Message ID 73e1e0e2-d6a4-3d1b-4303-f9e8984eaa79@web.de (mailing list archive)
State New, archived
Headers show
Series revision: fix order of revs for ^! | expand

Commit Message

René Scharfe Sept. 15, 2022, 2:54 p.m. UTC
Move the handling of !exclude_parent to the two callers that pass zero.
This allows checking the validity of the child separately from adding
its parents, which we'll make use of in the next patch.

Rename the function to reflect its changed purpose, now that it
requires exclude_parent to be given and only adds at most one parent.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
Created with --inter-hunk-context=1 for easier review.

 revision.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

--
2.37.3
diff mbox series

Patch

diff --git a/revision.c b/revision.c
index 284393a146..5e756b76aa 100644
--- a/revision.c
+++ b/revision.c
@@ -1868,19 +1868,15 @@  static void add_parents(struct rev_info *revs, struct commit_list *parents,
 		add_parent(revs, &parents->item->object, arg, flags);
 }

-static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
-			    int exclude_parent)
+static int add_nth_parent(struct rev_info *revs, const char *arg_, int flags,
+			  int exclude_parent)
 {
 	struct commit *commit = get_commit(revs, arg_);
 	struct commit_list *parents;
 	int parent_number;

 	if (!commit)
 		return 0;
-	if (!exclude_parent) {
-		add_parents(revs, commit->parents, arg_, flags);
-		return 1;
-	}
 	for (parents = commit->parents, parent_number = 1;
 	     parents;
 	     parents = parents->next, parent_number++) {
@@ -2127,15 +2123,26 @@  static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int fl

 	mark = strstr(arg, "^@");
 	if (mark && !mark[2]) {
+		struct commit *commit;
+
 		*mark = 0;
-		if (add_parents_only(revs, arg, flags, 0))
+		commit = get_commit(revs, arg);
+		if (commit) {
+			add_parents(revs, commit->parents, arg, flags);
 			return 0;
+		}
 		*mark = '^';
 	}
 	mark = strstr(arg, "^!");
 	if (mark && !mark[2]) {
+		struct commit *commit;
+
 		*mark = 0;
-		if (!add_parents_only(revs, arg, flags ^ (UNINTERESTING | BOTTOM), 0))
+		commit = get_commit(revs, arg);
+		if (commit)
+			add_parents(revs, commit->parents, arg,
+				    flags ^ (UNINTERESTING | BOTTOM));
+		else
 			*mark = '^';
 	}
 	mark = strstr(arg, "^-");
@@ -2149,7 +2156,7 @@  static int handle_revision_arg_1(const char *arg_, struct rev_info *revs, int fl
 		}

 		*mark = 0;
-		if (!add_parents_only(revs, arg, flags ^ (UNINTERESTING | BOTTOM), exclude_parent))
+		if (!add_nth_parent(revs, arg, flags ^ (UNINTERESTING | BOTTOM), exclude_parent))
 			*mark = '^';
 	}