git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: "David Turner" <dturner@twopensource.com>,
	"Jeff King" <peff@peff.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	git@vger.kernel.org
Subject: Re: [PATCH 09/13] refs: introduce an iterator interface
Date: Tue, 31 May 2016 10:45:54 +0200	[thread overview]
Message-ID: <574D4F42.3090807@alum.mit.edu> (raw)
In-Reply-To: <xmqqr3ci7o73.fsf@gitster.mtv.corp.google.com>

On 05/31/2016 08:10 AM, Junio C Hamano wrote:
> Michael Haggerty <mhagger@alum.mit.edu> writes:
> 
>> This commit introduces a new iteration primitive for references: a
>> ref_iterator. A ref_iterator is a polymorphic object that a reference
>> storage backend can be asked to instantiate. There are three functions
>> that can be applied to a ref_iterator:
>>
>> * ref_iterator_advance(): move to the next reference in the iteration
>> * ref_iterator_abort(): end the iteration before it is exhausted
>> * ref_iterator_peel(): peel the reference currently being looked at
> 
> This part looked somewhat strange in that it makes "peel" sound
> something very special.  Even though I understand why, it made me
> feel uneasy.  I do not think of another operation like peel that may
> want to have such a specialized helper, so I'll let it pass, but the
> primary uneasiness I felt comes from the fact that "iterator-peel"
> is not an essential service of the API that needs for correctness,
> but is a pure optimization (i.e. you could grab a ref from the
> normal iterator call, and then ask "please peel this ref" to the
> usual ref API that does not know anything about iteration).

I agree that this is inelegant. The underlying reason is that the
iterator embodies both the iteration and also the reference currently
being iterated over. So ref_iterator_advance() and ref_iterator_abort()
are really iterator methods, whereas ref_iterator_peel() is really a
method on the current reference. For that matter, the refname etc fields
are conceptually parts of the current reference, too, not of the iteration.

One of my many coding spikes tried to separate the two concepts by
having the iterator give back a separate object representing the
reference. That object would have had a peel() method. But I wasn't
happy with that approach:

* Anything that made it look like the reference object had a lifetime
independent of that of the iterator seemed like asking for trouble.

* The peel() method would probably have to be a real method that knows
where the reference came from (as opposed to a simple function) because
of things like prefix_ref_iterator, where the refname stored in the
ref_iterator might have had its prefix stripped off.

The complexity level was getting beyond what I felt was tenable in C, so
I made the compromise that you see.

If I had more time I'd do some benchmarking to see whether the "peeling"
optimization is really still needed. It comes from the days when
references were stored in giant lists. Now that we store refs in tries,
and each level gets sorted as part of the iteration anyway, the lookup
might be fast enough that nobody would care.

> [...]

Michael

  reply	other threads:[~2016-05-31  8:46 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-30  7:55 [PATCH 00/13] Reference iterators Michael Haggerty
2016-05-30  7:55 ` [PATCH 01/13] refs: remove unnecessary "extern" keywords Michael Haggerty
2016-05-30  7:55 ` [PATCH 02/13] do_for_each_ref(): move docstring to the header file Michael Haggerty
2016-05-30  7:55 ` [PATCH 03/13] refs: use name "prefix" consistently Michael Haggerty
2016-05-30  7:55 ` [PATCH 04/13] delete_refs(): add a flags argument Michael Haggerty
2016-05-30  7:55 ` [PATCH 05/13] remote rm: handle symbolic refs correctly Michael Haggerty
2016-05-30  7:55 ` [PATCH 06/13] get_ref_cache(): only create an instance if there is a submodule Michael Haggerty
2016-05-30  7:55 ` [PATCH 07/13] entry_resolves_to_object(): rename function from ref_resolves_to_object() Michael Haggerty
2016-05-30  7:55 ` [PATCH 08/13] ref_resolves_to_object(): new function Michael Haggerty
2016-05-30  7:55 ` [PATCH 09/13] refs: introduce an iterator interface Michael Haggerty
2016-05-30 15:22   ` Ramsay Jones
2016-05-30 16:57     ` Ramsay Jones
2016-05-31  1:16       ` Michael Haggerty
2016-05-31  5:29   ` Eric Sunshine
2016-05-31  7:59     ` Michael Haggerty
2016-05-31 23:12       ` Eric Sunshine
2016-06-03 11:48         ` Michael Haggerty
2016-05-31  6:10   ` Junio C Hamano
2016-05-31  8:45     ` Michael Haggerty [this message]
2016-06-02 10:08   ` Duy Nguyen
2016-06-02 16:23     ` Michael Haggerty
2016-05-30  7:55 ` [PATCH 10/13] do_for_each_ref(): reimplement using reference iteration Michael Haggerty
2016-05-30  7:55 ` [PATCH 11/13] for_each_reflog(): don't abort for bad references Michael Haggerty
2016-05-30  7:55 ` [PATCH 12/13] dir_iterator: new API for iterating over a directory tree Michael Haggerty
2016-06-01  0:12   ` David Turner
2016-06-03 11:57     ` Michael Haggerty
2016-05-30  7:55 ` [PATCH 13/13] for_each_reflog(): reimplement using iterators 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=574D4F42.3090807@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=dturner@twopensource.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    /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).