forked from kevadesu/forgejo
Calculate filename hash only once (#19654)
* Calculate hash only once. * remove unused Sha1 template helper function, use ctx.Data["FileNameHash"] * fix unit tests
This commit is contained in:
parent
9efa47131f
commit
a9ca4b4100
8 changed files with 26 additions and 29 deletions
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ func TestGetDiffPreview(t *testing.T) {
|
|||
{
|
||||
Name: "README.md",
|
||||
OldName: "README.md",
|
||||
NameHash: "8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d",
|
||||
Index: 1,
|
||||
Addition: 2,
|
||||
Deletion: 1,
|
||||
|
@ -123,7 +124,7 @@ func TestGetDiffPreview(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
bs, err := json.Marshal(diff)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, expectedBs, bs)
|
||||
assert.EqualValues(t, string(expectedBs), string(bs))
|
||||
})
|
||||
|
||||
t.Run("empty branch, same results", func(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue