aboutsummaryrefslogtreecommitdiffstats
path: root/services/gitdiff
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2022-05-09 00:29:50 +0200
committerGitHub <noreply@github.com>2022-05-09 00:29:50 +0200
commita9ca4b410080814051952f71a8339ea81e0de8bf (patch)
tree7201cc3caa17b361f5555298e52f31b78f756564 /services/gitdiff
parent9efa47131f3fa576bd0ef73fa4c5b96c95d89906 (diff)
downloadgitea-a9ca4b410080814051952f71a8339ea81e0de8bf.tar.gz
gitea-a9ca4b410080814051952f71a8339ea81e0de8bf.zip
Calculate filename hash only once (#19654)
* Calculate hash only once. * remove unused Sha1 template helper function, use ctx.Data["FileNameHash"] * fix unit tests
Diffstat (limited to 'services/gitdiff')
-rw-r--r--services/gitdiff/gitdiff.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index 7fe056a481..92ff92a6c0 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -25,6 +25,7 @@ import (
pull_model "code.gitea.io/gitea/models/pull"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/analyze"
+ "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/highlight"
@@ -604,6 +605,7 @@ func (diffSection *DiffSection) GetComputedInlineDiffFor(diffLine *DiffLine) Dif
// DiffFile represents a file diff.
type DiffFile struct {
Name string
+ NameHash string
OldName string
Index int
Addition, Deletion int
@@ -952,7 +954,6 @@ parsingLoop:
break curFileLoop
}
}
-
}
// TODO: There are numerous issues with this:
@@ -964,6 +965,8 @@ parsingLoop:
diffLineTypeBuffers[DiffLineAdd] = new(bytes.Buffer)
diffLineTypeBuffers[DiffLineDel] = new(bytes.Buffer)
for _, f := range diff.Files {
+ f.NameHash = base.EncodeSha1(f.Name)
+
for _, buffer := range diffLineTypeBuffers {
buffer.Reset()
}