git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Daniel Ferreira <bnmvco@gmail.com>
Cc: git@vger.kernel.org, sbeller@google.com, pclouds@gmail.com,
	mhagger@alum.mit.edu
Subject: Re: [PATCH v9 3/5] dir_iterator: add helpers to dir_iterator_advance
Date: Mon, 17 Apr 2017 21:23:21 -0700	[thread overview]
Message-ID: <xmqq8tmyfio6.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <1492462296-4990-4-git-send-email-bnmvco@gmail.com> (Daniel Ferreira's message of "Mon, 17 Apr 2017 17:51:34 -0300")

Daniel Ferreira <bnmvco@gmail.com> writes:

> Create helpers to dir_iterator_advance(). Make dir_iterator_advance()'s
> code more legible and allow some behavior to be reusable.
>
> Signed-off-by: Daniel Ferreira <bnmvco@gmail.com>
> ---

This is the kind of change we typically call "refactoring" ---
factoring out reusable helpers out of existing code, without
changing the behaviour of the code at all.

> +static int set_iterator_data(struct dir_iterator_int *iter, struct dir_iterator_level *level)
> +{

If you are going to fold line in a patch that immediately follows
this one, do so from the get-go here.

I am not happy with the name of the function in that "set data" does
not convey as much information as it spends words.  

Conceptually, this is called once per each new directory entry
readdir() returns, and the most important "iterator data" that is
set to iter structure per loop is to update iter->base.path with
de->d_name; everything else is secondary and derived data from that.
And from that point of view, I have trouble with this function not
getting "de" passed to it, but the most important setting is instead
done by its caller.

If the function were called "adjust_iterator_data()", I wouldn't
find this function so troubling, I guess; after the caller sets the
iter.base.path, all the secondary data that can be derived from it
that are used by the caller of "advance" are set by this function.

> +	if (lstat(iter->base.path.buf, &iter->base.st) < 0) {
> +		if (errno != ENOENT)
> +			warning("error reading path '%s': %s",
> +				iter->base.path.buf,
> +				strerror(errno));
> +		return -1;
> +	}
> +
> +	/*
> +	 * We have to set these each time because
> +	 * the path strbuf might have been realloc()ed.
> +	 */
> +	iter->base.relative_path =
> +		iter->base.path.buf + iter->levels[0].prefix_len;
> +	iter->base.basename =
> +		iter->base.path.buf + level->prefix_len;
> +	level->dir_state = DIR_STATE_ITER;
> +
> +	return 0;
> +}
> +

  reply	other threads:[~2017-04-18  4:23 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-17 20:51 [PATCH v9 0/5] [GSoC] remove_subtree(): reimplement using iterators Daniel Ferreira
2017-04-17 20:51 ` [PATCH v9 1/5] dir_iterator: add tests for dir_iterator API Daniel Ferreira
2017-04-18  4:12   ` Junio C Hamano
2017-04-18  4:37   ` Junio C Hamano
2017-04-17 20:51 ` [PATCH v9 2/5] remove_subtree(): test removing nested directories Daniel Ferreira
2017-04-17 20:51 ` [PATCH v9 3/5] dir_iterator: add helpers to dir_iterator_advance Daniel Ferreira
2017-04-18  4:23   ` Junio C Hamano [this message]
2017-04-17 20:51 ` [PATCH v9 4/5] dir_iterator: refactor state machine model Daniel Ferreira
2017-04-18  4:35   ` Junio C Hamano
2017-04-18  5:13   ` Junio C Hamano
2017-04-17 20:51 ` [PATCH v9 5/5] remove_subtree(): reimplement using iterators Daniel Ferreira
2017-04-18  4:09 ` [PATCH v9 0/5] [GSoC] " Junio C Hamano
2017-04-18 18:45   ` Stefan Beller

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=xmqq8tmyfio6.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=bnmvco@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=mhagger@alum.mit.edu \
    --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).