aboutsummaryrefslogtreecommitdiffstats
path: root/modules/repofiles
diff options
context:
space:
mode:
authora1012112796 <1012112796@qq.com>2021-03-01 20:14:17 +0800
committerGitHub <noreply@github.com>2021-03-01 14:14:17 +0200
commit6cf97df9fd6aba59104dba41a2eabd64542f68b9 (patch)
treeb372ec58b6315df4e26a01b2d09acc2f6ca52d13 /modules/repofiles
parentfaf775c552ae18a9ca55050fedf86908d09dd3f6 (diff)
downloadgitea-6cf97df9fd6aba59104dba41a2eabd64542f68b9.tar.gz
gitea-6cf97df9fd6aba59104dba41a2eabd64542f68b9.zip
remove duplicate define of CheckAttribute() (#14837)
Signed-off-by: a1012112796 <1012112796@qq.com>
Diffstat (limited to 'modules/repofiles')
-rw-r--r--modules/repofiles/temp_repo.go55
-rw-r--r--modules/repofiles/update.go5
-rw-r--r--modules/repofiles/upload.go6
3 files changed, 9 insertions, 57 deletions
diff --git a/modules/repofiles/temp_repo.go b/modules/repofiles/temp_repo.go
index 99c62a16c6..820f5f2542 100644
--- a/modules/repofiles/temp_repo.go
+++ b/modules/repofiles/temp_repo.go
@@ -328,61 +328,6 @@ func (t *TemporaryUploadRepository) DiffIndex() (*gitdiff.Diff, error) {
return diff, nil
}
-// CheckAttribute checks the given attribute of the provided files
-func (t *TemporaryUploadRepository) CheckAttribute(attribute string, args ...string) (map[string]map[string]string, error) {
- err := git.LoadGitVersion()
- if err != nil {
- log.Error("Error retrieving git version: %v", err)
- return nil, err
- }
-
- stdout := new(bytes.Buffer)
- stderr := new(bytes.Buffer)
-
- cmdArgs := []string{"check-attr", "-z", attribute}
-
- // git check-attr --cached first appears in git 1.7.8
- if git.CheckGitVersionAtLeast("1.7.8") == nil {
- cmdArgs = append(cmdArgs, "--cached")
- }
- cmdArgs = append(cmdArgs, "--")
-
- for _, arg := range args {
- if arg != "" {
- cmdArgs = append(cmdArgs, arg)
- }
- }
-
- if err := git.NewCommand(cmdArgs...).RunInDirPipeline(t.basePath, stdout, stderr); err != nil {
- log.Error("Unable to check-attr in temporary repo: %s (%s) Error: %v\nStdout: %s\nStderr: %s",
- t.repo.FullName(), t.basePath, err, stdout, stderr)
- return nil, fmt.Errorf("Unable to check-attr in temporary repo: %s Error: %v\nStdout: %s\nStderr: %s",
- t.repo.FullName(), err, stdout, stderr)
- }
-
- fields := bytes.Split(stdout.Bytes(), []byte{'\000'})
-
- if len(fields)%3 != 1 {
- return nil, fmt.Errorf("Wrong number of fields in return from check-attr")
- }
-
- var name2attribute2info = make(map[string]map[string]string)
-
- for i := 0; i < (len(fields) / 3); i++ {
- filename := string(fields[3*i])
- attribute := string(fields[3*i+1])
- info := string(fields[3*i+2])
- attribute2info := name2attribute2info[filename]
- if attribute2info == nil {
- attribute2info = make(map[string]string)
- }
- attribute2info[attribute] = info
- name2attribute2info[filename] = attribute2info
- }
-
- return name2attribute2info, err
-}
-
// GetBranchCommit Gets the commit object of the given branch
func (t *TemporaryUploadRepository) GetBranchCommit(branch string) (*git.Commit, error) {
if t.gitRepo == nil {
diff --git a/modules/repofiles/update.go b/modules/repofiles/update.go
index 0ee1ada34c..d25e109b29 100644
--- a/modules/repofiles/update.go
+++ b/modules/repofiles/update.go
@@ -377,7 +377,10 @@ func CreateOrUpdateRepoFile(repo *models.Repository, doer *models.User, opts *Up
if setting.LFS.StartServer {
// Check there is no way this can return multiple infos
- filename2attribute2info, err := t.CheckAttribute("filter", treePath)
+ filename2attribute2info, err := t.gitRepo.CheckAttribute(git.CheckAttributeOpts{
+ Attributes: []string{"filter"},
+ Filenames: []string{treePath},
+ })
if err != nil {
return nil, err
}
diff --git a/modules/repofiles/upload.go b/modules/repofiles/upload.go
index c261e188c1..2846e6c44b 100644
--- a/modules/repofiles/upload.go
+++ b/modules/repofiles/upload.go
@@ -11,6 +11,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
@@ -88,7 +89,10 @@ func UploadRepoFiles(repo *models.Repository, doer *models.User, opts *UploadRep
var filename2attribute2info map[string]map[string]string
if setting.LFS.StartServer {
- filename2attribute2info, err = t.CheckAttribute("filter", names...)
+ filename2attribute2info, err = t.gitRepo.CheckAttribute(git.CheckAttributeOpts{
+ Attributes: []string{"filter"},
+ Filenames: names,
+ })
if err != nil {
return err
}