@@ -6,28 +6,18 @@ import (
66 "os"
77 "os/exec"
88 "strings"
9-
10- "github.com/schollz/progressbar/v2"
119)
1210
13- type entry struct {
14- commit string
15- timestamp int
16- data string
17- }
18-
19- var directory string
20- var command string
21- var branch string
22- var outputFile string
23- var limit int
24- var after string
25- var before string
26-
2711func main () {
12+ var directory string
13+ var command string
14+ var outputFile string
15+ var limit int
16+ var after string
17+ var before string
18+
2819 flag .StringVar (& directory , "directory" , "" , "git workspace (by default current directory)" )
2920 flag .StringVar (& command , "command" , "" , "command to execute" )
30- flag .StringVar (& branch , "branch" , "master" , "git branch to check" )
3121 flag .StringVar (& outputFile , "output" , "out.csv" , "output csv file" )
3222 flag .StringVar (& after , "after" , "" , "optional begin date of history search" )
3323 flag .StringVar (& before , "before" , "" , "optional end date of history search" )
@@ -36,37 +26,14 @@ func main() {
3626
3727 // if no parameter given, use history of current history
3828 var err error
39- if directory == "" {
40- directory , err = os .Getwd ()
41- checkError (err )
42- }
43-
44- if stat , err := os .Stat (directory ); err != nil || ! stat .IsDir () {
45- fmt .Printf ("Invalid directory: %s\n " , directory )
46- flag .PrintDefaults ()
47- os .Exit (1 )
48- }
49-
50- commits , err := getCommits (branch , limit , after , before )
51- checkError (err )
52-
53- bar := progressbar .New (len (commits ))
54- result := make ([]entry , 0 , len (commits ))
55-
56- for _ , commit := range commits {
57- bar .Add (1 )
58- result = append (result , evaluate (commit ))
59- }
60-
61- // checkout to initial version
62- checkout (branch )
6329
6430 out , err := os .Create (outputFile )
6531 checkError (err )
6632 defer out .Close ()
6733
68- err = writeCsv ( result , out )
34+ err = DumpHistory ( directory , command , out , limit , after , before )
6935 checkError (err )
36+
7037 fmt .Printf ("\n Wrote file %s\n " , outputFile )
7138}
7239
@@ -77,25 +44,25 @@ func checkError(err error) {
7744 }
7845}
7946
80- func evaluate (commit entry ) entry {
81- checkout ( commit .commit )
47+ func evaluate (commit entry , command string ) entry {
48+ execute ( "git" , "checkout" , commit .commit )
8249
8350 stdout , _ := execute ("sh" , "-c" , command )
8451
85- commit .data = strings .TrimSpace (stdout )
52+ data := strings .SplitN (stdout , "\n " , 2 )
53+ commit .data = data [0 ]
8654
8755 return commit
8856}
8957
9058func execute (name string , args ... string ) (string , error ) {
9159 cmd := exec .Command (name , args ... )
92- cmd .Dir = directory
9360 out , err := cmd .CombinedOutput ()
9461
9562 if err != nil {
9663 fmt .Fprintf (os .Stderr , "Command '%s' failed: %s: %s" , cmd .String (), err , string (out ))
9764 os .Exit (1 )
9865 }
9966
100- return string (out ), err
67+ return strings . TrimSpace ( string (out ) ), err
10168}
0 commit comments