Skip to content
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

Abstract hash function usage #28138

Merged
merged 2 commits into from
Dec 13, 2023
Merged

Abstract hash function usage #28138

merged 2 commits into from
Dec 13, 2023

Conversation

AdamMajer
Copy link
Contributor

Refactor Hash interfaces and centralize hash function. This will allow easier introduction of different hash function later on.

This forms the "no-op" part of the SHA256 enablement patch.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Nov 20, 2023
@pull-request-size pull-request-size bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Nov 20, 2023
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin labels Nov 20, 2023
@delvh delvh added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Nov 21, 2023
@delvh
Copy link
Member

delvh commented Nov 21, 2023

"no-op".
I mean, it does change the database.
As such, we need a database migration.

cmd/hook.go Outdated Show resolved Hide resolved
cmd/hook.go Outdated Show resolved Hide resolved
@AdamMajer
Copy link
Contributor Author

"no-op". I mean, it does change the database. As such, we need a database migration.

Let's keep a true no-op. We can change database in other commits. I've now pushed a change here that doesn't require a change in database. If you see anything that does, please point it out and I will move it out.

@AdamMajer AdamMajer force-pushed the sha-agnostic branch 3 times, most recently from 44bd4fc to 05a23b8 Compare November 21, 2023 15:08
@6543 6543 added this to the 1.22.0 milestone Nov 21, 2023
modules/git/blame.go Outdated Show resolved Hide resolved
@AdamMajer
Copy link
Contributor Author

I've gone over the patch and renamed things as requested and did some further refactoring. Please let me know if I've missed something..

Locally, I've run integration unit tests against mssql container and regular backend unit tests, so hopefully things will pass against other backends.

@AdamMajer
Copy link
Contributor Author

Just out of curiosity, is the test build failure because of some desync on the test end or something else? I can build locally with TAGS="gogit sqlite ..." and also TAGS="nogogit sqlite .." while some of the bots are getting compilation errors. I'm confused.

@wxiaoguang
Copy link
Contributor

I can build locally with TAGS="gogit sqlite ..." and also TAGS="nogogit sqlite .." while some of the bots are getting compilation errors. I'm confused.

How do you build locally? What if you introduce some explict errors in the "gogit" files?

The CI still says that the errors are related to gogit.

modules/git/hash.go Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Dec 12, 2023
services/pull/check.go Outdated Show resolved Hide resolved
@lunny
Copy link
Member

lunny commented Dec 13, 2023

Wow, what a big refactor. I think https://github.com/go-gitea/gitea/pull/28138/files#r1424969756 is the only one I want to know.

Refactor SHA1 interfaces and centralize the hash function. This will
allow easier introduction of different hash function later on.
@wxiaoguang
Copy link
Contributor

https://github.com/go-gitea/gitea/blob/main/CONTRIBUTING.md#maintaining-open-prs

The moment you create a non-draft PR or the moment you convert a draft PR to a non-draft PR is the moment code review starts for it.
Once that happens, do not rebase or squash your branch anymore as it makes it difficult to review the new changes.
Merge the base branch into your branch only when you really need to, i.e. because of conflicting changes in the mean time.
This reduces unnecessary CI runs.
Don't worry about merge commits messing up your commit history as every PR will be squash merged.
This means that all changes are joined into a single new commit whose message is as described below.

@AdamMajer
Copy link
Contributor Author

Wow, what a big refactor. I think https://github.com/go-gitea/gitea/pull/28138/files#r1424969756 is the only one I want to know.

This issue should be fixed now. There are plenty of other, tangential refactors that can be done with these changes but these can be done at a smaller pace.

@AdamMajer
Copy link
Contributor Author

Thanks @wxiaoguang , seems I was doing it wrong and re-basing on top of main while I should be adding new commits and merges (when conflicts arise) instead.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Dec 13, 2023
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Dec 13, 2023
@lunny lunny enabled auto-merge (squash) December 13, 2023 12:51
@lunny lunny merged commit cbf923e into go-gitea:main Dec 13, 2023
25 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Dec 13, 2023
zjjhot added a commit to zjjhot/gitea that referenced this pull request Dec 14, 2023
* giteaofficial/main:
  Abstract hash function usage (go-gitea#28138)
  Add endpoint for not implemented Docker auth (go-gitea#28457)
  docs: Update group membership fields to match application. (go-gitea#28175)
type ObjectFormatID int

const (
Sha1 ObjectFormatID = iota
Copy link
Contributor

@wxiaoguang wxiaoguang Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it needs "integer" number?

I think type ObjectFormat string and Sha1 = "sha1" work better?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is another function that does this from string already, at the bottom of the file.

git.ObjectFormatFromString()

Basically, there is no need for this to be int or string in particular, but I wanted to move at least temporarily away from string to catch errors like passing "SHA1" vs. "sha1".

Finally, maybe my prejudice shows, coming from C and C++ world shows, where enums are ints 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fuxiaohei pushed a commit to fuxiaohei/gitea that referenced this pull request Jan 17, 2024
Refactor Hash interfaces and centralize hash function. This will allow
easier introduction of different hash function later on.

This forms the "no-op" part of the SHA256 enablement patch.
6543 added a commit that referenced this pull request Jan 19, 2024
Currently only SHA1 repositories are supported by Gitea. This adds
support for alternate SHA256 with the additional aim of easier support
for additional hash types in the future.

Fixes: #13794
Limited by: go-git/go-git#899
Depend on: #28138

<img width="776" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/5448c9a7-608e-4341-a149-5dd0069c9447">

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
AdamMajer added a commit to AdamMajer/gitea that referenced this pull request Jan 22, 2024
Refactor Hash interfaces and centralize hash function. This will allow
easier introduction of different hash function later on.

This forms the "no-op" part of the SHA256 enablement patch.
AdamMajer added a commit to AdamMajer/gitea that referenced this pull request Jan 22, 2024
Currently only SHA1 repositories are supported by Gitea. This adds
support for alternate SHA256 with the additional aim of easier support
for additional hash types in the future.

Fixes: go-gitea#13794
Limited by: go-git/go-git#899
Depend on: go-gitea#28138

<img width="776" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/5448c9a7-608e-4341-a149-5dd0069c9447">

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
henrygoodman pushed a commit to henrygoodman/gitea that referenced this pull request Jan 31, 2024
Currently only SHA1 repositories are supported by Gitea. This adds
support for alternate SHA256 with the additional aim of easier support
for additional hash types in the future.

Fixes: go-gitea#13794
Limited by: go-git/go-git#899
Depend on: go-gitea#28138

<img width="776" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/5448c9a7-608e-4341-a149-5dd0069c9447">

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
silverwind pushed a commit to silverwind/gitea that referenced this pull request Feb 20, 2024
Refactor Hash interfaces and centralize hash function. This will allow
easier introduction of different hash function later on.

This forms the "no-op" part of the SHA256 enablement patch.
silverwind pushed a commit to silverwind/gitea that referenced this pull request Feb 20, 2024
Currently only SHA1 repositories are supported by Gitea. This adds
support for alternate SHA256 with the additional aim of easier support
for additional hash types in the future.

Fixes: go-gitea#13794
Limited by: go-git/go-git#899
Depend on: go-gitea#28138

<img width="776" alt="图片" src="https://github.com/go-gitea/gitea/assets/81045/5448c9a7-608e-4341-a149-5dd0069c9447">

---------

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
KN4CK3R added a commit that referenced this pull request Feb 26, 2024
There's a miss in #28138:

![image](https://github.com/go-gitea/gitea/assets/18380374/b1e0c5fc-0e6e-44ab-9f6e-34bc8ffbe1cc)


https://github.com/go-gitea/gitea/pull/28138/files#diff-2556e62ad7204a230c91927a3f2115e25a2b688240d0ee1de6d34f0277f37dfeR162

@lunny 
Not sure about the impact of this, but it will only effect 1.22, and
maybe we should fix it ASAP.

Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
zjjhot added a commit to zjjhot/gitea that referenced this pull request Feb 27, 2024
* giteaofficial/main:
  Fix mail template error (go-gitea#29410)
  Document our issue locking policy (go-gitea#29433)
  Fix htmx rendering the login page in frame on session logout (go-gitea#29405)
  Ignore empty repo for CreateRepository in action notifier (go-gitea#29416)
  Fix incorrect tree path value for patch editor (go-gitea#29377)
  Fix logic error from go-gitea#28138 (go-gitea#29417)
@go-gitea go-gitea locked as resolved and limited conversation to collaborators Mar 12, 2024
_, _ = h.Write([]byte(" "))
_, _ = h.Write([]byte(strconv.FormatInt(int64(len(content)), 10)))
_, _ = h.Write([]byte{0})
return h.HashSum()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below, a regression ..... the "content" is not written into the hasher 😭

-> Fix incorrect object id hash function #30708

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/cli PR changes something on the CLI, i.e. gitea doctor or gitea admin size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants