git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Daniel Ferreira <bnmvco@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, sbeller@google.com, pclouds@gmail.com,
	mhagger@alum.mit.edu, Daniel Ferreira <bnmvco@gmail.com>
Subject: [PATCH v5 2/6] dir_iterator: refactor state machine model
Date: Thu, 30 Mar 2017 00:32:06 -0300	[thread overview]
Message-ID: <1490844730-47634-3-git-send-email-bnmvco@gmail.com> (raw)
In-Reply-To: <1490844730-47634-1-git-send-email-bnmvco@gmail.com>

Remove the "initialized" member of dir_iterator_level. Replace its
functionality with a DIR_STATE_PUSH state in the
dir_iterator_level.dir_state enum.

This serves to remove a redundant property in the dir_iterator_level
struct and ease comprehension of the state machine's behavior.

Signed-off-by: Daniel Ferreira <bnmvco@gmail.com>
---
 dir-iterator.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/dir-iterator.c b/dir-iterator.c
index ce8bf81..3ac984b 100644
--- a/dir-iterator.c
+++ b/dir-iterator.c
@@ -4,8 +4,6 @@
 #include "dir-iterator.h"

 struct dir_iterator_level {
-	int initialized;
-
 	DIR *dir;

 	/*
@@ -20,6 +18,7 @@ struct dir_iterator_level {
 	 * iteration and also iterated into):
 	 */
 	enum {
+		DIR_STATE_PUSH,
 		DIR_STATE_ITER,
 		DIR_STATE_RECURSE
 	} dir_state;
@@ -55,8 +54,10 @@ static inline void push_dir_level(struct dir_iterator_int *iter, struct dir_iter
 	level->dir_state = DIR_STATE_RECURSE;
 	ALLOC_GROW(iter->levels, iter->levels_nr + 1,
 		   iter->levels_alloc);
+
+	/* Push a new level */
 	level = &iter->levels[iter->levels_nr++];
-	level->initialized = 0;
+	level->dir_state = DIR_STATE_PUSH;
 }

 static inline int pop_dir_level(struct dir_iterator_int *iter)
@@ -97,7 +98,7 @@ int dir_iterator_advance(struct dir_iterator *dir_iterator)
 			&iter->levels[iter->levels_nr - 1];
 		struct dirent *de;

-		if (!level->initialized) {
+		if (level->dir_state == DIR_STATE_PUSH) {
 			/*
 			 * Note: dir_iterator_begin() ensures that
 			 * path is not the empty string.
@@ -112,8 +113,6 @@ int dir_iterator_advance(struct dir_iterator *dir_iterator)
 					iter->base.path.buf, strerror(errno));
 				/* Popping the level is handled below */
 			}
-
-			level->initialized = 1;
 		} else if (S_ISDIR(iter->base.st.st_mode)) {
 			if (level->dir_state == DIR_STATE_ITER) {
 				/*
@@ -215,7 +214,7 @@ struct dir_iterator *dir_iterator_begin(const char *path)
 	ALLOC_GROW(iter->levels, 10, iter->levels_alloc);

 	iter->levels_nr = 1;
-	iter->levels[0].initialized = 0;
+	iter->levels[0].dir_state = DIR_STATE_PUSH;

 	return dir_iterator;
 }
--
2.7.4 (Apple Git-66)


  parent reply	other threads:[~2017-03-30  3:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-30  3:32 [PATCH v5 0/6] [GSoC] remove_subtree(): reimplement using iterators Daniel Ferreira
2017-03-30  3:32 ` [PATCH v5 1/6] dir_iterator: add helpers to dir_iterator_advance Daniel Ferreira
2017-03-30  3:32 ` Daniel Ferreira [this message]
2017-03-30  8:18   ` [PATCH v5 2/6] dir_iterator: refactor state machine model Michael Haggerty
2017-03-30  3:32 ` [PATCH v5 3/6] dir_iterator: iterate over dir after its contents Daniel Ferreira
2017-03-30 11:03   ` Michael Haggerty
2017-03-30  3:32 ` [PATCH v5 4/6] dir_iterator: add tests for dir_iterator API Daniel Ferreira
2017-03-30  7:46   ` Michael Haggerty
2017-03-30 18:25     ` Daniel Ferreira (theiostream)
2017-04-01  9:03       ` Jeff King
2017-04-01 17:16         ` Junio C Hamano
2017-03-30  7:48   ` Michael Haggerty
2017-03-30  8:05   ` Michael Haggerty
2017-03-30 18:26     ` Daniel Ferreira (theiostream)
2017-03-30  3:32 ` [PATCH v5 5/6] remove_subtree(): reimplement using iterators Daniel Ferreira
2017-03-30  3:32 ` [PATCH v5 6/6] remove_subtree(): test removing nested directories Daniel Ferreira
2017-03-30 11:07   ` Michael Haggerty
2017-03-30 11:27 ` [PATCH v5 0/6] [GSoC] remove_subtree(): reimplement using iterators Michael Haggerty
2017-03-30 12:10   ` Duy Nguyen

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=1490844730-47634-3-git-send-email-bnmvco@gmail.com \
    --to=bnmvco@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --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).