From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: Michael J Gruber <git@drmicha.warpmail.net>,
Jon Schewe <jpschewe@mtu.net>,
spearce@spearce.org, git@vger.kernel.org
Subject: Re: Possible bug in git-completion.sh
Date: Fri, 08 Jan 2010 11:58:11 -0800 [thread overview]
Message-ID: <7vvdfcfjxo.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <7v8wc8jw3k.fsf@alter.siamese.dyndns.org> (Junio C. Hamano's message of "Fri\, 08 Jan 2010 10\:21\:51 -0800")
Junio C Hamano <gitster@pobox.com> writes:
> Nah, I should have checked the code.
>
> The implementation of ls-files does cd up and uses pathspec, so the intent
> is to apply higher level gitignore.
>
> It however feeds paths from the already ignored directories, which _is_
> the real bug.
> ...
> I think a proper fix should be in dir.c::read_directory() where it calls
> read_directory_recursive() without first checking if the directory itself
> should be ignored. read_directory_recursive() itself has a logic to see
> if the dirent it found is worth recursing into and a similar logic should
> be in the toplevel caller.
Actually doing less in fill_directory() turned out to be a simpler
solution.
builtin_add() cares about the return value from fill_directory() and
performs prune_directory() optimization magic, and we may want to change
it not to do so as well, but I didn't want to worry about too many things
at once, so this version still runs the "common_prefix()" that forgets to
take .gitignore at higher levels (or a $GIT_DIR/info/exclude entry that
ignores the common prefix directory of given pathspecs) into account.
Another possibility is to fix common_prefix() and make it walk the path it
returns one level at a time from the top, making sure they are not
ignored, and that would probably be a better fix, but at least this patch
will give you a starting point and tests to check the result against.
diff --git a/dir.c b/dir.c
index d0999ba..56d3f60 100644
--- a/dir.c
+++ b/dir.c
@@ -53,7 +53,6 @@ static int common_prefix(const char **pathspec)
int fill_directory(struct dir_struct *dir, const char **pathspec)
{
- const char *path;
int len;
/*
@@ -61,13 +60,8 @@ int fill_directory(struct dir_struct *dir, const char **pathspec)
* use that to optimize the directory walk
*/
len = common_prefix(pathspec);
- path = "";
-
- if (len)
- path = xmemdupz(*pathspec, len);
-
/* Read the directory and prune it */
- read_directory(dir, path, len, pathspec);
+ read_directory(dir, "", 0, pathspec);
return len;
}
diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh
index c65bca8..17d1764 100755
--- a/t/t3001-ls-files-others-exclude.sh
+++ b/t/t3001-ls-files-others-exclude.sh
@@ -153,4 +153,42 @@ test_expect_success 'negated exclude matches can override previous ones' '
grep "^a.1" output
'
+test_expect_success 'subdirectory ignore (setup)' '
+ mkdir -p top/l1/l2 &&
+ (
+ cd top &&
+ git init &&
+ echo /.gitignore >.gitignore &&
+ echo l1 >>.gitignore &&
+ echo l2 >l1/.gitignore
+ )
+'
+
+test_expect_success 'subdirectory ignore (toplevel)' '
+ (
+ cd top &&
+ git ls-files -o --exclude-standard
+ ) >actual &&
+ >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'subdirectory ignore (l1/l2)' '
+ (
+ cd top/l1/l2 &&
+ git ls-files -o --exclude-standard
+ ) >actual &&
+ >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'subdirectory ignore (l1)' '
+ (
+ cd top/l1 &&
+ git ls-files -o --exclude-standard
+ ) >actual &&
+ >expect &&
+ test_cmp expect actual
+'
+
test_done
next prev parent reply other threads:[~2010-01-08 19:58 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-08 15:17 Possible bug in git-completion.sh Jon Schewe
2010-01-08 15:40 ` Michael J Gruber
2010-01-08 16:24 ` Jeff King
2010-01-08 16:38 ` Junio C Hamano
2010-01-08 16:41 ` Jeff King
2010-01-08 16:45 ` Junio C Hamano
2010-01-08 16:56 ` Junio C Hamano
2010-01-08 17:24 ` Jeff King
2010-01-08 17:21 ` Jeff King
2010-01-08 18:21 ` Junio C Hamano
2010-01-08 19:58 ` Junio C Hamano [this message]
2010-01-08 23:01 ` [PATCH] ls-files: fix overeager pathspec optimization Junio C Hamano
2010-01-08 23:24 ` Linus Torvalds
2010-01-08 23:31 ` Junio C Hamano
2010-01-09 0:06 ` Junio C Hamano
2010-01-09 0:24 ` Linus Torvalds
2010-01-09 0:54 ` Junio C Hamano
2010-01-09 1:07 ` Linus Torvalds
2010-01-09 5:42 ` Jeff King
2010-01-09 7:16 ` Junio C Hamano
2010-01-09 7:35 ` [PATCH 1/4] t3001: test ls-files -o ignored/dir Junio C Hamano
2010-01-09 7:35 ` [PATCH 2/4] read_directory_recursive(): refactor handling of a single path into a separate function Junio C Hamano
2010-01-09 7:35 ` [PATCH 3/4] read_directory(): further split treat_path() Junio C Hamano
2010-01-09 7:35 ` [PATCH 4/4] ls-files: fix overeager pathspec optimization Junio C Hamano
2010-01-12 16:33 ` Jeff King
2010-01-09 8:07 ` [PATCH] " Junio C Hamano
2010-01-09 18:05 ` Linus Torvalds
2010-01-10 6:31 ` 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=7vvdfcfjxo.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=jpschewe@mtu.net \
--cc=peff@peff.net \
--cc=spearce@spearce.org \
--cc=torvalds@linux-foundation.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.