From: Michael Haggerty <mhagger@alum.mit.edu>
To: Junio C Hamano <gitster@pobox.com>
Cc: Daniel Ferreira <bnmvco@gmail.com>,
git@vger.kernel.org, sbeller@google.com, pclouds@gmail.com
Subject: Re: [PATCH v4 2/5] dir_iterator: iterate over dir after its contents
Date: Thu, 30 Mar 2017 08:39:28 +0200 [thread overview]
Message-ID: <1751d788-d1f1-1c97-b33b-f53dab78ef86@alum.mit.edu> (raw)
In-Reply-To: <xmqqinmr70uc.fsf@gitster.mtv.corp.google.com>
On 03/30/2017 08:08 AM, Junio C Hamano wrote:
> Michael Haggerty <mhagger@alum.mit.edu> writes:
>
>> I think IN_ORDER really only applies to *binary* trees, not arbitrary
>> trees like a filesystem.
>
> How true. Even if we were giving a sorted output (and dir-iterator
> doesn't and there is no need for it to), dir/ should come before any
> of its contents, so for that application we can use pre-order, and
> there is no sensible and useful definition of in-order.
Your email got me thinking, though, that there is one generalization of
the concept of PRE_ORDER vs. POST_ORDER that would be both easy to
implement and potentially useful. Namely, flags could include the
following orthogonal options (instead of `DIR_ITERATOR_POST_ORDER)`:
* DIR_ITERATOR_DIRS_BEFORE -- when this is set, directories
are included in the iteration *before* their contents.
* DIR_ITERATOR_DIRS_AFTER -- when this is set, directories
are included in the iteration *after* their contents.
Enabling one or the other of these options would select pre-order or
post-order iteration.
Enabling neither of them would mean that directory entries themselves
are not included in the iteration at all, even though recursion would
happen *into* subdirectories. This option would surely be useful to some
caller somewhere (though it's easy for the caller to get the same effect
itself via
if (S_ISDIR(iter->base.st.st_mode))
continue;
).
It's even conceivable that enabling *both* options at the same time
would be useful, if the caller want to know when the processing of a
directory is begun and also when it is finished (e.g., because it needs
to load or unload a `.gitignore` file for that directory). If we wanted
to make it easier for the caller figure out whether it is seeing an
"entering directory" event vs. a "leaving directory" event, we could
expose something like the `dir_state` member in the iterator.
While we're blue-skying, a
* DIR_ITERATOR_RECURSE -- recurse into subdirectories
would make the set of possible options complete. If this option is not
set, then the iteration would be over the entries in a single directory
without traversing its subdirectories.
I don't think any of this needs to be implemented now, but maybe keep it
in mind if/when `dir_iterator` gets more users.
Michael
next prev parent reply other threads:[~2017-03-30 6:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-29 0:32 [PATCH v4 0/5] [GSoC] remove_subtree(): reimplement using iterators Daniel Ferreira
2017-03-29 0:32 ` [PATCH v4 1/5] dir_iterator: add helpers to dir_iterator_advance Daniel Ferreira
2017-03-29 4:32 ` Michael Haggerty
2017-03-29 0:32 ` [PATCH v4 2/5] dir_iterator: iterate over dir after its contents Daniel Ferreira
2017-03-29 9:56 ` Michael Haggerty
2017-03-29 10:44 ` Michael Haggerty
2017-03-29 16:46 ` Junio C Hamano
2017-03-30 4:59 ` Michael Haggerty
2017-03-30 6:08 ` Junio C Hamano
2017-03-30 6:39 ` Michael Haggerty [this message]
2017-03-30 11:08 ` Duy Nguyen
2017-04-02 4:25 ` Daniel Ferreira (theiostream)
2017-04-05 9:21 ` Duy Nguyen
2017-03-30 17:26 ` Junio C Hamano
2017-03-29 0:32 ` [PATCH v4 3/5] remove_subtree(): reimplement using iterators Daniel Ferreira
2017-03-29 10:01 ` Michael Haggerty
2017-03-29 0:32 ` [PATCH v4 4/5] remove_subtree(): test removing nested directories Daniel Ferreira
2017-03-29 0:32 ` [PATCH v4 5/5] files_reflog_iterator: amend use of dir_iterator Daniel Ferreira
2017-03-29 10:45 ` 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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1751d788-d1f1-1c97-b33b-f53dab78ef86@alum.mit.edu \
--to=mhagger@alum.mit.edu \
--cc=bnmvco@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=pclouds@gmail.com \
--cc=sbeller@google.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).