Browse Source

Allow to pass multiple arguments to pkg.sh script

 + For instance, ./pkg.sh HEAD master dev creates archives for current
 HEAD, master and dev. Interesting to use like this:

git tag --contains=initial | xargs ./pkg.sh

and create a tarball for each tagged commit.
Leo 9 years ago
parent
commit
1fc43c517a
1 changed files with 32 additions and 25 deletions
  1. 32 25
      pkg.sh

+ 32 - 25
pkg.sh

@@ -2,6 +2,32 @@
 # A little script to create tarball, especially for Oasis2Opam
 # You may pass source commit as first argument, HEAD is used if omitted.
 
+create_archive() {
+  # Target commit (TC) i.e. commit from which tarball is created.
+  TC=$1
+  TCID=`git rev-parse ${TC}`
+  echo "Creating tarball from commit ${TCID} ($TC)."
+
+  # If no tag, use commit SHA1
+  id=`git describe --abbrev=10 --candidates=50 ${TCID}`
+  name=oclaunch_${id}_source # _source emphasis the difference with binary tarballs
+
+  echo "Writing in" $name".*"
+  git archive ${TCID} --prefix=${name}/ --format=zip -o dist/${name}.zip -9
+  # Creating .xz .gz and .bz2 from tar archive
+  tar_name=${name}.tar
+  git archive ${TCID} --prefix=${name}/ --format=tar \
+    | tee dist/${tar_name} \
+    | gzip -c9 > dist/${tar_name}.gz
+  bzip2 -c9 < dist/${tar_name} >  dist/${tar_name}.bz2
+  xz -c9 < dist/${tar_name} >  dist/${tar_name}.xz
+
+  # Verification
+  gzip -t < dist/${tar_name}.gz
+  bzip2 -t <  dist/${tar_name}.bz2
+  xz -t <  dist/${tar_name}.xz
+}
+
 echo "Start"
 
 # If directory doesn't exist, create it
@@ -9,32 +35,13 @@ if ! [ -e dist ]; then
     mkdir dist
 fi
 
-# Target commit (TC) i.e. commit from which tarball is created.
 if [[ $1 = "" ]]; then
   echo "No argument, using HEAD to create tarball."
-  TC=HEAD
+  create_archive HEAD
 else
-  TC=$1
+  # If several commits are given, create an archive for each
+  for commit in "$@"; do
+    create_archive $commit
+  done
 fi
-TCID=`git rev-parse ${TC}`
-echo "Creating tarball from commit ${TCID} ($TC)."
-
-# If no tag, use commit SHA1
-id=`git describe --abbrev=10 --candidates=50 ${TCID}`
-name=oclaunch_${id}_source # _source emphasis the difference with binary tarballs
-
-echo "Writing in" $name".*"
-git archive ${TCID} --prefix=${name}/ --format=zip -o dist/${name}.zip -9
-# Creating .xz .gz and .bz2 from tar archive
-tar_name=${name}.tar
-git archive ${TCID} --prefix=${name}/ --format=tar \
-  | tee dist/${tar_name} \
-  | gzip -c9 > dist/${tar_name}.gz
-cd dist
-bzip2 -c9 < ${tar_name} >  ${tar_name}.bz2
-xz -c9 < ${tar_name} >  ${tar_name}.xz
-
-# Verification
-gzip -t < ${tar_name}.gz
-bzip2 -t <  ${tar_name}.bz2
-xz -t <  ${tar_name}.xz
+