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

[RFC 08/14] dir: convert add_excludes to take an index

From
BWBrandon Williams <bmwill@google.com>
Date
May 5, 2017, 19:53 UTC
Message-ID
<20170505195334.121856-9-bmwill@google.com>
In-Reply-To
<20170505195334.121856-1-bmwill@google.com>
Signed-off-by: Brandon Williams <bmwill@google.com>
---
 dir.c          | 29 +++++++++++++++--------------
 dir.h          |  2 +-
 unpack-trees.c |  2 +-
 3 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/dir.c b/dir.c
index 497a2db85..b86d02ff9 100644
--- a/dir.c
+++ b/dir.c
@@ -730,7 +730,7 @@ static void invalidate_directory(struct untracked_cache *uc,
 
 /*
  * Given a file with name "fname", read it (either from disk, or from
- * the index if "check_index" is non-zero), parse it and store the
+ * an index if 'istate' is non-null), parse it and store the
  * exclude rules in "el".
  *
  * If "ss" is not NULL, compute SHA-1 of the exclude file and fill
@@ -738,7 +738,8 @@ static void invalidate_directory(struct untracked_cache *uc,
  * ss_valid is non-zero, "ss" must contain good value as input.
  */
 static int add_excludes(const char *fname, const char *base, int baselen,
-			struct exclude_list *el, int check_index,
+			struct exclude_list *el,
+			struct index_state *istate,
 			struct sha1_stat *sha1_stat)
 {
 	struct stat st;
@@ -752,8 +753,8 @@ static int add_excludes(const char *fname, const char *base, int baselen,
 			warn_on_inaccessible(fname);
 		if (0 <= fd)
 			close(fd);
-		if (!check_index ||
-		    (buf = read_skip_worktree_file_from_index(&the_index, fname, &size, sha1_stat)) == NULL)
+		if (!istate ||
+		    (buf = read_skip_worktree_file_from_index(istate, fname, &size, sha1_stat)) == NULL)
 			return -1;
 		if (size == 0) {
 			free(buf);
@@ -785,15 +786,15 @@ static int add_excludes(const char *fname, const char *base, int baselen,
 		if (sha1_stat) {
 			int pos;
 			if (sha1_stat->valid &&
-			    !match_stat_data_racy(&the_index, &sha1_stat->stat, &st))
+			    !match_stat_data_racy(istate, &sha1_stat->stat, &st))
 				; /* no content change, ss->sha1 still good */
-			else if (check_index &&
-				 (pos = index_name_pos(&the_index, fname, strlen(fname))) >= 0 &&
-				 !ce_stage(the_index.cache[pos]) &&
-				 ce_uptodate(the_index.cache[pos]) &&
+			else if (istate &&
+				 (pos = index_name_pos(istate, fname, strlen(fname))) >= 0 &&
+				 !ce_stage(istate->cache[pos]) &&
+				 ce_uptodate(istate->cache[pos]) &&
 				 !would_convert_to_git(fname))
 				hashcpy(sha1_stat->sha1,
-					the_index.cache[pos]->oid.hash);
+					istate->cache[pos]->oid.hash);
 			else
 				hash_sha1_file(buf, size, "blob", sha1_stat->sha1);
 			fill_stat_data(&sha1_stat->stat, &st);
@@ -824,9 +825,9 @@ static int add_excludes(const char *fname, const char *base, int baselen,
 
 int add_excludes_from_file_to_list(const char *fname, const char *base,
 				   int baselen, struct exclude_list *el,
-				   int check_index)
+				   struct index_state *istate)
 {
-	return add_excludes(fname, base, baselen, el, check_index, NULL);
+	return add_excludes(fname, base, baselen, el, istate, NULL);
 }
 
 struct exclude_list *add_exclude_list(struct dir_struct *dir,
@@ -858,7 +859,7 @@ static void add_excludes_from_file_1(struct dir_struct *dir, const char *fname,
 	if (!dir->untracked)
 		dir->unmanaged_exclude_files++;
 	el = add_exclude_list(dir, EXC_FILE, fname);
-	if (add_excludes(fname, "", 0, el, 0, sha1_stat) < 0)
+	if (add_excludes(fname, "", 0, el, NULL, sha1_stat) < 0)
 		die("cannot use %s as an exclude file", fname);
 }
 
@@ -1166,7 +1167,7 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)
 			strbuf_addbuf(&sb, &dir->basebuf);
 			strbuf_addstr(&sb, dir->exclude_per_dir);
 			el->src = strbuf_detach(&sb, NULL);
-			add_excludes(el->src, el->src, stk->baselen, el, 1,
+			add_excludes(el->src, el->src, stk->baselen, el, &the_index,
 				     untracked ? &sha1_stat : NULL);
 		}
 		/*
diff --git a/dir.h b/dir.h
index 64254c7e7..1bcda0d23 100644
--- a/dir.h
+++ b/dir.h
@@ -243,7 +243,7 @@ extern int is_excluded(struct dir_struct *dir, const char *name, int *dtype);
 extern struct exclude_list *add_exclude_list(struct dir_struct *dir,
 					     int group_type, const char *src);
 extern int add_excludes_from_file_to_list(const char *fname, const char *base, int baselen,
-					  struct exclude_list *el, int check_index);
+					  struct exclude_list *el, struct  index_state *istate);
 extern void add_excludes_from_file(struct dir_struct *, const char *fname);
 extern void parse_exclude_pattern(const char **string, int *patternlen, unsigned *flags, int *nowildcardlen);
 extern void add_exclude(const char *string, const char *base,
diff --git a/unpack-trees.c b/unpack-trees.c
index 9bcb13e4f..5b19849e4 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1223,7 +1223,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 		o->skip_sparse_checkout = 1;
 	if (!o->skip_sparse_checkout) {
 		char *sparse = git_pathdup("info/sparse-checkout");
-		if (add_excludes_from_file_to_list(sparse, "", 0, &el, 0) < 0)
+		if (add_excludes_from_file_to_list(sparse, "", 0, &el, NULL) < 0)
 			o->skip_sparse_checkout = 1;
 		else
 			o->el = &el;
-- 
2.13.0.rc1.294.g07d810a77f-goog
Previous: Brandon WilliamsNext: Brandon Williams
Message 13 of 18 in “[RFC 00/14] convert dir.c to take an index parameter”
  1. Brandon WilliamsMay 5, 2017
  2. 01/14 dir: stop using the index compatibility macrosBrandon Williams, May 5, 2017
  3. 02/14 dir: convert read_skip_worktree_file_from_index to take an indexBrandon Williams, May 5, 2017
  4. 04/14 dir: convert get_dtype to take indexBrandon Williams, May 5, 2017
  5. 05/14 dir: convert dir_add* to take an indexBrandon Williams, May 5, 2017
  6. 06/14 dir: convert last_exclude_matching_from_list to take an indexBrandon Williams, May 5, 2017
  7. 07/14 dir: convert is_excluded_from_list to take an indexBrandon Williams, May 5, 2017
  8. 12/14 dir: convert read_directory_recursive to take an indexBrandon Williams, May 5, 2017
  9. 14/14 dir: convert fill_directory to take an indexBrandon Williams, May 5, 2017
  10. 13/14 dir: convert read_directory to take an indexBrandon Williams, May 5, 2017
  11. 10/14 dir: convert is_excluded to take an indexBrandon Williams, May 5, 2017
  12. 11/14 dir: convert open_cached_dir to take an indexBrandon Williams, May 5, 2017
  13. 08/14 dir: convert add_excludes to take an indexBrandon Williams, May 5, 2017
  14. 03/14 dir: convert directory_exists_in_index to take indexBrandon Williams, May 5, 2017
  15. 09/14 dir: convert prep_exclude to take an indexBrandon Williams, May 5, 2017
  16. Junio C HamanoMay 6, 2017
  17. Brandon WilliamsMay 8, 2017
  18. Jeff HostetlerMay 8, 2017

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.