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

[RFC] Add posibility to preload stat information.

From
Fredrik Gustafsson <iveqy@iveqy.com>
Date
Mar 20, 2013, 12:15 UTC
Message-ID
<1363781732-11396-1-git-send-email-iveqy@iveqy.com>

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
Next: Jeff King
Message 1 of 13 in “[RFC] Add posibility to preload stat information.”
  1. Fredrik GustafssonMar 20, 2013
  2. Jeff KingMar 20, 2013
  3. Junio C HamanoMar 20, 2013
  4. Jeff KingMar 20, 2013
  5. Thomas RastMar 21, 2013
  6. Junio C HamanoMar 21, 2013
  7. Phil HordMar 30, 2013
  8. Fredrik GustafssonMar 20, 2013
  9. Ramkumar RamachandraMar 20, 2013
  10. Fredrik GustafssonMar 20, 2013
  11. Ramkumar RamachandraMar 20, 2013
  12. Fredrik GustafssonMar 20, 2013
  13. Jeff KingMar 20, 2013

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.