Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
48 lines
982 B
Go
48 lines
982 B
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//go:build !gogit
|
|
|
|
package git
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gitea.dev/modules/log"
|
|
)
|
|
|
|
func (te *TreeEntry) GetSize(ctx context.Context, gitRepo *Repository) int64 {
|
|
if te.IsDir() {
|
|
return 0
|
|
} else if te.sized {
|
|
return te.size
|
|
}
|
|
|
|
batch, cancel, err := gitRepo.CatFileBatch()
|
|
if err != nil {
|
|
log.Debug("error whilst reading size for %s in %s. Error: %v", te.ID.String(), gitRepo.LogString(), err)
|
|
return 0
|
|
}
|
|
defer cancel()
|
|
info, err := batch.QueryInfo(te.ID.String())
|
|
if err != nil {
|
|
log.Debug("error whilst reading size for %s in %s. Error: %v", te.ID.String(), gitRepo.LogString(), err)
|
|
return 0
|
|
}
|
|
|
|
te.size = info.Size
|
|
te.sized = true
|
|
return te.size
|
|
}
|
|
|
|
// Blob returns the blob object the entry
|
|
func (te *TreeEntry) Blob(gitRepo *Repository) *Blob {
|
|
return &Blob{
|
|
ID: te.ID,
|
|
name: te.Name(),
|
|
size: te.size,
|
|
gotSize: te.sized,
|
|
repo: gitRepo,
|
|
}
|
|
}
|