|
|
@ -11,7 +11,10 @@ import ( |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
"path/filepath" |
|
|
|
"path/filepath" |
|
|
|
|
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/Unknwon/com" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Repository represents a Git repository.
|
|
|
|
// Repository represents a Git repository.
|
|
|
@ -198,3 +201,63 @@ func MoveFile(repoPath, oldTreeName, newTreeName string) error { |
|
|
|
_, err := NewCommand("mv").AddArguments(oldTreeName, newTreeName).RunInDir(repoPath) |
|
|
|
_, err := NewCommand("mv").AddArguments(oldTreeName, newTreeName).RunInDir(repoPath) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CountObject represents repository count objects report
|
|
|
|
|
|
|
|
type CountObject struct { |
|
|
|
|
|
|
|
Count int64 |
|
|
|
|
|
|
|
Size int64 |
|
|
|
|
|
|
|
InPack int64 |
|
|
|
|
|
|
|
Packs int64 |
|
|
|
|
|
|
|
SizePack int64 |
|
|
|
|
|
|
|
PrunePack int64 |
|
|
|
|
|
|
|
Garbage int64 |
|
|
|
|
|
|
|
SizeGarbage int64 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
|
|
|
statCount = "count: " |
|
|
|
|
|
|
|
statSize = "size: " |
|
|
|
|
|
|
|
statInpack = "in-pack: " |
|
|
|
|
|
|
|
statPacks = "packs: " |
|
|
|
|
|
|
|
statSizePack = "size-pack: " |
|
|
|
|
|
|
|
statPrunePackage = "prune-package: " |
|
|
|
|
|
|
|
statGarbage = "garbage: " |
|
|
|
|
|
|
|
statSizeGarbage = "size-garbage: " |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetRepoSize returns disk consumption for repo in path
|
|
|
|
|
|
|
|
func GetRepoSize(repoPath string) (*CountObject, error) { |
|
|
|
|
|
|
|
cmd := NewCommand("count-objects", "-v") |
|
|
|
|
|
|
|
stdout, err := cmd.RunInDir(repoPath) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return parseSize(stdout), nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// parseSize parses the output from count-objects and return a CountObject
|
|
|
|
|
|
|
|
func parseSize(objects string) *CountObject { |
|
|
|
|
|
|
|
repoSize := new(CountObject) |
|
|
|
|
|
|
|
for _, line := range strings.Split(objects, "\n") { |
|
|
|
|
|
|
|
switch { |
|
|
|
|
|
|
|
case strings.HasPrefix(line, statCount): |
|
|
|
|
|
|
|
repoSize.Count = com.StrTo(line[7:]).MustInt64() |
|
|
|
|
|
|
|
case strings.HasPrefix(line, statSize): |
|
|
|
|
|
|
|
repoSize.Size = com.StrTo(line[6:]).MustInt64() * 1024 |
|
|
|
|
|
|
|
case strings.HasPrefix(line, statInpack): |
|
|
|
|
|
|
|
repoSize.InPack = com.StrTo(line[9:]).MustInt64() |
|
|
|
|
|
|
|
case strings.HasPrefix(line, statPacks): |
|
|
|
|
|
|
|
repoSize.Packs = com.StrTo(line[7:]).MustInt64() |
|
|
|
|
|
|
|
case strings.HasPrefix(line, statSizePack): |
|
|
|
|
|
|
|
repoSize.SizePack = com.StrTo(line[11:]).MustInt64() * 1024 |
|
|
|
|
|
|
|
case strings.HasPrefix(line, statPrunePackage): |
|
|
|
|
|
|
|
repoSize.PrunePack = com.StrTo(line[16:]).MustInt64() |
|
|
|
|
|
|
|
case strings.HasPrefix(line, statGarbage): |
|
|
|
|
|
|
|
repoSize.Garbage = com.StrTo(line[9:]).MustInt64() |
|
|
|
|
|
|
|
case strings.HasPrefix(line, statSizeGarbage): |
|
|
|
|
|
|
|
repoSize.SizeGarbage = com.StrTo(line[14:]).MustInt64() * 1024 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return repoSize |
|
|
|
|
|
|
|
} |
|
|
|