From 6b655b7f82a080370305ac6c0b8a8f7d12a4c0af Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Thu, 28 Feb 2019 15:56:47 +0300 Subject: [PATCH] Refactoring: Factor out run-repos and run-workdirs --- edit-description-repos | 2 +- fix-config-repos | 2 +- fsck-repos | 4 +--- ls-assumed | 7 ++----- ls-assumed-repos | 2 +- ls-branches-repos | 2 +- ls-dirty | 10 +++------- ls-dirty-repos | 2 +- ls-no-description-repos | 2 +- ls-remotes-repos | 2 +- ls-stash | 6 ++---- ls-stash-repos | 2 +- ls-status | 15 ++++++--------- ls-status-repos | 2 +- run-recursive | 2 +- run-repos | 17 +++++++++++++++++ run-workdirs | 18 ++++++++++++++++++ set-commit-date-repos | 4 +--- 18 files changed, 60 insertions(+), 41 deletions(-) create mode 100755 run-repos create mode 100755 run-workdirs diff --git a/edit-description-repos b/edit-description-repos index bd6c81a..8c48ca5 100755 --- a/edit-description-repos +++ b/edit-description-repos @@ -4,4 +4,4 @@ cd "`dirname \"$0\"`" && prog_dir="`pwd`" && export prog_dir -exec "$prog_dir"/do-all 'cd "$d" && "$prog_dir"/edit-description-recursive || exit 1' +exec "$prog_dir"/run-repos "$prog_dir"/edit-description-recursive diff --git a/fix-config-repos b/fix-config-repos index 404f7d2..da5e46e 100755 --- a/fix-config-repos +++ b/fix-config-repos @@ -4,4 +4,4 @@ cd "`dirname \"$0\"`" && prog_dir="`pwd`" && export prog_dir -exec "$prog_dir"/do-all 'cd "$d" && "$prog_dir"/fix-config-recursive || exit 1' +exec "$prog_dir"/run-repos "$prog_dir"/fix-config-recursive diff --git a/fsck-repos b/fsck-repos index a31c8bb..7e05666 100755 --- a/fsck-repos +++ b/fsck-repos @@ -4,6 +4,4 @@ cd "`dirname \"$0\"`" && prog_dir="`pwd`" && export prog_dir -exec "$prog_dir"/do-all \ - 'echo "----- $d -----" && cd "$d" &&' \ - '"$prog_dir"/fsck-recursive || exit 1' +exec "$prog_dir"/run-repos -v $prog_dir"/fsck-recursive diff --git a/ls-assumed b/ls-assumed index 7f7a407..7516733 100755 --- a/ls-assumed +++ b/ls-assumed @@ -1,8 +1,5 @@ #! /bin/sh -d="`git rev-parse --show-toplevel`" && -g="`git rev-parse --git-dir`" && - -if [ -n "$d" ]; then - if [ -n "`git ls-files -v | grep ^[a-z]`" ]; then echo "$d"; fi +if [ -n "`git ls-files -v | grep ^[a-z]`" ]; then + pwd fi diff --git a/ls-assumed-repos b/ls-assumed-repos index c3d177f..085626f 100755 --- a/ls-assumed-repos +++ b/ls-assumed-repos @@ -4,4 +4,4 @@ cd "`dirname \"$0\"`" && prog_dir="`pwd`" && export prog_dir -exec "$prog_dir"/do-all 'cd "$d" && "$prog_dir"/ls-assumed-recursive || exit 1' +exec "$prog_dir"/run-workdirs "$prog_dir"/ls-assumed-recursive diff --git a/ls-branches-repos b/ls-branches-repos index 737a0a3..6efd112 100755 --- a/ls-branches-repos +++ b/ls-branches-repos @@ -9,4 +9,4 @@ if [ "$1" = "-v" ]; then fi export verbose -exec "$prog_dir"/do-all 'cd "$d" && "$prog_dir"/ls-branches-recursive || exit 1' +exec "$prog_dir"/run-repos "$prog_dir"/ls-branches-recursive diff --git a/ls-dirty b/ls-dirty index 77cad68..d2eaac4 100755 --- a/ls-dirty +++ b/ls-dirty @@ -1,10 +1,6 @@ #! /bin/sh -d="`git rev-parse --show-toplevel`" && - -if [ -n "$d" ]; then - if [ -n "`git ls-files --deleted --modified --others --unmerged --killed --exclude-standard --directory --no-empty-directory`" ] - then - echo "$d" - fi +if [ -n "`git ls-files --deleted --modified --others --unmerged --killed --exclude-standard --directory --no-empty-directory`" ] +then + pwd fi diff --git a/ls-dirty-repos b/ls-dirty-repos index fa9df2f..d22680f 100755 --- a/ls-dirty-repos +++ b/ls-dirty-repos @@ -4,4 +4,4 @@ cd "`dirname \"$0\"`" && prog_dir="`pwd`" && export prog_dir -exec "$prog_dir"/do-all 'cd "$d" && "$prog_dir"/ls-dirty-recursive || exit 1' +exec "$prog_dir"/run-workdirs "$prog_dir"/ls-dirty-recursive diff --git a/ls-no-description-repos b/ls-no-description-repos index 76c689b..e80a3e0 100755 --- a/ls-no-description-repos +++ b/ls-no-description-repos @@ -4,4 +4,4 @@ cd "`dirname \"$0\"`" && prog_dir="`pwd`" && export prog_dir -exec "$prog_dir"/do-all 'cd "$d" && "$prog_dir"/ls-no-description-recursive || exit 1' +exec "$prog_dir"/run-repos "$prog_dir"/ls-no-description-recursive diff --git a/ls-remotes-repos b/ls-remotes-repos index 966989f..5cfb391 100755 --- a/ls-remotes-repos +++ b/ls-remotes-repos @@ -9,4 +9,4 @@ if [ "$1" = "-v" ]; then fi export verbose -exec "$prog_dir"/do-all 'cd "$d" && "$prog_dir"/ls-remotes-recursive || exit 1' +exec "$prog_dir"/run-repos "$prog_dir"/ls-remotes-recursive diff --git a/ls-stash b/ls-stash index 1933508..5f1e57f 100755 --- a/ls-stash +++ b/ls-stash @@ -1,7 +1,5 @@ #! /bin/sh -d="`git rev-parse --show-toplevel`" && - -if [ -n "$d" ]; then - if [ -n "`git stash list`" ]; then echo "$d"; fi +if [ -n "`git stash list`" ]; then + pwd fi diff --git a/ls-stash-repos b/ls-stash-repos index 9e057ba..4dcca86 100755 --- a/ls-stash-repos +++ b/ls-stash-repos @@ -4,4 +4,4 @@ cd "`dirname \"$0\"`" && prog_dir="`pwd`" && export prog_dir -exec "$prog_dir"/do-all 'cd "$d" && "$prog_dir"/ls-stash-recursive || exit 1' +exec "$prog_dir"/run-workdirs "$prog_dir"/ls-stash-recursive diff --git a/ls-status b/ls-status index 5d38083..3bcc50c 100755 --- a/ls-status +++ b/ls-status @@ -1,12 +1,9 @@ #! /bin/sh -d="`git rev-parse --show-toplevel`" && +d="`pwd`" && +cd "`dirname \"$0\"`" && +prog_dir="`pwd`" && +export prog_dir && +cd "$d" && -if [ -n "$d" ]; then - cd "`dirname \"$0\"`" && - prog_dir="`pwd`" && - export prog_dir && - cd "$d" && - - if [ -n "`"$prog_dir"/git-status.sh --short`" ]; then echo "$d"; fi -fi +if [ -n "`"$prog_dir"/git-status.sh --short`" ]; then echo "$d"; fi diff --git a/ls-status-repos b/ls-status-repos index 349cee7..bfae2ff 100755 --- a/ls-status-repos +++ b/ls-status-repos @@ -4,4 +4,4 @@ cd "`dirname \"$0\"`" && prog_dir="`pwd`" && export prog_dir -exec "$prog_dir"/do-all 'cd "$d" && "$prog_dir"/ls-status-recursive || exit 1' +exec "$prog_dir"/run-workdirs "$prog_dir"/ls-status-recursive diff --git a/run-recursive b/run-recursive index 3599293..5881aed 100755 --- a/run-recursive +++ b/run-recursive @@ -3,5 +3,5 @@ "$@" && if [ -f .gitmodules ]; then - exec git submodule foreach --quiet --recursive "$@" + exec git submodule foreach --quiet --recursive "$@" || exit 1 fi diff --git a/run-repos b/run-repos new file mode 100755 index 0000000..c38b923 --- /dev/null +++ b/run-repos @@ -0,0 +1,17 @@ +#! /bin/sh + +cd "`dirname \"$0\"`" && +prog_dir="`pwd`" && +export prog_dir + +if [ "$1" = "-v" ]; then + verbose=1 + shift +fi + +cat "$prog_dir"/locate-all.list | +while read d; do + if ! test -d "$d"; then echo "No such dir: $d" >&2; continue; fi + if [ "$verbose" = 1 ]; then echo "$d"; fi + cd "$d" && "$@" < /dev/tty || exit 1 +done diff --git a/run-workdirs b/run-workdirs new file mode 100755 index 0000000..01b6a3d --- /dev/null +++ b/run-workdirs @@ -0,0 +1,18 @@ +#! /bin/sh + +cd "`dirname \"$0\"`" && +prog_dir="`pwd`" && +export prog_dir + +if [ "$1" = "-v" ]; then + verbose=1 + shift +fi + +cat "$prog_dir"/locate-all.list | +while read d; do + if ! test -d "$d"; then echo "No such dir: $d" >&2; continue; fi + if ! test -d "$d/.git"; then continue; fi # Skip bare repos + if [ "$verbose" = 1 ]; then echo "$d"; fi + cd "$d" && "$@" < /dev/tty || exit 1 +done diff --git a/set-commit-date-repos b/set-commit-date-repos index 727b083..cdf1bc0 100755 --- a/set-commit-date-repos +++ b/set-commit-date-repos @@ -5,6 +5,4 @@ cd "`dirname \"$0\"`" && prog_dir="`pwd`" && -exec "$prog_dir"/do-all \ - 'test "$g" = "$d/.git" || continue &&' \ - 'cd "$d"; echo "----- $d -----"; "$prog_dir"/set-commit-date-recursive' +exec "$prog_dir"/run-workdirs -v "$prog_dir"/set-commit-date-recursive' -- 2.39.5