git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-web--browser: avoid errors in terminal when running Firefox on Windows

From
Shumkin Alexey <alex.crezoff@gmail.com>
Date
Jan 25, 2013, 22:52 UTC
Message-ID
<CAEFUfsH9Xdd4R-uHZGYH4jXvv_z2SzRmtaZwj0_o0d4A9ynPBg@mail.gmail.com>
In-Reply-To
<20130125220617.GA23626@sigill.intra.peff.net>
2013/1/26 Jeff King <peff@peff.net>:
Show 29 quoted lines
> 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.
Yep, you're right
>
>   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.
Definitely right
Show 28 quoted lines
>
> 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 tes-t_web_browse can just spin waiting for "actual" to appear.
Not exactly, because, as I see, "actual" file is a result of redirection of
> git web--browse --browser="$1" "$2" >actual &&
command
>
> -Peff
Previous: Jeff King
Message 12 of 12 in “[PATCHv3] git-web--browse: avoid the use of eval”
  1. Chris PackhamOct 2, 2011
  2. Jeff KingOct 3, 2011
  3. Jeff KingNov 11, 2011
  4. Alexey ShumkinNov 11, 2011
  5. Jeff KingNov 11, 2011
  6. git-web--browser: avoid errors in terminal when running Firefox on WindowsAlexey Shumkin, Jan 25, 2013
  7. Junio C HamanoJan 25, 2013
  8. 0/2 git-web--browser: avoid errors in terminal when runningAlexey Shumkin, Jan 26, 2013
  9. 1/2 t9901-git-web--browse.sh: Use "write_script" helperAlexey Shumkin, Jan 26, 2013
  10. 2/2 git-web--browser: avoid errors in terminal when running Firefox on WindowsAlexey Shumkin, Jan 26, 2013
  11. Jeff KingJan 25, 2013
  12. Shumkin AlexeyJan 25, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.