Re: [PATCH] revision: allow missing promisor objects on CLI
- From
- Jonathan Tan <jonathantanmy@google.com>
- Date
- Dec 30, 2019, 18:38 UTC
- Message-ID
- <20191230183801.28538-1-jonathantanmy@google.com>
- In-Reply-To
- <xmqqlfqxhzvu.fsf@gitster-ct.c.googlers.com>
Show 17 quoted lines
> Jonathan Tan <jonathantanmy@google.com> writes: > > > object = get_reference(revs, arg, &oid, flags ^ local_flags); > > if (!object) > > - return revs->ignore_missing ? 0 : -1; > > + /* > > + * Either this object is missing and ignore_missing is true, or > > + * this object is a (missing) promisor object and > > + * exclude_promisor_objects is true. > > I had to guess and dig where these assertions are coming from; we > should not force future readers of the code to. > > At least this comment must say why these assertions hold. Say > something like "get_reference() yields NULL on only such and such > cases" before concluding with "and in any of these cases, we can > safely ignore it because ...".
OK, will do.
Show 7 quoted lines
> I think the two cases the comment covers are safe for this caller to > silently return 0. Another case get_reference() yields NULL is when > oid_object_info() says it is a commit but it turns out that the > object is found by repo_parse_commit() to be a non-commit, isn't it? > I am not sure if it is safe for this caller to just return 0. There > may be some other "unusual-but-not-fatal" cases where get_reference() > does not hit a die() but returns NULL.
I don't think there is any other case where get_reference() yields NULL, at least where I based my patch (99c33bed56 ("Git 2.25-rc0", 2019-12-25)). Quoting the entire get_reference():
Show 19 quoted lines
> static struct object *get_reference(struct rev_info *revs, const char *name,
> const struct object_id *oid,
> unsigned int flags)
> {
> struct object *object;
>
> /*
> * If the repository has commit graphs, repo_parse_commit() avoids
> * reading the object buffer, so use it whenever possible.
> */
> if (oid_object_info(revs->repo, oid, NULL) == OBJ_COMMIT) {
> struct commit *c = lookup_commit(revs->repo, oid);
> if (!repo_parse_commit(revs->repo, c))
> object = (struct object *) c;
> else
> object = NULL;
> } else {
> object = parse_object(revs->repo, oid);
> }No return statements at all prior to this line.
> if (!object) {
> if (revs->ignore_missing)
> return object;Return NULL (the value of object).
> if (revs->exclude_promisor_objects && is_promisor_object(oid)) > return NULL;
Return NULL.
> die("bad object %s", name);Die (so this function invocation never returns). In conclusion, if object is NULL at this point in time, get_reference() either returns NULL or dies.
> }
Since get_reference() did not return NULL or die, object is non-NULL here.
> object->flags |= flags; > return object;
Nothing has overridden object since, so we're returning non-NULL here.
> }
So I think get_reference() only returns NULL in those two safe cases. (Or did I miss something?)