From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] string_list API: document what "sorted" means.
Date: Tue, 18 Sep 2012 09:58:35 +0200 [thread overview]
Message-ID: <505829AB.8000506@alum.mit.edu> (raw)
In-Reply-To: <7vy5k8s622.fsf@alter.siamese.dyndns.org>
On 09/17/2012 11:17 PM, Junio C Hamano wrote:
> Michael Haggerty <mhagger@alum.mit.edu> writes:
>
>> Junio pointed out that the sort order currently used by string_list
>> could be considered to be an implementation detail internal to
>> string_list. But the sort order is already visible to the outside
>> world (e.g., via iteration or via print_string_list()), so it
>> shouldn't be changed willy-nilly. Therefore, document the current
>> sort order as part of the API's contract.
>>
>> (If, at some future time, somebody wants a string_list that is sorted
>> by a different criterion, then the order should be made specifiable
>> via a callback function specified by the user.)
>
> As I said in a separate message, we do not give any documented
> guarantee on the order the strings comes out of print_string_list(),
> other than "if you are using the unsorted list function to insert or
> append strings, we won't muck with the order of the items and you
> will get your strings back in the order you gave us". Until we add
> a callback that the user can specify at the time of string list
> initialization, I do not think it is wise to cast it in stone and
> declare it as "shouldn't be changed willy-nilly", unnecessarily
> painting us into a corner that we need to expend extra effort to get
> out of.
>
> Besides, nobody calls print_string_list() in the first place. I have
> always considered it as a debugging aid.
As you pointed out, mh/fetch-filter-refs depends on the sort order of
the "sought" reference array matching the sort order of the linked list
of refs received from the remote.
The linked list has been sorted since 9e8e704f using mergesort based on
strcmp().
Prior to 8bee93dd2, the sought array was sorted using qsort() and an
explicit strcmp()-based comparison function. 8bee93dd2 switched to
sorting the "sought" array using sort_string_list(), which is also based
on strcmp().
If (after mh/fetch-filter-refs) somebody would decide to change the sort
order of string_list, then it would break fetch. So I see three
possibilities:
1. Document that string_list sorts entries according to their strcmp()
order, as proposed in this patch. Then fetch can rely on this ordering.
If somebody wants a different ordering in the future, it is easy to
make the sort order a parameter.
2. Leave string_list's "default" sort order unspecified, but already
implement a way to let string_list users specify a particular sort
order. Change the fetch machinery to specify a strcmp()-based ordering
explicitly. This approach has the advantage of letting the default sort
order of string_list to be changed, though I don't really see how this
would be helpful.
3. Change fetch back to doing its own sorting again, rather than relying
on sort_string_list(). This isn't a lot of work (inline the one line of
sort_string_list(), then either make string-list.c:cmp_items() public or
duplicate that function too).
I prefer (1) because it is nearly as flexible as (2) and doesn't require
us to do work now that might not be needed (namely, parameterizing the
compare function), nor does it require the overhead of keeping a pointer
to the compare function in the string_list header that might be needed
if string_lists with non-default sort orders should be usable with the
"functions for sorted lists only".
Michael
--
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/
next prev parent reply other threads:[~2012-09-18 7:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-17 15:21 [PATCH] string_list API: document what "sorted" means Michael Haggerty
2012-09-17 21:17 ` Junio C Hamano
2012-09-18 7:58 ` Michael Haggerty [this message]
2012-09-18 8:19 ` Junio C Hamano
2012-09-18 8:55 ` Michael Haggerty
2012-09-18 17:21 ` Junio C Hamano
2012-09-19 7:35 ` Michael Haggerty
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=505829AB.8000506@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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).