From: Junio C Hamano <gitster@pobox.com>
To: Harald Nordgren <haraldnordgren@gmail.com>
Cc: git@vger.kernel.org, avarab@gmail.com, peff@peff.net,
sunshine@sunshineco.com
Subject: Re: [PATCH v12 4/4] ls-remote: create '--sort' option
Date: Mon, 09 Apr 2018 07:16:47 +0900 [thread overview]
Message-ID: <xmqq7eph9wds.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20180408122832.65414-4-haraldnordgren@gmail.com> (Harald Nordgren's message of "Sun, 8 Apr 2018 14:28:32 +0200")
Harald Nordgren <haraldnordgren@gmail.com> writes:
> +--sort=<key>::
> + Sort based on the key given. Prefix `-` to sort in descending order
> + of the value. Supports "version:refname" or "v:refname" (tag names
> + are treated as versions). The "version:refname" sort order can also
> + be affected by the "versionsort.suffix" configuration variable.
> + See linkgit:git-for-each-ref[1] for more sort options, but be aware
> + that because `ls-remote` deals only with remotes, any key like
> + `committerdate` that requires access to the object itself will
> + cause a failure.
I can connect "because it deals only with remotes" and "access to
the object may fail", but I wonder if we can clarify the former a
bit better to make it easier to understand for those who are not yet
familiar with Git.
Keys like `committerdate` that require access to the object will
not work [***HOW??? Do we get a segfault or something???***] for
refs whose objects have not yet been fetched from the remote.
I added "for refs whose objects have not yet been fetched", whose
explicit-ness made "will not work" to be an OK expression, but
without it I would have suggested to rephrase it to "may not work".
This is a tangent but I suspect that the description of --sort in
git-for-each-ref documentation is wrong on the use of multiple
options, or I am misreading parse_opt_ref_sorting(), which I think
appends later keys to the end of the list, and compare_refs() which
I think yields results when an earlier key in the last decides two
are not equal and ignores the later keys. The commit that added the
description was c0f6dc9b ("git-for-each-ref.txt: minor
improvements", 2008-06-05), and I think even back then the code in
builtin-for-each-ref.c appended later keys at the end, and it seems
nobody complained, so it is possible I am not reading the code right
before fully adjusting to timezone change ;-)
> + for (i = 0; i < ref_array.nr; i++) {
> + const struct ref_array_item *ref = ref_array.items[i];
> if (show_symref_target && ref->symref)
> - printf("ref: %s\t%s\n", ref->symref, ref->name);
> - printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
> + printf("ref: %s\t%s\n", ref->symref, ref->refname);
> + printf("%s\t%s\n", oid_to_hex(&ref->objectname), ref->refname);
> status = 0; /* we found something */
> }
> +
> + UNLEAK(sorting);
> + UNLEAK(ref_array);
> return status;
> }
It is not too big a deal, but I find that liberal sprinkling of
UNLEAK() is somewhat unsightly. From the code we leave with this
change, it is clear what we'd need to do when we make the code fully
leak-proof (i.e. we'd have a several lines to free resources held by
these two variables here, and then UNLEAK() that appear earlier in
the function will become a "goto cleanup;" after setting appropriate
value to "status"), so let's not worry about it.
> +test_expect_success 'ls-remote --sort="version:refname" --tags self' '
> + cat >expect <<-\EOF &&
> + '$(git rev-parse mark)' refs/tags/mark
> + '$(git rev-parse mark1.1)' refs/tags/mark1.1
> + '$(git rev-parse mark1.2)' refs/tags/mark1.2
> + '$(git rev-parse mark1.10)' refs/tags/mark1.10
> + EOF
Please do *NOT* step outside the pair of single quotes that protects
the body of the test scriptlet and execute commands like "git
rev-parse". These execute in order to prepare the command line
argument strings BEFORE test_expect_success can run (or the test
framework decides if the test will be skipped via GIT_TEST_SKIP).
Instead do it like so:
cat >expect <<-EOF &&
$(git rev-parse mark) refs/tags/mark
$(git rev-parse mark1.1) refs/tags/mark1.1
$(git rev-parse mark1.2) refs/tags/mark1.2
$(git rev-parse mark1.10) refs/tags/mark1.10
EOF
I.e. the end token for << that is not quoted allows $var and $(cmd)
to be substituted.
Same comment applies throughout the remainder of this file.
Other than that, this patch was a very pleasant read. Thanks.
next prev parent reply other threads:[~2018-04-08 22:16 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-02 0:52 [PATCH] ls-remote: create option to sort by versions Harald Nordgren
2018-04-02 6:37 ` Ævar Arnfjörð Bjarmason
2018-04-02 16:26 ` Harald Nordgren
2018-04-02 17:32 ` Ævar Arnfjörð Bjarmason
2018-04-02 17:42 ` Harald Nordgren
2018-04-02 17:46 ` Jeff King
2018-04-02 18:32 ` Junio C Hamano
2018-04-02 20:03 ` Harald Nordgren
2018-04-02 22:11 ` [PATCH v5] ls-remote: create '--sort' option Harald Nordgren
2018-04-02 22:53 ` Eric Sunshine
2018-04-02 22:54 ` Eric Sunshine
2018-04-03 0:48 ` [PATCH v6] " Harald Nordgren
2018-04-02 21:05 ` [PATCH v4] " Harald Nordgren
2018-04-04 17:11 ` [PATCH v7] " Harald Nordgren
2018-04-04 17:18 ` Harald Nordgren
2018-04-04 17:47 ` Harald Nordgren
2018-04-04 18:56 ` Jeff King
2018-04-04 18:55 ` Jeff King
2018-04-04 23:01 ` [PATCH v8] " Harald Nordgren
2018-04-04 23:11 ` Harald Nordgren
2018-04-06 18:58 ` Jeff King
2018-04-06 18:58 ` [PATCH 1/3] ref-filter: use "struct object_id" consistently Jeff King
2018-04-06 18:59 ` [PATCH 2/3] ref-filter: make ref_array_item allocation more consistent Jeff King
2018-04-06 18:59 ` [PATCH 3/3] ref-filter: factor ref_array pushing into its own function Jeff King
2018-04-06 19:27 ` Derrick Stolee
2018-04-07 15:22 ` Harald Nordgren
2018-04-08 23:18 ` Junio C Hamano
2018-04-09 3:57 ` Jeff King
2018-04-04 23:32 ` [PATCH v9] ls-remote: create '--sort' option Harald Nordgren
2018-04-05 0:04 ` [PATCH v10] " Harald Nordgren
2018-04-07 16:42 ` [PATCH v11 1/4] ref-filter: use "struct object_id" consistently Harald Nordgren
2018-04-08 1:06 ` Eric Sunshine
2018-04-08 12:27 ` Harald Nordgren
2018-04-07 16:42 ` [PATCH v11 2/4] ref-filter: make ref_array_item allocation more consistent Harald Nordgren
2018-04-07 16:42 ` [PATCH v11 3/4] ref-filter: factor ref_array pushing into its own function Harald Nordgren
2018-04-07 16:42 ` [PATCH v11 4/4] ls-remote: create '--sort' option Harald Nordgren
2018-04-08 1:48 ` Eric Sunshine
2018-04-08 12:28 ` [PATCH v12 1/4] ref-filter: use "struct object_id" consistently Harald Nordgren
2018-04-08 12:28 ` [PATCH v12 2/4] ref-filter: make ref_array_item allocation more consistent Harald Nordgren
2018-04-08 12:28 ` [PATCH v12 3/4] ref-filter: factor ref_array pushing into its own function Harald Nordgren
2018-04-08 12:28 ` [PATCH v12 4/4] ls-remote: create '--sort' option Harald Nordgren
2018-04-08 22:16 ` Junio C Hamano [this message]
2018-04-09 0:09 ` Harald Nordgren
2018-04-09 0:48 ` Junio C Hamano
2018-04-09 2:31 ` Eric Sunshine
2018-04-08 23:58 ` [PATCH v13 1/4] ref-filter: use "struct object_id" consistently Harald Nordgren
2018-04-08 23:58 ` [PATCH v13 2/4] ref-filter: make ref_array_item allocation more consistent Harald Nordgren
2018-04-08 23:58 ` [PATCH v13 3/4] ref-filter: factor ref_array pushing into its own function Harald Nordgren
2018-04-08 23:58 ` [PATCH v13 4/4] ls-remote: create '--sort' option Harald Nordgren
2018-04-09 0:56 ` Junio C Hamano
2018-04-09 1:45 ` Harald Nordgren
2018-04-09 1:42 ` [PATCH v14 1/4] ref-filter: use "struct object_id" consistently Harald Nordgren
2018-04-09 1:42 ` [PATCH v14 2/4] ref-filter: make ref_array_item allocation more consistent Harald Nordgren
2018-04-11 17:57 ` Harald Nordgren
2018-04-11 18:07 ` Stefan Beller
2018-04-11 18:30 ` Todd Zullinger
2018-04-11 18:56 ` Eric Sunshine
2018-04-11 23:25 ` Junio C Hamano
2018-04-09 1:42 ` [PATCH v14 3/4] ref-filter: factor ref_array pushing into its own function Harald Nordgren
2018-04-09 1:42 ` [PATCH v14 4/4] ls-remote: create '--sort' option Harald Nordgren
2018-05-12 8:45 ` René Scharfe
2018-05-12 9:55 ` Jeff King
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=xmqq7eph9wds.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=haraldnordgren@gmail.com \
--cc=peff@peff.net \
--cc=sunshine@sunshineco.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).