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,10 +444,9 @@ 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
@ -458,15 +457,15 @@ function gitstatus_start() {
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
@ -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 $kernel ]] || return
fi
if [[ $GITSTATUS_DAEMON == /* ]]; then
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 [[ -n $os ]] || return
case $os in [[ $os == android ]] || os=linux
Linux) [[ "$(uname -o)" == Android ]] && os=android;; ;;
(#i)cygwin_nt-*) os=cygwin_nt-10.0;; cygwin_nt-*) os=cygwin_nt-10.0;;
(#i)(mingw|msys)) os=msys_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
local daemon
for daemon in $daemons; do
$daemon "${(@)args}" $daemon "${(@)args}"
if [[ $? != (0|10) && $? -le 128 && -x ${daemon}-static ]]; then local -i ret=$?
${daemon}-static "${(@)args}" || return (( ret == 0 || ret == 10 || ret > 128 )) && return ret
fi 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,24 +610,24 @@ 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 -- ''
print -ru2 -- ' Your git prompt may disappear or become slow.' print -ru2 -- ' Your Git prompt may disappear or become slow.'
if [[ -s $xtrace ]]; then if [[ -s $xtrace ]]; then
print -ru2 -- '' print -ru2 -- ''
print -ru2 -- " The content of ${(q-)xtrace} (gitstatus_start xtrace):" print -ru2 -- " The content of ${(q-)xtrace} (gitstatus_start xtrace):"
print -Pru2 -- '%F{yellow}' print -Pru2 -- '%F{yellow}'
>&2 awk '{print " " $0}' <$xtrace >&2 awk '{print " " $0}' <$xtrace
print -Pnru2 -- '%f' print -Pru2 -- "%F{red} ^ this command failed ($err)%f"
fi fi
if [[ -s $daemon_log ]]; then if [[ -s $daemon_log ]]; then
print -ru2 -- '' print -ru2 -- ''
@ -646,7 +667,8 @@ function gitstatus_start() {
print -ru2 -- '' print -ru2 -- ''
print -ru2 -- ' With this parameter gitstatus will print additional information on error.' print -ru2 -- ' With this parameter gitstatus will print additional information on error.'
fi 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