From: Ramsay Jones <ramsay@ramsayjones.plus.com>
To: Michael Haggerty <mhagger@alum.mit.edu>,
Junio C Hamano <gitster@pobox.com>,
David Turner <dturner@twopensource.com>
Cc: "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: Mon, 30 May 2016 17:57:19 +0100 [thread overview]
Message-ID: <574C70EF.5070705@ramsayjones.plus.com> (raw)
In-Reply-To: <574C5AB0.4090005@ramsayjones.plus.com>
On 30/05/16 16:22, Ramsay Jones wrote:
>
>
> On 30/05/16 08:55, Michael Haggerty wrote:
> [snip]
>
>> /* Reference is a symbolic reference. */
>> diff --git a/refs/files-backend.c b/refs/files-backend.c
>> index 8ab4d5f..dbf1587 100644
>> --- a/refs/files-backend.c
>> +++ b/refs/files-backend.c
>> @@ -1,6 +1,7 @@
>> #include "../cache.h"
>> #include "../refs.h"
>> #include "refs-internal.h"
>> +#include "../iterator.h"
>> #include "../lockfile.h"
>> #include "../object.h"
>> #include "../dir.h"
>> @@ -704,6 +705,154 @@ static void prime_ref_dir(struct ref_dir *dir)
>> }
>> }
>>
>> +/*
>> + * A level in the reference hierarchy that is currently being iterated
>> + * through.
>> + */
>> +struct cache_ref_iterator_level {
>> + /*
>> + * The ref_dir being iterated over at this level. The ref_dir
>> + * is sorted before being stored here.
>> + */
>> + struct ref_dir *dir;
>> +
>> + /*
>> + * The index of the current entry within dir (which might
>> + * itself be a directory). If index == -1, then the iteration
>> + * hasn't yet begun. If index == dir->nr, then the iteration
>> + * through this level is over.
>> + */
>> + int index;
>> +};
>> +
>> +/*
>> + * Represent an iteration through a ref_dir in the memory cache. The
>> + * iteration recurses through subdirectories.
>> + */
>> +struct cache_ref_iterator {
>> + struct ref_iterator base;
>> +
>> + /*
>> + * The number of levels currently on the stack. This is always
>> + * at least 1, because when it becomes zero the iteration is
>> + * ended and this struct is freed.
>> + */
>> + size_t levels_nr;
>> +
>> + /* The number of levels that have been allocated on the stack */
>> + size_t levels_alloc;
>> +
>> + /*
>> + * A stack of levels. levels[0] is the uppermost level that is
>> + * being iterated over in this iteration. (This is not
>> + * necessary the top level in the references hierarchy. If we
>> + * are iterating through a subtree, then levels[0] will hold
>> + * the ref_dir for that subtree, and subsequent levels will go
>> + * on from there.)
>> + */
>> + struct cache_ref_iterator_level *levels;
>> +};
>> +
>> +static int cache_ref_iterator_advance(struct ref_iterator *ref_iterator)
>> +{
>> + struct cache_ref_iterator *iter =
>> + (struct cache_ref_iterator *)ref_iterator;
>> +
>> + while (1) {
>> + struct cache_ref_iterator_level *level =
>> + &iter->levels[iter->levels_nr - 1];
>> + struct ref_dir *dir = level->dir;
>> + struct ref_entry *entry;
>> +
>> + if (level->index == -1)
>> + sort_ref_dir(dir);
>
> do you need to sort here ...
>> +
>> + if (++level->index == level->dir->nr) {
>> + /* This level is exhausted; pop up a level */
>> + if (--iter->levels_nr == 0)
>> + return ref_iterator_abort(ref_iterator);
>> +
>> + continue;
>> + }
>> +
>> + entry = dir->entries[level->index];
>> +
>> + if (entry->flag & REF_DIR) {
>> + /* push down a level */
>> + ALLOC_GROW(iter->levels, iter->levels_nr + 1,
>> + iter->levels_alloc);
>> +
>> + level = &iter->levels[iter->levels_nr++];
>> + level->dir = get_ref_dir(entry);
>> + sort_ref_dir(level->dir);
>
> ... given that you sort here?
I had intended to say 'or vice versa' here. When I wrote this, I had not
finished reading this patch (let alone the series). Now, I suspect that
you can simply drop this 'sort_ref_dir()' call site. Unless I've misread
the code, of course! ;-)
ATB,
Ramsay Jones
next prev parent reply other threads:[~2016-05-30 16:57 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 [this message]
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
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=574C70EF.5070705@ramsayjones.plus.com \
--to=ramsay@ramsayjones.plus.com \
--cc=dturner@twopensource.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mhagger@alum.mit.edu \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.