summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-12-01 01:01:42 -0500
committerLuke Shumaker <lukeshu@lukeshu.com>2017-12-01 01:01:42 -0500
commit97fb1c1311850908b2e625cf18ee584dc755a089 (patch)
tree0a15f8b50c406ee98315bc07d013b57175c3161e
parentb9bfdd202e43ad74fe7d0d78c61797d80550788d (diff)
add other commands
-rw-r--r--fi-filelist/main.go91
-rw-r--r--fi-pacmanlog/main.go88
2 files changed, 179 insertions, 0 deletions
diff --git a/fi-filelist/main.go b/fi-filelist/main.go
new file mode 100644
index 0000000..7fbb820
--- /dev/null
+++ b/fi-filelist/main.go
@@ -0,0 +1,91 @@
+package main
+
+import (
+ "fmt"
+ "io"
+ "os"
+ "sort"
+ "time"
+
+ "git.lukeshu.com/go/libfastimport"
+ "github.com/pkg/errors"
+)
+
+func abort(err error) {
+ fmt.Fprintln(os.Stderr, "Error:", err)
+ os.Exit(1)
+}
+
+func main() {
+ frontend := libfastimport.NewFrontend(os.Stdin, nil, nil)
+ fileset := make(map[string]bool)
+
+ commits := 0
+ beg := time.Now()
+ status := func() {
+ fmt.Fprintf(os.Stderr,
+ "%d commits => %d files (%.2f commit/s)\r",
+ commits, len(fileset),
+ float64(commits)/time.Since(beg).Seconds())
+ }
+ for {
+ cmd, err := frontend.ReadCmd()
+ if err != nil {
+ if err == io.EOF {
+ break
+ }
+ abort(err)
+ }
+ switch cmdt := cmd.(type) {
+
+ case libfastimport.CmdCommit:
+ case libfastimport.CmdCommitEnd:
+ commits++
+ status()
+
+ case libfastimport.FileModify:
+ fileset[string(cmdt.Path)] = true
+ case libfastimport.FileModifyInline:
+ fileset[string(cmdt.Path)] = true
+ case libfastimport.FileDelete:
+ fileset[string(cmdt.Path)] = true
+ case libfastimport.FileCopy:
+ fileset[string(cmdt.Src)] = true
+ fileset[string(cmdt.Dst)] = true
+ case libfastimport.FileRename:
+ fileset[string(cmdt.Src)] = true
+ fileset[string(cmdt.Dst)] = true
+
+ case libfastimport.FileDeleteAll:
+ case libfastimport.NoteModify:
+ case libfastimport.NoteModifyInline:
+
+ case libfastimport.CmdTag:
+ case libfastimport.CmdReset:
+ case libfastimport.CmdBlob:
+ case libfastimport.CmdCheckpoint:
+ case libfastimport.CmdProgress:
+ case libfastimport.CmdFeature:
+ case libfastimport.CmdOption:
+ case libfastimport.CmdDone:
+
+ case libfastimport.CmdComment:
+
+ default:
+ abort(errors.Errorf("Unexpected command: %[1]T(%#[1]v)", cmd))
+ }
+ }
+ status()
+ fmt.Fprintln(os.Stderr)
+
+ filelist := make([]string, len(fileset))
+ i := 0
+ for filename := range fileset {
+ filelist[i] = filename
+ i++
+ }
+ sort.Strings(filelist)
+ for _, filename := range filelist {
+ fmt.Println(filename)
+ }
+}
diff --git a/fi-pacmanlog/main.go b/fi-pacmanlog/main.go
new file mode 100644
index 0000000..b78e8ed
--- /dev/null
+++ b/fi-pacmanlog/main.go
@@ -0,0 +1,88 @@
+package main
+
+import (
+ "fmt"
+ "io"
+ "os"
+ "strings"
+
+ "git.lukeshu.com/go/libfastimport"
+ "github.com/pkg/errors"
+)
+
+func abort(err error) {
+ fmt.Fprintln(os.Stderr, "Error:", err)
+ os.Exit(1)
+}
+
+func main() {
+ newrefname := os.Args[1]
+
+ frontend := libfastimport.NewFrontend(os.Stdin, nil, nil)
+ backend := libfastimport.NewBackend(os.Stdout, nil, nil)
+
+ commitMeta := libfastimport.CmdCommit{}
+ commitFile := []libfastimport.Cmd{}
+ for {
+ cmd, err := frontend.ReadCmd()
+ if err != nil {
+ if err == io.EOF {
+ break
+ }
+ abort(err)
+ }
+ switch cmdt := cmd.(type) {
+
+ case libfastimport.CmdCommit:
+ commitMeta = cmdt
+ commitFile = []libfastimport.Cmd{}
+ case libfastimport.CmdCommitEnd:
+ commitMeta.Ref = newrefname
+ err := backend.Do(commitMeta)
+ if err != nil {
+ abort(err)
+ }
+ if len(commitFile) > 1 {
+ for _, file := range commitFile {
+ err := backend.Do(file)
+ if err != nil {
+ abort(err)
+ }
+ }
+ }
+ case libfastimport.FileModify:
+ if !strings.HasPrefix(string(cmdt.Path), "repos/core-x86_64/") {
+ break
+ }
+ cmdt.Path = libfastimport.Path(strings.TrimPrefix(string(cmdt.Path), "repos/core-x86_64/"))
+ commitFile = append(commitFile, cmdt)
+ case libfastimport.FileDeleteAll:
+ commitFile = append(commitFile, cmd)
+
+ case libfastimport.CmdReset:
+ cmdt.RefName = newrefname
+ err := backend.Do(cmdt)
+ if err != nil {
+ abort(err)
+ }
+ case libfastimport.CmdFeature:
+ err := backend.Do(cmdt)
+ if err != nil {
+ abort(err)
+ }
+ case libfastimport.CmdOption:
+ err := backend.Do(cmdt)
+ if err != nil {
+ abort(err)
+ }
+ case libfastimport.CmdDone:
+ err := backend.Do(cmdt)
+ if err != nil {
+ abort(err)
+ }
+ case libfastimport.CmdComment:
+ default:
+ abort(errors.Errorf("Unexpected command: %[1]T(%#[1]v)", cmd))
+ }
+ }
+}