Skip to content

Commit d407c86

Browse files
committed
Don't print reference count for json v1
The reference count is still displayed when the -j flag is passed to git-sizer. ``` git-sizer master~50^{tree} 'HEAD@{1.week.ago}' -v -j [TRUNCATED_OUTPUT] "reference_count": 15, "reference_groups": { "ignored": 15 }, [TRUNCATED_OUTPUT] ``` We don't want to print the reference count for json v1, when explicit root are not provided git-sizer
1 parent 0315cba commit d407c86

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

git-sizer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ func mainImplementation(ctx context.Context, stdout, stderr io.Writer, args []st
352352
var err error
353353
switch jsonVersion {
354354
case 1:
355-
j, err = json.MarshalIndent(historySize, "", " ")
355+
j, err = json.MarshalIndent(historySize.JsonV1Format(&formatOptions), "", " ")
356356
case 2:
357357
j, err = historySize.JSON(rg.Groups(), threshold, nameStyle, formatOptions)
358358
default:

sizes/output.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ func (s TagSize) String() string {
4141
return fmt.Sprintf("tag_depth=%d", s.TagDepth)
4242
}
4343

44+
func (s *HistorySize) JsonV1Format(opts *FormatOptions) *HistorySize {
45+
if opts == nil {
46+
return s
47+
}
48+
49+
if opts.WithoutReferenceCount {
50+
s.ReferenceCount = 0
51+
s.ReferenceGroups = nil
52+
}
53+
54+
return s
55+
}
56+
4457
func (s *HistorySize) String() string {
4558
return fmt.Sprintf(
4659
"unique_commit_count=%d, unique_commit_count = %d, max_commit_size = %d, "+

sizes/sizes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ type HistorySize struct {
158158
// The number of references analyzed. Note that we don't eliminate
159159
// duplicates if the user passes the same reference more than
160160
// once.
161-
ReferenceCount counts.Count32 `json:"reference_count"`
161+
ReferenceCount counts.Count32 `json:"reference_count,omitempty"`
162162

163163
// ReferenceGroups keeps track of how many references in each
164164
// reference group were scanned.
165-
ReferenceGroups map[RefGroupSymbol]*counts.Count32 `json:"reference_groups"`
165+
ReferenceGroups map[RefGroupSymbol]*counts.Count32 `json:"reference_groups,omitempty"`
166166

167167
// The maximum TreeSize in the analyzed history (where each
168168
// attribute is maximized separately).

0 commit comments

Comments
 (0)