From 6bbc02fc423843dae68d11568abac697a27e1052 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Fri, 1 Nov 2013 17:30:05 -0400 Subject: [PATCH] Extract git_fetch_at_ref The really dense logic in the zuulification of trees is actually hard to understand. Extracting it into a common function makes this much easier to understand the AND and OR logic of it. Change-Id: I96f94da8901cd94772d1910d39b48270a45f73e6 --- devstack-vm-gate-wrap.sh | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/devstack-vm-gate-wrap.sh b/devstack-vm-gate-wrap.sh index 66a1c571..cdc9da9e 100755 --- a/devstack-vm-gate-wrap.sh +++ b/devstack-vm-gate-wrap.sh @@ -26,6 +26,19 @@ function function_exists { type $1 2>/dev/null | grep -q 'is a function' } +# Attempt to fetch a git ref for a project, if that ref is not empty +function git_fetch_at_ref { + local project=$1 + local ref=$2 + if [ "$ref" != "" ]; then + git fetch $ZUUL_URL/$project $ref + return $? + else + # return failing + return 1 + fi +} + function git_checkout { local branch=$1 local reset_branch=$branch @@ -125,13 +138,11 @@ function setup_project { # See if we should check out a Zuul ref if [ "$ZUUL_BRANCH" == "$branch" ]; then # See if Zuul prepared a ref for this project - if { [ "$OVERRIDE_ZUUL_REF" != "" ] && \ - git fetch $ZUUL_URL/$project $OVERRIDE_ZUUL_REF ; } || \ - { [ "$ZUUL_REF" != "" ] && \ - git fetch $ZUUL_URL/$project $ZUUL_REF ; } || \ - { [ "$FALLBACK_ZUUL_REF" != "" ] && \ - git fetch $ZUUL_URL/$project $FALLBACK_ZUUL_REF ; }; then - # It's there, so check it out. + if git_fetch_at_ref $project $OVERRIDE_ZUUL_REF || \ + git_fetch_at_ref $project $ZUUL_REF || \ + git_fetch_at_ref $project $FALLBACK_ZUUL_REF; then + + # It's there, so check it out. git_checkout FETCH_HEAD else if [ "$project" == "$ZUUL_PROJECT" ]; then