summaryrefslogtreecommitdiff
path: root/fi-filefilter/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'fi-filefilter/main.go')
-rw-r--r--fi-filefilter/main.go29
1 files changed, 16 insertions, 13 deletions
diff --git a/fi-filefilter/main.go b/fi-filefilter/main.go
index 6731c1e..12c291d 100644
--- a/fi-filefilter/main.go
+++ b/fi-filefilter/main.go
@@ -19,7 +19,6 @@ package main
import (
"fmt"
- "io"
"os"
"regexp"
"time"
@@ -30,21 +29,24 @@ import (
"git.parabola.nu/~lukeshu/fastimport-go-utils/fiutil"
)
-func usage(w io.Writer) {
- fmt.Fprintf(w, "Usage: git fast-export --full-tree | %s REGEXP | git fast-import\n", os.Args[0])
- fmt.Fprintf(w, "Prunes a fast-import stream, removing filenames that do not match a regexp\n")
+func usage() {
+ fmt.Printf("Usage: git fast-export --full-tree | %s REGEXP | git fast-import\n", os.Args[0])
+ fmt.Printf(" or: %s --help\n", os.Args[0])
+ fmt.Printf("Prunes a fast-import stream, removing filenames that do not match a regexp\n")
+ os.Exit(0)
}
func main() {
if len(os.Args) != 2 {
- usage(os.Stderr)
- os.Exit(2)
+ fiutil.ErrUsage(fmt.Sprintf("expected exactly 1 argument, got %d", len(os.Args)-1))
+ }
+ if os.Args[1] == "--help" {
+ usage()
}
re, err := regexp.Compile(os.Args[1])
if err != nil {
- fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
- os.Exit(2)
+ fiutil.ErrUsage(fmt.Sprintf("bad regexp: %q: %v", os.Args[1], err))
}
frontend := libfastimport.NewFrontend(os.Stdin, os.Stdin, nil)
@@ -111,11 +113,12 @@ func (h *FileFilter) FileRename(cmd libfastimport.FileRename) error {
// statistics //////////////////////////////////////////////////////////////////
func (h *FileFilter) CmdCommitEnd(cmd libfastimport.CmdCommitEnd) error {
h.commits++
- fmt.Fprintf(os.Stderr,
- "%d commits (%d => %d files) (%.2f commit/s)\r",
- h.commits, h.filesIn, h.filesOut,
- float64(h.commits)/time.Since(h.beg).Seconds())
- return nil
+ return h.backend.Do(libfastimport.CmdProgress{
+ Str: fmt.Sprintf("[%s] %d commits (%d => %d files) (%.2f commit/s)",
+ os.Args[0],
+ h.commits, h.filesIn, h.filesOut,
+ float64(h.commits)/time.Since(h.beg).Seconds()),
+ })
}
// note commands ///////////////////////////////////////////////////////////////