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:
parent
81a4fc7528
commit
3c4724d70e
13 changed files with 223 additions and 97 deletions
|
@ -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())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue