Re: [FEATURE REQUEST] Filter-branch extend progress with a simple estimated time remaning
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Aug 30, 2015, 19:40 UTC
- Message-ID
- <CAPig+cTf2YLWGi2swmMxdx_XpEU=GkAx11ng6VVACMX9NpA_SQ@mail.gmail.com>
- In-Reply-To
- <xmqqd1y4zpjx.fsf@gitster.mtv.corp.google.com>
On Sun, Aug 30, 2015 at 12:52 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 23 quoted lines
>>> http://stackoverflow.com/questions/2445198/get-seconds-since-epoch-in-any-posix-compliant-shell
>>> Found this,
>>>
>>> awk 'BEGIN{srand();print srand()}'
>>>
>>> srand() in awk returns the previous seed value, and calling it without
>>> an argument sets it to time of day, so the above sequence should
>>> return seconds since the epoch, or at least something in seconds that
>>> is relative to a fixed point which is all that's needed in this
>>> thread.
>
> In practice this should work, but it makes me feel somewhat uneasy.
>
> POSIX says "Set the seed value for rand to expr or use the time of
> day if expr is omitted. The previous seed value shall be returned."
> but I do not see anything that says that "the time of day" is
> counted in seconds around there (which is the crucial bit for this
> application).
>
> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html
> (4.15 Seconds since the Epoch) says "The relationship between the
> actual time of day and the current value for seconds since the Epoch
> is unspecified."I suppose a viable approach might be to test once outside the loop if "date +%s" is supported and print the "(%d elapsed / %d estimated remaining)" annotation within the loop if it is, else not. The test might look something like this:
echo $(date +%s) | grep -q '^[0-9][0-9]*$' 2>/dev/null && show_eta=t
Platforms, such as Linux, Mac OS X, and FreeBSD, which support "date +%s" would get the annotated output, whereas it would fall back gracefully to the non-annotated output on platforms such as Solaris (and perhaps AIX) which lack it.