git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
René Scharfe <l.s.r@web.de>
Date
Sep 15, 2022, 14:54 UTC
Message-ID
<73e1e0e2-d6a4-3d1b-4303-f9e8984eaa79@web.de>
In-Reply-To
<ba6eea28-fb3a-b376-2529-351727c02f1a@web.de>

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(-)
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 = '^';
 	}

--
2.37.3
Previous: René ScharfeNext: René Scharfe
Message 7 of 16 in “revision: fix order of revs for ^!”
  1. 0/6 revision: fix order of revs for ^!René Scharfe, Sep 15, 2022
  2. 1/6 revision: use strtol_i() for exclude_parentRené Scharfe, Sep 15, 2022
  3. Chris TorekSep 17, 2022
  4. 2/6 revision: factor out get_commit()René Scharfe, Sep 15, 2022
  5. 3/6 revision: factor out add_parent()René Scharfe, Sep 15, 2022
  6. 4/6 revision: factor out add_parents()René Scharfe, Sep 15, 2022
  7. 5/6 revision: rename add_parents_only() to add_nth_parent()René Scharfe, Sep 15, 2022
  8. 6/6 revision: add parents after child for ^!René Scharfe, Sep 15, 2022
  9. Junio C HamanoSep 15, 2022
  10. René ScharfeSep 16, 2022
  11. Junio C HamanoSep 16, 2022
  12. René ScharfeSep 18, 2022
  13. 0/3 diff: support ^! for mergesRené Scharfe, Oct 1, 2022
  14. 1/3 revision: use strtol_i() for exclude_parentRené Scharfe, Oct 1, 2022
  15. 2/3 revisions.txt: unspecify order of resolved parts of ^!René Scharfe, Oct 1, 2022
  16. 3/3 diff: support ^! for mergesRené Scharfe, Oct 1, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.