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

[PATCH v3] Support "\" in non-wildcard exclusion entries

From
Finn Arne Gangstad <finnag@pvv.org>
Date
Feb 12, 2009, 09:32 UTC
Message-ID
<20090212093250.GA9623@pvv.org>
In-Reply-To
<7v7i3ynt1z.fsf@gitster.siamese.dyndns.org>
On Tue, Feb 10, 2009 at 08:41:12AM -0800, Junio C Hamano wrote:
Show 5 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
> 
> Oh, by the way, do we really want to add a new test script?  I am
> wondering why the test is not an update to an existing test for the
> exclusion feature, such as t/t3001-ls-files-others-exclude.sh

Ok, here is the final version with your suggested test-modification, which seems to to the trick!

- Finn Arne

--8<-- Support "\" in non-wildcard exclusion entries

"\" was treated differently in exclude rules depending on whether a wildcard match was done. For wildcard rules, "\" was de-escaped in fnmatch, but this was not done for other rules since they used strcmp instead. A file named "#foo" would not be excluded by "\#foo", but would be excluded by "\#foo*".

We now treat all rules with "\" as wildcard rules.

Another solution could be to de-escape all non-wildcard rules as we read them, but we would have to do the de-escaping exactly as fnmatch does it to avoid inconsistencies.

Signed-off-by: Finn Arne Gangstad <finnag@pvv.org>
---
 dir.c                              |    2 +-
 t/t3001-ls-files-others-exclude.sh |    7 +++++++
 2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/dir.c b/dir.c
index cfd1ea5..2245749 100644
--- a/dir.c
+++ b/dir.c
@@ -137,7 +137,7 @@ int match_pathspec(const char **pathspec, const char *name, int namelen,
 
 static int no_wildcard(const char *string)
 {
-	return string[strcspn(string, "*?[{")] == '\0';
+	return string[strcspn(string, "*?[{\\")] == '\0';
 }
 
 void add_exclude(const char *string, const char *base,
diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh
index 85aef12..9be9557 100755
--- a/t/t3001-ls-files-others-exclude.sh
+++ b/t/t3001-ls-files-others-exclude.sh
@@ -19,6 +19,9 @@ do
     >$dir/a.$i
   done
 done
+>"#ignore1"
+>"#ignore2"
+>"#hidden"
 
 cat >expect <<EOF
 a.2
@@ -42,6 +45,9 @@ three/a.8
 EOF
 
 echo '.gitignore
+\#ignore1
+\#ignore2*
+\#hid*n
 output
 expect
 .gitignore
@@ -82,6 +88,7 @@ test_expect_success \
 cat > excludes-file << EOF
 *.[1-8]
 e*
+\#*
 EOF
 
 git config core.excludesFile excludes-file
-- 
1.6.2.rc0.11.g665ed
Previous: Finn Arne GangstadNext: Johannes Schindelin
Message 11 of 13 in “Support \ in non-wildcard .gitignore entries”
  1. Support \ in non-wildcard .gitignore entriesFinn Arne Gangstad, Feb 10, 2009
  2. Johannes SchindelinFeb 10, 2009
  3. Finn Arne GangstadFeb 10, 2009
  4. Johannes SchindelinFeb 10, 2009
  5. Support "\" in non-wildcard exclusion entriesFinn Arne Gangstad, Feb 10, 2009
  6. Johannes SchindelinFeb 10, 2009
  7. Finn Arne GangstadFeb 10, 2009
  8. Junio C HamanoFeb 10, 2009
  9. Junio C HamanoFeb 10, 2009
  10. Finn Arne GangstadFeb 10, 2009
  11. Support "\" in non-wildcard exclusion entriesFinn Arne Gangstad, Feb 12, 2009
  12. Johannes SchindelinFeb 12, 2009
  13. Junio C HamanoFeb 12, 2009

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.