{"thread":{"id":"1367","subject":"[PATCH] git-applymbox: allow retrying after fixing up.","startedAt":"2005-07-30T02:11:33Z","lastAt":"2005-07-30T02:11:33Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"6618","messageId":"7vy87p6o16.fsf@assigned-by-dhcp.cox.net","threadId":"1367","inReplyTo":null,"subject":"[PATCH] git-applymbox: allow retrying after fixing up.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-07-30T02:11:33Z","receivedAt":"2005-07-30T02:11:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"After failing to apply a patch, when operating under -q (query)\nflag, give the user an opportunity to fix up the patch in a\nseparate window and retry.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n tools/git-applymbox |   56 +++++++++++++++++++++++++++++++++++++--------------\n 1 files changed, 41 insertions(+), 15 deletions(-)\n\n2b1077125e629c316905ae480ab4f8699332b7f7\ndiff --git a/tools/git-applymbox b/tools/git-applymbox\n--- a/tools/git-applymbox\n+++ b/tools/git-applymbox\n@@ -9,7 +9,7 @@\n ## You give it a mbox-format collection of emails, and it will try to\n ## apply them to the kernel using \"applypatch\"\n ##\n-## applymbox [ -c .dotest/msg-number ] [ -q ] mail_archive [Signoff_file]\"\n+## applymbox [ -q ] (-c .dotest/msg-number | mail_archive) [Signoff_file]\"\n ##\n ## The patch application may fail in the middle.  In which case:\n ## (1) look at .dotest/patch and fix it up to apply\n@@ -35,29 +35,55 @@ case \"$continue\" in\n \trm -rf .dotest\n \tmkdir .dotest\n \tgit-mailsplit \"$1\" .dotest || exit 1\n+\tshift\n esac\n \n case \"$query_apply\" in\n t)\ttouch .dotest/.query_apply\n esac\n \n-for i in .dotest/0*\n+signoff=\"$1\"\n+set x .dotest/0*\n+shift\n+while case \"$#\" in 0) break;; esac\n do\n-\tcase \"$resume,$continue\" in\n-\tf,$i)\tresume=t;;\n-\tf,*)\tcontinue;;\n-\t*)\n-\t\tgit-mailinfo .dotest/msg .dotest/patch <$i >.dotest/info || exit 1\n-\t\tgit-stripspace < .dotest/msg > .dotest/msg-clean\n-\t\t;;\n-\tesac\n-\tgit-applypatch .dotest/msg-clean .dotest/patch .dotest/info \"$2\"\n-\tret=$?\n-\tif [ $ret -ne 0 ]; then\n+    i=\"$1\" \n+    case \"$resume,$continue\" in\n+    f,$i)\tresume=t;;\n+    f,*)\tcontinue;;\n+    *)\n+\t    git-mailinfo .dotest/msg .dotest/patch <$i >.dotest/info || exit 1\n+\t    git-stripspace < .dotest/msg > .dotest/msg-clean\n+\t    ;;\n+    esac\n+    while :; # for fixing up and retry\n+    do\n+\tgit-applypatch .dotest/msg-clean .dotest/patch .dotest/info \"$signoff\"\n+\tcase \"$?\" in\n+\t0 | 2 )\n \t\t# 2 is a special exit code from applypatch to indicate that\n \t    \t# the patch wasn't applied, but continue anyway \n-\t\t[ $ret -ne 2 ] && exit $ret\n-\tfi\n+\t\t;;\n+\t*)\n+\t\tret=$?\n+\t\tif test -f .dotest/.query_apply\n+\t\tthen\n+\t\t\techo >&2 \"* Patch failed.\"\n+\t\t\techo >&2 \"* You could fix it up in your editor and\"\n+\t\t\techo >&2 \"  retry.  If you want to do so, say yes here\"\n+\t\t\techo >&2 \"  AFTER fixing .dotest/patch up.\"\n+\t\t\techo >&2 -n \"Retry [y/N]? \"\n+\t\t\tread yesno\n+\t\t\tcase \"$yesno\" in\n+\t\t\t[Yy]*)\n+\t\t\t\tcontinue ;;\n+\t\t        esac\n+\t\tfi\n+\t\texit $ret\n+\tesac\n+\tbreak\n+    done\n+    shift\n done\n # return to pristine\n rm -fr .dotest\n"}]}