Browse Source

Improve progress reporting

Vadim Markovtsev 8 years ago
parent
commit
186ff0d7e4
3 changed files with 8 additions and 8 deletions
  1. 4 4
      analyser.go
  2. 3 3
      cmd/hercules/main.go
  3. 1 1
      file.go

+ 4 - 4
analyser.go

@@ -17,7 +17,7 @@ import (
 type Analyser struct {
 	Repository  *git.Repository
 	Granularity int
-	OnProgress  func(int)
+	OnProgress  func(int, int)
 }
 
 func checkClose(c io.Closer) {
@@ -105,7 +105,7 @@ func (analyser *Analyser) handleModification(
 	str_to := str(blob_to)
 	file, exists := files[change.From.Name]
 	if !exists {
-		fmt.Fprintf(os.Stderr, "warning: file %s does not exist\n", change.From.Name)
+		// fmt.Fprintf(os.Stderr, "warning: file %s does not exist\n", change.From.Name)
 		analyser.handleInsertion(change, day, status, files)
 		return
 	}
@@ -212,7 +212,7 @@ func (analyser *Analyser) Analyse() [][]int64 {
 	}
 	onProgress := analyser.OnProgress
 	if onProgress == nil {
-		onProgress = func(int) {}
+		onProgress = func(int, int) {}
 	}
 
 	// current daily alive number of lines; key is the number of days from the
@@ -230,7 +230,7 @@ func (analyser *Analyser) Analyse() [][]int64 {
 	prev_day := 0
 
 	for index, commit := range commits {
-		onProgress(index)
+		onProgress(index, len(commits))
 		tree, err := commit.Tree()
 		if err != nil {
 			panic(err)

+ 3 - 3
cmd/hercules/main.go

@@ -44,7 +44,7 @@ func main() {
 		} else {
 			repository = git.NewMemoryRepository()
 		}
-		fmt.Fprint(os.Stderr, "Cloning...\r")
+		fmt.Fprint(os.Stderr, "cloning...\r")
 		err = repository.Clone(&git.CloneOptions{
 		  URL: uri,
 	  })
@@ -64,8 +64,8 @@ func main() {
 	// core logic
 	analyser := hercules.Analyser{
 		Repository: repository,
-		OnProgress: func(commit int) {
-		  fmt.Fprintf(os.Stderr, "%d\r", commit)
+		OnProgress: func(commit, length int) {
+		  fmt.Fprintf(os.Stderr, "%d / %d\r", commit, length)
 	  },
 		Granularity: granularity,
 	}

+ 1 - 1
file.go

@@ -55,7 +55,7 @@ func (file *File) Update(time int, pos int, ins_length int, del_length int) {
 	tree := file.tree
 	if pos > tree.Max().Item().key {
 		panic(fmt.Sprintf("attempt to insert after the end of the file: %d < %d",
-		                  tree.Max().Item().key, pos))
+			tree.Max().Item().key, pos))
 	}
 	status := file.status
 	iter := tree.FindLE(pos)