mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-08 19:51:31 +00:00
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.
This commit is contained in:
parent
153fde5b43
commit
fe3057b4b9
16
src/diff.c
16
src/diff.c
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user