fix: refactor parallel fetch; close #518

- Resolve circular dependencies for local packages
  - Integrate _fisher_deps functionality to _fisher_fetch
- Update _fisher_jobs to exit with status 1 if there are no jobs
- Use `set -q myvar[1]` instead of `test -z $myvar` where possible
This commit is contained in:
Jorge Bucaran 2019-01-22 17:58:42 +09:00
parent db82938731
commit 91417201f4
No known key found for this signature in database
GPG key ID: E54BA3C0E646DB30

View file

@ -263,25 +263,24 @@ function _fisher_parse -a mode cmd
end end
function _fisher_fetch function _fisher_fetch
set -l pkg_jobs
set -l next_pkgs set -l next_pkgs
set -l local_pkgs set -l local_pkgs
set -l actual_pkgs set -l actual_pkgs
set -q fisher_user_api_token; and set -l curl_opts -u $fisher_user_api_token set -q fisher_user_api_token; and set -l curl_opts -u $fisher_user_api_token
for i in $argv for pkg in $argv
switch $i switch $pkg
case \~\* /\* case \~\* /\*
set -l path (echo "$i" | command sed "s|^~|$HOME|") set -l path (echo "$pkg" | command sed "s|^~|$HOME|")
if test -e "$path" if test -e "$path"
set local_pkgs $local_pkgs $path set local_pkgs $local_pkgs $path
else else
echo "fisher: cannot add \"$i\" -- is this a valid file?" >&2 echo "fisher: cannot add \"$pkg\" -- is this a valid file?" >&2
end end
continue continue
end end
command awk -v NAME="$i" -v FS=/ ' command awk -v NAME="$pkg" -v FS=/ '
BEGIN { BEGIN {
if (split(NAME, tmp, /@+|:/) > 2) { if (split(NAME, tmp, /@+|:/) > 2) {
if (tmp[4]) sub("@"tmp[4], "", NAME) if (tmp[4]) sub("@"tmp[4], "", NAME)
@ -299,6 +298,7 @@ function _fisher_fetch
' | read -l url pkg branch ' | read -l url pkg branch
if test ! -d "$fisher_config/$pkg" if test ! -d "$fisher_config/$pkg"
set next_pkgs $next_pkgs "$fisher_config/$pkg"
fish -c " fish -c "
echo fetching $url >&2 echo fetching $url >&2
command mkdir -p $fisher_config/$pkg $fisher_cache/(command dirname $pkg) command mkdir -p $fisher_config/$pkg $fisher_cache/(command dirname $pkg)
@ -318,14 +318,11 @@ function _fisher_fetch
echo fisher: cannot add \"$pkg\" -- is this a valid package\? >&2 echo fisher: cannot add \"$pkg\" -- is this a valid package\? >&2
end end
" >/dev/null & " >/dev/null &
set pkg_jobs $pkg_jobs (_fisher_jobs --last)
set next_pkgs $next_pkgs "$fisher_config/$pkg"
end end
end end
if test ! -z "$pkg_jobs" if set -l jobs (_fisher_jobs)
while for job in $pkg_jobs while for job in $jobs
contains -- $job (_fisher_jobs); and break contains -- $job (_fisher_jobs); and break
end end
end end
@ -337,28 +334,28 @@ function _fisher_fetch
end end
end end
set -l local_path $fisher_config/local/$USER set -l local_prefix $fisher_config/local/$USER
for src in $local_pkgs if test ! -d "$local_prefix"
command mkdir -p $local_path command mkdir -p $local_prefix
command ln -sf $src $local_path/(command basename $src)
set actual_pkgs $actual_pkgs $src
_fisher_add $src --link
end end
for pkg in $local_pkgs
if test ! -z "$actual_pkgs" set -l target $local_prefix/(command basename $pkg)
_fisher_fetch (_fisher_deps $actual_pkgs | command awk '!seen[$0]++') if test ! -L "$target"
printf "%s\n" $actual_pkgs | _fisher_fmt command ln -sf $pkg $target
end set actual_pkgs $actual_pkgs $pkg
end _fisher_add $pkg --link
function _fisher_deps
for pkg in $argv
if test ! -d "$pkg"
echo $pkg
else if test -s "$pkg/fishfile"
_fisher_deps (_fisher_fmt < $pkg/fishfile | _fisher_parse -R)
end end
end end
if set -q actual_pkgs[1]
_fisher_fetch (
for pkg in $actual_pkgs
if test -s "$pkg/fishfile"
_fisher_fmt < $pkg/fishfile | _fisher_parse -R
end
end)
printf "%s\n" $actual_pkgs | _fisher_fmt
end
end end
function _fisher_add -a pkg opts function _fisher_add -a pkg opts
@ -423,7 +420,7 @@ function _fisher_rm -a pkg
end end
function _fisher_jobs function _fisher_jobs
jobs $argv | command awk '/^[0-9]+\t/ { print $1 }' jobs $argv | command awk '/^[0-9]+\t/ { print (status = $1) } END { exit !status }'
end end
function _fisher_now -a elapsed function _fisher_now -a elapsed