Skip to content

Commit b176fa9

Browse files
committed
Speed up submodules archival progress
`git submodules` is an expensive command which unless cached is called once per individual submodule. Use temporary file to cache output of this command and remove the file on exit.
1 parent 1e68543 commit b176fa9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

git-archive-all.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ IFS="$(printf '\n \t')"
4848

4949
function cleanup () {
5050
rm -f $TMPFILE
51+
rm -f $TMPLIST
5152
rm -f $TOARCHIVE
5253
IFS="$OLD_IFS"
5354
}
@@ -188,6 +189,7 @@ done
188189
OLD_PWD="`pwd`"
189190
TMPDIR=${TMPDIR:-/tmp}
190191
TMPFILE=`mktemp "$TMPDIR/$PROGRAM.XXXXXX"` # Create a place to store our work's progress
192+
TMPLIST=`mktemp "$TMPDIR/$PROGRAM.submodules.XXXXXX"`
191193
TOARCHIVE=`mktemp "$TMPDIR/$PROGRAM.toarchive.XXXXXX"`
192194
OUT_FILE=$OLD_PWD # assume "this directory" without a name change by default
193195

@@ -246,8 +248,9 @@ fi
246248
if [ $VERBOSE -eq 1 ]; then
247249
echo -n "archiving submodules..."
248250
fi
251+
git submodule >>"$TMPLIST"
249252
while read path; do
250-
TREEISH=$(git submodule | grep "^ .*${path%/} " | cut -d ' ' -f 2) # git submodule does not list trailing slashes in $path
253+
TREEISH=$(grep "^ .*${path%/} " "$TMPLIST" | cut -d ' ' -f 2) # git submodule does not list trailing slashes in $path
251254
cd "$path"
252255
git archive --format=$FORMAT --prefix="${PREFIX}$path" $ARCHIVE_OPTS ${TREEISH:-HEAD} > "$TMPDIR"/"$(echo "$path" | sed -e 's/\//./g')"$FORMAT
253256
if [ $FORMAT == 'zip' ]; then

0 commit comments

Comments
 (0)