@@ -17,9 +17,7 @@ import (
17
17
)
18
18
19
19
const Usage = `usage: git-sizer [OPTS]
20
- --branches process all branches
21
- --tags process all tags
22
- --remotes process all remotes
20
+
23
21
-v, --verbose report all statistics, whether concerning or not
24
22
--threshold threshold minimum level of concern (i.e., number of stars)
25
23
that should be reported. Default:
@@ -34,6 +32,22 @@ const Usage = `usage: git-sizer [OPTS]
34
32
Default: --json-version=1.
35
33
--[no-]progress report (don't report) progress to stderr.
36
34
--version only report the git-sizer version number
35
+
36
+ Reference selection:
37
+
38
+ By default, git-sizer processes all Git objects that are reachable from any
39
+ reference. The following options can be used to limit which references to
40
+ include. The last rule matching a reference determines whether that reference
41
+ is processed:
42
+
43
+ --branches process branches
44
+ --tags process tags
45
+ --remotes process remote refs
46
+ --include prefix process references with the specified prefix
47
+ (e.g., '--include=refs/remotes/origin')
48
+ --exclude prefix don't process references with the specified
49
+ prefix (e.g., '--exclude=refs/notes')
50
+
37
51
`
38
52
39
53
var ReleaseVersion string
@@ -65,6 +79,59 @@ func (v *NegatedBoolValue) Type() string {
65
79
return "bool"
66
80
}
67
81
82
+ type filterValue struct {
83
+ filter * git.IncludeExcludeFilter
84
+ polarity git.Polarity
85
+ prefix string
86
+ }
87
+
88
+ func (v * filterValue ) Set (s string ) error {
89
+ var prefix string
90
+ var polarity git.Polarity
91
+
92
+ if v .prefix == "" {
93
+ prefix = s
94
+ polarity = v .polarity
95
+ } else {
96
+ prefix = v .prefix
97
+ // Allow a boolean value to alter the polarity:
98
+ b , err := strconv .ParseBool (s )
99
+ if err != nil {
100
+ return err
101
+ }
102
+ if b {
103
+ polarity = git .Include
104
+ } else {
105
+ polarity = git .Exclude
106
+ }
107
+ }
108
+
109
+ switch polarity {
110
+ case git .Include :
111
+ v .filter .Include (git .PrefixFilter (prefix ))
112
+ case git .Exclude :
113
+ v .filter .Exclude (git .PrefixFilter (prefix ))
114
+ }
115
+
116
+ return nil
117
+ }
118
+
119
+ func (v * filterValue ) Get () interface {} {
120
+ return nil
121
+ }
122
+
123
+ func (v * filterValue ) String () string {
124
+ return ""
125
+ }
126
+
127
+ func (v * filterValue ) Type () string {
128
+ if v .prefix == "" {
129
+ return "prefix"
130
+ } else {
131
+ return ""
132
+ }
133
+ }
134
+
68
135
func main () {
69
136
err := mainImplementation ()
70
137
if err != nil {
@@ -74,25 +141,40 @@ func main() {
74
141
}
75
142
76
143
func mainImplementation () error {
77
- var processBranches bool
78
- var processTags bool
79
- var processRemotes bool
80
144
var nameStyle sizes.NameStyle = sizes .NameStyleFull
81
145
var cpuprofile string
82
146
var jsonOutput bool
83
147
var jsonVersion uint
84
148
var threshold sizes.Threshold = 1
85
149
var progress bool
86
150
var version bool
151
+ var filter git.IncludeExcludeFilter
87
152
88
153
flags := pflag .NewFlagSet ("git-sizer" , pflag .ContinueOnError )
89
154
flags .Usage = func () {
90
155
fmt .Print (Usage )
91
156
}
92
157
93
- flags .BoolVar (& processBranches , "branches" , false , "process all branches" )
94
- flags .BoolVar (& processTags , "tags" , false , "process all tags" )
95
- flags .BoolVar (& processRemotes , "remotes" , false , "process all remote-tracking branches" )
158
+ flags .Var (& filterValue {& filter , git .Include , "" }, "include" , "include specified references" )
159
+ flags .Var (& filterValue {& filter , git .Exclude , "" }, "exclude" , "exclude specified references" )
160
+
161
+ flag := flags .VarPF (
162
+ & filterValue {& filter , git .Include , "refs/heads/" }, "branches" , "" ,
163
+ "process all branches" ,
164
+ )
165
+ flag .NoOptDefVal = "true"
166
+
167
+ flag = flags .VarPF (
168
+ & filterValue {& filter , git .Include , "refs/tags/" }, "tags" , "" ,
169
+ "process all tags" ,
170
+ )
171
+ flag .NoOptDefVal = "true"
172
+
173
+ flag = flags .VarPF (
174
+ & filterValue {& filter , git .Include , "refs/remotes/" }, "remotes" , "" ,
175
+ "process all remotes" ,
176
+ )
177
+ flag .NoOptDefVal = "true"
96
178
97
179
flags .VarP (
98
180
sizes .NewThresholdFlagValue (& threshold , 0 ),
@@ -181,19 +263,6 @@ func mainImplementation() error {
181
263
182
264
var historySize sizes.HistorySize
183
265
184
- var filter git.IncludeExcludeFilter
185
- if processBranches || processTags || processRemotes {
186
- if processBranches {
187
- filter .Include (git .BranchesFilter )
188
- }
189
- if processTags {
190
- filter .Include (git .TagsFilter )
191
- }
192
- if processRemotes {
193
- filter .Include (git .RemotesFilter )
194
- }
195
- }
196
-
197
266
historySize , err = sizes .ScanRepositoryUsingGraph (repo , filter .Filter , nameStyle , progress )
198
267
if err != nil {
199
268
return fmt .Errorf ("error scanning repository: %s" , err )
0 commit comments