From: Jeff King <peff@peff.net>
To: Alexey Shumkin <alex.crezoff@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] git-web--browser: avoid errors in terminal when running Firefox on Windows
Date: Fri, 25 Jan 2013 17:06:17 -0500 [thread overview]
Message-ID: <20130125220617.GA23626@sigill.intra.peff.net> (raw)
In-Reply-To: <3eeabf4989f7f1b4593e89e4c6bcfa8710a7b793.1359125053.git.Alex.Crezoff@gmail.com>
On Fri, Jan 25, 2013 at 06:44:13PM +0400, Alexey Shumkin wrote:
> test_web_browse () {
> - # browser=$1 url=$2
> + # browser=$1 url=$2 sleep_timeout=$3
> + sleep_timeout="$3"
> git web--browse --browser="$1" "$2" >actual &&
> + # if $3 is set
> + # as far as Firefox is run in background (it is run with &)
> + # we trying to avoid race condition
> + # by waiting for "$sleep_timeout" seconds of timeout for 'fake_browser_ran' file appearance
> + (test -z "$sleep_timeout" || (
> + for timeout in $(seq 1 $sleep_timeout); do
> + test -f fake_browser_ran && break
> + sleep 1
> + done
> + test $timeout -ne $sleep_timeout
> + )
> + ) &&
> tr -d '\015' <actual >text &&
Gross, but I don't really see another way to handle the asynchronous
nature of spawning background browsers.
Two things, though:
1. Should test_web_browse just delete fake_browser_ran for us? Then
later tests do not have to remember to do so.
2. Seeing fake_browser_ran appeared, we know that the script has
started. But there is still a race condition in which it may not
have written anything to "actual" yet.
In this implementation:
> + cat >"fake browser" <<-\EOF &&
> + #!/bin/sh
> +
> + : > fake_browser_ran
> + if test "$1" = "-version"; then
> + echo Fake Firefox browser version 1.2.3
> + else
> + # Firefox (in contrast to w3m) is run in background (with &)
> + # so redirect output to "actual"
> + echo fake: "$@" > actual
> + fi
> + EOF
There is a period where fake_browser_ran exists, but nothing is in
actual. You can solve it by setting fake_browser_ran at the end rather
than the beginning.
Or you can drop fake_browser_ran entirely, and just atomically move
actual into place, like:
echo "fake: $*" >actual.tmp
mv actual.tmp actual
and then test_web_browse can just spin waiting for "actual" to appear.
-Peff
next prev parent reply other threads:[~2013-01-25 22:06 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-02 0:44 [PATCHv3] git-web--browse: avoid the use of eval Chris Packham
2011-10-03 9:57 ` Jeff King
[not found] ` <1321028283-17307-1-git-send-email-Alex.Crezoff@gmail.com>
2011-11-11 18:35 ` [PATCH] git-web--browser: avoid errors in terminal when running Firefox on Windows Jeff King
2011-11-11 19:48 ` Alexey Shumkin
2011-11-11 20:26 ` Jeff King
2013-01-25 14:44 ` Alexey Shumkin
2013-01-25 19:49 ` Junio C Hamano
2013-01-26 0:40 ` [PATCH v2 0/2] git-web--browser: avoid errors in terminal when running Alexey Shumkin
2013-01-26 0:40 ` [PATCH v2 1/2] t9901-git-web--browse.sh: Use "write_script" helper Alexey Shumkin
2013-01-26 0:40 ` [PATCH v2 2/2] git-web--browser: avoid errors in terminal when running Firefox on Windows Alexey Shumkin
2013-01-25 22:06 ` Jeff King [this message]
2013-01-25 22:52 ` [PATCH] " Shumkin Alexey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130125220617.GA23626@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=alex.crezoff@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).