diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-11-25 00:00:03 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-11-25 00:00:03 -0500 |
commit | 070eb5742be798ce0df1e5a4f55c62aa67326b5f (patch) | |
tree | eb490e29a770618ed632251c4eb5d5db6882ae60 | |
parent | 9d38dfb06fe49531a22114ce90a1a342fbdbe319 (diff) |
add current progress output
-rw-r--r-- | filter.go | 6 | ||||
-rw-r--r-- | main.go | 34 |
2 files changed, 40 insertions, 0 deletions
@@ -30,6 +30,8 @@ type Filter struct { curCommitIn libfastimport.CmdCommit curCommitOut map[string]fullcommit + + OnCommit func() } func NewFilter(fromRef string, toPfx string) (*Filter, error) { @@ -191,6 +193,10 @@ func (f *Filter) Run() error { // TODO: synthesize ABS-tree submodule commits f.curCommitIn = libfastimport.CmdCommit{} f.curCommitOut = nil + + if f.OnCommit != nil { + f.OnCommit() + } case libfastimport.FileModify: branchname := filename2branchname(string(cmdt.Path)) if branchname == "" { @@ -5,8 +5,19 @@ import ( "io" "os" "strings" + "time" ) +func fmtDuration(d time.Duration) string { + h := d / time.Hour + d -= h * time.Hour + m := d / time.Minute + d -= m * time.Minute + s := d / time.Second + + return fmt.Sprintf("%02d:%02d:%02", h, m, s) +} + func usage(w io.Writer) { fmt.Fprintf(w, "Usage: %s refs/FROM_REFNAME refs/TO_PREFIX\n", os.Args[0]) fmt.Fprintf(w, " or: %s -h|--help\n", os.Args[0]) @@ -33,12 +44,35 @@ func main() { os.Exit(2) } + commits := 0 + beg := time.Now() + maxline := 0 + status := func() { + duration := time.Since(beg) + line := fmt.Sprintf("[%s] commits (%.2f commit/s)", + fmtDuration(duration), + commits, + float64(commits)/duration.Seconds()) + if len(line) > maxline { + maxline = len(line) + } + fmt.Fprintf(os.Stderr, "\r%-[1]*[2]s", maxline, line) + } + filter, err := NewFilter(fromRef, toPfx) if err != nil { fmt.Fprintln(os.Stderr, "Could not initialize filter:", err) os.Exit(1) } + + filter.OnCommit = func() { + commits++ + status() + } + err = filter.Run() + status() + fmt.Fprintln(os.Stderr) if err != nil { fmt.Fprintln(os.Stderr, "Error:", err) os.Exit(1) |