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

[PATCH 2/2] dir: test_one_path: fix inconsistent behavior due to missing '/'

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Aug 23, 2013, 04:29 UTC
Message-ID
<1377232155-7300-3-git-send-email-sunshine@sunshineco.com>
In-Reply-To
<1377232155-7300-1-git-send-email-sunshine@sunshineco.com>

Although undocumented, directory_exists_in_index_icase(dirname,len) unconditionally assumes the presence of a '/' at dirname[len] (despite being past the end-of-string). Callers are expected to respect this assumption by ensuring that a '/' is present beyond the last character of the passed path. directory_exists_in_index(), on the other hand, does not assume nor care about a trailing '/' beyond end-of-string.

2eac2a4cc4bdc8d7 (ls-files -k: a directory only can be killed if the index has a non-directory; 2013-08-15) adds a caller which forgets to ensure the trailing '/', thus leading to inconsistent behavior between directory_exists_in_index() and directory_exists_in_index_icase() depending upon the setting of core.ignorecase. Fix this problem.

This also fixes an initially-unnoticed failure in a t3010 test added by 3c56875176390eee (t3010: update to demonstrate "ls-files -k" optimization pitfalls; 2013-08-15) when core.ignorecase is true.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 dir.c                   | 12 +++++++++---
 t/t3103-ls-tree-misc.sh |  2 +-
 2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/dir.c b/dir.c
index edd666a..a52c6f9 100644
--- a/dir.c
+++ b/dir.c
@@ -1160,9 +1160,15 @@ static enum path_treatment treat_one_path(struct dir_struct *dir,
 	 */
 	if ((dir->flags & DIR_COLLECT_KILLED_ONLY) &&
 	    (dtype == DT_DIR) &&
-	    !has_path_in_index &&
-	    (directory_exists_in_index(path->buf, path->len) == index_nonexistent))
-		return path_none;
+	    !has_path_in_index) {
+		strbuf_addch(path, '/');
+		if (directory_exists_in_index(path->buf, path->len - 1) ==
+		    index_nonexistent) {
+			strbuf_setlen(path, path->len - 1);
+			return path_none;
+		}
+		strbuf_setlen(path, path->len - 1);
+	}
 
 	exclude = is_excluded(dir, path->buf, &dtype);
 
diff --git a/t/t3103-ls-tree-misc.sh b/t/t3103-ls-tree-misc.sh
index fd95991..9fb1706 100755
--- a/t/t3103-ls-tree-misc.sh
+++ b/t/t3103-ls-tree-misc.sh
@@ -22,7 +22,7 @@ test_expect_success 'ls-tree fails with non-zero exit code on broken tree' '
 	test_must_fail git ls-tree -r HEAD
 '
 
-test_expect_failure 'ls-tree directory core.ignorecase' '
+test_expect_success 'ls-tree directory core.ignorecase' '
 	cat >expect <<-\EOF &&
 	d/e/f
 	EOF
-- 
1.8.4.rc4.529.g78818d7
Previous: Junio C HamanoNext: Jonathan Nieder
Message 4 of 7 in “fix t3010 failure when core.ignorecase=true”
  1. 0/2 fix t3010 failure when core.ignorecase=trueEric Sunshine, Aug 23, 2013
  2. 1/2 t3103: demonstrate dir.c:treat_one_path() core.ignorecase failureEric Sunshine, Aug 23, 2013
  3. Junio C HamanoAug 23, 2013
  4. 2/2 dir: test_one_path: fix inconsistent behavior due to missing '/'Eric Sunshine, Aug 23, 2013
  5. Jonathan NiederAug 25, 2013
  6. Eric SunshineAug 25, 2013
  7. Junio C HamanoAug 26, 2013

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.