Browse Source

Add the cloning progress indication

Vadim Markovtsev 7 years ago
parent
commit
840eca3877
1 changed files with 21 additions and 1 deletions
  1. 21 1
      cmd/hercules/main.go

+ 21 - 1
cmd/hercules/main.go

@@ -28,8 +28,10 @@ each identity on separate line, matching names and emails separated with |
 package main
 
 import (
+	"bytes"
 	"flag"
 	"fmt"
+	"io"
 	"net/http"
 	_ "net/http/pprof"
 	"os"
@@ -58,6 +60,23 @@ func sortedKeys(m map[string][][]int64) []string {
 	return keys
 }
 
+type OneLineWriter struct {
+	Writer io.Writer
+}
+
+func (writer OneLineWriter) Write(p []byte) (n int, err error) {
+	if p[len(p) - 1] == '\n' {
+		p = p[:len(p) - 1]
+		if bytes.Compare(p[len(p) - 5:], []byte("done.")) == 0 {
+			p = []byte("cloning...")
+		}
+		p = append(p, '\r')
+		writer.Writer.Write([]byte("\r" + strings.Repeat(" ", 80) + "\r"))
+	}
+	n, err = writer.Writer.Write(p)
+	return
+}
+
 func main() {
 	var protobuf bool
 	var withFiles bool
@@ -119,8 +138,9 @@ func main() {
 		fmt.Fprint(os.Stderr, "cloning...\r")
 		repository, err = git.Clone(backend, nil, &git.CloneOptions{
 			URL: uri,
+			Progress: OneLineWriter{Writer: os.Stderr},
 		})
-		fmt.Fprint(os.Stderr, "          \r")
+		fmt.Fprint(os.Stderr, strings.Repeat(" ", 80) + "\r")
 	} else {
 		if uri[len(uri)-1] == os.PathSeparator {
 			uri = uri[:len(uri)-1]