Re: [PATCH] ref-filter: don't look for objects when outside of a repository
- From
SZEDER Gábor <szeder.dev@gmail.com>
- Date
- Sep 24, 2018, 21:20 UTC
- Message-ID
- <20180924212034.GF27036@localhost>
- In-Reply-To
- <20180924181722.GA25341@sigill.intra.peff.net>
On Mon, Sep 24, 2018 at 02:17:22PM -0400, Jeff King wrote:
> On Sat, Sep 22, 2018 at 04:11:45PM +0200, SZEDER Gábor wrote:
Show 25 quoted lines
> > diff --git a/ref-filter.c b/ref-filter.c
> > index e1bcb4ca8a..3555bc29e7 100644
> > --- a/ref-filter.c
> > +++ b/ref-filter.c
> > @@ -1473,7 +1473,8 @@ static int get_object(struct ref_array_item *ref, int deref, struct object **obj
> > oi->info.sizep = &oi->size;
> > oi->info.typep = &oi->type;
> > }
> > - if (oid_object_info_extended(the_repository, &oi->oid, &oi->info,
> > + if (!have_git_dir() ||
> > + oid_object_info_extended(the_repository, &oi->oid, &oi->info,
> > OBJECT_INFO_LOOKUP_REPLACE))
> > return strbuf_addf_ret(err, -1, _("missing object %s for %s"),
> > oid_to_hex(&oi->oid), ref->refname);
>
> Would we perhaps want to give the user a hint that the object is not
> really missing, but rather that we're not in a repository? E.g.,
> something like:
>
> if (!have_git_dir())
> return strbuf_addf_ret(err, -1, "format specifier requires a repository");
> if (oid_object_info_extended(...))
> return ...;
>
> ?I think it makes sense.
I wanted to preserve the error message, because the description of '--sort=<key>' in 'Documentation/git-ls-remote.txt' explicitly mentions it, and I added the condition at this place because I didn't want to duplicate the construction of the error message.
However, if we go for a more informative error message, then wouldn't it be better to add this condition in populate_value() before it even calls get_object()? Then we could also add the problematic format specifier to the error message (I think, but didn't actually check), just in case someone specified multiple sort keys.