* [PATCH] am: don't infloop for an empty input file
@ 2012-02-25 17:34 Jim Meyering
2012-02-26 23:58 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Jim Meyering @ 2012-02-25 17:34 UTC (permalink / raw)
To: git list
Today, "git am" surprised me.
I mistakenly ran it on an empty file and it went into an infinite loop.
: > e && git am e
To fix it, I made a failing bourne shell "read" break out
of the offending loop. Looking through git-am.sh for other
instances, I did find one, but didn't try to address it here.
action=again
while test "$action" = again
do
gettextln "Commit Body is:"
echo "--------------------------"
cat "$dotest/final-commit"
echo "--------------------------"
# TRANSLATORS: Make sure to include [y], [n], [e], [v] and [a]
# in your translation. The program will only accept English
# input at this point.
gettext "Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all "
may infloop-> read reply
case "$reply" in
In that case (when someone hits ^D in response to that prompt?),
you may want to exit altogether.
In the test addition, I didn't try to handle potentially-inflooping code.
In coreutils tests, it's easy (since it includes the timeout program):
I would just prefix the command with something like "timeout 10", but
the timeout command is not universally available. And besides, the
infloop is supposed to be fixed, now.
Here's a patch for the infloop I triggered:
[Noticed with and tested against master v1.7.9.2-262-gba998d3,
but seems to apply also to maint. ]
-- >8 --
git-am.sh's check_patch_format function would attempt to preview
the patch to guess its format, but would go into an infinite loop
when the patch file happened to be empty. The solution: exit the
loop when "read" fails, not when the line var, "$l1" becomes empty.
Signed-off-by: Jim Meyering <meyering@redhat.com>
---
git-am.sh | 2 +-
t/t4150-am.sh | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/git-am.sh b/git-am.sh
index 64d8e2a..906f91f 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -202,7 +202,7 @@ check_patch_format () {
l1=
while test -z "$l1"
do
- read l1
+ read l1 || break
done
read l2
read l3
diff --git a/t/t4150-am.sh b/t/t4150-am.sh
index f1b60b8..6f77fff 100755
--- a/t/t4150-am.sh
+++ b/t/t4150-am.sh
@@ -505,4 +505,14 @@ test_expect_success 'am -q is quiet' '
! test -s output.out
'
+test_expect_success 'am empty-file does not infloop' '
+ rm -fr .git/rebase-apply &&
+ git reset --hard &&
+ touch empty-file &&
+ test_tick &&
+ { git am empty-file > actual 2>&1 && false || :; } &&
+ echo Patch format detection failed. >expected &&
+ test_cmp expected actual
+'
+
test_done
--
1.7.9.2.263.g9be8b7
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] am: don't infloop for an empty input file
2012-02-25 17:34 [PATCH] am: don't infloop for an empty input file Jim Meyering
@ 2012-02-26 23:58 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2012-02-26 23:58 UTC (permalink / raw)
To: Jim Meyering; +Cc: git list
Jim Meyering <jim@meyering.net> writes:
> Today, "git am" surprised me.
> I mistakenly ran it on an empty file and it went into an infinite loop.
Yeah, that is an embarrassing regression in 1.7.7.
Thanks for noticing.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-02-26 23:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-25 17:34 [PATCH] am: don't infloop for an empty input file Jim Meyering
2012-02-26 23:58 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).