-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve ObjectFormat interface #28496
Conversation
Not sure whether it is right to remove |
Reintroduced |
I do not have full understanding, the only question is it good to "guess" the object format by length. I can accept if it is fine to do so. |
My thought was to move "the other way" when it comes to refactoring. That is, to move away from string and toward ObjectID and ObjectFormat to store these references everywhere. Then the The only problem here is that you are removing objectFormat and assuming that hashes will always be in correct format, there will be an issue when you pass a partial hash the length of SHA1 into a SHA256 repository. Any user input cannot be assumed to be full hash just by looking at length, for example. So if we take care that user input never hits these functions, there should be no issue. |
That's what |
* giteaofficial/main: Add more ways to try (go-gitea#28581) Convert to url auth to header auth in tests (go-gitea#28484) Fix 500 error of searching commits (go-gitea#28576) improve possible performance bottleneck (go-gitea#28547) Use information from previous blame parts (go-gitea#28572) Make offline mode as default to no connect external avatar service by default (go-gitea#28548) Fix merging artifact chunks error when minio storage basepath is set (go-gitea#28555) feat: bump `dessant/lock-threads` and `actions/setup-go` to use nodejs20 runtime (go-gitea#28565) Update actions document about comparsion as Github Actions (go-gitea#28560) Fix inperformant query on retrifing review from database. (go-gitea#28552) Fix the issue ref rendering for wiki (go-gitea#28556) Add missing head of lfs client batch (go-gitea#28550) [skip ci] Updated translations via Crowdin Remove deadcode under models/issues (go-gitea#28536) Always enable caches (go-gitea#28527) Improve ObjectFormat interface (go-gitea#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.
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.
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.
The 4 functions are duplicated, especially as interface methods. I think we just need to keep
MustID
the only one and remove other 3.Introduced the new interfrace method
ComputeHash
which will replace the interfaceHasherInterface
. Now we don't need to keep two interfaces.Reintroduced
git.NewIDFromString
andgit.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.