66 "path"
77 "strings"
88
9- "github.com/samber/lo"
109 lop "github.com/samber/lo/parallel"
1110
11+ "github.com/dirk/quickhook/internal"
1212 "github.com/dirk/quickhook/repo"
1313 "github.com/dirk/quickhook/tracing"
1414)
@@ -26,41 +26,32 @@ type PreCommit struct {
2626// argsFiles can be non-empty with the files passed in by the user when manually running this hook,
2727// or it can be empty and the list of files will be retrieved from Git.
2828func (hook * PreCommit ) Run (argsFiles []string ) error {
29- // Resolve files to be committed in parallel with shimming git.
30- filesChan := lo .Async2 (func () ([]string , error ) {
31- if len (argsFiles ) > 0 {
32- return argsFiles , nil
33- }
34- if files , err := hook .Repo .FilesToBeCommitted (); err != nil {
35- return nil , err
36- } else {
37- return files , nil
38- }
39- })
40- shimChan := lo .Async2 (shimGit )
41- mutatingChan := lo .Async2 (func () ([]string , error ) {
42- return hook .Repo .FindHookExecutables (PRE_COMMIT_MUTATING_HOOK )
43- })
44- parallelChan := lo .Async2 (func () ([]string , error ) {
45- return hook .Repo .FindHookExecutables (PRE_COMMIT_HOOK )
46- })
47-
48- dirForPath , err := (<- shimChan ).Unpack ()
29+ // The shimming is really fast, so just do it first with a defer for cleaning up the
30+ // temporary directory.
31+ dirForPath , err := shimGit ()
4932 if err != nil {
5033 return err
5134 }
52- // Check the shimChan first so that if we did successfully create a directory with a shim we
53- // can make sure to clean it up if anything else errored.
5435 defer os .RemoveAll (dirForPath )
55- files , err := (<- filesChan ).Unpack ()
56- if err != nil {
57- return err
58- }
59- mutatingExecutables , err := (<- mutatingChan ).Unpack ()
60- if err != nil {
61- return err
62- }
63- parallelExecutables , err := (<- parallelChan ).Unpack ()
36+
37+ files , mutatingExecutables , parallelExecutables , err := internal .FanOut3 (
38+ func () ([]string , error ) {
39+ if len (argsFiles ) > 0 {
40+ return argsFiles , nil
41+ }
42+ if files , err := hook .Repo .FilesToBeCommitted (); err != nil {
43+ return nil , err
44+ } else {
45+ return files , nil
46+ }
47+ },
48+ func () ([]string , error ) {
49+ return hook .Repo .FindHookExecutables (PRE_COMMIT_MUTATING_HOOK )
50+ },
51+ func () ([]string , error ) {
52+ return hook .Repo .FindHookExecutables (PRE_COMMIT_HOOK )
53+ },
54+ )
6455 if err != nil {
6556 return err
6657 }
0 commit comments