Skip to content

Commit 6335198

Browse files
authored
Merge pull request #75 from wp-cli/sync-repositories-single-pass
Sync all repositories in a single parallel pass, with live per-repository output
2 parents 0ed6b50 + 69780bd commit 6335198

4 files changed

Lines changed: 811 additions & 16 deletions

File tree

‎.maintenance/clone-all-repositories.sh‎

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@
33
set -euo pipefail
44

55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
export SCRIPT_DIR
7+
8+
# peek.php renders a live lane of output per parallel job. Its use is
9+
# optional: it degrades to a plain passthrough on platforms that cannot
10+
# support the display (e.g. Windows) and can be disabled with NO_PEEK=1.
11+
PEEK_PHP="${SCRIPT_DIR}/peek.php"
12+
export PEEK_PHP
13+
14+
# Parallel jobs run behind the peek display, where an interactive prompt is
15+
# instantly overdrawn and would hang the run waiting for input nobody can
16+
# see. Git and ssh prompt on /dev/tty (not stdin), so disable prompting
17+
# entirely: failures then surface as visible errors in the job's lane.
18+
# - GIT_TERMINAL_PROMPT=0: no credential/username prompts from git itself.
19+
# - BatchMode=yes: ssh fails instead of asking for passphrases or host key
20+
# confirmation (keys served by an ssh-agent keep working). Only set when
21+
# GIT_SSH_COMMAND is not already customized.
22+
# - GIT_MERGE_AUTOEDIT=no: a non-fast-forward pull keeps the default merge
23+
# message instead of opening an editor.
24+
export GIT_TERMINAL_PROMPT=0
25+
export GIT_MERGE_AUTOEDIT=no
26+
if [[ -z "${GIT_SSH_COMMAND:-}" ]]; then
27+
export GIT_SSH_COMMAND="ssh -oBatchMode=yes"
28+
fi
629

730
if ! command -v jq &>/dev/null; then
831
echo "Required command 'jq' is not installed or not available in PATH." >&2
@@ -119,8 +142,11 @@ get_destination() {
119142
fi
120143
}
121144

122-
CLONE_LIST=()
123-
UPDATE_FOLDERS=()
145+
# One task per repository: sync-repository.sh clones missing folders and
146+
# refreshes existing ones. Running a single parallel pass over all
147+
# repositories keeps all ${CORES} slots busy for the whole run, instead of
148+
# a clone stage and a refresh stage separated by a barrier.
149+
TASK_LIST=()
124150

125151
while IFS=$'\t' read -r name clone_url ssh_url; do
126152
if [[ -z "${name}" ]]; then
@@ -133,21 +159,14 @@ while IFS=$'\t' read -r name clone_url ssh_url; do
133159

134160
destination=$(get_destination "${name}")
135161

136-
if [[ ! -d "${destination}" ]]; then
137-
if [[ "${PROTOCOL}" == "ssh" ]]; then
138-
CLONE_LIST+=("${destination}"$'\t'"${ssh_url}")
139-
else
140-
CLONE_LIST+=("${destination}"$'\t'"${clone_url}")
141-
fi
162+
if [[ "${PROTOCOL}" == "ssh" ]]; then
163+
TASK_LIST+=("${destination}"$'\t'"${ssh_url}")
164+
else
165+
TASK_LIST+=("${destination}"$'\t'"${clone_url}")
142166
fi
143-
144-
UPDATE_FOLDERS+=("${destination}")
145167
done <<< "${REPOSITORIES}"
146168

147-
if [[ ${#CLONE_LIST[@]} -gt 0 ]]; then
148-
printf '%s\n' "${CLONE_LIST[@]}" | xargs -n2 -P"${CORES}" bash "${SCRIPT_DIR}/clone-repository.sh"
149-
fi
150-
151-
if [[ ${#UPDATE_FOLDERS[@]} -gt 0 ]]; then
152-
printf '%s\n' "${UPDATE_FOLDERS[@]}" | xargs -P"${CORES}" -I% php "${SCRIPT_DIR}/refresh-repository.php" %
169+
if [[ ${#TASK_LIST[@]} -gt 0 ]]; then
170+
printf '%s\n' "${TASK_LIST[@]}" | php "${PEEK_PHP}" -- xargs -n2 -P"${CORES}" \
171+
bash -c 'exec php "${PEEK_PHP}" run -n "$1" -- bash "${SCRIPT_DIR}/sync-repository.sh" "$1" "$2"' _
153172
fi

0 commit comments

Comments
 (0)