summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authoroliverpool <git@olivier.pfad.fr>2024-03-24 12:44:30 +0100
committeroliverpool <git@olivier.pfad.fr>2024-03-28 10:52:51 +0100
commit3c81f7478c491e284c72b07a14975dd14d0af1f8 (patch)
tree6fa991212553ac7acb31e55a249d8fb55965b961 /routers
parentMerge pull request 'Update module github.com/klauspost/compress to v1.17.7' (... (diff)
downloadforgejo-3c81f7478c491e284c72b07a14975dd14d0af1f8.tar.xz
forgejo-3c81f7478c491e284c72b07a14975dd14d0af1f8.zip
[PERFORMANCE] git check-attr on bare repo if supported
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/setting/lfs.go39
-rw-r--r--routers/web/repo/view.go17
2 files changed, 26 insertions, 30 deletions
diff --git a/routers/web/repo/setting/lfs.go b/routers/web/repo/setting/lfs.go
index 9b66af37b2..c18cb6a8c8 100644
--- a/routers/web/repo/setting/lfs.go
+++ b/routers/web/repo/setting/lfs.go
@@ -145,30 +145,13 @@ func LFSLocks(ctx *context.Context) {
return
}
- name2attribute2info, err := gitRepo.CheckAttribute(git.CheckAttributeOpts{
- Attributes: []string{"lockable"},
- Filenames: filenames,
- CachedOnly: true,
- })
+ ctx.Data["Lockables"], err = lockablesGitAttributes(gitRepo, lfsLocks)
if err != nil {
- log.Error("Unable to check attributes in %s (%v)", tmpBasePath, err)
+ log.Error("Unable to get lockablesGitAttributes in %s (%v)", tmpBasePath, err)
ctx.ServerError("LFSLocks", err)
return
}
- lockables := make([]bool, len(lfsLocks))
- for i, lock := range lfsLocks {
- attribute2info, has := name2attribute2info[lock.Path]
- if !has {
- continue
- }
- if attribute2info["lockable"] != "set" {
- continue
- }
- lockables[i] = true
- }
- ctx.Data["Lockables"] = lockables
-
filelist, err := gitRepo.LsFiles(filenames...)
if err != nil {
log.Error("Unable to lsfiles in %s (%v)", tmpBasePath, err)
@@ -189,6 +172,24 @@ func LFSLocks(ctx *context.Context) {
ctx.HTML(http.StatusOK, tplSettingsLFSLocks)
}
+func lockablesGitAttributes(gitRepo *git.Repository, lfsLocks []*git_model.LFSLock) ([]bool, error) {
+ checker, err := gitRepo.GitAttributeChecker("", "lockable")
+ if err != nil {
+ return nil, fmt.Errorf("could not GitAttributeChecker: %w", err)
+ }
+ defer checker.Close()
+
+ lockables := make([]bool, len(lfsLocks))
+ for i, lock := range lfsLocks {
+ attrs, err := checker.CheckPath(lock.Path)
+ if err != nil {
+ return nil, fmt.Errorf("could not CheckPath(%s): %w", lock.Path, err)
+ }
+ lockables[i] = attrs["lockable"].Bool().Value()
+ }
+ return lockables, nil
+}
+
// LFSLockFile locks a file
func LFSLockFile(ctx *context.Context) {
if !setting.LFS.StartServer {
diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go
index e4d7179f63..becb8748cd 100644
--- a/routers/web/repo/view.go
+++ b/routers/web/repo/view.go
@@ -643,17 +643,12 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry) {
}
if ctx.Repo.GitRepo != nil {
- checker, deferable := ctx.Repo.GitRepo.CheckAttributeReader(ctx.Repo.CommitID)
- if checker != nil {
- defer deferable()
- attrs, err := checker.CheckPath(ctx.Repo.TreePath)
- if err == nil {
- vendored, has := attrs["linguist-vendored"]
- ctx.Data["IsVendored"] = has && (vendored == "set" || vendored == "true")
-
- generated, has := attrs["linguist-generated"]
- ctx.Data["IsGenerated"] = has && (generated == "set" || generated == "true")
- }
+ attrs, err := ctx.Repo.GitRepo.GitAttributes(ctx.Repo.CommitID, ctx.Repo.TreePath, "linguist-vendored", "linguist-generated")
+ if err != nil {
+ log.Error("GitAttributes(%s, %s) failed: %v", ctx.Repo.CommitID, ctx.Repo.TreePath, err)
+ } else {
+ ctx.Data["IsVendored"] = attrs["linguist-vendored"].Bool().Value()
+ ctx.Data["IsGenerated"] = attrs["linguist-generated"].Bool().Value()
}
}