read-cache: let verify_path() reject trailing dir separators again

6e773527b6 (sparse-index: convert from full to sparse, 2021-03-30) made verify_path() accept trailing directory separators for directories, which is necessary for sparse directory entries. This clemency causes "git stash" to stumble over sub-repositories, though, and there may be more unintended side-effects. Avoid them by restoring the old verify_path() behavior and accepting trailing directory separators only in places that are supposed to handle sparse directory entries. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Oct 7, 2021 at 22:31 UTC c8ad9d04c6a51cb5c73ebc9e42b627314eeafe2f
2 files changed +4 -4
read-cache.c
+3 -3
@@ -854,7 +854,7 @@ static enum verify_path_result verify_path_internal(const char *, unsigned);
854
855 int verify_path(const char *path, unsigned mode)
856 {
857 - return verify_path_internal(path, mode) != PATH_INVALID;
857 + return verify_path_internal(path, mode) == PATH_OK;
858 }
859
860 struct cache_entry *make_cache_entry(struct index_state *istate,
@@ -867,7 +867,7 @@ struct cache_entry *make_cache_entry(struct index_state *istate,
867 struct cache_entry *ce, *ret;
868 int len;
869
870 - if (!verify_path(path, mode)) {
870 + if (verify_path_internal(path, mode) == PATH_INVALID) {
871 error(_("invalid path '%s'"), path);
872 return NULL;
873 }
@@ -1356,7 +1356,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e
1356
1357 if (!ok_to_add)
1358 return -1;
1359 - if (!verify_path(ce->name, ce->ce_mode))
1359 + if (verify_path_internal(ce->name, ce->ce_mode) == PATH_INVALID)
1360 return error(_("invalid path '%s'"), ce->name);
1361
1362 if (!skip_df_check &&
t/t3905-stash-include-untracked.sh
+1 -1
@@ -405,7 +405,7 @@ test_expect_success 'stash show --include-untracked errors on duplicate files' '
405 test_i18ngrep "worktree and untracked commit have duplicate entries: tracked" err
406 '
407
408 -test_expect_failure 'stash -u ignores sub-repository' '
408 +test_expect_success 'stash -u ignores sub-repository' '
409 test_when_finished "rm -rf sub-repo" &&
410 git init sub-repo &&
411 git stash -u