@@ -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;
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@web.de> --- revision.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) -- 2.37.3