pgit.sh: Beautify variable names some more

Continue to name variables in pgit.sh somewhat more consistently,
notably turn somevar into some_var. Plus some additional cleanup.
Still not a beauty.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-02-21 08:05:57 +01:00
commit 82b41ffce2

View file

@ -130,14 +130,12 @@ cmd_clone()
cd $projects_dir cd $projects_dir
local projects="$PGIT_CLONE_PROJECTS" local projects="$PGIT_CLONE_PROJECTS"
local ignore="$PGIT_IGNORE" local ignore="$PGIT_IGNORE"
local thisdir="${0%/*}" local this_dir="${0%/*}"
local jw_projects="/usr/bin/python3 $thisdir/jw-pkg.py" local jw_projects="/usr/bin/python3 $this_dir/jw-pkg.py"
local create_remote_user_repos=false local create_remote_user_repos=false
local long_opts="create-remote-user-repos" local long_opts="create-remote-user-repos"
local refspec_arg refspec=() local refspec_arg refspec=()
long_opts="$long_opts,refspec:" long_opts="$long_opts,refspec:"
local login="$whoami"
[ "$remote_user" ] && login="$remote_user"
local opts local opts
opts=$(getopt -o C --long "$long_opts" -n clone -- "$@") || fatal "Failed to parse options $@" opts=$(getopt -o C --long "$long_opts" -n clone -- "$@") || fatal "Failed to parse options $@"
@ -155,26 +153,22 @@ cmd_clone()
*) *)
fatal "Unknown option $1" fatal "Unknown option $1"
;; ;;
esac esac
shift shift
done done
local fromuser="${refspec[0]}" local git_srv_admin="$SSH $remote_user@git.janware.com /opt/jw-pkg/bin/git-srv-admin.sh"
local fromref="${refspec[1]}" local from_user="${refspec[0]}"
local toref="${refspec[2]}" [ "$from_user" ] || from_user=$whoami
[ "$fromuser" ] || fromuser=$whoami
[ "$fromref" ] || fromref=master
local git_srv_admin="$SSH $login@git.janware.com /opt/jw-pkg/bin/git-srv-admin.sh"
if [ -z "$projects" ]; then if [ -z "$projects" ]; then
projects=`$jw_projects projects list-repos --from-user $fromuser $remote_base` projects=`$jw_projects projects list-repos --from-user $from_user $remote_base`
[ "$?" != 0 ] && exit 1 [ "$?" != 0 ] && exit 1
fi fi
if [ "$login" ]; then if [ "$remote_user" ]; then
[ "${remote_base/@/}" = "${remote_base}" ] || fatal "Specified both --login $login and user in URL $remote_base" [ "${remote_base/@/}" = "${remote_base}" ] || fatal "Specified both --login $remote_user and user in URL $remote_base"
remote_base=$(echo $remote_base | sed "s|://|://$login@|") remote_base=$(echo $remote_base | sed "s|://|://$remote_user@|")
fi fi
n_projects=`echo $projects | wc -w` n_projects=`echo $projects | wc -w`
@ -182,42 +176,41 @@ cmd_clone()
local project_dir local project_dir
for project_dir in $projects; do for project_dir in $projects; do
local project_name=$(readlink -f $project_dir | xargs basename) local project_name=$(readlink -f $project_dir | xargs basename)
if echo $ignore | grep -q "\b$project_name\b"; then echo $ignore | grep -q "\b$project_name\b" && continue
continue
fi
cur=`expr $cur + 1` cur=`expr $cur + 1`
local pullurl=$remote_base/$fromuser$remote_subpath/$project_name local pull_url=$remote_base/$from_user$remote_subpath/$project_name
local pushurl=$remote_base/$login$remote_subpath/$project_name local push_url=$remote_base/$remote_user$remote_subpath/$project_name
fat_marker "Fetching project $project_name from user $fromuser" local cur_ref=$(git -C $project_dir rev-parse --abbrev-ref HEAD)
local remotename="jw-$fromuser" local remote_name="jw-$from_user"
if [ "$fromuser" = "$login" ]; then local from_ref="${refspec[1]}"
remotename="origin" local to_ref="${refspec[2]}"
fi [ "$from_ref" ] || from_ref=master
local curref=$(git -C $project_dir rev-parse --abbrev-ref HEAD) [ "$from_user" = "$remote_user" ] && remote_name="origin"
[ "$toref" = "current-branch" ] && toref=$curref [ "$to_ref" = "current-branch" ] && to_ref=$cur_ref
[ "$fromref" = "current-branch" ] && fromref=$curref [ "$from_ref" = "current-branch" ] && from_ref=$cur_ref
[ "$refspec_arg" != "$fromuser:$fromref:$toref" ] && log "Fetching $fromuser:$fromref:$toref ($refspec_arg)" [ "$refspec_arg" != "$from_user:$from_ref:$to_ref" ] && log "Fetching $from_user:$from_ref:$to_ref ($refspec_arg)"
fat_marker "Fetching project $project_name from user $from_user"
if [ -d $project_dir ]; then if [ -d $project_dir ]; then
run_git -C $project_dir remote | grep -q "^$remotename$" || { run_git -C $project_dir remote | grep -q "^$remote_name$" || {
run_git -C $project_dir remote add $remotename $pullurl run_git -C $project_dir remote add $remote_name $pull_url
[ "$fromuser" = "$login" ] || run_git -C $project_dir remote set-url --push $remotename no_push [ "$from_user" = "$remote_user" ] || run_git -C $project_dir remote set-url --push $remote_name no_push
} }
run_git -C $project_dir fetch --prune --recurse-submodules=on-demand $remotename $fromref run_git -C $project_dir fetch --prune --recurse-submodules=on-demand $remote_name $from_ref
run_git -C $project_dir submodule foreach --recursive 'git fetch --tags -f origin' run_git -C $project_dir submodule foreach --recursive 'git fetch --tags -f origin'
if [ "$toref" ]; then if [ "$to_ref" ]; then
run_git -C $project_dir rebase --autostash $remotename/$fromref $toref run_git -C $project_dir rebase --autostash $remote_name/$from_ref $to_ref
run_git -C $project_dir merge --ff-only $remotename/$fromref $toref run_git -C $project_dir merge --ff-only $remote_name/$from_ref $to_ref
fi fi
else else
run_clone $remote_base/$fromuser$remote_subpath/$project_name $project_dir run_clone $remote_base/$from_user$remote_subpath/$project_name $project_dir
if [ "$fromuser" != "$login" ]; then if [ "$from_user" != "$remote_user" ]; then
run_git -C $project_dir remote rename origin $remotename || fatal "Failed to rename remote in $project_dir" run_git -C $project_dir remote rename origin $remote_name || fatal "Failed to rename remote in $project_dir"
run_git -C $project_dir remote set-url --push $remotename no_push run_git -C $project_dir remote set-url --push $remote_name no_push
if [ $create_remote_user_repos = true ]; then if [ $create_remote_user_repos = true ]; then
$git_srv_admin -u $login -j create-personal-project $project_name $git_srv_admin -u $remote_user -j create-personal-project $project_name
run_git -C $project_dir remote add origin $pushurl run_git -C $project_dir remote add origin $push_url
run_git -C $project_dir push --recurse-submodules=on-demand origin master run_git -C $project_dir push --recurse-submodules=on-demand origin master
$git_srv_admin -u $login -j update-descriptions $project_name $git_srv_admin -u $remote_user -j update-descriptions $project_name
run_git -C $project_dir branch --set-upstream-to origin/master master run_git -C $project_dir branch --set-upstream-to origin/master master
fi fi
fi fi
@ -265,6 +258,7 @@ fi
cmd=$1 cmd=$1
shift shift
remote_user=$(id -un)
while [ "${1:0:1}" = - ]; do while [ "${1:0:1}" = - ]; do
case $1 in case $1 in
'--login') '--login')