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

Re: [PATCH] gitignore(5): Allow "foo/" in ignore list to match directory "foo"

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jan 31, 2008, 11:38 UTC
Message-ID
<alpine.LSU.1.00.0801311128190.23907@racer.site>
In-Reply-To
<20080131104256.GF25546@coredump.intra.peff.net>
Hi,
On Thu, 31 Jan 2008, Jeff King wrote:
Show 14 quoted lines
> On Thu, Jan 31, 2008 at 02:35:33AM -0800, Junio C Hamano wrote:
> 
> > Without "foo/", you do not have to pay the price, so I think that is a 
> > sane optimization, but at the same time it would make it worse if 
> > "foo/" is actually used.  excluded_1() is called for the same pathname 
> > from a loop to check for a match and you would end up running lstat(2) 
> > three times (once each for EXC_CMDL, EXC_DIRS and EXC_FILE).
> > 
> > But maybe people who want "foo/" deserve it.  I dunno.
> 
> Ah, I didn't look at it that closely.
> 
> To do the laziness right, I think you would need to pass a pointer to 
> the dtype around, and just fill it in the first time it is needed.

Just to add my two eurocents: I think the patch is complicated enough that we could go the other way round: while parsing the ignore entries, we can plainly state that entries with a trailing slash are ignored:

-- snipsnap -- [PATCH] Warn if an ignore/exclude entry ends in a slash

Git does not like ignore entries ending in a slash; they will be ignored. So just be honest and warn the user about it.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
 dir.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/dir.c b/dir.c
index 1b9cc7a..c3e9a0d 100644
--- a/dir.c
+++ b/dir.c
@@ -135,6 +135,11 @@ void add_exclude(const char *string, const char *base,
 	}
 	x->pattern = string;
 	x->patternlen = strlen(string);
+	if (x->patternlen && x->pattern[x->patternlen - 1] == '/') {
+		warning("Ignoring ignore entry because of trailing slash: %s",
+			string);
+		return;
+	}
 	x->base = base;
 	x->baselen = baselen;
 	x->flags = 0;
Previous: Jeff KingNext: pradeep singh rautela
Message 14 of 20 in “Why does git track directory listed in .gitignore/".git/info/exclude"?”
  1. pradeep singh rautelaJan 23, 2008
  2. pradeep singh rautelaJan 23, 2008
  3. Linus TorvaldsJan 23, 2008
  4. pradeep singh rautelaJan 24, 2008
  5. Adam PiatyszekJan 30, 2008
  6. Junio C HamanoJan 30, 2008
  7. Junio C HamanoJan 30, 2008
  8. Adam PiatyszekJan 31, 2008
  9. *Re: Why does git track directory listed in .gitignore/".git/info/exclude"?Junio C Hamano, Jan 31, 2008
  10. gitignore(5): Allow "foo/" in ignore list to match directory "foo"Junio C Hamano, Jan 31, 2008
  11. Jeff KingJan 31, 2008
  12. Junio C HamanoJan 31, 2008
  13. Jeff KingJan 31, 2008
  14. Johannes SchindelinJan 31, 2008
  15. pradeep singh rautelaJan 31, 2008
  16. Junio C HamanoJan 31, 2008
  17. Adam PiatyszekJan 31, 2008
  18. Andreas EricssonFeb 1, 2008
  19. Adam PiatyszekJan 31, 2008
  20. Wayne DavisonJan 23, 2008

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.