From d68a613ba8fd860863a3465b5b5945b191b87b25 Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Fri, 19 Jan 2024 16:05:02 +0000 Subject: [PATCH] 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 zcmZ>E5Aa}QVqx(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objects/pack/pack-c01aa121b9c5e345fe0da2f9be78665970b0c38c6b495d5fc034bc7a7b95334b.rev b/modules/git/tests/repos/repo1_bare_sha256/objects/pack/pack-c01aa121b9c5e345fe0da2f9be78665970b0c38c6b495d5fc034bc7a7b95334b.rev new file mode 100644 index 0000000000000000000000000000000000000000..d24fd8e9cefdefb8ddfb268d7b6f8b8e6d447c53 GIT binary patch literal 224 zcmXZWyGnuq0D#exnrV3{%`z)5)zqq!W8@%hPD({v%fGZ02`+(4tvx_3uB}3d5RGo_ zL5)2?wMYbh4{-Qe&BHe45W+fEv4kiVkwFY8gb_g*1#F^(ZRD_q^vwHj16j-?jwJT5 zi)9qCf(7g#fi2``Kb3Lep)!2^Y)q4nzoV=3&c)NqUC=x|8`qw%yZ6IOH_4U!Xd^?`pzQ;%XTw;Il{Re$uBHaK0 literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare_sha256/packed-refs b/modules/git/tests/repos/repo1_bare_sha256/packed-refs new file mode 100644 index 0000000000..36c92ce3ba --- /dev/null +++ b/modules/git/tests/repos/repo1_bare_sha256/packed-refs @@ -0,0 +1,8 @@ +# pack-refs with: peeled fully-peeled sorted +42e334efd04cd36eea6da0599913333c26116e1a537ca76e5b6e4af4dda00236 refs/heads/branch1 +5bc2249e32e0ba40a08879fba2bd4e97a13cb345831549f4bc5649525da8f6cc refs/heads/branch2 +9433b2a62b964c17a4485ae180f45f595d3e69d31b786087775e28c6b6399df0 refs/heads/main +29a82d4fc02e19190fb489cc90d5730ed91970b49f4e39acda2798b3dd4f814e refs/tags/signed-tag +^9433b2a62b964c17a4485ae180f45f595d3e69d31b786087775e28c6b6399df0 +171822a62559f3aa28a00aa3785dbe915d6a8eb02712682740db44fc8bd2187a refs/tags/test +^6aae864a3d1d0d6a5be0cc64028c1e7021e2632b031fd8eb82afc5a283d1c3d1 diff --git a/modules/git/tests/repos/repo1_bare_sha256/refs/heads/main b/modules/git/tests/repos/repo1_bare_sha256/refs/heads/main new file mode 100644 index 0000000000..b09fd5c560 --- /dev/null +++ b/modules/git/tests/repos/repo1_bare_sha256/refs/heads/main @@ -0,0 +1 @@ +9433b2a62b964c17a4485ae180f45f595d3e69d31b786087775e28c6b6399df0 diff --git a/modules/git/tests/repos/repo5_pulls_sha256/HEAD b/modules/git/tests/repos/repo5_pulls_sha256/HEAD new file mode 100644 index 0000000000..b870d82622 --- /dev/null +++ b/modules/git/tests/repos/repo5_pulls_sha256/HEAD @@ -0,0 +1 @@ +ref: refs/heads/main diff --git a/modules/git/tests/repos/repo5_pulls_sha256/config b/modules/git/tests/repos/repo5_pulls_sha256/config new file mode 100644 index 0000000000..2388a50b2f --- /dev/null +++ b/modules/git/tests/repos/repo5_pulls_sha256/config @@ -0,0 +1,6 @@ +[core] + repositoryformatversion = 1 + filemode = true + bare = true +[extensions] + objectformat = sha256 diff --git a/modules/git/tests/repos/repo5_pulls_sha256/description b/modules/git/tests/repos/repo5_pulls_sha256/description new file mode 100644 index 0000000000..498b267a8c --- /dev/null +++ b/modules/git/tests/repos/repo5_pulls_sha256/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/modules/git/tests/repos/repo5_pulls_sha256/info/refs b/modules/git/tests/repos/repo5_pulls_sha256/info/refs new file mode 100644 index 0000000000..454e45de2d --- /dev/null +++ b/modules/git/tests/repos/repo5_pulls_sha256/info/refs @@ -0,0 +1,4 @@ +35ecd0f946c8baeb76fa5a3876f46bf35218655e2304d8505026fa4bfb496a4b refs/heads/main +35ecd0f946c8baeb76fa5a3876f46bf35218655e2304d8505026fa4bfb496a4b refs/heads/main-clone +7f50a4906503378b0bbb7d61bd2ca8d8d8ff4f7a2474980f99402d742ccc9665 refs/heads/test-patch-1 +1e35a51dc00fd7de730344c07061acfe80e8117e075ac979b6a29a3a045190ca refs/tags/v0.9.99 diff --git a/modules/git/tests/repos/repo5_pulls_sha256/objects/info/commit-graph b/modules/git/tests/repos/repo5_pulls_sha256/objects/info/commit-graph new file mode 100644 index 0000000000000000000000000000000000000000..8e5ef41ad69472d47a62c0126c44a28738ddf48f GIT binary patch literal 1544 zcmZ>E5Aa}QVqx(2ba7*V02hBx7as_d#l_jhF$Btf;_l*T1YxsYfzTkp`U1fw3NSJ- zPz^INFp!Ly85oGdEDQ{zn20c71to$}JaWT;J9GQ)l-aRv4}Df|b8BmTdbdbu!kXj% zpRru7xfedE*j3JSsq6v%>-UP8T@Dl^uKCySLa>fK>SX1%MYF6}0whsA%Ne>Qz{;iub)U9Zc2MOl=6$^IN9ks7DWaw8x> z?U(m&&n)lyfF%=Bna#Voch@HF)md@l#()1Rm693!GaYnGbk0mmy*2B=T+ZqxUN2_7 z>D_7iMSH#e&%>V$*8Y35_xa;C=8}J)@~8k(baAAv6qZTuVRvatGVuMt@;v^+?%4+| z&Re-YsC3op`yjKuadF8vkXopEmeiF3osXH<@d~l8Dd>(>J;__myI|>?S;tKp7r18a zd$GZ8--ig0(NOg~sVhZ7_`3gb?bPi~d1$)+;OsWl>NRD3^TYQ>@~=vq`&9bG$vRM( z230SRx>95*U$sssgL7XFvxiLOlz0C7mU3|%(=KG&du<}mto@Iy=Yh&IsCtpqm7)u= pmBP2DD!mOj`TX{|U#`nsJ?A^yFDcZ#I(_%-*K>vc8Y$}d0|2DM$@%~Q literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo5_pulls_sha256/objects/info/packs b/modules/git/tests/repos/repo5_pulls_sha256/objects/info/packs new file mode 100644 index 0000000000..6f51e7b9a8 --- /dev/null +++ b/modules/git/tests/repos/repo5_pulls_sha256/objects/info/packs @@ -0,0 +1,2 @@ +P pack-bfe8f09d42ef5dd1610bf42641fe145d4a02b788eb26c31022a362312660a29d.pack + diff --git a/modules/git/tests/repos/repo5_pulls_sha256/objects/pack/pack-bfe8f09d42ef5dd1610bf42641fe145d4a02b788eb26c31022a362312660a29d.bitmap b/modules/git/tests/repos/repo5_pulls_sha256/objects/pack/pack-bfe8f09d42ef5dd1610bf42641fe145d4a02b788eb26c31022a362312660a29d.bitmap new file mode 100644 index 0000000000000000000000000000000000000000..38fca6e092d53768091823a5f04d2e11c6c73c3d GIT binary patch literal 414 zcmZ?r4Dn@PWME}rU|`+<;=^30_puifxxc76{u7DyV%pyETJ5la(&8jTwS+};L24Kn z7?_|K2IQd(E=)P*2T(ZyOu0WW{UE@I%wb?);0E&@Fm?U^4^_#AOU3# YsWU`hkGuA)Z}K`pLG_R|Gs1TR04qQ*h5!Hn literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo5_pulls_sha256/objects/pack/pack-bfe8f09d42ef5dd1610bf42641fe145d4a02b788eb26c31022a362312660a29d.idx b/modules/git/tests/repos/repo5_pulls_sha256/objects/pack/pack-bfe8f09d42ef5dd1610bf42641fe145d4a02b788eb26c31022a362312660a29d.idx new file mode 100644 index 0000000000000000000000000000000000000000..fd43d04e0a7125dd77aaad27bb23b7201f76adac GIT binary patch literal 1736 zcmexg;-AdGz`(>n8en8#fMaF`28u8X0|QRX%D{jXvoSCbh1nSx1{8BJFpz~g85n4S zxfmEwFgF7O81pbN3^?XxU>FvdkAVR%=4W6ahy@rJ=!>~Cx9?7w9qabcXZ1F>w$`V2 zi-abuIsX3{%jKGT;ggD8`Kon78Jzoam_1}Fr@Zsux0H+Hn06uC-fI(iX6=7uJ&&*Z zAJkrOuQ>|W8);B+VZzTV!#JNwUPn@iiGhHfsfdBfvVrG{E1&M3^HM|h4 zV~;vnxoy!bE0(|sr&N6>GQKVU`?SYB=Z_ww8-Di-MAyc@cH1@rxLYbNZe{vCQYkK^e7U2m-Nl6%-)nvx8B zKd?NHzp#7uL5uTNt`90*wfa8DY;Rm#@~v{p!>ge@N;B=H6o2{(+VJ$P`28j3sh^!) zNnAJcR@V4hzJIL$p1j+Cq@u$vd&V5?yT9I@^HtzG_ovB;YsQ%m_4NTuCZsZ(cXRKq zP28)q;>L~t{#7a^Gx%pZ=$7c5nU=aB?q-LlI+WC6R@}Grs zg%yrmz4Y+n*0QV7Ig-t2w;xQ)5w-(%)=yh7}23c6!ePx4mtE?D|z)^U@@1+H29UTm=2 z_aWlT;l&NS`O~&siL2%2o8cUptaNuvbLdNFP9c&&C= vKxuK3p<2SCxdA8c9-g*z-PZ#ue?{%KcWN5{b&E-yP}TP9zpvT1CA=j7`7&10 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 zcmbu)c{~#g1Hkb)lXF&*QK2DcQ@cjtE~=ht7aOuty3$rv24M+aNeDO-^s)|xm?(NvM}K{i8VrO$?*OL~ zT5y(BTZf+Q=&At?4qm~~xIgo9$s{YEhXBfyJ7Y_mH5b?B0KcpapR%UtUyx|5WPwzNUPpMO4bDcZTL~T4w|4@KMq3AIW@llkJuaKi7#_T^ zmj2(aW(pF{1O>(%`6Y@=>%>prpS}--Kx=_h$sxG)ZSV`#^s&jW6k+l}9yXoObN#YP z&HD6mxVh|5l#;vSC)3E%ADwzb>}I%4QD;V&VKK`r*1&$u)cKJ254~-M@SvhDCqAH8 zyqqo?cJu1s1O#7A{e07D#L$2bXX+b1dgb9~ITu}i^XE=_{UV;Vy8U1;F;!8w%RUB?=7ZZ{mB+%0s)80@5G?N|9=jKjz6oxvk z9oF=BKY0`p(a$piosKB=uGs4S4M_fv*=Sv%It3)zetgy%w8e9{AFa_&;dkiA7qth>$o`Xon>`( z%uK_bW z3O|)bT6pEwPV<_!!Ps1^HLfOu@>Rxb*P-d6KbCx80Y5e|t%mlCp97cVWQU&nVd@sB zljc^e0(`;OSRPB-D0SE~dn7B-hussbV)z$cR1}Y%HQc%PJchxeDU)AlJGN6;r&nnj zN-X;kIc0GuV8IpH#b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v)nM24K7GGpKPade?bebE6ca{LGW#`Dhq2_egqRD z(~U7{lo7R0v6*vLu*dsZL0;}f-R_At{ZuKCJWuFym8^U)D-`iMt*T7_wN!GSTU0_r zaNHATG0@^;i+Vz{g-(}yL%i{&i)6TuQ*lH0{VyMRLu#b=4B2uQ)qEc@_c4YFK68u! z1irC2^@?V~62A4kk9K-4spv#@=3fZ{TyJ6yMn?<&-CsC8XF2%0UNvPFYQBgi$RIuXEp=27w=c>6FAjSwRR910 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|?imU|?ckVBlt8U|?flU|?l{0A?gPeg*~xJ_ZH`4h9AWb_NCp9tH*m zE(Qh$P6h@B76t|e-u*8=%yoJndohvwi<;v;t1 hQE5Aa}QVqx(2ba7*V02hBx7as_d#l_jhF$Bt9;_l*T1Yxt9KxhzPbwIF3!6={@ zFfuUE6f-d}3|q|1z(9XI*?og#&&5vx;^DI^FHG)VF?W~AT2+w`cPD+@Gd=F&qJOKk z!j_=)Pp-}l3X9yLW_E1U^1Hg^YRLZ&p!8Az zNp>8mF7H_;*KOIF@gk0uIf{jw{l;0n4SaSJZf*D8HlO{ff;>mC0Z1)WJxi*~yBE4! zEUiBkEYcTKk7sjknSQ^T>qmvZx%d}8X~Kluuu<%GW0C;o`K9(w*U>$Kc$3IIHT BE$RRO literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo6_blame_sha256/objects/pack/pack-fcb8a221b76025fd8415d3c562b611ac24312a5ffc3d3703d7c5cc906bdaee8e.idx b/modules/git/tests/repos/repo6_blame_sha256/objects/pack/pack-fcb8a221b76025fd8415d3c562b611ac24312a5ffc3d3703d7c5cc906bdaee8e.idx new file mode 100644 index 0000000000000000000000000000000000000000..faaee22ff4aab77fb7cc84887a94d54d603b713b GIT binary patch literal 1456 zcmexg;-AdGz`(>n9l*%IKvxWM_b47bVZhA50LH8g3^c`T3=A~E>)HIYMB--F8DEDGN!=wJ_n)zt>Ta>L{#39?Uraro&ADaz z{c5fs75?V#2UE*SqL*cAeVO=HZtk|Nu@A3pJ)tZ9$YVGhPzufaTz1{A+erfrspAunGyI1w^;^{qRo8EV=Eq@e!F|ya&>plg`ZYx-8oVI&Fy8@*~<(JOnVp@m^c|2m~JyLFq~mv zU>0X!U~FVyV5(zaU=C$qVBq<)W0B(a1l7MSqL+^*Z4+FhVyG4W$JU(r`q48JvTwcX n^Y>vnx^KtD*rj?i>X-9O5T2Vi|LJAlZLS5n_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{HCqpN_$iDTiufNUyiuOn6=~vcWWa@b8>Z;B7@WMao>5UB!UUA0# H)|?3d(q|(D 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=6_7as_dCBWImF$Bu~;O^pR1Yxs2aCLEag|fduXb@oi zgJ6$>Q7~u$BLf4`n2CX5Krk}{176I+z%b}A>&m3i&ntfAbY8pD%}5E8Vyj630|NsHgTgk|N!$fKGywmIyrG!NY!cgw~vmQi11Z)NN3)63laKi zYc-(hfZba&_T`$dlC^F_Gw8tke zKsEonc`4WS7JcD}Ep_!C-p5b3rhJt+*rD=0;akkQ_ROm$%a5U||MnPS6$W5wU|?V@ my}r+TLsRmz=G+%OvzD@&Ca2X-+RA$1OUT<3yLVqbnhOB;yv?%! 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^0I6YM zU|@n`7?6iD_%P*k5}X3djMB3=CvrP?+Pw%nS@fVHO4kyqJ}Nfo#miz(7;X&cHx2=3rnT z8gnu*U|=o=2AX4T1_r#Chk=1)%*(()HO$ArfPwja*W@lgxMkxh=PgWgt5zAlPHhl1 zW?DF_ecnp-#n*3b{~nX~_RZs1HfN_F+_(3tZ+$XtMS$bMB_FN@7(5a85v&PGK5sL< z^7f@4jQQ8rul0S>csC;T*sho6KNJ~r658XF7v#oYnz)-k-NkR_YEOOXkALpRp5nZ< z$>+1-gFwM8=MOF}<=Wn&FC4L@uHM7@`03V^uM!74RK6#Ci&@v6dDUe3u@;+cLPvMK z{#LGE`A+S`^2<9a=U%If=m~VbDyclZdy><}xN4?z=6!Egj$oTCm zU5AU!CHk7ld~%rvES0~#LSOBFx$(ySofGDArZ2ypT9p2{Fkn4j{NuTdmB!jNq7!B? zYiPW(pL*$O!u(|38@B`agJxWa6}$JT$x+WP?QO=HS`On)6Ezp!l6~uNr!TrD%(3vx ze*F{XEbaHsZ#%aEQJpILKBFPL-PCk`6 zogpDoZN}&JOT^sR-z$?d^xSMsm96)^W;?3y`J~;MYa;&8)A`Edzn1q8b2k>f{o#ID z|LD)$%O5X@n!4@!uPl3E#pOpKJ$HotHKQ8?1FJa$1It1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!{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@Mp>(CbeQi0G}Ce``6`hx53 dIVgJUTK{LltM3=Lf4nh;@x*h{SHFHw0Ra4ABzXV; literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-65162b86afdbac3c566696d487e67bb2a4a5501ca1fa3528fad8a9474fba7e50.idx b/modules/git/tests/repos/repo6_merge_sha256/objects/pack/pack-65162b86afdbac3c566696d487e67bb2a4a5501ca1fa3528fad8a9474fba7e50.idx new file mode 100644 index 0000000000000000000000000000000000000000..3b58342e68711ff246ea9624745cf1ae9f13639e GIT binary patch literal 1176 zcmexg;-AdGz`(>Xuz-<)VZ>liSdZe-Fc?&6K%S?2BFAB^z)zBZu?b6?cBTDU^`<3D17sHdGS&EXW2L+QuDXCg3-ezO<@h~r ciHfbBD%90jWZ1YUAnJeW!a413eJwxp01j|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|?imU|?c^0LD}??Y8x|*Vu%mO}o3_ett$YXdm>~2 literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo6_merge_sha256/packed-refs b/modules/git/tests/repos/repo6_merge_sha256/packed-refs new file mode 100644 index 0000000000..b906893c52 --- /dev/null +++ b/modules/git/tests/repos/repo6_merge_sha256/packed-refs @@ -0,0 +1,5 @@ +# pack-refs with: peeled fully-peeled sorted +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/refs/heads/main b/modules/git/tests/repos/repo6_merge_sha256/refs/heads/main new file mode 100644 index 0000000000..c8c02921e1 --- /dev/null +++ b/modules/git/tests/repos/repo6_merge_sha256/refs/heads/main @@ -0,0 +1 @@ +d2e5609f630dd8db500f5298d05d16def282412e3e66ed68cc7d0833b29129a1 diff --git a/modules/markup/html.go b/modules/markup/html.go index a64e4c565d..33dc1e9086 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -45,19 +45,19 @@ var ( // valid chars in encoded path and parameter: [-+~_%.a-zA-Z0-9/] - // sha1CurrentPattern matches string that represents a commit SHA, e.g. d8a994ef243349f321568f9e36d5c3f444b99cae - // Although SHA1 hashes are 40 chars long, the regex matches the hash from 7 to 40 chars in length + // hashCurrentPattern matches string that represents a commit SHA, e.g. d8a994ef243349f321568f9e36d5c3f444b99cae + // Although SHA1 hashes are 40 chars long, SHA256 are 64, the regex matches the hash from 7 to 64 chars in length // so that abbreviated hash links can be used as well. This matches git and GitHub usability. - sha1CurrentPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-f]{7,40})(?:\s|$|\)|\]|[.,](\s|$))`) + hashCurrentPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-f]{7,64})(?:\s|$|\)|\]|[.,](\s|$))`) // shortLinkPattern matches short but difficult to parse [[name|link|arg=test]] syntax shortLinkPattern = regexp.MustCompile(`\[\[(.*?)\]\](\w*)`) // anySHA1Pattern splits url containing SHA into parts - anySHA1Pattern = regexp.MustCompile(`https?://(?:\S+/){4,5}([0-9a-f]{40})(/[-+~_%.a-zA-Z0-9/]+)?(#[-+~_%.a-zA-Z0-9]+)?`) + anyHashPattern = regexp.MustCompile(`https?://(?:\S+/){4,5}([0-9a-f]{40,64})(/[-+~_%.a-zA-Z0-9/]+)?(#[-+~_%.a-zA-Z0-9]+)?`) // comparePattern matches "http://domain/org/repo/compare/COMMIT1...COMMIT2#hash" - comparePattern = regexp.MustCompile(`https?://(?:\S+/){4,5}([0-9a-f]{7,40})(\.\.\.?)([0-9a-f]{7,40})?(#[-+~_%.a-zA-Z0-9]+)?`) + comparePattern = regexp.MustCompile(`https?://(?:\S+/){4,5}([0-9a-f]{7,64})(\.\.\.?)([0-9a-f]{7,64})?(#[-+~_%.a-zA-Z0-9]+)?`) validLinksPattern = regexp.MustCompile(`^[a-z][\w-]+://`) @@ -171,13 +171,13 @@ type processor func(ctx *RenderContext, node *html.Node) var defaultProcessors = []processor{ fullIssuePatternProcessor, comparePatternProcessor, - fullSha1PatternProcessor, + fullHashPatternProcessor, shortLinkProcessor, linkProcessor, mentionProcessor, issueIndexPatternProcessor, commitCrossReferencePatternProcessor, - sha1CurrentPatternProcessor, + hashCurrentPatternProcessor, emailAddressProcessor, emojiProcessor, emojiShortCodeProcessor, @@ -199,12 +199,12 @@ func PostProcess( var commitMessageProcessors = []processor{ fullIssuePatternProcessor, comparePatternProcessor, - fullSha1PatternProcessor, + fullHashPatternProcessor, linkProcessor, mentionProcessor, issueIndexPatternProcessor, commitCrossReferencePatternProcessor, - sha1CurrentPatternProcessor, + hashCurrentPatternProcessor, emailAddressProcessor, emojiProcessor, emojiShortCodeProcessor, @@ -231,12 +231,12 @@ func RenderCommitMessage( var commitMessageSubjectProcessors = []processor{ fullIssuePatternProcessor, comparePatternProcessor, - fullSha1PatternProcessor, + fullHashPatternProcessor, linkProcessor, mentionProcessor, issueIndexPatternProcessor, commitCrossReferencePatternProcessor, - sha1CurrentPatternProcessor, + hashCurrentPatternProcessor, emojiShortCodeProcessor, emojiProcessor, } @@ -273,7 +273,7 @@ func RenderIssueTitle( return renderProcessString(ctx, []processor{ issueIndexPatternProcessor, commitCrossReferencePatternProcessor, - sha1CurrentPatternProcessor, + hashCurrentPatternProcessor, emojiShortCodeProcessor, emojiProcessor, }, title) @@ -946,15 +946,15 @@ func commitCrossReferencePatternProcessor(ctx *RenderContext, node *html.Node) { } } -// fullSha1PatternProcessor renders SHA containing URLs -func fullSha1PatternProcessor(ctx *RenderContext, node *html.Node) { +// fullHashPatternProcessor renders SHA containing URLs +func fullHashPatternProcessor(ctx *RenderContext, node *html.Node) { if ctx.Metas == nil { return } next := node.NextSibling for node != nil && node != next { - m := anySHA1Pattern.FindStringSubmatchIndex(node.Data) + m := anyHashPattern.FindStringSubmatchIndex(node.Data) if m == nil { return } @@ -1111,9 +1111,9 @@ func emojiProcessor(ctx *RenderContext, node *html.Node) { } } -// sha1CurrentPatternProcessor renders SHA1 strings to corresponding links that +// hashCurrentPatternProcessor renders SHA1 strings to corresponding links that // are assumed to be in the same repository. -func sha1CurrentPatternProcessor(ctx *RenderContext, node *html.Node) { +func hashCurrentPatternProcessor(ctx *RenderContext, node *html.Node) { if ctx.Metas == nil || ctx.Metas["user"] == "" || ctx.Metas["repo"] == "" || ctx.Metas["repoPath"] == "" { return } @@ -1124,7 +1124,7 @@ func sha1CurrentPatternProcessor(ctx *RenderContext, node *html.Node) { ctx.ShaExistCache = make(map[string]bool) } for node != nil && node != next && start < len(node.Data) { - m := sha1CurrentPattern.FindStringSubmatchIndex(node.Data[start:]) + m := hashCurrentPattern.FindStringSubmatchIndex(node.Data[start:]) if m == nil { return } diff --git a/modules/markup/html_internal_test.go b/modules/markup/html_internal_test.go index 5ba9561915..93ba9d7667 100644 --- a/modules/markup/html_internal_test.go +++ b/modules/markup/html_internal_test.go @@ -390,10 +390,10 @@ func TestRegExp_sha1CurrentPattern(t *testing.T) { } for _, testCase := range trueTestCases { - assert.True(t, sha1CurrentPattern.MatchString(testCase)) + assert.True(t, hashCurrentPattern.MatchString(testCase)) } for _, testCase := range falseTestCases { - assert.False(t, sha1CurrentPattern.MatchString(testCase)) + assert.False(t, hashCurrentPattern.MatchString(testCase)) } } @@ -427,7 +427,7 @@ func TestRegExp_anySHA1Pattern(t *testing.T) { } for k, v := range testCases { - assert.Equal(t, anySHA1Pattern.FindStringSubmatch(k)[1:], v) + assert.Equal(t, anyHashPattern.FindStringSubmatch(k)[1:], v) } } diff --git a/modules/references/references.go b/modules/references/references.go index 64a67d7da7..7758312564 100644 --- a/modules/references/references.go +++ b/modules/references/references.go @@ -39,7 +39,7 @@ var ( crossReferenceIssueNumericPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-zA-Z-_\.]+/[0-9a-zA-Z-_\.]+[#!][0-9]+)(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`) // crossReferenceCommitPattern matches a string that references a commit in a different repository // e.g. go-gitea/gitea@d8a994ef, go-gitea/gitea@d8a994ef243349f321568f9e36d5c3f444b99cae (7-40 characters) - crossReferenceCommitPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-zA-Z-_\.]+)/([0-9a-zA-Z-_\.]+)@([0-9a-f]{7,40})(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`) + crossReferenceCommitPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-zA-Z-_\.]+)/([0-9a-zA-Z-_\.]+)@([0-9a-f]{7,64})(?:\s|$|\)|\]|[:;,.?!]\s|[:;,.?!]$)`) // spaceTrimmedPattern let's find the trailing space spaceTrimmedPattern = regexp.MustCompile(`(?:.*[0-9a-zA-Z-_])\s`) // timeLogPattern matches string for time tracking diff --git a/modules/references/references_test.go b/modules/references/references_test.go index b60d6b0459..ba7dda80cc 100644 --- a/modules/references/references_test.go +++ b/modules/references/references_test.go @@ -343,7 +343,7 @@ func TestFindRenderizableCommitCrossReference(t *testing.T) { }, }, { - Input: "go-gitea/gitea@abcd1234abcd1234abcd1234abcd1234abcd12340", // longer than 40 characters + Input: "go-gitea/gitea@abcd1234abcd1234abcd1234abcd1234abcd12341234512345123451234512345", // longer than 64 characters Expected: nil, }, { diff --git a/modules/structs/repo.go b/modules/structs/repo.go index 3974c4db3a..51e175fba8 100644 --- a/modules/structs/repo.go +++ b/modules/structs/repo.go @@ -105,6 +105,9 @@ type Repository struct { AvatarURL string `json:"avatar_url"` Internal bool `json:"internal"` MirrorInterval string `json:"mirror_interval"` + // ObjectFormatName of the underlying git repository + // enum: sha1,sha256 + ObjectFormatName string `json:"object_format_name"` // swagger:strfmt date-time MirrorUpdated time.Time `json:"mirror_updated,omitempty"` RepoTransfer *RepoTransfer `json:"repo_transfer"` @@ -139,6 +142,9 @@ type CreateRepoOption struct { // TrustModel of the repository // enum: default,collaborator,committer,collaboratorcommitter TrustModel string `json:"trust_model"` + // ObjectFormatName of the underlying git repository + // enum: sha1,sha256 + ObjectFormatName string `json:"object_format_name" binding:"MaxSize(6)"` } // EditRepoOption options when editing a repository's properties diff --git a/modules/templates/util_string.go b/modules/templates/util_string.go index 18a0d5cacc..2771b1e223 100644 --- a/modules/templates/util_string.go +++ b/modules/templates/util_string.go @@ -41,3 +41,7 @@ func (su *StringUtils) Cut(s, sep string) []any { func (su *StringUtils) EllipsisString(s string, max int) string { return base.EllipsisString(s, max) } + +func (su *StringUtils) ToUpper(s string) string { + return strings.ToUpper(s) +} diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index e8345595aa..5448db4b99 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -970,6 +970,8 @@ issue_labels_helper = Select an issue label set. license = License license_helper = Select a license file. license_helper_desc = A license governs what others can and can't do with your code. Not sure which one is right for your project? See 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",