Use setvar for return variables
This commit is contained in:
parent
2a65af1d20
commit
6e90c21c87
1 changed files with 31 additions and 27 deletions
|
@ -25,7 +25,6 @@ Packlist=
|
||||||
Keeplist=
|
Keeplist=
|
||||||
Extension_list=
|
Extension_list=
|
||||||
Repack_limit=25
|
Repack_limit=25
|
||||||
Packlist_delete=
|
|
||||||
|
|
||||||
Recipients=
|
Recipients=
|
||||||
Signers=
|
Signers=
|
||||||
|
@ -62,11 +61,18 @@ sort_stable_k2()
|
||||||
|
|
||||||
tac() { sed '1!G;h;$!d'; }
|
tac() { sed '1!G;h;$!d'; }
|
||||||
|
|
||||||
# Split $1 into $prefix_:$suffix_
|
# setvar is used for named return variables
|
||||||
|
# $1 *must* be a valid variable name, $2 is any value
|
||||||
|
setvar()
|
||||||
|
{
|
||||||
|
eval $1=\$2
|
||||||
|
}
|
||||||
|
|
||||||
|
# Split $1 into $2:$3
|
||||||
splitcolon()
|
splitcolon()
|
||||||
{
|
{
|
||||||
prefix_=${1%%:*}
|
setvar "$2" "${1%%:*}"
|
||||||
suffix_=${1#*:}
|
setvar "$3" "${1#*:}"
|
||||||
}
|
}
|
||||||
repoidstr() { xecho "repo $Repoid"; }
|
repoidstr() { xecho "repo $Repoid"; }
|
||||||
|
|
||||||
|
@ -477,9 +483,7 @@ ensure_connected()
|
||||||
fetch_decrypt_pack()
|
fetch_decrypt_pack()
|
||||||
{
|
{
|
||||||
local key_= rcv_id= htype_= pack_= hfunc_=
|
local key_= rcv_id= htype_= pack_= hfunc_=
|
||||||
splitcolon "${1#pack :}"
|
splitcolon "${1#pack :}" htype_ pack_
|
||||||
htype_=$prefix_
|
|
||||||
pack_=$suffix_
|
|
||||||
|
|
||||||
if isnoteq "$htype_" SHA256 && isnoteq "$htype_" SHA224 &&
|
if isnoteq "$htype_" SHA256 && isnoteq "$htype_" SHA224 &&
|
||||||
isnoteq "$htype_" SHA384 && isnoteq "$htype_" SHA512
|
isnoteq "$htype_" SHA384 && isnoteq "$htype_" SHA512
|
||||||
|
@ -494,15 +498,16 @@ fetch_decrypt_pack()
|
||||||
DECRYPT "$key_" < "$TmpPack_Encrypted"
|
DECRYPT "$key_" < "$TmpPack_Encrypted"
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1 is new pack id $2 key
|
# $1 is new pack id $2 key, $3, $4 return variables
|
||||||
# set did_repack=yes if repacked
|
# set $3 to yes if repacked
|
||||||
|
# $4 to list of packfiles to delete
|
||||||
repack_if_needed()
|
repack_if_needed()
|
||||||
{
|
{
|
||||||
local pack_= packline_= premote_= key_= pkeep_= n_=
|
local pack_= packline_= premote_= key_= pkeep_= n_=
|
||||||
|
|
||||||
# $TmpPack_Encrypted set in caller
|
# $TmpPack_Encrypted set in caller
|
||||||
|
|
||||||
did_repack=no
|
setvar "$3" no
|
||||||
isnonnull "$Packlist" || return 0
|
isnonnull "$Packlist" || return 0
|
||||||
|
|
||||||
if isnonnull "$GCRYPT_FULL_REPACK"
|
if isnonnull "$GCRYPT_FULL_REPACK"
|
||||||
|
@ -550,10 +555,10 @@ repack_if_needed()
|
||||||
|
|
||||||
# Truncate packlist to only the kept packs
|
# Truncate packlist to only the kept packs
|
||||||
if isnull "$pkeep_"; then
|
if isnull "$pkeep_"; then
|
||||||
Packlist_delete=$premote_
|
setvar "$4" "$premote_"
|
||||||
Packlist=
|
Packlist=
|
||||||
else
|
else
|
||||||
Packlist_delete=$(xecho "$premote_" | xgrep -v -e "$pkeep_")
|
setvar "$4" "$(xecho "$premote_" | xgrep -v -e "$pkeep_")"
|
||||||
Packlist=$(xecho "$Packlist" | xgrep -e "$pkeep_")
|
Packlist=$(xecho "$Packlist" | xgrep -e "$pkeep_")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -561,7 +566,7 @@ repack_if_needed()
|
||||||
Packlist=$(append "$Packlist" "pack :${Hashtype}:$pack_id $key_")
|
Packlist=$(append "$Packlist" "pack :${Hashtype}:$pack_id $key_")
|
||||||
Keeplist=$(append "$Keeplist" "keep :${Hashtype}:$pack_id 1")
|
Keeplist=$(append "$Keeplist" "keep :${Hashtype}:$pack_id 1")
|
||||||
rm -r -f "$Localdir/pack"
|
rm -r -f "$Localdir/pack"
|
||||||
did_repack=yes
|
setvar "$3" yes
|
||||||
}
|
}
|
||||||
|
|
||||||
do_capabilities()
|
do_capabilities()
|
||||||
|
@ -634,7 +639,8 @@ do_push()
|
||||||
# Each git packfile is encrypted and then named for the encrypted
|
# Each git packfile is encrypted and then named for the encrypted
|
||||||
# file's hash. The manifest is updated with the pack id.
|
# file's hash. The manifest is updated with the pack id.
|
||||||
# The manifest is encrypted.
|
# The manifest is encrypted.
|
||||||
local remote_has= remote_want= prefix_= suffix_= line_= pack_id= key_=
|
local remote_has= remote_want= src_= dst_= line_= pack_id= key_= obj_= \
|
||||||
|
pack_delete=
|
||||||
del_hash=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
del_hash=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||||
|
|
||||||
ensure_connected
|
ensure_connected
|
||||||
|
@ -654,16 +660,15 @@ do_push()
|
||||||
while read line_ # from <<
|
while read line_ # from <<
|
||||||
do
|
do
|
||||||
# +src:dst -- remove leading + then split at :
|
# +src:dst -- remove leading + then split at :
|
||||||
splitcolon "${line_#+}"
|
splitcolon "${line_#+}" src_ dst_
|
||||||
if isnonnull "$prefix_"
|
if isnonnull "$src_"
|
||||||
then
|
then
|
||||||
remote_want=$(append "$remote_want" "$prefix_")
|
remote_want=$(append "$remote_want" "$src_")
|
||||||
Branchlist=$(append "$Branchlist" \
|
obj_=$(xecho "$src_" | safe_git_rev_parse)
|
||||||
"$(xecho "$prefix_" | safe_git_rev_parse) $suffix_")
|
|
||||||
else
|
else
|
||||||
# Mark branch for deletion
|
obj_=$del_hash # Mark for deletion
|
||||||
Branchlist=$(append "$Branchlist" "$del_hash $suffix_")
|
|
||||||
fi
|
fi
|
||||||
|
Branchlist=$(append "$Branchlist" "$obj_ $dst_")
|
||||||
done <<EOF
|
done <<EOF
|
||||||
$1
|
$1
|
||||||
EOF
|
EOF
|
||||||
|
@ -683,8 +688,7 @@ EOF
|
||||||
if [ -s "$TmpObjlist" ]
|
if [ -s "$TmpObjlist" ]
|
||||||
then
|
then
|
||||||
pack_id=$(pack_hash < "$TmpPack_Encrypted")
|
pack_id=$(pack_hash < "$TmpPack_Encrypted")
|
||||||
did_repack=
|
repack_if_needed "$pack_id" "$key_" did_repack pack_delete
|
||||||
repack_if_needed "$pack_id" "$key_"
|
|
||||||
|
|
||||||
if isnoteq "$did_repack" yes
|
if isnoteq "$did_repack" yes
|
||||||
then
|
then
|
||||||
|
@ -716,8 +720,8 @@ EOF
|
||||||
PUT "$URL" "$Manifestfile" "$TmpManifest_Enc"
|
PUT "$URL" "$Manifestfile" "$TmpManifest_Enc"
|
||||||
|
|
||||||
# Delete packs
|
# Delete packs
|
||||||
if isnonnull "$Packlist_delete"; then
|
if isnonnull "$pack_delete"; then
|
||||||
REMOVE "$URL" "$(xecho "$Packlist_delete" | while read packline_
|
REMOVE "$URL" "$(xecho "$pack_delete" | while read packline_
|
||||||
do
|
do
|
||||||
isnonnull "$packline_" || continue
|
isnonnull "$packline_" || continue
|
||||||
pack_=${packline_#$Packpat}
|
pack_=${packline_#$Packpat}
|
||||||
|
@ -733,8 +737,8 @@ EOF
|
||||||
xecho "$1" | while read line_
|
xecho "$1" | while read line_
|
||||||
do
|
do
|
||||||
# +src:dst -- remove leading + then split at :
|
# +src:dst -- remove leading + then split at :
|
||||||
splitcolon "${line_#+}"
|
splitcolon "${line_#+}" src_ dst_
|
||||||
echo_git "ok $suffix_"
|
echo_git "ok $dst_"
|
||||||
done
|
done
|
||||||
|
|
||||||
echo_git
|
echo_git
|
||||||
|
|
Loading…
Reference in a new issue