]> source.dussan.org Git - gitea.git/commit
Improve ObjectFormat interface (#28496)
authorLunny Xiao <xiaolunwen@gmail.com>
Tue, 19 Dec 2023 07:20:47 +0000 (15:20 +0800)
committerGitHub <noreply@github.com>
Tue, 19 Dec 2023 07:20:47 +0000 (07:20 +0000)
commit4eb2a29910779ac6005a5d67f31067a1132c5297
tree6be901075430e94785bc37ac4ec67392a17ed868
parent128eac9e0b03ee9c1e45dbd49da8e4726ca569f2
Improve ObjectFormat interface (#28496)

The 4 functions are duplicated, especially as interface methods. I think
we just need to keep `MustID` the only one and remove other 3.

```
MustID(b []byte) ObjectID
MustIDFromString(s string) ObjectID
NewID(b []byte) (ObjectID, error)
NewIDFromString(s string) (ObjectID, error)
```

Introduced the new interfrace method `ComputeHash` which will replace
the interface `HasherInterface`. Now we don't need to keep two
interfaces.

Reintroduced `git.NewIDFromString` and `git.MustIDFromString`. The new
function will detect the hash length to decide which objectformat of it.
If it's 40, then it's SHA1. If it's 64, then it's SHA256. This will be
right if the commitID is a full one. So the parameter should be always a
full commit id.

@AdamMajer Please review.
39 files changed:
cmd/hook.go
models/git/branch_test.go
models/git/commit_status.go
modules/git/commit_info_nogogit.go
modules/git/commit_reader.go
modules/git/commit_test.go
modules/git/last_commit_cache.go
modules/git/object_format.go
modules/git/object_id.go
modules/git/parse_gogit.go
modules/git/parse_gogit_test.go
modules/git/parse_nogogit.go
modules/git/parse_nogogit_test.go
modules/git/pipeline/lfs_nogogit.go
modules/git/repo.go
modules/git/repo_blob.go
modules/git/repo_blob_test.go
modules/git/repo_commit.go
modules/git/repo_commit_gogit.go
modules/git/repo_commit_nogogit.go
modules/git/repo_index.go
modules/git/repo_language_stats_nogogit.go
modules/git/repo_object.go
modules/git/repo_ref_nogogit.go
modules/git/repo_tag.go
modules/git/repo_tag_gogit.go
modules/git/repo_tag_nogogit.go
modules/git/repo_tag_test.go
modules/git/repo_tree.go
modules/git/repo_tree_gogit.go
modules/git/repo_tree_nogogit.go
modules/git/tag.go
modules/repository/commits_test.go
modules/repository/push.go
routers/api/v1/utils/git.go
routers/private/hook_verification.go
routers/web/repo/setting/lfs.go
services/actions/commit_status.go
services/pull/patch.go