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

[PATCH 2/2] bash prompt: faster untracked status indicator with untracked directories

From
SZEDER Gábor <szeder@ira.uka.de>
Date
Jul 19, 2015, 11:28 UTC
Message-ID
<1437305286-23587-2-git-send-email-szeder@ira.uka.de>
In-Reply-To
<1437305286-23587-1-git-send-email-szeder@ira.uka.de>

If the untracked status indicator is enabled, __git_ps1() looks for untracked files by running 'git ls-files'. This can be perceptibly slow in case of an untracked directory containing lot of files, because it lists all files found in the untracked directory only to be redirected into /dev/null right away (this is the actual command run by __git_ps1()):

  $ ls untracked-dir/ |wc -l
  100000
  $ time git ls-files --others --exclude-standard --error-unmatch \
    -- ':/*' >/dev/null 2>/dev/null
  real	0m0.955s
  user	0m0.936s
  sys	0m0.016s

Eliminate this delay by additionally passing the '--directory --no-empty-directory' options to 'git ls-files' to show only the name of non-empty untracked directories instead of all their content:

  $ time git ls-files --others --exclude-standard --directory \
    --no-empty-directory --error-unmatch -- ':/*' >/dev/null 2>/dev/null
  real	0m0.010s
  user	0m0.008s
  sys	0m0.000s

This follows suit of ea95c7b8f5 (completion: improve untracked directory filtering for filename completion, 2013-09-18).

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-prompt.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 366f0bc1e9..07b52bedf1 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -491,7 +491,7 @@ __git_ps1 ()
 
 		if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
 		   [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
-		   git ls-files --others --exclude-standard --error-unmatch -- ':/*' >/dev/null 2>/dev/null
+		   git ls-files --others --exclude-standard --directory --no-empty-directory --error-unmatch -- ':/*' >/dev/null 2>/dev/null
 		then
 			u="%${ZSH_VERSION+%}"
 		fi
-- 
2.5.0.rc2.15.gd82f7f6
Previous: SZEDER Gábor
Message 2 of 2 in “bash prompt: test untracked files status indicator with untracked dirs”
  1. 1/2 bash prompt: test untracked files status indicator with untracked dirsSZEDER Gábor, Jul 19, 2015
  2. 2/2 bash prompt: faster untracked status indicator with untracked directoriesSZEDER Gábor, Jul 19, 2015

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.