Commit fe3057b4 by Patrick Steinhardt

diff: simplify code for handling empty dirs

When determining diffs between two iterators we may need to
recurse into an unmatched directory for the "new" iterator when
it is either a prefix to the current item of the "old" iterator
or when untracked/ignored changes are requested by the user and
the directory is untracked/ignored.

When advancing into the directory and no files are found, we will
get back `GIT_ENOTFOUND`. If so, we simply skip the directory,
handling resulting unmatched old items in the next iteration. The
other case of `iterator_advance_into` returning either
`GIT_NOERROR` or any other error but `GIT_ENOTFOUND` will be
handled by the caller, which will now either compare the first
directory entry of the "new" iterator in case of `GIT_ENOERROR`
or abort on other cases.

Improve readability of the code to make the above logic more
clear.
parent 153fde5b
......@@ -1083,17 +1083,13 @@ static int handle_unmatched_new_item(
if (recurse_into_dir) {
error = iterator_advance_into(&info->nitem, info->new_iter);
/* if real error or no error, proceed with iteration */
if (error != GIT_ENOTFOUND)
return error;
giterr_clear();
/* if directory is empty, can't advance into it, so skip it */
if (error == GIT_ENOTFOUND) {
giterr_clear();
error = iterator_advance(&info->nitem, info->new_iter);
}
/* if directory is empty, can't advance into it, so either skip
* it or ignore it
*/
if (error == GIT_ENOTFOUND || contains_oitem)
return iterator_advance(&info->nitem, info->new_iter);
delta_type = GIT_DELTA_IGNORED;
return error;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment