Skip to content

Commit 57a5f45

Browse files
committed
ENH: Parallelize decryption
1 parent 900fb76 commit 57a5f45

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

myba.sh

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -297,21 +297,21 @@ cmd_decrypt () {
297297
trap "rm -rf \"$temp_dir\"" INT HUP TERM EXIT
298298

299299
have_commitable_changes () { WORK_TREE="$temp_dir" git_plain diff --staged --quiet; }
300-
read_decrypt_and_git_add_files () {
301-
while IFS="$_tab" _read_vars _enc_path _plain_path; do
302-
WORK_TREE="$temp_dir" YES_OVERWRITE=1 _decrypt_file "$_enc_path" "$_plain_path"
303-
WORK_TREE="$temp_dir" git_plain add -vf "$_plain_path" # -f to ignore .gitignore
304-
done
305-
}
300+
decrypt_one () { WORK_TREE="$temp_dir" YES_OVERWRITE=1 _decrypt_file "$1" "$2"; }
301+
git_add_files () { WORK_TREE="$temp_dir" git_plain add -vf "$@"; } # -f to ignore .gitignore
306302

307303
_ask_pw
308304
_bind_tty_fd7
309305
if [ "${1:-}" = "--squash" ]; then
310306
git_enc sparse-checkout disable
311-
git_enc ls-files "manifest/" |
312-
grep -RFhf- "$PLAIN_REPO/manifest" |
313-
sort -u |
314-
read_decrypt_and_git_add_files
307+
# Files available as of the current ref and for which password exists
308+
available_files="$(git_enc ls-files |
309+
grep -RFhf- "$PLAIN_REPO/manifest" |
310+
sort -u -k2)"
311+
echo "$available_files" |
312+
_parallelize 0 2 decrypt_one
313+
# shellcheck disable=SC2046
314+
git_add_files $(echo "$available_files" | cut -f2)
315315
if ! have_commitable_changes; then
316316
WORK_TREE="$temp_dir" git_plain commit -m "Restore '$1' at $(date '+%Y-%m-%d %H:%M:%S%z')"
317317
fi
@@ -328,7 +328,9 @@ cmd_decrypt () {
328328
# Decrypt and stage files from this commit into temp_dir
329329
plain_commit="$(git_enc show --name-only --pretty=format: "$_enc_commit" -- "manifest/" |
330330
cut -d/ -f2)"
331-
read_decrypt_and_git_add_files < "$PLAIN_REPO/manifest/$plain_commit"
331+
_parallelize 0 2 decrypt_one < "$PLAIN_REPO/manifest/$plain_commit"
332+
# shellcheck disable=SC2046
333+
git_add_files $(cut -f2 "$PLAIN_REPO/manifest/$plain_commit")
332334

333335
# Commit the changes to the plain repo
334336
_msg="$(git_enc show -s --format='%B' "$_enc_commit" |

0 commit comments

Comments
 (0)