Skip to content

nd/untracked-cache updates

Nguyễn Thái Ngọc Duy git 3 versions In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest23 patches 9 repliesIn review
  2. v222 patches 12 repliesSuperseded
  3. v119 patches 10 repliesSuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/23dir.c: optionally compute sha-1 of a .gitignore filedir.c dir.h+52 -70 replies
2/23untracked cache: record .gitignore information and dir hierarchydir.c dir.h+183 -190 replies
3/23untracked cache: initial untracked cache validationdir.c dir.h+114 -30 replies
4/23untracked cache: invalidate dirs recursively if .gitignore changesdir.c+17 -10 replies
5/23untracked cache: make a wrapper around {open,read,close}dir()dir.c+47 -80 replies
6/23untracked cache: record/validate dir mtime and reuse cached outputdir.c dir.h+121 -20 replies
7/23untracked cache: mark what dirs should be recursed/saveddir.c dir.h+15 -20 replies
8/23untracked cache: don't open non-existent .gitignoredir.c+25 -10 replies
9/23ewah: add convenient wrapper ewah_serialize_strbuf()ewah/ewah_io.c ewah/ewok.h split-index.c+17 -90 replies
10/23untracked cache: save to an index extensionDocumentation/technical/index-format.txt cache.h dir.c +2 more+208 -02 replies
11/23untracked cache: load from UNTR index extensiondir.c dir.h read-cache.c+227 -01 reply
12/23untracked cache: invalidate at index addition or removaldir.c dir.h read-cache.c +1 more+44 -20 replies
13/23read-cache.c: split racy stat test to a separate functionread-cache.c+15 -90 replies
14/23untracked cache: avoid racy timestampscache.h dir.c read-cache.c+12 -20 replies
15/23untracked cache: print stats with $GIT_TRACE_UNTRACKED_STATSdir.c+12 -00 replies
16/23untracked cache: mark index dirty if untracked cache is updatedcache.h dir.c read-cache.c+11 -10 replies
17/23untracked-cache: temporarily disable with $GIT_DISABLE_UNTRACKED_CACHEdir.c+1 -10 replies
18/23status: enable untracked cachebuiltin/commit.c wt-status.c+5 -20 replies
19/23update-index: manually enable or disable untracked cacheDocumentation/git-update-index.txt builtin/update-index.c+24 -00 replies
20/23update-index: test the system before enabling untracked cacheDocumentation/git-update-index.txt builtin/update-index.c+154 -00 replies
21/23t7063: tests for untracked cache.gitignore Makefile t/t7063-status-untracked-cache.sh +1 more+416 -00 replies
22/23mingw32: add uname()compat/mingw.c compat/mingw.h+20 -00 replies
23/23untracked cache: guard and disable on system changesDocumentation/technical/index-format.txt dir.c git-compat-util.h +1 more+33 -06 replies

Reviews trailers per patch

None of the 23 patches has a Reviewed-by or Acked-by.

PatchEric SunshineJunio C HamanoTorsten BögershausenDavid TurnerRamsay Jones
1/23Helped-by Helped-by
2/23Helped-by Helped-by
3/23
4/23
5/23Helped-by
6/23Helped-by
7/23
8/23
9/23
10/23
11/23
12/23
13/23
14/23
15/23
16/23
17/23
18/23
19/23
20/23Helped-by
21/23
22/23Helped-by
23/23Helped-by

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 5 reviewers.

Read the v3 thread

Cover letter [PATCH v3 00/23] nd/untracked-cache updates

Compare to v1 (the one on 'pu' as v2 never got to 'pu'):

- New cleanup patch 09/23

- New patch 17/23 allows to ignore untracked cache without destroying it (for comparison and verification)

- New patches 22/23 and 23/23 add some protection against filesystem or operating system changes

- Document UNTR extension

- Reorganize UNTR to avoid saving SHA-1/stat data when it's useless

- Fix writing UNTR to base index in split index mode

- Various review comments since v1

-- 8< --

Documentation/technical/index-format.txt +61 -0
index fe6f316..5dc2bee 100644
@@ -233,3 +233,64 @@ Git index format
   The remaining index entries after replaced ones will be added to the
   final index. These added entries are also sorted by entry namme then
   stage.
+
+== Untracked cache
+
+  Untracked cache saves the untracked file list and necessary data to
+  verify the cache. The signature for this extension is { 'U', 'N',
+  'T', 'R' }.
+
+  The extension starts with
+
+  - A NUL-terminated string describing the environment when the cache
+    is created.
+
+  - Stat data of $GIT_DIR/info/exclude. See "Index entry" section from
+    ctime field until "file size".
+
+  - Stat data of core.excludesfile
+
+  - 32-bit dir_flags (see struct dir_struct)
+
+  - 160-bit SHA-1 of $GIT_DIR/info/exclude. Null SHA-1 means the file
+    does not exist.
+
+  - 160-bit SHA-1 of core.excludesfile. Null SHA-1 means the file does
+    not exist.
+
+  - NUL-terminated string of per-dir exclude file name. This usually
+    is ".gitignore".
+
+  - The number of following directory blocks, variable width
+    encoding. If this number is zero, the extension ends here with a
+    following NUL.
+
+  - A number of directory blocks in depth-first-search order, each
+    consists of
+
+    - The number of untracked entries, variable witdh encoding.
+
+    - The number of sub-directory blocks, variable with encoding.
+
+    - The directory name terminated by NUL.
+
+    - A number of untrached file/dir names terminated by NUL.
+
+The remaining data of each directory block is grouped by type:
+
+  - An ewah bitmap, the n-th bit marks whether the n-th directory has
+    valid untracked cache entries.
+
+  - An ewah bitmap, the n-th bit records "check-only" bit of
+    read_directory_recursive() for the n-th directory.
+
+  - An ewah bitmap, the n-th bit indicates whether SHA-1 and stat data
+    is valid for the n-th directory and exists in the next data.
+
+  - An array of stat data. The n-th data corresponds with the n-th
+    "one" bit in the previous ewah bitmap.
+
+  - An array of SHA-1. The n-th SHA-1 corresponds with the n-th "one" bit
+    in the previous ewah bitmap.
+
+  - One NUL.
builtin/update-index.c +4 -2
index c1c18db..f23ec83 100644
@@ -115,6 +115,7 @@ static int test_if_untracked_cache_is_supported(void)
 	fd = create_file("dir-mtime-test/newfile");
 	xstat("dir-mtime-test", &st);
 	if (!match_stat_data(&base, &st)) {
+		close(fd);
 		fputc('\n', stderr);
 		fprintf_ln(stderr,_("directory stat info does not "
 				    "change after adding a new file"));
@@ -127,6 +128,7 @@ static int test_if_untracked_cache_is_supported(void)
 	xmkdir("dir-mtime-test/new-dir");
 	xstat("dir-mtime-test", &st);
 	if (!match_stat_data(&base, &st)) {
+		close(fd);
 		fputc('\n', stderr);
 		fprintf_ln(stderr, _("directory stat info does not change "
 				     "after adding a new directory"));
@@ -1094,10 +1096,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
 		/* should be the same flags used by git-status */
 		uc->dir_flags = DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
 		the_index.untracked = uc;
-		the_index.cache_changed |= SOMETHING_CHANGED;
+		the_index.cache_changed |= UNTRACKED_CHANGED;
 	} else if (!untracked_cache && the_index.untracked) {
 		the_index.untracked = NULL;
-		the_index.cache_changed |= SOMETHING_CHANGED;
+		the_index.cache_changed |= UNTRACKED_CHANGED;
 	}
 
 	if (active_cache_changed) {
cache.h +1 -1
index 201b22e..fca979b 100644
@@ -295,7 +295,7 @@ static inline unsigned int canon_mode(unsigned int mode)
 #define RESOLVE_UNDO_CHANGED	(1 << 4)
 #define CACHE_TREE_CHANGED	(1 << 5)
 #define SPLIT_INDEX_ORDERED	(1 << 6)
-#define UNTRACKED_CHANGED       (1 << 7)
+#define UNTRACKED_CHANGED	(1 << 7)
 
 struct split_index;
 struct untracked_cache;
compat/mingw.c +11 -0
index c5c37e5..88140e4 100644
@@ -2128,3 +2128,14 @@ void mingw_startup()
 	/* initialize Unicode console */
 	winansi_init();
 }
+
+int uname(struct utsname *buf)
+{
+	DWORD v = GetVersion();
+	memset(buf, 0, sizeof(*buf));
+	strcpy(buf->sysname, "Windows");
+	sprintf(buf->release, "%u.%u", v & 0xff, (v >> 8) & 0xff);
+	/* assuming NT variants only.. */
+	sprintf(buf->version, "%u", (v >> 16) & 0x7fff);
+	return 0;
+}
compat/mingw.h +9 -0
index df0e320..d00ba7a 100644
@@ -77,6 +77,14 @@ struct itimerval {
 };
 #define ITIMER_REAL 0
 
+struct utsname {
+	char sysname[16];
+	char nodename[1];
+	char release[16];
+	char version[16];
+	char machine[1];
+};
+
 /*
  * sanitize preprocessor namespace polluted by Windows headers defining
  * macros which collide with git local versions
@@ -166,6 +174,7 @@ struct passwd *getpwuid(uid_t uid);
 int setitimer(int type, struct itimerval *in, struct itimerval *out);
 int sigaction(int sig, struct sigaction *in, struct sigaction *out);
 int link(const char *oldpath, const char *newpath);
+int uname(struct utsname *buf);
 
 /*
  * replacements of existing functions
dir.c +260 -105

598 lines not on this page · raw message

dir.h +8 -8
index 8c29324..2ce7dd3 100644
@@ -77,6 +77,7 @@ struct exclude_list_group {
 struct sha1_stat {
 	struct stat_data stat;
 	unsigned char sha1[20];
+	int valid;
 };
 
 /*
@@ -85,7 +86,7 @@ struct sha1_stat {
  *  The following inputs are sufficient to determine what files in a
  *  directory are excluded:
  *
- *   - The list of files and directories of the direction in question
+ *   - The list of files and directories of the directory in question
  *   - The $GIT_DIR/index
  *   - dir_struct flags
  *   - The content of $GIT_DIR/info/exclude
@@ -110,16 +111,16 @@ struct sha1_stat {
 struct untracked_cache_dir {
 	struct untracked_cache_dir **dirs;
 	char **untracked;
-	/* null SHA-1 means this directory does not have .gitignore */
-	unsigned char exclude_sha1[20];
 	struct stat_data stat_data;
-	unsigned int recurse : 1;
+	unsigned int untracked_alloc, dirs_nr, dirs_alloc;
+	unsigned int untracked_nr;
 	unsigned int check_only : 1;
 	/* all data except 'dirs' in this struct are good */
 	unsigned int valid : 1;
-	unsigned int untracked_nr : 29;
-	unsigned int untracked_alloc, dirs_nr, dirs_alloc;
-	char name[1];
+	unsigned int recurse : 1;
+	/* null SHA-1 means this directory does not have .gitignore */
+	unsigned char exclude_sha1[20];
+	char name[FLEX_ARRAY];
 };
 
 struct untracked_cache {
@@ -137,7 +138,6 @@ struct untracked_cache {
 	int gitignore_invalidated;
 	int dir_invalidated;
 	int dir_opened;
-	int loaded;
 };
 
 struct dir_struct {
ewah/ewah_io.c +13 -0
index 1c2d7af..43481b9 100644
@@ -19,6 +19,7 @@
  */
 #include "git-compat-util.h"
 #include "ewok.h"
+#include "strbuf.h"
 
 int ewah_serialize_native(struct ewah_bitmap *self, int fd)
 {
@@ -110,6 +111,18 @@ int ewah_serialize(struct ewah_bitmap *self, int fd)
 	return ewah_serialize_to(self, write_helper, (void *)(intptr_t)fd);
 }
 
+static int write_strbuf(void *user_data, const void *data, size_t len)
+{
+	struct strbuf *sb = user_data;
+	strbuf_add(sb, data, len);
+	return len;
+}
+
+int ewah_serialize_strbuf(struct ewah_bitmap *self, struct strbuf *sb)
+{
+	return ewah_serialize_to(self, write_strbuf, sb);
+}
+
 int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len)
 {
 	const uint8_t *ptr = map;
ewah/ewok.h +2 -0
index f6ad190..4d7f5e9 100644
@@ -30,6 +30,7 @@
 #	define ewah_calloc xcalloc
 #endif
 
+struct strbuf;
 typedef uint64_t eword_t;
 #define BITS_IN_WORD (sizeof(eword_t) * 8)
 
@@ -97,6 +98,7 @@ int ewah_serialize_to(struct ewah_bitmap *self,
 		      void *out);
 int ewah_serialize(struct ewah_bitmap *self, int fd);
 int ewah_serialize_native(struct ewah_bitmap *self, int fd);
+int ewah_serialize_strbuf(struct ewah_bitmap *self, struct strbuf *);
 
 int ewah_deserialize(struct ewah_bitmap *self, int fd);
 int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len);
git-compat-util.h +1 -0
index f587749..e9502a1 100644
@@ -132,6 +132,7 @@
 #elif defined(_MSC_VER)
 #include "compat/msvc.h"
 #else
+#include <sys/utsname.h>
 #include <sys/wait.h>
 #include <sys/resource.h>
 #include <sys/socket.h>
read-cache.c +1 -1
index 21ae963..71d8e20 100644
@@ -2040,7 +2040,7 @@ static int do_write_index(struct index_state *istate, int newfd,
 		if (err)
 			return -1;
 	}
-	if (istate->untracked) {
+	if (!strip_extensions && istate->untracked) {
 		struct strbuf sb = STRBUF_INIT;
 
 		write_untracked_extension(&sb, istate->untracked);
split-index.c +2 -9
index 21485e2..968b780 100644
@@ -41,13 +41,6 @@ int read_link_extension(struct index_state *istate,
 	return 0;
 }
 
-static int write_strbuf(void *user_data, const void *data, size_t len)
-{
-	struct strbuf *sb = user_data;
-	strbuf_add(sb, data, len);
-	return len;
-}
-
 int write_link_extension(struct strbuf *sb,
 			 struct index_state *istate)
 {
@@ -55,8 +48,8 @@ int write_link_extension(struct strbuf *sb,
 	strbuf_add(sb, si->base_sha1, 20);
 	if (!si->delete_bitmap && !si->replace_bitmap)
 		return 0;
-	ewah_serialize_to(si->delete_bitmap, write_strbuf, sb);
-	ewah_serialize_to(si->replace_bitmap, write_strbuf, sb);
+	ewah_serialize_strbuf(si->delete_bitmap, sb);
+	ewah_serialize_strbuf(si->replace_bitmap, sb);
 	return 0;
 }
 
test-dump-untracked-cache.c +1 -0
index 710441e..25d855d 100644
@@ -44,6 +44,7 @@ int main(int ac, char **av)
 {
 	struct untracked_cache *uc;
 	struct strbuf base = STRBUF_INIT;
+	setup_git_directory();
 	if (read_cache() < 0)
 		die("unable to read index file");
 	uc = the_index.untracked;

-- 8< --

Signature · 1 line
2.2.0.60.gb7b3c64