From: Jeff King <peff@peff.net>
To: Harald Nordgren <haraldnordgren@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] ls-remote: create '--sort' option
Date: Mon, 2 Apr 2018 17:19:20 -0400 [thread overview]
Message-ID: <20180402211920.GA32099@sigill.intra.peff.net> (raw)
In-Reply-To: <20180402200736.80161-1-haraldnordgren@gmail.com>
On Mon, Apr 02, 2018 at 10:07:36PM +0200, Harald Nordgren wrote:
> @@ -108,9 +115,25 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
> continue;
> if (!tail_match(pattern, ref->name))
> continue;
> +
> + struct ref_array_item *item;
We don't allow mixed declarations and code; this line needs to go at the
top of the block.
> + FLEX_ALLOC_MEM(item, refname, ref->name, strlen(ref->name));
> + item->symref = ref->symref;
> + item->objectname = ref->old_oid;
> +
> + REALLOC_ARRAY(array.items, array.nr + 1);
> + array.items[array.nr++] = item;
> + }
This will grow by one each time, which ends up doing quadratic work in
the number of items (although it can often be less if the realloc is
able to just extend the block). It should probably use ALLOC_GROW()
to move it more aggressively.
Interestingly, the ref-filter code itself seems to have the same
problem, but I couldn't measure any speedup. So either my analysis is
totally wrong, or we end up reusing the block most of the time in
practice.
> +
> + if (sorting) {
> + ref_array_sort(sorting, &array);
> + }
Minor style nit: we usually omit the braces for a one-liner block.
The ref-filter code lets you sort on any arbitrary field. So you could
do:
git ls-remote --sort=committerdate
What should that do?
With your patch, I think we'll just get something like:
fatal: missing object 468165c1d8a442994a825f3684528361727cd8c0 for HEAD
which is perhaps the best we can do (it might even work if you've
recently fetched from the other side).
-Peff
prev parent reply other threads:[~2018-04-02 21:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <[PATCH] ls-remote: create option to sort by versions>
2018-04-02 3:23 ` [PATCH 2/2] ls-remote: create option to sort by versions Harald Nordgren
2018-04-02 20:07 ` [PATCH] ls-remote: create '--sort' option Harald Nordgren
2018-04-02 20:12 ` Junio C Hamano
2018-04-02 21:14 ` Harald Nordgren
2018-04-02 21:19 ` Jeff King [this message]
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=20180402211920.GA32099@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=haraldnordgren@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).