Skip to content

Commit 90e10ea

Browse files
committed
Add option to use cached flag
1 parent c4e5c8b commit 90e10ea

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

modules/git/attribute/batch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func NewBatchChecker(repo *git.Repository, treeish string, attributes []string)
3636
}
3737
}()
3838

39-
cmd, envs, cleanup, err := checkAttrCommand(repo, treeish, nil, attributes)
39+
cmd, envs, cleanup, err := checkAttrCommand(repo, treeish, nil, attributes, false)
4040
if err != nil {
4141
return nil, err
4242
}

modules/git/attribute/checker.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"code.gitea.io/gitea/modules/git"
1414
)
1515

16-
func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attributes []string) (*git.Command, []string, func(), error) {
16+
func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attributes []string, cached bool) (*git.Command, []string, func(), error) {
1717
cancel := func() {}
1818
envs := []string{"GIT_FLUSH=1"}
1919
cmd := git.NewCommand("check-attr", "-z")
@@ -39,6 +39,8 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
3939
)
4040
cancel = deleteTemporaryFile
4141
}
42+
} else if cached {
43+
cmd.AddArguments("--cached")
4244
} // else: no treeish, assume it is a not a bare repo, read from working directory
4345

4446
cmd.AddDynamicArguments(attributes...)
@@ -51,12 +53,13 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
5153
type CheckAttributeOpts struct {
5254
Filenames []string
5355
Attributes []string
56+
Cached bool
5457
}
5558

5659
// CheckAttributes return the attributes of the given filenames and attributes in the given treeish.
5760
// If treeish is empty, then it will use current working directory, otherwise it will use the provided treeish on the bare repo
5861
func CheckAttributes(ctx context.Context, gitRepo *git.Repository, treeish string, opts CheckAttributeOpts) (map[string]*Attributes, error) {
59-
cmd, envs, cancel, err := checkAttrCommand(gitRepo, treeish, opts.Filenames, opts.Attributes)
62+
cmd, envs, cancel, err := checkAttrCommand(gitRepo, treeish, opts.Filenames, opts.Attributes, opts.Cached)
6063
if err != nil {
6164
return nil, err
6265
}

services/repository/files/update.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,11 @@ func CreateOrUpdateFile(ctx context.Context, t *TemporaryUploadRepository, file
492492
var lfsMetaObject *git_model.LFSMetaObject
493493
if setting.LFS.StartServer && hasOldBranch {
494494
// Check there is no way this can return multiple infos
495-
attributesMap, err := attribute.CheckAttributes(ctx, t.gitRepo, "HEAD", attribute.CheckAttributeOpts{
495+
attributesMap, err := attribute.CheckAttributes(ctx, t.gitRepo, "", attribute.CheckAttributeOpts{
496496
Attributes: []string{attribute.Filter},
497497
Filenames: []string{file.Options.treePath},
498+
// An index is set, so it's okay to list the attributes from it
499+
Cached: true,
498500
})
499501
if err != nil {
500502
return err

services/repository/files/upload.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
108108

109109
var attributesMap map[string]*attribute.Attributes
110110
if setting.LFS.StartServer && hasOldBranch {
111-
attributesMap, err = attribute.CheckAttributes(ctx, t.gitRepo, "HEAD", attribute.CheckAttributeOpts{
111+
attributesMap, err = attribute.CheckAttributes(ctx, t.gitRepo, "", attribute.CheckAttributeOpts{
112112
Attributes: []string{attribute.Filter},
113113
Filenames: names,
114+
// An index is set, so it's okay to list the attributes from it
115+
Cached: true,
114116
})
115117
if err != nil {
116118
return err

0 commit comments

Comments
 (0)