diff options
author | Patrick Steinhardt <ps@pks.im> | 2016-05-03 17:36:09 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2016-05-03 18:19:20 +0200 |
commit | fe3057b4b9bbab028d7cd18ce06edc034847f844 (patch) | |
tree | 496628e449221d8c727bd352b2ed5d5fb14cc0db | |
parent | 153fde5b4349f12de4f152c26d3b298e58a69cd8 (diff) | |
download | libgit2-fe3057b4b9bbab028d7cd18ce06edc034847f844.tar.gz |
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.
-rw-r--r-- | src/diff.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/diff.c b/src/diff.c index 64641daab..26c0b895b 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; } } |