[PATCH 2/6] revision: factor out get_commit()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Split out the first half of add_parents_only() to obtain a function that
finds and returns the commit object.  It allows checking the validity of
the child separately from adding its parents.

Signed-off-by: René Scharfe <l.s.r@xxxxxx>
---
 revision.c | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/revision.c b/revision.c
index 0b8d48f94c..4f896b4992 100644
--- a/revision.c
+++ b/revision.c
@@ -1822,35 +1822,46 @@ static void add_alternate_refs_to_pending(struct rev_info *revs,
 	for_each_alternate_ref(add_one_alternate_ref, &data);
 }

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

-	if (*arg == '^') {
-		flags ^= UNINTERESTING | BOTTOM;
+	if (*arg == '^')
 		arg++;
-	}
 	if (get_oid_committish(arg, &oid))
-		return 0;
+		return NULL;
 	while (1) {
 		it = get_reference(revs, arg, &oid, 0);
 		if (!it && revs->ignore_missing)
-			return 0;
+			return NULL;
 		if (it->type != OBJ_TAG)
 			break;
 		if (!((struct tag*)it)->tagged)
-			return 0;
+			return NULL;
 		oidcpy(&oid, &((struct tag*)it)->tagged->oid);
 	}
 	if (it->type != OBJ_COMMIT)
+		return NULL;
+	return (struct commit *)it;
+}
+
+static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
+			    int exclude_parent)
+{
+	struct object *it;
+	struct commit *commit = get_commit(revs, arg_);
+	struct commit_list *parents;
+	int parent_number;
+	const char *arg = arg_;
+
+	if (*arg == '^') {
+		flags ^= UNINTERESTING | BOTTOM;
+		arg++;
+	}
+	if (!commit)
 		return 0;
-	commit = (struct commit *)it;
 	if (exclude_parent &&
 	    exclude_parent > commit_list_count(commit->parents))
 		return 0;
--
2.37.3




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux