From 0db974d778b423c636bfd7620f1889c88de41de7 Mon Sep 17 00:00:00 2001 From: yasuda Date: Tue, 6 Feb 2024 16:14:03 +0900 Subject: [PATCH 1/2] Support other tar format configured by git `tar.FORMAT.command` setting --- git-archive-all.sh | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/git-archive-all.sh b/git-archive-all.sh index b72dc4d..7a32186 100755 --- a/git-archive-all.sh +++ b/git-archive-all.sh @@ -271,7 +271,21 @@ if [ $VERBOSE -eq 1 ]; then fi # Concatenate archives into a super-archive. if [ $SEPARATE -eq 0 -o "-" == "$OUT_FILE" ]; then - if [ $FORMAT == 'tar.gz' ]; then + cmd=$(git config --get "tar.$FORMAT.command" || true) + if [ $FORMAT == 'tar' ]; then + sed -e '1d' $TMPFILE | while read file; do + $TARCMD --concatenate -f "$superfile" "$file" && rm -f "$file" + done + elif [ -n "$cmd" ]; then + superfile_=${superfile%.$FORMAT}.tar + $cmd -d < "$superfile" > "$superfile_" && rm -f "$superfile" + sed -e '1d' $TMPFILE | while read file; do + file_=${file%.$FORMAT}.tar + $cmd -d < "$file" > "$file_" && rm -f "$file" + $TARCMD --concatenate -f "$superfile_" "$file_" && rm -f "$file_" + done + $cmd < "$superfile_" > "$superfile" && rm -f "$superfile_" + elif [ $FORMAT == 'tar.gz' ]; then gunzip $superfile superfile=${superfile:0: -3} # Remove '.gz' sed -e '1d' $TMPFILE | while read file; do @@ -281,10 +295,6 @@ if [ $SEPARATE -eq 0 -o "-" == "$OUT_FILE" ]; then done gzip $superfile superfile=$superfile.gz - elif [ $FORMAT == 'tar' ]; then - sed -e '1d' $TMPFILE | while read file; do - $TARCMD --concatenate -f "$superfile" "$file" && rm -f "$file" - done elif [ $FORMAT == 'zip' ]; then sed -e '1d' $TMPFILE | while read file; do # zip incorrectly stores the full path, so cd and then grow From 86015f1eab31085b89f3b773816bffa767a19540 Mon Sep 17 00:00:00 2001 From: yasuda Date: Tue, 6 Feb 2024 17:30:19 +0900 Subject: [PATCH 2/2] Use raw tar format in processing for `tar.*` formats --- git-archive-all.sh | 49 ++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/git-archive-all.sh b/git-archive-all.sh index 7a32186..1092767 100755 --- a/git-archive-all.sh +++ b/git-archive-all.sh @@ -115,6 +115,7 @@ VERBOSE=0 TARCMD=`command -v gtar || command -v gnutar || command -v tar` FORMAT=tar +FORMAT_=tar # Format in processing PREFIX= TREEISH=HEAD ARCHIVE_OPTS= @@ -134,6 +135,9 @@ while test $# -gt 0; do --format ) shift FORMAT="$1" + if [ "${FORMAT}" == "zip" ]; then + FORMAT_="zip" + fi shift ;; @@ -202,7 +206,7 @@ if [ ! -z "$1" ]; then fi # Validate parameters; error early, error often. -if [ "-" == "$OUT_FILE" -o $SEPARATE -ne 1 ] && [ "$FORMAT" == "tar" -a `$TARCMD --help | grep -q -- "--concatenate"; echo $?` -ne 0 ]; then +if [ "-" == "$OUT_FILE" -o $SEPARATE -ne 1 ] && [ "$FORMAT_" == "tar" -a `$TARCMD --help | grep -q -- "--concatenate"; echo $?` -ne 0 ]; then echo "Your 'tar' does not support the '--concatenate' option, which we need" echo "to produce a single tarfile. Either install a compatible tar (such as" echo "gnutar), or invoke $PROGRAM with the '--separate' option." @@ -220,12 +224,12 @@ fi if [ $VERBOSE -eq 1 ]; then echo -n "creating superproject archive..." fi -rm -f $TMPDIR/$(basename "$(pwd)").$FORMAT -git archive --format=$FORMAT --prefix="$PREFIX" $ARCHIVE_OPTS $TREEISH > $TMPDIR/$(basename "$(pwd)").$FORMAT +rm -f $TMPDIR/$(basename "$(pwd)").$FORMAT_ +git archive --format=$FORMAT_ --prefix="$PREFIX" $ARCHIVE_OPTS $TREEISH > $TMPDIR/$(basename "$(pwd)").$FORMAT_ if [ $VERBOSE -eq 1 ]; then echo "done" fi -echo $TMPDIR/$(basename "$(pwd)").$FORMAT >| $TMPFILE # clobber on purpose +echo $TMPDIR/$(basename "$(pwd)").$FORMAT_ >| $TMPFILE # clobber on purpose superfile=`head -n 1 $TMPFILE` if [ $VERBOSE -eq 1 ]; then @@ -253,13 +257,13 @@ git submodule >>"$TMPLIST" while read path; do TREEISH=$(grep "^ .*${path%/} " "$TMPLIST" | cut -d ' ' -f 2) # git submodule does not list trailing slashes in $path cd "$path" - rm -f "$TMPDIR"/"$(echo "$path" | sed -e 's/\//./g')"$FORMAT - git archive --format=$FORMAT --prefix="${PREFIX}$path" $ARCHIVE_OPTS ${TREEISH:-HEAD} > "$TMPDIR"/"$(echo "$path" | sed -e 's/\//./g')"$FORMAT - if [ $FORMAT == 'zip' ]; then + rm -f "$TMPDIR"/"$(echo "$path" | sed -e 's/\//./g')"$FORMAT_ + git archive --format=$FORMAT_ --prefix="${PREFIX}$path" $ARCHIVE_OPTS ${TREEISH:-HEAD} > "$TMPDIR"/"$(echo "$path" | sed -e 's/\//./g')"$FORMAT_ + if [ $FORMAT_ == 'zip' ]; then # delete the empty directory entry; zipped submodules won't unzip if we don't do this zip -d "$(tail -n 1 $TMPFILE)" "${PREFIX}${path%/}" >/dev/null 2>&1 || true # remove trailing '/' fi - echo "$TMPDIR"/"$(echo "$path" | sed -e 's/\//./g')"$FORMAT >> $TMPFILE + echo "$TMPDIR"/"$(echo "$path" | sed -e 's/\//./g')"$FORMAT_ >> $TMPFILE cd "$OLD_PWD" done < $TOARCHIVE if [ $VERBOSE -eq 1 ]; then @@ -272,29 +276,18 @@ fi # Concatenate archives into a super-archive. if [ $SEPARATE -eq 0 -o "-" == "$OUT_FILE" ]; then cmd=$(git config --get "tar.$FORMAT.command" || true) - if [ $FORMAT == 'tar' ]; then + if [ $FORMAT_ == 'tar' ]; then sed -e '1d' $TMPFILE | while read file; do $TARCMD --concatenate -f "$superfile" "$file" && rm -f "$file" done - elif [ -n "$cmd" ]; then - superfile_=${superfile%.$FORMAT}.tar - $cmd -d < "$superfile" > "$superfile_" && rm -f "$superfile" - sed -e '1d' $TMPFILE | while read file; do - file_=${file%.$FORMAT}.tar - $cmd -d < "$file" > "$file_" && rm -f "$file" - $TARCMD --concatenate -f "$superfile_" "$file_" && rm -f "$file_" - done - $cmd < "$superfile_" > "$superfile" && rm -f "$superfile_" - elif [ $FORMAT == 'tar.gz' ]; then - gunzip $superfile - superfile=${superfile:0: -3} # Remove '.gz' - sed -e '1d' $TMPFILE | while read file; do - gunzip $file - file=${file:0: -3} - $TARCMD --concatenate -f "$superfile" "$file" && rm -f "$file" - done - gzip $superfile - superfile=$superfile.gz + + if [ "${FORMAT}" != "tar" -a -n "$cmd" ]; then + $cmd < "$superfile" > "${superfile%.tar}.${FORMAT}" && rm -f "$superfile" + superfile="${superfile%.tar}.${FORMAT}" + elif [ $FORMAT == 'tar.gz' ]; then + gzip $superfile + superfile="$superfile.gz" + fi elif [ $FORMAT == 'zip' ]; then sed -e '1d' $TMPFILE | while read file; do # zip incorrectly stores the full path, so cd and then grow