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:
		| @@ -8,6 +8,7 @@ import ( | ||||
| 	"bytes" | ||||
| 	"context" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"strings" | ||||
|  | ||||
| 	"code.gitea.io/gitea/modules/log" | ||||
| @@ -45,14 +46,15 @@ func (repo *Repository) readTreeToIndex(id SHA1, indexFilename ...string) error | ||||
| } | ||||
|  | ||||
| // ReadTreeToTemporaryIndex reads a treeish to a temporary index file | ||||
| func (repo *Repository) ReadTreeToTemporaryIndex(treeish string) (filename string, cancel context.CancelFunc, err error) { | ||||
| 	tmpIndex, err := os.CreateTemp("", "index") | ||||
| func (repo *Repository) ReadTreeToTemporaryIndex(treeish string) (filename, tmpDir string, cancel context.CancelFunc, err error) { | ||||
| 	tmpDir, err = os.MkdirTemp("", "index") | ||||
| 	if err != nil { | ||||
| 		return | ||||
| 	} | ||||
| 	filename = tmpIndex.Name() | ||||
|  | ||||
| 	filename = filepath.Join(tmpDir, ".tmp-index") | ||||
| 	cancel = func() { | ||||
| 		err := util.Remove(filename) | ||||
| 		err := util.RemoveAll(tmpDir) | ||||
| 		if err != nil { | ||||
| 			log.Error("failed to remove tmp index file: %v", err) | ||||
| 		} | ||||
| @@ -60,7 +62,7 @@ func (repo *Repository) ReadTreeToTemporaryIndex(treeish string) (filename strin | ||||
| 	err = repo.ReadTreeToIndex(treeish, filename) | ||||
| 	if err != nil { | ||||
| 		defer cancel() | ||||
| 		return "", func() {}, err | ||||
| 		return "", "", func() {}, err | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user