From 2bdab948cbbd7b348621f853bb8aecd8a74aa3ee Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 17 Jan 2024 17:26:45 +0800 Subject: [PATCH 01/26] Add missing migration (#28827) Missed from #28498 --- models/migrations/migrations.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 578cbca035..3b4ac24a2c 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -552,6 +552,8 @@ var migrations = []Migration{ NewMigration("Add Index to pull_auto_merge.doer_id", v1_22.AddIndexToPullAutoMergeDoerID), // v283 -> v284 NewMigration("Add combined Index to issue_user.uid and issue_id", v1_22.AddCombinedIndexToIssueUser), + // v284 -> v285 + NewMigration("Add ignore stale approval column on branch table", v1_22.AddIgnoreStaleApprovalsColumnToProtectedBranchTable), } // GetCurrentDBVersion returns the current db version From c8ba17c73ff455ea381c8ab5a81f77d545a672fd Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 17 Jan 2024 17:56:00 +0800 Subject: [PATCH 02/26] Remove duplicated checkinit on git module (#28824) `checkInit` has been invoked in `InitSimple`. So it's unnecessary to invoke it twice in `InitFull`. --- modules/git/git.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/git/git.go b/modules/git/git.go index 166655eb73..24eff05afc 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -166,10 +166,6 @@ func InitSimple(ctx context.Context) error { // InitFull initializes git module with version check and change global variables, sync gitconfig. // It should only be called once at the beginning of the program initialization (TestMain/GlobalInitInstalled) as this code makes unsynchronized changes to variables. func InitFull(ctx context.Context) (err error) { - if err = checkInit(); err != nil { - return err - } - if err = InitSimple(ctx); err != nil { return err } From eba9c0ce48c7d43910eb77db74c6648157663ceb Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 17 Jan 2024 21:27:59 +0800 Subject: [PATCH 03/26] Add testing for CalcCommitStatus (#28823) --- models/git/commit_status_test.go | 115 +++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/models/git/commit_status_test.go b/models/git/commit_status_test.go index f7dd8597ed..74ba4a1006 100644 --- a/models/git/commit_status_test.go +++ b/models/git/commit_status_test.go @@ -60,3 +60,118 @@ func TestGetCommitStatuses(t *testing.T) { assert.Equal(t, int(maxResults), 5) assert.Empty(t, statuses) } + +func Test_CalcCommitStatus(t *testing.T) { + kases := []struct { + statuses []*git_model.CommitStatus + expected *git_model.CommitStatus + }{ + { + statuses: []*git_model.CommitStatus{ + { + State: structs.CommitStatusPending, + }, + }, + expected: &git_model.CommitStatus{ + State: structs.CommitStatusPending, + }, + }, + { + statuses: []*git_model.CommitStatus{ + { + State: structs.CommitStatusSuccess, + }, + { + State: structs.CommitStatusPending, + }, + }, + expected: &git_model.CommitStatus{ + State: structs.CommitStatusPending, + }, + }, + { + statuses: []*git_model.CommitStatus{ + { + State: structs.CommitStatusSuccess, + }, + { + State: structs.CommitStatusPending, + }, + { + State: structs.CommitStatusSuccess, + }, + }, + expected: &git_model.CommitStatus{ + State: structs.CommitStatusPending, + }, + }, + { + statuses: []*git_model.CommitStatus{ + { + State: structs.CommitStatusError, + }, + { + State: structs.CommitStatusPending, + }, + { + State: structs.CommitStatusSuccess, + }, + }, + expected: &git_model.CommitStatus{ + State: structs.CommitStatusError, + }, + }, + { + statuses: []*git_model.CommitStatus{ + { + State: structs.CommitStatusWarning, + }, + { + State: structs.CommitStatusPending, + }, + { + State: structs.CommitStatusSuccess, + }, + }, + expected: &git_model.CommitStatus{ + State: structs.CommitStatusWarning, + }, + }, + { + statuses: []*git_model.CommitStatus{ + { + State: structs.CommitStatusSuccess, + }, + { + State: structs.CommitStatusSuccess, + }, + { + State: structs.CommitStatusSuccess, + }, + }, + expected: &git_model.CommitStatus{ + State: structs.CommitStatusSuccess, + }, + }, + { + statuses: []*git_model.CommitStatus{ + { + State: structs.CommitStatusFailure, + }, + { + State: structs.CommitStatusError, + }, + { + State: structs.CommitStatusWarning, + }, + }, + expected: &git_model.CommitStatus{ + State: structs.CommitStatusError, + }, + }, + } + + for _, kase := range kases { + assert.Equal(t, kase.expected, git_model.CalcCommitStatus(kase.statuses)) + } +} From 4674aea25b54baf08594c54f061dee9e44190f02 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 18 Jan 2024 19:27:07 +0900 Subject: [PATCH 04/26] Fix display latest sync time for pull mirrors on the repo page (#28841) Follow #28712 1. Missing Locale word `mirror_sync` 2. Maybe forgot checking the conflict from #27760 Before: ![image](https://github.com/go-gitea/gitea/assets/18380374/6100d35b-7fe3-4095-9c24-7875568f7380) After: ![image](https://github.com/go-gitea/gitea/assets/18380374/69647169-b812-45bc-a267-ab28f2df6ef6) --- options/locale/locale_en-US.ini | 1 + templates/repo/header.tmpl | 15 +++++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 90e3ac503a..6f9ba8c884 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -987,6 +987,7 @@ mirror_prune = Prune mirror_prune_desc = Remove obsolete remote-tracking references mirror_interval = Mirror Interval (valid time units are 'h', 'm', 's'). 0 to disable periodic sync. (Minimum interval: %s) mirror_interval_invalid = The mirror interval is not valid. +mirror_sync = synced mirror_sync_on_commit = Sync when commits are pushed mirror_address = Clone From URL mirror_address_desc = Put any required credentials in the Authorization section. diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index c362059ef3..a5ef8daa9a 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -28,13 +28,6 @@
{{svg "octicon-repo-template" 18}}
{{end}} - {{if $.PullMirror}} -
- {{ctx.Locale.Tr "repo.mirror_from"}} - {{$.PullMirror.RemoteAddress}} - {{if $.PullMirror.UpdatedUnix}}{{ctx.Locale.Tr "repo.mirror_sync"}} {{TimeSinceUnix $.PullMirror.UpdatedUnix ctx.Locale}}{{end}} -
- {{end}} {{if not (or .IsBeingCreated .IsBroken)}}
@@ -147,7 +140,13 @@
{{end}} - {{if $.PullMirror}}
{{ctx.Locale.Tr "repo.mirror_from"}} {{$.PullMirror.RemoteAddress}}
{{end}} + {{if $.PullMirror}} +
+ {{ctx.Locale.Tr "repo.mirror_from"}} + {{$.PullMirror.RemoteAddress}} + {{if $.PullMirror.UpdatedUnix}}{{ctx.Locale.Tr "repo.mirror_sync"}} {{TimeSinceUnix $.PullMirror.UpdatedUnix ctx.Locale}}{{end}} +
+ {{end}} {{if .IsFork}}
{{ctx.Locale.Tr "repo.forked_from"}} {{.BaseRepo.FullName}}
{{end}} {{if .IsGenerated}}
{{ctx.Locale.Tr "repo.generated_from"}} {{(.TemplateRepo ctx).FullName}}
{{end}} From b60a7c3358cdeec3e0a731b68be33b6ba63a6563 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 19 Jan 2024 11:45:23 +0900 Subject: [PATCH 05/26] Return `responseText` instead of string in some functions (#28836) Follow https://github.com/go-gitea/gitea/pull/28796#issuecomment-1891727591 --- cmd/actions.go | 2 +- cmd/keys.go | 2 +- cmd/mailer.go | 2 +- modules/private/actions.go | 8 ++------ modules/private/hook.go | 6 +++--- modules/private/key.go | 10 +++------- modules/private/mail.go | 8 ++------ modules/private/request.go | 10 +++++----- 8 files changed, 18 insertions(+), 30 deletions(-) diff --git a/cmd/actions.go b/cmd/actions.go index 275fd7904e..f582c16c81 100644 --- a/cmd/actions.go +++ b/cmd/actions.go @@ -50,6 +50,6 @@ func runGenerateActionsRunnerToken(c *cli.Context) error { if extra.HasError() { return handleCliResponseExtra(extra) } - _, _ = fmt.Printf("%s\n", respText) + _, _ = fmt.Printf("%s\n", respText.Text) return nil } diff --git a/cmd/keys.go b/cmd/keys.go index 9d5278f109..ceeec48486 100644 --- a/cmd/keys.go +++ b/cmd/keys.go @@ -78,6 +78,6 @@ func runKeys(c *cli.Context) error { if extra.Error != nil { return extra.Error } - _, _ = fmt.Fprintln(c.App.Writer, strings.TrimSpace(authorizedString)) + _, _ = fmt.Fprintln(c.App.Writer, strings.TrimSpace(authorizedString.Text)) return nil } diff --git a/cmd/mailer.go b/cmd/mailer.go index 646330e85a..0c5f2c8c8d 100644 --- a/cmd/mailer.go +++ b/cmd/mailer.go @@ -45,6 +45,6 @@ func runSendMail(c *cli.Context) error { if extra.HasError() { return handleCliResponseExtra(extra) } - _, _ = fmt.Printf("Sent %s email(s) to all users\n", respText) + _, _ = fmt.Printf("Sent %s email(s) to all users\n", respText.Text) return nil } diff --git a/modules/private/actions.go b/modules/private/actions.go index a22833632e..311a283650 100644 --- a/modules/private/actions.go +++ b/modules/private/actions.go @@ -14,16 +14,12 @@ type GenerateTokenRequest struct { } // GenerateActionsRunnerToken calls the internal GenerateActionsRunnerToken function -func GenerateActionsRunnerToken(ctx context.Context, scope string) (string, ResponseExtra) { +func GenerateActionsRunnerToken(ctx context.Context, scope string) (*ResponseText, ResponseExtra) { reqURL := setting.LocalURL + "api/internal/actions/generate_actions_runner_token" req := newInternalRequest(ctx, reqURL, "POST", GenerateTokenRequest{ Scope: scope, }) - resp, extra := requestJSONResp(req, &responseText{}) - if extra.HasError() { - return "", extra - } - return resp.Text, extra + return requestJSONResp(req, &ResponseText{}) } diff --git a/modules/private/hook.go b/modules/private/hook.go index 23e03896e4..cab8c81224 100644 --- a/modules/private/hook.go +++ b/modules/private/hook.go @@ -101,7 +101,7 @@ func HookPreReceive(ctx context.Context, ownerName, repoName string, opts HookOp reqURL := setting.LocalURL + fmt.Sprintf("api/internal/hook/pre-receive/%s/%s", url.PathEscape(ownerName), url.PathEscape(repoName)) req := newInternalRequest(ctx, reqURL, "POST", opts) req.SetReadWriteTimeout(time.Duration(60+len(opts.OldCommitIDs)) * time.Second) - _, extra := requestJSONResp(req, &responseText{}) + _, extra := requestJSONResp(req, &ResponseText{}) return extra } @@ -130,7 +130,7 @@ func SetDefaultBranch(ctx context.Context, ownerName, repoName, branch string) R url.PathEscape(branch), ) req := newInternalRequest(ctx, reqURL, "POST") - _, extra := requestJSONResp(req, &responseText{}) + _, extra := requestJSONResp(req, &ResponseText{}) return extra } @@ -138,6 +138,6 @@ func SetDefaultBranch(ctx context.Context, ownerName, repoName, branch string) R func SSHLog(ctx context.Context, isErr bool, msg string) error { reqURL := setting.LocalURL + "api/internal/ssh/log" req := newInternalRequest(ctx, reqURL, "POST", &SSHLogOption{IsError: isErr, Message: msg}) - _, extra := requestJSONResp(req, &responseText{}) + _, extra := requestJSONResp(req, &ResponseText{}) return extra.Error } diff --git a/modules/private/key.go b/modules/private/key.go index 08762bd401..dcd1714856 100644 --- a/modules/private/key.go +++ b/modules/private/key.go @@ -15,20 +15,16 @@ func UpdatePublicKeyInRepo(ctx context.Context, keyID, repoID int64) error { // Ask for running deliver hook and test pull request tasks. reqURL := setting.LocalURL + fmt.Sprintf("api/internal/ssh/%d/update/%d", keyID, repoID) req := newInternalRequest(ctx, reqURL, "POST") - _, extra := requestJSONResp(req, &responseText{}) + _, extra := requestJSONResp(req, &ResponseText{}) return extra.Error } // AuthorizedPublicKeyByContent searches content as prefix (leak e-mail part) // and returns public key found. -func AuthorizedPublicKeyByContent(ctx context.Context, content string) (string, ResponseExtra) { +func AuthorizedPublicKeyByContent(ctx context.Context, content string) (*ResponseText, ResponseExtra) { // Ask for running deliver hook and test pull request tasks. reqURL := setting.LocalURL + "api/internal/ssh/authorized_keys" req := newInternalRequest(ctx, reqURL, "POST") req.Param("content", content) - resp, extra := requestJSONResp(req, &responseText{}) - if extra.HasError() { - return "", extra - } - return resp.Text, extra + return requestJSONResp(req, &ResponseText{}) } diff --git a/modules/private/mail.go b/modules/private/mail.go index ac55d6fe4d..08de5b7e28 100644 --- a/modules/private/mail.go +++ b/modules/private/mail.go @@ -20,7 +20,7 @@ type Email struct { // It accepts a list of usernames. // If DB contains these users it will send the email to them. // If to list == nil, it's supposed to send emails to every user present in DB -func SendEmail(ctx context.Context, subject, message string, to []string) (string, ResponseExtra) { +func SendEmail(ctx context.Context, subject, message string, to []string) (*ResponseText, ResponseExtra) { reqURL := setting.LocalURL + "api/internal/mail/send" req := newInternalRequest(ctx, reqURL, "POST", Email{ @@ -29,9 +29,5 @@ func SendEmail(ctx context.Context, subject, message string, to []string) (strin To: to, }) - resp, extra := requestJSONResp(req, &responseText{}) - if extra.HasError() { - return "", extra - } - return resp.Text, extra + return requestJSONResp(req, &ResponseText{}) } diff --git a/modules/private/request.go b/modules/private/request.go index 2bc43b972d..58cd261239 100644 --- a/modules/private/request.go +++ b/modules/private/request.go @@ -12,8 +12,8 @@ import ( "code.gitea.io/gitea/modules/json" ) -// responseText is used to get the response as text, instead of parsing it as JSON. -type responseText struct { +// ResponseText is used to get the response as text, instead of parsing it as JSON. +type ResponseText struct { Text string } @@ -50,7 +50,7 @@ func (re responseError) Error() string { // Caller should check the ResponseExtra.HasError() first to see whether the request fails. // // * If the "res" is a struct pointer, the response will be parsed as JSON -// * If the "res" is responseText pointer, the response will be stored as text in it +// * If the "res" is ResponseText pointer, the response will be stored as text in it // * If the "res" is responseCallback pointer, the callback function should set the ResponseExtra fields accordingly func requestJSONResp[T any](req *httplib.Request, res *T) (ret *T, extra ResponseExtra) { resp, err := req.Response() @@ -81,7 +81,7 @@ func requestJSONResp[T any](req *httplib.Request, res *T) (ret *T, extra Respons // now, the StatusCode must be 2xx var v any = res - if respText, ok := v.(*responseText); ok { + if respText, ok := v.(*ResponseText); ok { // get the whole response as a text string bs, err := io.ReadAll(resp.Body) if err != nil { @@ -119,7 +119,7 @@ func requestJSONResp[T any](req *httplib.Request, res *T) (ret *T, extra Respons // requestJSONClientMsg sends a request to the gitea server, server only responds text message status=200 with "success" body // If the request succeeds (200), the argument clientSuccessMsg will be used as ResponseExtra.UserMsg. func requestJSONClientMsg(req *httplib.Request, clientSuccessMsg string) ResponseExtra { - _, extra := requestJSONResp(req, &responseText{}) + _, extra := requestJSONResp(req, &ResponseText{}) if extra.HasError() { return extra } From 1167d523c4c24eba4c159cda04e49a49f458afbf Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 19 Jan 2024 06:49:18 +0100 Subject: [PATCH 06/26] Fix archive creating LFS hooks and breaking pull requests (#28848) When LFS hooks are present in gitea-repositories, operations like git push for creating a pull request fail. These repositories are not meant to include LFS files or git push them, that is handled separately. And so they should not have LFS hooks. Installing git-lfs on some systems (like Debian Linux) will automatically set up /etc/gitconfig to create LFS hooks in repositories. For most git commands in Gitea this is not a problem, either because they run on a temporary clone or the git command does not create LFS hooks. But one case where this happens is git archive for creating repository archives. To fix that, add a GIT_CONFIG_NOSYSTEM=1 to disable using the system configuration for that command. According to a comment, GIT_CONFIG_NOSYSTEM is not used for all git commands because the system configuration can be intentionally set up for Gitea to use. Resolves #19810, #21148 --- modules/git/repo_archive.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/git/repo_archive.go b/modules/git/repo_archive.go index 2b45a50f19..1bf1aa41b9 100644 --- a/modules/git/repo_archive.go +++ b/modules/git/repo_archive.go @@ -8,6 +8,7 @@ import ( "context" "fmt" "io" + "os" "path/filepath" "strings" ) @@ -62,11 +63,15 @@ func (repo *Repository) CreateArchive(ctx context.Context, format ArchiveType, t cmd.AddOptionFormat("--format=%s", format.String()) cmd.AddDynamicArguments(commitID) + // Avoid LFS hooks getting installed because of /etc/gitconfig, which can break pull requests. + env := append(os.Environ(), "GIT_CONFIG_NOSYSTEM=1") + var stderr strings.Builder err := cmd.Run(&RunOpts{ Dir: repo.Path, Stdout: target, Stderr: &stderr, + Env: env, }) if err != nil { return ConcatenateError(err, stderr.String()) From 075c4c89ee28590bd4ab8f6cf7338d723c4696eb Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Fri, 19 Jan 2024 07:12:21 +0000 Subject: [PATCH 07/26] tests: missing refs/ in bare repositories (#28844) Git 2.43.0 will not detect a git repository as valid without refs/ subdirectory present. `git gc` cleans this up and puts it in packed-refs. We must keep refs/ non-empty. --- .../user2/test_commit_revert.git/refs/heads/main | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/gitea-repositories-meta/user2/test_commit_revert.git/refs/heads/main diff --git a/tests/gitea-repositories-meta/user2/test_commit_revert.git/refs/heads/main b/tests/gitea-repositories-meta/user2/test_commit_revert.git/refs/heads/main new file mode 100644 index 0000000000..ab80ca3ca6 --- /dev/null +++ b/tests/gitea-repositories-meta/user2/test_commit_revert.git/refs/heads/main @@ -0,0 +1 @@ +deebcbc752e540bab4ce3ee713d3fc8fdc35b2f7 From 461d8b53c2e51a8a6a1715ba40ac61d7e9f93971 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Fri, 19 Jan 2024 12:37:10 +0100 Subject: [PATCH 08/26] Fix some RPM registry flaws (#28782) Related #26984 (https://github.com/go-gitea/gitea/pull/26984#issuecomment-1889588912) Fix admin cleanup message. Fix models `Get` not respecting default values. Rebuild RPM repository files after cleanup. Do not add RPM group to package version name. Force stable sorting of Alpine/Debian/RPM repository data. Fix missing deferred `Close`. Add tests for multiple RPM groups. Removed non-cached `ReplaceAllStringRegex`. If there are multiple groups available, it's stated in the package installation screen: ![grafik](https://github.com/go-gitea/gitea/assets/1666336/8f132760-882c-4ab8-9678-77e47dfc4415) --- docs/content/usage/packages/rpm.en-us.md | 49 +- models/packages/package.go | 14 +- models/packages/package_blob.go | 12 +- models/packages/package_file.go | 26 +- models/packages/package_version.go | 12 +- models/packages/rpm/search.go | 23 + modules/packages/rpm/metadata.go | 5 +- modules/templates/util_string.go | 5 - modules/util/slice.go | 8 + options/locale/locale_en-US.ini | 3 + routers/api/packages/api.go | 148 +++-- routers/api/packages/rpm/rpm.go | 31 +- routers/web/admin/packages.go | 2 +- routers/web/user/package.go | 30 +- services/packages/cleanup/cleanup.go | 5 + services/packages/rpm/repository.go | 69 ++- templates/package/content/rpm.tmpl | 32 +- tests/integration/api_packages_rpm_test.go | 638 +++++++++++---------- 18 files changed, 634 insertions(+), 478 deletions(-) create mode 100644 models/packages/rpm/search.go diff --git a/docs/content/usage/packages/rpm.en-us.md b/docs/content/usage/packages/rpm.en-us.md index 586e48d47f..1f93376b7b 100644 --- a/docs/content/usage/packages/rpm.en-us.md +++ b/docs/content/usage/packages/rpm.en-us.md @@ -24,16 +24,26 @@ The following examples use `dnf`. ## Configuring the package registry -To register the RPM registry add the url to the list of known apt sources: +To register the RPM registry add the url to the list of known sources: ```shell dnf config-manager --add-repo https://gitea.example.com/api/packages/{owner}/rpm/{group}.repo ``` -| Placeholder | Description | -| ----------- |----------------------------------------------------| -| `owner` | The owner of the package. | -| `group` | Everything, e.g. `el7`, `rocky/el9` , `test/fc38`.| +| Placeholder | Description | +| ----------- | ----------- | +| `owner` | The owner of the package. | +| `group` | Optional: Everything, e.g. empty, `el7`, `rocky/el9`, `test/fc38`. | + +Example: + +```shell +# without a group +dnf config-manager --add-repo https://gitea.example.com/api/packages/testuser/rpm.repo + +# with the group 'centos/el7' +dnf config-manager --add-repo https://gitea.example.com/api/packages/testuser/rpm/centos/el7.repo +``` If the registry is private, provide credentials in the url. You can use a password or a [personal access token](development/api-usage.md#authentication): @@ -41,7 +51,7 @@ If the registry is private, provide credentials in the url. You can use a passwo dnf config-manager --add-repo https://{username}:{your_password_or_token}@gitea.example.com/api/packages/{owner}/rpm/{group}.repo ``` -You have to add the credentials to the urls in the `rpm.repo` file in `/etc/yum.repos.d` too. +You have to add the credentials to the urls in the created `.repo` file in `/etc/yum.repos.d` too. ## Publish a package @@ -54,11 +64,17 @@ PUT https://gitea.example.com/api/packages/{owner}/rpm/{group}/upload | Parameter | Description | | --------- | ----------- | | `owner` | The owner of the package. | -| `group` | Everything, e.g. `el7`, `rocky/el9` , `test/fc38`.| +| `group` | Optional: Everything, e.g. empty, `el7`, `rocky/el9`, `test/fc38`. | Example request using HTTP Basic authentication: ```shell +# without a group +curl --user your_username:your_password_or_token \ + --upload-file path/to/file.rpm \ + https://gitea.example.com/api/packages/testuser/rpm/upload + +# with the group 'centos/el7' curl --user your_username:your_password_or_token \ --upload-file path/to/file.rpm \ https://gitea.example.com/api/packages/testuser/rpm/centos/el7/upload @@ -83,17 +99,22 @@ To delete an RPM package perform a HTTP DELETE operation. This will delete the p DELETE https://gitea.example.com/api/packages/{owner}/rpm/{group}/package/{package_name}/{package_version}/{architecture} ``` -| Parameter | Description | -|-------------------|----------------------------| -| `owner` | The owner of the package. | -| `group` | The package group . | -| `package_name` | The package name. | -| `package_version` | The package version. | -| `architecture` | The package architecture. | +| Parameter | Description | +| ----------------- | ----------- | +| `owner` | The owner of the package. | +| `group` | Optional: The package group. | +| `package_name` | The package name. | +| `package_version` | The package version. | +| `architecture` | The package architecture. | Example request using HTTP Basic authentication: ```shell +# without a group +curl --user your_username:your_token_or_password -X DELETE \ + https://gitea.example.com/api/packages/testuser/rpm/package/test-package/1.0.0/x86_64 + +# with the group 'centos/el7' curl --user your_username:your_token_or_password -X DELETE \ https://gitea.example.com/api/packages/testuser/rpm/centos/el7/package/test-package/1.0.0/x86_64 ``` diff --git a/models/packages/package.go b/models/packages/package.go index 380a076f9d..65a2574150 100644 --- a/models/packages/package.go +++ b/models/packages/package.go @@ -191,18 +191,18 @@ type Package struct { func TryInsertPackage(ctx context.Context, p *Package) (*Package, error) { e := db.GetEngine(ctx) - key := &Package{ - OwnerID: p.OwnerID, - Type: p.Type, - LowerName: p.LowerName, - } + existing := &Package{} - has, err := e.Get(key) + has, err := e.Where(builder.Eq{ + "owner_id": p.OwnerID, + "type": p.Type, + "lower_name": p.LowerName, + }).Get(existing) if err != nil { return nil, err } if has { - return key, ErrDuplicatePackage + return existing, ErrDuplicatePackage } if _, err = e.Insert(p); err != nil { return nil, err diff --git a/models/packages/package_blob.go b/models/packages/package_blob.go index d1f470d520..d9c30b6533 100644 --- a/models/packages/package_blob.go +++ b/models/packages/package_blob.go @@ -41,12 +41,20 @@ type PackageBlob struct { func GetOrInsertBlob(ctx context.Context, pb *PackageBlob) (*PackageBlob, bool, error) { e := db.GetEngine(ctx) - has, err := e.Get(pb) + existing := &PackageBlob{} + + has, err := e.Where(builder.Eq{ + "size": pb.Size, + "hash_md5": pb.HashMD5, + "hash_sha1": pb.HashSHA1, + "hash_sha256": pb.HashSHA256, + "hash_sha512": pb.HashSHA512, + }).Get(existing) if err != nil { return nil, false, err } if has { - return pb, true, nil + return existing, true, nil } if _, err = e.Insert(pb); err != nil { return nil, false, err diff --git a/models/packages/package_file.go b/models/packages/package_file.go index 1c2c9ac072..1bb6b57a34 100644 --- a/models/packages/package_file.go +++ b/models/packages/package_file.go @@ -46,18 +46,18 @@ type PackageFile struct { func TryInsertFile(ctx context.Context, pf *PackageFile) (*PackageFile, error) { e := db.GetEngine(ctx) - key := &PackageFile{ - VersionID: pf.VersionID, - LowerName: pf.LowerName, - CompositeKey: pf.CompositeKey, - } + existing := &PackageFile{} - has, err := e.Get(key) + has, err := e.Where(builder.Eq{ + "version_id": pf.VersionID, + "lower_name": pf.LowerName, + "composite_key": pf.CompositeKey, + }).Get(existing) if err != nil { return nil, err } if has { - return pf, ErrDuplicatePackageFile + return existing, ErrDuplicatePackageFile } if _, err = e.Insert(pf); err != nil { return nil, err @@ -93,13 +93,13 @@ func GetFileForVersionByName(ctx context.Context, versionID int64, name, key str return nil, ErrPackageFileNotExist } - pf := &PackageFile{ - VersionID: versionID, - LowerName: strings.ToLower(name), - CompositeKey: key, - } + pf := &PackageFile{} - has, err := db.GetEngine(ctx).Get(pf) + has, err := db.GetEngine(ctx).Where(builder.Eq{ + "version_id": versionID, + "lower_name": strings.ToLower(name), + "composite_key": key, + }).Get(pf) if err != nil { return nil, err } diff --git a/models/packages/package_version.go b/models/packages/package_version.go index 9999fc4dab..8fc475691b 100644 --- a/models/packages/package_version.go +++ b/models/packages/package_version.go @@ -39,17 +39,17 @@ type PackageVersion struct { func GetOrInsertVersion(ctx context.Context, pv *PackageVersion) (*PackageVersion, error) { e := db.GetEngine(ctx) - key := &PackageVersion{ - PackageID: pv.PackageID, - LowerVersion: pv.LowerVersion, - } + existing := &PackageVersion{} - has, err := e.Get(key) + has, err := e.Where(builder.Eq{ + "package_id": pv.PackageID, + "lower_version": pv.LowerVersion, + }).Get(existing) if err != nil { return nil, err } if has { - return key, ErrDuplicatePackageVersion + return existing, ErrDuplicatePackageVersion } if _, err = e.Insert(pv); err != nil { return nil, err diff --git a/models/packages/rpm/search.go b/models/packages/rpm/search.go new file mode 100644 index 0000000000..e697421b49 --- /dev/null +++ b/models/packages/rpm/search.go @@ -0,0 +1,23 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package rpm + +import ( + "context" + + packages_model "code.gitea.io/gitea/models/packages" + rpm_module "code.gitea.io/gitea/modules/packages/rpm" +) + +// GetGroups gets all available groups +func GetGroups(ctx context.Context, ownerID int64) ([]string, error) { + return packages_model.GetDistinctPropertyValues( + ctx, + packages_model.TypeRpm, + ownerID, + packages_model.PropertyTypeFile, + rpm_module.PropertyGroup, + nil, + ) +} diff --git a/modules/packages/rpm/metadata.go b/modules/packages/rpm/metadata.go index 1ba4c73e8d..7fc47a53e6 100644 --- a/modules/packages/rpm/metadata.go +++ b/modules/packages/rpm/metadata.go @@ -15,7 +15,10 @@ import ( ) const ( - PropertyMetadata = "rpm.metadata" + PropertyMetadata = "rpm.metadata" + PropertyGroup = "rpm.group" + PropertyArchitecture = "rpm.architecture" + SettingKeyPrivate = "rpm.key.private" SettingKeyPublic = "rpm.key.public" diff --git a/modules/templates/util_string.go b/modules/templates/util_string.go index 613940ccdc..18a0d5cacc 100644 --- a/modules/templates/util_string.go +++ b/modules/templates/util_string.go @@ -4,7 +4,6 @@ package templates import ( - "regexp" "strings" "code.gitea.io/gitea/modules/base" @@ -26,10 +25,6 @@ func (su *StringUtils) Contains(s, substr string) bool { return strings.Contains(s, substr) } -func (su *StringUtils) ReplaceAllStringRegex(s, regex, new string) string { - return regexp.MustCompile(regex).ReplaceAllString(s, new) -} - func (su *StringUtils) Split(s, sep string) []string { return strings.Split(s, sep) } diff --git a/modules/util/slice.go b/modules/util/slice.go index 6d63ab4a77..a7073fedee 100644 --- a/modules/util/slice.go +++ b/modules/util/slice.go @@ -4,6 +4,7 @@ package util import ( + "cmp" "slices" "strings" ) @@ -45,3 +46,10 @@ func SliceSortedEqual[T comparable](s1, s2 []T) bool { func SliceRemoveAll[T comparable](slice []T, target T) []T { return slices.DeleteFunc(slice, func(t T) bool { return t == target }) } + +// Sorted returns the sorted slice +// Note: The parameter is sorted inline. +func Sorted[S ~[]E, E cmp.Ordered](values S) S { + slices.Sort(values) + return values +} diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 6f9ba8c884..e8345595aa 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3414,6 +3414,9 @@ rpm.registry = Setup this registry from the command line: rpm.distros.redhat = on RedHat based distributions rpm.distros.suse = on SUSE based distributions rpm.install = To install the package, run the following command: +rpm.repository = Repository Info +rpm.repository.architectures = Architectures +rpm.repository.multiple_groups = This package is available in multiple groups. rubygems.install = To install the package using gem, run the following command: rubygems.install2 = or add it to the Gemfile: rubygems.dependencies.runtime = Runtime Dependencies diff --git a/routers/api/packages/api.go b/routers/api/packages/api.go index 9026387129..d990ebb56a 100644 --- a/routers/api/packages/api.go +++ b/routers/api/packages/api.go @@ -512,7 +512,77 @@ func CommonRoutes() *web.Route { r.Get("/files/{id}/{version}/{filename}", pypi.DownloadPackageFile) r.Get("/simple/{id}", pypi.PackageMetadata) }, reqPackageAccess(perm.AccessModeRead)) - r.Group("/rpm", RpmRoutes(r), reqPackageAccess(perm.AccessModeRead)) + r.Group("/rpm", func() { + r.Group("/repository.key", func() { + r.Head("", rpm.GetRepositoryKey) + r.Get("", rpm.GetRepositoryKey) + }) + + var ( + repoPattern = regexp.MustCompile(`\A(.*?)\.repo\z`) + uploadPattern = regexp.MustCompile(`\A(.*?)/upload\z`) + filePattern = regexp.MustCompile(`\A(.*?)/package/([^/]+)/([^/]+)/([^/]+)(?:/([^/]+\.rpm)|)\z`) + repoFilePattern = regexp.MustCompile(`\A(.*?)/repodata/([^/]+)\z`) + ) + + r.Methods("HEAD,GET,PUT,DELETE", "*", func(ctx *context.Context) { + path := ctx.Params("*") + isHead := ctx.Req.Method == "HEAD" + isGetHead := ctx.Req.Method == "HEAD" || ctx.Req.Method == "GET" + isPut := ctx.Req.Method == "PUT" + isDelete := ctx.Req.Method == "DELETE" + + m := repoPattern.FindStringSubmatch(path) + if len(m) == 2 && isGetHead { + ctx.SetParams("group", strings.Trim(m[1], "/")) + rpm.GetRepositoryConfig(ctx) + return + } + + m = repoFilePattern.FindStringSubmatch(path) + if len(m) == 3 && isGetHead { + ctx.SetParams("group", strings.Trim(m[1], "/")) + ctx.SetParams("filename", m[2]) + if isHead { + rpm.CheckRepositoryFileExistence(ctx) + } else { + rpm.GetRepositoryFile(ctx) + } + return + } + + m = uploadPattern.FindStringSubmatch(path) + if len(m) == 2 && isPut { + reqPackageAccess(perm.AccessModeWrite)(ctx) + if ctx.Written() { + return + } + ctx.SetParams("group", strings.Trim(m[1], "/")) + rpm.UploadPackageFile(ctx) + return + } + + m = filePattern.FindStringSubmatch(path) + if len(m) == 6 && (isGetHead || isDelete) { + ctx.SetParams("group", strings.Trim(m[1], "/")) + ctx.SetParams("name", m[2]) + ctx.SetParams("version", m[3]) + ctx.SetParams("architecture", m[4]) + if isGetHead { + rpm.DownloadPackageFile(ctx) + } else { + reqPackageAccess(perm.AccessModeWrite)(ctx) + if ctx.Written() { + return + } + rpm.DeletePackageFile(ctx) + } + return + } + + ctx.Status(http.StatusNotFound) + }) + }, reqPackageAccess(perm.AccessModeRead)) r.Group("/rubygems", func() { r.Get("/specs.4.8.gz", rubygems.EnumeratePackages) r.Get("/latest_specs.4.8.gz", rubygems.EnumeratePackagesLatest) @@ -577,82 +647,6 @@ func CommonRoutes() *web.Route { return r } -// Support for uploading rpm packages with arbitrary depth paths -func RpmRoutes(r *web.Route) func() { - var ( - groupRepoInfo = regexp.MustCompile(`\A((?:/(?:[^/]+))*|)\.repo\z`) - groupUpload = regexp.MustCompile(`\A((?:/(?:[^/]+))*|)/upload\z`) - groupRpm = regexp.MustCompile(`\A((?:/(?:[^/]+))*|)/package/([^/]+)/([^/]+)/([^/]+)(?:/([^/]+\.rpm)|)\z`) - groupMetadata = regexp.MustCompile(`\A((?:/(?:[^/]+))*|)/repodata/([^/]+)\z`) - ) - - return func() { - r.Methods("HEAD,GET,POST,PUT,PATCH,DELETE", "*", func(ctx *context.Context) { - path := ctx.Params("*") - isHead := ctx.Req.Method == "HEAD" - isGetHead := ctx.Req.Method == "HEAD" || ctx.Req.Method == "GET" - isPut := ctx.Req.Method == "PUT" - isDelete := ctx.Req.Method == "DELETE" - - if path == "/repository.key" && isGetHead { - rpm.GetRepositoryKey(ctx) - return - } - - // get repo - m := groupRepoInfo.FindStringSubmatch(path) - if len(m) == 2 && isGetHead { - ctx.SetParams("group", strings.Trim(m[1], "/")) - rpm.GetRepositoryConfig(ctx) - return - } - // get meta - m = groupMetadata.FindStringSubmatch(path) - if len(m) == 3 && isGetHead { - ctx.SetParams("group", strings.Trim(m[1], "/")) - ctx.SetParams("filename", m[2]) - if isHead { - rpm.CheckRepositoryFileExistence(ctx) - } else { - rpm.GetRepositoryFile(ctx) - } - return - } - // upload - m = groupUpload.FindStringSubmatch(path) - if len(m) == 2 && isPut { - reqPackageAccess(perm.AccessModeWrite)(ctx) - if ctx.Written() { - return - } - ctx.SetParams("group", strings.Trim(m[1], "/")) - rpm.UploadPackageFile(ctx) - return - } - // rpm down/delete - m = groupRpm.FindStringSubmatch(path) - if len(m) == 6 { - ctx.SetParams("group", strings.Trim(m[1], "/")) - ctx.SetParams("name", m[2]) - ctx.SetParams("version", m[3]) - ctx.SetParams("architecture", m[4]) - if isGetHead { - rpm.DownloadPackageFile(ctx) - return - } else if isDelete { - reqPackageAccess(perm.AccessModeWrite)(ctx) - if ctx.Written() { - return - } - rpm.DeletePackageFile(ctx) - } - } - // default - ctx.Status(http.StatusNotFound) - }) - } -} - // ContainerRoutes provides endpoints that implement the OCI API to serve containers // These have to be mounted on `/v2/...` to comply with the OCI spec: // https://github.com/opencontainers/distribution-spec/blob/main/spec.md diff --git a/routers/api/packages/rpm/rpm.go b/routers/api/packages/rpm/rpm.go index 75d19e2b43..5d06680552 100644 --- a/routers/api/packages/rpm/rpm.go +++ b/routers/api/packages/rpm/rpm.go @@ -34,13 +34,17 @@ func apiError(ctx *context.Context, status int, obj any) { // https://dnf.readthedocs.io/en/latest/conf_ref.html func GetRepositoryConfig(ctx *context.Context) { group := ctx.Params("group") + + var groupParts []string if group != "" { - group = fmt.Sprintf("/%s", group) + groupParts = strings.Split(group, "/") } + url := fmt.Sprintf("%sapi/packages/%s/rpm", setting.AppURL, ctx.Package.Owner.Name) - ctx.PlainText(http.StatusOK, `[gitea-`+ctx.Package.Owner.LowerName+strings.ReplaceAll(group, "/", "-")+`] -name=`+ctx.Package.Owner.Name+` - `+setting.AppName+strings.ReplaceAll(group, "/", " - ")+` -baseurl=`+url+group+`/ + + ctx.PlainText(http.StatusOK, `[gitea-`+strings.Join(append([]string{ctx.Package.Owner.LowerName}, groupParts...), "-")+`] +name=`+strings.Join(append([]string{ctx.Package.Owner.Name, setting.AppName}, groupParts...), " - ")+` +baseurl=`+strings.Join(append([]string{url}, groupParts...), "/")+` enabled=1 gpgcheck=1 gpgkey=`+url+`/repository.key`) @@ -157,7 +161,7 @@ func UploadPackageFile(ctx *context.Context) { Owner: ctx.Package.Owner, PackageType: packages_model.TypeRpm, Name: pck.Name, - Version: strings.Trim(fmt.Sprintf("%s/%s", group, pck.Version), "/"), + Version: pck.Version, }, Creator: ctx.Doer, Metadata: pck.VersionMetadata, @@ -171,7 +175,9 @@ func UploadPackageFile(ctx *context.Context) { Data: buf, IsLead: true, Properties: map[string]string{ - rpm_module.PropertyMetadata: string(fileMetadataRaw), + rpm_module.PropertyGroup: group, + rpm_module.PropertyArchitecture: pck.FileMetadata.Architecture, + rpm_module.PropertyMetadata: string(fileMetadataRaw), }, }, ) @@ -187,7 +193,7 @@ func UploadPackageFile(ctx *context.Context) { return } - if err := rpm_service.BuildRepositoryFiles(ctx, ctx.Package.Owner.ID, group); err != nil { + if err := rpm_service.BuildSpecificRepositoryFiles(ctx, ctx.Package.Owner.ID, group); err != nil { apiError(ctx, http.StatusInternalServerError, err) return } @@ -196,20 +202,20 @@ func UploadPackageFile(ctx *context.Context) { } func DownloadPackageFile(ctx *context.Context) { - group := ctx.Params("group") name := ctx.Params("name") version := ctx.Params("version") + s, u, pf, err := packages_service.GetFileStreamByPackageNameAndVersion( ctx, &packages_service.PackageInfo{ Owner: ctx.Package.Owner, PackageType: packages_model.TypeRpm, Name: name, - Version: strings.Trim(fmt.Sprintf("%s/%s", group, version), "/"), + Version: version, }, &packages_service.PackageFileInfo{ Filename: fmt.Sprintf("%s-%s.%s.rpm", name, version, ctx.Params("architecture")), - CompositeKey: group, + CompositeKey: ctx.Params("group"), }, ) if err != nil { @@ -229,6 +235,7 @@ func DeletePackageFile(webctx *context.Context) { name := webctx.Params("name") version := webctx.Params("version") architecture := webctx.Params("architecture") + var pd *packages_model.PackageDescriptor err := db.WithTx(webctx, func(ctx stdctx.Context) error { @@ -236,7 +243,7 @@ func DeletePackageFile(webctx *context.Context) { webctx.Package.Owner.ID, packages_model.TypeRpm, name, - strings.Trim(fmt.Sprintf("%s/%s", group, version), "/"), + version, ) if err != nil { return err @@ -286,7 +293,7 @@ func DeletePackageFile(webctx *context.Context) { notify_service.PackageDelete(webctx, webctx.Doer, pd) } - if err := rpm_service.BuildRepositoryFiles(webctx, webctx.Package.Owner.ID, group); err != nil { + if err := rpm_service.BuildSpecificRepositoryFiles(webctx, webctx.Package.Owner.ID, group); err != nil { apiError(webctx, http.StatusInternalServerError, err) return } diff --git a/routers/web/admin/packages.go b/routers/web/admin/packages.go index f4e1a93a22..35ce215be4 100644 --- a/routers/web/admin/packages.go +++ b/routers/web/admin/packages.go @@ -108,6 +108,6 @@ func CleanupExpiredData(ctx *context.Context) { return } - ctx.Flash.Success(ctx.Tr("packages.cleanup.success")) + ctx.Flash.Success(ctx.Tr("admin.packages.cleanup.success")) ctx.Redirect(setting.AppSubURL + "/admin/packages") } diff --git a/routers/web/user/package.go b/routers/web/user/package.go index d8da6a192e..708af3e43c 100644 --- a/routers/web/user/package.go +++ b/routers/web/user/package.go @@ -19,6 +19,7 @@ import ( "code.gitea.io/gitea/modules/log" alpine_module "code.gitea.io/gitea/modules/packages/alpine" debian_module "code.gitea.io/gitea/modules/packages/debian" + rpm_module "code.gitea.io/gitea/modules/packages/rpm" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" @@ -195,9 +196,9 @@ func ViewPackageVersion(ctx *context.Context) { } } - ctx.Data["Branches"] = branches.Values() - ctx.Data["Repositories"] = repositories.Values() - ctx.Data["Architectures"] = architectures.Values() + ctx.Data["Branches"] = util.Sorted(branches.Values()) + ctx.Data["Repositories"] = util.Sorted(repositories.Values()) + ctx.Data["Architectures"] = util.Sorted(architectures.Values()) case packages_model.TypeDebian: distributions := make(container.Set[string]) components := make(container.Set[string]) @@ -216,9 +217,26 @@ func ViewPackageVersion(ctx *context.Context) { } } - ctx.Data["Distributions"] = distributions.Values() - ctx.Data["Components"] = components.Values() - ctx.Data["Architectures"] = architectures.Values() + ctx.Data["Distributions"] = util.Sorted(distributions.Values()) + ctx.Data["Components"] = util.Sorted(components.Values()) + ctx.Data["Architectures"] = util.Sorted(architectures.Values()) + case packages_model.TypeRpm: + groups := make(container.Set[string]) + architectures := make(container.Set[string]) + + for _, f := range pd.Files { + for _, pp := range f.Properties { + switch pp.Name { + case rpm_module.PropertyGroup: + groups.Add(pp.Value) + case rpm_module.PropertyArchitecture: + architectures.Add(pp.Value) + } + } + } + + ctx.Data["Groups"] = util.Sorted(groups.Values()) + ctx.Data["Architectures"] = util.Sorted(architectures.Values()) } var ( diff --git a/services/packages/cleanup/cleanup.go b/services/packages/cleanup/cleanup.go index 04ee6c4419..0ff8077bc9 100644 --- a/services/packages/cleanup/cleanup.go +++ b/services/packages/cleanup/cleanup.go @@ -19,6 +19,7 @@ import ( cargo_service "code.gitea.io/gitea/services/packages/cargo" container_service "code.gitea.io/gitea/services/packages/container" debian_service "code.gitea.io/gitea/services/packages/debian" + rpm_service "code.gitea.io/gitea/services/packages/rpm" ) // Task method to execute cleanup rules and cleanup expired package data @@ -127,6 +128,10 @@ func ExecuteCleanupRules(outerCtx context.Context) error { if err := alpine_service.BuildAllRepositoryFiles(ctx, pcr.OwnerID); err != nil { return fmt.Errorf("CleanupRule [%d]: alpine.BuildAllRepositoryFiles failed: %w", pcr.ID, err) } + } else if pcr.Type == packages_model.TypeRpm { + if err := rpm_service.BuildAllRepositoryFiles(ctx, pcr.OwnerID); err != nil { + return fmt.Errorf("CleanupRule [%d]: rpm.BuildAllRepositoryFiles failed: %w", pcr.ID, err) + } } } return nil diff --git a/services/packages/rpm/repository.go b/services/packages/rpm/repository.go index 7a49efde4f..c52c8a5dd9 100644 --- a/services/packages/rpm/repository.go +++ b/services/packages/rpm/repository.go @@ -18,6 +18,7 @@ import ( "time" packages_model "code.gitea.io/gitea/models/packages" + rpm_model "code.gitea.io/gitea/models/packages/rpm" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/json" packages_module "code.gitea.io/gitea/modules/packages" @@ -96,6 +97,39 @@ func generateKeypair() (string, string, error) { return priv.String(), pub.String(), nil } +// BuildAllRepositoryFiles (re)builds all repository files for every available group +func BuildAllRepositoryFiles(ctx context.Context, ownerID int64) error { + pv, err := GetOrCreateRepositoryVersion(ctx, ownerID) + if err != nil { + return err + } + + // 1. Delete all existing repository files + pfs, err := packages_model.GetFilesByVersionID(ctx, pv.ID) + if err != nil { + return err + } + + for _, pf := range pfs { + if err := packages_service.DeletePackageFile(ctx, pf); err != nil { + return err + } + } + + // 2. (Re)Build repository files for existing packages + groups, err := rpm_model.GetGroups(ctx, ownerID) + if err != nil { + return err + } + for _, group := range groups { + if err := BuildSpecificRepositoryFiles(ctx, ownerID, group); err != nil { + return fmt.Errorf("failed to build repository files [%s]: %w", group, err) + } + } + + return nil +} + type repoChecksum struct { Value string `xml:",chardata"` Type string `xml:"type,attr"` @@ -126,7 +160,7 @@ type packageData struct { type packageCache = map[*packages_model.PackageFile]*packageData // BuildSpecificRepositoryFiles builds metadata files for the repository -func BuildRepositoryFiles(ctx context.Context, ownerID int64, compositeKey string) error { +func BuildSpecificRepositoryFiles(ctx context.Context, ownerID int64, group string) error { pv, err := GetOrCreateRepositoryVersion(ctx, ownerID) if err != nil { return err @@ -136,7 +170,7 @@ func BuildRepositoryFiles(ctx context.Context, ownerID int64, compositeKey strin OwnerID: ownerID, PackageType: packages_model.TypeRpm, Query: "%.rpm", - CompositeKey: compositeKey, + CompositeKey: group, }) if err != nil { return err @@ -195,15 +229,15 @@ func BuildRepositoryFiles(ctx context.Context, ownerID int64, compositeKey strin cache[pf] = pd } - primary, err := buildPrimary(ctx, pv, pfs, cache, compositeKey) + primary, err := buildPrimary(ctx, pv, pfs, cache, group) if err != nil { return err } - filelists, err := buildFilelists(ctx, pv, pfs, cache, compositeKey) + filelists, err := buildFilelists(ctx, pv, pfs, cache, group) if err != nil { return err } - other, err := buildOther(ctx, pv, pfs, cache, compositeKey) + other, err := buildOther(ctx, pv, pfs, cache, group) if err != nil { return err } @@ -217,12 +251,12 @@ func BuildRepositoryFiles(ctx context.Context, ownerID int64, compositeKey strin filelists, other, }, - compositeKey, + group, ) } // https://docs.pulpproject.org/en/2.19/plugins/pulp_rpm/tech-reference/rpm.html#repomd-xml -func buildRepomd(ctx context.Context, pv *packages_model.PackageVersion, ownerID int64, data []*repoData, compositeKey string) error { +func buildRepomd(ctx context.Context, pv *packages_model.PackageVersion, ownerID int64, data []*repoData, group string) error { type Repomd struct { XMLName xml.Name `xml:"repomd"` Xmlns string `xml:"xmlns,attr"` @@ -278,7 +312,7 @@ func buildRepomd(ctx context.Context, pv *packages_model.PackageVersion, ownerID &packages_service.PackageFileCreationInfo{ PackageFileInfo: packages_service.PackageFileInfo{ Filename: file.Name, - CompositeKey: compositeKey, + CompositeKey: group, }, Creator: user_model.NewGhostUser(), Data: file.Data, @@ -295,7 +329,7 @@ func buildRepomd(ctx context.Context, pv *packages_model.PackageVersion, ownerID } // https://docs.pulpproject.org/en/2.19/plugins/pulp_rpm/tech-reference/rpm.html#primary-xml -func buildPrimary(ctx context.Context, pv *packages_model.PackageVersion, pfs []*packages_model.PackageFile, c packageCache, compositeKey string) (*repoData, error) { +func buildPrimary(ctx context.Context, pv *packages_model.PackageVersion, pfs []*packages_model.PackageFile, c packageCache, group string) (*repoData, error) { type Version struct { Epoch string `xml:"epoch,attr"` Version string `xml:"ver,attr"` @@ -434,11 +468,11 @@ func buildPrimary(ctx context.Context, pv *packages_model.PackageVersion, pfs [] XmlnsRpm: "http://linux.duke.edu/metadata/rpm", PackageCount: len(pfs), Packages: packages, - }, compositeKey) + }, group) } // https://docs.pulpproject.org/en/2.19/plugins/pulp_rpm/tech-reference/rpm.html#filelists-xml -func buildFilelists(ctx context.Context, pv *packages_model.PackageVersion, pfs []*packages_model.PackageFile, c packageCache, compositeKey string) (*repoData, error) { //nolint:dupl +func buildFilelists(ctx context.Context, pv *packages_model.PackageVersion, pfs []*packages_model.PackageFile, c packageCache, group string) (*repoData, error) { //nolint:dupl type Version struct { Epoch string `xml:"epoch,attr"` Version string `xml:"ver,attr"` @@ -481,12 +515,11 @@ func buildFilelists(ctx context.Context, pv *packages_model.PackageVersion, pfs Xmlns: "http://linux.duke.edu/metadata/other", PackageCount: len(pfs), Packages: packages, - }, - compositeKey) + }, group) } // https://docs.pulpproject.org/en/2.19/plugins/pulp_rpm/tech-reference/rpm.html#other-xml -func buildOther(ctx context.Context, pv *packages_model.PackageVersion, pfs []*packages_model.PackageFile, c packageCache, compositeKey string) (*repoData, error) { //nolint:dupl +func buildOther(ctx context.Context, pv *packages_model.PackageVersion, pfs []*packages_model.PackageFile, c packageCache, group string) (*repoData, error) { //nolint:dupl type Version struct { Epoch string `xml:"epoch,attr"` Version string `xml:"ver,attr"` @@ -529,7 +562,7 @@ func buildOther(ctx context.Context, pv *packages_model.PackageVersion, pfs []*p Xmlns: "http://linux.duke.edu/metadata/other", PackageCount: len(pfs), Packages: packages, - }, compositeKey) + }, group) } // writtenCounter counts all written bytes @@ -549,8 +582,10 @@ func (wc *writtenCounter) Written() int64 { return wc.written } -func addDataAsFileToRepo(ctx context.Context, pv *packages_model.PackageVersion, filetype string, obj any, compositeKey string) (*repoData, error) { +func addDataAsFileToRepo(ctx context.Context, pv *packages_model.PackageVersion, filetype string, obj any, group string) (*repoData, error) { content, _ := packages_module.NewHashedBuffer() + defer content.Close() + gzw := gzip.NewWriter(content) wc := &writtenCounter{} h := sha256.New() @@ -574,7 +609,7 @@ func addDataAsFileToRepo(ctx context.Context, pv *packages_model.PackageVersion, &packages_service.PackageFileCreationInfo{ PackageFileInfo: packages_service.PackageFileInfo{ Filename: filename, - CompositeKey: compositeKey, + CompositeKey: group, }, Creator: user_model.NewGhostUser(), Data: content, diff --git a/templates/package/content/rpm.tmpl b/templates/package/content/rpm.tmpl index 4fd54a3197..0f128fd3fb 100644 --- a/templates/package/content/rpm.tmpl +++ b/templates/package/content/rpm.tmpl @@ -4,15 +4,21 @@
-
# {{ctx.Locale.Tr "packages.rpm.distros.redhat"}}
-{{$group_name:= StringUtils.ReplaceAllStringRegex .PackageDescriptor.Version.Version "(/[^/]+|[^/]*)\\z" "" -}}
-{{- if $group_name -}}
-{{- $group_name = (print "/" $group_name) -}}
-{{- end -}}
-dnf config-manager --add-repo 
+				
{{- if gt (len .Groups) 1 -}}
+# {{ctx.Locale.Tr "packages.rpm.repository.multiple_groups"}}
+
+{{end -}}
+# {{ctx.Locale.Tr "packages.rpm.distros.redhat"}}
+{{- range $group := .Groups}}
+	{{- if $group}}{{$group = print "/" $group}}{{end}}
+dnf config-manager --add-repo 
+{{- end}}
 
 # {{ctx.Locale.Tr "packages.rpm.distros.suse"}}
-zypper addrepo 
+{{- range $group := .Groups}} + {{- if $group}}{{$group = print "/" $group}}{{end}} +zypper addrepo +{{- end}}
@@ -30,6 +36,18 @@ zypper install {{$.PackageDescriptor.Package.Name}}
+

{{ctx.Locale.Tr "packages.rpm.repository"}}

+
+ + + + + + + +
{{ctx.Locale.Tr "packages.rpm.repository.architectures"}}
{{StringUtils.Join .Architectures ", "}}
+
+ {{if or .PackageDescriptor.Metadata.Summary .PackageDescriptor.Metadata.Description}}

{{ctx.Locale.Tr "packages.about"}}

{{if .PackageDescriptor.Metadata.Summary}}
{{.PackageDescriptor.Metadata.Summary}}
{{end}} diff --git a/tests/integration/api_packages_rpm_test.go b/tests/integration/api_packages_rpm_test.go index 822b0b040e..1dcec6099e 100644 --- a/tests/integration/api_packages_rpm_test.go +++ b/tests/integration/api_packages_rpm_test.go @@ -12,6 +12,7 @@ import ( "io" "net/http" "net/http/httptest" + "strings" "testing" "code.gitea.io/gitea/models/db" @@ -20,6 +21,7 @@ import ( user_model "code.gitea.io/gitea/models/user" rpm_module "code.gitea.io/gitea/modules/packages/rpm" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/tests" "github.com/stretchr/testify/assert" @@ -73,346 +75,362 @@ Mu0UFYgZ/bYnuvn/vz4wtCz8qMwsHUvP0PX3tbYFUctAPdrY6tiiDtcCddDECahx7SuVNP5dpmb5 rootURL := fmt.Sprintf("/api/packages/%s/rpm", user.Name) - t.Run("RepositoryConfig", func(t *testing.T) { - defer tests.PrintCurrentTest(t)() + for _, group := range []string{"", "el9", "el9/stable"} { + t.Run(fmt.Sprintf("[Group:%s]", group), func(t *testing.T) { + var groupParts []string + if group != "" { + groupParts = strings.Split(group, "/") + } + groupURL := strings.Join(append([]string{rootURL}, groupParts...), "/") - req := NewRequest(t, "GET", rootURL+"/el9/stable.repo") - resp := MakeRequest(t, req, http.StatusOK) + t.Run("RepositoryConfig", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() - expected := fmt.Sprintf(`[gitea-%s-el9-stable] -name=%s - %s - el9 - stable -baseurl=%sapi/packages/%s/rpm/el9/stable/ + req := NewRequest(t, "GET", groupURL+".repo") + resp := MakeRequest(t, req, http.StatusOK) + + expected := fmt.Sprintf(`[gitea-%s] +name=%s +baseurl=%s enabled=1 gpgcheck=1 -gpgkey=%sapi/packages/%s/rpm/repository.key`, user.Name, user.Name, setting.AppName, setting.AppURL, user.Name, setting.AppURL, user.Name) +gpgkey=%sapi/packages/%s/rpm/repository.key`, + strings.Join(append([]string{user.LowerName}, groupParts...), "-"), + strings.Join(append([]string{user.Name, setting.AppName}, groupParts...), " - "), + util.URLJoin(setting.AppURL, groupURL), + setting.AppURL, + user.Name, + ) - assert.Equal(t, expected, resp.Body.String()) - }) + assert.Equal(t, expected, resp.Body.String()) + }) - t.Run("RepositoryKey", func(t *testing.T) { - defer tests.PrintCurrentTest(t)() + t.Run("RepositoryKey", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() - req := NewRequest(t, "GET", rootURL+"/repository.key") - resp := MakeRequest(t, req, http.StatusOK) + req := NewRequest(t, "GET", rootURL+"/repository.key") + resp := MakeRequest(t, req, http.StatusOK) - assert.Equal(t, "application/pgp-keys", resp.Header().Get("Content-Type")) - assert.Contains(t, resp.Body.String(), "-----BEGIN PGP PUBLIC KEY BLOCK-----") - }) + assert.Equal(t, "application/pgp-keys", resp.Header().Get("Content-Type")) + assert.Contains(t, resp.Body.String(), "-----BEGIN PGP PUBLIC KEY BLOCK-----") + }) - t.Run("Upload", func(t *testing.T) { - url := rootURL + "/el9/stable/upload" + t.Run("Upload", func(t *testing.T) { + url := groupURL + "/upload" - req := NewRequestWithBody(t, "PUT", url, bytes.NewReader(content)) - MakeRequest(t, req, http.StatusUnauthorized) + req := NewRequestWithBody(t, "PUT", url, bytes.NewReader(content)) + MakeRequest(t, req, http.StatusUnauthorized) - req = NewRequestWithBody(t, "PUT", url, bytes.NewReader(content)). - AddBasicAuth(user.Name) - MakeRequest(t, req, http.StatusCreated) + req = NewRequestWithBody(t, "PUT", url, bytes.NewReader(content)). + AddBasicAuth(user.Name) + MakeRequest(t, req, http.StatusCreated) - pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeRpm) - assert.NoError(t, err) - assert.Len(t, pvs, 1) + pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeRpm) + assert.NoError(t, err) + assert.Len(t, pvs, 1) - pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0]) - assert.NoError(t, err) - assert.Nil(t, pd.SemVer) - assert.IsType(t, &rpm_module.VersionMetadata{}, pd.Metadata) - assert.Equal(t, packageName, pd.Package.Name) - assert.Equal(t, fmt.Sprintf("el9/stable/%s", packageVersion), pd.Version.Version) + pd, err := packages.GetPackageDescriptor(db.DefaultContext, pvs[0]) + assert.NoError(t, err) + assert.Nil(t, pd.SemVer) + assert.IsType(t, &rpm_module.VersionMetadata{}, pd.Metadata) + assert.Equal(t, packageName, pd.Package.Name) + assert.Equal(t, packageVersion, pd.Version.Version) - pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID) - assert.NoError(t, err) - assert.Len(t, pfs, 1) - assert.Equal(t, fmt.Sprintf("%s-%s.%s.rpm", packageName, packageVersion, packageArchitecture), pfs[0].Name) - assert.True(t, pfs[0].IsLead) + pfs, err := packages.GetFilesByVersionID(db.DefaultContext, pvs[0].ID) + assert.NoError(t, err) + assert.Len(t, pfs, 1) + assert.Equal(t, fmt.Sprintf("%s-%s.%s.rpm", packageName, packageVersion, packageArchitecture), pfs[0].Name) + assert.True(t, pfs[0].IsLead) - pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID) - assert.NoError(t, err) - assert.Equal(t, int64(len(content)), pb.Size) + pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID) + assert.NoError(t, err) + assert.Equal(t, int64(len(content)), pb.Size) - req = NewRequestWithBody(t, "PUT", url, bytes.NewReader(content)). - AddBasicAuth(user.Name) - MakeRequest(t, req, http.StatusConflict) - }) + req = NewRequestWithBody(t, "PUT", url, bytes.NewReader(content)). + AddBasicAuth(user.Name) + MakeRequest(t, req, http.StatusConflict) + }) - t.Run("Download", func(t *testing.T) { - defer tests.PrintCurrentTest(t)() + t.Run("Download", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() - req := NewRequest(t, "GET", fmt.Sprintf("%s/el9/stable/package/%s/%s/%s", rootURL, packageName, packageVersion, packageArchitecture)) - resp := MakeRequest(t, req, http.StatusOK) + req := NewRequest(t, "GET", fmt.Sprintf("%s/package/%s/%s/%s", groupURL, packageName, packageVersion, packageArchitecture)) + resp := MakeRequest(t, req, http.StatusOK) - assert.Equal(t, content, resp.Body.Bytes()) - }) + assert.Equal(t, content, resp.Body.Bytes()) + }) - t.Run("Repository", func(t *testing.T) { - defer tests.PrintCurrentTest(t)() + t.Run("Repository", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() - url := rootURL + "/el9/stable/repodata" + url := groupURL + "/repodata" - req := NewRequest(t, "HEAD", url+"/dummy.xml") - MakeRequest(t, req, http.StatusNotFound) + req := NewRequest(t, "HEAD", url+"/dummy.xml") + MakeRequest(t, req, http.StatusNotFound) - req = NewRequest(t, "GET", url+"/dummy.xml") - MakeRequest(t, req, http.StatusNotFound) + req = NewRequest(t, "GET", url+"/dummy.xml") + MakeRequest(t, req, http.StatusNotFound) - t.Run("repomd.xml", func(t *testing.T) { - defer tests.PrintCurrentTest(t)() + t.Run("repomd.xml", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() - req = NewRequest(t, "HEAD", url+"/repomd.xml") - MakeRequest(t, req, http.StatusOK) + req = NewRequest(t, "HEAD", url+"/repomd.xml") + MakeRequest(t, req, http.StatusOK) - req = NewRequest(t, "GET", url+"/repomd.xml") - resp := MakeRequest(t, req, http.StatusOK) + req = NewRequest(t, "GET", url+"/repomd.xml") + resp := MakeRequest(t, req, http.StatusOK) - type Repomd struct { - XMLName xml.Name `xml:"repomd"` - Xmlns string `xml:"xmlns,attr"` - XmlnsRpm string `xml:"xmlns:rpm,attr"` - Data []struct { - Type string `xml:"type,attr"` - Checksum struct { - Value string `xml:",chardata"` - Type string `xml:"type,attr"` - } `xml:"checksum"` - OpenChecksum struct { - Value string `xml:",chardata"` - Type string `xml:"type,attr"` - } `xml:"open-checksum"` - Location struct { - Href string `xml:"href,attr"` - } `xml:"location"` - Timestamp int64 `xml:"timestamp"` - Size int64 `xml:"size"` - OpenSize int64 `xml:"open-size"` - } `xml:"data"` - } + type Repomd struct { + XMLName xml.Name `xml:"repomd"` + Xmlns string `xml:"xmlns,attr"` + XmlnsRpm string `xml:"xmlns:rpm,attr"` + Data []struct { + Type string `xml:"type,attr"` + Checksum struct { + Value string `xml:",chardata"` + Type string `xml:"type,attr"` + } `xml:"checksum"` + OpenChecksum struct { + Value string `xml:",chardata"` + Type string `xml:"type,attr"` + } `xml:"open-checksum"` + Location struct { + Href string `xml:"href,attr"` + } `xml:"location"` + Timestamp int64 `xml:"timestamp"` + Size int64 `xml:"size"` + OpenSize int64 `xml:"open-size"` + } `xml:"data"` + } - var result Repomd - decodeXML(t, resp, &result) + var result Repomd + decodeXML(t, resp, &result) - assert.Len(t, result.Data, 3) - for _, d := range result.Data { - assert.Equal(t, "sha256", d.Checksum.Type) - assert.NotEmpty(t, d.Checksum.Value) - assert.Equal(t, "sha256", d.OpenChecksum.Type) - assert.NotEmpty(t, d.OpenChecksum.Value) - assert.NotEqual(t, d.Checksum.Value, d.OpenChecksum.Value) - assert.Greater(t, d.OpenSize, d.Size) + assert.Len(t, result.Data, 3) + for _, d := range result.Data { + assert.Equal(t, "sha256", d.Checksum.Type) + assert.NotEmpty(t, d.Checksum.Value) + assert.Equal(t, "sha256", d.OpenChecksum.Type) + assert.NotEmpty(t, d.OpenChecksum.Value) + assert.NotEqual(t, d.Checksum.Value, d.OpenChecksum.Value) + assert.Greater(t, d.OpenSize, d.Size) - switch d.Type { - case "primary": - assert.EqualValues(t, 722, d.Size) - assert.EqualValues(t, 1759, d.OpenSize) - assert.Equal(t, "repodata/primary.xml.gz", d.Location.Href) - case "filelists": - assert.EqualValues(t, 257, d.Size) - assert.EqualValues(t, 326, d.OpenSize) - assert.Equal(t, "repodata/filelists.xml.gz", d.Location.Href) - case "other": - assert.EqualValues(t, 306, d.Size) - assert.EqualValues(t, 394, d.OpenSize) - assert.Equal(t, "repodata/other.xml.gz", d.Location.Href) + switch d.Type { + case "primary": + assert.EqualValues(t, 722, d.Size) + assert.EqualValues(t, 1759, d.OpenSize) + assert.Equal(t, "repodata/primary.xml.gz", d.Location.Href) + case "filelists": + assert.EqualValues(t, 257, d.Size) + assert.EqualValues(t, 326, d.OpenSize) + assert.Equal(t, "repodata/filelists.xml.gz", d.Location.Href) + case "other": + assert.EqualValues(t, 306, d.Size) + assert.EqualValues(t, 394, d.OpenSize) + assert.Equal(t, "repodata/other.xml.gz", d.Location.Href) + } + } + }) + + t.Run("repomd.xml.asc", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req = NewRequest(t, "GET", url+"/repomd.xml.asc") + resp := MakeRequest(t, req, http.StatusOK) + + assert.Contains(t, resp.Body.String(), "-----BEGIN PGP SIGNATURE-----") + }) + + decodeGzipXML := func(t testing.TB, resp *httptest.ResponseRecorder, v any) { + t.Helper() + + zr, err := gzip.NewReader(resp.Body) + assert.NoError(t, err) + + assert.NoError(t, xml.NewDecoder(zr).Decode(v)) } - } + + t.Run("primary.xml.gz", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req = NewRequest(t, "GET", url+"/primary.xml.gz") + resp := MakeRequest(t, req, http.StatusOK) + + type EntryList struct { + Entries []*rpm_module.Entry `xml:"entry"` + } + + type Metadata struct { + XMLName xml.Name `xml:"metadata"` + Xmlns string `xml:"xmlns,attr"` + XmlnsRpm string `xml:"xmlns:rpm,attr"` + PackageCount int `xml:"packages,attr"` + Packages []struct { + XMLName xml.Name `xml:"package"` + Type string `xml:"type,attr"` + Name string `xml:"name"` + Architecture string `xml:"arch"` + Version struct { + Epoch string `xml:"epoch,attr"` + Version string `xml:"ver,attr"` + Release string `xml:"rel,attr"` + } `xml:"version"` + Checksum struct { + Checksum string `xml:",chardata"` + Type string `xml:"type,attr"` + Pkgid string `xml:"pkgid,attr"` + } `xml:"checksum"` + Summary string `xml:"summary"` + Description string `xml:"description"` + Packager string `xml:"packager"` + URL string `xml:"url"` + Time struct { + File uint64 `xml:"file,attr"` + Build uint64 `xml:"build,attr"` + } `xml:"time"` + Size struct { + Package int64 `xml:"package,attr"` + Installed uint64 `xml:"installed,attr"` + Archive uint64 `xml:"archive,attr"` + } `xml:"size"` + Location struct { + Href string `xml:"href,attr"` + } `xml:"location"` + Format struct { + License string `xml:"license"` + Vendor string `xml:"vendor"` + Group string `xml:"group"` + Buildhost string `xml:"buildhost"` + Sourcerpm string `xml:"sourcerpm"` + Provides EntryList `xml:"provides"` + Requires EntryList `xml:"requires"` + Conflicts EntryList `xml:"conflicts"` + Obsoletes EntryList `xml:"obsoletes"` + Files []*rpm_module.File `xml:"file"` + } `xml:"format"` + } `xml:"package"` + } + + var result Metadata + decodeGzipXML(t, resp, &result) + + assert.EqualValues(t, 1, result.PackageCount) + assert.Len(t, result.Packages, 1) + p := result.Packages[0] + assert.Equal(t, "rpm", p.Type) + assert.Equal(t, packageName, p.Name) + assert.Equal(t, packageArchitecture, p.Architecture) + assert.Equal(t, "YES", p.Checksum.Pkgid) + assert.Equal(t, "sha256", p.Checksum.Type) + assert.Equal(t, "f1d5d2ffcbe4a7568e98b864f40d923ecca084e9b9bcd5977ed6521c46d3fa4c", p.Checksum.Checksum) + assert.Equal(t, "https://gitea.io", p.URL) + assert.EqualValues(t, len(content), p.Size.Package) + assert.EqualValues(t, 13, p.Size.Installed) + assert.EqualValues(t, 272, p.Size.Archive) + assert.Equal(t, fmt.Sprintf("package/%s/%s/%s/%s", packageName, packageVersion, packageArchitecture, fmt.Sprintf("%s-%s.%s.rpm", packageName, packageVersion, packageArchitecture)), p.Location.Href) + f := p.Format + assert.Equal(t, "MIT", f.License) + assert.Len(t, f.Provides.Entries, 2) + assert.Len(t, f.Requires.Entries, 7) + assert.Empty(t, f.Conflicts.Entries) + assert.Empty(t, f.Obsoletes.Entries) + assert.Len(t, f.Files, 1) + }) + + t.Run("filelists.xml.gz", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req = NewRequest(t, "GET", url+"/filelists.xml.gz") + resp := MakeRequest(t, req, http.StatusOK) + + type Filelists struct { + XMLName xml.Name `xml:"filelists"` + Xmlns string `xml:"xmlns,attr"` + PackageCount int `xml:"packages,attr"` + Packages []struct { + Pkgid string `xml:"pkgid,attr"` + Name string `xml:"name,attr"` + Architecture string `xml:"arch,attr"` + Version struct { + Epoch string `xml:"epoch,attr"` + Version string `xml:"ver,attr"` + Release string `xml:"rel,attr"` + } `xml:"version"` + Files []*rpm_module.File `xml:"file"` + } `xml:"package"` + } + + var result Filelists + decodeGzipXML(t, resp, &result) + + assert.EqualValues(t, 1, result.PackageCount) + assert.Len(t, result.Packages, 1) + p := result.Packages[0] + assert.NotEmpty(t, p.Pkgid) + assert.Equal(t, packageName, p.Name) + assert.Equal(t, packageArchitecture, p.Architecture) + assert.Len(t, p.Files, 1) + f := p.Files[0] + assert.Equal(t, "/usr/local/bin/hello", f.Path) + }) + + t.Run("other.xml.gz", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req = NewRequest(t, "GET", url+"/other.xml.gz") + resp := MakeRequest(t, req, http.StatusOK) + + type Other struct { + XMLName xml.Name `xml:"otherdata"` + Xmlns string `xml:"xmlns,attr"` + PackageCount int `xml:"packages,attr"` + Packages []struct { + Pkgid string `xml:"pkgid,attr"` + Name string `xml:"name,attr"` + Architecture string `xml:"arch,attr"` + Version struct { + Epoch string `xml:"epoch,attr"` + Version string `xml:"ver,attr"` + Release string `xml:"rel,attr"` + } `xml:"version"` + Changelogs []*rpm_module.Changelog `xml:"changelog"` + } `xml:"package"` + } + + var result Other + decodeGzipXML(t, resp, &result) + + assert.EqualValues(t, 1, result.PackageCount) + assert.Len(t, result.Packages, 1) + p := result.Packages[0] + assert.NotEmpty(t, p.Pkgid) + assert.Equal(t, packageName, p.Name) + assert.Equal(t, packageArchitecture, p.Architecture) + assert.Len(t, p.Changelogs, 1) + c := p.Changelogs[0] + assert.Equal(t, "KN4CK3R ", c.Author) + assert.EqualValues(t, 1678276800, c.Date) + assert.Equal(t, "- Changelog message.", c.Text) + }) + }) + + t.Run("Delete", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + req := NewRequest(t, "DELETE", fmt.Sprintf("%s/package/%s/%s/%s", groupURL, packageName, packageVersion, packageArchitecture)) + MakeRequest(t, req, http.StatusUnauthorized) + + req = NewRequest(t, "DELETE", fmt.Sprintf("%s/package/%s/%s/%s", groupURL, packageName, packageVersion, packageArchitecture)). + AddBasicAuth(user.Name) + MakeRequest(t, req, http.StatusNoContent) + + pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeRpm) + assert.NoError(t, err) + assert.Empty(t, pvs) + req = NewRequest(t, "DELETE", fmt.Sprintf("%s/package/%s/%s/%s", groupURL, packageName, packageVersion, packageArchitecture)). + AddBasicAuth(user.Name) + MakeRequest(t, req, http.StatusNotFound) + }) }) - - t.Run("repomd.xml.asc", func(t *testing.T) { - defer tests.PrintCurrentTest(t)() - - req = NewRequest(t, "GET", url+"/repomd.xml.asc") - resp := MakeRequest(t, req, http.StatusOK) - - assert.Contains(t, resp.Body.String(), "-----BEGIN PGP SIGNATURE-----") - }) - - decodeGzipXML := func(t testing.TB, resp *httptest.ResponseRecorder, v any) { - t.Helper() - - zr, err := gzip.NewReader(resp.Body) - assert.NoError(t, err) - - assert.NoError(t, xml.NewDecoder(zr).Decode(v)) - } - - t.Run("primary.xml.gz", func(t *testing.T) { - defer tests.PrintCurrentTest(t)() - - req = NewRequest(t, "GET", url+"/primary.xml.gz") - resp := MakeRequest(t, req, http.StatusOK) - - type EntryList struct { - Entries []*rpm_module.Entry `xml:"entry"` - } - - type Metadata struct { - XMLName xml.Name `xml:"metadata"` - Xmlns string `xml:"xmlns,attr"` - XmlnsRpm string `xml:"xmlns:rpm,attr"` - PackageCount int `xml:"packages,attr"` - Packages []struct { - XMLName xml.Name `xml:"package"` - Type string `xml:"type,attr"` - Name string `xml:"name"` - Architecture string `xml:"arch"` - Version struct { - Epoch string `xml:"epoch,attr"` - Version string `xml:"ver,attr"` - Release string `xml:"rel,attr"` - } `xml:"version"` - Checksum struct { - Checksum string `xml:",chardata"` - Type string `xml:"type,attr"` - Pkgid string `xml:"pkgid,attr"` - } `xml:"checksum"` - Summary string `xml:"summary"` - Description string `xml:"description"` - Packager string `xml:"packager"` - URL string `xml:"url"` - Time struct { - File uint64 `xml:"file,attr"` - Build uint64 `xml:"build,attr"` - } `xml:"time"` - Size struct { - Package int64 `xml:"package,attr"` - Installed uint64 `xml:"installed,attr"` - Archive uint64 `xml:"archive,attr"` - } `xml:"size"` - Location struct { - Href string `xml:"href,attr"` - } `xml:"location"` - Format struct { - License string `xml:"license"` - Vendor string `xml:"vendor"` - Group string `xml:"group"` - Buildhost string `xml:"buildhost"` - Sourcerpm string `xml:"sourcerpm"` - Provides EntryList `xml:"provides"` - Requires EntryList `xml:"requires"` - Conflicts EntryList `xml:"conflicts"` - Obsoletes EntryList `xml:"obsoletes"` - Files []*rpm_module.File `xml:"file"` - } `xml:"format"` - } `xml:"package"` - } - - var result Metadata - decodeGzipXML(t, resp, &result) - - assert.EqualValues(t, 1, result.PackageCount) - assert.Len(t, result.Packages, 1) - p := result.Packages[0] - assert.Equal(t, "rpm", p.Type) - assert.Equal(t, packageName, p.Name) - assert.Equal(t, packageArchitecture, p.Architecture) - assert.Equal(t, "YES", p.Checksum.Pkgid) - assert.Equal(t, "sha256", p.Checksum.Type) - assert.Equal(t, "f1d5d2ffcbe4a7568e98b864f40d923ecca084e9b9bcd5977ed6521c46d3fa4c", p.Checksum.Checksum) - assert.Equal(t, "https://gitea.io", p.URL) - assert.EqualValues(t, len(content), p.Size.Package) - assert.EqualValues(t, 13, p.Size.Installed) - assert.EqualValues(t, 272, p.Size.Archive) - assert.Equal(t, fmt.Sprintf("package/%s/%s/%s/%s", packageName, packageVersion, packageArchitecture, fmt.Sprintf("%s-%s.%s.rpm", packageName, packageVersion, packageArchitecture)), p.Location.Href) - f := p.Format - assert.Equal(t, "MIT", f.License) - assert.Len(t, f.Provides.Entries, 2) - assert.Len(t, f.Requires.Entries, 7) - assert.Empty(t, f.Conflicts.Entries) - assert.Empty(t, f.Obsoletes.Entries) - assert.Len(t, f.Files, 1) - }) - - t.Run("filelists.xml.gz", func(t *testing.T) { - defer tests.PrintCurrentTest(t)() - - req = NewRequest(t, "GET", url+"/filelists.xml.gz") - resp := MakeRequest(t, req, http.StatusOK) - - type Filelists struct { - XMLName xml.Name `xml:"filelists"` - Xmlns string `xml:"xmlns,attr"` - PackageCount int `xml:"packages,attr"` - Packages []struct { - Pkgid string `xml:"pkgid,attr"` - Name string `xml:"name,attr"` - Architecture string `xml:"arch,attr"` - Version struct { - Epoch string `xml:"epoch,attr"` - Version string `xml:"ver,attr"` - Release string `xml:"rel,attr"` - } `xml:"version"` - Files []*rpm_module.File `xml:"file"` - } `xml:"package"` - } - - var result Filelists - decodeGzipXML(t, resp, &result) - - assert.EqualValues(t, 1, result.PackageCount) - assert.Len(t, result.Packages, 1) - p := result.Packages[0] - assert.NotEmpty(t, p.Pkgid) - assert.Equal(t, packageName, p.Name) - assert.Equal(t, packageArchitecture, p.Architecture) - assert.Len(t, p.Files, 1) - f := p.Files[0] - assert.Equal(t, "/usr/local/bin/hello", f.Path) - }) - - t.Run("other.xml.gz", func(t *testing.T) { - defer tests.PrintCurrentTest(t)() - - req = NewRequest(t, "GET", url+"/other.xml.gz") - resp := MakeRequest(t, req, http.StatusOK) - - type Other struct { - XMLName xml.Name `xml:"otherdata"` - Xmlns string `xml:"xmlns,attr"` - PackageCount int `xml:"packages,attr"` - Packages []struct { - Pkgid string `xml:"pkgid,attr"` - Name string `xml:"name,attr"` - Architecture string `xml:"arch,attr"` - Version struct { - Epoch string `xml:"epoch,attr"` - Version string `xml:"ver,attr"` - Release string `xml:"rel,attr"` - } `xml:"version"` - Changelogs []*rpm_module.Changelog `xml:"changelog"` - } `xml:"package"` - } - - var result Other - decodeGzipXML(t, resp, &result) - - assert.EqualValues(t, 1, result.PackageCount) - assert.Len(t, result.Packages, 1) - p := result.Packages[0] - assert.NotEmpty(t, p.Pkgid) - assert.Equal(t, packageName, p.Name) - assert.Equal(t, packageArchitecture, p.Architecture) - assert.Len(t, p.Changelogs, 1) - c := p.Changelogs[0] - assert.Equal(t, "KN4CK3R ", c.Author) - assert.EqualValues(t, 1678276800, c.Date) - assert.Equal(t, "- Changelog message.", c.Text) - }) - }) - - t.Run("Delete", func(t *testing.T) { - defer tests.PrintCurrentTest(t)() - - req := NewRequest(t, "DELETE", fmt.Sprintf("%s/el9/stable/package/%s/%s/%s", rootURL, packageName, packageVersion, packageArchitecture)) - MakeRequest(t, req, http.StatusUnauthorized) - - req = NewRequest(t, "DELETE", fmt.Sprintf("%s/el9/stable/package/%s/%s/%s", rootURL, packageName, packageVersion, packageArchitecture)). - AddBasicAuth(user.Name) - MakeRequest(t, req, http.StatusNoContent) - - pvs, err := packages.GetVersionsByPackageType(db.DefaultContext, user.ID, packages.TypeRpm) - assert.NoError(t, err) - assert.Empty(t, pvs) - req = NewRequest(t, "DELETE", fmt.Sprintf("%s/el9/stable/package/%s/%s/%s", rootURL, packageName, packageVersion, packageArchitecture)). - AddBasicAuth(user.Name) - MakeRequest(t, req, http.StatusNotFound) - }) + } } From 07ba4d9f87cf21b7ce87158ae5651cae3bb35604 Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Fri, 19 Jan 2024 23:05:49 +0900 Subject: [PATCH 09/26] Fix incorrect action duration time when rerun the job before executed once (#28364) Fix #28323 Reason was mentioned here: https://github.com/go-gitea/gitea/issues/28323#issuecomment-1841867298 ### Changes: (maybe breaking) We can rerun jobs in Gitea, so there will be some problems in calculating duration time. In this PR, I use the exist `Started` and `Stopped` column to record the last run time instead of the total time, and add a new `PreviousDuration` column to record the previous duration time. You can also check the cost time of last run: ![image](https://github.com/go-gitea/gitea/assets/18380374/2ca39145-2c92-401a-b78b-43164f7ae061) --- models/actions/run.go | 13 ++++++++----- models/migrations/migrations.go | 2 ++ models/migrations/v1_22/v285.go | 18 ++++++++++++++++++ routers/web/repo/actions/view.go | 11 +++++++++++ 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 models/migrations/v1_22/v285.go diff --git a/models/actions/run.go b/models/actions/run.go index 1a3701b0b0..fcac58d515 100644 --- a/models/actions/run.go +++ b/models/actions/run.go @@ -46,10 +46,13 @@ type ActionRun struct { TriggerEvent string // the trigger event defined in the `on` configuration of the triggered workflow Status Status `xorm:"index"` Version int `xorm:"version default 0"` // Status could be updated concomitantly, so an optimistic lock is needed - Started timeutil.TimeStamp - Stopped timeutil.TimeStamp - Created timeutil.TimeStamp `xorm:"created"` - Updated timeutil.TimeStamp `xorm:"updated"` + // Started and Stopped is used for recording last run time, if rerun happened, they will be reset to 0 + Started timeutil.TimeStamp + Stopped timeutil.TimeStamp + // PreviousDuration is used for recording previous duration + PreviousDuration time.Duration + Created timeutil.TimeStamp `xorm:"created"` + Updated timeutil.TimeStamp `xorm:"updated"` } func init() { @@ -118,7 +121,7 @@ func (run *ActionRun) LoadAttributes(ctx context.Context) error { } func (run *ActionRun) Duration() time.Duration { - return calculateDuration(run.Started, run.Stopped, run.Status) + return calculateDuration(run.Started, run.Stopped, run.Status) + run.PreviousDuration } func (run *ActionRun) GetPushEventPayload() (*api.PushPayload, error) { diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 3b4ac24a2c..21675cab8a 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -554,6 +554,8 @@ var migrations = []Migration{ NewMigration("Add combined Index to issue_user.uid and issue_id", v1_22.AddCombinedIndexToIssueUser), // v284 -> v285 NewMigration("Add ignore stale approval column on branch table", v1_22.AddIgnoreStaleApprovalsColumnToProtectedBranchTable), + // v285 -> v286 + NewMigration("Add PreviousDuration to ActionRun", v1_22.AddPreviousDurationToActionRun), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_22/v285.go b/models/migrations/v1_22/v285.go new file mode 100644 index 0000000000..c0dacd40bc --- /dev/null +++ b/models/migrations/v1_22/v285.go @@ -0,0 +1,18 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_22 //nolint + +import ( + "time" + + "xorm.io/xorm" +) + +func AddPreviousDurationToActionRun(x *xorm.Engine) error { + type ActionRun struct { + PreviousDuration time.Duration + } + + return x.Sync(&ActionRun{}) +} diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index 1cdae32a32..9cda30d23d 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -279,6 +279,17 @@ func Rerun(ctx *context_module.Context) { return } + // reset run's start and stop time when it is done + if run.Status.IsDone() { + run.PreviousDuration = run.Duration() + run.Started = 0 + run.Stopped = 0 + if err := actions_model.UpdateRun(ctx, run, "started", "stopped", "previous_duration"); err != nil { + ctx.Error(http.StatusInternalServerError, err.Error()) + return + } + } + job, jobs := getRunJobs(ctx, runIndex, jobIndex) if ctx.Written() { return From d68a613ba8fd860863a3465b5b5945b191b87b25 Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Fri, 19 Jan 2024 16:05:02 +0000 Subject: [PATCH 10/26] Add support for sha256 repositories (#23894) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/go-git/go-git/issues/899 Depend on: #28138 图片 --------- Co-authored-by: Lunny Xiao Co-authored-by: 6543 <6543@obermui.de> --- models/git/commit_status.go | 2 +- models/issues/comment.go | 2 +- models/issues/pull.go | 4 +- models/issues/review.go | 2 +- .../Test_RepositoryFormat/repository.yml | 11 + models/migrations/migrations.go | 2 + models/migrations/v1_22/v286.go | 104 ++++++++++ models/migrations/v1_22/v286_test.go | 62 ++++++ models/pull/review_state.go | 2 +- models/repo/archiver.go | 2 +- models/repo/release.go | 2 +- models/repo/repo.go | 6 +- models/repo/repo_indexer.go | 2 +- modules/git/blame_sha256_test.go | 144 +++++++++++++ modules/git/commit_reader.go | 2 + modules/git/commit_sha256_test.go | 195 ++++++++++++++++++ modules/git/git.go | 8 +- modules/git/object_format.go | 65 +++++- modules/git/object_id.go | 16 ++ modules/git/object_id_gogit.go | 2 + modules/git/repo.go | 13 +- modules/git/repo_base.go | 2 + modules/git/repo_base_gogit.go | 4 + modules/git/repo_base_nogogit.go | 4 + .../git/tests/repos/repo1_bare_sha256/HEAD | 1 + .../git/tests/repos/repo1_bare_sha256/config | 6 + .../tests/repos/repo1_bare_sha256/description | 1 + .../repos/repo1_bare_sha256/info/exclude | 6 + .../tests/repos/repo1_bare_sha256/info/refs | 7 + .../objects/info/commit-graph | Bin 0 -> 2048 bytes .../repo1_bare_sha256/objects/info/packs | 2 + ...65970b0c38c6b495d5fc034bc7a7b95334b.bitmap | Bin 0 -> 710 bytes ...78665970b0c38c6b495d5fc034bc7a7b95334b.idx | Bin 0 -> 2576 bytes ...8665970b0c38c6b495d5fc034bc7a7b95334b.pack | Bin 0 -> 5656 bytes ...78665970b0c38c6b495d5fc034bc7a7b95334b.rev | Bin 0 -> 224 bytes .../tests/repos/repo1_bare_sha256/packed-refs | 8 + .../repos/repo1_bare_sha256/refs/heads/main | 1 + .../git/tests/repos/repo5_pulls_sha256/HEAD | 1 + .../git/tests/repos/repo5_pulls_sha256/config | 6 + .../repos/repo5_pulls_sha256/description | 1 + .../tests/repos/repo5_pulls_sha256/info/refs | 4 + .../objects/info/commit-graph | Bin 0 -> 1544 bytes .../repo5_pulls_sha256/objects/info/packs | 2 + ...45d4a02b788eb26c31022a362312660a29d.bitmap | Bin 0 -> 414 bytes ...fe145d4a02b788eb26c31022a362312660a29d.idx | Bin 0 -> 1736 bytes ...e145d4a02b788eb26c31022a362312660a29d.pack | Bin 0 -> 3140 bytes ...fe145d4a02b788eb26c31022a362312660a29d.rev | Bin 0 -> 140 bytes .../repos/repo5_pulls_sha256/packed-refs | 5 + .../repos/repo5_pulls_sha256/refs/heads/main | 1 + .../git/tests/repos/repo6_blame_sha256/HEAD | 1 + .../git/tests/repos/repo6_blame_sha256/config | 6 + .../repos/repo6_blame_sha256/description | 1 + .../repos/repo6_blame_sha256/info/exclude | 6 + .../tests/repos/repo6_blame_sha256/info/refs | 1 + .../objects/info/commit-graph | Bin 0 -> 1376 bytes .../repo6_blame_sha256/objects/info/packs | 2 + ...1ac24312a5ffc3d3703d7c5cc906bdaee8e.bitmap | Bin 0 -> 318 bytes ...b611ac24312a5ffc3d3703d7c5cc906bdaee8e.idx | Bin 0 -> 1456 bytes ...611ac24312a5ffc3d3703d7c5cc906bdaee8e.pack | Bin 0 -> 904 bytes ...b611ac24312a5ffc3d3703d7c5cc906bdaee8e.rev | Bin 0 -> 112 bytes .../repos/repo6_blame_sha256/packed-refs | 2 + .../repos/repo6_blame_sha256/refs/refs/main | 1 + .../git/tests/repos/repo6_merge_sha256/HEAD | 1 + .../git/tests/repos/repo6_merge_sha256/config | 6 + .../repos/repo6_merge_sha256/description | 1 + .../repos/repo6_merge_sha256/info/exclude | 6 + .../tests/repos/repo6_merge_sha256/info/refs | 4 + .../objects/info/commit-graph | Bin 0 -> 1564 bytes .../repo6_merge_sha256/objects/info/packs | 3 + ...096c7530f577d5c0a79c63d9ac2b44f7510.bitmap | Bin 0 -> 410 bytes ...b6a096c7530f577d5c0a79c63d9ac2b44f7510.idx | Bin 0 -> 1696 bytes ...6a096c7530f577d5c0a79c63d9ac2b44f7510.pack | Bin 0 -> 1556 bytes ...b6a096c7530f577d5c0a79c63d9ac2b44f7510.rev | Bin 0 -> 136 bytes ...e67bb2a4a5501ca1fa3528fad8a9474fba7e50.idx | Bin 0 -> 1176 bytes ...bb2a4a5501ca1fa3528fad8a9474fba7e50.mtimes | Bin 0 -> 84 bytes ...67bb2a4a5501ca1fa3528fad8a9474fba7e50.pack | Bin 0 -> 447 bytes ...e67bb2a4a5501ca1fa3528fad8a9474fba7e50.rev | Bin 0 -> 84 bytes .../repos/repo6_merge_sha256/packed-refs | 5 + .../repos/repo6_merge_sha256/refs/heads/main | 1 + modules/markup/html.go | 36 ++-- modules/markup/html_internal_test.go | 6 +- modules/references/references.go | 2 +- modules/references/references_test.go | 2 +- modules/structs/repo.go | 6 + modules/templates/util_string.go | 4 + options/locale/locale_en-US.ini | 3 + routers/api/v1/repo/repo.go | 2 +- routers/web/githttp.go | 6 +- routers/web/repo/repo.go | 3 +- routers/web/web.go | 14 +- services/repository/create.go | 4 + services/repository/fork.go | 23 ++- templates/admin/repo/list.tmpl | 3 + templates/explore/repo_list.tmpl | 3 + templates/repo/commits_list.tmpl | 2 +- templates/repo/create.tmpl | 13 ++ templates/repo/header.tmpl | 3 + templates/swagger/v1_json.tmpl | 18 ++ 98 files changed, 834 insertions(+), 76 deletions(-) create mode 100644 models/migrations/fixtures/Test_RepositoryFormat/repository.yml create mode 100644 models/migrations/v1_22/v286.go create mode 100644 models/migrations/v1_22/v286_test.go create mode 100644 modules/git/blame_sha256_test.go create mode 100644 modules/git/commit_sha256_test.go create mode 100644 modules/git/tests/repos/repo1_bare_sha256/HEAD create mode 100644 modules/git/tests/repos/repo1_bare_sha256/config create mode 100644 modules/git/tests/repos/repo1_bare_sha256/description create mode 100644 modules/git/tests/repos/repo1_bare_sha256/info/exclude create mode 100644 modules/git/tests/repos/repo1_bare_sha256/info/refs create mode 100644 modules/git/tests/repos/repo1_bare_sha256/objects/info/commit-graph create mode 100644 modules/git/tests/repos/repo1_bare_sha256/objects/info/packs create mode 100644 modules/git/tests/repos/repo1_bare_sha256/objects/pack/pack-c01aa121b9c5e345fe0da2f9be78665970b0c38c6b495d5fc034bc7a7b95334b.bitmap create mode 100644 modules/git/tests/repos/repo1_bare_sha256/objects/pack/pack-c01aa121b9c5e345fe0da2f9be78665970b0c38c6b495d5fc034bc7a7b95334b.idx create mode 100644 modules/git/tests/repos/repo1_bare_sha256/objects/pack/pack-c01aa121b9c5e345fe0da2f9be78665970b0c38c6b495d5fc034bc7a7b95334b.pack create mode 100644 modules/git/tests/repos/repo1_bare_sha256/objects/pack/pack-c01aa121b9c5e345fe0da2f9be78665970b0c38c6b495d5fc034bc7a7b95334b.rev create mode 100644 modules/git/tests/repos/repo1_bare_sha256/packed-refs create mode 100644 modules/git/tests/repos/repo1_bare_sha256/refs/heads/main create mode 100644 modules/git/tests/repos/repo5_pulls_sha256/HEAD create mode 100644 modules/git/tests/repos/repo5_pulls_sha256/config create mode 100644 modules/git/tests/repos/repo5_pulls_sha256/description create mode 100644 modules/git/tests/repos/repo5_pulls_sha256/info/refs create mode 100644 modules/git/tests/repos/repo5_pulls_sha256/objects/info/commit-graph create mode 100644 modules/git/tests/repos/repo5_pulls_sha256/objects/info/packs create mode 100644 modules/git/tests/repos/repo5_pulls_sha256/objects/pack/pack-bfe8f09d42ef5dd1610bf42641fe145d4a02b788eb26c31022a362312660a29d.bitmap create mode 100644 modules/git/tests/repos/repo5_pulls_sha256/objects/pack/pack-bfe8f09d42ef5dd1610bf42641fe145d4a02b788eb26c31022a362312660a29d.idx create mode 100644 modules/git/tests/repos/repo5_pulls_sha256/objects/pack/pack-bfe8f09d42ef5dd1610bf42641fe145d4a02b788eb26c31022a362312660a29d.pack create mode 100644 modules/git/tests/repos/repo5_pulls_sha256/objects/pack/pack-bfe8f09d42ef5dd1610bf42641fe145d4a02b788eb26c31022a362312660a29d.rev create mode 100644 modules/git/tests/repos/repo5_pulls_sha256/packed-refs create mode 100644 modules/git/tests/repos/repo5_pulls_sha256/refs/heads/main create mode 100644 modules/git/tests/repos/repo6_blame_sha256/HEAD create mode 100644 modules/git/tests/repos/repo6_blame_sha256/config create mode 100644 modules/git/tests/repos/repo6_blame_sha256/description create mode 100644 modules/git/tests/repos/repo6_blame_sha256/info/exclude create mode 100644 modules/git/tests/repos/repo6_blame_sha256/info/refs create mode 100644 modules/git/tests/repos/repo6_blame_sha256/objects/info/commit-graph create mode 100644 modules/git/tests/repos/repo6_blame_sha256/objects/info/packs create mode 100644 modules/git/tests/repos/repo6_blame_sha256/objects/pack/pack-fcb8a221b76025fd8415d3c562b611ac24312a5ffc3d3703d7c5cc906bdaee8e.bitmap create mode 100644 modules/git/tests/repos/repo6_blame_sha256/objects/pack/pack-fcb8a221b76025fd8415d3c562b611ac24312a5ffc3d3703d7c5cc906bdaee8e.idx create mode 100644 modules/git/tests/repos/repo6_blame_sha256/objects/pack/pack-fcb8a221b76025fd8415d3c562b611ac24312a5ffc3d3703d7c5cc906bdaee8e.pack create mode 100644 modules/git/tests/repos/repo6_blame_sha256/objects/pack/pack-fcb8a221b76025fd8415d3c562b611ac24312a5ffc3d3703d7c5cc906bdaee8e.rev create mode 100644 modules/git/tests/repos/repo6_blame_sha256/packed-refs create mode 100644 modules/git/tests/repos/repo6_blame_sha256/refs/refs/main create mode 100644 modules/git/tests/repos/repo6_merge_sha256/HEAD create mode 100644 modules/git/tests/repos/repo6_merge_sha256/config create mode 100644 modules/git/tests/repos/repo6_merge_sha256/description create mode 100644 modules/git/tests/repos/repo6_merge_sha256/info/exclude create mode 100644 modules/git/tests/repos/repo6_merge_sha256/info/refs create mode 100644 modules/git/tests/repos/repo6_merge_sha256/objects/info/commit-graph create mode 100644 modules/git/tests/repos/repo6_merge_sha256/objects/info/packs create mode 100644 modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-2fff0848f8d8eab8f7902ac91ab6a096c7530f577d5c0a79c63d9ac2b44f7510.bitmap create mode 100644 modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-2fff0848f8d8eab8f7902ac91ab6a096c7530f577d5c0a79c63d9ac2b44f7510.idx create mode 100644 modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-2fff0848f8d8eab8f7902ac91ab6a096c7530f577d5c0a79c63d9ac2b44f7510.pack create mode 100644 modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-2fff0848f8d8eab8f7902ac91ab6a096c7530f577d5c0a79c63d9ac2b44f7510.rev create mode 100644 modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-65162b86afdbac3c566696d487e67bb2a4a5501ca1fa3528fad8a9474fba7e50.idx create mode 100644 modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-65162b86afdbac3c566696d487e67bb2a4a5501ca1fa3528fad8a9474fba7e50.mtimes create mode 100644 modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-65162b86afdbac3c566696d487e67bb2a4a5501ca1fa3528fad8a9474fba7e50.pack create mode 100644 modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-65162b86afdbac3c566696d487e67bb2a4a5501ca1fa3528fad8a9474fba7e50.rev create mode 100644 modules/git/tests/repos/repo6_merge_sha256/packed-refs create mode 100644 modules/git/tests/repos/repo6_merge_sha256/refs/heads/main diff --git a/models/git/commit_status.go b/models/git/commit_status.go index c126d17f20..1118b6cc8c 100644 --- a/models/git/commit_status.go +++ b/models/git/commit_status.go @@ -37,7 +37,7 @@ type CommitStatus struct { SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_index)"` TargetURL string `xorm:"TEXT"` Description string `xorm:"TEXT"` - ContextHash string `xorm:"char(40) index"` + ContextHash string `xorm:"VARCHAR(64) index"` Context string `xorm:"TEXT"` Creator *user_model.User `xorm:"-"` CreatorID int64 diff --git a/models/issues/comment.go b/models/issues/comment.go index a1698d4824..8a3bae5b88 100644 --- a/models/issues/comment.go +++ b/models/issues/comment.go @@ -270,7 +270,7 @@ type Comment struct { UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` // Reference issue in commit message - CommitSHA string `xorm:"VARCHAR(40)"` + CommitSHA string `xorm:"VARCHAR(64)"` Attachments []*repo_model.Attachment `xorm:"-"` Reactions ReactionList `xorm:"-"` diff --git a/models/issues/pull.go b/models/issues/pull.go index 614ee9a87c..4ae6e38ae1 100644 --- a/models/issues/pull.go +++ b/models/issues/pull.go @@ -171,11 +171,11 @@ type PullRequest struct { HeadBranch string HeadCommitID string `xorm:"-"` BaseBranch string - MergeBase string `xorm:"VARCHAR(40)"` + MergeBase string `xorm:"VARCHAR(64)"` AllowMaintainerEdit bool `xorm:"NOT NULL DEFAULT false"` HasMerged bool `xorm:"INDEX"` - MergedCommitID string `xorm:"VARCHAR(40)"` + MergedCommitID string `xorm:"VARCHAR(64)"` MergerID int64 `xorm:"INDEX"` Merger *user_model.User `xorm:"-"` MergedUnix timeutil.TimeStamp `xorm:"updated INDEX"` diff --git a/models/issues/review.go b/models/issues/review.go index 4cbfa4f443..f2022ae0aa 100644 --- a/models/issues/review.go +++ b/models/issues/review.go @@ -116,7 +116,7 @@ type Review struct { Content string `xorm:"TEXT"` // Official is a review made by an assigned approver (counts towards approval) Official bool `xorm:"NOT NULL DEFAULT false"` - CommitID string `xorm:"VARCHAR(40)"` + CommitID string `xorm:"VARCHAR(64)"` Stale bool `xorm:"NOT NULL DEFAULT false"` Dismissed bool `xorm:"NOT NULL DEFAULT false"` diff --git a/models/migrations/fixtures/Test_RepositoryFormat/repository.yml b/models/migrations/fixtures/Test_RepositoryFormat/repository.yml new file mode 100644 index 0000000000..5a3675917c --- /dev/null +++ b/models/migrations/fixtures/Test_RepositoryFormat/repository.yml @@ -0,0 +1,11 @@ +# type Repository struct { +# ID int64 `xorm:"pk autoincr"` +# } +- + id: 1 +- + id: 2 +- + id: 3 +- + id: 10 diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 21675cab8a..beb1f3bb96 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -556,6 +556,8 @@ var migrations = []Migration{ NewMigration("Add ignore stale approval column on branch table", v1_22.AddIgnoreStaleApprovalsColumnToProtectedBranchTable), // v285 -> v286 NewMigration("Add PreviousDuration to ActionRun", v1_22.AddPreviousDurationToActionRun), + // v286 -> v287 + NewMigration("Add support for SHA256 git repositories", v1_22.AdjustDBForSha256), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_22/v286.go b/models/migrations/v1_22/v286.go new file mode 100644 index 0000000000..ef19f64221 --- /dev/null +++ b/models/migrations/v1_22/v286.go @@ -0,0 +1,104 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT +package v1_22 //nolint + +import ( + "errors" + "fmt" + + "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" + + "xorm.io/xorm" +) + +func expandHashReferencesToSha256(x *xorm.Engine) error { + alteredTables := [][2]string{ + {"commit_status", "context_hash"}, + {"comment", "commit_sha"}, + {"pull_request", "merge_base"}, + {"pull_request", "merged_commit_id"}, + {"review", "commit_id"}, + {"review_state", "commit_sha"}, + {"repo_archiver", "commit_id"}, + {"release", "sha1"}, + {"repo_indexer_status", "commit_sha"}, + } + + db := x.NewSession() + defer db.Close() + + if err := db.Begin(); err != nil { + return err + } + + if !setting.Database.Type.IsSQLite3() { + if setting.Database.Type.IsMSSQL() { + // drop indexes that need to be re-created afterwards + droppedIndexes := []string{ + "DROP INDEX commit_status.IDX_commit_status_context_hash", + "DROP INDEX review_state.UQE_review_state_pull_commit_user", + "DROP INDEX repo_archiver.UQE_repo_archiver_s", + } + for _, s := range droppedIndexes { + _, err := db.Exec(s) + if err != nil { + return errors.New(s + " " + err.Error()) + } + } + } + + for _, alts := range alteredTables { + var err error + if setting.Database.Type.IsMySQL() { + _, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` MODIFY COLUMN `%s` VARCHAR(64)", alts[0], alts[1])) + } else if setting.Database.Type.IsMSSQL() { + _, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` ALTER COLUMN `%s` VARCHAR(64)", alts[0], alts[1])) + } else { + _, err = db.Exec(fmt.Sprintf("ALTER TABLE `%s` ALTER COLUMN `%s` TYPE VARCHAR(64)", alts[0], alts[1])) + } + if err != nil { + return fmt.Errorf("alter column '%s' of table '%s' failed: %w", alts[1], alts[0], err) + } + } + + if setting.Database.Type.IsMSSQL() { + recreateIndexes := []string{ + "CREATE INDEX IDX_commit_status_context_hash ON commit_status(context_hash)", + "CREATE UNIQUE INDEX UQE_review_state_pull_commit_user ON review_state(user_id, pull_id, commit_sha)", + "CREATE UNIQUE INDEX UQE_repo_archiver_s ON repo_archiver(repo_id, type, commit_id)", + } + for _, s := range recreateIndexes { + _, err := db.Exec(s) + if err != nil { + return errors.New(s + " " + err.Error()) + } + } + } + } + log.Debug("Updated database tables to hold SHA256 git hash references") + + return db.Commit() +} + +func addObjectFormatNameToRepository(x *xorm.Engine) error { + type Repository struct { + ObjectFormatName string `xorm:"VARCHAR(6) NOT NULL DEFAULT 'sha1'"` + } + + if err := x.Sync(new(Repository)); err != nil { + return err + } + + // Here to catch weird edge-cases where column constraints above are + // not applied by the DB backend + _, err := x.Exec("UPDATE repository set object_format_name = 'sha1' WHERE object_format_name = '' or object_format_name IS NULL") + return err +} + +func AdjustDBForSha256(x *xorm.Engine) error { + if err := expandHashReferencesToSha256(x); err != nil { + return err + } + return addObjectFormatNameToRepository(x) +} diff --git a/models/migrations/v1_22/v286_test.go b/models/migrations/v1_22/v286_test.go new file mode 100644 index 0000000000..e36a18a116 --- /dev/null +++ b/models/migrations/v1_22/v286_test.go @@ -0,0 +1,62 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_22 //nolint + +import ( + "testing" + + "code.gitea.io/gitea/models/migrations/base" + + "github.com/stretchr/testify/assert" + "xorm.io/xorm" +) + +func PrepareOldRepository(t *testing.T) (*xorm.Engine, func()) { + type Repository struct { // old struct + ID int64 `xorm:"pk autoincr"` + } + + // Prepare and load the testing database + return base.PrepareTestEnv(t, 0, new(Repository)) +} + +func Test_RepositoryFormat(t *testing.T) { + x, deferable := PrepareOldRepository(t) + defer deferable() + + type Repository struct { + ID int64 `xorm:"pk autoincr"` + ObjectFormatName string `xorg:"not null default('sha1')"` + } + + repo := new(Repository) + + // check we have some records to migrate + count, err := x.Count(new(Repository)) + assert.NoError(t, err) + assert.EqualValues(t, 4, count) + + assert.NoError(t, AdjustDBForSha256(x)) + + repo.ID = 20 + repo.ObjectFormatName = "sha256" + _, err = x.Insert(repo) + assert.NoError(t, err) + + count, err = x.Count(new(Repository)) + assert.NoError(t, err) + assert.EqualValues(t, 5, count) + + repo = new(Repository) + ok, err := x.ID(2).Get(repo) + assert.NoError(t, err) + assert.EqualValues(t, true, ok) + assert.EqualValues(t, "sha1", repo.ObjectFormatName) + + repo = new(Repository) + ok, err = x.ID(20).Get(repo) + assert.NoError(t, err) + assert.EqualValues(t, true, ok) + assert.EqualValues(t, "sha256", repo.ObjectFormatName) +} diff --git a/models/pull/review_state.go b/models/pull/review_state.go index 1a2b1e165f..e46a22a49d 100644 --- a/models/pull/review_state.go +++ b/models/pull/review_state.go @@ -39,7 +39,7 @@ type ReviewState struct { ID int64 `xorm:"pk autoincr"` UserID int64 `xorm:"NOT NULL UNIQUE(pull_commit_user)"` PullID int64 `xorm:"NOT NULL INDEX UNIQUE(pull_commit_user) DEFAULT 0"` // Which PR was the review on? - CommitSHA string `xorm:"NOT NULL VARCHAR(40) UNIQUE(pull_commit_user)"` // Which commit was the head commit for the review? + CommitSHA string `xorm:"NOT NULL VARCHAR(64) UNIQUE(pull_commit_user)"` // Which commit was the head commit for the review? UpdatedFiles map[string]ViewedState `xorm:"NOT NULL LONGTEXT JSON"` // Stores for each of the changed files of a PR whether they have been viewed, changed since last viewed, or not viewed UpdatedUnix timeutil.TimeStamp `xorm:"updated"` // Is an accurate indicator of the order of commits as we do not expect it to be possible to make reviews on previous commits } diff --git a/models/repo/archiver.go b/models/repo/archiver.go index d9520c670c..14ffa1d89b 100644 --- a/models/repo/archiver.go +++ b/models/repo/archiver.go @@ -33,7 +33,7 @@ type RepoArchiver struct { //revive:disable-line:exported RepoID int64 `xorm:"index unique(s)"` Type git.ArchiveType `xorm:"unique(s)"` Status ArchiverStatus - CommitID string `xorm:"VARCHAR(40) unique(s)"` + CommitID string `xorm:"VARCHAR(64) unique(s)"` CreatedUnix timeutil.TimeStamp `xorm:"INDEX NOT NULL created"` } diff --git a/models/repo/release.go b/models/repo/release.go index 72a73f8e80..1f37f11b2e 100644 --- a/models/repo/release.go +++ b/models/repo/release.go @@ -75,7 +75,7 @@ type Release struct { Target string TargetBehind string `xorm:"-"` // to handle non-existing or empty target Title string - Sha1 string `xorm:"VARCHAR(40)"` + Sha1 string `xorm:"VARCHAR(64)"` NumCommits int64 NumCommitsBehind int64 `xorm:"-"` Note string `xorm:"TEXT"` diff --git a/models/repo/repo.go b/models/repo/repo.go index 3695e1f78b..4401041cdd 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -180,7 +180,7 @@ type Repository struct { IsFsckEnabled bool `xorm:"NOT NULL DEFAULT true"` CloseIssuesViaCommitInAnyBranch bool `xorm:"NOT NULL DEFAULT false"` Topics []string `xorm:"TEXT JSON"` - ObjectFormatName string `xorm:"-"` + ObjectFormatName string `xorm:"VARCHAR(6) NOT NULL DEFAULT 'sha1'"` TrustModel TrustModelType @@ -276,10 +276,6 @@ func (repo *Repository) AfterLoad() { repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones repo.NumOpenProjects = repo.NumProjects - repo.NumClosedProjects repo.NumOpenActionRuns = repo.NumActionRuns - repo.NumClosedActionRuns - - // this is a temporary behaviour to support old repos, next step is to store the object format in the database - // and read from database so this line could be removed. To not depend on git module, we use a constant variable here - repo.ObjectFormatName = "sha1" } // LoadAttributes loads attributes of the repository. diff --git a/models/repo/repo_indexer.go b/models/repo/repo_indexer.go index bad1248b40..6e19d8f937 100644 --- a/models/repo/repo_indexer.go +++ b/models/repo/repo_indexer.go @@ -27,7 +27,7 @@ const ( type RepoIndexerStatus struct { //revive:disable-line:exported ID int64 `xorm:"pk autoincr"` RepoID int64 `xorm:"INDEX(s)"` - CommitSha string `xorm:"VARCHAR(40)"` + CommitSha string `xorm:"VARCHAR(64)"` IndexerType RepoIndexerType `xorm:"INDEX(s) NOT NULL DEFAULT 0"` } diff --git a/modules/git/blame_sha256_test.go b/modules/git/blame_sha256_test.go new file mode 100644 index 0000000000..01de0454a3 --- /dev/null +++ b/modules/git/blame_sha256_test.go @@ -0,0 +1,144 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package git + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestReadingBlameOutputSha256(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + t.Run("Without .git-blame-ignore-revs", func(t *testing.T) { + repo, err := OpenRepository(ctx, "./tests/repos/repo5_pulls_sha256") + assert.NoError(t, err) + defer repo.Close() + + commit, err := repo.GetCommit("0b69b7bb649b5d46e14cabb6468685e5dd721290acc7ffe604d37cde57927345") + assert.NoError(t, err) + + parts := []*BlamePart{ + { + Sha: "1e35a51dc00fd7de730344c07061acfe80e8117e075ac979b6a29a3a045190ca", + Lines: []string{ + "# test_repo", + "Test repository for testing migration from github to gitea", + }, + }, + { + Sha: "0b69b7bb649b5d46e14cabb6468685e5dd721290acc7ffe604d37cde57927345", + Lines: []string{"", "Do not make any changes to this repo it is used for unit testing"}, + PreviousSha: "1e35a51dc00fd7de730344c07061acfe80e8117e075ac979b6a29a3a045190ca", + PreviousPath: "README.md", + }, + } + + for _, bypass := range []bool{false, true} { + blameReader, err := CreateBlameReader(ctx, Sha256ObjectFormat, "./tests/repos/repo5_pulls_sha256", commit, "README.md", bypass) + assert.NoError(t, err) + assert.NotNil(t, blameReader) + defer blameReader.Close() + + assert.False(t, blameReader.UsesIgnoreRevs()) + + for _, part := range parts { + actualPart, err := blameReader.NextPart() + assert.NoError(t, err) + assert.Equal(t, part, actualPart) + } + + // make sure all parts have been read + actualPart, err := blameReader.NextPart() + assert.Nil(t, actualPart) + assert.NoError(t, err) + } + }) + + t.Run("With .git-blame-ignore-revs", func(t *testing.T) { + repo, err := OpenRepository(ctx, "./tests/repos/repo6_blame_sha256") + assert.NoError(t, err) + defer repo.Close() + + full := []*BlamePart{ + { + Sha: "ab2b57a4fa476fb2edb74dafa577caf918561abbaa8fba0c8dc63c412e17a7cc", + Lines: []string{"line", "line"}, + }, + { + Sha: "9347b0198cd1f25017579b79d0938fa89dba34ad2514f0dd92f6bc975ed1a2fe", + Lines: []string{"changed line"}, + PreviousSha: "ab2b57a4fa476fb2edb74dafa577caf918561abbaa8fba0c8dc63c412e17a7cc", + PreviousPath: "blame.txt", + }, + { + Sha: "ab2b57a4fa476fb2edb74dafa577caf918561abbaa8fba0c8dc63c412e17a7cc", + Lines: []string{"line", "line", ""}, + }, + } + + cases := []struct { + CommitID string + UsesIgnoreRevs bool + Bypass bool + Parts []*BlamePart + }{ + { + CommitID: "e2f5660e15159082902960af0ed74fc144921d2b0c80e069361853b3ece29ba3", + UsesIgnoreRevs: true, + Bypass: false, + Parts: []*BlamePart{ + { + Sha: "ab2b57a4fa476fb2edb74dafa577caf918561abbaa8fba0c8dc63c412e17a7cc", + Lines: []string{"line", "line", "changed line", "line", "line", ""}, + }, + }, + }, + { + CommitID: "e2f5660e15159082902960af0ed74fc144921d2b0c80e069361853b3ece29ba3", + UsesIgnoreRevs: false, + Bypass: true, + Parts: full, + }, + { + CommitID: "9347b0198cd1f25017579b79d0938fa89dba34ad2514f0dd92f6bc975ed1a2fe", + UsesIgnoreRevs: false, + Bypass: false, + Parts: full, + }, + { + CommitID: "9347b0198cd1f25017579b79d0938fa89dba34ad2514f0dd92f6bc975ed1a2fe", + UsesIgnoreRevs: false, + Bypass: false, + Parts: full, + }, + } + + for _, c := range cases { + commit, err := repo.GetCommit(c.CommitID) + assert.NoError(t, err) + + blameReader, err := CreateBlameReader(ctx, repo.objectFormat, "./tests/repos/repo6_blame_sha256", commit, "blame.txt", c.Bypass) + assert.NoError(t, err) + assert.NotNil(t, blameReader) + defer blameReader.Close() + + assert.Equal(t, c.UsesIgnoreRevs, blameReader.UsesIgnoreRevs()) + + for _, part := range c.Parts { + actualPart, err := blameReader.NextPart() + assert.NoError(t, err) + assert.Equal(t, part, actualPart) + } + + // make sure all parts have been read + actualPart, err := blameReader.NextPart() + assert.Nil(t, actualPart) + assert.NoError(t, err) + } + }) +} diff --git a/modules/git/commit_reader.go b/modules/git/commit_reader.go index d74bcffed8..4809d6c7ed 100644 --- a/modules/git/commit_reader.go +++ b/modules/git/commit_reader.go @@ -85,6 +85,8 @@ readLoop: commit.Committer.Decode(data) _, _ = payloadSB.Write(line) case "gpgsig": + fallthrough + case "gpgsig-sha256": // FIXME: no intertop, so only 1 exists at present. _, _ = signatureSB.Write(data) _ = signatureSB.WriteByte('\n') pgpsig = true diff --git a/modules/git/commit_sha256_test.go b/modules/git/commit_sha256_test.go new file mode 100644 index 0000000000..82112cb409 --- /dev/null +++ b/modules/git/commit_sha256_test.go @@ -0,0 +1,195 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +//go:build !gogit + +package git + +import ( + "path/filepath" + "strings" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestCommitsCountSha256(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256") + + commitsCount, err := CommitsCount(DefaultContext, + CommitsCountOptions{ + RepoPath: bareRepo1Path, + Revision: []string{"f004f41359117d319dedd0eaab8c5259ee2263da839dcba33637997458627fdc"}, + }) + + assert.NoError(t, err) + assert.Equal(t, int64(3), commitsCount) +} + +func TestCommitsCountWithoutBaseSha256(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256") + + commitsCount, err := CommitsCount(DefaultContext, + CommitsCountOptions{ + RepoPath: bareRepo1Path, + Not: "main", + Revision: []string{"branch1"}, + }) + + assert.NoError(t, err) + assert.Equal(t, int64(2), commitsCount) +} + +func TestGetFullCommitIDSha256(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256") + + id, err := GetFullCommitID(DefaultContext, bareRepo1Path, "f004f4") + assert.NoError(t, err) + assert.Equal(t, "f004f41359117d319dedd0eaab8c5259ee2263da839dcba33637997458627fdc", id) +} + +func TestGetFullCommitIDErrorSha256(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256") + + id, err := GetFullCommitID(DefaultContext, bareRepo1Path, "unknown") + assert.Empty(t, id) + if assert.Error(t, err) { + assert.EqualError(t, err, "object does not exist [id: unknown, rel_path: ]") + } +} + +func TestCommitFromReaderSha256(t *testing.T) { + commitString := `9433b2a62b964c17a4485ae180f45f595d3e69d31b786087775e28c6b6399df0 commit 1114 +tree e7f9e96dd79c09b078cac8b303a7d3b9d65ff9b734e86060a4d20409fd379f9e +parent 26e9ccc29fad747e9c5d9f4c9ddeb7eff61cc45ef6a8dc258cbeb181afc055e8 +author Adam Majer 1698676906 +0100 +committer Adam Majer 1698676906 +0100 +gpgsig-sha256 -----BEGIN PGP SIGNATURE----- +` + " " + ` + iQIrBAABCgAtFiEES+fB08xlgTrzSdQvhkUIsBsmec8FAmU/wKoPHGFtYWplckBz + dXNlLmRlAAoJEIZFCLAbJnnP4s4PQIJATa++WPzR6/H4etT7bsOGoMyguEJYyWOd + aTybplzT7QAL7h2to0QszGabtzMJPIA39xSFZNYNN30voK5YyyYibXluPKgjemfK + WNXwF+gkwgZI38gSvKf+vlqI+EYyIFe19wOhiju0m8SIlB5NEPiWHa17q2mqmqqx + 1FWa2JdqLPYjAtSLFXeSZegrY5V1FxdemyMUONkg8YO9OSIMZiE0GsnnOXQ3xcT4 + JTCnmlUxIKw689UiEY80JopUIq+Wl7+qq9507IYYSUCyB6JazL42AKMzVCbD+qBP + oOzh/hafYgk9H9qCQXaLbmvs17zXRpicig1bAzqgAy1FDelvpERyRTydEajSLIG6 + U1cRCkgXCZ0NfsYNPPmBa8b3+rnstypXYTbyMwTln7FfUAaGo6o9JYiPMkzxlmsy + zfp/tcaY8+LlBL9aOJjtv+a0p+HrpCGd6CCa4ARfphTLq8QRSSh8uzlB9N+6HnRI + VAEUo6ecdDxSpyt2naeg9pKus/BRi7P6g4B1hkk/zZstUX/QP4IQuAJbXjkvsC+X + HKRr3NlRM/DygzTyj0gN74uoa0goCIbyAQhiT42nm0cuhM7uN/W0ayrlZjGF1cbR + 8NCJUL2Nwj0ywKIavC99Ipkb8AsFwpVT6U6effs6 + =xybZ + -----END PGP SIGNATURE----- + +signed commit` + + sha := &Sha256Hash{ + 0x94, 0x33, 0xb2, 0xa6, 0x2b, 0x96, 0x4c, 0x17, 0xa4, 0x48, 0x5a, 0xe1, 0x80, 0xf4, 0x5f, 0x59, + 0x5d, 0x3e, 0x69, 0xd3, 0x1b, 0x78, 0x60, 0x87, 0x77, 0x5e, 0x28, 0xc6, 0xb6, 0x39, 0x9d, 0xf0, + } + gitRepo, err := openRepositoryWithDefaultContext(filepath.Join(testReposDir, "repo1_bare_sha256")) + assert.NoError(t, err) + assert.NotNil(t, gitRepo) + defer gitRepo.Close() + + commitFromReader, err := CommitFromReader(gitRepo, sha, strings.NewReader(commitString)) + assert.NoError(t, err) + if !assert.NotNil(t, commitFromReader) { + return + } + assert.EqualValues(t, sha, commitFromReader.ID) + assert.EqualValues(t, `-----BEGIN PGP SIGNATURE----- + +iQIrBAABCgAtFiEES+fB08xlgTrzSdQvhkUIsBsmec8FAmU/wKoPHGFtYWplckBz +dXNlLmRlAAoJEIZFCLAbJnnP4s4PQIJATa++WPzR6/H4etT7bsOGoMyguEJYyWOd +aTybplzT7QAL7h2to0QszGabtzMJPIA39xSFZNYNN30voK5YyyYibXluPKgjemfK +WNXwF+gkwgZI38gSvKf+vlqI+EYyIFe19wOhiju0m8SIlB5NEPiWHa17q2mqmqqx +1FWa2JdqLPYjAtSLFXeSZegrY5V1FxdemyMUONkg8YO9OSIMZiE0GsnnOXQ3xcT4 +JTCnmlUxIKw689UiEY80JopUIq+Wl7+qq9507IYYSUCyB6JazL42AKMzVCbD+qBP +oOzh/hafYgk9H9qCQXaLbmvs17zXRpicig1bAzqgAy1FDelvpERyRTydEajSLIG6 +U1cRCkgXCZ0NfsYNPPmBa8b3+rnstypXYTbyMwTln7FfUAaGo6o9JYiPMkzxlmsy +zfp/tcaY8+LlBL9aOJjtv+a0p+HrpCGd6CCa4ARfphTLq8QRSSh8uzlB9N+6HnRI +VAEUo6ecdDxSpyt2naeg9pKus/BRi7P6g4B1hkk/zZstUX/QP4IQuAJbXjkvsC+X +HKRr3NlRM/DygzTyj0gN74uoa0goCIbyAQhiT42nm0cuhM7uN/W0ayrlZjGF1cbR +8NCJUL2Nwj0ywKIavC99Ipkb8AsFwpVT6U6effs6 +=xybZ +-----END PGP SIGNATURE----- +`, commitFromReader.Signature.Signature) + assert.EqualValues(t, `tree e7f9e96dd79c09b078cac8b303a7d3b9d65ff9b734e86060a4d20409fd379f9e +parent 26e9ccc29fad747e9c5d9f4c9ddeb7eff61cc45ef6a8dc258cbeb181afc055e8 +author Adam Majer 1698676906 +0100 +committer Adam Majer 1698676906 +0100 + +signed commit`, commitFromReader.Signature.Payload) + assert.EqualValues(t, "Adam Majer ", commitFromReader.Author.String()) + + commitFromReader2, err := CommitFromReader(gitRepo, sha, strings.NewReader(commitString+"\n\n")) + assert.NoError(t, err) + commitFromReader.CommitMessage += "\n\n" + commitFromReader.Signature.Payload += "\n\n" + assert.EqualValues(t, commitFromReader, commitFromReader2) +} + +func TestHasPreviousCommitSha256(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256") + + repo, err := openRepositoryWithDefaultContext(bareRepo1Path) + assert.NoError(t, err) + defer repo.Close() + + commit, err := repo.GetCommit("f004f41359117d319dedd0eaab8c5259ee2263da839dcba33637997458627fdc") + assert.NoError(t, err) + + parentSHA := MustIDFromString("b0ec7af4547047f12d5093e37ef8f1b3b5415ed8ee17894d43a34d7d34212e9c") + notParentSHA := MustIDFromString("42e334efd04cd36eea6da0599913333c26116e1a537ca76e5b6e4af4dda00236") + assert.Equal(t, repo.objectFormat, parentSHA.Type()) + assert.Equal(t, repo.objectFormat.Name(), "sha256") + + haz, err := commit.HasPreviousCommit(parentSHA) + assert.NoError(t, err) + assert.True(t, haz) + + hazNot, err := commit.HasPreviousCommit(notParentSHA) + assert.NoError(t, err) + assert.False(t, hazNot) + + selfNot, err := commit.HasPreviousCommit(commit.ID) + assert.NoError(t, err) + assert.False(t, selfNot) +} + +func TestGetCommitFileStatusMergesSha256(t *testing.T) { + bareRepo1Path := filepath.Join(testReposDir, "repo6_merge_sha256") + + commitFileStatus, err := GetCommitFileStatus(DefaultContext, bareRepo1Path, "d2e5609f630dd8db500f5298d05d16def282412e3e66ed68cc7d0833b29129a1") + assert.NoError(t, err) + + expected := CommitFileStatus{ + []string{ + "add_file.txt", + }, + []string{}, + []string{ + "to_modify.txt", + }, + } + + assert.Equal(t, expected.Added, commitFileStatus.Added) + assert.Equal(t, expected.Removed, commitFileStatus.Removed) + assert.Equal(t, expected.Modified, commitFileStatus.Modified) + + expected = CommitFileStatus{ + []string{}, + []string{ + "to_remove.txt", + }, + []string{}, + } + + commitFileStatus, err = GetCommitFileStatus(DefaultContext, bareRepo1Path, "da1ded40dc8e5b7c564171f4bf2fc8370487decfb1cb6a99ef28f3ed73d09172") + assert.NoError(t, err) + + assert.Equal(t, expected.Added, commitFileStatus.Added) + assert.Equal(t, expected.Removed, commitFileStatus.Removed) + assert.Equal(t, expected.Modified, commitFileStatus.Modified) +} diff --git a/modules/git/git.go b/modules/git/git.go index 24eff05afc..89c23ff230 100644 --- a/modules/git/git.go +++ b/modules/git/git.go @@ -185,7 +185,13 @@ func InitFull(ctx context.Context) (err error) { globalCommandArgs = append(globalCommandArgs, "-c", "credential.helper=") } SupportProcReceive = CheckGitVersionAtLeast("2.29") == nil - SupportHashSha256 = CheckGitVersionAtLeast("2.42") == nil + SupportHashSha256 = CheckGitVersionAtLeast("2.42") == nil && !isGogit + if SupportHashSha256 { + SupportedObjectFormats = append(SupportedObjectFormats, Sha256ObjectFormat) + } else { + log.Warn("sha256 hash support is disabled - requires Git >= 2.42. Gogit is currently unsupported") + } + if setting.LFS.StartServer { if CheckGitVersionAtLeast("2.1.2") != nil { return errors.New("LFS server support requires Git >= 2.1.2") diff --git a/modules/git/object_format.go b/modules/git/object_format.go index 27771e7459..a056b20e8a 100644 --- a/modules/git/object_format.go +++ b/modules/git/object_format.go @@ -5,6 +5,7 @@ package git import ( "crypto/sha1" + "crypto/sha256" "regexp" "strconv" ) @@ -12,6 +13,9 @@ import ( // sha1Pattern can be used to determine if a string is an valid sha var sha1Pattern = regexp.MustCompile(`^[0-9a-f]{4,40}$`) +// sha256Pattern can be used to determine if a string is an valid sha +var sha256Pattern = regexp.MustCompile(`^[0-9a-f]{4,64}$`) + type ObjectFormat interface { // Name returns the name of the object format Name() string @@ -29,11 +33,12 @@ type ObjectFormat interface { ComputeHash(t ObjectType, content []byte) ObjectID } +/* SHA1 Type */ type Sha1ObjectFormatImpl struct{} var ( - emptyObjectID = &Sha1Hash{} - emptyTree = &Sha1Hash{ + emptySha1ObjectID = &Sha1Hash{} + emptySha1Tree = &Sha1Hash{ 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60, 0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04, } @@ -41,11 +46,11 @@ var ( func (Sha1ObjectFormatImpl) Name() string { return "sha1" } func (Sha1ObjectFormatImpl) EmptyObjectID() ObjectID { - return emptyObjectID + return emptySha1ObjectID } func (Sha1ObjectFormatImpl) EmptyTree() ObjectID { - return emptyTree + return emptySha1Tree } func (Sha1ObjectFormatImpl) FullLength() int { return 40 } func (Sha1ObjectFormatImpl) IsValid(input string) bool { @@ -72,11 +77,59 @@ func (h Sha1ObjectFormatImpl) ComputeHash(t ObjectType, content []byte) ObjectID return &sha1 } -var Sha1ObjectFormat ObjectFormat = Sha1ObjectFormatImpl{} +/* SHA256 Type */ +type Sha256ObjectFormatImpl struct{} + +var ( + emptySha256ObjectID = &Sha256Hash{} + emptySha256Tree = &Sha256Hash{ + 0x6e, 0xf1, 0x9b, 0x41, 0x22, 0x5c, 0x53, 0x69, 0xf1, 0xc1, + 0x04, 0xd4, 0x5d, 0x8d, 0x85, 0xef, 0xa9, 0xb0, 0x57, 0xb5, + 0x3b, 0x14, 0xb4, 0xb9, 0xb9, 0x39, 0xdd, 0x74, 0xde, 0xcc, + 0x53, 0x21, + } +) + +func (Sha256ObjectFormatImpl) Name() string { return "sha256" } +func (Sha256ObjectFormatImpl) EmptyObjectID() ObjectID { + return emptySha256ObjectID +} + +func (Sha256ObjectFormatImpl) EmptyTree() ObjectID { + return emptySha256Tree +} +func (Sha256ObjectFormatImpl) FullLength() int { return 64 } +func (Sha256ObjectFormatImpl) IsValid(input string) bool { + return sha256Pattern.MatchString(input) +} + +func (Sha256ObjectFormatImpl) MustID(b []byte) ObjectID { + var id Sha256Hash + copy(id[0:32], b) + return &id +} + +// ComputeHash compute the hash for a given ObjectType and content +func (h Sha256ObjectFormatImpl) ComputeHash(t ObjectType, content []byte) ObjectID { + hasher := sha256.New() + _, _ = hasher.Write(t.Bytes()) + _, _ = hasher.Write([]byte(" ")) + _, _ = hasher.Write([]byte(strconv.FormatInt(int64(len(content)), 10))) + _, _ = hasher.Write([]byte{0}) + + // HashSum generates a SHA256 for the provided hash + var sha256 Sha1Hash + copy(sha256[:], hasher.Sum(nil)) + return &sha256 +} + +var ( + Sha1ObjectFormat ObjectFormat = Sha1ObjectFormatImpl{} + Sha256ObjectFormat ObjectFormat = Sha256ObjectFormatImpl{} +) var SupportedObjectFormats = []ObjectFormat{ Sha1ObjectFormat, - // TODO: add sha256 } func ObjectFormatFromName(name string) ObjectFormat { diff --git a/modules/git/object_id.go b/modules/git/object_id.go index 01c23ed3da..4f8c39ee1d 100644 --- a/modules/git/object_id.go +++ b/modules/git/object_id.go @@ -16,6 +16,7 @@ type ObjectID interface { Type() ObjectFormat } +/* SHA1 */ type Sha1Hash [20]byte func (h *Sha1Hash) String() string { @@ -39,6 +40,21 @@ func MustIDFromString(hexHash string) ObjectID { return id } +/* SHA256 */ +type Sha256Hash [32]byte + +func (h *Sha256Hash) String() string { + return hex.EncodeToString(h[:]) +} + +func (h *Sha256Hash) IsZero() bool { + empty := Sha256Hash{} + return bytes.Equal(empty[:], h[:]) +} +func (h *Sha256Hash) RawValue() []byte { return h[:] } +func (*Sha256Hash) Type() ObjectFormat { return Sha256ObjectFormat } + +/* utility */ func NewIDFromString(hexHash string) (ObjectID, error) { var theObjectFormat ObjectFormat for _, objectFormat := range SupportedObjectFormats { diff --git a/modules/git/object_id_gogit.go b/modules/git/object_id_gogit.go index 0cebb0d50b..db4c4ae0bd 100644 --- a/modules/git/object_id_gogit.go +++ b/modules/git/object_id_gogit.go @@ -13,6 +13,8 @@ func ParseGogitHash(h plumbing.Hash) ObjectID { switch hash.Size { case 20: return Sha1ObjectFormat.MustID(h[:]) + case 32: + return Sha256ObjectFormat.MustID(h[:]) } return nil diff --git a/modules/git/repo.go b/modules/git/repo.go index 7ccce0ba20..c3de2eb0ad 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -97,15 +97,12 @@ func InitRepository(ctx context.Context, repoPath string, bare bool, objectForma } cmd := NewCommand(ctx, "init") - if SupportHashSha256 { - if objectFormatName == "" { - objectFormatName = Sha1ObjectFormat.Name() - } - if !IsValidObjectFormat(objectFormatName) { - return fmt.Errorf("invalid object format: %s", objectFormatName) - } - cmd.AddOptionValues("--object-format", objectFormatName) + + if !IsValidObjectFormat(objectFormatName) { + return fmt.Errorf("invalid object format: %s", objectFormatName) } + cmd.AddOptionValues("--object-format", objectFormatName) + if bare { cmd.AddArguments("--bare") } diff --git a/modules/git/repo_base.go b/modules/git/repo_base.go index 2c6df8b9c4..a9d91d2deb 100644 --- a/modules/git/repo_base.go +++ b/modules/git/repo_base.go @@ -8,6 +8,8 @@ import ( "io" ) +var isGogit bool + // contextKey is a value for use with context.WithValue. type contextKey struct { name string diff --git a/modules/git/repo_base_gogit.go b/modules/git/repo_base_gogit.go index d0b8e79368..90123ee84b 100644 --- a/modules/git/repo_base_gogit.go +++ b/modules/git/repo_base_gogit.go @@ -21,6 +21,10 @@ import ( "github.com/go-git/go-git/v5/storage/filesystem" ) +func init() { + isGogit = true +} + // Repository represents a Git repository. type Repository struct { Path string diff --git a/modules/git/repo_base_nogogit.go b/modules/git/repo_base_nogogit.go index a783366cc1..d5a350a926 100644 --- a/modules/git/repo_base_nogogit.go +++ b/modules/git/repo_base_nogogit.go @@ -15,6 +15,10 @@ import ( "code.gitea.io/gitea/modules/log" ) +func init() { + isGogit = false +} + // Repository represents a Git repository. type Repository struct { Path string diff --git a/modules/git/tests/repos/repo1_bare_sha256/HEAD b/modules/git/tests/repos/repo1_bare_sha256/HEAD new file mode 100644 index 0000000000..b870d82622 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare_sha256/HEAD @@ -0,0 +1 @@ +ref: refs/heads/main diff --git a/modules/git/tests/repos/repo1_bare_sha256/config b/modules/git/tests/repos/repo1_bare_sha256/config new file mode 100644 index 0000000000..2388a50b2f --- /dev/null +++ b/modules/git/tests/repos/repo1_bare_sha256/config @@ -0,0 +1,6 @@ +[core] + repositoryformatversion = 1 + filemode = true + bare = true +[extensions] + objectformat = sha256 diff --git a/modules/git/tests/repos/repo1_bare_sha256/description b/modules/git/tests/repos/repo1_bare_sha256/description new file mode 100644 index 0000000000..498b267a8c --- /dev/null +++ b/modules/git/tests/repos/repo1_bare_sha256/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/modules/git/tests/repos/repo1_bare_sha256/info/exclude b/modules/git/tests/repos/repo1_bare_sha256/info/exclude new file mode 100644 index 0000000000..a5196d1be8 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare_sha256/info/exclude @@ -0,0 +1,6 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ diff --git a/modules/git/tests/repos/repo1_bare_sha256/info/refs b/modules/git/tests/repos/repo1_bare_sha256/info/refs new file mode 100644 index 0000000000..b4de954582 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare_sha256/info/refs @@ -0,0 +1,7 @@ +42e334efd04cd36eea6da0599913333c26116e1a537ca76e5b6e4af4dda00236 refs/heads/branch1 +5bc2249e32e0ba40a08879fba2bd4e97a13cb345831549f4bc5649525da8f6cc refs/heads/branch2 +9433b2a62b964c17a4485ae180f45f595d3e69d31b786087775e28c6b6399df0 refs/heads/main +29a82d4fc02e19190fb489cc90d5730ed91970b49f4e39acda2798b3dd4f814e refs/tags/signed-tag +9433b2a62b964c17a4485ae180f45f595d3e69d31b786087775e28c6b6399df0 refs/tags/signed-tag^{} +171822a62559f3aa28a00aa3785dbe915d6a8eb02712682740db44fc8bd2187a refs/tags/test +6aae864a3d1d0d6a5be0cc64028c1e7021e2632b031fd8eb82afc5a283d1c3d1 refs/tags/test^{} diff --git a/modules/git/tests/repos/repo1_bare_sha256/objects/info/commit-graph b/modules/git/tests/repos/repo1_bare_sha256/objects/info/commit-graph new file mode 100644 index 0000000000000000000000000000000000000000..2985d3e4361fa5d2453795c1d2fa235bc162232b GIT binary patch literal 2048 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 V03y}m<@UOrf!d;j&yBtl{0h7u+fV=i literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare_sha256/objects/pack/pack-c01aa121b9c5e345fe0da2f9be78665970b0c38c6b495d5fc034bc7a7b95334b.pack b/modules/git/tests/repos/repo1_bare_sha256/objects/pack/pack-c01aa121b9c5e345fe0da2f9be78665970b0c38c6b495d5fc034bc7a7b95334b.pack new file mode 100644 index 0000000000000000000000000000000000000000..c77bf2024c8938b19faa05798afe14293fd5f6f5 GIT binary patch literal 5656 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 literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo5_pulls_sha256/objects/pack/pack-bfe8f09d42ef5dd1610bf42641fe145d4a02b788eb26c31022a362312660a29d.pack b/modules/git/tests/repos/repo5_pulls_sha256/objects/pack/pack-bfe8f09d42ef5dd1610bf42641fe145d4a02b788eb26c31022a362312660a29d.pack new file mode 100644 index 0000000000000000000000000000000000000000..689318da321ce6cb4091760f4be5f2685cf60f73 GIT binary patch literal 3140 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 aDGs4tLBeR86E?+rfTCp%3gUL91^)#Odn{D| literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo5_pulls_sha256/objects/pack/pack-bfe8f09d42ef5dd1610bf42641fe145d4a02b788eb26c31022a362312660a29d.rev b/modules/git/tests/repos/repo5_pulls_sha256/objects/pack/pack-bfe8f09d42ef5dd1610bf42641fe145d4a02b788eb26c31022a362312660a29d.rev new file mode 100644 index 0000000000000000000000000000000000000000..c0bac95376c0e5e72e9cbc01721d452b92ab9e02 GIT binary patch literal 140 zcmWIYbctYKU|E5Aa}QVqx(2ba7*V02d(J2f}1=advSGfwGslyEqy_*sLZH8bq=>AlRd<(GZ|G z1Q>xP&=NBN%^$9q8R$2<b`x%G_ue+2{i=dIN3a1%EmS>As>{0< zx?3!*KNT#}7gLXCb8eY_znbeug}=G`!PN4S=w+E&UqA*!)$;(&w*c{BU}?F^W$U?@ fSGM`8IGj_y`_=S^WU;~5MrY2gkE27o$`=Cw{U?2W literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo6_blame_sha256/objects/info/packs b/modules/git/tests/repos/repo6_blame_sha256/objects/info/packs new file mode 100644 index 0000000000..73744cf8f7 --- /dev/null +++ b/modules/git/tests/repos/repo6_blame_sha256/objects/info/packs @@ -0,0 +1,2 @@ +P pack-fcb8a221b76025fd8415d3c562b611ac24312a5ffc3d3703d7c5cc906bdaee8e.pack + diff --git a/modules/git/tests/repos/repo6_blame_sha256/objects/pack/pack-fcb8a221b76025fd8415d3c562b611ac24312a5ffc3d3703d7c5cc906bdaee8e.bitmap b/modules/git/tests/repos/repo6_blame_sha256/objects/pack/pack-fcb8a221b76025fd8415d3c562b611ac24312a5ffc3d3703d7c5cc906bdaee8e.bitmap new file mode 100644 index 0000000000000000000000000000000000000000..c34487c53ad7ebe36637dc0c14255794fa88c940 GIT binary patch literal 318 zcmZ?r4Dn@PWME}rU|{~UW0B(a1l7MSqL+^*Z4+FhVyG4W$JU(r`q48JvTwcX1E~RG zCMX6{V89NgIe;{}+zF^0C#D>u0aOk|F(R=+OpsX&3=TkyW+LN%kOUBbT!LN2Gq4N; z*iYD1w18C1YDj`AM5SgtU)=+fTmC9#b!BC7?(>PMfB)nwe3ldXTA%nM>U!w;$E?$G Hw5c_8Mr59|BS^{cZ;RGbGL1ceRyr_30?6|uFee#i`=4Sc5Kx0ySn6R$o~(M z-8V?~T>KOu9zMJB!sPxHb9b4nRTcSgcha{#)8j5K`Zu|5%hrq+ajeWyEZpoj&gyO8 zvzu^hyZ5&F>{k`!If4yVYlkoS<(|Lk?RMYwOUqCFln9gBy{dl~Pwz1sM?LZ7XATOy zcy|6-n3?dam3R3>(*vfg+SHhQ`_RJVcQN0}_-A~&)GfT&Ow`!>V}Q~ot>i~5cR#T7 zzPP7!BHLSYtzWnHPkZz=jZai`Lem7zg!O#a{SUfKlGWyEc#vr(5xn`$quGmRYVMJ? zY0IDSwED>&Tk!z(+uhritGjzH{IpW*&WZAGZZEUWUIu2vJwObMJEq&fI6MQ)3gW=x zuo1|w1F}PbVmyC#EK=N_p!&B(^zzZ9ZGvl547K9_*qSq6KYC_D_N{k){yr>6_wBeC fyHsyR{c@fO!gKTHKfUbx?NZi?t_J}tFM0z2T;9!# literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo6_blame_sha256/objects/pack/pack-fcb8a221b76025fd8415d3c562b611ac24312a5ffc3d3703d7c5cc906bdaee8e.pack b/modules/git/tests/repos/repo6_blame_sha256/objects/pack/pack-fcb8a221b76025fd8415d3c562b611ac24312a5ffc3d3703d7c5cc906bdaee8e.pack new file mode 100644 index 0000000000000000000000000000000000000000..626f081398c8859462e1323ed5907ca9202772e3 GIT binary patch literal 904 zcmV;319$vTK|@Ob00062000S<5qO-Hj!ACAFbn|ieueIZ11*#&0zr{HppT$TGIdeM zg{LS5n_5m|eLlRG^8ds9W30PtdU|xixm9`LOmB7(-;>Y;hySoZ+?t{Oy zyEAWpyc~~1PonQG6e9mR@ZjEj@P1nMZCl6Ce`eEF#GP*InAe< zlTb&S5O|!G%S%o}F$@LJc~+4*QWd9mJ`$=xj9J8W>`)M|MX#yE@_{8VI-|38_t?pe zyqgvkF(>E!Y~kq;eAe#y->b1KTSZy z9>7D)bf%~n3TX-+Up<1Wck%G{rfQ3ylmo|$q=F&tWmF|qJ%+ELr!n+R=aPh8)i40^=y7x zB5^b8jITq8r0x=q`_EWR0oIu=vatksoCU$b0l**#1HgZ$0TdzQfRX)2=pELM7DZm_ zn2Ux7IzYk7sRX;$E}H8eAz^d+BK%Ry=6ydgI1!+-0(hLu$;?aT$^j9{8Hsu6sVNFM za1k)U1pv~I3vZzVc$_mdFfcPQQAo;3%uUrRsVHF()R5ELyVdSn>W0}3XFZ#rmPp*p zI^*jQBB{HC2&l<)ca41lOn- zYQ_JtHD|tl^vs0pTkrb%+w8Ase{`OHW!*)lj;F4!+Kdk`{F9#E*zn*LXWVbinE=vf BBLx5e literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo6_blame_sha256/packed-refs b/modules/git/tests/repos/repo6_blame_sha256/packed-refs new file mode 100644 index 0000000000..644269299f --- /dev/null +++ b/modules/git/tests/repos/repo6_blame_sha256/packed-refs @@ -0,0 +1,2 @@ +# pack-refs with: peeled fully-peeled sorted +e2f5660e15159082902960af0ed74fc144921d2b0c80e069361853b3ece29ba3 refs/heads/main diff --git a/modules/git/tests/repos/repo6_blame_sha256/refs/refs/main b/modules/git/tests/repos/repo6_blame_sha256/refs/refs/main new file mode 100644 index 0000000000..829662cdf5 --- /dev/null +++ b/modules/git/tests/repos/repo6_blame_sha256/refs/refs/main @@ -0,0 +1 @@ +e2f5660e15159082902960af0ed74fc144921d2b0c80e069361853b3ece29ba3 diff --git a/modules/git/tests/repos/repo6_merge_sha256/HEAD b/modules/git/tests/repos/repo6_merge_sha256/HEAD new file mode 100644 index 0000000000..b870d82622 --- /dev/null +++ b/modules/git/tests/repos/repo6_merge_sha256/HEAD @@ -0,0 +1 @@ +ref: refs/heads/main diff --git a/modules/git/tests/repos/repo6_merge_sha256/config b/modules/git/tests/repos/repo6_merge_sha256/config new file mode 100644 index 0000000000..2388a50b2f --- /dev/null +++ b/modules/git/tests/repos/repo6_merge_sha256/config @@ -0,0 +1,6 @@ +[core] + repositoryformatversion = 1 + filemode = true + bare = true +[extensions] + objectformat = sha256 diff --git a/modules/git/tests/repos/repo6_merge_sha256/description b/modules/git/tests/repos/repo6_merge_sha256/description new file mode 100644 index 0000000000..498b267a8c --- /dev/null +++ b/modules/git/tests/repos/repo6_merge_sha256/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/modules/git/tests/repos/repo6_merge_sha256/info/exclude b/modules/git/tests/repos/repo6_merge_sha256/info/exclude new file mode 100644 index 0000000000..a5196d1be8 --- /dev/null +++ b/modules/git/tests/repos/repo6_merge_sha256/info/exclude @@ -0,0 +1,6 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ diff --git a/modules/git/tests/repos/repo6_merge_sha256/info/refs b/modules/git/tests/repos/repo6_merge_sha256/info/refs new file mode 100644 index 0000000000..7dae8a1be7 --- /dev/null +++ b/modules/git/tests/repos/repo6_merge_sha256/info/refs @@ -0,0 +1,4 @@ +d2e5609f630dd8db500f5298d05d16def282412e3e66ed68cc7d0833b29129a1 refs/heads/main +b45258e9823233edea2d40d183742f29630e1e69300479fb4a55eabfe9b1d8bf refs/heads/merge/add_file +ff2b996e2fa366146300e4c9e51ccb6818147b360e46fa1437334f4a690955ce refs/heads/merge/modify_file +da1ded40dc8e5b7c564171f4bf2fc8370487decfb1cb6a99ef28f3ed73d09172 refs/heads/merge/remove_file diff --git a/modules/git/tests/repos/repo6_merge_sha256/objects/info/commit-graph b/modules/git/tests/repos/repo6_merge_sha256/objects/info/commit-graph new file mode 100644 index 0000000000000000000000000000000000000000..98068475e872f046ba11bdf7d5893f98a0255cbd GIT binary patch literal 1564 zcmZ>E5Aa}QVrB66ba7*VfB+!d2f}0taCUJFfwDiiyEqy_*sKp+UEE!v>@N@+M6&)t zut!;=Auwn|fD!02Vlfj??Lc5=puPAo3s8QrVb+yNp`Ta$%IUmzrTIr&uPbcTdTwHcq=FA;NNf3Hl=&~tO@Z9|rHJ&ByM z$1bh)kj8sy`5Y6@U#FknsM*VK`ova~0$`wmFc7e$x_k`uU6Z@~;FgW2oVPH|ty*RH zI<-O6m}%jx_IWGS7hk`%{X0k@R6Pe!ecdmolM|PPRGoHz`{A~dgbj)KN$0`tzYZ=r15S<>akrf&3`B|<|MSo zCocdgM412Gyp(Hui@tEgmb!Wm@8hRiQ@%`?ih@GWLtd*)S><;PIfe|rq#V*xA; p!1P~weV_M+rsQYMxi5NVEoC)LPOF`?mG!`vkhdpx@4k987XbIX&9eXi literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo6_merge_sha256/objects/info/packs b/modules/git/tests/repos/repo6_merge_sha256/objects/info/packs new file mode 100644 index 0000000000..f3cf8197ce --- /dev/null +++ b/modules/git/tests/repos/repo6_merge_sha256/objects/info/packs @@ -0,0 +1,3 @@ +P pack-2fff0848f8d8eab8f7902ac91ab6a096c7530f577d5c0a79c63d9ac2b44f7510.pack +P pack-65162b86afdbac3c566696d487e67bb2a4a5501ca1fa3528fad8a9474fba7e50.pack + diff --git a/modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-2fff0848f8d8eab8f7902ac91ab6a096c7530f577d5c0a79c63d9ac2b44f7510.bitmap b/modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-2fff0848f8d8eab8f7902ac91ab6a096c7530f577d5c0a79c63d9ac2b44f7510.bitmap new file mode 100644 index 0000000000000000000000000000000000000000..d1624a0780e2ec1c910e845302f8baed9867beba GIT binary patch literal 410 zcmZ?r4Dn@PWME}rU|`k%&*Aao#;YCQCup6N+O}ZY@nHV&+8D0NW45ynZSgM^0I30D zCMX6{U?2~r`G7Q?*JsxOsxM8mSJGv#-$=w2&w|) z9tH*nAVxEzTm&Qm1RP+}0Z5{$2;BjeVPIg#sR9%lU@&X4Q38lDt6}*OFx|ldqTpaw u^V$V44ooeGU%OUD;lo|_NHzYiEy~CCZS$UdE=^oJbZwhC=R2Oy9o7JVEii=u literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-2fff0848f8d8eab8f7902ac91ab6a096c7530f577d5c0a79c63d9ac2b44f7510.idx b/modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-2fff0848f8d8eab8f7902ac91ab6a096c7530f577d5c0a79c63d9ac2b44f7510.idx new file mode 100644 index 0000000000000000000000000000000000000000..09b897d2db2804e585f2fdb78ed661ea4570427f GIT binary patch literal 1696 zcmexg;-AdGz`z8=qk!}fU<7I*7lXna7iI>^5rbKP>hNJ!pgg&l4XBrvm>p<7sh9(( zhgi%BREv(efMT@9+(0|B9} z^vc_pelX@=Tff%#N#os!)ML9|n*UH_%t>gEPhOB4e`(@w{&W|=nX5hZr9b|;AA5@P z)+V3Nh7SS-x12w?xRh&qi@tEgmb!Wm@8hRiQ@%`?ih@GWLtd*)S><;PlVwh0~G z_4-@6e&sv06U#5}sGNJPGNLEY`KqMy^zKPcbLwqFmUKOdoU+F*t@V(`dujO`6V6|! zpWmq2%W(R{R+E)Up`Ta$%IUmzrvpJURJP z=5&UHNVOTC+b=`kN;ZUKg``&^!A7Q zW&NW+b1#3qAZqHi>%X$>g%y_{h4kDNKJ@rjsFysjD7p(QW_|;U5)B}I9Y}it>6buS z3@8^0EXGy<*$*MI?|b$>RGl$~P6V727VZs;iiVye0(vc6E3`~vcyI`oqC}=1 zp(WobSDxN@=(;;$5Eb;&tEN_Z$_NDvn+5AN7LT=vc5BdEW+JsvEvl3#o}h#;k6CC$ zS%Y!R88Aoh6+3Byel#moz|vwqmf09EmKf2HGkHp>>zAit3aKj95JNofD2MBJaJ+)S z0v%oj&2;FokTv9#l$$9vklJkG_x-#L_bj})7k<^@9(lRWpO^QG-itmt$V48fRPSy* zct7=RS>}D$|Ex_fI!@|_F59km`{4e2UQezKUi(=u?q(bFXVff{-ZZP zzOiMK**-p*<5j+47Wrh;KM0ALu9gsZoR!PLO$0FvK+$`u$Q=pUldcmimDbIQ`4}Yr1DHJxXu2Halz!0pu{&P}|LSK{FDj&WCy{HDtqI(HW#ta8XEC zo&L45Hr|M$sDyHtW^7#wKp@*u(Qz|lA`(Jq-mB^EozU>8mDDZieZ8MEznYHxrXN1@ zla9Z>-0nAjG=I*>tpN%V<_AE4)Xy<4YxzI7G<}@kp5yZA=?7DLOxTtXc$}5XO-cqa z3;@u5Ptm;~%}n!C5YYp8h%`xY#5yuxzlFCKkKpR9-nt?(W6{o1w*fm!uN*w8)NX8D zkm^7X1Cgx`rZNakLztT5UX_i~w_fqJvNqZf$F4GzOq!FM?4=AK?+gK(J0YSVlorOW zH4MR_Goywly|4H4%CD|7zv)L@`AO%WFSq+G9zC8jP-_LG66c2kr6fD&Jl2YTwlq&a z#!nu{XQW?yaZCb}5O|!G%Rx?rAq)o4J*QxAVp^aS5@YlL9^!+RIL6;G|1kGgkKpR9 z-ag%9G0bYv$)gOOD0vi0-4sA(A5|K$o3CEu=xBJZ>&7ULJ z-iei3jSs{`VP22pvbX=U1(?Nk`SkDuiBwCblMHyAmCH*C0x=8#(0xyly&&l{{eg%c zz(b^IiX)bhY3Kgp5nR31o4YDxiOp3{Oo^3z&Q!!{2+7N`ByG0X7Q_+e#!@ua6s1%| zDUynJWcZlRZHIg14iA3m4j1k}Z{rwxu6hLb{g&=yJ!Ong7ocjVsFRKh;X( z5SofobMwm}F55X_E@%4k+o?tAj|&6V^Tj`&%UEfwT_ZYS2D667EBmPcXMtBZ=K_F4 zc$@(z0NDS|0hs}ic_3VF?d;=S217#l3){UXwd9tlP(i_@@YYZ;u=@ymG9I}EWf;?a_+Ut zh@L>_tCGsoyC*prLe!V!$LHp!WTsVuHO1t;ee*b$&DrS(_wBvvTc1o@5#V@m$%ktJ z22aF&1ZzSNnu=0$^UG4fns!c@%bC9Xc4|@j!&CM@MQrW(I)taSI^RTmIwVgBo(9KXjc cQL)uig}NGx3>y~(MEy@)IH%pMujOYR01j|Sm;e9( literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-65162b86afdbac3c566696d487e67bb2a4a5501ca1fa3528fad8a9474fba7e50.mtimes b/modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-65162b86afdbac3c566696d487e67bb2a4a5501ca1fa3528fad8a9474fba7e50.mtimes new file mode 100644 index 0000000000000000000000000000000000000000..a669a06e2741e4eb21149dab64899024ca52aa37 GIT binary patch literal 84 zcmV-a0IUB^R82(y000310007IMEVS6MEB)o7AuCY+pIiRW|q{4=6kZFrBEE9`ZXx} q*r`WPx_(dwPSy=szZh0sjm=`$s5CF9=`yxB+tqXRT`xw-u;fjXFeVEC literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-65162b86afdbac3c566696d487e67bb2a4a5501ca1fa3528fad8a9474fba7e50.pack b/modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-65162b86afdbac3c566696d487e67bb2a4a5501ca1fa3528fad8a9474fba7e50.pack new file mode 100644 index 0000000000000000000000000000000000000000..a28808ee11835d7525339f6aae7e862364567183 GIT binary patch literal 447 zcmV;w0YLsxK|@Ob000620007*Bb7cK=)c znBloy;Av^2{`}$L7t5iUu<8bZHh7%-!+f22gF7ROg_()zWN${}NDxCo+rZGkfQ!pF zwJ1GRA*m=aFF7N%SV27(#Me(uNr_L(%t=+(fr%8Q=H{2BLIf2O^HN~qx%nxXX_XLh pE&$6xA~9taD~7MztUOj`mehyld$OdZP#mH9H7NSnsYg$`eo(!B)C~Xt literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-65162b86afdbac3c566696d487e67bb2a4a5501ca1fa3528fad8a9474fba7e50.rev b/modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-65162b86afdbac3c566696d487e67bb2a4a5501ca1fa3528fad8a9474fba7e50.rev new file mode 100644 index 0000000000000000000000000000000000000000..c09bb3203ba74067d70d94bad6ae9ec9b7ac8469 GIT binary patch literal 84 zcmWIYbctYKU|Choose a license. +object_format = Object Format +object_format_helper = Object format of the repository. Cannot be changed later. SHA1 is most compatible. readme = README readme_helper = Select a README file template. readme_helper_desc = This is the place where you can write a complete description for your project. @@ -1038,6 +1040,7 @@ desc.public = Public desc.template = Template desc.internal = Internal desc.archived = Archived +desc.sha256 = SHA256 template.items = Template Items template.git_content = Git Content (Default Branch) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 8ce03cf29c..9810e461de 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -253,7 +253,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre DefaultBranch: opt.DefaultBranch, TrustModel: repo_model.ToTrustModel(opt.TrustModel), IsTemplate: opt.Template, - ObjectFormatName: git.Sha1ObjectFormat.Name(), + ObjectFormatName: opt.ObjectFormatName, }) if err != nil { if repo_model.IsErrRepoAlreadyExist(err) { diff --git a/routers/web/githttp.go b/routers/web/githttp.go index 8d0d1ce03a..ab74e9a333 100644 --- a/routers/web/githttp.go +++ b/routers/web/githttp.go @@ -36,8 +36,8 @@ func gitHTTPRouters(m *web.Route) { m.Methods("GET,OPTIONS", "/objects/info/http-alternates", repo.GetTextFile("objects/info/http-alternates")) m.Methods("GET,OPTIONS", "/objects/info/packs", repo.GetInfoPacks) m.Methods("GET,OPTIONS", "/objects/info/{file:[^/]*}", repo.GetTextFile("")) - m.Methods("GET,OPTIONS", "/objects/{head:[0-9a-f]{2}}/{hash:[0-9a-f]{38}}", repo.GetLooseObject) - m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40}}.pack", repo.GetPackFile) - m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40}}.idx", repo.GetIdxFile) + m.Methods("GET,OPTIONS", "/objects/{head:[0-9a-f]{2}}/{hash:[0-9a-f]{38,62}}", repo.GetLooseObject) + m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.pack", repo.GetPackFile) + m.Methods("GET,OPTIONS", "/objects/pack/pack-{file:[0-9a-f]{40,64}}.idx", repo.GetIdxFile) }, ignSignInAndCsrf, requireSignIn, repo.HTTPGitEnabledHandler, repo.CorsHandler(), context_service.UserAssignmentWeb()) } diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index b5c550ae45..b64db91406 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -159,7 +159,6 @@ func Create(ctx *context.Context) { ctx.Data["private"] = getRepoPrivate(ctx) ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate ctx.Data["default_branch"] = setting.Repository.DefaultBranch - ctx.Data["hash_type"] = "sha1" ctxUser := checkContextUser(ctx, ctx.FormInt64("org")) if ctx.Written() { @@ -179,6 +178,8 @@ func Create(ctx *context.Context) { ctx.Data["CanCreateRepo"] = ctx.Doer.CanCreateRepo() ctx.Data["MaxCreationLimit"] = ctx.Doer.MaxCreationLimit() + ctx.Data["SupportedObjectFormats"] = git.SupportedObjectFormats + ctx.Data["DefaultObjectFormat"] = git.Sha1ObjectFormat ctx.HTML(http.StatusOK, tplCreate) } diff --git a/routers/web/web.go b/routers/web/web.go index 22f98d95de..ff0ce0c258 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -1235,7 +1235,7 @@ func registerRoutes(m *web.Route) { Post(web.Bind(forms.UploadRepoFileForm{}), repo.UploadFilePost) m.Combo("/_diffpatch/*").Get(repo.NewDiffPatch). Post(web.Bind(forms.EditRepoFileForm{}), repo.NewDiffPatchPost) - m.Combo("/_cherrypick/{sha:([a-f0-9]{7,40})}/*").Get(repo.CherryPick). + m.Combo("/_cherrypick/{sha:([a-f0-9]{7,64})}/*").Get(repo.CherryPick). Post(web.Bind(forms.CherryPickForm{}), repo.CherryPickPost) }, repo.MustBeEditable) m.Group("", func() { @@ -1377,8 +1377,8 @@ func registerRoutes(m *web.Route) { m.Combo("/*"). Get(repo.Wiki). Post(context.RepoMustNotBeArchived(), reqSignIn, reqRepoWikiWriter, web.Bind(forms.NewWikiForm{}), repo.WikiPost) - m.Get("/commit/{sha:[a-f0-9]{7,40}}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.Diff) - m.Get("/commit/{sha:[a-f0-9]{7,40}}.{ext:patch|diff}", repo.RawDiff) + m.Get("/commit/{sha:[a-f0-9]{7,64}}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.Diff) + m.Get("/commit/{sha:[a-f0-9]{7,64}}.{ext:patch|diff}", repo.RawDiff) }, repo.MustEnableWiki, func(ctx *context.Context) { ctx.Data["PageIsWiki"] = true ctx.Data["CloneButtonOriginLink"] = ctx.Repo.Repository.WikiCloneLink() @@ -1498,9 +1498,9 @@ func registerRoutes(m *web.Route) { m.Group("", func() { m.Get("/graph", repo.Graph) - m.Get("/commit/{sha:([a-f0-9]{7,40})$}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.Diff) - m.Get("/commit/{sha:([a-f0-9]{7,40})$}/load-branches-and-tags", repo.LoadBranchesAndTags) - m.Get("/cherry-pick/{sha:([a-f0-9]{7,40})$}", repo.SetEditorconfigIfExists, repo.CherryPick) + m.Get("/commit/{sha:([a-f0-9]{7,64})$}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.Diff) + m.Get("/commit/{sha:([a-f0-9]{7,64})$}/load-branches-and-tags", repo.LoadBranchesAndTags) + m.Get("/cherry-pick/{sha:([a-f0-9]{7,64})$}", repo.SetEditorconfigIfExists, repo.CherryPick) }, repo.MustBeNotEmpty, context.RepoRef(), reqRepoCodeReader) m.Get("/rss/branch/*", context.RepoRefByType(context.RepoRefBranch), feedEnabled, feed.RenderBranchFeed) @@ -1517,7 +1517,7 @@ func registerRoutes(m *web.Route) { m.Group("", func() { m.Get("/forks", repo.Forks) }, context.RepoRef(), reqRepoCodeReader) - m.Get("/commit/{sha:([a-f0-9]{7,40})}.{ext:patch|diff}", repo.MustBeNotEmpty, reqRepoCodeReader, repo.RawDiff) + m.Get("/commit/{sha:([a-f0-9]{7,64})}.{ext:patch|diff}", repo.MustBeNotEmpty, reqRepoCodeReader, repo.RawDiff) }, ignSignIn, context.RepoAssignment, context.UnitTypes()) m.Post("/{username}/{reponame}/lastcommit/*", ignSignInAndCsrf, context.RepoAssignment, context.UnitTypes(), context.RepoRefByType(context.RepoRefCommit), reqRepoCodeReader, repo.LastCommit) diff --git a/services/repository/create.go b/services/repository/create.go index bcf2c85c21..0e89573343 100644 --- a/services/repository/create.go +++ b/services/repository/create.go @@ -217,6 +217,10 @@ func CreateRepositoryDirectly(ctx context.Context, doer, u *user_model.User, opt } } + if opts.ObjectFormatName == "" { + opts.ObjectFormatName = git.Sha1ObjectFormat.Name() + } + repo := &repo_model.Repository{ OwnerID: u.ID, Owner: u, diff --git a/services/repository/fork.go b/services/repository/fork.go index 851a69c80f..a8ff2717b0 100644 --- a/services/repository/fork.go +++ b/services/repository/fork.go @@ -76,17 +76,18 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork defaultBranch = opts.SingleBranch } repo := &repo_model.Repository{ - OwnerID: owner.ID, - Owner: owner, - OwnerName: owner.Name, - Name: opts.Name, - LowerName: strings.ToLower(opts.Name), - Description: opts.Description, - DefaultBranch: defaultBranch, - IsPrivate: opts.BaseRepo.IsPrivate || opts.BaseRepo.Owner.Visibility == structs.VisibleTypePrivate, - IsEmpty: opts.BaseRepo.IsEmpty, - IsFork: true, - ForkID: opts.BaseRepo.ID, + OwnerID: owner.ID, + Owner: owner, + OwnerName: owner.Name, + Name: opts.Name, + LowerName: strings.ToLower(opts.Name), + Description: opts.Description, + DefaultBranch: defaultBranch, + IsPrivate: opts.BaseRepo.IsPrivate || opts.BaseRepo.Owner.Visibility == structs.VisibleTypePrivate, + IsEmpty: opts.BaseRepo.IsEmpty, + IsFork: true, + ForkID: opts.BaseRepo.ID, + ObjectFormatName: opts.BaseRepo.ObjectFormatName, } oldRepoPath := opts.BaseRepo.RepoPath() diff --git a/templates/admin/repo/list.tmpl b/templates/admin/repo/list.tmpl index 7102f73305..fdba0734a2 100644 --- a/templates/admin/repo/list.tmpl +++ b/templates/admin/repo/list.tmpl @@ -67,6 +67,9 @@ {{if .IsTemplate}} {{ctx.Locale.Tr "repo.desc.template"}} {{end}} + {{if eq .ObjectFormatName "sha256"}} + {{ctx.Locale.Tr "repo.desc.sha256"}} + {{end}} {{if .IsMirror}} {{svg "octicon-mirror"}} {{else if .IsFork}} diff --git a/templates/explore/repo_list.tmpl b/templates/explore/repo_list.tmpl index b28aa02c1e..c51dcaa3ff 100644 --- a/templates/explore/repo_list.tmpl +++ b/templates/explore/repo_list.tmpl @@ -25,6 +25,9 @@ {{if .IsTemplate}} {{ctx.Locale.Tr "repo.desc.template"}} {{end}} + {{if eq .ObjectFormatName "sha256"}} + {{ctx.Locale.Tr "repo.desc.sha256"}} + {{end}}
diff --git a/templates/repo/commits_list.tmpl b/templates/repo/commits_list.tmpl index 7bfed53124..7702770c40 100644 --- a/templates/repo/commits_list.tmpl +++ b/templates/repo/commits_list.tmpl @@ -3,7 +3,7 @@ {{ctx.Locale.Tr "repo.commits.author"}} - SHA1 + {{StringUtils.ToUpper $.Repository.ObjectFormatName}} {{ctx.Locale.Tr "repo.commits.message"}} {{ctx.Locale.Tr "repo.commits.date"}} diff --git a/templates/repo/create.tmpl b/templates/repo/create.tmpl index 3b4b994be7..66f73fb398 100644 --- a/templates/repo/create.tmpl +++ b/templates/repo/create.tmpl @@ -185,6 +185,19 @@ {{ctx.Locale.Tr "repo.default_branch_helper"}}
+
+ + + {{ctx.Locale.Tr "repo.object_format_helper"}} +
diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index a5ef8daa9a..dac30af600 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -27,6 +27,9 @@ {{ctx.Locale.Tr "repo.desc.template"}}
{{svg "octicon-repo-template" 18}}
{{end}} + {{if eq .ObjectFormatName "sha256"}} + {{ctx.Locale.Tr "repo.desc.sha256"}} + {{end}}
{{if not (or .IsBeingCreated .IsBroken)}} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 094a0e9aec..dc04a97b83 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -18370,6 +18370,15 @@ "uniqueItems": true, "x-go-name": "Name" }, + "object_format_name": { + "description": "ObjectFormatName of the underlying git repository", + "type": "string", + "enum": [ + "sha1", + "sha256" + ], + "x-go-name": "ObjectFormatName" + }, "private": { "description": "Whether the repository is private", "type": "boolean", @@ -22185,6 +22194,15 @@ "type": "string", "x-go-name": "Name" }, + "object_format_name": { + "description": "ObjectFormatName of the underlying git repository", + "type": "string", + "enum": [ + "sha1", + "sha256" + ], + "x-go-name": "ObjectFormatName" + }, "open_issues_count": { "type": "integer", "format": "int64", From 62f995203ab3397a6d995afb80767b33b1f00a1f Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 20 Jan 2024 10:07:31 +0800 Subject: [PATCH 11/26] Move doctor package from modules to services (#28856) --- cmd/doctor.go | 2 +- cmd/doctor_test.go | 2 +- {modules => services}/doctor/authorizedkeys.go | 0 {modules => services}/doctor/breaking.go | 0 {modules => services}/doctor/checkOldArchives.go | 0 {modules => services}/doctor/dbconsistency.go | 0 {modules => services}/doctor/dbversion.go | 0 {modules => services}/doctor/doctor.go | 0 {modules => services}/doctor/fix16961.go | 0 {modules => services}/doctor/fix16961_test.go | 0 {modules => services}/doctor/fix8312.go | 0 {modules => services}/doctor/heads.go | 0 {modules => services}/doctor/lfs.go | 0 {modules => services}/doctor/mergebase.go | 0 {modules => services}/doctor/misc.go | 0 {modules => services}/doctor/paths.go | 0 {modules => services}/doctor/repository.go | 0 {modules => services}/doctor/storage.go | 0 {modules => services}/doctor/usertype.go | 0 19 files changed, 2 insertions(+), 2 deletions(-) rename {modules => services}/doctor/authorizedkeys.go (100%) rename {modules => services}/doctor/breaking.go (100%) rename {modules => services}/doctor/checkOldArchives.go (100%) rename {modules => services}/doctor/dbconsistency.go (100%) rename {modules => services}/doctor/dbversion.go (100%) rename {modules => services}/doctor/doctor.go (100%) rename {modules => services}/doctor/fix16961.go (100%) rename {modules => services}/doctor/fix16961_test.go (100%) rename {modules => services}/doctor/fix8312.go (100%) rename {modules => services}/doctor/heads.go (100%) rename {modules => services}/doctor/lfs.go (100%) rename {modules => services}/doctor/mergebase.go (100%) rename {modules => services}/doctor/misc.go (100%) rename {modules => services}/doctor/paths.go (100%) rename {modules => services}/doctor/repository.go (100%) rename {modules => services}/doctor/storage.go (100%) rename {modules => services}/doctor/usertype.go (100%) diff --git a/cmd/doctor.go b/cmd/doctor.go index f891b12608..e433f4adc5 100644 --- a/cmd/doctor.go +++ b/cmd/doctor.go @@ -15,9 +15,9 @@ import ( "code.gitea.io/gitea/models/migrations" migrate_base "code.gitea.io/gitea/models/migrations/base" "code.gitea.io/gitea/modules/container" - "code.gitea.io/gitea/modules/doctor" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/services/doctor" "github.com/urfave/cli/v2" "xorm.io/xorm" diff --git a/cmd/doctor_test.go b/cmd/doctor_test.go index 75376a567e..3e1ff299c5 100644 --- a/cmd/doctor_test.go +++ b/cmd/doctor_test.go @@ -7,8 +7,8 @@ import ( "context" "testing" - "code.gitea.io/gitea/modules/doctor" "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/services/doctor" "github.com/stretchr/testify/assert" "github.com/urfave/cli/v2" diff --git a/modules/doctor/authorizedkeys.go b/services/doctor/authorizedkeys.go similarity index 100% rename from modules/doctor/authorizedkeys.go rename to services/doctor/authorizedkeys.go diff --git a/modules/doctor/breaking.go b/services/doctor/breaking.go similarity index 100% rename from modules/doctor/breaking.go rename to services/doctor/breaking.go diff --git a/modules/doctor/checkOldArchives.go b/services/doctor/checkOldArchives.go similarity index 100% rename from modules/doctor/checkOldArchives.go rename to services/doctor/checkOldArchives.go diff --git a/modules/doctor/dbconsistency.go b/services/doctor/dbconsistency.go similarity index 100% rename from modules/doctor/dbconsistency.go rename to services/doctor/dbconsistency.go diff --git a/modules/doctor/dbversion.go b/services/doctor/dbversion.go similarity index 100% rename from modules/doctor/dbversion.go rename to services/doctor/dbversion.go diff --git a/modules/doctor/doctor.go b/services/doctor/doctor.go similarity index 100% rename from modules/doctor/doctor.go rename to services/doctor/doctor.go diff --git a/modules/doctor/fix16961.go b/services/doctor/fix16961.go similarity index 100% rename from modules/doctor/fix16961.go rename to services/doctor/fix16961.go diff --git a/modules/doctor/fix16961_test.go b/services/doctor/fix16961_test.go similarity index 100% rename from modules/doctor/fix16961_test.go rename to services/doctor/fix16961_test.go diff --git a/modules/doctor/fix8312.go b/services/doctor/fix8312.go similarity index 100% rename from modules/doctor/fix8312.go rename to services/doctor/fix8312.go diff --git a/modules/doctor/heads.go b/services/doctor/heads.go similarity index 100% rename from modules/doctor/heads.go rename to services/doctor/heads.go diff --git a/modules/doctor/lfs.go b/services/doctor/lfs.go similarity index 100% rename from modules/doctor/lfs.go rename to services/doctor/lfs.go diff --git a/modules/doctor/mergebase.go b/services/doctor/mergebase.go similarity index 100% rename from modules/doctor/mergebase.go rename to services/doctor/mergebase.go diff --git a/modules/doctor/misc.go b/services/doctor/misc.go similarity index 100% rename from modules/doctor/misc.go rename to services/doctor/misc.go diff --git a/modules/doctor/paths.go b/services/doctor/paths.go similarity index 100% rename from modules/doctor/paths.go rename to services/doctor/paths.go diff --git a/modules/doctor/repository.go b/services/doctor/repository.go similarity index 100% rename from modules/doctor/repository.go rename to services/doctor/repository.go diff --git a/modules/doctor/storage.go b/services/doctor/storage.go similarity index 100% rename from modules/doctor/storage.go rename to services/doctor/storage.go diff --git a/modules/doctor/usertype.go b/services/doctor/usertype.go similarity index 100% rename from modules/doctor/usertype.go rename to services/doctor/usertype.go From b9d91694afc4b2b52220450927107e6f44f9a7bd Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Sat, 20 Jan 2024 03:12:20 +0100 Subject: [PATCH 12/26] In administration documentation about environment variables, point to those for the Go runtime instead of Go compiler (#28859) The previous variables are used by the compiler and aren't too useful for non-developers. The newly listed variables are more likely to be of interest. Apologies for this drive-by PR, I probably missed instructions from the contributors guide. The patch can be regarded as a simple way to explain the problem and solution. Feel free to close and possibly create a new PR that does adhere to the contributors guide. --- .../administration/environment-variables.en-us.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/content/administration/environment-variables.en-us.md b/docs/content/administration/environment-variables.en-us.md index f910cf060e..2c6fcbe681 100644 --- a/docs/content/administration/environment-variables.en-us.md +++ b/docs/content/administration/environment-variables.en-us.md @@ -27,14 +27,15 @@ GITEA_CUSTOM=/home/gitea/custom ./gitea web ## From Go language -As Gitea is written in Go, it uses some Go variables, such as: +As Gitea is written in Go, it uses some variables that influence the behaviour of Go's runtime, such as: -- `GOOS` -- `GOARCH` -- [`GOPATH`](https://golang.org/cmd/go/#hdr-GOPATH_environment_variable) +- `GOMEMLIMIT` +- `GOGC` +- `GOMAXPROCS` +- `GODEBUG` For documentation about each of the variables available, refer to the -[official Go documentation](https://golang.org/cmd/go/#hdr-Environment_variables). +[official Go documentation on runtime environment variables](https://pkg.go.dev/runtime#hdr-Environment_Variables). ## Gitea files From 5574968ecbc34908dfa17b28bfc79c3490eaa685 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sat, 20 Jan 2024 04:38:16 +0200 Subject: [PATCH 13/26] Set the `isPermaLink` attribute to `false` in the `guid` sub-element (#28860) Our `guid` is not a valid URL so according to the RSS spec the `isPermaLink` attribute needs to be set to `false`. Example: ```diff yardenshoham opened issue <a href="https://3000-yardenshoham-gitea-jqlxjixsez9.ws-us107.gitpod.io/yardenshoham/test/issues/2">yardenshoham/test#2</a> https://3000-yardenshoham-gitea-jqlxjixsez9.ws-us107.gitpod.io/yardenshoham/test/issues/2 2#hey yardenshoham - 355: https://3000-yardenshoham-gitea-jqlxjixsez9.ws-us107.gitpod.io/yardenshoham/test/issues/2 + 355: https://3000-yardenshoham-gitea-jqlxjixsez9.ws-us107.gitpod.io/yardenshoham/test/issues/2 Tue, 16 Jan 2024 18:54:36 +0000 ``` References: - https://www.rssboard.org/rss-specification#ltguidgtSubelementOfLtitemgt - Fixes https://github.com/go-gitea/gitea/issues/28734 - https://github.com/gorilla/feeds/issues/78 - https://github.com/go-gitea/gitea/pull/21550 - https://github.com/gorilla/feeds/pull/107 Signed-off-by: Yarden Shoham --- go.mod | 2 ++ go.sum | 4 ++-- routers/web/feed/convert.go | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index e1b37c65f6..7bf0804871 100644 --- a/go.mod +++ b/go.mod @@ -306,6 +306,8 @@ replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142 replace github.com/nektos/act => gitea.com/gitea/act v0.2.51 +replace github.com/gorilla/feeds => github.com/yardenshoham/feeds v0.0.0-20240110072658-f3d0c21c0bd5 + exclude github.com/gofrs/uuid v3.2.0+incompatible exclude github.com/gofrs/uuid v4.0.0+incompatible diff --git a/go.sum b/go.sum index ae6c91f902..52aeabfeac 100644 --- a/go.sum +++ b/go.sum @@ -501,8 +501,6 @@ github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8 github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8= github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0= -github.com/gorilla/feeds v1.1.2 h1:pxzZ5PD3RJdhFH2FsJJ4x6PqMqbgFk1+Vez4XWBW8Iw= -github.com/gorilla/feeds v1.1.2/go.mod h1:WMib8uJP3BbY+X8Szd1rA5Pzhdfh+HCCAYT2z7Fza6Y= github.com/gorilla/handlers v1.5.2 h1:cLTUSsNkgcwhgRqvCNmdbRWG0A3N4F+M2nWKdScwyEE= github.com/gorilla/handlers v1.5.2/go.mod h1:dX+xVpaxdSw+q0Qek8SSsl3dfMk3jNddUkMzo0GtH0w= github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= @@ -904,6 +902,8 @@ github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMx github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e h1:+SOyEddqYF09QP7vr7CgJ1eti3pY9Fn3LHO1M1r/0sI= github.com/xrash/smetrics v0.0.0-20231213231151-1d8dd44e695e/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/yardenshoham/feeds v0.0.0-20240110072658-f3d0c21c0bd5 h1:3seWKGVhGoc66Ht5QlhQsr4xT2caDnFegsnh2NqvENU= +github.com/yardenshoham/feeds v0.0.0-20240110072658-f3d0c21c0bd5/go.mod h1:WMib8uJP3BbY+X8Szd1rA5Pzhdfh+HCCAYT2z7Fza6Y= github.com/yohcop/openid-go v1.0.1 h1:DPRd3iPO5F6O5zX2e62XpVAbPT6wV51cuucH0z9g3js= github.com/yohcop/openid-go v1.0.1/go.mod h1:b/AvD03P0KHj4yuihb+VtLD6bYYgsy0zqBzPCRjkCNs= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= diff --git a/routers/web/feed/convert.go b/routers/web/feed/convert.go index 95b1062253..6dbc2c2cbc 100644 --- a/routers/web/feed/convert.go +++ b/routers/web/feed/convert.go @@ -244,6 +244,7 @@ func feedActionsToFeedItems(ctx *context.Context, actions activities_model.Actio Title: title, Link: link, Description: desc, + IsPermaLink: "false", Author: &feeds.Author{ Name: act.ActUser.DisplayName(), Email: act.ActUser.GetEmail(), From 7711db0a7138a063a36a412d9780328795a9cea2 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 20 Jan 2024 23:27:31 +0800 Subject: [PATCH 14/26] Fix migrate storage bug (#28830) --- cmd/migrate_storage.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/migrate_storage.go b/cmd/migrate_storage.go index acc3ba16ba..aa49445a89 100644 --- a/cmd/migrate_storage.go +++ b/cmd/migrate_storage.go @@ -110,6 +110,9 @@ func migrateLFS(ctx context.Context, dstStorage storage.ObjectStorage) error { func migrateAvatars(ctx context.Context, dstStorage storage.ObjectStorage) error { return db.Iterate(ctx, nil, func(ctx context.Context, user *user_model.User) error { + if user.CustomAvatarRelativePath() == "" { + return nil + } _, err := storage.Copy(dstStorage, user.CustomAvatarRelativePath(), storage.Avatars, user.CustomAvatarRelativePath()) return err }) @@ -117,6 +120,9 @@ func migrateAvatars(ctx context.Context, dstStorage storage.ObjectStorage) error func migrateRepoAvatars(ctx context.Context, dstStorage storage.ObjectStorage) error { return db.Iterate(ctx, nil, func(ctx context.Context, repo *repo_model.Repository) error { + if repo.CustomAvatarRelativePath() == "" { + return nil + } _, err := storage.Copy(dstStorage, repo.CustomAvatarRelativePath(), storage.RepoAvatars, repo.CustomAvatarRelativePath()) return err }) From 6c771a311b09c511d837dda79c84264dcf4abb47 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sat, 20 Jan 2024 17:37:32 +0200 Subject: [PATCH 15/26] Run `npm audit fix` (#28866) --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5f4dc9bc2b..b299967eba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11160,9 +11160,9 @@ } }, "node_modules/vite": { - "version": "5.0.10", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.0.10.tgz", - "integrity": "sha512-2P8J7WWgmc355HUMlFrwofacvr98DAjoE52BfdbwQtyLH06XKwaL/FMnmKM2crF0iX4MpmMKoDlNCB1ok7zHCw==", + "version": "5.0.12", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.0.12.tgz", + "integrity": "sha512-4hsnEkG3q0N4Tzf1+t6NdN9dg/L3BM+q8SWgbSPnJvrgH2kgdyzfVJwbR1ic69/4uMJJ/3dqDZZE5/WwqW8U1w==", "dev": true, "dependencies": { "esbuild": "^0.19.3", From 80d48621cdf484247f70ddd653fb4c47a640317a Mon Sep 17 00:00:00 2001 From: sdvcrx Date: Sun, 21 Jan 2024 00:04:47 +0800 Subject: [PATCH 16/26] Fix incorrect PostgreSQL connection string for Unix sockets (#28865) Fix #28864 --- modules/setting/database.go | 4 ++-- modules/setting/database_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/setting/database.go b/modules/setting/database.go index 0b0488ce85..e200b15b2e 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -169,8 +169,8 @@ func getPostgreSQLConnectionString(dbHost, dbUser, dbPasswd, dbName, dbsslMode s RawQuery: dbParam, } query := connURL.Query() - if strings.HasPrefix(dbHost, "/") { // looks like a unix socket - query.Add("host", dbHost) + if strings.HasPrefix(host, "/") { // looks like a unix socket + query.Add("host", host) connURL.Host = ":" + port } query.Set("sslmode", dbsslMode) diff --git a/modules/setting/database_test.go b/modules/setting/database_test.go index 14e0a6ac02..a742d54f8c 100644 --- a/modules/setting/database_test.go +++ b/modules/setting/database_test.go @@ -77,6 +77,14 @@ func Test_getPostgreSQLConnectionString(t *testing.T) { SSLMode: "false", Output: "postgres://testuser:space%20space%20%21%23$%25%5E%5E%25%5E%60%60%60-=%3F=@:5432/gitea?host=%2Ftmp%2Fpg.sock&sslmode=false", }, + { + Host: "/tmp/pg.sock:6432", + User: "testuser", + Passwd: "pass", + Name: "gitea", + SSLMode: "false", + Output: "postgres://testuser:pass@:6432/gitea?host=%2Ftmp%2Fpg.sock&sslmode=false", + }, { Host: "localhost", User: "pgsqlusername", From 14f6fcf4481cedc2cd9d5ea5aaff88e109089e1f Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sat, 20 Jan 2024 21:44:51 +0200 Subject: [PATCH 17/26] Don't do a full page load when clicking the subscribe button (#28871) - Refactor the form around the subscribe button into its own template - Use htmx to perform the form submission - `hx-boost="true"` to prevent the default form submission behavior of a full page load - `hx-sync="this:replace"` to replace the current request (in case the button is clicked again before the response is returned) - `hx-target="this"` to replace the form tag with the new form tag - `hx-push-url="false"` to disable a change to the URL - `hx-swap="show:no-scroll"` to preserve the scroll position - Change the backend response to return a `
` tag instead of a redirect to the issue page - Include `htmx.org` in javascript imports This change introduces htmx with the hope we could use it to make Gitea more reactive while keeping our "HTML rendered on the server" approach. # Before ![before](https://github.com/go-gitea/gitea/assets/20454870/4ec3e81e-4dbf-4338-9968-b0655c276d4c) # After ![after](https://github.com/go-gitea/gitea/assets/20454870/8c8841af-9bfe-40b2-b1cd-cd1f3c90ba4d) --------- Signed-off-by: Yarden Shoham --- package-lock.json | 6 ++++++ package.json | 1 + routers/web/repo/issue_watch.go | 9 ++++++++- templates/repo/issue/view_content/sidebar.tmpl | 14 +------------- templates/repo/issue/view_content/watching.tmpl | 13 +++++++++++++ web_src/js/features/common-global.js | 1 + webpack.config.js | 1 + 7 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 templates/repo/issue/view_content/watching.tmpl diff --git a/package-lock.json b/package-lock.json index b299967eba..d73fc5df5a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,7 @@ "esbuild-loader": "4.0.2", "escape-goat": "4.0.0", "fast-glob": "3.3.2", + "htmx.org": "1.9.10", "jquery": "3.7.1", "katex": "0.16.9", "license-checker-webpack-plugin": "0.2.1", @@ -6158,6 +6159,11 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, + "node_modules/htmx.org": { + "version": "1.9.10", + "resolved": "https://registry.npmjs.org/htmx.org/-/htmx.org-1.9.10.tgz", + "integrity": "sha512-UgchasltTCrTuU2DQLom3ohHrBvwr7OqpwyAVJ9VxtNBng4XKkVsqrv0Qr3srqvM9ZNI3f1MmvVQQqK7KW/bTA==" + }, "node_modules/http-proxy-agent": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.0.tgz", diff --git a/package.json b/package.json index 801e85db83..5c6de1dd62 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "esbuild-loader": "4.0.2", "escape-goat": "4.0.0", "fast-glob": "3.3.2", + "htmx.org": "1.9.10", "jquery": "3.7.1", "katex": "0.16.9", "license-checker-webpack-plugin": "0.2.1", diff --git a/routers/web/repo/issue_watch.go b/routers/web/repo/issue_watch.go index 1cb5cc7162..1f51ceba5e 100644 --- a/routers/web/repo/issue_watch.go +++ b/routers/web/repo/issue_watch.go @@ -8,10 +8,15 @@ import ( "strconv" issues_model "code.gitea.io/gitea/models/issues" + "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" ) +const ( + tplWatching base.TplName = "repo/issue/view_content/watching" +) + // IssueWatch sets issue watching func IssueWatch(ctx *context.Context) { issue := GetActionIssue(ctx) @@ -52,5 +57,7 @@ func IssueWatch(ctx *context.Context) { return } - ctx.Redirect(issue.Link()) + ctx.Data["Issue"] = issue + ctx.Data["IssueWatch"] = &issues_model.IssueWatch{IsWatching: watch} + ctx.HTML(http.StatusOK, tplWatching) } diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 4334e4bcbd..6c13eef023 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -270,19 +270,7 @@
{{ctx.Locale.Tr "notification.notifications"}}
- - - {{$.CsrfTokenHtml}} - - + {{template "repo/issue/view_content/watching" .}}
{{end}} diff --git a/templates/repo/issue/view_content/watching.tmpl b/templates/repo/issue/view_content/watching.tmpl new file mode 100644 index 0000000000..06b9d9af33 --- /dev/null +++ b/templates/repo/issue/view_content/watching.tmpl @@ -0,0 +1,13 @@ +
+ + {{$.CsrfTokenHtml}} + +
diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 0b00eb8e8e..ffa0434cff 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -12,6 +12,7 @@ import {showTemporaryTooltip} from '../modules/tippy.js'; import {confirmModal} from './comp/ConfirmModal.js'; import {showErrorToast} from '../modules/toast.js'; import {request, POST} from '../modules/fetch.js'; +import 'htmx.org'; const {appUrl, appSubUrl, csrfToken, i18n} = window.config; diff --git a/webpack.config.js b/webpack.config.js index 448dc64003..0d8418938f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -214,6 +214,7 @@ export default { }, override: { 'khroma@*': {licenseName: 'MIT'}, // https://github.com/fabiospampinato/khroma/pull/33 + 'htmx.org@1.9.10': {licenseName: 'BSD-2-Clause'}, // "BSD 2-Clause" -> "BSD-2-Clause" }, emitError: true, allow: '(Apache-2.0 OR BSD-2-Clause OR BSD-3-Clause OR MIT OR ISC OR CPAL-1.0 OR Unlicense OR EPL-1.0 OR EPL-2.0)', From 1df06e3f399307c14b60a2b88e1b26cedc1ae2f9 Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sun, 21 Jan 2024 00:37:22 +0200 Subject: [PATCH 18/26] Don't do a full page load when clicking the follow button (#28872) - Use htmx to perform the button request - `hx-headers='{"x-csrf-token": "{{.CsrfToken}}"}'` to authenticate (we should probably learn to reuse this) - `hx-post="{{.ContextUser.HomeLink}}?action=follow"` to send a POST request to follow the user - `hx-target="#profile-avatar-card"` to target the card div for replacement - `hx-swap="outerHTML"` to replace the card (as opposed to its inner content) with the new card that shows the new follower count and button color - Change the backend response to return a `
` tag (the card) instead of a redirect to the user page # Before ![before](https://github.com/go-gitea/gitea/assets/20454870/86899d15-41c9-42ed-bd85-253b9caac7f8) # After ![after](https://github.com/go-gitea/gitea/assets/20454870/59455d96-548c-4a81-a5b0-fab1dc1e87ef) Signed-off-by: Yarden Shoham --- routers/web/user/profile.go | 11 +++++++++-- templates/shared/user/profile_big_avatar.tmpl | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index c5305ebcd9..73ab93caed 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -14,6 +14,7 @@ import ( "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" @@ -26,6 +27,10 @@ import ( shared_user "code.gitea.io/gitea/routers/web/shared/user" ) +const ( + tplProfileBigAvatar base.TplName = "shared/user/profile_big_avatar" +) + // OwnerProfile render profile page for a user or a organization (aka, repo owner) func OwnerProfile(ctx *context.Context) { if strings.Contains(ctx.Req.Header.Get("Accept"), "application/rss+xml") { @@ -309,8 +314,10 @@ func Action(ctx *context.Context) { if err != nil { log.Error("Failed to apply action %q: %v", ctx.FormString("action"), err) - ctx.JSONError(fmt.Sprintf("Action %q failed", ctx.FormString("action"))) + ctx.Error(http.StatusBadRequest, fmt.Sprintf("Action %q failed", ctx.FormString("action"))) return } - ctx.JSONOK() + + shared_user.PrepareContextForProfileBigAvatar(ctx) + ctx.HTML(http.StatusOK, tplProfileBigAvatar) } diff --git a/templates/shared/user/profile_big_avatar.tmpl b/templates/shared/user/profile_big_avatar.tmpl index a637a9a5f9..7afc852d1b 100644 --- a/templates/shared/user/profile_big_avatar.tmpl +++ b/templates/shared/user/profile_big_avatar.tmpl @@ -1,4 +1,4 @@ -
+
{{if eq .SignedUserID .ContextUser.ID}} @@ -110,13 +110,13 @@ {{end}} {{if and .IsSigned (ne .SignedUserID .ContextUser.ID)}} - {{end}} {{if and .IsSigned (ne .SignedUserID .ContextUser.ID)}} -
{{if .IsNothingToCompare}} - {{if and $.IsSigned $.AllowEmptyPr (not .Repository.IsArchived)}} + {{if and $.IsSigned $.AllowEmptyPr (not .Repository.IsArchived) .PageIsComparePull}}
{{ctx.Locale.Tr "repo.pulls.nothing_to_compare_and_allow_empty_pr"}}
@@ -185,8 +185,10 @@
{{template "repo/issue/new_form" .}}
- {{else}} + {{else if and .HeadIsBranch .BaseIsBranch}}
{{ctx.Locale.Tr "repo.pulls.nothing_to_compare"}}
+ {{else}} +
{{ctx.Locale.Tr "repo.pulls.nothing_to_compare_have_tag"}}
{{end}} {{else if and .PageIsComparePull (gt .CommitCount 0)}} {{if .HasPullRequest}} @@ -229,7 +231,7 @@ {{end}} {{$showDiffBox = true}} {{end}} - {{else}} + {{else if not .IsNothingToCompare}} {{$showDiffBox = true}} {{end}}
From caad931385687a06cac73a168a46c00728ed14b6 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Sun, 21 Jan 2024 17:31:29 +0100 Subject: [PATCH 23/26] Prevent anonymous container access if `RequireSignInView` is enabled (#28877) Fixes #28875 If `RequireSignInView` is enabled, the ghost user has no access rights. --- modules/context/package.go | 2 +- routers/api/packages/container/container.go | 19 ++++++++++++++----- .../api_packages_container_test.go | 9 +++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/modules/context/package.go b/modules/context/package.go index 87e817c1cd..c452c657e7 100644 --- a/modules/context/package.go +++ b/modules/context/package.go @@ -93,7 +93,7 @@ func packageAssignment(ctx *packageAssignmentCtx, errCb func(int, string, any)) } func determineAccessMode(ctx *Base, pkg *Package, doer *user_model.User) (perm.AccessMode, error) { - if setting.Service.RequireSignInView && doer == nil { + if setting.Service.RequireSignInView && (doer == nil || doer.IsGhost()) { return perm.AccessModeNone, nil } diff --git a/routers/api/packages/container/container.go b/routers/api/packages/container/container.go index dce3809264..8621242da4 100644 --- a/routers/api/packages/container/container.go +++ b/routers/api/packages/container/container.go @@ -114,11 +114,15 @@ func apiErrorDefined(ctx *context.Context, err *namedError) { }) } -// ReqContainerAccess is a middleware which checks the current user valid (real user or ghost for anonymous access) +func apiUnauthorizedError(ctx *context.Context) { + ctx.Resp.Header().Add("WWW-Authenticate", `Bearer realm="`+setting.AppURL+`v2/token",service="container_registry",scope="*"`) + apiErrorDefined(ctx, errUnauthorized) +} + +// ReqContainerAccess is a middleware which checks the current user valid (real user or ghost if anonymous access is enabled) func ReqContainerAccess(ctx *context.Context) { - if ctx.Doer == nil { - ctx.Resp.Header().Add("WWW-Authenticate", `Bearer realm="`+setting.AppURL+`v2/token",service="container_registry",scope="*"`) - apiErrorDefined(ctx, errUnauthorized) + if ctx.Doer == nil || (setting.Service.RequireSignInView && ctx.Doer.IsGhost()) { + apiUnauthorizedError(ctx) } } @@ -138,10 +142,15 @@ func DetermineSupport(ctx *context.Context) { } // Authenticate creates a token for the current user -// If the current user is anonymous, the ghost user is used +// If the current user is anonymous, the ghost user is used unless RequireSignInView is enabled. func Authenticate(ctx *context.Context) { u := ctx.Doer if u == nil { + if setting.Service.RequireSignInView { + apiUnauthorizedError(ctx) + return + } + u = user_model.NewGhostUser() } diff --git a/tests/integration/api_packages_container_test.go b/tests/integration/api_packages_container_test.go index f32d33888b..509ad424e6 100644 --- a/tests/integration/api_packages_container_test.go +++ b/tests/integration/api_packages_container_test.go @@ -21,6 +21,7 @@ import ( container_module "code.gitea.io/gitea/modules/packages/container" "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/tests" "github.com/minio/sha256-simd" @@ -106,6 +107,14 @@ func TestPackageContainer(t *testing.T) { req = NewRequest(t, "GET", fmt.Sprintf("%sv2", setting.AppURL)). AddTokenAuth(anonymousToken) MakeRequest(t, req, http.StatusOK) + + defer test.MockVariableValue(&setting.Service.RequireSignInView, true)() + + req = NewRequest(t, "GET", fmt.Sprintf("%sv2", setting.AppURL)) + MakeRequest(t, req, http.StatusUnauthorized) + + req = NewRequest(t, "GET", fmt.Sprintf("%sv2/token", setting.AppURL)) + MakeRequest(t, req, http.StatusUnauthorized) }) t.Run("User", func(t *testing.T) { From 692929b628da20258f9f46279142287eb72a843f Mon Sep 17 00:00:00 2001 From: GiteaBot Date: Mon, 22 Jan 2024 00:26:33 +0000 Subject: [PATCH 24/26] [skip ci] Updated licenses and gitignores --- options/license/BSD-Source-beginning-file | 23 +++ options/license/Caldera-no-preamble | 35 +++++ options/license/HPND-MIT-disclaimer | 18 +++ options/license/LPD-document | 8 + options/license/TGPPL-1.0 | 181 ++++++++++++++++++++++ 5 files changed, 265 insertions(+) create mode 100644 options/license/BSD-Source-beginning-file create mode 100644 options/license/Caldera-no-preamble create mode 100644 options/license/HPND-MIT-disclaimer create mode 100644 options/license/LPD-document create mode 100644 options/license/TGPPL-1.0 diff --git a/options/license/BSD-Source-beginning-file b/options/license/BSD-Source-beginning-file new file mode 100644 index 0000000000..6265f97608 --- /dev/null +++ b/options/license/BSD-Source-beginning-file @@ -0,0 +1,23 @@ +Copyright (c) 1997 Justin T. Gibbs. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: +1. Redistributions of source code must retain the above copyright + notice, this list of conditions, and the following disclaimer, + without modification, immediately at the beginning of the file. +2. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +SUCH DAMAGE. diff --git a/options/license/Caldera-no-preamble b/options/license/Caldera-no-preamble new file mode 100644 index 0000000000..f70f34b32b --- /dev/null +++ b/options/license/Caldera-no-preamble @@ -0,0 +1,35 @@ +Copyright(C) Caldera International Inc. 2001-2002. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +Redistributions of source code and documentation must retain the above +copyright notice, this list of conditions and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +All advertising materials mentioning features or use of this software +must display the following acknowledgement: + + This product includes software developed or owned by Caldera + International, Inc. + +Neither the name of Caldera International, Inc. nor the names of other +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA +INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN +NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT, +INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/options/license/HPND-MIT-disclaimer b/options/license/HPND-MIT-disclaimer new file mode 100644 index 0000000000..bf035915cf --- /dev/null +++ b/options/license/HPND-MIT-disclaimer @@ -0,0 +1,18 @@ + LICENSE + ======= + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, provided +that the original copyright notices appear in all copies and that both +copyright notice and this permission notice appear in supporting +documentation, and that the name of the author not be used in advertising +or publicity pertaining to distribution of the software without specific +prior written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/options/license/LPD-document b/options/license/LPD-document new file mode 100644 index 0000000000..0b46392e2f --- /dev/null +++ b/options/license/LPD-document @@ -0,0 +1,8 @@ +Copyright (c) 1996 L. Peter Deutsch + +Permission is granted to copy and distribute this +document for any purpose and without charge, including +translations into other languages and incorporation +into compilations, provided that the copyright notice +and this notice are preserved, and that any substantive +changes or deletions from the original are clearly marked. diff --git a/options/license/TGPPL-1.0 b/options/license/TGPPL-1.0 new file mode 100644 index 0000000000..fbafe92c82 --- /dev/null +++ b/options/license/TGPPL-1.0 @@ -0,0 +1,181 @@ +======================================================= +Transitive Grace Period Public Licence ("TGPPL") v. 1.0 +======================================================= + +This Transitive Grace Period Public Licence (the "License") applies to any +original work of authorship (the "Original Work") whose owner (the +"Licensor") has placed the following licensing notice adjacent to the +copyright notice for the Original Work: + + *Licensed under the Transitive Grace Period Public Licence version 1.0* + +1. **Grant of Copyright License.** Licensor grants You a worldwide, + royalty-free, non-exclusive, sublicensable license, for the duration of + the copyright, to do the following: + + a. to reproduce the Original Work in copies, either alone or as part of a + collective work; + + b. to translate, adapt, alter, transform, modify, or arrange the Original + Work, thereby creating derivative works ("Derivative Works") based upon + the Original Work; + + c. to distribute or communicate copies of the Original Work and Derivative + Works to the public, with the proviso that copies of Original Work or + Derivative Works that You distribute or communicate shall be licensed + under this Transitive Grace Period Public Licence no later than 12 + months after You distributed or communicated said copies; + + d. to perform the Original Work publicly; and + + e. to display the Original Work publicly. + +2. **Grant of Patent License.** Licensor grants You a worldwide, + royalty-free, non-exclusive, sublicensable license, under patent claims + owned or controlled by the Licensor that are embodied in the Original + Work as furnished by the Licensor, for the duration of the patents, to + make, use, sell, offer for sale, have made, and import the Original Work + and Derivative Works. + +3. **Grant of Source Code License.** The term "Source Code" means the + preferred form of the Original Work for making modifications to it and + all available documentation describing how to modify the Original + Work. Licensor agrees to provide a machine-readable copy of the Source + Code of the Original Work along with each copy of the Original Work that + Licensor distributes. Licensor reserves the right to satisfy this + obligation by placing a machine-readable copy of the Source Code in an + information repository reasonably calculated to permit inexpensive and + convenient access by You for as long as Licensor continues to distribute + the Original Work. + +4. **Exclusions From License Grant.** Neither the names of Licensor, nor the + names of any contributors to the Original Work, nor any of their + trademarks or service marks, may be used to endorse or promote products + derived from this Original Work without express prior permission of the + Licensor. Except as expressly stated herein, nothing in this License + grants any license to Licensor's trademarks, copyrights, patents, trade + secrets or any other intellectual property. No patent license is granted + to make, use, sell, offer for sale, have made, or import embodiments of + any patent claims other than the licensed claims defined in Section 2. No + license is granted to the trademarks of Licensor even if such marks are + included in the Original Work. Nothing in this License shall be + interpreted to prohibit Licensor from licensing under terms different + from this License any Original Work that Licensor otherwise would have a + right to license. + +5. **External Deployment.** The term "External Deployment" means the use, + distribution, or communication of the Original Work or Derivative Works + in any way such that the Original Work or Derivative Works may be used by + anyone other than You, whether those works are distributed or + communicated to those persons or made available as an application + intended for use over a network. As an express condition for the grants + of license hereunder, You must treat any External Deployment by You of + the Original Work or a Derivative Work as a distribution under section + 1(c). + +6. **Attribution Rights.** You must retain, in the Source Code of any + Derivative Works that You create, all copyright, patent, or trademark + notices from the Source Code of the Original Work, as well as any notices + of licensing and any descriptive text identified therein as an + "Attribution Notice." You must cause the Source Code for any Derivative + Works that You create to carry a prominent Attribution Notice reasonably + calculated to inform recipients that You have modified the Original Work. + +7. **Warranty of Provenance and Disclaimer of Warranty.** Licensor warrants + that the copyright in and to the Original Work and the patent rights + granted herein by Licensor are owned by the Licensor or are sublicensed + to You under the terms of this License with the permission of the + contributor(s) of those copyrights and patent rights. Except as expressly + stated in the immediately preceding sentence, the Original Work is + provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, + either express or implied, including, without limitation, the warranties + of non-infringement, merchantability or fitness for a particular + purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH + YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this + License. No license to the Original Work is granted by this License + except under this disclaimer. + +8. **Limitation of Liability.** Under no circumstances and under no legal + theory, whether in tort (including negligence), contract, or otherwise, + shall the Licensor be liable to anyone for any indirect, special, + incidental, or consequential damages of any character arising as a result + of this License or the use of the Original Work including, without + limitation, damages for loss of goodwill, work stoppage, computer failure + or malfunction, or any and all other commercial damages or losses. This + limitation of liability shall not apply to the extent applicable law + prohibits such limitation. + +9. **Acceptance and Termination.** If, at any time, You expressly assented + to this License, that assent indicates your clear and irrevocable + acceptance of this License and all of its terms and conditions. If You + distribute or communicate copies of the Original Work or a Derivative + Work, You must make a reasonable effort under the circumstances to obtain + the express assent of recipients to the terms of this License. This + License conditions your rights to undertake the activities listed in + Section 1, including your right to create Derivative Works based upon the + Original Work, and doing so without honoring these terms and conditions + is prohibited by copyright law and international treaty. Nothing in this + License is intended to affect copyright exceptions and limitations + (including 'fair use' or 'fair dealing'). This License shall terminate + immediately and You may no longer exercise any of the rights granted to + You by this License upon your failure to honor the conditions in Section + 1(c). + +10. **Termination for Patent Action.** This License shall terminate + automatically and You may no longer exercise any of the rights granted to + You by this License as of the date You commence an action, including a + cross-claim or counterclaim, against Licensor or any licensee alleging + that the Original Work infringes a patent. This termination provision + shall not apply for an action alleging patent infringement by + combinations of the Original Work with other software or hardware. + +11. **Jurisdiction, Venue and Governing Law.** Any action or suit relating to + this License may be brought only in the courts of a jurisdiction wherein + the Licensor resides or in which Licensor conducts its primary business, + and under the laws of that jurisdiction excluding its conflict-of-law + provisions. The application of the United Nations Convention on Contracts + for the International Sale of Goods is expressly excluded. Any use of the + Original Work outside the scope of this License or after its termination + shall be subject to the requirements and penalties of copyright or patent + law in the appropriate jurisdiction. This section shall survive the + termination of this License. + +12. **Attorneys' Fees.** In any action to enforce the terms of this License + or seeking damages relating thereto, the prevailing party shall be + entitled to recover its costs and expenses, including, without + limitation, reasonable attorneys' fees and costs incurred in connection + with such action, including any appeal of such action. This section shall + survive the termination of this License. + +13. **Miscellaneous.** If any provision of this License is held to be + unenforceable, such provision shall be reformed only to the extent + necessary to make it enforceable. + +14. **Definition of "You" in This License.** "You" throughout this License, + whether in upper or lower case, means an individual or a legal entity + exercising rights under, and complying with all of the terms of, this + License. For legal entities, "You" includes any entity that controls, is + controlled by, or is under common control with you. For purposes of this + definition, "control" means (i) the power, direct or indirect, to cause + the direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + +15. **Right to Use.** You may use the Original Work in all ways not otherwise + restricted or conditioned by this License or by law, and Licensor + promises not to interfere with or be responsible for such uses by You. + +16. **Modification of This License.** This License is Copyright © 2007 Zooko + Wilcox-O'Hearn. Permission is granted to copy, distribute, or communicate + this License without modification. Nothing in this License permits You to + modify this License as applied to the Original Work or to Derivative + Works. However, You may modify the text of this License and copy, + distribute or communicate your modified version (the "Modified License") + and apply it to other original works of authorship subject to the + following conditions: (i) You may not indicate in any way that your + Modified License is the "Transitive Grace Period Public Licence" or + "TGPPL" and you may not use those names in the name of your Modified + License; and (ii) You must replace the notice specified in the first + paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to + the notice in this License. From 23efd9d2781c2ac22594a83afa75182d276b1571 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 22 Jan 2024 10:13:24 +0800 Subject: [PATCH 25/26] Fix schedule not trigger bug because matching full ref name with short ref name (#28874) Fix #28533 Caused by #28691 --- services/actions/notifier_helper.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go index 0618f15602..2a3ffb76f3 100644 --- a/services/actions/notifier_helper.go +++ b/services/actions/notifier_helper.go @@ -159,24 +159,28 @@ func notify(ctx context.Context, input *notifyInput) error { workflows, schedules, err := actions_module.DetectWorkflows(gitRepo, commit, input.Event, input.Payload, - input.Event == webhook_module.HookEventPush && input.Ref == input.Repo.DefaultBranch, + input.Event == webhook_module.HookEventPush && git.RefName(input.Ref).BranchName() == input.Repo.DefaultBranch, ) if err != nil { return fmt.Errorf("DetectWorkflows: %w", err) } - if len(workflows) == 0 { - log.Trace("repo %s with commit %s couldn't find workflows", input.Repo.RepoPath(), commit.ID) - } else { - for _, wf := range workflows { - if actionsConfig.IsWorkflowDisabled(wf.EntryName) { - log.Trace("repo %s has disable workflows %s", input.Repo.RepoPath(), wf.EntryName) - continue - } + log.Trace("repo %s with commit %s event %s find %d workflows and %d schedules", + input.Repo.RepoPath(), + commit.ID, + input.Event, + len(workflows), + len(schedules), + ) - if wf.TriggerEvent.Name != actions_module.GithubEventPullRequestTarget { - detectedWorkflows = append(detectedWorkflows, wf) - } + for _, wf := range workflows { + if actionsConfig.IsWorkflowDisabled(wf.EntryName) { + log.Trace("repo %s has disable workflows %s", input.Repo.RepoPath(), wf.EntryName) + continue + } + + if wf.TriggerEvent.Name != actions_module.GithubEventPullRequestTarget { + detectedWorkflows = append(detectedWorkflows, wf) } } From 8e9b6817bc2032c5af607b63d70ffc7e6599ebbb Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Mon, 22 Jan 2024 08:19:56 +0100 Subject: [PATCH 26/26] Fix `DeleteCollaboration` transaction behaviour (#28886) The method can't be called with an outer transaction because if the user is not a collaborator the outer transaction will be rolled back even if the inner transaction uses the no-error path. `has == 0` leads to `return nil` which cancels the transaction. A standalone call of this method does nothing but if used with an outer transaction, that will be canceled. --- services/repository/collaboration.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/repository/collaboration.go b/services/repository/collaboration.go index eff33c71f3..dccc124748 100644 --- a/services/repository/collaboration.go +++ b/services/repository/collaboration.go @@ -26,9 +26,12 @@ func DeleteCollaboration(ctx context.Context, repo *repo_model.Repository, uid i } defer committer.Close() - if has, err := db.GetEngine(ctx).Delete(collaboration); err != nil || has == 0 { + if has, err := db.GetEngine(ctx).Delete(collaboration); err != nil { return err - } else if err = access_model.RecalculateAccesses(ctx, repo); err != nil { + } else if has == 0 { + return committer.Commit() + } + if err = access_model.RecalculateAccesses(ctx, repo); err != nil { return err }