filter-branch: add passed/remaining seconds on progress

adds seconds progress and estimated seconds time if getting the current timestamp is supported by the date +%s command Signed-off-by: Gabor Bernat <gabor.bernat@gravityrd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Gabor Bernat committed Sep 7, 2015 at 15:52 UTC 6a9d16a0a80ef53c1fcc0f6bc3d1d24d21961272
1 file changed +29 -1
git-filter-branch.sh
+29 -1
@@ -275,11 +275,39 @@ commits=$(wc -l <../revs | tr -d " ")
275 test $commits -eq 0 && die "Found nothing to rewrite"
276
277 # Rewrite the commits
278 +report_progress ()
279 +{
280 + if test -n "$progress" &&
281 + test $git_filter_branch__commit_count -gt $next_sample_at
282 + then
283 + now_timestamp=$(date +%s)
284 + elapsed_seconds=$(($now_timestamp - $start_timestamp))
285 + remaining_second=$(( ($commits - $git_filter_branch__commit_count) * $elapsed_seconds / $git_filter_branch__commit_count ))
286 + if test $elapsed_seconds -gt 0
287 + then
288 + next_sample_at=$(( ($elapsed_seconds + 1) * $git_filter_branch__commit_count / $elapsed_seconds ))
289 + else
290 + next_sample_at=$(($next_sample_at + 1))
291 + fi
292 + progress=" ($elapsed_seconds seconds passed, remaining $remaining_second predicted)"
293 + fi
294 + printf "\rRewrite $commit ($git_filter_branch__commit_count/$commits)$progress "
295 +}
296
297 git_filter_branch__commit_count=0
298 +
299 +progress= start_timestamp=
300 +if date '+%s' 2>/dev/null | grep -q '^[0-9][0-9]*$'
301 +then
302 + next_sample_at=0
303 + progress="dummy to ensure this is not empty"
304 + start_timestamp=$(date '+%s')
305 +fi
306 +
307 while read commit parents; do
308 git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1))
282 - printf "\rRewrite $commit ($git_filter_branch__commit_count/$commits)"
309 +
310 + report_progress
311
312 case "$filter_subdir" in
313 "")