remove duplicate define of CheckAttribute() (#14837)
Signed-off-by: a1012112796 <1012112796@qq.com>
This commit is contained in:
		
							parent
							
								
									faf775c552
								
							
						
					
					
						commit
						6cf97df9fd
					
				
					 3 changed files with 9 additions and 57 deletions
				
			
		|  | @ -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 { | ||||
|  |  | |||
|  | @ -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 | ||||
| 		} | ||||
|  |  | |||
|  | @ -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 | ||||
| 		} | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue