From: Michael J Gruber <git@drmicha.warpmail.net>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Matthijs Kooijman" <matthijs@stdin.nl>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] dir.c: do not trip over difference in "/"
Date: Fri, 25 Mar 2011 16:52:22 +0100 [thread overview]
Message-ID: <b28c22b42c43f5dced45bee8ba4c76965b736d9a.1301068238.git.git@drmicha.warpmail.net> (raw)
In-Reply-To: <1301060989-7246-1-git-send-email-pclouds@gmail.com>
get_relative_cwd() tries to determine a common prefix for dir and cwd.
The fix in
490544b (get_cwd_relative(): do not misinterpret suffix as subdirectory, 2010-05-22)
made the logic less naive (so that foo-bar is not misdetected as being
within foo) but broke some other cases, in particular foo not being
detected as being within foo/ any more.
Fix it by taking into a account that a directory name may or may not end
in /.
Document with a test.
Reported-by: Matthijs Kooijman <matthijs@stdin.nl>
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
So I think this would be a proper fix.
I tried to be nice and base it on the commit which I bisected the problem to. I
saw much too late that their were later (failed) attempts at fixing this and a
major rewrite of the test, which is quite a nuisance. Anyway, this problem needs a fix,
and by taking get_cwd_relative() from this patch on top of next the problem is fixed.
I have not looked into resolving the merge conflict in the test.
dir.c | 23 +++++++++++++++--------
t/t1501-worktree.sh | 13 +++++++++++++
2 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/dir.c b/dir.c
index 5615f33..b090cd0 100644
--- a/dir.c
+++ b/dir.c
@@ -956,16 +956,23 @@ char *get_relative_cwd(char *buffer, int size, const char *dir)
dir++;
cwd++;
}
- if (*dir)
+
+ /* dir has more than just '/' left */
+ if (*dir && ((*dir != '/') || *(dir+1)))
return NULL;
- switch (*cwd) {
- case '\0':
+ /* *dir is now '\0' or '/' followed by '\0' */
+ if (cwd == buffer) /* we did not move */
+ return (*cwd) ? NULL : cwd;
+ /* we have moved at least by 1 */
+ if (*dir) /* == '/' */
+ return (*cwd) ? NULL : cwd;
+ if (!(*cwd)) /* both ended */
return cwd;
- case '/':
- return cwd + 1;
- default:
- return NULL;
- }
+ if (*(dir-1) == '/') /* must have been common */
+ return cwd;
+ if (*cwd == '/')
+ return cwd+1;
+ return NULL;
}
int is_inside_dir(const char *dir)
diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
index bd8b607..f0dbdd8 100755
--- a/t/t1501-worktree.sh
+++ b/t/t1501-worktree.sh
@@ -63,6 +63,19 @@ cd sub/dir || exit 1
test_rev_parse 'subdirectory' false false true sub/dir/
cd ../../.. || exit 1
+say "core.worktree = absolute path/"
+GIT_DIR=$(pwd)/repo.git
+GIT_CONFIG=$GIT_DIR/config
+git config core.worktree "$(pwd)/work/"
+test_rev_parse 'outside' false false false
+cd work2
+test_rev_parse 'outside2' false false false
+cd ../work || exit 1
+test_rev_parse 'inside' false false true ''
+cd sub/dir || exit 1
+test_rev_parse 'subdirectory' false false true sub/dir/
+cd ../../.. || exit 1
+
say "GIT_WORK_TREE=relative path (override core.worktree)"
GIT_DIR=$(pwd)/repo.git
GIT_CONFIG=$GIT_DIR/config
--
1.7.4.1.607.g888da
next prev parent reply other threads:[~2011-03-25 15:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-25 10:02 git-add says 'pathspec did not match any files' for git repository in / Matthijs Kooijman
2011-03-25 12:56 ` Nguyen Thai Ngoc Duy
2011-03-25 13:49 ` [PATCH] setup: return correct prefix if worktree is '/' Nguyễn Thái Ngọc Duy
2011-03-25 14:17 ` Michael J Gruber
2011-03-25 15:11 ` Nguyen Thai Ngoc Duy
2011-03-25 15:52 ` Michael J Gruber [this message]
2011-03-26 7:59 ` [PATCH] dir.c: do not trip over difference in "/" Nguyen Thai Ngoc Duy
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=b28c22b42c43f5dced45bee8ba4c76965b736d9a.1301068238.git.git@drmicha.warpmail.net \
--to=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=matthijs@stdin.nl \
--cc=pclouds@gmail.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).