Commit 8f2ca62d67489d1f75ac4eb42590a9b720c66ccc

Stefan Sperling 2021-10-13T10:34:06

do not skip ignored directories in 'got status' if they contain tracked files Fixes regression introduced by commit 41f061b2f459318f3738f59d7676efccc4beb344 where tracked files inside an ignored directory were reported as missing.

diff --git a/lib/fileindex.c b/lib/fileindex.c
index fba8eb7..91a35e4 100644
--- a/lib/fileindex.c
+++ b/lib/fileindex.c
@@ -987,6 +987,30 @@ free_dirlist(struct got_pathlist_head *dirlist)
 	got_pathlist_free(dirlist);
 }
 
+static int
+have_tracked_file_in_dir(struct got_fileindex *fileindex, const char *path)
+{
+	struct got_fileindex_entry *ie;
+	size_t path_len = strlen(path);
+	int cmp;
+
+	ie = RB_ROOT(&fileindex->entries);
+	while (ie) {
+		if (got_path_is_child(ie->path, path, path_len))
+			return 1;
+		cmp = got_path_cmp(path, ie->path, path_len,
+		    got_fileindex_entry_path_len(ie));
+		if (cmp < 0)
+			ie = RB_LEFT(ie, entry);
+		else if (cmp > 0)
+			ie = RB_RIGHT(ie, entry);
+		else
+			break;
+	}
+
+	return 0;
+}
+
 static const struct got_error *
 walk_dir(struct got_pathlist_entry **next, struct got_fileindex *fileindex,
     struct got_fileindex_entry **ie, struct got_pathlist_entry *dle, int fd,
@@ -1013,6 +1037,11 @@ walk_dir(struct got_pathlist_entry **next, struct got_fileindex *fileindex,
 	} else
 		type = de->d_type;
 
+	/* Must traverse ignored directories if they contain tracked files. */
+	if (type == DT_DIR && ignore &&
+	    have_tracked_file_in_dir(fileindex, path))
+		ignore = 0;
+
 	if (type == DT_DIR && !ignore) {
 		char *subpath;
 		char *subdirpath;
diff --git a/regress/cmdline/status.sh b/regress/cmdline/status.sh
index 8b67476..9e58172 100755
--- a/regress/cmdline/status.sh
+++ b/regress/cmdline/status.sh
@@ -531,6 +531,7 @@ test_status_cvsignore() {
 	mkdir -p $testroot/wt/epsilon/new/
 	echo "unversioned file" > $testroot/wt/epsilon/new/foo
 	echo "**/foo" > $testroot/wt/.cvsignore
+	echo "**/gamma" >> $testroot/wt/.cvsignore
 	echo "bar" > $testroot/wt/epsilon/.cvsignore
 	echo "moo" >> $testroot/wt/epsilon/.cvsignore