tools / git-applymboxon commit Teach applymbox to keep the Subject: line. (6bff6a6)
   1#!/bin/sh
   2##
   3## "dotest" is my stupid name for my patch-application script, which
   4## I never got around to renaming after I tested it. We're now on the
   5## second generation of scripts, still called "dotest".
   6##
   7## Update: Ryan Anderson finally shamed me into naming this "applymbox".
   8##
   9## You give it a mbox-format collection of emails, and it will try to
  10## apply them to the kernel using "applypatch"
  11##
  12## applymbox [ -k ] [ -q ] (-c .dotest/msg-number | mail_archive) [Signoff_file]"
  13##
  14## The patch application may fail in the middle.  In which case:
  15## (1) look at .dotest/patch and fix it up to apply
  16## (2) re-run applymbox with -c .dotest/msg-number for the current one.
  17## Pay a special attention to the commit log message if you do this and
  18## use a Signoff_file, because applypatch wants to append the sign-off
  19## message to msg-clean every time it is run.
  20
  21keep_subject= query_apply= continue= resume=t
  22while case "$#" in 0) break ;; esac
  23do
  24        case "$1" in
  25        -k)     keep_subject=-k ;;
  26        -q)     query_apply=t ;;
  27        -c)     continue="$2"; resume=f; shift ;;
  28        -*)     usage ;;
  29        *)      break ;;
  30        esac
  31        shift
  32done
  33
  34case "$continue" in
  35'')
  36        rm -rf .dotest
  37        mkdir .dotest
  38        git-mailsplit "$1" .dotest || exit 1
  39        shift
  40esac
  41
  42case "$query_apply" in
  43t)      touch .dotest/.query_apply
  44esac
  45case "$keep_subject" in
  46-k)     : >.dotest/.keep_subject
  47esac
  48
  49signoff="$1"
  50set x .dotest/0*
  51shift
  52while case "$#" in 0) break;; esac
  53do
  54    i="$1" 
  55    case "$resume,$continue" in
  56    f,$i)       resume=t;;
  57    f,*)        continue;;
  58    *)
  59            git-mailinfo $keep_subject \
  60                .dotest/msg .dotest/patch <$i >.dotest/info || exit 1
  61            git-stripspace < .dotest/msg > .dotest/msg-clean
  62            ;;
  63    esac
  64    while :; # for fixing up and retry
  65    do
  66        git-applypatch .dotest/msg-clean .dotest/patch .dotest/info "$signoff"
  67        case "$?" in
  68        0 | 2 )
  69                # 2 is a special exit code from applypatch to indicate that
  70                # the patch wasn't applied, but continue anyway 
  71                ;;
  72        *)
  73                ret=$?
  74                if test -f .dotest/.query_apply
  75                then
  76                        echo >&2 "* Patch failed."
  77                        echo >&2 "* You could fix it up in your editor and"
  78                        echo >&2 "  retry.  If you want to do so, say yes here"
  79                        echo >&2 "  AFTER fixing .dotest/patch up."
  80                        echo >&2 -n "Retry [y/N]? "
  81                        read yesno
  82                        case "$yesno" in
  83                        [Yy]*)
  84                                continue ;;
  85                        esac
  86                fi
  87                exit $ret
  88        esac
  89        break
  90    done
  91    shift
  92done
  93# return to pristine
  94rm -fr .dotest