git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] Add posibility to preload stat information.
@ 2013-03-20 12:15 Fredrik Gustafsson
  2013-03-20 16:48 ` Jeff King
  2013-03-20 17:15 ` Ramkumar Ramachandra
  0 siblings, 2 replies; 13+ messages in thread
From: Fredrik Gustafsson @ 2013-03-20 12:15 UTC (permalink / raw)
  To: spearce; +Cc: git, pclouds, iveqy

When entering a git working dir, optionally run a forked process that
stat all files in the whole workdir and therefore loads stat information
to RAM which will speedup things like git status and so on.

The feature is optional and by default it's off.

Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>
---
 contrib/completion/git-prompt.sh | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 341422a..e67bc97 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -78,6 +78,12 @@
 # If you would like a colored hint about the current dirty state, set
 # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
 # the colored output of "git status -sb".
+#
+# When enter a git work dir you can have a forked process run
+# stat on all files in the top level directory for git and down.
+# This will decrease later calls to git status and alike because
+# stat info will already be loaded into RAM. set GIT_PRE_STAT to
+# a nonempty value.
 
 # __gitdir accepts 0 or 1 arguments (i.e., location)
 # returns location of .git repo
@@ -222,6 +228,19 @@ __git_ps1_show_upstream ()
 
 }
 
+# Forks and recursive do a stat from the toplevel git dir.
+# This will load inodes into RAM for faster access when running
+# A git command, like git show.
+__git_recursive_stat ()
+{
+	if test ! -e /tmp/gitbash.lock
+	then
+		touch /tmp/gitbash.lock
+		cd $(git rev-parse --show-toplevel)
+		find . | xargs stat 2&> /dev/null
+		rm /tmp/gitbash.lock
+	fi
+}
 
 # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
 # when called from PS1 using command substitution
@@ -320,6 +339,10 @@ __git_ps1 ()
 				b="GIT_DIR!"
 			fi
 		elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
+			if [ -n "${GIT_PRE_STAT-}" ];
+			then
+				(__git_recursive_stat 2&> /dev/null &)
+			fi
 			if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
 			   [ "$(git config --bool bash.showDirtyState)" != "false" ]
 			then
-- 
1.8.1.5

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2013-03-30 19:43 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-20 12:15 [RFC] Add posibility to preload stat information Fredrik Gustafsson
2013-03-20 16:48 ` Jeff King
2013-03-20 17:15   ` Junio C Hamano
2013-03-20 17:47     ` Jeff King
2013-03-21 10:41       ` Thomas Rast
2013-03-21 14:44         ` Junio C Hamano
2013-03-30 19:42           ` Phil Hord
2013-03-20 18:40   ` Fredrik Gustafsson
2013-03-20 17:15 ` Ramkumar Ramachandra
2013-03-20 17:41   ` Fredrik Gustafsson
2013-03-20 17:49     ` Ramkumar Ramachandra
2013-03-20 18:36       ` Fredrik Gustafsson
2013-03-20 18:46         ` Jeff King

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).