Add passed and estimated seconds to the filter-branch on demand via --progress-eta flag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I've submitted this first to this list as a feature request, however
in the meantime with the help of Jeff King <peff@xxxxxxxx>, Junio C
Hamano <gitster@xxxxxxxxx>, Eric Sunshine <sunshine@xxxxxxxxxxxxxx>
and Mikael Magnusson <mikachu@xxxxxxxxx> came up with solution, so now
I submit it as a patch. Here follows a patch, I really hope I got
right the format:

>From 620e69d10a1bfcfcace347cbb95991d75fd23a1d Mon Sep 17 00:00:00 2001
From: Gabor Bernat <gabor.bernat@xxxxxxxxxxxxx>
Date: Thu, 27 Aug 2015 00:46:52 +0200
Subject: [PATCH] Add to the git filter-branch a --progress-eta flag which when
 enabled will print with the progress also the number of seconds passed since
 started plus the number of seconds predicted until the operation finishes.

Signed-off-by: Gabor Bernat <gabor.bernat@xxxxxxxxxxxxx>
---
 Documentation/git-filter-branch.txt |  6 ++++++
 git-filter-branch.sh                | 29 ++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/Documentation/git-filter-branch.txt
b/Documentation/git-filter-branch.txt
index 73fd9e8..6ca9d6e 100644
--- a/Documentation/git-filter-branch.txt
+++ b/Documentation/git-filter-branch.txt
@@ -194,6 +194,12 @@ to other tags will be rewritten to point to the
underlying commit.
  directory or when there are already refs starting with
  'refs/original/', unless forced.

+--progress-eta::
+ If specified will print the number of seconds elapsed and the predicted
+ count of seconds remaining until the operation is expected to finish. Note
+ that for calculating the eta the global speed up to the current point is
+ used.
+
 <rev-list options>...::
  Arguments for 'git rev-list'.  All positive refs included by
  these options are rewritten.  You may also specify options
diff --git a/git-filter-branch.sh b/git-filter-branch.sh
index 5b3f63d..7b565fb 100755
--- a/git-filter-branch.sh
+++ b/git-filter-branch.sh
@@ -105,6 +105,7 @@ filter_subdir=
 orig_namespace=refs/original/
 force=
 prune_empty=
+progress_eta=
 remap_to_ancestor=
 while :
 do
@@ -129,6 +130,11 @@ do
  prune_empty=t
  continue
  ;;
+ --progress-eta)
+ shift
+ progress_eta=t
+ continue
+ ;;
  -*)
  ;;
  *)
@@ -277,9 +283,30 @@ test $commits -eq 0 && die "Found nothing to rewrite"
 # Rewrite the commits

 git_filter_branch__commit_count=0
+
+case "$progress_eta" in
+ t)
+ start=$(PATH=`getconf PATH` awk 'BEGIN{srand();print srand()}')
+ ;;
+ '')
+ ;;
+esac
+
 while read commit parents; do
  git_filter_branch__commit_count=$(($git_filter_branch__commit_count+1))
- printf "\rRewrite $commit ($git_filter_branch__commit_count/$commits)"
+
+ case "$progress_eta" in
+ t)
+ now=$(PATH=`getconf PATH` awk 'BEGIN{srand();print srand()}')
+ elapsed=$(($now - $start))
+ remaining_second=$(( ($commits - $git_filter_branch__commit_count) *
$elapsed / $git_filter_branch__commit_count ))
+ progress=" ($elapsed seconds passed, remaining $remaining_second predicted)"
+ ;;
+ '')
+ progress=""
+ esac
+
+ printf "\rRewrite $commit
($git_filter_branch__commit_count/$commits)$progress"

  case "$filter_subdir" in
  "")
-- 
2.5.1.408.g14905ed.dirty

Let me know if this works for adding it to the main repository,

Thanks a lot,


Bernát GÁBOR
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]