Skip to content

Commit

Permalink
gce-xfstests: use an intelligent default for the git repo
Browse files Browse the repository at this point in the history
If the git repository is not explicitly specified, use hueristics
using the commit or branch name to determine a default repo.

Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
tytso committed Dec 23, 2024
1 parent f62433b commit ad8889b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 10 deletions.
2 changes: 1 addition & 1 deletion run-fstests/config.gce
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ GCE_MIN_SCR_SIZE=100
# Enable serial port access by default
#
GCE_SERIAL_PORT_ACCESS=TRUE
GIT_REPO=https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

# GIT_REPOS can be used to define user-specific git repository aliases
# in ~/.config/gce-xfstests. It will override any default mappings defined
# by DEF_GIT_REPOS
declare -A GIT_REPOS
declare -A DEF_GIT_REPOS
DEF_GIT_REPOS[linux.git]=https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
DEF_GIT_REPOS[stable.git]=https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
DEF_GIT_REPOS[next.git]=https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
DEF_GIT_REPOS[next-history.git]=https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next-history.git
Expand Down
83 changes: 74 additions & 9 deletions run-fstests/util/parse_cli
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,58 @@ validate_branch_name()
fi
}

function set_git_repo ()
{
if test -n "${GIT_REPOS[$1]}" ; then
GIT_REPO="${GIT_REPOS[$1]}"
elif test -n "${DEF_GIT_REPOS[$1]}" ; then
GIT_REPO="${DEF_GIT_REPOS[$1]}"
else
GIT_REPO="$1"
fi
case "$GIT_REPO" in
http://*|https://*|git://*) ;;
*)
echo "Invalid git repo: $GIT_REPO"
exit 1
esac
local host=$(echo "$GIT_REPO" | sed -e 's;[a-z]*://;;' -e 's;/.*$;;')
if type host >& /dev/null && ! host "$host" >& /dev/null ; then
echo "Invalid hostname in git repo: $GIT_REPO"
exit 1
fi
}

function get_default_repo_branch ()
{
case "$1" in
fs-next|fs-current|pending-fixes)
echo "next.git"
;;
linux-[0-9].*.y)
echo "stable-rc.git"
;;
*)
echo "linux.git"
;;
esac
}

function get_default_repo_commit ()
{
case "$1" in
next-[12]*)
echo "next-history.git"
;;
v[0-9].*.*)
echo "stable.git"
;;
*)
get_default_repo_branch "$1"
;;
esac
}

SKIP_KERNEL_ARCH_PROBE=

shortopts="ac:C:g:hI:m:n:No:O:r:vx:X:"
Expand Down Expand Up @@ -673,13 +725,7 @@ while (( $# >= 1 )); do
;;
--repo) shift
supported_flavors gce
if test -n "${GIT_REPOS[$1]}" ; then
GIT_REPO="${GIT_REPOS[$1]}"
elif test -n "${DEF_GIT_REPOS[$1]}" ; then
GIT_REPO="${DEF_GIT_REPOS[$1]}"
else
GIT_REPO="$1"
fi
set_git_repo "$1"
;;
--commit) shift
supported_flavors gce
Expand Down Expand Up @@ -1010,6 +1056,27 @@ then
exit 1
fi

if test -z "$GIT_REPO" -a -n "$COMMIT" ; then
set_git_repo $(get_default_repo_commit "$COMMIT")
fi

if test -z "$GIT_REPO" -a -n "$BISECT_BAD" ; then
set_git_repo $(get_default_repo_commit "$BISECT_BAD")
fi

if test -z "$GIT_REPO" -a -n "$BISECT_GOOD" ; then
b=$(echo "$BISECT_GOOD" | sed -e 's/|.*//')
set_git_repo $(get_default_repo_commit "$b")
fi

if test -z "$GIT_REPO" -a -n "$BRANCH" ; then
set_git_repo $(get_default_repo_branch "$BRANCH")
fi

if test -n "$NO_ACTION" ; then
echo "GIT_REPO: $GIT_REPO"
fi

if test -n "$COMMIT"
then
validate_commit_name $COMMIT
Expand Down Expand Up @@ -1044,8 +1111,6 @@ fi

if test -n "$GIT_REPO" -a -z "$RUN_ON_LTM" -a -z "$RUN_ON_KCS"
then
echo "GIT_REPO: $GIT_REPO"
echo ""
echo "Specifying a git repository only makes sense with LTM or KCS"
exit 1
fi
Expand Down

0 comments on commit ad8889b

Please sign in to comment.