diff options
author | zeripath <art27@cantab.net> | 2021-11-17 20:37:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-17 20:37:00 +0000 |
commit | 3c4724d70e4ac7bfc06b97f6fad8936f97479b6b (patch) | |
tree | 754286def789b823e020d3ccfafae148d0017b62 /modules/git/repo_index.go | |
parent | 81a4fc752833101dd7d6b4f612bccc4b29c98dff (diff) | |
download | gitea-3c4724d70e4ac7bfc06b97f6fad8936f97479b6b.tar.gz gitea-3c4724d70e4ac7bfc06b97f6fad8936f97479b6b.zip |
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>
Diffstat (limited to 'modules/git/repo_index.go')
-rw-r--r-- | modules/git/repo_index.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/modules/git/repo_index.go b/modules/git/repo_index.go index 27cb7fbebe..38c01295b6 100644 --- a/modules/git/repo_index.go +++ b/modules/git/repo_index.go @@ -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 } |