|
4 | 4 | package repo |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "html/template" |
7 | 8 | "net/http" |
8 | 9 |
|
9 | 10 | pull_model "code.gitea.io/gitea/models/pull" |
10 | 11 | "code.gitea.io/gitea/modules/base" |
11 | 12 | "code.gitea.io/gitea/modules/git" |
| 13 | + "code.gitea.io/gitea/modules/reqctx" |
| 14 | + "code.gitea.io/gitea/modules/templates" |
12 | 15 | "code.gitea.io/gitea/services/context" |
13 | 16 | "code.gitea.io/gitea/services/gitdiff" |
14 | 17 | files_service "code.gitea.io/gitea/services/repository/files" |
@@ -59,24 +62,27 @@ func isExcludedEntry(entry *git.TreeEntry) bool { |
59 | 62 | type FileDiffFile struct { |
60 | 63 | Name string |
61 | 64 | NameHash string |
| 65 | + FileIcon template.HTML |
62 | 66 | IsSubmodule bool |
63 | 67 | IsViewed bool |
64 | 68 | Status string |
65 | 69 | } |
66 | 70 |
|
67 | 71 | // transformDiffTreeForUI transforms a DiffTree into a slice of FileDiffFile for UI rendering |
68 | 72 | // it also takes a map of file names to their viewed state, which is used to mark files as viewed |
69 | | -func transformDiffTreeForUI(diffTree *gitdiff.DiffTree, filesViewedState map[string]pull_model.ViewedState) []FileDiffFile { |
| 73 | +func transformDiffTreeForUI(ctx *context.Context, commit *git.Commit, diffTree *gitdiff.DiffTree, filesViewedState map[string]pull_model.ViewedState) []FileDiffFile { |
70 | 74 | files := make([]FileDiffFile, 0, len(diffTree.Files)) |
71 | 75 |
|
72 | 76 | for _, file := range diffTree.Files { |
73 | 77 | nameHash := git.HashFilePathForWebUI(file.HeadPath) |
74 | 78 | isSubmodule := file.HeadMode == git.EntryModeCommit |
75 | 79 | isViewed := filesViewedState[file.HeadPath] == pull_model.Viewed |
| 80 | + entry, _ := commit.GetTreeEntryByPath(file.HeadPath) |
76 | 81 |
|
77 | 82 | files = append(files, FileDiffFile{ |
78 | 83 | Name: file.HeadPath, |
79 | 84 | NameHash: nameHash, |
| 85 | + FileIcon: templates.NewRenderUtils(reqctx.FromContext(ctx)).RenderFileIcon(entry), |
80 | 86 | IsSubmodule: isSubmodule, |
81 | 87 | IsViewed: isViewed, |
82 | 88 | Status: file.Status, |
|
0 commit comments