Introduce filter_to, pick_fields
This commit is contained in:
parent
56356a8315
commit
1cbe51f2e1
1 changed files with 78 additions and 26 deletions
|
@ -19,6 +19,9 @@ Packkey_bytes=33 # 33 random bytes for passphrase, still compatible if changed
|
||||||
Hashtype=SHA256 # SHA512 SHA384 SHA256 SHA224 supported.
|
Hashtype=SHA256 # SHA512 SHA384 SHA256 SHA224 supported.
|
||||||
Packpat="pack :*:"
|
Packpat="pack :*:"
|
||||||
Manifestfile=91bd0c092128cf2e60e1a608c31e92caf1f9c1595f83f2890ef17c0e4881aa0a
|
Manifestfile=91bd0c092128cf2e60e1a608c31e92caf1f9c1595f83f2890ef17c0e4881aa0a
|
||||||
|
Hex40="[a-f0-9]"
|
||||||
|
Hex40=$Hex40$Hex40$Hex40$Hex40$Hex40$Hex40$Hex40$Hex40
|
||||||
|
Hex40=$Hex40$Hex40$Hex40$Hex40$Hex40 # Match SHA-1 hexdigest
|
||||||
|
|
||||||
Did_find_repo= # yes for connected, no for no repo
|
Did_find_repo= # yes for connected, no for no repo
|
||||||
Repoid=
|
Repoid=
|
||||||
|
@ -61,9 +64,11 @@ tac() { sed '1!G;h;$!d'; }
|
||||||
|
|
||||||
# setvar is used for named return variables
|
# setvar is used for named return variables
|
||||||
# $1 *must* be a valid variable name, $2 is any value
|
# $1 *must* be a valid variable name, $2 is any value
|
||||||
|
# our convention: variable name requires @ prefix
|
||||||
setvar()
|
setvar()
|
||||||
{
|
{
|
||||||
eval $1=\$2
|
isnull "${1##@*}" || echo_die "Missing @ for return variable: $1"
|
||||||
|
eval ${1#@}=\$2
|
||||||
}
|
}
|
||||||
|
|
||||||
Newline="
|
Newline="
|
||||||
|
@ -72,10 +77,10 @@ Newline="
|
||||||
# $1 is return var, $2 is value appended with newline separator
|
# $1 is return var, $2 is value appended with newline separator
|
||||||
append_to()
|
append_to()
|
||||||
{
|
{
|
||||||
local tmp_=
|
local append_tmp_=
|
||||||
eval tmp_=\$$1
|
eval append_tmp_=\$${1#@}
|
||||||
isnull "$tmp_" || tmp_=$tmp_$Newline
|
isnull "$append_tmp_" || append_tmp_=$append_tmp_$Newline
|
||||||
setvar "$1" "$tmp_$2"
|
setvar "$1" "$append_tmp_$2"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Split $1 into $2:$3
|
# Split $1 into $2:$3
|
||||||
|
@ -85,6 +90,52 @@ splitcolon()
|
||||||
setvar "$3" "${1#*:}"
|
setvar "$3" "${1#*:}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# if $1 contains $2
|
||||||
|
contains()
|
||||||
|
{
|
||||||
|
isnull "${1##*"$2"*}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Pick words from each line
|
||||||
|
# $1 return variable name
|
||||||
|
# $2 field list "1,2,3"
|
||||||
|
# $3 input value
|
||||||
|
pick_fields()
|
||||||
|
{
|
||||||
|
local f_line_= f_result_= f_mask_= f_ret_var= f_oifs="$IFS" IFS=
|
||||||
|
f_ret_var=$1
|
||||||
|
f_mask_=$2
|
||||||
|
IFS=$Newline
|
||||||
|
for f_line_ in $3
|
||||||
|
do
|
||||||
|
IFS=$f_oifs
|
||||||
|
# split $f_line_ into words and pick them out
|
||||||
|
set -- $f_line_
|
||||||
|
f_line_=
|
||||||
|
! contains "$f_mask_" 1 || f_line_=${1:-}
|
||||||
|
! contains "$f_mask_" 2 || f_line_="$f_line_ ${2:-}"
|
||||||
|
! contains "$f_mask_" 3 || f_line_="$f_line_ ${3:-}"
|
||||||
|
append_to @f_result_ "${f_line_# }"
|
||||||
|
done
|
||||||
|
setvar "$f_ret_var" "$f_result_"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Take all lines matching $2 (anchored front)
|
||||||
|
# $1 return variable name
|
||||||
|
# $2 filter word
|
||||||
|
# $3 input value
|
||||||
|
filter_to()
|
||||||
|
{
|
||||||
|
local f_line= f_result_= IFS=
|
||||||
|
IFS=$Newline
|
||||||
|
for f_line in $3
|
||||||
|
do
|
||||||
|
iseq "$f_line" "${f_line#$2}" || append_to @f_result_ "$f_line"
|
||||||
|
done
|
||||||
|
setvar "$1" "$f_result_"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
## gitception part
|
## gitception part
|
||||||
# Fetch giturl $1, file $2
|
# Fetch giturl $1, file $2
|
||||||
gitception_get()
|
gitception_get()
|
||||||
|
@ -371,7 +422,7 @@ read_config()
|
||||||
|
|
||||||
isnonnull "$keyid_" &&
|
isnonnull "$keyid_" &&
|
||||||
signers_="$signers_ $keyid_" &&
|
signers_="$signers_ $keyid_" &&
|
||||||
append_to good_sig "^\[GNUPG:\] GOODSIG $keyid_" || {
|
append_to @good_sig "^\[GNUPG:\] GOODSIG $keyid_" || {
|
||||||
echo_info "WARNING: Skipping missing key $recp_"
|
echo_info "WARNING: Skipping missing key $recp_"
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -401,7 +452,7 @@ ensure_connected()
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
Did_find_repo=no
|
Did_find_repo=no
|
||||||
read_config sig_match signer_text
|
read_config @sig_match @signer_text
|
||||||
|
|
||||||
iseq "${NAME#gcrypt::}" "$URL" || r_name=$NAME
|
iseq "${NAME#gcrypt::}" "$URL" || r_name=$NAME
|
||||||
|
|
||||||
|
@ -465,11 +516,11 @@ ensure_connected()
|
||||||
echo_die "Failed to decrypt manifest!"
|
echo_die "Failed to decrypt manifest!"
|
||||||
rm -f "$TmpManifest_Enc"
|
rm -f "$TmpManifest_Enc"
|
||||||
|
|
||||||
Branchlist=$(xecho "$manifest_" | xgrep -E '^[0-9a-f]{40} ')
|
filter_to @Packlist "pack " "$manifest_"
|
||||||
Packlist=$(xecho "$manifest_" | xgrep "^pack ")
|
filter_to @Keeplist "keep " "$manifest_"
|
||||||
Keeplist=$(xecho "$manifest_" | xgrep "^keep ")
|
filter_to @Extension_list "extn " "$manifest_"
|
||||||
Extension_list=$(xecho "$manifest_" | xgrep "^extn ")
|
filter_to @rcv_repoid "repo " "$manifest_"
|
||||||
rcv_repoid=$(xecho "$manifest_" | xgrep "^repo ")
|
filter_to @Branchlist "$Hex40 " "$manifest_"
|
||||||
|
|
||||||
rcv_repoid=${rcv_repoid#repo }
|
rcv_repoid=${rcv_repoid#repo }
|
||||||
rcv_repoid=${rcv_repoid% *}
|
rcv_repoid=${rcv_repoid% *}
|
||||||
|
@ -496,7 +547,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 :}" htype_ pack_
|
splitcolon "${1#pack :}" @htype_ @pack_
|
||||||
|
|
||||||
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
|
||||||
|
@ -507,7 +558,8 @@ fetch_decrypt_pack()
|
||||||
rcv_id=$(gpg_hash "$htype_" < "$TmpPack_Encrypted") &&
|
rcv_id=$(gpg_hash "$htype_" < "$TmpPack_Encrypted") &&
|
||||||
iseq "$rcv_id" "$pack_" ||
|
iseq "$rcv_id" "$pack_" ||
|
||||||
echo_die "Packfile $pack_ does not match digest!"
|
echo_die "Packfile $pack_ does not match digest!"
|
||||||
key_=$(xecho "$Packlist" | grep "$pack_" | cut -f 3 -d ' ')
|
filter_to @key_ "pack :${htype_}:$pack_" "$Packlist"
|
||||||
|
pick_fields @key_ 3 "$key_"
|
||||||
DECRYPT "$key_" < "$TmpPack_Encrypted"
|
DECRYPT "$key_" < "$TmpPack_Encrypted"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -529,8 +581,8 @@ repack_if_needed()
|
||||||
Repack_limit=1
|
Repack_limit=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
premote_=$(xecho "$Packlist" | cut -f 1-2 -d ' ')
|
pick_fields @premote_ 1,2 "$Packlist"
|
||||||
pkeep_=$(xecho "$Keeplist" | cut -f 2 -d ' ')
|
pick_fields @pkeep_ 2 "$Keeplist"
|
||||||
|
|
||||||
if isnull "$pkeep_"; then
|
if isnull "$pkeep_"; then
|
||||||
n_=$(xecho "$Packlist" | wc -l)
|
n_=$(xecho "$Packlist" | wc -l)
|
||||||
|
@ -576,8 +628,8 @@ repack_if_needed()
|
||||||
fi
|
fi
|
||||||
|
|
||||||
pack_id=$(pack_hash < "$TmpPack_Encrypted")
|
pack_id=$(pack_hash < "$TmpPack_Encrypted")
|
||||||
append_to Packlist "pack :${Hashtype}:$pack_id $key_"
|
append_to @Packlist "pack :${Hashtype}:$pack_id $key_"
|
||||||
append_to Keeplist "keep :${Hashtype}:$pack_id 1"
|
append_to @Keeplist "keep :${Hashtype}:$pack_id 1"
|
||||||
rm -r -f "$Localdir/pack"
|
rm -r -f "$Localdir/pack"
|
||||||
setvar "$3" yes
|
setvar "$3" yes
|
||||||
}
|
}
|
||||||
|
@ -628,7 +680,7 @@ do_fetch()
|
||||||
TmpPack_Encrypted="$Localdir/tmp_pack_ENCRYPTED_.$$"
|
TmpPack_Encrypted="$Localdir/tmp_pack_ENCRYPTED_.$$"
|
||||||
|
|
||||||
# The `+` for $GITCEPTION is pointless but we will be safe for stacking
|
# The `+` for $GITCEPTION is pointless but we will be safe for stacking
|
||||||
premote_=$(xecho "$Packlist" | cut -f 1-2 -d ' ')
|
pick_fields @premote_ 1,2 "$Packlist"
|
||||||
if [ -s "$Localdir/have_packs+" ]
|
if [ -s "$Localdir/have_packs+" ]
|
||||||
then
|
then
|
||||||
pneed_="$(xecho "$premote_" | xgrep -v -x -f "$Localdir/have_packs+")"
|
pneed_="$(xecho "$premote_" | xgrep -v -x -f "$Localdir/have_packs+")"
|
||||||
|
@ -677,15 +729,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_#+}" src_ dst_
|
splitcolon "${line_#+}" @src_ @dst_
|
||||||
if isnonnull "$src_"
|
if isnonnull "$src_"
|
||||||
then
|
then
|
||||||
append_to rev_list "$src_"
|
append_to @rev_list "$src_"
|
||||||
obj_=$(xecho "$src_" | safe_git_rev_parse)
|
obj_=$(xecho "$src_" | safe_git_rev_parse)
|
||||||
else
|
else
|
||||||
obj_=$del_hash # Mark for deletion
|
obj_=$del_hash # Mark for deletion
|
||||||
fi
|
fi
|
||||||
append_to Branchlist "$obj_ $dst_"
|
append_to @Branchlist "$obj_ $dst_"
|
||||||
done <<EOF
|
done <<EOF
|
||||||
$1
|
$1
|
||||||
EOF
|
EOF
|
||||||
|
@ -704,11 +756,11 @@ EOF
|
||||||
if [ -s "$TmpObjlist" ]
|
if [ -s "$TmpObjlist" ]
|
||||||
then
|
then
|
||||||
pack_id=$(pack_hash < "$TmpPack_Encrypted")
|
pack_id=$(pack_hash < "$TmpPack_Encrypted")
|
||||||
repack_if_needed "$pack_id" "$key_" did_repack pack_delete
|
repack_if_needed "$pack_id" "$key_" @did_repack @pack_delete
|
||||||
|
|
||||||
if isnoteq "$did_repack" yes
|
if isnoteq "$did_repack" yes
|
||||||
then
|
then
|
||||||
append_to Packlist "pack :${Hashtype}:$pack_id $key_"
|
append_to @Packlist "pack :${Hashtype}:$pack_id $key_"
|
||||||
fi
|
fi
|
||||||
# else, repack rewrote Packlist
|
# else, repack rewrote Packlist
|
||||||
|
|
||||||
|
@ -757,7 +809,7 @@ 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_#+}" src_ dst_
|
splitcolon "${line_#+}" @src_ @dst_
|
||||||
echo_git "ok $dst_"
|
echo_git "ok $dst_"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -812,7 +864,7 @@ gcrypt_main_loop()
|
||||||
do
|
do
|
||||||
case "$input_inner" in
|
case "$input_inner" in
|
||||||
push\ *)
|
push\ *)
|
||||||
append_to args_ "${input_inner#push }"
|
append_to @args_ "${input_inner#push }"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in a new issue