History

Refactor sha1 and time-limited code (#31023)

Remove "EncodeSha1", it shouldn't be used as a general purpose hasher (just like we have removed "EncodeMD5" in #28622) Rewrite the "time-limited code" related code and write better tests, the old code doesn't seem quite right. (cherry picked from commit fb1ad920b769799aa1287441289d15477d9878c5)

wxiaoguang committed 2 years ago

Commit 5612cf31 parent 886a6758 files · +117 −99Browse files

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

Unified · Split

services/gitdiff/gitdiff.go+1−2
@@ -23,7 +23,6 @@ import ( · 22 unmodified lines
23 pull_model "code.gitea.io/gitea/models/pull"23 pull_model "code.gitea.io/gitea/models/pull"
24 user_model "code.gitea.io/gitea/models/user"24 user_model "code.gitea.io/gitea/models/user"
25 "code.gitea.io/gitea/modules/analyze"25 "code.gitea.io/gitea/modules/analyze"
26 "code.gitea.io/gitea/modules/base"
27 "code.gitea.io/gitea/modules/charset"26 "code.gitea.io/gitea/modules/charset"
28 "code.gitea.io/gitea/modules/git"27 "code.gitea.io/gitea/modules/git"
29 "code.gitea.io/gitea/modules/highlight"28 "code.gitea.io/gitea/modules/highlight"
@@ -742,7 +741,7 @@ parsingLoop: · 712 unmodified lines
742 diffLineTypeBuffers[DiffLineAdd] = new(bytes.Buffer)741 diffLineTypeBuffers[DiffLineAdd] = new(bytes.Buffer)
743 diffLineTypeBuffers[DiffLineDel] = new(bytes.Buffer)742 diffLineTypeBuffers[DiffLineDel] = new(bytes.Buffer)
744 for _, f := range diff.Files {743 for _, f := range diff.Files {
745 f.NameHash = base.EncodeSha1(f.Name)744 f.NameHash = git.HashFilePathForWebUI(f.Name)
746 745
747 for _, buffer := range diffLineTypeBuffers {746 for _, buffer := range diffLineTypeBuffers {
748 buffer.Reset()747 buffer.Reset()