From: Eric Sunshine <sunshine@sunshineco.com>
To: git@vger.kernel.org
Cc: Eric Sunshine <sunshine@sunshineco.com>,
Junio C Hamano <gitster@pobox.com>,
Joshua Jensen <jjensen@workspacewhiz.com>,
Brian Gernhardt <brian@gernhardtsoftware.com>
Subject: [PATCH 2/2] dir: test_one_path: fix inconsistent behavior due to missing '/'
Date: Fri, 23 Aug 2013 00:29:15 -0400 [thread overview]
Message-ID: <1377232155-7300-3-git-send-email-sunshine@sunshineco.com> (raw)
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
next prev parent reply other threads:[~2013-08-23 4:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-23 4:29 [PATCH 0/2] fix t3010 failure when core.ignorecase=true Eric Sunshine
2013-08-23 4:29 ` [PATCH 1/2] t3103: demonstrate dir.c:treat_one_path() core.ignorecase failure Eric Sunshine
2013-08-23 17:21 ` Junio C Hamano
2013-08-23 4:29 ` Eric Sunshine [this message]
2013-08-25 6:00 ` [PATCH 2/2] dir: test_one_path: fix inconsistent behavior due to missing '/' Jonathan Nieder
2013-08-25 8:05 ` Eric Sunshine
2013-08-26 5:38 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1377232155-7300-3-git-send-email-sunshine@sunshineco.com \
--to=sunshine@sunshineco.com \
--cc=brian@gernhardtsoftware.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jjensen@workspacewhiz.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).