History

Calculate filename hash only once (#19654)

* Calculate hash only once. * remove unused Sha1 template helper function, use ctx.Data["FileNameHash"] * fix unit tests

KN4CK3R committed 4 years ago

Commit a9ca4b41 parent 9efa4718 files · +26 −29Browse files

Showing the changes to services/gitdiff/gitdiff.go (1 of 8 files). Show all

Unified · Split

services/gitdiff/gitdiff.go+4−1
@@ -25,6 +25,7 @@ import ( · 24 unmodified lines
2525 pull_model "code.gitea.io/gitea/models/pull"
2626 user_model "code.gitea.io/gitea/models/user"
2727 "code.gitea.io/gitea/modules/analyze"
28+ "code.gitea.io/gitea/modules/base"
2829 "code.gitea.io/gitea/modules/charset"
2930 "code.gitea.io/gitea/modules/git"
3031 "code.gitea.io/gitea/modules/highlight"
@@ -604,6 +605,7 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine) Dif · 573 unmodified lines
604605 // DiffFile represents a file diff.
605606 type DiffFile struct {
606607 Name string
608+ NameHash string
607609 OldName string
608610 Index int
609611 Addition, Deletion int
@@ -952,7 +954,6 @@ parsingLoop: · 342 unmodified lines
952954 break curFileLoop
953955 }
954956 }
955−
956957 }
957958
958959 // TODO: There are numerous issues with this:
@@ -964,6 +965,8 @@ parsingLoop: · 5 unmodified lines
964965 diffLineTypeBuffers[DiffLineAdd] = new(bytes.Buffer)
965966 diffLineTypeBuffers[DiffLineDel] = new(bytes.Buffer)
966967 for _, f := range diff.Files {
968+ f.NameHash = base.EncodeSha1(f.Name)
969+
967970 for _, buffer := range diffLineTypeBuffers {
968971 buffer.Reset()
969972 }