From: Jeff King <peff@peff.net>
To: "SZEDER Gábor" <szeder.dev@gmail.com>
Cc: "Junio C Hamano" <gitster@pobox.com>,
git@vger.kernel.org, "H . Merijn Brand" <h.m.brand@xs4all.nl>,
"Harald Nordgren" <haraldnordgren@gmail.com>,
"Olga Telezhnaia" <olyatelezhnaya@gmail.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH] ref-filter: don't look for objects when outside of a repository
Date: Thu, 15 Nov 2018 04:38:44 -0500 [thread overview]
Message-ID: <20181115093844.GA14218@sigill.intra.peff.net> (raw)
In-Reply-To: <20181114122725.18659-1-szeder.dev@gmail.com>
On Wed, Nov 14, 2018 at 01:27:25PM +0100, SZEDER Gábor wrote:
> The command 'git ls-remote --sort=authordate <remote>' segfaults when
> run outside of a repository, ever since the introduction of its
> '--sort' option in 1fb20dfd8e (ls-remote: create '--sort' option,
> 2018-04-09).
>
> While in general the 'git ls-remote' command can be run outside of a
> repository just fine, its '--sort=<key>' option with certain keys does
> require access to the referenced objects. This sorting is implemented
> using the generic ref-filter sorting facility, which already handles
> missing objects gracefully with the appropriate 'missing object
> deadbeef for HEAD' message. However, being generic means that it
> checks replace refs while trying to retrieve an object, and while
> doing so it accesses the 'git_replace_ref_base' variable, which has
> not been initialized and is still a NULL pointer when outside of a
> repository, thus causing the segfault.
>
> Make ref-filter more careful upfront while parsing the format string,
> and make it error out when encountering a format atom requiring object
> access when we are not in a repository. Also add a test to ensure
> that 'git ls-remote --sort' fails gracefully when executed outside of
> a repository.
Thanks for picking up this loose end. I like the general approach here,
but...
> diff --git a/ref-filter.c b/ref-filter.c
> index 0c45ed9d94..a1290659af 100644
> --- a/ref-filter.c
> +++ b/ref-filter.c
> @@ -534,6 +534,10 @@ static int parse_ref_filter_atom(const struct ref_format *format,
> if (ARRAY_SIZE(valid_atom) <= i)
> return strbuf_addf_ret(err, -1, _("unknown field name: %.*s"),
> (int)(ep-atom), atom);
> + if (valid_atom[i].source != SOURCE_NONE && !have_git_dir())
> + return strbuf_addf_ret(err, -1,
> + _("not a git repository, but the field '%.*s' requires access to object data"),
> + (int)(ep-atom), atom);
Is SOURCE_NONE a complete match for what we want?
I see problems in both directions:
- sorting by "objectname" works now, but it's marked with SOURCE_OBJ,
and would be forbidden with your patch. I'm actually not sure if
SOURCE_OBJ is accurate; we shouldn't need to access the object to
show it (and we are probably wasting effort loading the full contents
for tools like for-each-ref).
However, that's not the full story. For objectname:short, it _does_ call
find_unique_abbrev(). So we expect to have an object directory.
- sorting by "HEAD" hits a BUG(), and would still be allowed with your
patch.
So I like the idea here that the particular atoms would tell us whether
they're going to need to be in a repository or not, but I think the
annotations have to be cleaned up first.
> diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
> index 91ee6841c1..32e722db2e 100755
> --- a/t/t5512-ls-remote.sh
> +++ b/t/t5512-ls-remote.sh
> @@ -302,6 +302,12 @@ test_expect_success 'ls-remote works outside repository' '
> nongit git ls-remote dst.git
> '
>
> +test_expect_success 'ls-remote --sort fails gracefully outside repository' '
> + # Use a sort key that requires access to the referenced objects.
> + nongit test_must_fail git ls-remote --sort=authordate "$TRASH_DIRECTORY" 2>err &&
> + test_i18ngrep "^fatal: not a git repository, but the field '\''authordate'\'' requires access to object data" err
> +'
Regardless of our solution, we probably want to add an extra test making
sure that something vanilla like:
nongit git ls-remote --sort=v:refname "$TRASH_DIRECTORY"
continues to work (we do test ls-remote outside a repo already, but not
with a sort specifier).
-Peff
next prev parent reply other threads:[~2018-11-15 9:38 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-22 10:42 Coredump on ls-remote + --sort H.Merijn Brand
2018-09-22 12:33 ` Ævar Arnfjörð Bjarmason
2018-09-22 14:11 ` [PATCH] ref-filter: don't look for objects when outside of a repository SZEDER Gábor
2018-09-24 16:15 ` Junio C Hamano
2018-09-24 18:17 ` Jeff King
2018-09-24 21:20 ` SZEDER Gábor
2018-09-24 21:30 ` Jeff King
2018-09-25 20:57 ` Junio C Hamano
2018-11-14 12:27 ` SZEDER Gábor
2018-11-15 9:38 ` Jeff King [this message]
2018-11-15 9:43 ` Jeff King
2018-11-16 5:09 ` Junio C Hamano
2018-11-16 8:56 ` Jeff King
2018-11-16 10:07 ` Junio C Hamano
2018-11-16 13:16 ` SZEDER Gábor
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181115093844.GA14218@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=h.m.brand@xs4all.nl \
--cc=haraldnordgren@gmail.com \
--cc=olyatelezhnaya@gmail.com \
--cc=szeder.dev@gmail.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.
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 NNTP newsgroup(s).