Skip to content

Commit 25b2390

Browse files
author
Scott Arbeit
committed
Added compressed size and updated a few labels.
1 parent 5bbde89 commit 25b2390

6 files changed

Lines changed: 73 additions & 16 deletions

File tree

Makefile.win

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,32 @@ GO111MODULES := 1
55

66
# Use the project's go wrapper script via the -File parameter to avoid loading your profile
77
GOSCRIPT := $(CURDIR)/script/go.ps1
8-
# GOSCRIPTCORRECTED := $(shell pwsh.exe -NoProfile -ExecutionPolicy Bypass -Command "$(GOSCRIPT) -replace '/', '\'")
98
GO := pwsh.exe -NoProfile -ExecutionPolicy Bypass -File $(GOSCRIPT)
109

1110
# Get the build version from git using try/catch instead of "||"
12-
BUILD_VERSION := $(shell pwsh.exe -NoProfile -ExecutionPolicy Bypass -Command "try { git describe --tags --always --dirty 2>$null } catch { Write-Output 'unknown' }")
11+
BUILD_VERSION := $(shell pwsh.exe -NoProfile -ExecutionPolicy Bypass -Command "try { git describe --tags --always --dirty 2>$$null } catch { Write-Output 'unknown' }")
1312
LDFLAGS := -X github.com/github/git-sizer/main.BuildVersion=$(BUILD_VERSION)
1413
GOFLAGS := -mod=readonly
1514

1615
ifdef USE_ISATTY
1716
GOFLAGS := $(GOFLAGS) --tags isatty
1817
endif
1918

19+
# Find all Go source files
20+
GO_SRC_FILES := $(shell powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem -Path . -Filter *.go -Recurse | Select-Object -ExpandProperty FullName")
21+
2022
# Default target
2123
all: bin/git-sizer.exe
2224

23-
# Main binary target
24-
bin/git-sizer.exe:
25+
# Main binary target - depend on all Go source files
26+
bin/git-sizer.exe: $(GO_SRC_FILES)
2527
@powershell -NoProfile -ExecutionPolicy Bypass -Command "if (-not (Test-Path bin)) { New-Item -ItemType Directory -Path bin | Out-Null }"
26-
$(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o .\bin\git-sizer.exe .
28+
$(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -a -o .\bin\git-sizer.exe .
2729

28-
# Test target
29-
test: bin/git-sizer.exe gotest
30+
# Test target - explicitly run the build first to ensure binary is up to date
31+
test:
32+
@$(MAKE) -f Makefile.win bin/git-sizer.exe
33+
@$(MAKE) -f Makefile.win gotest
3034

3135
# Run go tests
3236
gotest:
@@ -48,4 +52,3 @@ help:
4852
@powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host 'Example usage:' -ForegroundColor Green"
4953
@powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' nmake -f Makefile.win'"
5054
@powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-Host ' nmake -f Makefile.win test'"
51-

git-sizer.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,19 @@ func mainImplementation(ctx context.Context, stdout, stderr io.Writer, args []st
331331
return fmt.Errorf("error scanning repository: %w", err)
332332
}
333333

334+
// Calculate the actual size of the .git directory
335+
gitDir, err := repo.GitDir()
336+
if err != nil {
337+
return fmt.Errorf("error getting Git directory path: %w", err)
338+
}
339+
340+
gitDirSize, err := sizes.CalculateGitDirSize(gitDir)
341+
if err != nil {
342+
return fmt.Errorf("error calculating Git directory size: %w", err)
343+
}
344+
345+
historySize.GitDirSize = gitDirSize
346+
334347
if jsonOutput {
335348
var j []byte
336349
var err error

git/git.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,11 @@ func (repo *Repository) GitCommand(callerArgs ...string) *exec.Cmd {
150150

151151
// GitDir returns the path to `repo`'s `GIT_DIR`. It might be absolute
152152
// or it might be relative to the current directory.
153-
func (repo *Repository) GitDir() string {
154-
return repo.gitDir
153+
func (repo *Repository) GitDir() (string, error) {
154+
if repo.gitDir == "" {
155+
return "", errors.New("gitDir is not set")
156+
}
157+
return repo.gitDir, nil
155158
}
156159

157160
// GitPath returns that path of a file within the git repository, by

sizes/dirsize.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package sizes
2+
3+
import (
4+
"os"
5+
"path/filepath"
6+
7+
"github.com/github/git-sizer/counts"
8+
)
9+
10+
// CalculateGitDirSize returns the total size in bytes of the .git directory
11+
func CalculateGitDirSize(gitDir string) (counts.Count64, error) {
12+
var totalSize counts.Count64
13+
14+
err := filepath.Walk(gitDir, func(path string, info os.FileInfo, err error) error {
15+
if err != nil {
16+
// Skip files we can't access
17+
return nil
18+
}
19+
20+
// Only count files, not directories
21+
if !info.IsDir() {
22+
totalSize.Increment(counts.Count64(info.Size()))
23+
}
24+
return nil
25+
})
26+
27+
return totalSize, err
28+
}

sizes/output.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,10 @@ func (t *Threshold) Type() string {
279279
// A `pflag.Value` that can be used as a boolean option that sets a
280280
// `Threshold` variable to a fixed value. For example,
281281
//
282-
// pflag.Var(
283-
// sizes.NewThresholdFlagValue(&threshold, 30),
284-
// "critical", "only report critical statistics",
285-
// )
282+
// pflag.Var(
283+
// sizes.NewThresholdFlagValue(&threshold, 30),
284+
// "critical", "only report critical statistics",
285+
// )
286286
//
287287
// adds a `--critical` flag that sets `threshold` to 30.
288288
type thresholdFlagValue struct {
@@ -492,7 +492,7 @@ func (s *HistorySize) contents(refGroups []RefGroup) tableContents {
492492
return S(
493493
"",
494494
S(
495-
"Overall repository size",
495+
"Repository statistics",
496496
S(
497497
"Commits",
498498
I("uniqueCommitCount", "Count",
@@ -521,11 +521,18 @@ func (s *HistorySize) contents(refGroups []RefGroup) tableContents {
521521
I("uniqueBlobCount", "Count",
522522
"The total number of distinct blob objects",
523523
nil, s.UniqueBlobCount, metric, "", 1.5e6),
524-
I("uniqueBlobSize", "Total size",
524+
I("uniqueBlobSize", "Uncompressed total size",
525525
"The total size of all distinct blob objects",
526526
nil, s.UniqueBlobSize, binary, "B", 10e9),
527527
),
528528

529+
S(
530+
"On-disk size",
531+
I("gitDirSize", "Compressed total size",
532+
"The actual on-disk size of the .git directory",
533+
nil, s.GitDirSize, binary, "B", 1e9),
534+
),
535+
529536
S(
530537
"Annotated tags",
531538
I("uniqueTagCount", "Count",

sizes/sizes.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ type HistorySize struct {
210210

211211
// The tree with the maximum expanded submodule count.
212212
MaxExpandedSubmoduleCountTree *Path `json:"max_expanded_submodule_count_tree,omitempty"`
213+
214+
// The actual size of the .git directory on disk
215+
GitDirSize counts.Count64 `json:"git_dir_size"`
213216
}
214217

215218
// Convenience function: forget `*path` if it is non-nil and overwrite

0 commit comments

Comments
 (0)