Commit fe3057b4b9bbab028d7cd18ce06edc034847f844

Patrick Steinhardt 2016-05-03T17:36:09

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.

diff --git a/src/diff.c b/src/diff.c
index 64641da..26c0b89 100644
--- a/src/diff.c
+++ b/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;
 		}
 	}