pgit.sh: Beautify logging

Log to stderr and add some ASCII-art around the output. Also, add a
--porcelain option to allow more stable output parsing. Subsequently,
use that option in make targets parsing the output, notably make diff
and make git-show-xxx.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-03-25 12:19:18 +01:00
commit 27bf98f747
2 changed files with 46 additions and 10 deletions

View file

@ -4,7 +4,13 @@
log()
{
echo "$myname $*"
local prefix="| "
[ "$porcelain" = 0 ] || prefix=""
if [ "$1" ]; then
echo "$prefix$*" >&2
else
sed "s/^/$prefix/" >&2
fi
}
err()
@ -38,6 +44,26 @@ fat_marker()
log "# ====================================================$(counter) $@"
}
log_start_stop()
{
[ "$porcelain" = 1 ] || return
local b e
if [ "$1" = start ]; then
b=","
e=">"
else
b="\`"
e="<"
fi
shift
echo "$b----------------------------------------------- Running $cmdline --$e--" >&2
}
goodbye()
{
log_start_stop stop
}
#
# Guess and set the following global variables:
#
@ -72,7 +98,11 @@ set_global_variables()
run_git()
{
marker git "$@"
git "$@"
if [ "$porcelain" = 1 ]; then
git "$@"
else
git "$@" 2>&1 | log
fi
}
# ----------------- Commands
@ -194,7 +224,7 @@ cmd_get()
if [ -z "$projects" ]; then
projects=`$jw_projects projects list-repos --from-owner $from_user $remote_base`
[ "$?" != 0 ] && exit 1
[ "$?" != 0 ] && fatal "Failed to enumerate repositories"
fi
if [ "$remote_user" ]; then
@ -224,7 +254,7 @@ cmd_get()
[ "$refspec_arg" -a "$refspec_arg" != "$from_user:$from_ref:$to_ref" ] && log_refspec="$log_refspec ($refspec_arg)"
fat_marker "Getting project $project_name from $log_refspec"
if [ -d $project_dir ]; then
run_git -C $project_dir remote | grep -q "^$remote_name$" || {
git -C $project_dir remote | grep -q "^$remote_name$" || {
run_git -C $project_dir remote add $remote_name $pull_url
[ "$from_user" = "$remote_user" ] || run_git -C $project_dir remote set-url --push $remote_name no_push
}
@ -265,7 +295,9 @@ cmd_diff()
)
myname=${0##*/}
log "Running $0 $@"
cmdline="$myname $*"
porcelain=0
log_start_stop start
log "GIT_SSH=$GIT_SSH"
log "JW_PKG_SSH_EXTRA_OPTS=$JW_PKG_SSH_EXTRA_OPTS"
@ -280,6 +312,9 @@ while [ "${1:0:1}" = - ]; do
global_remote_base="$2"
shift
;;
'--porcelain')
porcelain=1
;;
esac
shift
done
@ -299,12 +334,13 @@ while [ "${1:0:1}" = - ]; do
case $1 in
'--login')
remote_user="$2"
shift 2
shift
;;
*)
break
;;
esac
shift
done
case $cmd in