1
1
package main
2
2
3
3
import (
4
+ "context"
4
5
"encoding/json"
5
6
"errors"
6
7
"fmt"
@@ -19,7 +20,9 @@ import (
19
20
"github.com/github/git-sizer/sizes"
20
21
)
21
22
22
- const usage = `usage: git-sizer [OPTS]
23
+ const usage = `usage: git-sizer [OPTS] [ROOT...]
24
+
25
+ Scan objects in your Git repository and emit statistics about them.
23
26
24
27
--threshold THRESHOLD minimum level of concern (i.e., number of stars)
25
28
that should be reported. Default:
@@ -45,12 +48,29 @@ const usage = `usage: git-sizer [OPTS]
45
48
be set via gitconfig: 'sizer.progress'.
46
49
--version only report the git-sizer version number
47
50
51
+ Object selection:
52
+
53
+ git-sizer traverses through your Git history to find objects to
54
+ process. By default, it processes all objects that are reachable from
55
+ any reference. You can tell it to process only some of your
56
+ references; see "Reference selection" below.
57
+
58
+ If explicit ROOTs are specified on the command line, each one should
59
+ be a string that 'git rev-parse' can convert into a single Git object
60
+ ID, like 'main', 'main~:src', or an abbreviated SHA-1. See
61
+ git-rev-parse(1) for details. In that case, git-sizer also treats
62
+ those objects as starting points for its traversal, and also includes
63
+ the Git objects that are reachable from those roots in the analysis.
64
+
65
+ As a special case, if one or more ROOTs are specified on the command
66
+ line but _no_ reference selection options, then _only_ the specified
67
+ ROOTs are traversed, and no references.
68
+
48
69
Reference selection:
49
70
50
- By default, git-sizer processes all Git objects that are reachable
51
- from any reference. The following options can be used to limit which
52
- references to process. The last rule matching a reference determines
53
- whether that reference is processed.
71
+ The following options can be used to limit which references to
72
+ process. The last rule matching a reference determines whether that
73
+ reference is processed.
54
74
55
75
--[no-]branches process [don't process] branches
56
76
--[no-]tags process [don't process] tags
@@ -93,14 +113,16 @@ var ReleaseVersion string
93
113
var BuildVersion string
94
114
95
115
func main () {
96
- err := mainImplementation (os .Stdout , os .Stderr , os .Args [1 :])
116
+ ctx := context .Background ()
117
+
118
+ err := mainImplementation (ctx , os .Stdout , os .Stderr , os .Args [1 :])
97
119
if err != nil {
98
120
fmt .Fprintf (os .Stderr , "error: %s\n " , err )
99
121
os .Exit (1 )
100
122
}
101
123
}
102
124
103
- func mainImplementation (stdout , stderr io.Writer , args []string ) error {
125
+ func mainImplementation (ctx context. Context , stdout , stderr io.Writer , args []string ) error {
104
126
var nameStyle sizes.NameStyle = sizes .NameStyleFull
105
127
var cpuprofile string
106
128
var jsonOutput bool
@@ -216,10 +238,6 @@ func mainImplementation(stdout, stderr io.Writer, args []string) error {
216
238
return nil
217
239
}
218
240
219
- if len (flags .Args ()) != 0 {
220
- return errors .New ("excess arguments" )
221
- }
222
-
223
241
if repoErr != nil {
224
242
return fmt .Errorf ("couldn't open Git repository: %w" , repoErr )
225
243
}
@@ -273,7 +291,7 @@ func mainImplementation(stdout, stderr io.Writer, args []string) error {
273
291
progress = v
274
292
}
275
293
276
- rg , err := rgb .Finish ()
294
+ rg , err := rgb .Finish (len ( flags . Args ()) == 0 )
277
295
if err != nil {
278
296
return err
279
297
}
@@ -288,7 +306,27 @@ func mainImplementation(stdout, stderr io.Writer, args []string) error {
288
306
progressMeter = meter .NewProgressMeter (stderr , 100 * time .Millisecond )
289
307
}
290
308
291
- historySize , err := sizes .ScanRepositoryUsingGraph (repo , rg , nameStyle , progressMeter )
309
+ refRoots , err := sizes .CollectReferences (ctx , repo , rg )
310
+ if err != nil {
311
+ return fmt .Errorf ("determining which reference to scan: %w" , err )
312
+ }
313
+
314
+ roots := make ([]sizes.Root , 0 , len (refRoots )+ len (flags .Args ()))
315
+ for _ , refRoot := range refRoots {
316
+ roots = append (roots , refRoot )
317
+ }
318
+
319
+ for _ , arg := range flags .Args () {
320
+ oid , err := repo .ResolveObject (arg )
321
+ if err != nil {
322
+ return fmt .Errorf ("resolving command-line argument %q: %w" , arg , err )
323
+ }
324
+ roots = append (roots , sizes .NewExplicitRoot (arg , oid ))
325
+ }
326
+
327
+ historySize , err := sizes .ScanRepositoryUsingGraph (
328
+ ctx , repo , roots , nameStyle , progressMeter ,
329
+ )
292
330
if err != nil {
293
331
return fmt .Errorf ("error scanning repository: %w" , err )
294
332
}
0 commit comments