#!/bin/bash
set -x
set -e
set -o pipefail
while read -r file
do tar xf /hdd-scratch/kenta/ghc/packages/hackage.haskell.org/$(perl /mit/ghc/src/random/packages-path.pl $file).tar.gz
pushd $file
if ! [ -e .git ]
then git init
git add .
git commit -m init
else git status
fi
if [ -e /mit/ghc/src/package-patches/packages/$file ]
then for mypatch in /mit/ghc/src/package-patches/packages/$file/*.patch
     do cat $mypatch
        patch -p1 < $mypatch || true
        # patches to cabal files can fail
        git add .
        git commit -m "old patch $(basename $mypatch)"
     done
     true =========================================== $file
     #sleep 15
fi
popd
done
find . -name '*.rej'
