Skip to content

Commit fe3057b

Browse files
committed
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.
1 parent 153fde5 commit fe3057b

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/diff.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,17 +1083,13 @@ static int handle_unmatched_new_item(
10831083
if (recurse_into_dir) {
10841084
error = iterator_advance_into(&info->nitem, info->new_iter);
10851085

1086-
/* if real error or no error, proceed with iteration */
1087-
if (error != GIT_ENOTFOUND)
1088-
return error;
1089-
giterr_clear();
1086+
/* if directory is empty, can't advance into it, so skip it */
1087+
if (error == GIT_ENOTFOUND) {
1088+
giterr_clear();
1089+
error = iterator_advance(&info->nitem, info->new_iter);
1090+
}
10901091

1091-
/* if directory is empty, can't advance into it, so either skip
1092-
* it or ignore it
1093-
*/
1094-
if (error == GIT_ENOTFOUND || contains_oitem)
1095-
return iterator_advance(&info->nitem, info->new_iter);
1096-
delta_type = GIT_DELTA_IGNORED;
1092+
return error;
10971093
}
10981094
}
10991095

0 commit comments

Comments
 (0)