mirror of
https://github.com/gogs/gogs.git
synced 2025-12-21 07:39:59 +01:00
repo: able to view size (#1158)
This commit is contained in:
59
vendor/github.com/gogits/git-module/repo.go
generated
vendored
59
vendor/github.com/gogits/git-module/repo.go
generated
vendored
@@ -11,7 +11,10 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Unknwon/com"
|
||||
)
|
||||
|
||||
// Repository represents a Git repository.
|
||||
@@ -219,3 +222,59 @@ func MoveFile(repoPath, oldTreeName, newTreeName string) error {
|
||||
_, err := NewCommand("mv").AddArguments(oldTreeName, newTreeName).RunInDir(repoPath)
|
||||
return err
|
||||
}
|
||||
|
||||
// CountObject represents disk usage report of Git repository.
|
||||
type CountObject struct {
|
||||
Count int64
|
||||
Size int64
|
||||
InPack int64
|
||||
Packs int64
|
||||
SizePack int64
|
||||
PrunePackable int64
|
||||
Garbage int64
|
||||
SizeGarbage int64
|
||||
}
|
||||
|
||||
const (
|
||||
_STAT_COUNT = "count: "
|
||||
_STAT_SIZE = "size: "
|
||||
_STAT_IN_PACK = "in-pack: "
|
||||
_STAT_PACKS = "packs: "
|
||||
_STAT_SIZE_PACK = "size-pack: "
|
||||
_STAT_PRUNE_PACKABLE = "prune-packable: "
|
||||
_STAT_GARBAGE = "garbage: "
|
||||
_STAT_SIZE_GARBAGE = "size-garbage: "
|
||||
)
|
||||
|
||||
// GetRepoSize returns disk usage report of repository in given path.
|
||||
func GetRepoSize(repoPath string) (*CountObject, error) {
|
||||
cmd := NewCommand("count-objects", "-v")
|
||||
stdout, err := cmd.RunInDir(repoPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
countObject := new(CountObject)
|
||||
for _, line := range strings.Split(stdout, "\n") {
|
||||
switch {
|
||||
case strings.HasPrefix(line, _STAT_COUNT):
|
||||
countObject.Count = com.StrTo(line[7:]).MustInt64()
|
||||
case strings.HasPrefix(line, _STAT_SIZE):
|
||||
countObject.Size = com.StrTo(line[6:]).MustInt64() * 1024
|
||||
case strings.HasPrefix(line, _STAT_IN_PACK):
|
||||
countObject.InPack = com.StrTo(line[9:]).MustInt64() * 1024
|
||||
case strings.HasPrefix(line, _STAT_PACKS):
|
||||
countObject.Packs = com.StrTo(line[7:]).MustInt64()
|
||||
case strings.HasPrefix(line, _STAT_SIZE_PACK):
|
||||
countObject.SizePack = com.StrTo(line[11:]).MustInt64() * 1024
|
||||
case strings.HasPrefix(line, _STAT_PRUNE_PACKABLE):
|
||||
countObject.PrunePackable = com.StrTo(line[16:]).MustInt64()
|
||||
case strings.HasPrefix(line, _STAT_GARBAGE):
|
||||
countObject.Garbage = com.StrTo(line[9:]).MustInt64()
|
||||
case strings.HasPrefix(line, _STAT_SIZE_GARBAGE):
|
||||
countObject.SizeGarbage = com.StrTo(line[14:]).MustInt64() * 1024
|
||||
}
|
||||
}
|
||||
|
||||
return countObject, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user