kdc: support pkinit_kdc_revoke for pkinit anchors
[lorikeet-heimdal.git] / apply_heimdal.sh
index 47cbf141bace711acc9d94c0cee6a26ef2c65dfc..a720766d3c8624d3a7d429d8809f67f9676ab2e0 100755 (executable)
@@ -14,10 +14,42 @@ git reset --hard
 git am --abort
 popd
 
+# From https://gist.github.com/kfish/7425248
+
+apply () {
+  filename=$1
+  shift
+  patch_args=$*
+
+  gotSubject=no
+  msg=""
+
+  cat $filename | while read line; do
+    if [ "$line" == "---" ]; then
+
+      patch $patch_args -p1 < $filename
+      git commit -a -m 'CHECK AUTHOR' -m "$msg"
+
+      break
+    fi
+    if [ "$gotSubject" == "no" ]; then
+      hdr=(${line//:/ })
+      if [ "${hdr[0]}" == "Subject" ]; then
+        gotSubject=yes
+        msg="${hdr[@]:3}"
+      fi
+    else
+      msg="$msg $line"
+    fi
+    msg="$msg
+"
+  done
+}
+
 try_patch() {
     commit="$1"
-    git format-patch --stdout $commit -1 > "$commit".patch
-    sed -i 's|/source4/heimdal/|/|g' "$commit".patch
+    git format-patch --stdout $commit -1 third_party/heimdal > "$commit".patch
+    sed -i 's|/third_party/heimdal/|/|g' "$commit".patch
     sed -i "s|^---$|(cherry picked from Samba commit $commit)\n---|g" "$commit".patch
     pushd $LORIKEET_PATH || exit 1
     git reset --hard
@@ -26,16 +58,17 @@ try_patch() {
        echo
        echo "Commit $commit can apply - applying"
        git reset --hard
-       git am "$S4PATH/$commit.patch"
+       git am "$S4PATH/$commit.patch" || apply "$S4PATH/$commit.patch"
     else
        echo
        echo "Commit $commit does not apply cleanly"
        echo
     fi
+    git am --abort
     popd || exit 1
 }
 
-commits="$(git log --pretty=oneline --reverse $IMPORT_HASH..HEAD -- source4/heimdal | cut -d' ' -f1)"
+commits="$(git log --pretty=oneline --reverse $IMPORT_HASH..HEAD -- third_party/heimdal | cut -d' ' -f1)"
 for c in $commits; do
     git log $c -1
     echo -n "Try apply? [Y/n] "