Skip to content

Commit d6f138b

Browse files
committed
fine tune
1 parent 9db6749 commit d6f138b

File tree

10 files changed

+28
-22
lines changed

10 files changed

+28
-22
lines changed

modules/git/attribute/attribute.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
LinguistDetectable = "linguist-detectable"
1919
LinguistLanguage = "linguist-language"
2020
GitlabLanguage = "gitlab-language"
21+
Lockable = "lockable"
2122
)
2223

2324
var LinguistAttributes = []string{

modules/git/attribute/batch.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,23 @@ type BatchChecker struct {
2727
}
2828

2929
// NewBatchChecker creates a check attribute reader for the current repository and provided commit ID
30-
func NewBatchChecker(repo *git.Repository, treeish string, attributes ...string) (checker *BatchChecker, returnedErr error) {
30+
func NewBatchChecker(repo *git.Repository, treeish string, attributes []string) (checker *BatchChecker, returnedErr error) {
3131
ctx, cancel := context.WithCancel(repo.Ctx)
32+
defer func() {
33+
if returnedErr != nil {
34+
cancel()
35+
}
36+
}()
37+
3238
cmd, envs, cleanup, err := checkAttrCommand(repo, treeish, nil, attributes)
3339
if err != nil {
34-
cancel()
3540
return nil, err
3641
}
42+
defer func() {
43+
if returnedErr != nil {
44+
cleanup()
45+
}
46+
}()
3747

3848
cmd.AddArguments("--stdin")
3949

@@ -47,11 +57,6 @@ func NewBatchChecker(repo *git.Repository, treeish string, attributes ...string)
4757
cleanup()
4858
},
4959
}
50-
defer func() {
51-
if returnedErr != nil {
52-
checker.cancel()
53-
}
54-
}()
5560

5661
stdinReader, stdinWriter, err := os.Pipe()
5762
if err != nil {

modules/git/attribute/batch_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func Test_BatchChecker(t *testing.T) {
122122

123123
t.Run("Create index file to run git check-attr", func(t *testing.T) {
124124
defer test.MockVariableValue(&git.DefaultFeatures().SupportCheckAttrOnBare, false)()
125-
checker, err := NewBatchChecker(gitRepo, commitID, LinguistAttributes...)
125+
checker, err := NewBatchChecker(gitRepo, commitID, LinguistAttributes)
126126
assert.NoError(t, err)
127127
defer checker.Close()
128128
attributes, err := checker.CheckPath("i-am-a-python.p")
@@ -143,7 +143,7 @@ func Test_BatchChecker(t *testing.T) {
143143
assert.NoError(t, err)
144144
defer tempRepo.Close()
145145

146-
checker, err := NewBatchChecker(tempRepo, "", LinguistAttributes...)
146+
checker, err := NewBatchChecker(tempRepo, "", LinguistAttributes)
147147
assert.NoError(t, err)
148148
defer checker.Close()
149149
attributes, err := checker.CheckPath("i-am-a-python.p")
@@ -157,7 +157,7 @@ func Test_BatchChecker(t *testing.T) {
157157
}
158158

159159
t.Run("Run git check-attr in bare repository", func(t *testing.T) {
160-
checker, err := NewBatchChecker(gitRepo, commitID, LinguistAttributes...)
160+
checker, err := NewBatchChecker(gitRepo, commitID, LinguistAttributes)
161161
assert.NoError(t, err)
162162
defer checker.Close()
163163

modules/git/languagestats/language_stats_gogit.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func GetLanguageStats(repo *git_module.Repository, commitID string) (map[string]
4242
return nil, err
4343
}
4444

45-
checker, err := attribute.NewBatchChecker(repo, commitID)
45+
checker, err := attribute.NewBatchChecker(repo, commitID, attribute.LinguistAttributes)
4646
if err != nil {
4747
return nil, err
4848
}
@@ -69,27 +69,27 @@ func GetLanguageStats(repo *git_module.Repository, commitID string) (map[string]
6969

7070
attrs, err := checker.CheckPath(f.Name)
7171
if err == nil {
72-
isVendored = attrs.HasVendored()
72+
isVendored = attrs.GetVendored()
7373
if isVendored.ValueOrDefault(false) {
7474
return nil
7575
}
7676

77-
isGenerated = attrs.HasGenerated()
77+
isGenerated = attrs.GetGenerated()
7878
if isGenerated.ValueOrDefault(false) {
7979
return nil
8080
}
8181

82-
isDocumentation = attrs.HasDocumentation()
82+
isDocumentation = attrs.GetDocumentation()
8383
if isDocumentation.ValueOrDefault(false) {
8484
return nil
8585
}
8686

87-
isDetectable = attrs.HasDetectable()
87+
isDetectable = attrs.GetDetectable()
8888
if !isDetectable.ValueOrDefault(true) {
8989
return nil
9090
}
9191

92-
hasLanguage := attrs.Language()
92+
hasLanguage := attrs.GetLanguage()
9393
if hasLanguage.Value() != "" {
9494
language := hasLanguage.Value()
9595

modules/git/languagestats/language_stats_nogogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func GetLanguageStats(repo *git.Repository, commitID string) (map[string]int64,
6464
return nil, err
6565
}
6666

67-
checker, err := attribute.NewBatchChecker(repo, commitID, attribute.LinguistAttributes...)
67+
checker, err := attribute.NewBatchChecker(repo, commitID, attribute.LinguistAttributes)
6868
if err != nil {
6969
return nil, err
7070
}

routers/web/repo/setting/lfs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func LFSLocks(ctx *context.Context) {
135135
}
136136
defer gitRepo.Close()
137137

138-
checker, err := attribute.NewBatchChecker(gitRepo, ctx.Repo.Repository.DefaultBranch, "lockable")
138+
checker, err := attribute.NewBatchChecker(gitRepo, ctx.Repo.Repository.DefaultBranch, []string{attribute.Lockable})
139139
if err != nil {
140140
log.Error("Unable to check attributes in %s (%v)", tmpBasePath, err)
141141
ctx.ServerError("LFSLocks", err)

routers/web/repo/view_file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
285285
}
286286

287287
if ctx.Repo.GitRepo != nil {
288-
checker, err := attribute.NewBatchChecker(ctx.Repo.GitRepo, ctx.Repo.CommitID, attribute.LinguistGenerated, attribute.LinguistVendored)
288+
checker, err := attribute.NewBatchChecker(ctx.Repo.GitRepo, ctx.Repo.CommitID, []string{attribute.LinguistGenerated, attribute.LinguistVendored})
289289
if err != nil {
290290
ctx.ServerError("NewAttributeChecker", err)
291291
return

services/gitdiff/gitdiff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ func GetDiffForRender(ctx context.Context, gitRepo *git.Repository, opts *DiffOp
12381238
return nil, err
12391239
}
12401240

1241-
checker, err := attribute.NewBatchChecker(gitRepo, opts.AfterCommitID, attribute.LinguistVendored, attribute.LinguistGenerated, attribute.LinguistLanguage, attribute.GitlabLanguage)
1241+
checker, err := attribute.NewBatchChecker(gitRepo, opts.AfterCommitID, []string{attribute.LinguistVendored, attribute.LinguistGenerated, attribute.LinguistLanguage, attribute.GitlabLanguage})
12421242
if err != nil {
12431243
return nil, err
12441244
}

services/repository/files/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ func CreateOrUpdateFile(ctx context.Context, t *TemporaryUploadRepository, file
489489
var lfsMetaObject *git_model.LFSMetaObject
490490
if setting.LFS.StartServer && hasOldBranch {
491491
// Check there is no way this can return multiple infos
492-
attributesMap, err := attribute.CheckAttributes(ctx, t.gitRepo, "", attribute.CheckAttributeOpts{
492+
attributesMap, err := attribute.CheckAttributes(ctx, t.gitRepo, "" /* use temp repo's working dir */, attribute.CheckAttributeOpts{
493493
Attributes: []string{"filter"},
494494
Filenames: []string{file.Options.treePath},
495495
})

services/repository/files/upload.go

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

109109
var attributesMap map[string]attribute.Attributes
110110
if setting.LFS.StartServer {
111-
attributesMap, err = attribute.CheckAttributes(ctx, t.gitRepo, "", attribute.CheckAttributeOpts{
111+
attributesMap, err = attribute.CheckAttributes(ctx, t.gitRepo, "" /* use temp repo's working dir */, attribute.CheckAttributeOpts{
112112
Attributes: []string{"filter"},
113113
Filenames: names,
114114
})

0 commit comments

Comments
 (0)