pull upstream changes from gitstatus

pull/527/head
romkatv 5 years ago
parent 0105d760d6
commit f4a0da0e4e

@ -418,7 +418,7 @@ function gitstatus_start() {
return 1 return 1
fi fi
local -i lock_fd resp_fd local -i lock_fd resp_fd stderr_fd
local file_prefix xtrace=/dev/null daemon_log=/dev/null local file_prefix xtrace=/dev/null daemon_log=/dev/null
if (( _GITSTATUS_STATE_$name )); then if (( _GITSTATUS_STATE_$name )); then
(( async )) && return (( async )) && return
@ -430,7 +430,7 @@ function gitstatus_start() {
file_prefix=${(P)${:-_GITSTATUS_FILE_PREFIX_$name}} file_prefix=${(P)${:-_GITSTATUS_FILE_PREFIX_$name}}
else else
local log_level=$GITSTATUS_LOG_LEVEL local log_level=$GITSTATUS_LOG_LEVEL
local file_prefix=${TMPDIR:-/tmp}/gitstatus.$EUID.$sysparams[pid].$EPOCHSECONDS local file_prefix=${${TMPDIR:-/tmp}:A}/gitstatus.$EUID.$sysparams[pid].$EPOCHSECONDS
(( GITSTATUS_ENABLE_LOGGING )) && : ${log_level:=INFO} (( GITSTATUS_ENABLE_LOGGING )) && : ${log_level:=INFO}
if [[ -n $log_level ]]; then if [[ -n $log_level ]]; then
xtrace=$file_prefix.xtrace.log xtrace=$file_prefix.xtrace.log
@ -444,11 +444,10 @@ function gitstatus_start() {
typeset -gi _GITSTATUS_DIRTY_MAX_INDEX_SIZE_$name=dirty_max_index_size typeset -gi _GITSTATUS_DIRTY_MAX_INDEX_SIZE_$name=dirty_max_index_size
fi fi
local -i stderr_fd () {
{
if [[ $xtrace != /dev/null && -o no_xtrace ]]; then if [[ $xtrace != /dev/null && -o no_xtrace ]]; then
exec {stderr_fd}>&2 exec {stderr_fd}>&2 || return
exec 2>>$xtrace || return exec 2>>$xtrace || return
setopt xtrace setopt xtrace
fi fi
@ -456,20 +455,20 @@ function gitstatus_start() {
if [[ -r /proc/version && "$(</proc/version)" == *Microsoft* ]]; then if [[ -r /proc/version && "$(</proc/version)" == *Microsoft* ]]; then
lock_fd=-1 lock_fd=-1
else else
print -rn >$file_prefix.lock || return print -rn >$file_prefix.lock || return
zsystem flock -f lock_fd $file_prefix.lock || return zsystem flock -f lock_fd $file_prefix.lock || return
[[ $lock_fd == <1-> ]] || return
fi fi
typeset -gi _GITSTATUS_LOCK_FD_$name=lock_fd typeset -gi _GITSTATUS_LOCK_FD_$name=lock_fd
{ {
() { () {
if [[ $sysparams[procsubstpid] == <1-> ]]; then typeset -gi GITSTATUS_DAEMON_PID_$name="${sysparams[procsubstpid]:--1}"
typeset -gi GITSTATUS_DAEMON_PID_$name="sysparams[procsubstpid]"
fi
sysopen -r -o cloexec -u resp_fd -- $1 || return sysopen -r -o cloexec -u resp_fd -- $1 || return
[[ $resp_fd == <1-> ]] || return
typeset -gi _GITSTATUS_RESP_FD_$name=resp_fd typeset -gi _GITSTATUS_RESP_FD_$name=resp_fd
} <( } <(
exec 2>&3 3>&- || return exec 2>&3 3>&- || return
local pgid=$sysparams[pid] local pgid=$sysparams[pid]
[[ $pgid == <1-> ]] || return [[ $pgid == <1-> ]] || return
@ -477,27 +476,45 @@ function gitstatus_start() {
{ {
trap '' PIPE trap '' PIPE
local os daemon=$GITSTATUS_DAEMON if [[ -z $GITSTATUS_DAEMON || $GITSTATUS_NUM_THREADS != <1-> ]]; then
if [[ -z $daemon ]]; then local kernel
os="$(uname -s)" || return kernel="${(L)$(uname -s)}" || return
[[ -n $os ]] || return [[ -n $kernel ]] || return
case $os in fi
Linux) [[ "$(uname -o)" == Android ]] && os=android;;
(#i)cygwin_nt-*) os=cygwin_nt-10.0;; if [[ $GITSTATUS_DAEMON == /* ]]; then
(#i)(mingw|msys)) os=msys_nt-10.0;; local daemons=($GITSTATUS_DAEMON)
elif (( $+commands[$GITSTATUS_DAEMON] )); then
local daemons=($commands[$GITSTATUS_DAEMON])
elif [[ -n $GITSTATUS_DAEMON ]]; then
local daemons=($_gitstatus_plugin_dir/{usrbin,bin}/$GITSTATUS_DAEMON)
else
local os
case $kernel in
linux)
os="${(L)$(uname -o)}" || return
[[ -n $os ]] || return
[[ $os == android ]] || os=linux
;;
cygwin_nt-*) os=cygwin_nt-10.0;;
mingw|msys) os=msys_nt-10.0;;
*) os=$kernel;;
esac esac
local arch local arch
arch="$(uname -m)" || return arch="${(L)$(uname -m)}" || return
[[ -n $arch ]] || return [[ -n $arch ]] || return
daemon=$_gitstatus_plugin_dir/bin/gitstatusd-${os:l}-${arch:l} local daemons=($_gitstatus_plugin_dir/{usrbin,bin}/gitstatusd-$os-$arch{,-static})
fi fi
[[ -x $daemon ]] || return
daemons=(${^daemons}(N:A))
daemons=(${^daemons}(N*))
(( $#daemons )) || return
if [[ $GITSTATUS_NUM_THREADS == <1-> ]]; then if [[ $GITSTATUS_NUM_THREADS == <1-> ]]; then
args+=(-t $GITSTATUS_NUM_THREADS) args+=(-t $GITSTATUS_NUM_THREADS)
else else
local cpus local cpus
if [[ $+commands[sysctl] == 0 || "${os:-$(uname -s)}" == Linux ]] || if (( ! $+commands[sysctl] )) || [[ $kernel == linux ]] ||
! cpus="$(sysctl -n hw.ncpu)"; then ! cpus="$(sysctl -n hw.ncpu)"; then
if (( ! $+commands[getconf] )) || ! cpus="$(getconf _NPROCESSORS_ONLN)"; then if (( ! $+commands[getconf] )) || ! cpus="$(getconf _NPROCESSORS_ONLN)"; then
cpus=8 cpus=8
@ -511,11 +528,14 @@ function gitstatus_start() {
exec <$file_prefix.fifo || return exec <$file_prefix.fifo || return
zf_rm -- $file_prefix.fifo || return zf_rm -- $file_prefix.fifo || return
$daemon "${(@)args}" local daemon
if [[ $? != (0|10) && $? -le 128 && -x ${daemon}-static ]]; then for daemon in $daemons; do
${daemon}-static "${(@)args}" || return $daemon "${(@)args}"
fi local -i ret=$?
(( ret == 0 || ret == 10 || ret > 128 )) && return ret
done
} always { } always {
local -i ret=$?
kill -- -$pgid kill -- -$pgid
} }
} &! } &!
@ -546,6 +566,7 @@ function gitstatus_start() {
typeset -gi GITSTATUS_DAEMON_PID_$name=pgid typeset -gi GITSTATUS_DAEMON_PID_$name=pgid
sysopen -w -o cloexec -u req_fd -- $file_prefix.fifo || return sysopen -w -o cloexec -u req_fd -- $file_prefix.fifo || return
[[ $req_fd == <1-> ]] || return
typeset -gi _GITSTATUS_REQ_FD_$name=req_fd typeset -gi _GITSTATUS_REQ_FD_$name=req_fd
function _gitstatus_process_response_$name() { function _gitstatus_process_response_$name() {
@ -574,7 +595,7 @@ function gitstatus_start() {
fi fi
print -nru $req_fd -- $'hello\x1f\x1e' || return print -nru $req_fd -- $'hello\x1f\x1e' || return
local expected=$'hello\x1f0' actual local expected=$'hello\x1f0\x1e' actual
while (( $#actual < $#expected )); do while (( $#actual < $#expected )); do
[[ -t $resp_fd ]] [[ -t $resp_fd ]]
sysread -s $(($#expected - $#actual)) -t $timeout -i $resp_fd 'actual[$#actual+1]' || return sysread -s $(($#expected - $#actual)) -t $timeout -i $resp_fd 'actual[$#actual+1]' || return
@ -589,64 +610,65 @@ function gitstatus_start() {
typeset -gi _GITSTATUS_STATE_$name=2 typeset -gi _GITSTATUS_STATE_$name=2
fi fi
} always { }
local err=$?
if (( stderr_fd )); then local -i err=$?
unsetopt xtrace (( stderr_fd )) && exec 2>&$stderr_fd
exec 2>&$stderr_fd (( err == 0 )) && return
fi
(( err )) || return gitstatus_stop $name
gitstatus_stop $name
setopt prompt_percent no_prompt_subst no_prompt_bang setopt prompt_percent no_prompt_subst no_prompt_bang
print -Pru2 -- '[%F{red}ERROR%f]: gitstatus failed to initialize.' print -Pru2 -- '[%F{red}ERROR%f]: gitstatus failed to initialize.'
print -ru2 -- ''
print -ru2 -- ' Your Git prompt may disappear or become slow.'
if [[ -s $xtrace ]]; then
print -ru2 -- '' print -ru2 -- ''
print -ru2 -- ' Your git prompt may disappear or become slow.' print -ru2 -- " The content of ${(q-)xtrace} (gitstatus_start xtrace):"
if [[ -s $xtrace ]]; then print -Pru2 -- '%F{yellow}'
print -ru2 -- '' >&2 awk '{print " " $0}' <$xtrace
print -ru2 -- " The content of ${(q-)xtrace} (gitstatus_start xtrace):" print -Pru2 -- "%F{red} ^ this command failed ($err)%f"
print -Pru2 -- '%F{yellow}' fi
>&2 awk '{print " " $0}' <$xtrace if [[ -s $daemon_log ]]; then
print -Pnru2 -- '%f' print -ru2 -- ''
fi print -ru2 -- " The content of ${(q-)daemon_log} (gitstatus daemon log):"
if [[ -s $daemon_log ]]; then print -Pru2 -- '%F{yellow}'
print -ru2 -- '' >&2 awk '{print " " $0}' <$daemon_log
print -ru2 -- " The content of ${(q-)daemon_log} (gitstatus daemon log):" print -Pnru2 -- '%f'
print -Pru2 -- '%F{yellow}' fi
>&2 awk '{print " " $0}' <$daemon_log if [[ $GITSTATUS_LOG_LEVEL == DEBUG ]]; then
print -Pnru2 -- '%f' print -ru2 -- ''
print -ru2 -- ' Your system information:'
print -Pru2 -- '%F{yellow}'
print -ru2 -- " zsh: $ZSH_VERSION"
print -ru2 -- " uname -a: $(uname -a)"
print -Pru2 -- '%f'
print -ru2 -- ' If you need help, open an issue and attach this whole error message to it:'
print -ru2 -- ''
print -Pru2 -- ' %F{green}https://github.com/romkatv/gitstatus/issues/new%f'
else
print -ru2 -- ''
print -ru2 -- ' Run the following command to retry with extra diagnostics:'
print -Pru2 -- '%F{green}'
local env="GITSTATUS_LOG_LEVEL=DEBUG"
if [[ -n $GITSTATUS_NUM_THREADS ]]; then
env+=" GITSTATUS_NUM_THREADS=${(q)GITSTATUS_NUM_THREADS}"
fi fi
if [[ $GITSTATUS_LOG_LEVEL == DEBUG ]]; then if [[ -n $GITSTATUS_DAEMON ]]; then
print -ru2 -- '' env+=" GITSTATUS_DAEMON=${(q)GITSTATUS_DAEMON}"
print -ru2 -- ' Your system information:'
print -Pru2 -- '%F{yellow}'
print -ru2 -- " zsh: $ZSH_VERSION"
print -ru2 -- " uname -a: $(uname -a)"
print -Pru2 -- '%f'
print -ru2 -- ' If you need help, open an issue and attach this whole error message to it:'
print -ru2 -- ''
print -Pru2 -- ' %F{green}https://github.com/romkatv/gitstatus/issues/new%f'
else
print -ru2 -- ''
print -ru2 -- ' Run the following command to retry with extra diagnostics:'
print -Pru2 -- '%F{green}'
local env="GITSTATUS_LOG_LEVEL=DEBUG"
if [[ -n $GITSTATUS_NUM_THREADS ]]; then
env+=" GITSTATUS_NUM_THREADS=${(q)GITSTATUS_NUM_THREADS}"
fi
if [[ -n $GITSTATUS_DAEMON ]]; then
env+=" GITSTATUS_DAEMON=${(q)GITSTATUS_DAEMON}"
fi
print -nru2 -- " ${env} gitstatus_start ${(@q-)*}"
print -Pru2 -- '%f'
print -ru2 -- ''
local zshrc=${(D)ZDOTDIR:-~}/.zshrc
print -ru2 -- " If this command produces no output, add the following parameter to $zshrc:"
print -ru2 -- ''
print -Pru2 -- '%F{green} GITSTATUS_LOG_LEVEL=DEBUG%f'
print -ru2 -- ''
print -ru2 -- ' With this parameter gitstatus will print additional information on error.'
fi fi
} print -nru2 -- " ${env} gitstatus_start ${(@q-)*}"
print -Pru2 -- '%f'
print -ru2 -- ''
local zshrc=${(D)ZDOTDIR:-~}/.zshrc
print -ru2 -- " If this command produces no output, add the following parameter to $zshrc:"
print -ru2 -- ''
print -Pru2 -- '%F{green} GITSTATUS_LOG_LEVEL=DEBUG%f'
print -ru2 -- ''
print -ru2 -- ' With this parameter gitstatus will print additional information on error.'
fi
return err
} }
# Stops gitstatusd if it's running. # Stops gitstatusd if it's running.
@ -685,8 +707,6 @@ function gitstatus_stop() {
local cleanup=_gitstatus_cleanup_$name local cleanup=_gitstatus_cleanup_$name
local process=_gitstatus_process_response_$name local process=_gitstatus_process_response_$name
[[ -n $daemon_pid ]] && kill -- -$daemon_pid 2>/dev/null
if (( $+functions[$cleanup] )); then if (( $+functions[$cleanup] )); then
add-zsh-hook -d zshexit $cleanup add-zsh-hook -d zshexit $cleanup
unfunction -- $cleanup unfunction -- $cleanup
@ -697,13 +717,17 @@ function gitstatus_stop() {
unfunction -- $process unfunction -- $process
fi fi
[[ -n $file_prefix ]] && zf_rm -f -- "$file_prefix.lock" "$file_prefix.fifo" [[ $daemon_pid == <1-> ]] && kill -- -$daemon_pid 2>/dev/null
[[ -n $lock_fd ]] && (( lock_fd != -1 )) && zsystem flock -u $lock_fd [[ $file_prefix == /* ]] && zf_rm -f -- $file_prefix.lock $file_prefix.fifo
[[ -n $req_fd ]] && exec {req_fd}>&- [[ $lock_fd == <1-> ]] && zsystem flock -u $lock_fd
[[ -n $resp_fd ]] && exec {resp_fd}>&- [[ $req_fd == <1-> ]] && exec {req_fd}>&-
[[ $resp_fd == <1-> ]] && exec {resp_fd}>&-
unset $state_var $req_fd_var $lock_fd_var $resp_fd_var $client_pid_var $daemon_pid_var unset $state_var $req_fd_var $lock_fd_var $resp_fd_var $client_pid_var $daemon_pid_var
unset $inflight_var $file_prefix_var $dirty_max_index_size_var unset $inflight_var $file_prefix_var $dirty_max_index_size_var
unset VCS_STATUS_RESULT
_gitstatus_clear
} }
# Usage: gitstatus_check NAME. # Usage: gitstatus_check NAME.

Loading…
Cancel
Save