-
Notifications
You must be signed in to change notification settings - Fork 158
Don't search/list every single repo reference when explicit references are provided #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
9d71973
721e353
0315cba
d407c86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,3 +140,8 @@ type regexpFilter struct { | |
func (f regexpFilter) Filter(refname string) bool { | ||
return f.re.MatchString(refname) | ||
} | ||
|
||
func IsNoReferencesFilter(val interface{}) bool { | ||
_, ok := val.(noReferencesFilter) | ||
return ok | ||
} | ||
Comment on lines
+143
to
+147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,10 @@ type refGroup struct { | |
otherRefGroup *sizes.RefGroup | ||
} | ||
|
||
func (rg *refGroup) GetFilter() git.ReferenceFilter { | ||
return rg.filter | ||
} | ||
|
||
Comment on lines
+33
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
func (rg *refGroup) collectSymbols(refname string) (bool, []sizes.RefGroupSymbol) { | ||
walk := false | ||
var symbols []sizes.RefGroupSymbol | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,10 @@ type RefGroupBuilder struct { | |
groups map[sizes.RefGroupSymbol]*refGroup | ||
} | ||
|
||
func (rgb *RefGroupBuilder) GetTopLevelGroup() *refGroup { | ||
return rgb.topLevelGroup | ||
} | ||
|
||
Comment on lines
+25
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
// NewRefGroupBuilder creates and returns a `RefGroupBuilder` | ||
// instance. | ||
func NewRefGroupBuilder(configger Configger) (*RefGroupBuilder, error) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,19 @@ func (s TagSize) String() string { | |
return fmt.Sprintf("tag_depth=%d", s.TagDepth) | ||
} | ||
|
||
func (s *HistorySize) JsonV1Format(opts *FormatOptions) *HistorySize { | ||
if opts == nil { | ||
return s | ||
} | ||
|
||
if opts.WithoutReferenceCount { | ||
s.ReferenceCount = 0 | ||
s.ReferenceGroups = nil | ||
} | ||
|
||
return s | ||
} | ||
|
||
func (s *HistorySize) String() string { | ||
return fmt.Sprintf( | ||
"unique_commit_count=%d, unique_commit_count = %d, max_commit_size = %d, "+ | ||
|
@@ -86,22 +99,22 @@ type section struct { | |
contents []tableContents | ||
} | ||
|
||
func newSection(name string, contents ...tableContents) *section { | ||
return §ion{ | ||
func newSection(name string, contents ...tableContents) section { | ||
return section{ | ||
name: name, | ||
contents: contents, | ||
} | ||
} | ||
|
||
func (s *section) Emit(t *table) { | ||
func (s section) Emit(t *table) { | ||
for _, c := range s.contents { | ||
subTable := t.subTable(s.name) | ||
c.Emit(subTable) | ||
t.addSection(subTable) | ||
} | ||
} | ||
|
||
func (s *section) CollectItems(items map[string]*item) { | ||
func (s section) CollectItems(items map[string]*item) { | ||
for _, c := range s.contents { | ||
c.CollectItems(items) | ||
} | ||
|
@@ -141,7 +154,7 @@ func newItem( | |
} | ||
} | ||
|
||
func (i *item) Emit(t *table) { | ||
func (i item) Emit(t *table) { | ||
levelOfConcern, interesting := i.levelOfConcern(t.threshold) | ||
if !interesting { | ||
return | ||
|
@@ -154,7 +167,7 @@ func (i *item) Emit(t *table) { | |
) | ||
} | ||
|
||
func (i *item) Footnote(nameStyle NameStyle) string { | ||
func (i item) Footnote(nameStyle NameStyle) string { | ||
if i.path == nil || i.path.OID == git.NullOID { | ||
return "" | ||
} | ||
|
@@ -173,7 +186,7 @@ func (i *item) Footnote(nameStyle NameStyle) string { | |
// If this item's alert level is at least as high as the threshold, | ||
// return the string that should be used as its "level of concern" and | ||
// `true`; otherwise, return `"", false`. | ||
func (i *item) levelOfConcern(threshold Threshold) (string, bool) { | ||
func (i item) levelOfConcern(threshold Threshold) (string, bool) { | ||
value, overflow := i.value.ToUint64() | ||
if overflow { | ||
return "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", true | ||
|
@@ -188,11 +201,11 @@ func (i *item) levelOfConcern(threshold Threshold) (string, bool) { | |
return stars[:int(alert)], true | ||
} | ||
|
||
func (i *item) CollectItems(items map[string]*item) { | ||
items[i.symbol] = i | ||
func (i item) CollectItems(items map[string]*item) { | ||
items[i.symbol] = &i | ||
} | ||
|
||
func (i *item) MarshalJSON() ([]byte, error) { | ||
func (i item) MarshalJSON() ([]byte, error) { | ||
// How we want to emit an item as JSON. | ||
value, _ := i.value.ToUint64() | ||
|
||
|
@@ -224,7 +237,7 @@ func (i *item) MarshalJSON() ([]byte, error) { | |
|
||
// Indented returns an `item` that is just like `i`, but indented by | ||
// `depth` more levels. | ||
func (i *item) Indented(depth int) tableContents { | ||
func (i item) Indented(depth int) tableContents { | ||
return &indentedItem{ | ||
tableContents: i, | ||
depth: depth, | ||
|
@@ -236,7 +249,7 @@ type indentedItem struct { | |
depth int | ||
} | ||
|
||
func (i *indentedItem) Emit(t *table) { | ||
func (i indentedItem) Emit(t *table) { | ||
subTable := t.indented("", i.depth) | ||
i.tableContents.Emit(subTable) | ||
t.addSection(subTable) | ||
|
@@ -373,8 +386,9 @@ type table struct { | |
|
||
func (s *HistorySize) TableString( | ||
refGroups []RefGroup, threshold Threshold, nameStyle NameStyle, | ||
opts FormatOptions, | ||
) string { | ||
contents := s.contents(refGroups) | ||
contents := s.contents(refGroups, opts) | ||
t := table{ | ||
threshold: threshold, | ||
nameStyle: nameStyle, | ||
|
@@ -454,17 +468,20 @@ func (t *table) formatRow( | |
) | ||
} | ||
|
||
type FormatOptions struct { | ||
WithoutReferenceCount bool | ||
} | ||
|
||
func (s *HistorySize) JSON( | ||
refGroups []RefGroup, threshold Threshold, nameStyle NameStyle, | ||
) ([]byte, error) { | ||
contents := s.contents(refGroups) | ||
refGroups []RefGroup, threshold Threshold, nameStyle NameStyle, opts FormatOptions) ([]byte, error) { | ||
contents := s.contents(refGroups, opts) | ||
items := make(map[string]*item) | ||
contents.CollectItems(items) | ||
j, err := json.MarshalIndent(items, "", " ") | ||
return j, err | ||
} | ||
|
||
func (s *HistorySize) contents(refGroups []RefGroup) tableContents { | ||
func (s *HistorySize) contents(refGroups []RefGroup, opts FormatOptions) tableContents { | ||
S := newSection | ||
I := newItem | ||
metric := counts.Metric | ||
|
@@ -489,6 +506,20 @@ func (s *HistorySize) contents(refGroups []RefGroup) tableContents { | |
rgis = append(rgis, rgi.Indented(indent)) | ||
} | ||
|
||
var refCountSection section | ||
if !opts.WithoutReferenceCount { | ||
refCountSection = S( | ||
"References", | ||
I("referenceCount", "Count", | ||
"The total number of references", | ||
nil, s.ReferenceCount, metric, "", 25e3), | ||
S( | ||
"", | ||
rgis..., | ||
), | ||
) | ||
} | ||
|
||
Comment on lines
+509
to
+522
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This approach seems to depend on the fact that even though the uninitialized |
||
return S( | ||
"", | ||
S( | ||
|
@@ -533,16 +564,7 @@ func (s *HistorySize) contents(refGroups []RefGroup) tableContents { | |
nil, s.UniqueTagCount, metric, "", 25e3), | ||
), | ||
|
||
S( | ||
"References", | ||
I("referenceCount", "Count", | ||
"The total number of references", | ||
nil, s.ReferenceCount, metric, "", 25e3), | ||
S( | ||
"", | ||
rgis..., | ||
), | ||
), | ||
refCountSection, | ||
), | ||
|
||
S("Biggest objects", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of revealing internal details via both
RefGroupBuilder.GetTopLevelGroup()
andrefGroup.GetFilter()
plus needing the strange functionIsNoReferencesFilter()
, how about adding a special-purpose method toRefGroupBuilder
, something like the following:git.NoReferencesFilter
is a singleton, so I think that a simple comparison like this should suffice.