f637971
#!/bin/sh
f637971
f637971
# Generic function to print an error message and bail out.
f637971
die ()
f637971
{
f637971
    echo $1 > /dev/stderr
f637971
    exit 1
f637971
}
f637971
f637971
# Print usage
f637971
usage ()
f637971
{
f637971
    cat <
f637971
$0 -- Generate a git repository from .patch files
f637971
f637971
Usage:
f637971
  $0 <REPOSITORY>
f637971
f637971
<REPOSITORY> is the directory where the rebase was performed.  You
f637971
need to clone the repository first.
f637971
f637971
Options are:
f637971
f637971
  -h: Print this message
f637971
EOF
f637971
    exit 0
f637971
}
f637971
f637971
test -f gdb.spec || die "This script needs to run from the same directory as gdb.spec."
f637971
f637971
test -z $1 && die "You need to specify the repository."
f637971
test "$1" = "-h" && usage
f637971
f637971
test -f _git_upstream_commit || die "Cannot find _git_upstream_commit file."
f637971
test -f _patch_order || die "Cannot find _patch_order file."
f637971
f637971
last_ancestor_commit=`cat _git_upstream_commit`
2e649f7
f637971
cd $1
2e649f7
2e649f7
git name-rev $last_ancestor_commit
2e649f7
test $? -eq 0 || die "Could not find $last_ancestor_commit in the repository $1.  Did you run 'git fetch'?"
2e649f7
f637971
git checkout $last_ancestor_commit
f637971
for p in `cat ../_patch_order` ; do
f637971
    git am ../$p
2e649f7
    test $? -eq 0 || die "Could not apply patch '$p'."
f637971
done