Re: [RFC] Add posibility to preload stat information.

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [RFC] Add posibility to preload stat information.

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:56:28

Thomas Rast [off-list ref] writes:
I think it would actually be a somewhat interesting feature if it
interacted with GIT_PS1_SHOW*.  If you use these settings (I personally
use SHOWDIRTYSTATE but not SHOWUNTRACKEDFILES), the prompt hangs while
__git_ps1 runs git-status.  It should be possible to run a git-status
process in the background when entering a repository, and displaying
some marker ('??' maybe) in the prompt instead of the dirty-state info
until git-status has finished.
This is somewhat interesting.

Perhaps we can introduce a helper binary that does what __git_ps1()
does, with a --timeout=500ms option to say "I dunno (yet)", and keep
priming the well in the background when it takes more than the
specified amount of time?

Re: [RFC] Add posibility to preload stat information.

From: Phil Hord <hidden>
Date: 2016-06-15 22:56:34

On Thu, Mar 21, 2013 at 10:44 AM, Junio C Hamano [off-list ref] wrote:
Thomas Rast [off-list ref] writes:
quoted
I think it would actually be a somewhat interesting feature if it
interacted with GIT_PS1_SHOW*.  If you use these settings (I personally
use SHOWDIRTYSTATE but not SHOWUNTRACKEDFILES), the prompt hangs while
__git_ps1 runs git-status.  It should be possible to run a git-status
process in the background when entering a repository, and displaying
some marker ('??' maybe) in the prompt instead of the dirty-state info
until git-status has finished.
This is somewhat interesting.

Perhaps we can introduce a helper binary that does what __git_ps1()
does, with a --timeout=500ms option to say "I dunno (yet)", and keep
priming the well in the background when it takes more than the
specified amount of time?
That would be nice.  My fork-fu is weak, so I cheated and relied on
kill/timeout instead.

I have had this code below in my zsh git prompt (based on oh-my-zsh)
for more than a year.  It uses $(timeout) to kill the status command
if it does not complete in 1 second.  It's dumb in several ways, but
it does show me four different flags fairly reliably indicating
whether I have changed files, untracked files, clean workdir, or I
timed out trying to find out.

git_dirty_timeout () {
  #-- Modified files
  xx=$(timeout 1s git status -s $@ 2> /dev/null)
  test $? -eq 124 && return 124
  test -n ${xx} && return 50

  #-- Untracked files (only)
  xx=$(timeout 1s git status -s -uno $@ 2> /dev/null)
  test $? -eq 124 && return 124
  test -n ${xx} && return 51
  return 0
}

parse_git_dirty () {
  git_dirty_timeout
  case "$?" in
        '50')  echo "$ZSH_THEME_GIT_PROMPT_DIRTY"       ;;
        '51')  echo "$ZSH_THEME_GIT_PROMPT_UNTRACKED"   ;;
        '124') echo "$ZSH_THEME_GIT_PROMPT_TIMEOUT"     ;;
        *)     echo "[$?]$ZSH_THEME_GIT_PROMPT_CLEAN"   ;;
  esac
}
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help