AOSP mirroring into local gerrit

60 Views Asked by At

I'm trying to mirror the AOSP code into our local Gerrit system using the bash method below.

#!/bin/bash

repo init -u https://android.googlesource.com/platform/manifest -b android-14.0.0_r9 --mirror
repo sync
repo_list=`repo list -p`
repo forall -c '
if [[ ${REPO_PATH} =~ $repo_list ]]; then
ssh -p 29418 gerritadmin@local-gerrit-host gerrit create-project aosp/${REPO_PATH} --parent All-Projects || echo "Failed to create project for ${REPO_PATH}"
fi
git push ssh://gerritadmin@local-gerrit-host:29418/aosp/${REPO_PATH} +refs/heads/* +refs/tags/* || echo "Failed to push ${REPO_PATH}"
'

However, I'm encountering an issue within the repo forall loop. I have an if condition, but it doesn't seem to work as expected. I'm not sure whether inside repo forall loop bash IF condition work or not.

Mainly, I'm aiming to minimize multiple Gerrit SSH connections to our to local gerrit server to reduce the load.

Could you please assist me in finding the correct approach to achieve this?

1

There are 1 best solutions below

1
ElpieKay On

There are some issues in the script.

if [[ ${REPO_PATH} =~ $repo_list ]]; then
    ssh -p 29418 gerritadmin@local-gerrit-host gerrit create-project aosp/${REPO_PATH} --parent All-Projects || echo "Failed to create project for ${REPO_PATH}"
fi

It should be $repo_list =~ ${REPO_PATH}. Otherwise, it's always false unless there is only one project. Even so, the if clause is unnecessary and flawed. repo list -p has the same effect with repo forall -c 'echo $REPO_PATH'. $REPO_PATH is always among the output of repo list -p. Besides, if there is a path foo/bar_baz in $repo_list and $REPO_PATH is foo/bar, the test still passes while it may be not expected.

Actually, the if clause here should be testing whether the project aosp/${REPO_PATH} has already existed on your Gerrit before it's to be created. First, list all the projects that contain the substring aosp/${REPO_PATH}. Unfortunately, it does not take a regular expression.

ssh -p 29418 gerritadmin@local-gerrit-host gerrit ls-projects -m "aosp/${REPO_PATH}" < /dev/null

And then test if one of the listed projects is exactly aosp/${REPO_PATH} instead of something like aosp/${REPO_PATH}_foo. I think it's also okay to omit the test because gerrit create-project would raise an error if the project already exists.

In my experience, always append < /dev/null to the Gerrit SSH CLI, especially when it's used in a loop. Without it, the loop breaks after the first run.

ssh -p 29418 gerritadmin@local-gerrit-host gerrit create-project aosp/${REPO_PATH} --parent All-Projects < /dev/null