git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 07/22] untracked cache: mark what dirs should be recursed/saved
Date: Sat,  8 Nov 2014 16:39:40 +0700	[thread overview]
Message-ID: <1415439595-469-8-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1415439595-469-1-git-send-email-pclouds@gmail.com>

If we redo this thing in a functional style, we would have one struct
untracked_dir as input tree and another as output. The input is used
for verification. The output is a brand new tree, reflecting current
worktree.

But that means recreate a lot of dir nodes even if a lot could be
shared between input and output trees in good cases. So we go with the
messy but efficient way, combining both input and output trees into
one. We need a way to know which node in this combined tree belongs to
the output. This is the purpose of this "recurse" flag.

"valid" bit can't be used for this because it's about data of the node
except the subdirs. When we invalidate a directory, we want to keep
cached data of the subdirs intact even though we don't really know
what subdir still exists (yet). Then we check worktree to see what
actual subdir remains on disk. Those will have 'recurse' bit set
again. If cached data for those are still valid, we may be able to
avoid computing exclude files for them. Those subdirs that are deleted
will have 'recurse' remained clear and their 'valid' bits do not
matter.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 dir.c | 14 +++++++++++++-
 dir.h |  3 ++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/dir.c b/dir.c
index f590761..32406bf 100644
--- a/dir.c
+++ b/dir.c
@@ -614,9 +614,12 @@ static void invalidate_gitignore(struct untracked_cache *uc,
 static void invalidate_directory(struct untracked_cache *uc,
 				 struct untracked_cache_dir *dir)
 {
+	int i;
 	uc->dir_invalidated++;
 	dir->valid = 0;
 	dir->untracked_nr = 0;
+	for (i = 0; i < dir->dirs_nr; i++)
+		dir->dirs[i]->recurse = 0;
 }
 
 /*
@@ -1576,6 +1579,10 @@ static int read_cached_dir(struct cached_dir *cdir)
 	}
 	while (cdir->nr_dirs < cdir->untracked->dirs_nr) {
 		struct untracked_cache_dir *d = cdir->untracked->dirs[cdir->nr_dirs];
+		if (!d->recurse) {
+			cdir->nr_dirs++;
+			continue;
+		}
 		cdir->ucd = d;
 		cdir->nr_dirs++;
 		return 0;
@@ -1597,8 +1604,10 @@ static void close_cached_dir(struct cached_dir *cdir)
 	 * We have gone through this directory and found no untracked
 	 * entries. Mark it valid.
 	 */
-	if (cdir->untracked)
+	if (cdir->untracked) {
 		cdir->untracked->valid = 1;
+		cdir->untracked->recurse = 1;
+	}
 }
 
 /*
@@ -1841,6 +1850,9 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
 		invalidate_gitignore(dir->untracked, root);
 		dir->untracked->ss_excludes_file = dir->ss_excludes_file;
 	}
+
+	/* Make sure this directory is not dropped out at saving phase */
+	root->recurse = 1;
 	return root;
 }
 
diff --git a/dir.h b/dir.h
index a755e49..5c688da 100644
--- a/dir.h
+++ b/dir.h
@@ -115,8 +115,9 @@ struct untracked_cache_dir {
 	unsigned int untracked_alloc, dirs_nr, dirs_alloc;
 	unsigned int untracked_nr;
 	unsigned int check_only : 1;
-	/* all data in this struct are good */
+	/* all data except 'dirs' in this struct are good */
 	unsigned int valid : 1;
+	unsigned int recurse : 1;
 	/* null SHA-1 means this directory does not have .gitignore */
 	unsigned char exclude_sha1[20];
 	char name[1];
-- 
2.1.0.rc0.78.gc0d8480

  parent reply	other threads:[~2014-11-08  9:40 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-27 12:10 [PATCH 00/19] Untracked cache to speed up "git status" Nguyễn Thái Ngọc Duy
2014-10-27 12:10 ` [PATCH 01/19] dir.c: optionally compute sha-1 of a .gitignore file Nguyễn Thái Ngọc Duy
2014-10-27 22:46   ` Junio C Hamano
2014-10-28  0:12     ` Duy Nguyen
2014-10-28 17:37   ` Torsten Bögershausen
2014-11-02  1:25     ` Duy Nguyen
2014-10-27 12:10 ` [PATCH 02/19] untracked cache: record .gitignore information and dir hierarchy Nguyễn Thái Ngọc Duy
2014-10-28 17:37   ` Torsten Bögershausen
2014-10-27 12:10 ` [PATCH 03/19] untracked cache: initial untracked cache validation Nguyễn Thái Ngọc Duy
2014-10-27 12:10 ` [PATCH 04/19] untracked cache: invalidate dirs recursively if .gitignore changes Nguyễn Thái Ngọc Duy
2014-10-27 12:10 ` [PATCH 05/19] untracked cache: make a wrapper around {open,read,close}dir() Nguyễn Thái Ngọc Duy
2014-10-27 12:10 ` [PATCH 06/19] untracked cache: record/validate dir mtime and reuse cached output Nguyễn Thái Ngọc Duy
2014-10-30 16:19   ` Eric Sunshine
2014-10-27 12:10 ` [PATCH 07/19] untracked cache: mark what dirs should be recursed/saved Nguyễn Thái Ngọc Duy
2014-10-27 12:10 ` [PATCH 08/19] untracked cache: don't open non-existent .gitignore Nguyễn Thái Ngọc Duy
2014-10-27 12:10 ` [PATCH 09/19] untracked cache: save to an index extension Nguyễn Thái Ngọc Duy
2014-10-27 12:10 ` [PATCH 10/19] untracked cache: load from UNTR " Nguyễn Thái Ngọc Duy
2014-10-27 12:10 ` [PATCH 11/19] untracked cache: invalidate at index addition or removal Nguyễn Thái Ngọc Duy
2014-10-27 12:10 ` [PATCH 12/19] read-cache.c: split racy stat test to a separate function Nguyễn Thái Ngọc Duy
2014-10-27 12:10 ` [PATCH 13/19] untracked cache: avoid racy timestamps Nguyễn Thái Ngọc Duy
2014-10-27 12:10 ` [PATCH 14/19] untracked cache: print stats with $GIT_TRACE_UNTRACKED_STATS Nguyễn Thái Ngọc Duy
2014-10-27 12:10 ` [PATCH 15/19] untracked cache: mark index dirty if untracked cache is updated Nguyễn Thái Ngọc Duy
2014-10-27 12:10 ` [PATCH 16/19] status: enable untracked cache Nguyễn Thái Ngọc Duy
2014-10-27 12:10 ` [PATCH 17/19] update-index: manually enable or disable " Nguyễn Thái Ngọc Duy
2014-10-27 12:10 ` [PATCH 18/19] update-index: test the system before enabling " Nguyễn Thái Ngọc Duy
2014-10-28 17:37   ` Torsten Bögershausen
2014-11-03 12:16     ` Duy Nguyen
2014-11-03 18:09     ` Junio C Hamano
2014-10-28 23:25   ` Eric Sunshine
2014-10-27 12:10 ` [PATCH 19/19] t7063: tests for " Nguyễn Thái Ngọc Duy
2014-11-08  9:39 ` [PATCH v2 00/22] untracked cache updates Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 01/22] dir.c: optionally compute sha-1 of a .gitignore file Nguyễn Thái Ngọc Duy
2014-11-17 19:31     ` David Turner
2014-11-08  9:39   ` [PATCH v2 02/22] untracked cache: record .gitignore information and dir hierarchy Nguyễn Thái Ngọc Duy
2014-11-08 17:08     ` brian m. carlson
2014-11-17 20:35     ` David Turner
2014-11-08  9:39   ` [PATCH v2 03/22] untracked cache: initial untracked cache validation Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 04/22] untracked cache: invalidate dirs recursively if .gitignore changes Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 05/22] untracked cache: make a wrapper around {open,read,close}dir() Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 06/22] untracked cache: record/validate dir mtime and reuse cached output Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` Nguyễn Thái Ngọc Duy [this message]
2014-11-08  9:39   ` [PATCH v2 08/22] untracked cache: don't open non-existent .gitignore Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 09/22] untracked cache: save to an index extension Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 10/22] untracked cache: load from UNTR " Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 11/22] untracked cache: invalidate at index addition or removal Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 12/22] read-cache.c: split racy stat test to a separate function Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 13/22] untracked cache: avoid racy timestamps Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 14/22] untracked cache: print stats with $GIT_TRACE_UNTRACKED_STATS Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 15/22] untracked cache: mark index dirty if untracked cache is updated Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 16/22] untracked-cache: temporarily disable with $GIT_DISABLE_UNTRACKED_CACHE Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 17/22] status: enable untracked cache Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 18/22] update-index: manually enable or disable " Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 19/22] update-index: test the system before enabling " Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 20/22] t7063: tests for " Nguyễn Thái Ngọc Duy
2014-11-08  9:39   ` [PATCH v2 21/22] mingw32: add uname() Nguyễn Thái Ngọc Duy
2014-11-09  3:32     ` Eric Sunshine
2014-11-09  8:36       ` Duy Nguyen
2014-11-09 11:46         ` Torsten Bögershausen
2014-11-09 18:47           ` Junio C Hamano
2014-11-08  9:39   ` [PATCH v2 22/22] untracked cache: guard and disable on system changes Nguyễn Thái Ngọc Duy
2014-11-09  3:39     ` Eric Sunshine
2014-11-09  8:34       ` Duy Nguyen
2014-11-09 21:39     ` Torsten Bögershausen
2014-11-09 23:47       ` Duy Nguyen
2014-11-10 20:48         ` Torsten Bögershausen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1415439595-469-8-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).