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

[PATCH v2 0/2] fsexcludes: Add programmatic way to exclude files

From
Ben Peart <ben.peart@microsoft.com>
Date
Apr 11, 2018, 20:01 UTC
Message-ID
<20180411200007.8612-1-benpeart@microsoft.com>
In-Reply-To
<20180410210408.13788-1-benpeart@microsoft.com>
Updated to incorporate feedback from V1.

I'd really like a close review of the changes in dir.c where I added the calls to fsexcludes_is_excluded_from(). While they work and pass all the git tests as well as our internal functional tests, I'd like to be sure I haven't missed anything.

Base Ref: master
Web-Diff: https://github.com/benpeart/git/commit/08442c209d
Checkout: git fetch https://github.com/benpeart/git fsexcludes-v2 && git checkout 08442c209d
### Interdiff (v1..v2):
diff --git a/fsexcludes.c b/fsexcludes.c
index 07bfe376a0..0ef57f107b 100644
--- a/fsexcludes.c
+++ b/fsexcludes.c
@@ -33,7 +33,6 @@ static int check_fsexcludes_hashmap(struct hashmap *map, const char *pattern, in
 	char *slash;
 
 	/* Check straight mapping */
-	strbuf_reset(&sb);
 	strbuf_add(&sb, pattern, patternlen);
 	fse.pattern = sb.buf;
 	fse.patternlen = sb.len;
@@ -155,7 +154,6 @@ static int check_directory_hashmap(struct hashmap *map, const char *pathname, in
 	struct fsexcludes fse;
 
 	/* Check for directory */
-	strbuf_reset(&sb);
 	strbuf_add(&sb, pathname, pathlen);
 	strbuf_addch(&sb, '/');
 	fse.pattern = sb.buf;
@@ -198,13 +196,16 @@ int fsexcludes_is_excluded_from(struct index_state *istate,
 	return -1;
 }
 
-void fsexcludes_init(struct strbuf *sb) {
+void fsexcludes_init(struct strbuf *sb)
+{
 	fsexcludes_initialized = 1;
 	fsexcludes_data = *sb;
+	strbuf_detach(sb, NULL);
 }
 
-void fsexcludes_free() {
+void fsexcludes_free(void) {
 	strbuf_release(&fsexcludes_data);
 	hashmap_free(&fsexcludes_hashmap, 1);
 	hashmap_free(&parent_directory_hashmap, 1);
+	fsexcludes_initialized = 0;
 }
diff --git a/fsexcludes.h b/fsexcludes.h
index 1c4101343c..10246daa02 100644
--- a/fsexcludes.h
+++ b/fsexcludes.h
@@ -6,16 +6,18 @@
  * where git will scan for untracked files.  This is used to speed up the
  * scan by avoiding scanning parts of the work directory that do not have
  * any new files.
- *
  */
 
 /*
  * sb should contain a NUL separated list of path names of the files
  * and/or directories that should be checked.  Any path not listed will
  * be excluded from the scan.
+ *
+ * NOTE: fsexcludes_init() will take ownership of the storage passed in
+ * sb and will reset sb to `STRBUF_INIT`
  */
 void fsexcludes_init(struct strbuf *sb);
-void fsexcludes_free();
+void fsexcludes_free(void);
 
 /*
  * Return 1 for exclude, 0 for include and -1 for undecided.


### Patches

Ben Peart (2):
  fsexcludes: add a programmatic way to exclude files from git's working
    directory traversal logic
  fsmonitor: switch to use new fsexcludes logic and remove unused
    untracked cache based logic

 Makefile                    |   1 +
 dir.c                       |  33 ++++--
 dir.h                       |   2 -
 fsexcludes.c                | 211 ++++++++++++++++++++++++++++++++++++
 fsexcludes.h                |  29 +++++
 fsmonitor.c                 |  21 +---
 fsmonitor.h                 |  10 +-
 t/t7519-status-fsmonitor.sh |  14 +--
 8 files changed, 273 insertions(+), 48 deletions(-)
 create mode 100644 fsexcludes.c
 create mode 100644 fsexcludes.h


base-commit: 0b0cc9f86731f894cff8dd25299a9b38c254569e
-- 
2.17.0.windows.1
Previous: Junio C HamanoNext: Ben Peart
Message 7 of 17 in “fsexcludes: Add programmatic way to exclude files”
  1. 0/2 fsexcludes: Add programmatic way to exclude filesBen Peart, Apr 10, 2018
  2. 2/2 fsmonitor: switch to use new fsexcludes logic and remove unused untracked cache based logicBen Peart, Apr 10, 2018
  3. 1/2 fsexcludes: add a programmatic way to exclude files from git's working directory traversal logicBen Peart, Apr 10, 2018
  4. Martin ÅgrenApr 10, 2018
  5. Ben PeartApr 11, 2018
  6. Junio C HamanoApr 11, 2018
  7. 0/2 fsexcludes: Add programmatic way to exclude filesBen Peart, Apr 11, 2018
  8. 1/2 fsexcludes: add a programmatic way to exclude files from git's working directory traversal logicBen Peart, Apr 11, 2018
  9. Junio C HamanoApr 11, 2018
  10. Ben PeartApr 13, 2018
  11. 2/2 fsmonitor: switch to use new fsexcludes logic and remove unused untracked cache based logicBen Peart, Apr 11, 2018
  12. 0/2 fsexcludes: Add programmatic way to exclude filesBen Peart, Apr 13, 2018
  13. 1/2 fsexcludes: add a programmatic way to exclude files from git's working directory traversal logicBen Peart, Apr 13, 2018
  14. 2/2 fsmonitor: switch to use new fsexcludes logic and remove unused untracked cache based logicBen Peart, Apr 13, 2018
  15. Ben PeartApr 18, 2018
  16. Junio C HamanoApr 18, 2018
  17. Duy NguyenApr 14, 2018

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.