@@ -11,50 +11,6 @@ import (
11
11
"github.com/github/git-sizer/meter"
12
12
)
13
13
14
- // RefGroupSymbol is the string "identifier" that is used to refer to
15
- // a refgroup, for example in the gitconfig. Nesting of refgroups is
16
- // inferred from their names, using "." as separator between
17
- // components. For example, if there are three refgroups with symbols
18
- // "tags", "tags.releases", and "foo.bar", then "tags.releases" is
19
- // considered to be nested within "tags", and "foo.bar" is considered
20
- // to be nested within "foo", the latter being created automatically
21
- // if it was not configured explicitly.
22
- type RefGroupSymbol string
23
-
24
- // RefGroup is a group of references, for example "branches" or
25
- // "tags". Reference groups might overlap.
26
- type RefGroup struct {
27
- // Symbol is the unique string by which this `RefGroup` is
28
- // identified and configured. It consists of dot-separated
29
- // components, which implicitly makes a nested tree-like
30
- // structure.
31
- Symbol RefGroupSymbol
32
-
33
- // Name is the name for this `ReferenceGroup` to be presented
34
- // in user-readable output.
35
- Name string
36
- }
37
-
38
- // RefGrouper describes a type that can collate reference names into
39
- // groups and decide which ones to walk.
40
- type RefGrouper interface {
41
- // Categorize tells whether `refname` should be walked at all,
42
- // and if so, the symbols of the reference groups to which it
43
- // belongs.
44
- Categorize (refname string ) (bool , []RefGroupSymbol )
45
-
46
- // Groups returns the list of `ReferenceGroup`s, in the order
47
- // that they should be presented. The return value might
48
- // depend on which references have been seen so far.
49
- Groups () []RefGroup
50
- }
51
-
52
- type refSeen struct {
53
- git.Reference
54
- walked bool
55
- groups []RefGroupSymbol
56
- }
57
-
58
14
// ScanRepositoryUsingGraph scans `repo`, using `rg` to decide which
59
15
// references to scan and how to group them. `nameStyle` specifies
60
16
// whether the output should include full names, hashes only, or
@@ -71,9 +27,9 @@ func ScanRepositoryUsingGraph(
71
27
72
28
graph := NewGraph (nameStyle )
73
29
74
- refIter , err := repo . NewReferenceIter (ctx )
30
+ refsSeen , err := CollectReferences (ctx , repo , rg )
75
31
if err != nil {
76
- return HistorySize {}, err
32
+ return HistorySize {}, fmt . Errorf ( "reading references: %w" , err )
77
33
}
78
34
79
35
objIter , err := repo .NewObjectIter (context .TODO ())
@@ -82,41 +38,22 @@ func ScanRepositoryUsingGraph(
82
38
}
83
39
84
40
errChan := make (chan error , 1 )
85
- var refsSeen []refSeen
86
- // Feed the references that we want into the stdin of the object
87
- // iterator:
41
+ // Feed the references that we want to walk into the stdin of the
42
+ // object iterator:
88
43
go func () {
89
44
defer objIter .Close ()
90
45
91
46
errChan <- func () error {
92
- for {
93
- ref , ok , err := refIter .Next ()
94
- if err != nil {
95
- return err
96
- }
97
- if ! ok {
98
- return nil
99
- }
100
-
101
- walk , groups := rg .Categorize (ref .Refname )
102
-
103
- refsSeen = append (
104
- refsSeen ,
105
- refSeen {
106
- Reference : ref ,
107
- walked : walk ,
108
- groups : groups ,
109
- },
110
- )
111
-
112
- if ! walk {
47
+ for _ , refSeen := range refsSeen {
48
+ if ! refSeen .walked {
113
49
continue
114
50
}
115
51
116
- if err := objIter .AddRoot (ref .OID ); err != nil {
52
+ if err := objIter .AddRoot (refSeen .OID ); err != nil {
117
53
return err
118
54
}
119
55
}
56
+ return nil
120
57
}()
121
58
}()
122
59
0 commit comments