git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>,
	Tim Jaacks <tim.jaacks@garz-fricke.com>,
	Chris Torek <chris.torek@gmail.com>
Subject: [PATCH 5/6] revision: rename add_parents_only() to add_nth_parent()
Date: Thu, 15 Sep 2022 16:54:32 +0200	[thread overview]
Message-ID: <73e1e0e2-d6a4-3d1b-4303-f9e8984eaa79@web.de> (raw)
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

  parent reply	other threads:[~2022-09-15 14:55 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-15 14:48 [PATCH 0/6] revision: fix order of revs for ^! René Scharfe
2022-09-15 14:51 ` [PATCH 1/6] revision: use strtol_i() for exclude_parent René Scharfe
2022-09-17  0:59   ` Chris Torek
2022-09-15 14:52 ` [PATCH 2/6] revision: factor out get_commit() René Scharfe
2022-09-15 14:52 ` [PATCH 3/6] revision: factor out add_parent() René Scharfe
2022-09-15 14:53 ` [PATCH 4/6] revision: factor out add_parents() René Scharfe
2022-09-15 14:54 ` René Scharfe [this message]
2022-09-15 14:55 ` [PATCH 6/6] revision: add parents after child for ^! René Scharfe
2022-09-15 17:53   ` Junio C Hamano
2022-09-16  9:02     ` René Scharfe
2022-09-16 15:55       ` Junio C Hamano
2022-09-18  5:36         ` René Scharfe
2022-10-01 10:23 ` [PATCH v3 0/3] diff: support ^! for merges René Scharfe
2022-10-01 10:25   ` [PATCH v3 1/3] revision: use strtol_i() for exclude_parent René Scharfe
2022-10-01 10:26   ` [PATCH v3 2/3] revisions.txt: unspecify order of resolved parts of ^! René Scharfe
2022-10-01 10:28   ` [PATCH v3 3/3] diff: support ^! for merges René Scharfe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=73e1e0e2-d6a4-3d1b-4303-f9e8984eaa79@web.de \
    --to=l.s.r@web.de \
    --cc=chris.torek@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=tim.jaacks@garz-fricke.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).