mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Add .gitattribute assisted language detection to blame, diff and render (#17590)
Use check attribute code to check the assigned language of a file and send that in to chroma as a hint for the language of the file. Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
		| @@ -22,6 +22,8 @@ type CheckAttributeOpts struct { | ||||
| 	AllAttributes bool | ||||
| 	Attributes    []string | ||||
| 	Filenames     []string | ||||
| 	IndexFile     string | ||||
| 	WorkTree      string | ||||
| } | ||||
|  | ||||
| // CheckAttribute return the Blame object of file | ||||
| @@ -31,6 +33,19 @@ func (repo *Repository) CheckAttribute(opts CheckAttributeOpts) (map[string]map[ | ||||
| 		return nil, fmt.Errorf("git version missing: %v", err) | ||||
| 	} | ||||
|  | ||||
| 	env := []string{} | ||||
|  | ||||
| 	if len(opts.IndexFile) > 0 && CheckGitVersionAtLeast("1.7.8") == nil { | ||||
| 		env = append(env, "GIT_INDEX_FILE="+opts.IndexFile) | ||||
| 	} | ||||
| 	if len(opts.WorkTree) > 0 && CheckGitVersionAtLeast("1.7.8") == nil { | ||||
| 		env = append(env, "GIT_WORK_TREE="+opts.WorkTree) | ||||
| 	} | ||||
|  | ||||
| 	if len(env) > 0 { | ||||
| 		env = append(os.Environ(), env...) | ||||
| 	} | ||||
|  | ||||
| 	stdOut := new(bytes.Buffer) | ||||
| 	stdErr := new(bytes.Buffer) | ||||
|  | ||||
| @@ -61,7 +76,7 @@ func (repo *Repository) CheckAttribute(opts CheckAttributeOpts) (map[string]map[ | ||||
|  | ||||
| 	cmd := NewCommand(cmdArgs...) | ||||
|  | ||||
| 	if err := cmd.RunInDirPipeline(repo.Path, stdOut, stdErr); err != nil { | ||||
| 	if err := cmd.RunInDirTimeoutEnvPipeline(env, -1, repo.Path, stdOut, stdErr); err != nil { | ||||
| 		return nil, fmt.Errorf("failed to run check-attr: %v\n%s\n%s", err, stdOut.String(), stdErr.String()) | ||||
| 	} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user