s3:tests: Reformat test_dfree_command.sh
[Samba.git] / third_party / heimdal / apply_heimdal.sh
blobfc9aa292e5a0d8473f5cd239d642a3b869d2127c
1 #!/bin/bash
3 [ $# == 2 ] || {
4 echo "Usage: apply_heimdal.sh <lorikeet_path>"
5 exit 1
8 LORIKEET_PATH="$1"
9 IMPORT_HASH="$2"
10 S4PATH="$PWD"
12 pushd $LORIKEET_PATH || exit 1
13 git reset --hard
14 git am --abort
15 popd
17 # From https://gist.github.com/kfish/7425248
19 apply () {
20 filename=$1
21 shift
22 patch_args=$*
24 gotSubject=no
25 msg=""
27 cat $filename | while read line; do
28 if [ "$line" == "---" ]; then
30 patch $patch_args -p1 < $filename
31 git commit -a -m 'CHECK AUTHOR' -m "$msg"
33 break
35 if [ "$gotSubject" == "no" ]; then
36 hdr=(${line//:/ })
37 if [ "${hdr[0]}" == "Subject" ]; then
38 gotSubject=yes
39 msg="${hdr[@]:3}"
41 else
42 msg="$msg $line"
44 msg="$msg
46 done
49 try_patch() {
50 commit="$1"
51 git format-patch --stdout $commit -1 source4/heimdal > "$commit".patch
52 sed -i 's|/source4/heimdal/|/|g' "$commit".patch
53 sed -i "s|^---$|(cherry picked from Samba commit $commit)\n---|g" "$commit".patch
54 pushd $LORIKEET_PATH || exit 1
55 git reset --hard
56 echo
57 if patch -p1 --forward < "$S4PATH/$commit.patch"; then
58 echo
59 echo "Commit $commit can apply - applying"
60 git reset --hard
61 git am "$S4PATH/$commit.patch" || apply "$S4PATH/$commit.patch"
62 else
63 echo
64 echo "Commit $commit does not apply cleanly"
65 echo
67 git am --abort
68 popd || exit 1
71 commits="$(git log --pretty=oneline --reverse $IMPORT_HASH..HEAD -- source4/heimdal | cut -d' ' -f1)"
72 for c in $commits; do
73 git log $c -1
74 echo -n "Try apply? [Y/n] "
75 read answer
76 case $answer in
77 n*)
78 continue
81 try_patch $c
83 esac
84 done