git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/3] read-cache: let verify_path() reject trailing dir separators again

From
René Scharfe <l.s.r@web.de>
Date
Oct 7, 2021, 20:31 UTC
Message-ID
<5e6fafa9-f155-61af-6906-05fec27808e6@web.de>
In-Reply-To
<CACr9BXmP1vQMK4b27Uc4R-3WWYHUYfCEEMN+hnth4yUg+UN7Zg@mail.gmail.com>

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>
---
 read-cache.c                       | 6 +++---
 t/t3905-stash-include-untracked.sh | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index 5b6fc08e46..f1aabc47b6 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -859,7 +859,7 @@ static enum verify_path_result verify_path_internal(const char *, unsigned);

 int verify_path(const char *path, unsigned mode)
 {
-	return verify_path_internal(path, mode) != PATH_INVALID;
+	return verify_path_internal(path, mode) == PATH_OK;
 }

 struct cache_entry *make_cache_entry(struct index_state *istate,
@@ -872,7 +872,7 @@ struct cache_entry *make_cache_entry(struct index_state *istate,
 	struct cache_entry *ce, *ret;
 	int len;

-	if (!verify_path(path, mode)) {
+	if (verify_path_internal(path, mode) == PATH_INVALID) {
 		error(_("invalid path '%s'"), path);
 		return NULL;
 	}
@@ -1364,7 +1364,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e

 	if (!ok_to_add)
 		return -1;
-	if (!verify_path(ce->name, ce->ce_mode))
+	if (verify_path_internal(ce->name, ce->ce_mode) == PATH_INVALID)
 		return error(_("invalid path '%s'"), ce->name);

 	if (!skip_df_check &&
diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh
index 19da46b7fb..5390eec4e3 100755
--- a/t/t3905-stash-include-untracked.sh
+++ b/t/t3905-stash-include-untracked.sh
@@ -422,7 +422,7 @@ test_expect_success 'stash show --{include,only}-untracked on stashes without un
 	test_must_be_empty actual
 '

-test_expect_failure 'stash -u ignores sub-repository' '
+test_expect_success 'stash -u ignores sub-repository' '
 	test_when_finished "rm -rf sub-repo" &&
 	git init sub-repo &&
 	git stash -u
--
2.33.0
Previous: René ScharfeNext: Junio C Hamano
Message 10 of 11 in “Bug/regression report - 'git stash push -u' fatal errors when sub-repo present”
  1. Robert LeftwichSep 30, 2021
  2. René ScharfeSep 30, 2021
  3. Junio C HamanoSep 30, 2021
  4. René ScharfeOct 1, 2021
  5. Derrick StoleeOct 4, 2021
  6. Junio C HamanoOct 4, 2021
  7. Derrick StoleeOct 4, 2021
  8. 1/3 t3905: show failure to ignore sub-repoRené Scharfe, Oct 7, 2021
  9. 2/3 read-cache: add verify_path_internal()René Scharfe, Oct 7, 2021
  10. 3/3 read-cache: let verify_path() reject trailing dir separators againRené Scharfe, Oct 7, 2021
  11. Junio C HamanoOct 8, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.