@@ -49,16 +49,18 @@ const Usage = `usage: git-sizer [OPTS]
49
49
include. The last rule matching a reference determines whether that reference
50
50
is processed:
51
51
52
- --branches process branches
53
- --tags process tags
54
- --remotes process remote refs
52
+ --[no-]branches process [don't process] branches
53
+ --[no-]tags process [don't process] tags
54
+ --[no-]remotes process [don't process] remote-tracking references
55
+ --[no-]notes process [don't process] git-notes references
56
+ --[no-]stash process [don't process] refs/stash
55
57
--include PREFIX process references with the specified PREFIX
56
58
(e.g., '--include=refs/remotes/origin')
57
59
--include-regexp REGEXP process references matching the specified
58
60
regular expression (e.g.,
59
61
'--include-regexp=refs/tags/release-.*')
60
62
--exclude PREFIX don't process references with the specified
61
- PREFIX (e.g., '--exclude=refs/notes ')
63
+ PREFIX (e.g., '--exclude=refs/changes ')
62
64
--exclude-regexp REGEXP don't process references matching the specified
63
65
regular expression
64
66
--show-refs show which refs are being included/excluded
@@ -99,38 +101,53 @@ func (v *NegatedBoolValue) Type() string {
99
101
}
100
102
101
103
type filterValue struct {
102
- filter * git.IncludeExcludeFilter
104
+ // The filter to which values will be appended:
105
+ filter * git.IncludeExcludeFilter
106
+
107
+ // The polarity of this option (i.e., does it cause the things
108
+ // that it references to be included or excluded?):
103
109
polarity git.Polarity
104
- pattern string
105
- regexp bool
110
+
111
+ // If this is set, then it is used as the pattern. If not, then
112
+ // the user should supply the pattern.
113
+ pattern string
114
+
115
+ // Should `pattern` be interpreted as a regexp (as opposed to a
116
+ // prefix)?
117
+ regexp bool
106
118
}
107
119
108
120
func (v * filterValue ) Set (s string ) error {
109
- var polarity git.Polarity
110
121
var filter git.ReferenceFilter
122
+ polarity := v .polarity
123
+
124
+ var pattern string
125
+ if v .pattern != "" {
126
+ // The pattern is fixed for this option:
127
+ pattern = v .pattern
128
+
129
+ // It's not really expected, but if the user supplied a
130
+ // `false` boolean value, invert the polarity:
131
+ b , err := strconv .ParseBool (s )
132
+ if err != nil {
133
+ return err
134
+ }
135
+ if ! b {
136
+ polarity = polarity .Inverted ()
137
+ }
138
+ } else {
139
+ // The user must supply the pattern.
140
+ pattern = s
141
+ }
111
142
112
143
if v .regexp {
113
- polarity = v .polarity
114
144
var err error
115
- filter , err = git .RegexpFilter (s )
145
+ filter , err = git .RegexpFilter (pattern )
116
146
if err != nil {
117
147
return fmt .Errorf ("invalid regexp: %q" , s )
118
148
}
119
- } else if v .pattern == "" {
120
- polarity = v .polarity
121
- filter = git .PrefixFilter (s )
122
149
} else {
123
- // Allow a boolean value to alter the polarity:
124
- b , err := strconv .ParseBool (s )
125
- if err != nil {
126
- return err
127
- }
128
- if b {
129
- polarity = git .Include
130
- } else {
131
- polarity = git .Exclude
132
- }
133
- filter = git .PrefixFilter (v .pattern )
150
+ filter = git .PrefixFilter (pattern )
134
151
}
135
152
136
153
switch polarity {
@@ -152,12 +169,12 @@ func (v *filterValue) String() string {
152
169
}
153
170
154
171
func (v * filterValue ) Type () string {
155
- if v .regexp {
172
+ if v .pattern != "" {
173
+ return "bool"
174
+ } else if v .regexp {
156
175
return "regexp"
157
- } else if v .pattern == "" {
158
- return "prefix"
159
176
} else {
160
- return ""
177
+ return "prefix "
161
178
}
162
179
}
163
180
@@ -203,20 +220,62 @@ func mainImplementation(args []string) error {
203
220
)
204
221
205
222
flag := flags .VarPF (
206
- & filterValue {& filter , git .Include , "refs/heads/ " , false }, "branches" , "" ,
223
+ & filterValue {& filter , git .Include , "refs/heads" , false }, "branches" , "" ,
207
224
"process all branches" ,
208
225
)
209
226
flag .NoOptDefVal = "true"
210
227
211
228
flag = flags .VarPF (
212
- & filterValue {& filter , git .Include , "refs/tags/" , false }, "tags" , "" ,
229
+ & filterValue {& filter , git .Exclude , "refs/heads" , false }, "no-branches" , "" ,
230
+ "exclude all branches" ,
231
+ )
232
+ flag .NoOptDefVal = "true"
233
+
234
+ flag = flags .VarPF (
235
+ & filterValue {& filter , git .Include , "refs/tags" , false }, "tags" , "" ,
213
236
"process all tags" ,
214
237
)
215
238
flag .NoOptDefVal = "true"
216
239
217
240
flag = flags .VarPF (
218
- & filterValue {& filter , git .Include , "refs/remotes/" , false }, "remotes" , "" ,
219
- "process all remotes" ,
241
+ & filterValue {& filter , git .Exclude , "refs/tags" , false }, "no-tags" , "" ,
242
+ "exclude all tags" ,
243
+ )
244
+ flag .NoOptDefVal = "true"
245
+
246
+ flag = flags .VarPF (
247
+ & filterValue {& filter , git .Include , "refs/remotes" , false }, "remotes" , "" ,
248
+ "process all remote-tracking references" ,
249
+ )
250
+ flag .NoOptDefVal = "true"
251
+
252
+ flag = flags .VarPF (
253
+ & filterValue {& filter , git .Exclude , "refs/remotes" , false }, "no-remotes" , "" ,
254
+ "exclude all remote-tracking references" ,
255
+ )
256
+ flag .NoOptDefVal = "true"
257
+
258
+ flag = flags .VarPF (
259
+ & filterValue {& filter , git .Include , "refs/notes" , false }, "notes" , "" ,
260
+ "process all git-notes references" ,
261
+ )
262
+ flag .NoOptDefVal = "true"
263
+
264
+ flag = flags .VarPF (
265
+ & filterValue {& filter , git .Exclude , "refs/notes" , false }, "no-notes" , "" ,
266
+ "exclude all git-notes references" ,
267
+ )
268
+ flag .NoOptDefVal = "true"
269
+
270
+ flag = flags .VarPF (
271
+ & filterValue {& filter , git .Include , "refs/stash" , true }, "stash" , "" ,
272
+ "process refs/stash" ,
273
+ )
274
+ flag .NoOptDefVal = "true"
275
+
276
+ flag = flags .VarPF (
277
+ & filterValue {& filter , git .Exclude , "refs/stash" , true }, "no-stash" , "" ,
278
+ "exclude refs/stash" ,
220
279
)
221
280
flag .NoOptDefVal = "true"
222
281
0 commit comments