{"thread":{"id":"29736","subject":"[PATCH] am: don't infloop for an empty input file","startedAt":"2012-02-25T17:34:26Z","lastAt":"2012-02-26T23:58:08Z","messageCount":2,"participants":["Jim Meyering","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"185433","messageId":"87399y24wt.fsf@rho.meyering.net","threadId":"29736","inReplyTo":null,"subject":"[PATCH] am: don't infloop for an empty input file","fromName":"Jim Meyering","fromEmail":"jim@meyering.net","sentAt":"2012-02-25T17:34:26Z","receivedAt":"2012-02-25T17:34:26Z","isPatch":true,"sender":{"key":"jim@meyering.net","avatar":"https://avatars.githubusercontent.com/u/710630?v=4"},"body":"Today, \"git am\" surprised me.\nI mistakenly ran it on an empty file and it went into an infinite loop.\n\n  : > e && git am e\n\nTo fix it, I made a failing bourne shell \"read\" break out\nof the offending loop.  Looking through git-am.sh for other\ninstances, I did find one, but didn't try to address it here.\n\n\n\t    action=again\n\t    while test \"$action\" = again\n\t    do\n\t\tgettextln \"Commit Body is:\"\n\t\techo \"--------------------------\"\n\t\tcat \"$dotest/final-commit\"\n\t\techo \"--------------------------\"\n\t\t# TRANSLATORS: Make sure to include [y], [n], [e], [v] and [a]\n\t\t# in your translation. The program will only accept English\n\t\t# input at this point.\n\t\tgettext \"Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all \"\nmay infloop->\tread reply\n\t\tcase \"$reply\" in\n\nIn that case (when someone hits ^D in response to that prompt?),\nyou may want to exit altogether.\n\nIn the test addition, I didn't try to handle potentially-inflooping code.\nIn coreutils tests, it's easy (since it includes the timeout program):\nI would just prefix the command with something like \"timeout 10\", but\nthe timeout command is not universally available.  And besides, the\ninfloop is supposed to be fixed, now.\n\nHere's a patch for the infloop I triggered:\n[Noticed with and tested against master v1.7.9.2-262-gba998d3,\n but seems to apply also to maint. ]\n\n-- >8 --\n\ngit-am.sh's check_patch_format function would attempt to preview\nthe patch to guess its format, but would go into an infinite loop\nwhen the patch file happened to be empty.  The solution: exit the\nloop when \"read\" fails, not when the line var, \"$l1\" becomes empty.\n\nSigned-off-by: Jim Meyering <meyering@redhat.com>\n---\n git-am.sh     |    2 +-\n t/t4150-am.sh |   10 ++++++++++\n 2 files changed, 11 insertions(+), 1 deletion(-)\n\ndiff --git a/git-am.sh b/git-am.sh\nindex 64d8e2a..906f91f 100755\n--- a/git-am.sh\n+++ b/git-am.sh\n@@ -202,7 +202,7 @@ check_patch_format () {\n \t\tl1=\n \t\twhile test -z \"$l1\"\n \t\tdo\n-\t\t\tread l1\n+\t\t\tread l1 || break\n \t\tdone\n \t\tread l2\n \t\tread l3\ndiff --git a/t/t4150-am.sh b/t/t4150-am.sh\nindex f1b60b8..6f77fff 100755\n--- a/t/t4150-am.sh\n+++ b/t/t4150-am.sh\n@@ -505,4 +505,14 @@ test_expect_success 'am -q is quiet' '\n \t! test -s output.out\n '\n\n+test_expect_success 'am empty-file does not infloop' '\n+\trm -fr .git/rebase-apply &&\n+\tgit reset --hard &&\n+\ttouch empty-file &&\n+\ttest_tick &&\n+\t{ git am empty-file > actual 2>&1 && false || :; } &&\n+\techo Patch format detection failed. >expected &&\n+\ttest_cmp expected actual\n+'\n+\n test_done\n--\n1.7.9.2.263.g9be8b7\n"},{"id":"185477","messageId":"7vty2dcflb.fsf@alter.siamese.dyndns.org","threadId":"29736","inReplyTo":"87399y24wt.fsf@rho.meyering.net","subject":"Re: [PATCH] am: don't infloop for an empty input file","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-02-26T23:58:08Z","receivedAt":"2012-02-26T23:58:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jim Meyering <jim@meyering.net> writes:\n\n> Today, \"git am\" surprised me.\n> I mistakenly ran it on an empty file and it went into an infinite loop.\n\nYeah, that is an embarrassing regression in 1.7.7.\n\nThanks for noticing.\n"}]}