66 "context"
77 "fmt"
88 "io"
9+ "iter"
910 "strings"
1011
1112 "github.com/charmbracelet/log"
@@ -133,10 +134,7 @@ type ConfigEntry struct {
133134
134135// ListRegexp lists all configuration entries that match the given pattern.
135136// If pattern is empty, '.' is used to match all entries.
136- func (cfg * Config ) ListRegexp (ctx context.Context , pattern string ) (
137- func (yield func (ConfigEntry , error ) bool ),
138- error ,
139- ) {
137+ func (cfg * Config ) ListRegexp (ctx context.Context , pattern string ) iter.Seq2 [ConfigEntry , error ] {
140138 if pattern == "" {
141139 pattern = "."
142140 }
@@ -145,26 +143,25 @@ func (cfg *Config) ListRegexp(ctx context.Context, pattern string) (
145143
146144var _newline = []byte ("\n " )
147145
148- func (cfg * Config ) list (ctx context.Context , args ... string ) (
149- func (yield func (ConfigEntry , error ) bool ),
150- error ,
151- ) {
146+ func (cfg * Config ) list (ctx context.Context , args ... string ) iter.Seq2 [ConfigEntry , error ] {
147+ log := cfg .log
152148 args = append ([]string {"config" , "--null" }, args ... )
153- cmd := newGitCmd (ctx , cfg .log , args ... ).
154- Dir (cfg .dir ).
155- AppendEnv (cfg .env ... )
156-
157- stdout , err := cmd .StdoutPipe ()
158- if err != nil {
159- return nil , fmt .Errorf ("stdout pipe: %w" , err )
160- }
149+ return func (yield func (ConfigEntry , error ) bool ) {
150+ cmd := newGitCmd (ctx , cfg .log , args ... ).
151+ Dir (cfg .dir ).
152+ AppendEnv (cfg .env ... )
153+
154+ stdout , err := cmd .StdoutPipe ()
155+ if err != nil {
156+ yield (ConfigEntry {}, fmt .Errorf ("stdout pipe: %w" , err ))
157+ return
158+ }
161159
162- if err := cmd .Start (cfg .exec ); err != nil {
163- return nil , fmt .Errorf ("start git-config: %w" , err )
164- }
160+ if err := cmd .Start (cfg .exec ); err != nil {
161+ yield (ConfigEntry {}, fmt .Errorf ("start git-config: %w" , err ))
162+ return
163+ }
165164
166- log := cfg .log
167- return func (yield func (ConfigEntry , error ) bool ) {
168165 // Always wait for the command to finish when this returns.
169166 // Ignore the error because git-config fails if there are no matches.
170167 // It's not an error for us if there are no matches.
@@ -195,9 +192,10 @@ func (cfg *Config) list(ctx context.Context, args ...string) (
195192 }
196193
197194 if err := scan .Err (); err != nil {
198- _ = yield (ConfigEntry {}, fmt .Errorf ("scan git-config output: %w" , err ))
195+ yield (ConfigEntry {}, fmt .Errorf ("scan git-config output: %w" , err ))
196+ return
199197 }
200- }, nil
198+ }
201199}
202200
203201// scanNullDelimited is a bufio.SplitFunc that splits on null bytes.
0 commit comments