Use an append function, and other cleanups
This commit is contained in:
parent
949ebdc92a
commit
e5c93d6306
1 changed files with 23 additions and 19 deletions
|
@ -23,8 +23,7 @@ sha1()
|
||||||
}
|
}
|
||||||
|
|
||||||
LOCALDIR="${GIT_DIR:-.git}/remote-gcrypt"
|
LOCALDIR="${GIT_DIR:-.git}/remote-gcrypt"
|
||||||
DUMMYKEY="00000000000000000000"
|
DID_FIND_REPO= # yes for connected, no for no repo
|
||||||
DID_CONNECT=
|
|
||||||
|
|
||||||
isurl() { test -z "${2%%$1://*}" ; }
|
isurl() { test -z "${2%%$1://*}" ; }
|
||||||
|
|
||||||
|
@ -99,6 +98,13 @@ DECRYPT()
|
||||||
gpg -q --batch --passphrase-fd 0 --output - -d /dev/fd/3) 3<&0
|
gpg -q --batch --passphrase-fd 0 --output - -d /dev/fd/3) 3<&0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Append $2 to $1 with a newline separator
|
||||||
|
append()
|
||||||
|
{
|
||||||
|
[ -n "$1" ] && printf "%s\n" "$1" || :
|
||||||
|
printf "%s\n" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
tac() { sed '1!G;h;$!d'; }
|
tac() { sed '1!G;h;$!d'; }
|
||||||
echo_info() { echo "$@" >&2; }
|
echo_info() { echo "$@" >&2; }
|
||||||
|
|
||||||
|
@ -127,12 +133,17 @@ ensure_connected()
|
||||||
{
|
{
|
||||||
local MANIFESTDATA
|
local MANIFESTDATA
|
||||||
|
|
||||||
if [ ! -z "$DID_CONNECT" ]
|
if [ -n "$DID_FIND_REPO" ]
|
||||||
then
|
then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
DID_CONNECT=1
|
DID_FIND_REPO=yes
|
||||||
MASTERKEY="$(get_masterkey)"
|
MASTERKEY="$(get_masterkey)"
|
||||||
|
if [ -z "$MASTERKEY" ]
|
||||||
|
then
|
||||||
|
DID_FIND_REPO=no
|
||||||
|
return
|
||||||
|
fi
|
||||||
MANIFESTDATA="$(GET_OR_EMPTY "$URL" manifest | DECRYPT)"
|
MANIFESTDATA="$(GET_OR_EMPTY "$URL" manifest | DECRYPT)"
|
||||||
BRANCHLIST=$(printf "%s\n" "$MANIFESTDATA" | (grep -v '^pack ' || :))
|
BRANCHLIST=$(printf "%s\n" "$MANIFESTDATA" | (grep -v '^pack ' || :))
|
||||||
PACKLIST=$(printf "%s\n" "$MANIFESTDATA" | (grep '^pack ' || :))
|
PACKLIST=$(printf "%s\n" "$MANIFESTDATA" | (grep '^pack ' || :))
|
||||||
|
@ -140,8 +151,7 @@ ensure_connected()
|
||||||
|
|
||||||
get_masterkey()
|
get_masterkey()
|
||||||
{
|
{
|
||||||
(GET "$URL" masterkey 2>/dev/null || : ) | \
|
GET "$URL" masterkey 2>/dev/null | gpg -q --batch -d || :
|
||||||
(gpg -q --batch -d || printf "%s" "$DUMMYKEY")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do_capabilities()
|
do_capabilities()
|
||||||
|
@ -186,14 +196,14 @@ do_fetch()
|
||||||
if [ -z "$PACKLIST" ]
|
if [ -z "$PACKLIST" ]
|
||||||
then
|
then
|
||||||
echo # end with blank line
|
echo # end with blank line
|
||||||
exit 0
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TMPPACK_ENCRYPTED="$LOCALDIR/tmp_pack_ENCRYPTED_.$$"
|
TMPPACK_ENCRYPTED="$LOCALDIR/tmp_pack_ENCRYPTED_.$$"
|
||||||
trap 'rm -f "$TMPPACK_ENCRYPTED"' EXIT
|
trap 'rm -f "$TMPPACK_ENCRYPTED"' EXIT
|
||||||
|
|
||||||
# Needed packs is REMOTE - (HAVE & REMOTE)
|
# Needed packs is REMOTE - (HAVE & REMOTE)
|
||||||
PHAVE="$(cat "$LOCALDIR/have_packs" || :)"
|
PHAVE="$(cat "$LOCALDIR/have_packs" 2>/dev/null || :)"
|
||||||
PBOTH="$(printf "%s\n%s" "$PACKLIST" "$PHAVE" | sort | uniq -d)"
|
PBOTH="$(printf "%s\n%s" "$PACKLIST" "$PHAVE" | sort | uniq -d)"
|
||||||
PNEED="$(printf "%s\n%s" "$PACKLIST" "$PBOTH" | sort | uniq -u)"
|
PNEED="$(printf "%s\n%s" "$PACKLIST" "$PBOTH" | sort | uniq -u)"
|
||||||
|
|
||||||
|
@ -231,7 +241,7 @@ do_push()
|
||||||
local suffix_
|
local suffix_
|
||||||
ensure_connected
|
ensure_connected
|
||||||
|
|
||||||
if [ "$MASTERKEY" = "$DUMMYKEY" ]
|
if [ "$DID_FIND_REPO" = "no" ]
|
||||||
then
|
then
|
||||||
make_new_repo
|
make_new_repo
|
||||||
fi
|
fi
|
||||||
|
@ -239,7 +249,7 @@ do_push()
|
||||||
trap 'rm -f "$TMPMANIFEST" "$TMPPACK_ENCRYPTED" "$TMPOBJLIST"' EXIT
|
trap 'rm -f "$TMPMANIFEST" "$TMPPACK_ENCRYPTED" "$TMPOBJLIST"' EXIT
|
||||||
TMPMANIFEST="$LOCALDIR/tmp_new_manifest_.$$"
|
TMPMANIFEST="$LOCALDIR/tmp_new_manifest_.$$"
|
||||||
touch "$TMPMANIFEST"
|
touch "$TMPMANIFEST"
|
||||||
if [ ! -z "$BRANCHLIST" ]
|
if [ -n "$BRANCHLIST" ]
|
||||||
then
|
then
|
||||||
printf "%s\n" "$BRANCHLIST" >"$TMPMANIFEST"
|
printf "%s\n" "$BRANCHLIST" >"$TMPMANIFEST"
|
||||||
REMOTEHAS="$(printf "%s" "$BRANCHLIST" | \
|
REMOTEHAS="$(printf "%s" "$BRANCHLIST" | \
|
||||||
|
@ -250,7 +260,7 @@ do_push()
|
||||||
do
|
do
|
||||||
# +src:dst -- remove leading + then split at :
|
# +src:dst -- remove leading + then split at :
|
||||||
splitcolon "${LINE#+}"
|
splitcolon "${LINE#+}"
|
||||||
if [ ! -z "$prefix_" ]
|
if [ -n "$prefix_" ]
|
||||||
then
|
then
|
||||||
printf "%s " "$prefix_"
|
printf "%s " "$prefix_"
|
||||||
printf "%s %s\n" "$(git rev-parse "$prefix_")" "$suffix_" >> "$TMPMANIFEST"
|
printf "%s %s\n" "$(git rev-parse "$prefix_")" "$suffix_" >> "$TMPMANIFEST"
|
||||||
|
@ -270,13 +280,7 @@ do_push()
|
||||||
if [ -s "$TMPOBJLIST" ]
|
if [ -s "$TMPOBJLIST" ]
|
||||||
then
|
then
|
||||||
PACKID=$(sha1 < "$TMPPACK_ENCRYPTED")
|
PACKID=$(sha1 < "$TMPPACK_ENCRYPTED")
|
||||||
if [ -z "$PACKLIST" ]
|
PACKLIST=$(append "$PACKLIST" "pack $PACKID")
|
||||||
then
|
|
||||||
PACKLIST="$(printf "pack %s\n" "$PACKID")"
|
|
||||||
else
|
|
||||||
PACKLIST="$(printf "%s\npack %s\n" "$PACKLIST" "$PACKID")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
PUT "$URL" "$PACKID" < "$TMPPACK_ENCRYPTED"
|
PUT "$URL" "$PACKID" < "$TMPPACK_ENCRYPTED"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -343,7 +347,7 @@ do
|
||||||
#echo_info "Got: (for push) $INPUTX"
|
#echo_info "Got: (for push) $INPUTX"
|
||||||
case "$INPUTX" in
|
case "$INPUTX" in
|
||||||
push\ *)
|
push\ *)
|
||||||
PUSH_ARGS="$(printf "%s\n%s" "$PUSH_ARGS" "${INPUTX#push }")"
|
PUSH_ARGS=$(append "$PUSH_ARGS" "${INPUTX#push }")
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in a new issue