]> git.ipfire.org Git - thirdparty/git.git/commit - dir-iterator.c
dir-iterator: refactor state machine model
authorMatheus Tavares <matheus.bernardino@usp.br>
Wed, 10 Jul 2019 23:58:59 +0000 (20:58 -0300)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Jul 2019 20:52:15 +0000 (13:52 -0700)
commit3012397e0327f5e4dfd1d1183a792268429744ae
tree79faf55ec5f3ce158864c809e309cc3fa5a0da17
parentc9bba372ed9ee0c5ea1a4037c3c723a6c31f5921
dir-iterator: refactor state machine model

dir_iterator_advance() is a large function with two nested loops. Let's
improve its readability factoring out three functions and simplifying
its mechanics. The refactored model will no longer depend on
level.initialized and level.dir_state to keep track of the iteration
state and will perform on a single loop.

Also, dir_iterator_begin() currently does not check if the given string
represents a valid directory path. Since the refactored model will have
to stat() the given path at initialization, let's also check for this
kind of error and make dir_iterator_begin() return NULL, on failures,
with errno appropriately set. And add tests for this new behavior.

Improve documentation at dir-iteration.h and code comments at
dir-iterator.c to reflect the changes and eliminate possible
ambiguities.

Finally, adjust refs/files-backend.c to check for now possible
dir_iterator_begin() failures.

Original-patch-by: Daniel Ferreira <bnmvco@gmail.com>
Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
dir-iterator.c
dir-iterator.h
refs/files-backend.c
t/helper/test-dir-iterator.c
t/t0066-dir-iterator.sh