Skip to content

Commit 136b901

Browse files
committed
filterValue: take a *RefGroupBuilder as argument
1 parent 33f9c9e commit 136b901

2 files changed

Lines changed: 18 additions & 19 deletions

File tree

internal/refopts/filter_value.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
)
99

1010
type filterValue struct {
11-
// filter is the filter that will be modified if this option
12-
// is used.
13-
filter *git.ReferenceFilter
11+
// rgb is the RefGroupBuilder whose top-level filter is
12+
// affected if this option is used.
13+
rgb *RefGroupBuilder
1414

1515
// combiner specifies how the filter generated by this option
1616
// is combined with the existing filter; i.e., does it cause
@@ -60,7 +60,7 @@ func (v *filterValue) Set(s string) error {
6060
filter = git.PrefixFilter(pattern)
6161
}
6262

63-
*v.filter = combiner.Combine(*v.filter, filter)
63+
v.rgb.topLevelGroup.filter = combiner.Combine(v.rgb.topLevelGroup.filter, filter)
6464

6565
return nil
6666
}

internal/refopts/ref_group_builder.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,80 +142,79 @@ func splitKey(key string) (sizes.RefGroupSymbol, string) {
142142

143143
// Add some reference-related options to `flags`.
144144
func (rgb *RefGroupBuilder) AddRefopts(flags *pflag.FlagSet) {
145-
tlf := &rgb.topLevelGroup.filter
146145
flags.Var(
147-
&filterValue{tlf, git.Include, "", false}, "include",
146+
&filterValue{rgb, git.Include, "", false}, "include",
148147
"include specified references",
149148
)
150149
flags.Var(
151-
&filterValue{tlf, git.Include, "", true}, "include-regexp",
150+
&filterValue{rgb, git.Include, "", true}, "include-regexp",
152151
"include references matching the specified regular expression",
153152
)
154153
flags.Var(
155-
&filterValue{tlf, git.Exclude, "", false}, "exclude",
154+
&filterValue{rgb, git.Exclude, "", false}, "exclude",
156155
"exclude specified references",
157156
)
158157
flags.Var(
159-
&filterValue{tlf, git.Exclude, "", true}, "exclude-regexp",
158+
&filterValue{rgb, git.Exclude, "", true}, "exclude-regexp",
160159
"exclude references matching the specified regular expression",
161160
)
162161

163162
flag := flags.VarPF(
164-
&filterValue{tlf, git.Include, "refs/heads", false}, "branches", "",
163+
&filterValue{rgb, git.Include, "refs/heads", false}, "branches", "",
165164
"process all branches",
166165
)
167166
flag.NoOptDefVal = "true"
168167

169168
flag = flags.VarPF(
170-
&filterValue{tlf, git.Exclude, "refs/heads", false}, "no-branches", "",
169+
&filterValue{rgb, git.Exclude, "refs/heads", false}, "no-branches", "",
171170
"exclude all branches",
172171
)
173172
flag.NoOptDefVal = "true"
174173

175174
flag = flags.VarPF(
176-
&filterValue{tlf, git.Include, "refs/tags", false}, "tags", "",
175+
&filterValue{rgb, git.Include, "refs/tags", false}, "tags", "",
177176
"process all tags",
178177
)
179178
flag.NoOptDefVal = "true"
180179

181180
flag = flags.VarPF(
182-
&filterValue{tlf, git.Exclude, "refs/tags", false}, "no-tags", "",
181+
&filterValue{rgb, git.Exclude, "refs/tags", false}, "no-tags", "",
183182
"exclude all tags",
184183
)
185184
flag.NoOptDefVal = "true"
186185

187186
flag = flags.VarPF(
188-
&filterValue{tlf, git.Include, "refs/remotes", false}, "remotes", "",
187+
&filterValue{rgb, git.Include, "refs/remotes", false}, "remotes", "",
189188
"process all remote-tracking references",
190189
)
191190
flag.NoOptDefVal = "true"
192191

193192
flag = flags.VarPF(
194-
&filterValue{tlf, git.Exclude, "refs/remotes", false}, "no-remotes", "",
193+
&filterValue{rgb, git.Exclude, "refs/remotes", false}, "no-remotes", "",
195194
"exclude all remote-tracking references",
196195
)
197196
flag.NoOptDefVal = "true"
198197

199198
flag = flags.VarPF(
200-
&filterValue{tlf, git.Include, "refs/notes", false}, "notes", "",
199+
&filterValue{rgb, git.Include, "refs/notes", false}, "notes", "",
201200
"process all git-notes references",
202201
)
203202
flag.NoOptDefVal = "true"
204203

205204
flag = flags.VarPF(
206-
&filterValue{tlf, git.Exclude, "refs/notes", false}, "no-notes", "",
205+
&filterValue{rgb, git.Exclude, "refs/notes", false}, "no-notes", "",
207206
"exclude all git-notes references",
208207
)
209208
flag.NoOptDefVal = "true"
210209

211210
flag = flags.VarPF(
212-
&filterValue{tlf, git.Include, "refs/stash", true}, "stash", "",
211+
&filterValue{rgb, git.Include, "refs/stash", true}, "stash", "",
213212
"process refs/stash",
214213
)
215214
flag.NoOptDefVal = "true"
216215

217216
flag = flags.VarPF(
218-
&filterValue{tlf, git.Exclude, "refs/stash", true}, "no-stash", "",
217+
&filterValue{rgb, git.Exclude, "refs/stash", true}, "no-stash", "",
219218
"exclude refs/stash",
220219
)
221220
flag.NoOptDefVal = "true"

0 commit comments

Comments
 (0)