From c46316f7aec1a00b3db74a3565008c44c0b0807f Mon Sep 17 00:00:00 2001
From: KN4CK3R
Date: Thu, 25 Jan 2024 09:54:44 +0100
Subject: [PATCH 01/17] Respect branch info for relative links (#28909)
Fix #28904
Co-authored-by: Giteabot
---
modules/markup/markdown/goldmark.go | 2 ++
modules/markup/markdown/markdown_test.go | 4 ++--
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/modules/markup/markdown/goldmark.go b/modules/markup/markdown/goldmark.go
index b92b90561b990..1db3cbad7e1b0 100644
--- a/modules/markup/markdown/goldmark.go
+++ b/modules/markup/markdown/goldmark.go
@@ -137,6 +137,8 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
var base string
if ctx.IsWiki {
base = ctx.Links.WikiLink()
+ } else if ctx.Links.HasBranchInfo() {
+ base = ctx.Links.SrcLink()
} else {
base = ctx.Links.Base
}
diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go
index 957d773acde18..1edfb3e664463 100644
--- a/modules/markup/markdown/markdown_test.go
+++ b/modules/markup/markdown/markdown_test.go
@@ -765,7 +765,7 @@ space
Expected: `space @mention-user
/just/a/path.bin
https://example.com/file.bin
-local link
+local link
remote link
local link
remote link
@@ -878,7 +878,7 @@ space
Expected: `space @mention-user
/just/a/path.bin
https://example.com/file.bin
-local link
+local link
remote link
local link
remote link
From 071b7b2a0308d3b65f2deafc0a004a340e6ead86 Mon Sep 17 00:00:00 2001
From: Zettat123
Date: Thu, 25 Jan 2024 20:06:29 +0800
Subject: [PATCH 02/17] Implement `MigrateRepository` for the actions notifier
(#28920)
Fixes #28699
This PR implements the `MigrateRepository` method for `actionsNotifier`
to detect the schedules from the workflow files in the migrated
repository.
---
services/actions/notifier.go | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/services/actions/notifier.go b/services/actions/notifier.go
index 5a71d1cd791f7..0b4fed5db1282 100644
--- a/services/actions/notifier.go
+++ b/services/actions/notifier.go
@@ -565,3 +565,15 @@ func (n *actionsNotifier) DeleteWikiPage(ctx context.Context, doer *user_model.U
Page: page,
}).Notify(ctx)
}
+
+// MigrateRepository is used to detect workflows after a repository has been migrated
+func (n *actionsNotifier) MigrateRepository(ctx context.Context, doer, u *user_model.User, repo *repo_model.Repository) {
+ ctx = withMethod(ctx, "MigrateRepository")
+
+ newNotifyInput(repo, doer, webhook_module.HookEventRepository).WithPayload(&api.RepositoryPayload{
+ Action: api.HookRepoCreated,
+ Repository: convert.ToRepo(ctx, repo, access_model.Permission{AccessMode: perm_model.AccessModeOwner}),
+ Organization: convert.ToUser(ctx, u, nil),
+ Sender: convert.ToUser(ctx, doer, nil),
+ }).Notify(ctx)
+}
From 3084c990b04aea16278f012da38152ada1290a0d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Anthony=20Qu=C3=A9r=C3=A9?=
<47711333+Anthony-Jhoiro@users.noreply.github.com>
Date: Thu, 25 Jan 2024 13:51:32 +0100
Subject: [PATCH 03/17] fix: update enable_prune even if mirror_interval is not
provided (#28905)
Currently, the `updateMirror` function which update the mirror interval
and enable prune properties is only executed by the `Edit` function. But
it is only triggered if `opts.MirrorInterval` is not null, even if
`opts.EnablePrune` is not null.
With this patch, it is now possible to update the enable_prune property
with a patch request without modifying the mirror_interval.
## Example request with httpie
### Currently:
**Does nothing**
```bash
http PATCH https://gitea.your-server/api/v1/repos/myOrg/myRepo "enable_prune:=false" -A bearer -a $gitea_token
```
**Updates both properties**
```bash
http PATCH https://gitea.your-server/api/v1/repos/myOrg/myRepo "enable_prune:=false" "mirror_interval=10m" -A bearer -a $gitea_token
```
### With the patch
**Updates enable_prune only**
```bash
http PATCH https://gitea.your-server/api/v1/repos/myOrg/myRepo "enable_prune:=false" -A bearer -a $gitea_token
```
---
routers/api/v1/repo/repo.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index 9810e461de3cb..436b83adf2b35 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -637,7 +637,7 @@ func Edit(ctx *context.APIContext) {
}
}
- if opts.MirrorInterval != nil {
+ if opts.MirrorInterval != nil || opts.EnablePrune != nil {
if err := updateMirror(ctx, opts); err != nil {
return
}
From 76bbad4e746af977fea66c719d38048869de36c4 Mon Sep 17 00:00:00 2001
From: John Olheiser
Date: Thu, 25 Jan 2024 12:04:50 -0600
Subject: [PATCH 04/17] Check for sha256 support to use --object-format flag
(#28928)
This should fix https://github.com/go-gitea/gitea/issues/28927
Technically older versions of Git would support this flag as well, but
per https://github.com/go-gitea/gitea/pull/28466 that's the version
where using it (object-format=sha256) left "experimental" state.
`sha1` is (currently) the default, so older clients should be unaffected
in either case.
Signed-off-by: jolheiser
---
modules/git/repo.go | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/modules/git/repo.go b/modules/git/repo.go
index c3de2eb0adc32..db99d285a86a6 100644
--- a/modules/git/repo.go
+++ b/modules/git/repo.go
@@ -101,7 +101,9 @@ func InitRepository(ctx context.Context, repoPath string, bare bool, objectForma
if !IsValidObjectFormat(objectFormatName) {
return fmt.Errorf("invalid object format: %s", objectFormatName)
}
- cmd.AddOptionValues("--object-format", objectFormatName)
+ if SupportHashSha256 {
+ cmd.AddOptionValues("--object-format", objectFormatName)
+ }
if bare {
cmd.AddArguments("--bare")
From ba24e0ba61b1b66f58c8448f27272d1d6d14f60c Mon Sep 17 00:00:00 2001
From: KN4CK3R
Date: Thu, 25 Jan 2024 22:40:24 +0100
Subject: [PATCH 05/17] Use new RPM constants (#28931)
https://github.com/sassoftware/go-rpmutils/pull/24 got merged.
---
go.mod | 2 +-
go.sum | 4 ++--
modules/packages/rpm/metadata.go | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/go.mod b/go.mod
index 3268b81e66ead..7a752ec874cfc 100644
--- a/go.mod
+++ b/go.mod
@@ -92,7 +92,7 @@ require (
github.com/redis/go-redis/v9 v9.4.0
github.com/robfig/cron/v3 v3.0.1
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
- github.com/sassoftware/go-rpmutils v0.2.0
+ github.com/sassoftware/go-rpmutils v0.2.1-0.20240124161140-277b154961dd
github.com/sergi/go-diff v1.3.1
github.com/shurcooL/vfsgen v0.0.0-20230704071429-0000e147ea92
github.com/stretchr/testify v1.8.4
diff --git a/go.sum b/go.sum
index f13026c6bb841..b3b8ad8ce48f9 100644
--- a/go.sum
+++ b/go.sum
@@ -781,8 +781,8 @@ github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6g
github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
-github.com/sassoftware/go-rpmutils v0.2.0 h1:pKW0HDYMFWQ5b4JQPiI3WI12hGsVoW0V8+GMoZiI/JE=
-github.com/sassoftware/go-rpmutils v0.2.0/go.mod h1:TJJQYtLe/BeEmEjelI3b7xNZjzAukEkeWKmoakvaOoI=
+github.com/sassoftware/go-rpmutils v0.2.1-0.20240124161140-277b154961dd h1:KpbqRPDwcAQTyaP+L+YudTRb3CnJlQ64Hfn1SF/zHBA=
+github.com/sassoftware/go-rpmutils v0.2.1-0.20240124161140-277b154961dd/go.mod h1:TJJQYtLe/BeEmEjelI3b7xNZjzAukEkeWKmoakvaOoI=
github.com/segmentio/asm v1.2.0 h1:9BQrFxC+YOHJlTlHGkTrFWf59nbL3XnCoFLTwDCI7ys=
github.com/segmentio/asm v1.2.0/go.mod h1:BqMnlJP91P8d+4ibuonYZw9mfnzI9HfxselHZr5aAcs=
github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516/go.mod h1:Yow6lPLSAXx2ifx470yD/nUe22Dv5vBvxK/UK9UUTVs=
diff --git a/modules/packages/rpm/metadata.go b/modules/packages/rpm/metadata.go
index 7fc47a53e69a2..f4f78c2cab57c 100644
--- a/modules/packages/rpm/metadata.go
+++ b/modules/packages/rpm/metadata.go
@@ -140,7 +140,7 @@ func ParsePackage(r io.Reader) (*Package, error) {
Provides: getEntries(rpm.Header, rpmutils.PROVIDENAME, rpmutils.PROVIDEVERSION, rpmutils.PROVIDEFLAGS),
Requires: getEntries(rpm.Header, rpmutils.REQUIRENAME, rpmutils.REQUIREVERSION, rpmutils.REQUIREFLAGS),
- Conflicts: getEntries(rpm.Header, 1054 /*rpmutils.CONFLICTNAME*/, 1055 /*rpmutils.CONFLICTVERSION*/, 1053 /*rpmutils.CONFLICTFLAGS*/), // https://github.com/sassoftware/go-rpmutils/pull/24
+ Conflicts: getEntries(rpm.Header, rpmutils.CONFLICTNAME, rpmutils.CONFLICTVERSION, rpmutils.CONFLICTFLAGS),
Obsoletes: getEntries(rpm.Header, rpmutils.OBSOLETENAME, rpmutils.OBSOLETEVERSION, rpmutils.OBSOLETEFLAGS),
Files: getFiles(rpm.Header),
Changelogs: getChangelogs(rpm.Header),
From 534917d57670d82703567131e2b33fd945e6f8cb Mon Sep 17 00:00:00 2001
From: Lunny Xiao
Date: Fri, 26 Jan 2024 14:18:19 +0800
Subject: [PATCH 06/17] Don't remove all mirror repository's releases when
mirroring (#28817)
Fix #22066
# Purpose
This PR fix the releases will be deleted when mirror repository sync the
tags.
# The problem
In the previous implementation of #19125. All releases record in
databases of one mirror repository will be deleted before sync.
Ref:
https://github.com/go-gitea/gitea/pull/19125/files#diff-2aa04998a791c30e5a02b49a97c07fcd93d50e8b31640ce2ddb1afeebf605d02R481
# The Pros
This PR introduced a new method which will load all releases from
databases and all tags on git data into memory. And detect which tags
needs to be inserted, which tags need to be updated or deleted. Only
tags releases(IsTag=true) which are not included in git data will be
deleted, only tags which sha1 changed will be updated. So it will not
delete any real releases include drafts.
# The Cons
The drawback is the memory usage will be higher than before if there are
many tags on this repository. This PR defined a special release struct
to reduce columns loaded from database to memory.
---
modules/repository/repo.go | 76 ++++++++++++++++++++++++++++++---
modules/repository/repo_test.go | 76 +++++++++++++++++++++++++++++++++
2 files changed, 146 insertions(+), 6 deletions(-)
create mode 100644 modules/repository/repo_test.go
diff --git a/modules/repository/repo.go b/modules/repository/repo.go
index 5af69763d152e..5352da0378d9a 100644
--- a/modules/repository/repo.go
+++ b/modules/repository/repo.go
@@ -508,6 +508,18 @@ func StoreMissingLfsObjectsInRepository(ctx context.Context, repo *repo_model.Re
return nil
}
+// shortRelease to reduce load memory, this struct can replace repo_model.Release
+type shortRelease struct {
+ ID int64
+ TagName string
+ Sha1 string
+ IsTag bool
+}
+
+func (shortRelease) TableName() string {
+ return "release"
+}
+
// pullMirrorReleaseSync is a pull-mirror specific tag<->release table
// synchronization which overwrites all Releases from the repository tags. This
// can be relied on since a pull-mirror is always identical to its
@@ -521,16 +533,20 @@ func pullMirrorReleaseSync(ctx context.Context, repo *repo_model.Repository, git
return fmt.Errorf("unable to GetTagInfos in pull-mirror Repo[%d:%s/%s]: %w", repo.ID, repo.OwnerName, repo.Name, err)
}
err = db.WithTx(ctx, func(ctx context.Context) error {
- //
- // clear out existing releases
- //
- if _, err := db.DeleteByBean(ctx, &repo_model.Release{RepoID: repo.ID}); err != nil {
- return fmt.Errorf("unable to clear releases for pull-mirror Repo[%d:%s/%s]: %w", repo.ID, repo.OwnerName, repo.Name, err)
+ dbReleases, err := db.Find[shortRelease](ctx, repo_model.FindReleasesOptions{
+ RepoID: repo.ID,
+ IncludeDrafts: true,
+ IncludeTags: true,
+ })
+ if err != nil {
+ return fmt.Errorf("unable to FindReleases in pull-mirror Repo[%d:%s/%s]: %w", repo.ID, repo.OwnerName, repo.Name, err)
}
+
+ inserts, deletes, updates := calcSync(tags, dbReleases)
//
// make release set identical to upstream tags
//
- for _, tag := range tags {
+ for _, tag := range inserts {
release := repo_model.Release{
RepoID: repo.ID,
TagName: tag.Name,
@@ -547,6 +563,25 @@ func pullMirrorReleaseSync(ctx context.Context, repo *repo_model.Repository, git
return fmt.Errorf("unable insert tag %s for pull-mirror Repo[%d:%s/%s]: %w", tag.Name, repo.ID, repo.OwnerName, repo.Name, err)
}
}
+
+ // only delete tags releases
+ if len(deletes) > 0 {
+ if _, err := db.GetEngine(ctx).Where("repo_id=?", repo.ID).
+ In("id", deletes).
+ Delete(&repo_model.Release{}); err != nil {
+ return fmt.Errorf("unable to delete tags for pull-mirror Repo[%d:%s/%s]: %w", repo.ID, repo.OwnerName, repo.Name, err)
+ }
+ }
+
+ for _, tag := range updates {
+ if _, err := db.GetEngine(ctx).Where("repo_id = ? AND lower_tag_name = ?", repo.ID, strings.ToLower(tag.Name)).
+ Cols("sha1").
+ Update(&repo_model.Release{
+ Sha1: tag.Object.String(),
+ }); err != nil {
+ return fmt.Errorf("unable to update tag %s for pull-mirror Repo[%d:%s/%s]: %w", tag.Name, repo.ID, repo.OwnerName, repo.Name, err)
+ }
+ }
return nil
})
if err != nil {
@@ -556,3 +591,32 @@ func pullMirrorReleaseSync(ctx context.Context, repo *repo_model.Repository, git
log.Trace("pullMirrorReleaseSync: done rebuilding %d releases", numTags)
return nil
}
+
+func calcSync(destTags []*git.Tag, dbTags []*shortRelease) ([]*git.Tag, []int64, []*git.Tag) {
+ destTagMap := make(map[string]*git.Tag)
+ for _, tag := range destTags {
+ destTagMap[tag.Name] = tag
+ }
+ dbTagMap := make(map[string]*shortRelease)
+ for _, rel := range dbTags {
+ dbTagMap[rel.TagName] = rel
+ }
+
+ inserted := make([]*git.Tag, 0, 10)
+ updated := make([]*git.Tag, 0, 10)
+ for _, tag := range destTags {
+ rel := dbTagMap[tag.Name]
+ if rel == nil {
+ inserted = append(inserted, tag)
+ } else if rel.Sha1 != tag.Object.String() {
+ updated = append(updated, tag)
+ }
+ }
+ deleted := make([]int64, 0, 10)
+ for _, tag := range dbTags {
+ if destTagMap[tag.TagName] == nil && tag.IsTag {
+ deleted = append(deleted, tag.ID)
+ }
+ }
+ return inserted, deleted, updated
+}
diff --git a/modules/repository/repo_test.go b/modules/repository/repo_test.go
new file mode 100644
index 0000000000000..68980f92f9450
--- /dev/null
+++ b/modules/repository/repo_test.go
@@ -0,0 +1,76 @@
+// Copyright 2024 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package repository
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/modules/git"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func Test_calcSync(t *testing.T) {
+ gitTags := []*git.Tag{
+ /*{
+ Name: "v0.1.0-beta", //deleted tag
+ Object: git.MustIDFromString(""),
+ },
+ {
+ Name: "v0.1.1-beta", //deleted tag but release should not be deleted because it's a release
+ Object: git.MustIDFromString(""),
+ },
+ */
+ {
+ Name: "v1.0.0", // keep as before
+ Object: git.MustIDFromString("1006e6e13c73ad3d9e2d5682ad266b5016523485"),
+ },
+ {
+ Name: "v1.1.0", // retagged with new commit id
+ Object: git.MustIDFromString("bbdb7df30248e7d4a26a909c8d2598a152e13868"),
+ },
+ {
+ Name: "v1.2.0", // new tag
+ Object: git.MustIDFromString("a5147145e2f24d89fd6d2a87826384cc1d253267"),
+ },
+ }
+
+ dbReleases := []*shortRelease{
+ {
+ ID: 1,
+ TagName: "v0.1.0-beta",
+ Sha1: "244758d7da8dd1d9e0727e8cb7704ed4ba9a17c3",
+ IsTag: true,
+ },
+ {
+ ID: 2,
+ TagName: "v0.1.1-beta",
+ Sha1: "244758d7da8dd1d9e0727e8cb7704ed4ba9a17c3",
+ IsTag: false,
+ },
+ {
+ ID: 3,
+ TagName: "v1.0.0",
+ Sha1: "1006e6e13c73ad3d9e2d5682ad266b5016523485",
+ },
+ {
+ ID: 4,
+ TagName: "v1.1.0",
+ Sha1: "53ab18dcecf4152b58328d1f47429510eb414d50",
+ },
+ }
+
+ inserts, deletes, updates := calcSync(gitTags, dbReleases)
+ if assert.EqualValues(t, 1, len(inserts), "inserts") {
+ assert.EqualValues(t, *gitTags[2], *inserts[0], "inserts equal")
+ }
+
+ if assert.EqualValues(t, 1, len(deletes), "deletes") {
+ assert.EqualValues(t, 1, deletes[0], "deletes equal")
+ }
+
+ if assert.EqualValues(t, 1, len(updates), "updates") {
+ assert.EqualValues(t, *gitTags[1], *updates[0], "updates equal")
+ }
+}
From a240d5dfa7e261f2fb703cf24b1ba4dc6aa47bfd Mon Sep 17 00:00:00 2001
From: wackbyte
Date: Fri, 26 Jan 2024 09:15:57 -0500
Subject: [PATCH 07/17] Fix non-alphabetic sorting of repo topics (#28938)
---
models/repo/topic.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/models/repo/topic.go b/models/repo/topic.go
index b71f43bc88046..79b13e320da1d 100644
--- a/models/repo/topic.go
+++ b/models/repo/topic.go
@@ -366,7 +366,7 @@ func syncTopicsInRepository(sess db.Engine, repoID int64) error {
topicNames := make([]string, 0, 25)
if err := sess.Table("topic").Cols("name").
Join("INNER", "repo_topic", "repo_topic.topic_id = topic.id").
- Where("repo_topic.repo_id = ?", repoID).Desc("topic.repo_count").Find(&topicNames); err != nil {
+ Where("repo_topic.repo_id = ?", repoID).Asc("topic.name").Find(&topicNames); err != nil {
return err
}
From 01acd1eea38f25d2b21f56ec15dd162ca6005fbf Mon Sep 17 00:00:00 2001
From: KN4CK3R
Date: Sat, 27 Jan 2024 04:36:01 +0100
Subject: [PATCH 08/17] Strip `/` from relative links (#28932)
Fixes #28915
Restores the old behaviour:
https://github.com/go-gitea/gitea/pull/26745/files#diff-d78a9d361b1fddc12218e4dd42f42d39d6be1fda184041e06bb6fb30f0d94c59L96
---
modules/markup/markdown/goldmark.go | 10 +++++----
modules/markup/markdown/markdown_test.go | 26 ++++++++++++++++++++++++
2 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/modules/markup/markdown/goldmark.go b/modules/markup/markdown/goldmark.go
index 1db3cbad7e1b0..3dc5530e008c8 100644
--- a/modules/markup/markdown/goldmark.go
+++ b/modules/markup/markdown/goldmark.go
@@ -85,9 +85,11 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
// 2. If they're not wrapped with a link they need a link wrapper
// Check if the destination is a real link
- link := v.Destination
- if len(link) > 0 && !markup.IsLink(link) {
- v.Destination = []byte(giteautil.URLJoin(ctx.Links.ResolveMediaLink(ctx.IsWiki), string(link)))
+ if len(v.Destination) > 0 && !markup.IsLink(v.Destination) {
+ v.Destination = []byte(giteautil.URLJoin(
+ ctx.Links.ResolveMediaLink(ctx.IsWiki),
+ strings.TrimLeft(string(v.Destination), "/"),
+ ))
}
parent := n.Parent()
@@ -103,7 +105,7 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
// Duplicate the current image node
image := ast.NewImage(ast.NewLink())
- image.Destination = link
+ image.Destination = v.Destination
image.Title = v.Title
for _, attr := range v.Attributes() {
image.SetAttribute(attr.Name, attr.Value)
diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go
index 1edfb3e664463..bdf4011fa2486 100644
--- a/modules/markup/markdown/markdown_test.go
+++ b/modules/markup/markdown/markdown_test.go
@@ -580,6 +580,8 @@ https://example.com/file.bin
[[local link|file.bin]]
[[remote link|https://example.com]]
![local image](image.jpg)
+![local image](path/file)
+![local image](/path/file)
![remote image](https://example.com/image.jpg)
[[local image|image.jpg]]
[[remote link|https://example.com/image.jpg]]
@@ -609,6 +611,8 @@ mail@domain.com
local link
remote link
+
+
@@ -634,6 +638,8 @@ space
local link
remote link
+
+
@@ -661,6 +667,8 @@ space
local link
remote link
+
+
@@ -688,6 +696,8 @@ space
local link
remote link
+
+
@@ -715,6 +725,8 @@ space
local link
remote link
+
+
@@ -742,6 +754,8 @@ space
local link
remote link
+
+
@@ -770,6 +784,8 @@ space
local link
remote link
+
+
@@ -798,6 +814,8 @@ space
local link
remote link
+
+
@@ -826,6 +844,8 @@ space
local link
remote link
+
+
@@ -854,6 +874,8 @@ space
local link
remote link
+
+
@@ -883,6 +905,8 @@ space
local link
remote link
+
+
@@ -912,6 +936,8 @@ space
local link
remote link
+
+
From fc1bae00a4cc07d832eb9405ec8fd8f4e52c0197 Mon Sep 17 00:00:00 2001
From: KN4CK3R
Date: Sat, 27 Jan 2024 10:27:34 +0100
Subject: [PATCH 09/17] Fix SSPI user creation (#28948)
Fixes #28945
Setting the avatar is wrong and creating a random password is equal to
leave it empty.
---
services/auth/sspi.go | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/services/auth/sspi.go b/services/auth/sspi.go
index 57ba0462c573b..0e974fde8f358 100644
--- a/services/auth/sspi.go
+++ b/services/auth/sspi.go
@@ -11,7 +11,6 @@ import (
"sync"
"code.gitea.io/gitea/models/auth"
- "code.gitea.io/gitea/models/avatars"
"code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
@@ -167,12 +166,9 @@ func (s *SSPI) shouldAuthenticate(req *http.Request) (shouldAuth bool) {
func (s *SSPI) newUser(ctx context.Context, username string, cfg *sspi.Source) (*user_model.User, error) {
email := gouuid.New().String() + "@localhost.localdomain"
user := &user_model.User{
- Name: username,
- Email: email,
- Passwd: gouuid.New().String(),
- Language: cfg.DefaultLanguage,
- UseCustomAvatar: true,
- Avatar: avatars.DefaultAvatarLink(),
+ Name: username,
+ Email: email,
+ Language: cfg.DefaultLanguage,
}
emailNotificationPreference := user_model.EmailNotificationsDisabled
overwriteDefault := &user_model.CreateUserOverwriteOptions{
From 0e650dca3076bbf8e1a4d1a80cef3275a51af658 Mon Sep 17 00:00:00 2001
From: Yarden Shoham
Date: Sat, 27 Jan 2024 14:27:37 +0200
Subject: [PATCH 10/17] Make loading animation less aggressive (#28955)
The current animation loops in a very fast manner, causing a slight
feeling of uncomfortableness. This change slows it a bit for a smoother
experience.
# Before
![before](https://github.com/go-gitea/gitea/assets/20454870/215a722d-feb4-4643-819d-c37a620c5e48)
# After
![after](https://github.com/go-gitea/gitea/assets/20454870/7acb1fab-9157-4f4d-8cc7-45fea0234b47)
Signed-off-by: Yarden Shoham
---
web_src/css/modules/animations.css | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/web_src/css/modules/animations.css b/web_src/css/modules/animations.css
index cac824d87d66d..87eb6a75cf071 100644
--- a/web_src/css/modules/animations.css
+++ b/web_src/css/modules/animations.css
@@ -22,7 +22,7 @@
height: min(4em, 66.6%);
aspect-ratio: 1;
transform: translate(-50%, -50%);
- animation: isloadingspin 500ms infinite linear;
+ animation: isloadingspin 1000ms infinite linear;
border-width: 4px;
border-style: solid;
border-color: var(--color-secondary) var(--color-secondary) var(--color-secondary-dark-8) var(--color-secondary-dark-8);
From 60e4a98ab07dcf3bd86cf630c79e6433c3ef3e84 Mon Sep 17 00:00:00 2001
From: silverwind
Date: Sat, 27 Jan 2024 19:02:51 +0100
Subject: [PATCH 11/17] Preserve BOM in web editor (#28935)
The `ToUTF8*` functions were stripping BOM, while BOM is actually valid
in UTF8, so the stripping must be optional depending on use case. This
does:
- Add a options struct to all `ToUTF8*` functions, that by default will
strip BOM to preserve existing behaviour
- Remove `ToUTF8` function, it was dead code
- Rename `ToUTF8WithErr` to `ToUTF8`
- Preserve BOM in Monaco Editor
- Remove a unnecessary newline in the textarea value. Browsers did
ignore it, it seems but it's better not to rely on this behaviour.
Fixes: https://github.com/go-gitea/gitea/issues/28743
Related: https://github.com/go-gitea/gitea/issues/6716 which seems to
have once introduced a mechanism that strips and re-adds the BOM, but
from what I can tell, this mechanism was removed at some point after
that PR.
---
modules/charset/charset.go | 43 +++---
modules/charset/charset_test.go | 133 +++++-------------
modules/indexer/code/bleve/bleve.go | 2 +-
.../code/elasticsearch/elasticsearch.go | 2 +-
routers/web/repo/commit.go | 2 +-
routers/web/repo/compare.go | 2 +-
routers/web/repo/editor.go | 4 +-
routers/web/repo/render.go | 2 +-
routers/web/repo/setting/lfs.go | 2 +-
routers/web/repo/view.go | 4 +-
templates/repo/editor/edit.tmpl | 3 +-
.../migration-test/migration_test.go | 2 +-
web_src/js/features/codeeditor.js | 2 +-
13 files changed, 69 insertions(+), 134 deletions(-)
diff --git a/modules/charset/charset.go b/modules/charset/charset.go
index 51152142a581f..1855446a98480 100644
--- a/modules/charset/charset.go
+++ b/modules/charset/charset.go
@@ -22,17 +22,21 @@ import (
// UTF8BOM is the utf-8 byte-order marker
var UTF8BOM = []byte{'\xef', '\xbb', '\xbf'}
+type ConvertOpts struct {
+ KeepBOM bool
+}
+
// ToUTF8WithFallbackReader detects the encoding of content and converts to UTF-8 reader if possible
-func ToUTF8WithFallbackReader(rd io.Reader) io.Reader {
+func ToUTF8WithFallbackReader(rd io.Reader, opts ConvertOpts) io.Reader {
buf := make([]byte, 2048)
n, err := util.ReadAtMost(rd, buf)
if err != nil {
- return io.MultiReader(bytes.NewReader(RemoveBOMIfPresent(buf[:n])), rd)
+ return io.MultiReader(bytes.NewReader(MaybeRemoveBOM(buf[:n], opts)), rd)
}
charsetLabel, err := DetectEncoding(buf[:n])
if err != nil || charsetLabel == "UTF-8" {
- return io.MultiReader(bytes.NewReader(RemoveBOMIfPresent(buf[:n])), rd)
+ return io.MultiReader(bytes.NewReader(MaybeRemoveBOM(buf[:n], opts)), rd)
}
encoding, _ := charset.Lookup(charsetLabel)
@@ -42,20 +46,20 @@ func ToUTF8WithFallbackReader(rd io.Reader) io.Reader {
return transform.NewReader(
io.MultiReader(
- bytes.NewReader(RemoveBOMIfPresent(buf[:n])),
+ bytes.NewReader(MaybeRemoveBOM(buf[:n], opts)),
rd,
),
encoding.NewDecoder(),
)
}
-// ToUTF8WithErr converts content to UTF8 encoding
-func ToUTF8WithErr(content []byte) (string, error) {
+// ToUTF8 converts content to UTF8 encoding
+func ToUTF8(content []byte, opts ConvertOpts) (string, error) {
charsetLabel, err := DetectEncoding(content)
if err != nil {
return "", err
} else if charsetLabel == "UTF-8" {
- return string(RemoveBOMIfPresent(content)), nil
+ return string(MaybeRemoveBOM(content, opts)), nil
}
encoding, _ := charset.Lookup(charsetLabel)
@@ -70,28 +74,22 @@ func ToUTF8WithErr(content []byte) (string, error) {
result = append(result, content[n:]...)
}
- result = RemoveBOMIfPresent(result)
+ result = MaybeRemoveBOM(result, opts)
return string(result), err
}
// ToUTF8WithFallback detects the encoding of content and converts to UTF-8 if possible
-func ToUTF8WithFallback(content []byte) []byte {
- bs, _ := io.ReadAll(ToUTF8WithFallbackReader(bytes.NewReader(content)))
+func ToUTF8WithFallback(content []byte, opts ConvertOpts) []byte {
+ bs, _ := io.ReadAll(ToUTF8WithFallbackReader(bytes.NewReader(content), opts))
return bs
}
-// ToUTF8 converts content to UTF8 encoding and ignore error
-func ToUTF8(content string) string {
- res, _ := ToUTF8WithErr([]byte(content))
- return res
-}
-
// ToUTF8DropErrors makes sure the return string is valid utf-8; attempts conversion if possible
-func ToUTF8DropErrors(content []byte) []byte {
+func ToUTF8DropErrors(content []byte, opts ConvertOpts) []byte {
charsetLabel, err := DetectEncoding(content)
if err != nil || charsetLabel == "UTF-8" {
- return RemoveBOMIfPresent(content)
+ return MaybeRemoveBOM(content, opts)
}
encoding, _ := charset.Lookup(charsetLabel)
@@ -117,11 +115,14 @@ func ToUTF8DropErrors(content []byte) []byte {
}
}
- return RemoveBOMIfPresent(decoded)
+ return MaybeRemoveBOM(decoded, opts)
}
-// RemoveBOMIfPresent removes a UTF-8 BOM from a []byte
-func RemoveBOMIfPresent(content []byte) []byte {
+// MaybeRemoveBOM removes a UTF-8 BOM from a []byte when opts.KeepBOM is false
+func MaybeRemoveBOM(content []byte, opts ConvertOpts) []byte {
+ if opts.KeepBOM {
+ return content
+ }
if len(content) > 2 && bytes.Equal(content[0:3], UTF8BOM) {
return content[3:]
}
diff --git a/modules/charset/charset_test.go b/modules/charset/charset_test.go
index fc56799b47360..829844a9766cd 100644
--- a/modules/charset/charset_test.go
+++ b/modules/charset/charset_test.go
@@ -30,15 +30,15 @@ func resetDefaultCharsetsOrder() {
}
}
-func TestRemoveBOMIfPresent(t *testing.T) {
- res := RemoveBOMIfPresent([]byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba})
+func TestMaybeRemoveBOM(t *testing.T) {
+ res := MaybeRemoveBOM([]byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, ConvertOpts{})
assert.Equal(t, []byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, res)
- res = RemoveBOMIfPresent([]byte{0xef, 0xbb, 0xbf, 0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba})
+ res = MaybeRemoveBOM([]byte{0xef, 0xbb, 0xbf, 0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, ConvertOpts{})
assert.Equal(t, []byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, res)
}
-func TestToUTF8WithErr(t *testing.T) {
+func TestToUTF8(t *testing.T) {
resetDefaultCharsetsOrder()
var res string
var err error
@@ -47,53 +47,53 @@ func TestToUTF8WithErr(t *testing.T) {
// locale, so some conversions might behave differently. For that reason, we don't
// depend on particular conversions but in expected behaviors.
- res, err = ToUTF8WithErr([]byte{0x41, 0x42, 0x43})
+ res, err = ToUTF8([]byte{0x41, 0x42, 0x43}, ConvertOpts{})
assert.NoError(t, err)
assert.Equal(t, "ABC", res)
// "áéíóú"
- res, err = ToUTF8WithErr([]byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba})
+ res, err = ToUTF8([]byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, ConvertOpts{})
assert.NoError(t, err)
assert.Equal(t, []byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, []byte(res))
// "áéíóú"
- res, err = ToUTF8WithErr([]byte{
+ res, err = ToUTF8([]byte{
0xef, 0xbb, 0xbf, 0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3,
0xc3, 0xba,
- })
+ }, ConvertOpts{})
assert.NoError(t, err)
assert.Equal(t, []byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, []byte(res))
- res, err = ToUTF8WithErr([]byte{
+ res, err = ToUTF8([]byte{
0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
0xF3, 0x6D, 0x6F, 0x20, 0xF1, 0x6F, 0x73, 0x41, 0x41, 0x41, 0x2e,
- })
+ }, ConvertOpts{})
assert.NoError(t, err)
stringMustStartWith(t, "Hola,", res)
stringMustEndWith(t, "AAA.", res)
- res, err = ToUTF8WithErr([]byte{
+ res, err = ToUTF8([]byte{
0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
0xF3, 0x6D, 0x6F, 0x20, 0x07, 0xA4, 0x6F, 0x73, 0x41, 0x41, 0x41, 0x2e,
- })
+ }, ConvertOpts{})
assert.NoError(t, err)
stringMustStartWith(t, "Hola,", res)
stringMustEndWith(t, "AAA.", res)
- res, err = ToUTF8WithErr([]byte{
+ res, err = ToUTF8([]byte{
0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
0xF3, 0x6D, 0x6F, 0x20, 0x81, 0xA4, 0x6F, 0x73, 0x41, 0x41, 0x41, 0x2e,
- })
+ }, ConvertOpts{})
assert.NoError(t, err)
stringMustStartWith(t, "Hola,", res)
stringMustEndWith(t, "AAA.", res)
// Japanese (Shift-JIS)
// 日属秘ぞしちゅ。
- res, err = ToUTF8WithErr([]byte{
+ res, err = ToUTF8([]byte{
0x93, 0xFA, 0x91, 0xAE, 0x94, 0xE9, 0x82, 0xBC, 0x82, 0xB5, 0x82,
0xBF, 0x82, 0xE3, 0x81, 0x42,
- })
+ }, ConvertOpts{})
assert.NoError(t, err)
assert.Equal(t, []byte{
0xE6, 0x97, 0xA5, 0xE5, 0xB1, 0x9E, 0xE7, 0xA7, 0x98, 0xE3,
@@ -101,7 +101,7 @@ func TestToUTF8WithErr(t *testing.T) {
},
[]byte(res))
- res, err = ToUTF8WithErr([]byte{0x00, 0x00, 0x00, 0x00})
+ res, err = ToUTF8([]byte{0x00, 0x00, 0x00, 0x00}, ConvertOpts{})
assert.NoError(t, err)
assert.Equal(t, []byte{0x00, 0x00, 0x00, 0x00}, []byte(res))
}
@@ -109,22 +109,22 @@ func TestToUTF8WithErr(t *testing.T) {
func TestToUTF8WithFallback(t *testing.T) {
resetDefaultCharsetsOrder()
// "ABC"
- res := ToUTF8WithFallback([]byte{0x41, 0x42, 0x43})
+ res := ToUTF8WithFallback([]byte{0x41, 0x42, 0x43}, ConvertOpts{})
assert.Equal(t, []byte{0x41, 0x42, 0x43}, res)
// "áéíóú"
- res = ToUTF8WithFallback([]byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba})
+ res = ToUTF8WithFallback([]byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, ConvertOpts{})
assert.Equal(t, []byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, res)
// UTF8 BOM + "áéíóú"
- res = ToUTF8WithFallback([]byte{0xef, 0xbb, 0xbf, 0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba})
+ res = ToUTF8WithFallback([]byte{0xef, 0xbb, 0xbf, 0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, ConvertOpts{})
assert.Equal(t, []byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, res)
// "Hola, así cómo ños"
res = ToUTF8WithFallback([]byte{
0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
0xF3, 0x6D, 0x6F, 0x20, 0xF1, 0x6F, 0x73,
- })
+ }, ConvertOpts{})
assert.Equal(t, []byte{
0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xC3, 0xAD, 0x20, 0x63,
0xC3, 0xB3, 0x6D, 0x6F, 0x20, 0xC3, 0xB1, 0x6F, 0x73,
@@ -133,126 +133,65 @@ func TestToUTF8WithFallback(t *testing.T) {
// "Hola, así cómo "
minmatch := []byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xC3, 0xAD, 0x20, 0x63, 0xC3, 0xB3, 0x6D, 0x6F, 0x20}
- res = ToUTF8WithFallback([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63, 0xF3, 0x6D, 0x6F, 0x20, 0x07, 0xA4, 0x6F, 0x73})
+ res = ToUTF8WithFallback([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63, 0xF3, 0x6D, 0x6F, 0x20, 0x07, 0xA4, 0x6F, 0x73}, ConvertOpts{})
// Do not fail for differences in invalid cases, as the library might change the conversion criteria for those
assert.Equal(t, minmatch, res[0:len(minmatch)])
- res = ToUTF8WithFallback([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63, 0xF3, 0x6D, 0x6F, 0x20, 0x81, 0xA4, 0x6F, 0x73})
+ res = ToUTF8WithFallback([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63, 0xF3, 0x6D, 0x6F, 0x20, 0x81, 0xA4, 0x6F, 0x73}, ConvertOpts{})
// Do not fail for differences in invalid cases, as the library might change the conversion criteria for those
assert.Equal(t, minmatch, res[0:len(minmatch)])
// Japanese (Shift-JIS)
// "日属秘ぞしちゅ。"
- res = ToUTF8WithFallback([]byte{0x93, 0xFA, 0x91, 0xAE, 0x94, 0xE9, 0x82, 0xBC, 0x82, 0xB5, 0x82, 0xBF, 0x82, 0xE3, 0x81, 0x42})
+ res = ToUTF8WithFallback([]byte{0x93, 0xFA, 0x91, 0xAE, 0x94, 0xE9, 0x82, 0xBC, 0x82, 0xB5, 0x82, 0xBF, 0x82, 0xE3, 0x81, 0x42}, ConvertOpts{})
assert.Equal(t, []byte{
0xE6, 0x97, 0xA5, 0xE5, 0xB1, 0x9E, 0xE7, 0xA7, 0x98, 0xE3,
0x81, 0x9E, 0xE3, 0x81, 0x97, 0xE3, 0x81, 0xA1, 0xE3, 0x82, 0x85, 0xE3, 0x80, 0x82,
}, res)
- res = ToUTF8WithFallback([]byte{0x00, 0x00, 0x00, 0x00})
+ res = ToUTF8WithFallback([]byte{0x00, 0x00, 0x00, 0x00}, ConvertOpts{})
assert.Equal(t, []byte{0x00, 0x00, 0x00, 0x00}, res)
}
-func TestToUTF8(t *testing.T) {
- resetDefaultCharsetsOrder()
- // Note: golang compiler seems so behave differently depending on the current
- // locale, so some conversions might behave differently. For that reason, we don't
- // depend on particular conversions but in expected behaviors.
-
- res := ToUTF8(string([]byte{0x41, 0x42, 0x43}))
- assert.Equal(t, "ABC", res)
-
- // "áéíóú"
- res = ToUTF8(string([]byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}))
- assert.Equal(t, []byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, []byte(res))
-
- // BOM + "áéíóú"
- res = ToUTF8(string([]byte{
- 0xef, 0xbb, 0xbf, 0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3,
- 0xc3, 0xba,
- }))
- assert.Equal(t, []byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, []byte(res))
-
- // Latin1
- // Hola, así cómo ños
- res = ToUTF8(string([]byte{
- 0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
- 0xF3, 0x6D, 0x6F, 0x20, 0xF1, 0x6F, 0x73,
- }))
- assert.Equal(t, []byte{
- 0x48, 0x6f, 0x6c, 0x61, 0x2c, 0x20, 0x61, 0x73, 0xc3, 0xad, 0x20, 0x63,
- 0xc3, 0xb3, 0x6d, 0x6f, 0x20, 0xc3, 0xb1, 0x6f, 0x73,
- }, []byte(res))
-
- // Latin1
- // Hola, así cómo \x07ños
- res = ToUTF8(string([]byte{
- 0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63,
- 0xF3, 0x6D, 0x6F, 0x20, 0x07, 0xA4, 0x6F, 0x73,
- }))
- // Hola,
- bytesMustStartWith(t, []byte{0x48, 0x6F, 0x6C, 0x61, 0x2C}, []byte(res))
-
- // This test FAILS
- // res = ToUTF8("Hola, así cómo \x81ños")
- // Do not fail for differences in invalid cases, as the library might change the conversion criteria for those
- // assert.Regexp(t, "^Hola, así cómo", res)
-
- // Japanese (Shift-JIS)
- // 日属秘ぞしちゅ。
- res = ToUTF8(string([]byte{
- 0x93, 0xFA, 0x91, 0xAE, 0x94, 0xE9, 0x82, 0xBC, 0x82, 0xB5, 0x82,
- 0xBF, 0x82, 0xE3, 0x81, 0x42,
- }))
- assert.Equal(t, []byte{
- 0xE6, 0x97, 0xA5, 0xE5, 0xB1, 0x9E, 0xE7, 0xA7, 0x98, 0xE3,
- 0x81, 0x9E, 0xE3, 0x81, 0x97, 0xE3, 0x81, 0xA1, 0xE3, 0x82, 0x85, 0xE3, 0x80, 0x82,
- },
- []byte(res))
-
- res = ToUTF8("\x00\x00\x00\x00")
- assert.Equal(t, []byte{0x00, 0x00, 0x00, 0x00}, []byte(res))
-}
-
func TestToUTF8DropErrors(t *testing.T) {
resetDefaultCharsetsOrder()
// "ABC"
- res := ToUTF8DropErrors([]byte{0x41, 0x42, 0x43})
+ res := ToUTF8DropErrors([]byte{0x41, 0x42, 0x43}, ConvertOpts{})
assert.Equal(t, []byte{0x41, 0x42, 0x43}, res)
// "áéíóú"
- res = ToUTF8DropErrors([]byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba})
+ res = ToUTF8DropErrors([]byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, ConvertOpts{})
assert.Equal(t, []byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, res)
// UTF8 BOM + "áéíóú"
- res = ToUTF8DropErrors([]byte{0xef, 0xbb, 0xbf, 0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba})
+ res = ToUTF8DropErrors([]byte{0xef, 0xbb, 0xbf, 0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, ConvertOpts{})
assert.Equal(t, []byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}, res)
// "Hola, así cómo ños"
- res = ToUTF8DropErrors([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63, 0xF3, 0x6D, 0x6F, 0x20, 0xF1, 0x6F, 0x73})
+ res = ToUTF8DropErrors([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63, 0xF3, 0x6D, 0x6F, 0x20, 0xF1, 0x6F, 0x73}, ConvertOpts{})
assert.Equal(t, []byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73}, res[:8])
assert.Equal(t, []byte{0x73}, res[len(res)-1:])
// "Hola, así cómo "
minmatch := []byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xC3, 0xAD, 0x20, 0x63, 0xC3, 0xB3, 0x6D, 0x6F, 0x20}
- res = ToUTF8DropErrors([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63, 0xF3, 0x6D, 0x6F, 0x20, 0x07, 0xA4, 0x6F, 0x73})
+ res = ToUTF8DropErrors([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63, 0xF3, 0x6D, 0x6F, 0x20, 0x07, 0xA4, 0x6F, 0x73}, ConvertOpts{})
// Do not fail for differences in invalid cases, as the library might change the conversion criteria for those
assert.Equal(t, minmatch, res[0:len(minmatch)])
- res = ToUTF8DropErrors([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63, 0xF3, 0x6D, 0x6F, 0x20, 0x81, 0xA4, 0x6F, 0x73})
+ res = ToUTF8DropErrors([]byte{0x48, 0x6F, 0x6C, 0x61, 0x2C, 0x20, 0x61, 0x73, 0xED, 0x20, 0x63, 0xF3, 0x6D, 0x6F, 0x20, 0x81, 0xA4, 0x6F, 0x73}, ConvertOpts{})
// Do not fail for differences in invalid cases, as the library might change the conversion criteria for those
assert.Equal(t, minmatch, res[0:len(minmatch)])
// Japanese (Shift-JIS)
// "日属秘ぞしちゅ。"
- res = ToUTF8DropErrors([]byte{0x93, 0xFA, 0x91, 0xAE, 0x94, 0xE9, 0x82, 0xBC, 0x82, 0xB5, 0x82, 0xBF, 0x82, 0xE3, 0x81, 0x42})
+ res = ToUTF8DropErrors([]byte{0x93, 0xFA, 0x91, 0xAE, 0x94, 0xE9, 0x82, 0xBC, 0x82, 0xB5, 0x82, 0xBF, 0x82, 0xE3, 0x81, 0x42}, ConvertOpts{})
assert.Equal(t, []byte{
0xE6, 0x97, 0xA5, 0xE5, 0xB1, 0x9E, 0xE7, 0xA7, 0x98, 0xE3,
0x81, 0x9E, 0xE3, 0x81, 0x97, 0xE3, 0x81, 0xA1, 0xE3, 0x82, 0x85, 0xE3, 0x80, 0x82,
}, res)
- res = ToUTF8DropErrors([]byte{0x00, 0x00, 0x00, 0x00})
+ res = ToUTF8DropErrors([]byte{0x00, 0x00, 0x00, 0x00}, ConvertOpts{})
assert.Equal(t, []byte{0x00, 0x00, 0x00, 0x00}, res)
}
@@ -302,10 +241,6 @@ func stringMustEndWith(t *testing.T, expected, value string) {
assert.Equal(t, expected, value[len(value)-len(expected):])
}
-func bytesMustStartWith(t *testing.T, expected, value []byte) {
- assert.Equal(t, expected, value[:len(expected)])
-}
-
func TestToUTF8WithFallbackReader(t *testing.T) {
resetDefaultCharsetsOrder()
@@ -317,7 +252,7 @@ func TestToUTF8WithFallbackReader(t *testing.T) {
}
input = input[:testLen]
input += "// Выключаем"
- rd := ToUTF8WithFallbackReader(bytes.NewReader([]byte(input)))
+ rd := ToUTF8WithFallbackReader(bytes.NewReader([]byte(input)), ConvertOpts{})
r, _ := io.ReadAll(rd)
assert.EqualValuesf(t, input, string(r), "testing string len=%d", testLen)
}
diff --git a/modules/indexer/code/bleve/bleve.go b/modules/indexer/code/bleve/bleve.go
index 0bfd85cb3f30d..8ba50ed77c938 100644
--- a/modules/indexer/code/bleve/bleve.go
+++ b/modules/indexer/code/bleve/bleve.go
@@ -174,7 +174,7 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro
return batch.Index(id, &RepoIndexerData{
RepoID: repo.ID,
CommitID: commitSha,
- Content: string(charset.ToUTF8DropErrors(fileContents)),
+ Content: string(charset.ToUTF8DropErrors(fileContents, charset.ConvertOpts{})),
Language: analyze.GetCodeLanguage(update.Filename, fileContents),
UpdatedAt: time.Now().UTC(),
})
diff --git a/modules/indexer/code/elasticsearch/elasticsearch.go b/modules/indexer/code/elasticsearch/elasticsearch.go
index e7e3429a39af6..2fadbfeb064e1 100644
--- a/modules/indexer/code/elasticsearch/elasticsearch.go
+++ b/modules/indexer/code/elasticsearch/elasticsearch.go
@@ -135,7 +135,7 @@ func (b *Indexer) addUpdate(ctx context.Context, batchWriter git.WriteCloserErro
Id(id).
Doc(map[string]any{
"repo_id": repo.ID,
- "content": string(charset.ToUTF8DropErrors(fileContents)),
+ "content": string(charset.ToUTF8DropErrors(fileContents, charset.ConvertOpts{})),
"commit_id": sha,
"language": analyze.GetCodeLanguage(update.Filename, fileContents),
"updated_at": timeutil.TimeStampNow(),
diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go
index abb39caa5753e..00157d44c99c4 100644
--- a/routers/web/repo/commit.go
+++ b/routers/web/repo/commit.go
@@ -384,7 +384,7 @@ func Diff(ctx *context.Context) {
Metas: ctx.Repo.Repository.ComposeMetas(ctx),
GitRepo: ctx.Repo.GitRepo,
Ctx: ctx,
- }, template.HTMLEscapeString(string(charset.ToUTF8WithFallback(note.Message))))
+ }, template.HTMLEscapeString(string(charset.ToUTF8WithFallback(note.Message, charset.ConvertOpts{}))))
if err != nil {
ctx.ServerError("RenderCommitMessage", err)
return
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index 042b8ed692acf..5ae48e1ce8148 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -142,7 +142,7 @@ func setCsvCompareContext(ctx *context.Context) {
return nil, nil, err
}
- csvReader, err := csv_module.CreateReaderAndDetermineDelimiter(ctx, charset.ToUTF8WithFallbackReader(reader))
+ csvReader, err := csv_module.CreateReaderAndDetermineDelimiter(ctx, charset.ToUTF8WithFallbackReader(reader, charset.ConvertOpts{}))
return csvReader, reader, err
}
diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go
index 5e7cd1caa3995..85d40e7820b16 100644
--- a/routers/web/repo/editor.go
+++ b/routers/web/repo/editor.go
@@ -166,8 +166,8 @@ func editFile(ctx *context.Context, isNewFile bool) {
}
buf = append(buf, d...)
- if content, err := charset.ToUTF8WithErr(buf); err != nil {
- log.Error("ToUTF8WithErr: %v", err)
+ if content, err := charset.ToUTF8(buf, charset.ConvertOpts{KeepBOM: true}); err != nil {
+ log.Error("ToUTF8: %v", err)
ctx.Data["FileContent"] = string(buf)
} else {
ctx.Data["FileContent"] = content
diff --git a/routers/web/repo/render.go b/routers/web/repo/render.go
index f2c6ab3f8fff4..7eb5a42aa43c0 100644
--- a/routers/web/repo/render.go
+++ b/routers/web/repo/render.go
@@ -43,7 +43,7 @@ func RenderFile(ctx *context.Context) {
st := typesniffer.DetectContentType(buf)
isTextFile := st.IsText()
- rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc))
+ rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc), charset.ConvertOpts{})
if markupType := markup.Type(blob.Name()); markupType == "" {
if isTextFile {
diff --git a/routers/web/repo/setting/lfs.go b/routers/web/repo/setting/lfs.go
index edf1298c2073e..cd0f11d548704 100644
--- a/routers/web/repo/setting/lfs.go
+++ b/routers/web/repo/setting/lfs.go
@@ -303,7 +303,7 @@ func LFSFileGet(ctx *context.Context) {
break
}
- rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc))
+ rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc), charset.ConvertOpts{})
// Building code view blocks with line number on server side.
escapedContent := &bytes.Buffer{}
diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go
index 00fd47b6506d1..af3021da11287 100644
--- a/routers/web/repo/view.go
+++ b/routers/web/repo/view.go
@@ -303,7 +303,7 @@ func renderReadmeFile(ctx *context.Context, subfolder string, readmeFile *git.Tr
return
}
- rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc))
+ rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc), charset.ConvertOpts{})
if markupType := markup.Type(readmeFile.Name()); markupType != "" {
ctx.Data["IsMarkup"] = true
@@ -492,7 +492,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry) {
break
}
- rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc))
+ rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc), charset.ConvertOpts{})
shouldRenderSource := ctx.FormString("display") == "source"
readmeExist := util.IsReadmeFileName(blob.Name())
diff --git a/templates/repo/editor/edit.tmpl b/templates/repo/editor/edit.tmpl
index 58ed6f356e71a..cfc266731b144 100644
--- a/templates/repo/editor/edit.tmpl
+++ b/templates/repo/editor/edit.tmpl
@@ -38,8 +38,7 @@
data-url="{{.Repository.Link}}/markup"
data-context="{{.RepoLink}}"
data-previewable-extensions="{{.PreviewableExtensions}}"
- data-line-wrap-extensions="{{.LineWrapExtensions}}">
-{{.FileContent}}
+ data-line-wrap-extensions="{{.LineWrapExtensions}}">{{.FileContent}}
diff --git a/tests/integration/migration-test/migration_test.go b/tests/integration/migration-test/migration_test.go
index 556a54015b4f1..40fcf95705887 100644
--- a/tests/integration/migration-test/migration_test.go
+++ b/tests/integration/migration-test/migration_test.go
@@ -141,7 +141,7 @@ func readSQLFromFile(version string) (string, error) {
if err != nil {
return "", err
}
- return string(charset.RemoveBOMIfPresent(bytes)), nil
+ return string(charset.MaybeRemoveBOM(bytes, charset.ConvertOpts{})), nil
}
func restoreOldDB(t *testing.T, version string) bool {
diff --git a/web_src/js/features/codeeditor.js b/web_src/js/features/codeeditor.js
index ae54268d56d18..fceb2f7620e9e 100644
--- a/web_src/js/features/codeeditor.js
+++ b/web_src/js/features/codeeditor.js
@@ -114,7 +114,7 @@ export async function createMonaco(textarea, filename, editorOpts) {
const model = editor.getModel();
model.onDidChangeContent(() => {
- textarea.value = editor.getValue();
+ textarea.value = editor.getValue({preserveBOM: true});
textarea.dispatchEvent(new Event('change')); // seems to be needed for jquery-are-you-sure
});
From 5f82ead13cb7706d3f660271d94de6101cef4119 Mon Sep 17 00:00:00 2001
From: Lunny Xiao
Date: Sun, 28 Jan 2024 04:09:51 +0800
Subject: [PATCH 12/17] Simplify how git repositories are opened (#28937)
## Purpose
This is a refactor toward building an abstraction over managing git
repositories.
Afterwards, it does not matter anymore if they are stored on the local
disk or somewhere remote.
## What this PR changes
We used `git.OpenRepository` everywhere previously.
Now, we should split them into two distinct functions:
Firstly, there are temporary repositories which do not change:
```go
git.OpenRepository(ctx, diskPath)
```
Gitea managed repositories having a record in the database in the
`repository` table are moved into the new package `gitrepo`:
```go
gitrepo.OpenRepository(ctx, repo_model.Repo)
```
Why is `repo_model.Repository` the second parameter instead of file
path?
Because then we can easily adapt our repository storage strategy.
The repositories can be stored locally, however, they could just as well
be stored on a remote server.
## Further changes in other PRs
- A Git Command wrapper on package `gitrepo` could be created. i.e.
`NewCommand(ctx, repo_model.Repository, commands...)`. `git.RunOpts{Dir:
repo.RepoPath()}`, the directory should be empty before invoking this
method and it can be filled in the function only. #28940
- Remove the `RepoPath()`/`WikiPath()` functions to reduce the
possibility of mistakes.
---------
Co-authored-by: delvh
---
cmd/admin.go | 3 +-
models/activities/repo_activity.go | 5 +-
models/issues/comment.go | 5 +-
models/issues/pull.go | 3 +-
models/repo/repo.go | 8 ++
modules/context/api.go | 9 +-
modules/context/context.go | 4 +-
modules/context/repo.go | 10 +-
modules/contexttest/context_tests.go | 6 +-
modules/git/repo_base.go | 44 --------
modules/git/repo_branch.go | 23 ----
modules/git/repo_branch_gogit.go | 29 -----
modules/git/repo_branch_nogogit.go | 13 +--
modules/gitrepo/branch.go | 32 ++++++
modules/gitrepo/gitrepo.go | 103 ++++++++++++++++++
modules/gitrepo/walk_gogit.go | 40 +++++++
modules/gitrepo/walk_nogogit.go | 17 +++
modules/indexer/stats/db.go | 3 +-
modules/repository/branch.go | 5 +-
modules/repository/generate.go | 3 +-
modules/repository/repo.go | 3 +-
routers/api/v1/repo/branch.go | 5 +-
routers/api/v1/repo/file.go | 4 +-
routers/api/v1/repo/pull.go | 9 +-
routers/api/v1/repo/pull_review.go | 5 +-
routers/api/v1/repo/repo.go | 3 +-
routers/api/v1/repo/wiki.go | 3 +-
routers/api/v1/utils/git.go | 3 +-
routers/private/internal_repo.go | 4 +-
routers/web/repo/commit.go | 5 +-
routers/web/repo/compare.go | 7 +-
routers/web/repo/editor_test.go | 3 +-
routers/web/repo/pull.go | 17 +--
routers/web/repo/wiki.go | 3 +-
routers/web/repo/wiki_test.go | 3 +-
routers/web/shared/user/header.go | 3 +-
services/actions/notifier_helper.go | 3 +-
services/asymkey/sign.go | 7 +-
services/automerge/automerge.go | 7 +-
services/convert/pull.go | 9 +-
services/doctor/misc.go | 3 +-
services/migrations/gitea_uploader.go | 3 +-
services/migrations/gitea_uploader_test.go | 5 +-
services/mirror/mirror_pull.go | 7 +-
services/mirror/mirror_push.go | 21 +++-
services/pull/check.go | 3 +-
services/pull/comment.go | 5 +-
services/pull/commit_status.go | 3 +-
services/pull/merge_rebase.go | 3 +-
services/pull/merge_squash.go | 3 +-
services/pull/patch.go | 3 +-
services/pull/pull.go | 17 +--
services/pull/pull_test.go | 5 +-
services/pull/review.go | 3 +-
services/release/release.go | 3 +-
services/release/release_test.go | 10 +-
services/repository/adopt.go | 3 +-
services/repository/archiver/archiver.go | 3 +-
services/repository/branch.go | 9 +-
services/repository/create.go | 3 +-
services/repository/files/commit.go | 3 +-
services/repository/files/content.go | 5 +-
services/repository/files/content_test.go | 5 +-
services/repository/files/file_test.go | 4 +-
services/repository/files/patch.go | 3 +-
services/repository/files/update.go | 3 +-
services/repository/fork.go | 5 +-
services/repository/hooks.go | 6 +-
services/repository/lfs.go | 3 +-
services/repository/push.go | 9 +-
services/wiki/wiki.go | 4 +-
services/wiki/wiki_test.go | 9 +-
tests/integration/api_packages_cargo_test.go | 4 +-
tests/integration/api_releases_test.go | 5 +-
.../integration/api_repo_file_create_test.go | 6 +-
.../integration/api_repo_file_update_test.go | 4 +-
.../integration/api_repo_files_change_test.go | 4 +-
.../api_repo_get_contents_list_test.go | 3 +-
.../integration/api_repo_get_contents_test.go | 3 +-
tests/integration/api_repo_git_tags_test.go | 3 +-
tests/integration/mirror_pull_test.go | 3 +-
tests/integration/mirror_push_test.go | 5 +-
tests/integration/pull_merge_test.go | 5 +-
tests/integration/repofiles_change_test.go | 9 +-
84 files changed, 426 insertions(+), 273 deletions(-)
create mode 100644 modules/gitrepo/branch.go
create mode 100644 modules/gitrepo/gitrepo.go
create mode 100644 modules/gitrepo/walk_gogit.go
create mode 100644 modules/gitrepo/walk_nogogit.go
diff --git a/cmd/admin.go b/cmd/admin.go
index 74bfa5a6c6703..6c9480e76eb7a 100644
--- a/cmd/admin.go
+++ b/cmd/admin.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
repo_module "code.gitea.io/gitea/modules/repository"
@@ -122,7 +123,7 @@ func runRepoSyncReleases(_ *cli.Context) error {
log.Trace("Processing next %d repos of %d", len(repos), count)
for _, repo := range repos {
log.Trace("Synchronizing repo %s with path %s", repo.FullName(), repo.RepoPath())
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
log.Warn("OpenRepository: %v", err)
continue
diff --git a/models/activities/repo_activity.go b/models/activities/repo_activity.go
index 91f5ac12bdc04..ba5e4959f0df8 100644
--- a/models/activities/repo_activity.go
+++ b/models/activities/repo_activity.go
@@ -14,6 +14,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"xorm.io/xorm"
)
@@ -65,7 +66,7 @@ func GetActivityStats(ctx context.Context, repo *repo_model.Repository, timeFrom
return nil, fmt.Errorf("FillUnresolvedIssues: %w", err)
}
if code {
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return nil, fmt.Errorf("OpenRepository: %w", err)
}
@@ -82,7 +83,7 @@ func GetActivityStats(ctx context.Context, repo *repo_model.Repository, timeFrom
// GetActivityStatsTopAuthors returns top author stats for git commits for all branches
func GetActivityStatsTopAuthors(ctx context.Context, repo *repo_model.Repository, timeFrom time.Time, count int) ([]*ActivityAuthorData, error) {
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return nil, fmt.Errorf("OpenRepository: %w", err)
}
diff --git a/models/issues/comment.go b/models/issues/comment.go
index 8a3bae5b883d2..c63fcab8944f5 100644
--- a/models/issues/comment.go
+++ b/models/issues/comment.go
@@ -18,7 +18,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/references"
@@ -762,8 +762,7 @@ func (c *Comment) LoadPushCommits(ctx context.Context) (err error) {
c.OldCommit = data.CommitIDs[0]
c.NewCommit = data.CommitIDs[1]
} else {
- repoPath := c.Issue.Repo.RepoPath()
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repoPath)
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, c.Issue.Repo)
if err != nil {
return err
}
diff --git a/models/issues/pull.go b/models/issues/pull.go
index 4ae6e38ae180e..2cb1e1b971e9c 100644
--- a/models/issues/pull.go
+++ b/models/issues/pull.go
@@ -19,6 +19,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/timeutil"
@@ -865,7 +866,7 @@ func PullRequestCodeOwnersReview(ctx context.Context, pull *Issue, pr *PullReque
return err
}
- repo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ repo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
return err
}
diff --git a/models/repo/repo.go b/models/repo/repo.go
index 4401041cdd528..13493ba6e80e6 100644
--- a/models/repo/repo.go
+++ b/models/repo/repo.go
@@ -196,6 +196,14 @@ func init() {
db.RegisterModel(new(Repository))
}
+func (repo *Repository) GetName() string {
+ return repo.Name
+}
+
+func (repo *Repository) GetOwnerName() string {
+ return repo.OwnerName
+}
+
// SanitizedOriginalURL returns a sanitized OriginalURL
func (repo *Repository) SanitizedOriginalURL() string {
if repo.OriginalURL == "" {
diff --git a/modules/context/api.go b/modules/context/api.go
index f41228ad7674e..e226264a87352 100644
--- a/modules/context/api.go
+++ b/modules/context/api.go
@@ -11,11 +11,11 @@ import (
"net/url"
"strings"
- repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
mc "code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/httpcache"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -224,7 +224,7 @@ func APIContexter() func(http.Handler) http.Handler {
defer baseCleanUp()
ctx.Base.AppendContextValue(apiContextKey, ctx)
- ctx.Base.AppendContextValueFunc(git.RepositoryContextKey, func() any { return ctx.Repo.GitRepo })
+ ctx.Base.AppendContextValueFunc(gitrepo.RepositoryContextKey, func() any { return ctx.Repo.GitRepo })
// If request sends files, parse them here otherwise the Query() can't be parsed and the CsrfToken will be invalid.
if ctx.Req.Method == "POST" && strings.Contains(ctx.Req.Header.Get("Content-Type"), "multipart/form-data") {
@@ -278,10 +278,9 @@ func ReferencesGitRepo(allowEmpty ...bool) func(ctx *APIContext) (cancel context
// For API calls.
if ctx.Repo.GitRepo == nil {
- repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
- gitRepo, err := git.OpenRepository(ctx, repoPath)
+ gitRepo, err := gitrepo.OpenRepository(ctx, ctx.Repo.Repository)
if err != nil {
- ctx.Error(http.StatusInternalServerError, "RepoRef Invalid repo "+repoPath, err)
+ ctx.Error(http.StatusInternalServerError, fmt.Sprintf("Open Repository %v failed", ctx.Repo.Repository.FullName()), err)
return cancel
}
ctx.Repo.GitRepo = gitRepo
diff --git a/modules/context/context.go b/modules/context/context.go
index 8a94e958b5169..d19c5d119830d 100644
--- a/modules/context/context.go
+++ b/modules/context/context.go
@@ -17,7 +17,7 @@ import (
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
mc "code.gitea.io/gitea/modules/cache"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/httpcache"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/templates"
@@ -163,7 +163,7 @@ func Contexter() func(next http.Handler) http.Handler {
ctx.Data["PageData"] = ctx.PageData
ctx.Base.AppendContextValue(WebContextKey, ctx)
- ctx.Base.AppendContextValueFunc(git.RepositoryContextKey, func() any { return ctx.Repo.GitRepo })
+ ctx.Base.AppendContextValueFunc(gitrepo.RepositoryContextKey, func() any { return ctx.Repo.GitRepo })
ctx.Csrf = PrepareCSRFProtector(csrfOpts, ctx)
diff --git a/modules/context/repo.go b/modules/context/repo.go
index 8d82be1990da1..75ebfec705447 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -23,6 +23,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
code_indexer "code.gitea.io/gitea/modules/indexer/code"
"code.gitea.io/gitea/modules/log"
repo_module "code.gitea.io/gitea/modules/repository"
@@ -633,7 +634,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc {
return nil
}
- gitRepo, err := git.OpenRepository(ctx, repo_model.RepoPath(userName, repoName))
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
if strings.Contains(err.Error(), "repository does not exist") || strings.Contains(err.Error(), "no such file or directory") {
log.Error("Repository %-v has a broken repository on the file system: %s Error: %v", ctx.Repo.Repository, ctx.Repo.Repository.RepoPath(), err)
@@ -645,7 +646,7 @@ func RepoAssignment(ctx *Context) context.CancelFunc {
}
return nil
}
- ctx.ServerError("RepoAssignment Invalid repo "+repo_model.RepoPath(userName, repoName), err)
+ ctx.ServerError("RepoAssignment Invalid repo "+repo.FullName(), err)
return nil
}
if ctx.Repo.GitRepo != nil {
@@ -920,10 +921,9 @@ func RepoRefByType(refType RepoRefType, ignoreNotExistErr ...bool) func(*Context
)
if ctx.Repo.GitRepo == nil {
- repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
- ctx.Repo.GitRepo, err = git.OpenRepository(ctx, repoPath)
+ ctx.Repo.GitRepo, err = gitrepo.OpenRepository(ctx, ctx.Repo.Repository)
if err != nil {
- ctx.ServerError("RepoRef Invalid repo "+repoPath, err)
+ ctx.ServerError(fmt.Sprintf("Open Repository %v failed", ctx.Repo.Repository.FullName()), err)
return nil
}
// We opened it, we should close it
diff --git a/modules/contexttest/context_tests.go b/modules/contexttest/context_tests.go
index 8994c1e451c41..9ca028bb6ec26 100644
--- a/modules/contexttest/context_tests.go
+++ b/modules/contexttest/context_tests.go
@@ -18,7 +18,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/templates"
"code.gitea.io/gitea/modules/translation"
"code.gitea.io/gitea/modules/web/middleware"
@@ -107,7 +107,7 @@ func LoadRepoCommit(t *testing.T, ctx gocontext.Context) {
assert.FailNow(t, "context is not *context.Context or *context.APIContext")
}
- gitRepo, err := git.OpenRepository(ctx, repo.Repository.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo.Repository)
assert.NoError(t, err)
defer gitRepo.Close()
branch, err := gitRepo.GetHEADBranch()
@@ -137,7 +137,7 @@ func LoadUser(t *testing.T, ctx gocontext.Context, userID int64) {
func LoadGitRepo(t *testing.T, ctx *context.Context) {
assert.NoError(t, ctx.Repo.Repository.LoadOwner(ctx))
var err error
- ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath())
+ ctx.Repo.GitRepo, err = gitrepo.OpenRepository(ctx, ctx.Repo.Repository)
assert.NoError(t, err)
}
diff --git a/modules/git/repo_base.go b/modules/git/repo_base.go
index a9d91d2deb2d2..6c148d9af516a 100644
--- a/modules/git/repo_base.go
+++ b/modules/git/repo_base.go
@@ -3,48 +3,4 @@
package git
-import (
- "context"
- "io"
-)
-
var isGogit bool
-
-// contextKey is a value for use with context.WithValue.
-type contextKey struct {
- name string
-}
-
-// RepositoryContextKey is a context key. It is used with context.Value() to get the current Repository for the context
-var RepositoryContextKey = &contextKey{"repository"}
-
-// RepositoryFromContext attempts to get the repository from the context
-func RepositoryFromContext(ctx context.Context, path string) *Repository {
- value := ctx.Value(RepositoryContextKey)
- if value == nil {
- return nil
- }
-
- if repo, ok := value.(*Repository); ok && repo != nil {
- if repo.Path == path {
- return repo
- }
- }
-
- return nil
-}
-
-type nopCloser func()
-
-func (nopCloser) Close() error { return nil }
-
-// RepositoryFromContextOrOpen attempts to get the repository from the context or just opens it
-func RepositoryFromContextOrOpen(ctx context.Context, path string) (*Repository, io.Closer, error) {
- gitRepo := RepositoryFromContext(ctx, path)
- if gitRepo != nil {
- return gitRepo, nopCloser(nil), nil
- }
-
- gitRepo, err := OpenRepository(ctx, path)
- return gitRepo, gitRepo, err
-}
diff --git a/modules/git/repo_branch.go b/modules/git/repo_branch.go
index 59580939757c1..979c5dec9175a 100644
--- a/modules/git/repo_branch.go
+++ b/modules/git/repo_branch.go
@@ -86,29 +86,6 @@ func (repo *Repository) GetBranch(branch string) (*Branch, error) {
}, nil
}
-// GetBranchesByPath returns a branch by it's path
-// if limit = 0 it will not limit
-func GetBranchesByPath(ctx context.Context, path string, skip, limit int) ([]*Branch, int, error) {
- gitRepo, err := OpenRepository(ctx, path)
- if err != nil {
- return nil, 0, err
- }
- defer gitRepo.Close()
-
- return gitRepo.GetBranches(skip, limit)
-}
-
-// GetBranchCommitID returns a branch commit ID by its name
-func GetBranchCommitID(ctx context.Context, path, branch string) (string, error) {
- gitRepo, err := OpenRepository(ctx, path)
- if err != nil {
- return "", err
- }
- defer gitRepo.Close()
-
- return gitRepo.GetBranchCommitID(branch)
-}
-
// GetBranches returns a slice of *git.Branch
func (repo *Repository) GetBranches(skip, limit int) ([]*Branch, int, error) {
brs, countAll, err := repo.GetBranchNames(skip, limit)
diff --git a/modules/git/repo_branch_gogit.go b/modules/git/repo_branch_gogit.go
index 1c0d9a18aa9d9..d1ec14d81155f 100644
--- a/modules/git/repo_branch_gogit.go
+++ b/modules/git/repo_branch_gogit.go
@@ -7,7 +7,6 @@
package git
import (
- "context"
"sort"
"strings"
@@ -95,34 +94,6 @@ func (repo *Repository) GetBranchNames(skip, limit int) ([]string, int, error) {
return branchNames, len(branchData), nil
}
-// WalkReferences walks all the references from the repository
-// refType should be empty, ObjectTag or ObjectBranch. All other values are equivalent to empty.
-func WalkReferences(ctx context.Context, repoPath string, walkfn func(sha1, refname string) error) (int, error) {
- repo := RepositoryFromContext(ctx, repoPath)
- if repo == nil {
- var err error
- repo, err = OpenRepository(ctx, repoPath)
- if err != nil {
- return 0, err
- }
- defer repo.Close()
- }
-
- i := 0
- iter, err := repo.gogitRepo.References()
- if err != nil {
- return i, err
- }
- defer iter.Close()
-
- err = iter.ForEach(func(ref *plumbing.Reference) error {
- err := walkfn(ref.Hash().String(), string(ref.Name()))
- i++
- return err
- })
- return i, err
-}
-
// WalkReferences walks all the references from the repository
func (repo *Repository) WalkReferences(arg ObjectType, skip, limit int, walkfn func(sha1, refname string) error) (int, error) {
i := 0
diff --git a/modules/git/repo_branch_nogogit.go b/modules/git/repo_branch_nogogit.go
index b1e7c8b73e640..470faebe25f79 100644
--- a/modules/git/repo_branch_nogogit.go
+++ b/modules/git/repo_branch_nogogit.go
@@ -65,11 +65,6 @@ func (repo *Repository) GetBranchNames(skip, limit int) ([]string, int, error) {
return callShowRef(repo.Ctx, repo.Path, BranchPrefix, TrustedCmdArgs{BranchPrefix, "--sort=-committerdate"}, skip, limit)
}
-// WalkReferences walks all the references from the repository
-func WalkReferences(ctx context.Context, repoPath string, walkfn func(sha1, refname string) error) (int, error) {
- return walkShowRef(ctx, repoPath, nil, 0, 0, walkfn)
-}
-
// WalkReferences walks all the references from the repository
// refType should be empty, ObjectTag or ObjectBranch. All other values are equivalent to empty.
func (repo *Repository) WalkReferences(refType ObjectType, skip, limit int, walkfn func(sha1, refname string) error) (int, error) {
@@ -81,12 +76,12 @@ func (repo *Repository) WalkReferences(refType ObjectType, skip, limit int, walk
args = TrustedCmdArgs{BranchPrefix, "--sort=-committerdate"}
}
- return walkShowRef(repo.Ctx, repo.Path, args, skip, limit, walkfn)
+ return WalkShowRef(repo.Ctx, repo.Path, args, skip, limit, walkfn)
}
// callShowRef return refs, if limit = 0 it will not limit
func callShowRef(ctx context.Context, repoPath, trimPrefix string, extraArgs TrustedCmdArgs, skip, limit int) (branchNames []string, countAll int, err error) {
- countAll, err = walkShowRef(ctx, repoPath, extraArgs, skip, limit, func(_, branchName string) error {
+ countAll, err = WalkShowRef(ctx, repoPath, extraArgs, skip, limit, func(_, branchName string) error {
branchName = strings.TrimPrefix(branchName, trimPrefix)
branchNames = append(branchNames, branchName)
@@ -95,7 +90,7 @@ func callShowRef(ctx context.Context, repoPath, trimPrefix string, extraArgs Tru
return branchNames, countAll, err
}
-func walkShowRef(ctx context.Context, repoPath string, extraArgs TrustedCmdArgs, skip, limit int, walkfn func(sha1, refname string) error) (countAll int, err error) {
+func WalkShowRef(ctx context.Context, repoPath string, extraArgs TrustedCmdArgs, skip, limit int, walkfn func(sha1, refname string) error) (countAll int, err error) {
stdoutReader, stdoutWriter := io.Pipe()
defer func() {
_ = stdoutReader.Close()
@@ -189,7 +184,7 @@ func walkShowRef(ctx context.Context, repoPath string, extraArgs TrustedCmdArgs,
// GetRefsBySha returns all references filtered with prefix that belong to a sha commit hash
func (repo *Repository) GetRefsBySha(sha, prefix string) ([]string, error) {
var revList []string
- _, err := walkShowRef(repo.Ctx, repo.Path, nil, 0, 0, func(walkSha, refname string) error {
+ _, err := WalkShowRef(repo.Ctx, repo.Path, nil, 0, 0, func(walkSha, refname string) error {
if walkSha == sha && strings.HasPrefix(refname, prefix) {
revList = append(revList, refname)
}
diff --git a/modules/gitrepo/branch.go b/modules/gitrepo/branch.go
new file mode 100644
index 0000000000000..dcaf92668d158
--- /dev/null
+++ b/modules/gitrepo/branch.go
@@ -0,0 +1,32 @@
+// Copyright 2024 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "context"
+
+ "code.gitea.io/gitea/modules/git"
+)
+
+// GetBranchesByPath returns a branch by its path
+// if limit = 0 it will not limit
+func GetBranchesByPath(ctx context.Context, repo Repository, skip, limit int) ([]*git.Branch, int, error) {
+ gitRepo, err := OpenRepository(ctx, repo)
+ if err != nil {
+ return nil, 0, err
+ }
+ defer gitRepo.Close()
+
+ return gitRepo.GetBranches(skip, limit)
+}
+
+func GetBranchCommitID(ctx context.Context, repo Repository, branch string) (string, error) {
+ gitRepo, err := OpenRepository(ctx, repo)
+ if err != nil {
+ return "", err
+ }
+ defer gitRepo.Close()
+
+ return gitRepo.GetBranchCommitID(branch)
+}
diff --git a/modules/gitrepo/gitrepo.go b/modules/gitrepo/gitrepo.go
new file mode 100644
index 0000000000000..d89f8f9c0c88c
--- /dev/null
+++ b/modules/gitrepo/gitrepo.go
@@ -0,0 +1,103 @@
+// Copyright 2024 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package gitrepo
+
+import (
+ "context"
+ "io"
+ "path/filepath"
+ "strings"
+
+ "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/setting"
+)
+
+type Repository interface {
+ GetName() string
+ GetOwnerName() string
+}
+
+func repoPath(repo Repository) string {
+ return filepath.Join(setting.RepoRootPath, strings.ToLower(repo.GetOwnerName()), strings.ToLower(repo.GetName())+".git")
+}
+
+func wikiPath(repo Repository) string {
+ return filepath.Join(setting.RepoRootPath, strings.ToLower(repo.GetOwnerName()), strings.ToLower(repo.GetName())+".wiki.git")
+}
+
+// OpenRepository opens the repository at the given relative path with the provided context.
+func OpenRepository(ctx context.Context, repo Repository) (*git.Repository, error) {
+ return git.OpenRepository(ctx, repoPath(repo))
+}
+
+func OpenWikiRepository(ctx context.Context, repo Repository) (*git.Repository, error) {
+ return git.OpenRepository(ctx, wikiPath(repo))
+}
+
+// contextKey is a value for use with context.WithValue.
+type contextKey struct {
+ name string
+}
+
+// RepositoryContextKey is a context key. It is used with context.Value() to get the current Repository for the context
+var RepositoryContextKey = &contextKey{"repository"}
+
+// RepositoryFromContext attempts to get the repository from the context
+func repositoryFromContext(ctx context.Context, repo Repository) *git.Repository {
+ value := ctx.Value(RepositoryContextKey)
+ if value == nil {
+ return nil
+ }
+
+ if gitRepo, ok := value.(*git.Repository); ok && gitRepo != nil {
+ if gitRepo.Path == repoPath(repo) {
+ return gitRepo
+ }
+ }
+
+ return nil
+}
+
+type nopCloser func()
+
+func (nopCloser) Close() error { return nil }
+
+// RepositoryFromContextOrOpen attempts to get the repository from the context or just opens it
+func RepositoryFromContextOrOpen(ctx context.Context, repo Repository) (*git.Repository, io.Closer, error) {
+ gitRepo := repositoryFromContext(ctx, repo)
+ if gitRepo != nil {
+ return gitRepo, nopCloser(nil), nil
+ }
+
+ gitRepo, err := OpenRepository(ctx, repo)
+ return gitRepo, gitRepo, err
+}
+
+// repositoryFromContextPath attempts to get the repository from the context
+func repositoryFromContextPath(ctx context.Context, path string) *git.Repository {
+ value := ctx.Value(RepositoryContextKey)
+ if value == nil {
+ return nil
+ }
+
+ if repo, ok := value.(*git.Repository); ok && repo != nil {
+ if repo.Path == path {
+ return repo
+ }
+ }
+
+ return nil
+}
+
+// RepositoryFromContextOrOpenPath attempts to get the repository from the context or just opens it
+// Deprecated: Use RepositoryFromContextOrOpen instead
+func RepositoryFromContextOrOpenPath(ctx context.Context, path string) (*git.Repository, io.Closer, error) {
+ gitRepo := repositoryFromContextPath(ctx, path)
+ if gitRepo != nil {
+ return gitRepo, nopCloser(nil), nil
+ }
+
+ gitRepo, err := git.OpenRepository(ctx, path)
+ return gitRepo, gitRepo, err
+}
diff --git a/modules/gitrepo/walk_gogit.go b/modules/gitrepo/walk_gogit.go
new file mode 100644
index 0000000000000..6370faf08e7df
--- /dev/null
+++ b/modules/gitrepo/walk_gogit.go
@@ -0,0 +1,40 @@
+// Copyright 2024 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+//go:build gogit
+
+package gitrepo
+
+import (
+ "context"
+
+ "github.com/go-git/go-git/v5/plumbing"
+)
+
+// WalkReferences walks all the references from the repository
+// refname is empty, ObjectTag or ObjectBranch. All other values should be treated as equivalent to empty.
+func WalkReferences(ctx context.Context, repo Repository, walkfn func(sha1, refname string) error) (int, error) {
+ gitRepo := repositoryFromContext(ctx, repo)
+ if gitRepo == nil {
+ var err error
+ gitRepo, err = OpenRepository(ctx, repo)
+ if err != nil {
+ return 0, err
+ }
+ defer gitRepo.Close()
+ }
+
+ i := 0
+ iter, err := gitRepo.GoGitRepo().References()
+ if err != nil {
+ return i, err
+ }
+ defer iter.Close()
+
+ err = iter.ForEach(func(ref *plumbing.Reference) error {
+ err := walkfn(ref.Hash().String(), string(ref.Name()))
+ i++
+ return err
+ })
+ return i, err
+}
diff --git a/modules/gitrepo/walk_nogogit.go b/modules/gitrepo/walk_nogogit.go
new file mode 100644
index 0000000000000..ff9555996dff5
--- /dev/null
+++ b/modules/gitrepo/walk_nogogit.go
@@ -0,0 +1,17 @@
+// Copyright 2024 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+//go:build !gogit
+
+package gitrepo
+
+import (
+ "context"
+
+ "code.gitea.io/gitea/modules/git"
+)
+
+// WalkReferences walks all the references from the repository
+func WalkReferences(ctx context.Context, repo Repository, walkfn func(sha1, refname string) error) (int, error) {
+ return git.WalkShowRef(ctx, repoPath(repo), nil, 0, 0, walkfn)
+}
diff --git a/modules/indexer/stats/db.go b/modules/indexer/stats/db.go
index 163843b47fa5a..98a977c7008fe 100644
--- a/modules/indexer/stats/db.go
+++ b/modules/indexer/stats/db.go
@@ -8,6 +8,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -35,7 +36,7 @@ func (db *DBIndexer) Index(id int64) error {
return err
}
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
if err.Error() == "no such file or directory" {
return nil
diff --git a/modules/repository/branch.go b/modules/repository/branch.go
index cd45f162276f3..e448490f4ac18 100644
--- a/modules/repository/branch.go
+++ b/modules/repository/branch.go
@@ -11,6 +11,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/timeutil"
)
@@ -24,9 +25,9 @@ func SyncRepoBranches(ctx context.Context, repoID, doerID int64) (int64, error)
log.Debug("SyncRepoBranches: in Repo[%d:%s]", repo.ID, repo.FullName())
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
- log.Error("OpenRepository[%s]: %w", repo.RepoPath(), err)
+ log.Error("OpenRepository[%s]: %w", repo.FullName(), err)
return 0, err
}
defer gitRepo.Close()
diff --git a/modules/repository/generate.go b/modules/repository/generate.go
index f8478b8c1852a..b32c4e058e503 100644
--- a/modules/repository/generate.go
+++ b/modules/repository/generate.go
@@ -19,6 +19,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
@@ -271,7 +272,7 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r
repo.DefaultBranch = templateRepo.DefaultBranch
}
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
return fmt.Errorf("openRepository: %w", err)
}
diff --git a/modules/repository/repo.go b/modules/repository/repo.go
index 5352da0378d9a..fc3af040719ff 100644
--- a/modules/repository/repo.go
+++ b/modules/repository/repo.go
@@ -19,6 +19,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/migration"
@@ -291,7 +292,7 @@ func SyncRepoTags(ctx context.Context, repoID int64) error {
return err
}
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
return err
}
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index edbfbcc568bad..bd02a8afc4340 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -16,6 +16,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
repo_module "code.gitea.io/gitea/modules/repository"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
@@ -643,7 +644,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
} else {
if !isPlainRule {
if ctx.Repo.GitRepo == nil {
- ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath())
+ ctx.Repo.GitRepo, err = gitrepo.OpenRepository(ctx, ctx.Repo.Repository)
if err != nil {
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
return
@@ -920,7 +921,7 @@ func EditBranchProtection(ctx *context.APIContext) {
} else {
if !isPlainRule {
if ctx.Repo.GitRepo == nil {
- ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath())
+ ctx.Repo.GitRepo, err = gitrepo.OpenRepository(ctx, ctx.Repo.Repository)
if err != nil {
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
return
diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go
index 94e634461c278..065d6bf8b2c38 100644
--- a/routers/api/v1/repo/file.go
+++ b/routers/api/v1/repo/file.go
@@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/httpcache"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
@@ -279,9 +280,8 @@ func GetArchive(ctx *context.APIContext) {
// "404":
// "$ref": "#/responses/notFound"
- repoPath := repo_model.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
if ctx.Repo.GitRepo == nil {
- gitRepo, err := git.OpenRepository(ctx, repoPath)
+ gitRepo, err := gitrepo.OpenRepository(ctx, ctx.Repo.Repository)
if err != nil {
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
return
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index b1cb7011f1d4b..eaf406e64d8a6 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -23,6 +23,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -906,9 +907,9 @@ func MergePullRequest(ctx *context.APIContext) {
if ctx.Repo != nil && ctx.Repo.Repository != nil && ctx.Repo.Repository.ID == pr.HeadRepoID && ctx.Repo.GitRepo != nil {
headRepo = ctx.Repo.GitRepo
} else {
- headRepo, err = git.OpenRepository(ctx, pr.HeadRepo.RepoPath())
+ headRepo, err = gitrepo.OpenRepository(ctx, pr.HeadRepo)
if err != nil {
- ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
+ ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.FullName()), err)
return
}
defer headRepo.Close()
@@ -1004,7 +1005,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
headRepo = ctx.Repo.Repository
headGitRepo = ctx.Repo.GitRepo
} else {
- headGitRepo, err = git.OpenRepository(ctx, repo_model.RepoPath(headUser.Name, headRepo.Name))
+ headGitRepo, err = gitrepo.OpenRepository(ctx, headRepo)
if err != nil {
ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
return nil, nil, nil, nil, "", ""
@@ -1308,7 +1309,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
}
var prInfo *git.CompareInfo
- baseGitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
+ baseGitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.BaseRepo)
if err != nil {
ctx.ServerError("OpenRepository", err)
return
diff --git a/routers/api/v1/repo/pull_review.go b/routers/api/v1/repo/pull_review.go
index 7b9445be4c068..07d8f4877bb3d 100644
--- a/routers/api/v1/repo/pull_review.go
+++ b/routers/api/v1/repo/pull_review.go
@@ -13,7 +13,7 @@ import (
access_model "code.gitea.io/gitea/models/perm/access"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/routers/api/v1/utils"
@@ -329,8 +329,7 @@ func CreatePullReview(ctx *context.APIContext) {
// if CommitID is empty, set it as lastCommitID
if opts.CommitID == "" {
-
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.Issue.Repo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.Issue.Repo)
if err != nil {
ctx.Error(http.StatusInternalServerError, "git.OpenRepository", err)
return
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index 436b83adf2b35..2efdccb569901 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -21,6 +21,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/label"
"code.gitea.io/gitea/modules/log"
repo_module "code.gitea.io/gitea/modules/repository"
@@ -718,7 +719,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
if ctx.Repo.GitRepo == nil && !repo.IsEmpty {
var err error
- ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath())
+ ctx.Repo.GitRepo, err = gitrepo.OpenRepository(ctx, ctx.Repo.Repository)
if err != nil {
ctx.Error(http.StatusInternalServerError, "Unable to OpenRepository", err)
return err
diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go
index 8e5ecce310e3e..ba3e978a83531 100644
--- a/routers/api/v1/repo/wiki.go
+++ b/routers/api/v1/repo/wiki.go
@@ -12,6 +12,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
@@ -475,7 +476,7 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error)
// findWikiRepoCommit opens the wiki repo and returns the latest commit, writing to context on error.
// The caller is responsible for closing the returned repo again
func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit) {
- wikiRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath())
+ wikiRepo, err := gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository)
if err != nil {
if git.IsErrNotExist(err) || err.Error() == "no such file or directory" {
diff --git a/routers/api/v1/utils/git.go b/routers/api/v1/utils/git.go
index 39714e343f013..2299cdc247548 100644
--- a/routers/api/v1/utils/git.go
+++ b/routers/api/v1/utils/git.go
@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
)
@@ -79,7 +80,7 @@ func ConvertToObjectID(ctx gocontext.Context, repo *context.Repository, commitID
}
}
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.Repository.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo.Repository)
if err != nil {
return objectFormat.EmptyObjectID(), fmt.Errorf("RepositoryFromContextOrOpen: %w", err)
}
diff --git a/routers/private/internal_repo.go b/routers/private/internal_repo.go
index 5e7e82b03c961..615239d479d96 100644
--- a/routers/private/internal_repo.go
+++ b/routers/private/internal_repo.go
@@ -10,7 +10,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
gitea_context "code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/private"
)
@@ -28,7 +28,7 @@ func RepoAssignment(ctx *gitea_context.PrivateContext) context.CancelFunc {
return nil
}
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
log.Error("Failed to open repository: %s/%s Error: %v", ownerName, repoName, err)
ctx.JSON(http.StatusInternalServerError, private.Response{
diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go
index 00157d44c99c4..32fa973ef61e5 100644
--- a/routers/web/repo/commit.go
+++ b/routers/web/repo/commit.go
@@ -22,6 +22,7 @@ import (
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/gitgraph"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/setting"
@@ -279,7 +280,7 @@ func Diff(ctx *context.Context) {
)
if ctx.Data["PageIsWiki"] != nil {
- gitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath())
+ gitRepo, err = gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository)
if err != nil {
ctx.ServerError("Repo.GitRepo.GetCommit", err)
return
@@ -404,7 +405,7 @@ func Diff(ctx *context.Context) {
func RawDiff(ctx *context.Context) {
var gitRepo *git.Repository
if ctx.Data["PageIsWiki"] != nil {
- wikiRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath())
+ wikiRepo, err := gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository)
if err != nil {
ctx.ServerError("OpenRepository", err)
return
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index 5ae48e1ce8148..a3593815b8b74 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -28,6 +28,7 @@ import (
"code.gitea.io/gitea/modules/context"
csv_module "code.gitea.io/gitea/modules/csv"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/setting"
@@ -408,7 +409,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
ci.HeadRepo = ctx.Repo.Repository
ci.HeadGitRepo = ctx.Repo.GitRepo
} else if has {
- ci.HeadGitRepo, err = git.OpenRepository(ctx, ci.HeadRepo.RepoPath())
+ ci.HeadGitRepo, err = gitrepo.OpenRepository(ctx, ci.HeadRepo)
if err != nil {
ctx.ServerError("OpenRepository", err)
return nil
@@ -688,7 +689,7 @@ func PrepareCompareDiff(
}
func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repository) (branches, tags []string, err error) {
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
return nil, nil, err
}
@@ -876,7 +877,7 @@ func ExcerptBlob(ctx *context.Context) {
gitRepo := ctx.Repo.GitRepo
if ctx.FormBool("wiki") {
var err error
- gitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath())
+ gitRepo, err = gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository)
if err != nil {
ctx.ServerError("OpenRepository", err)
return
diff --git a/routers/web/repo/editor_test.go b/routers/web/repo/editor_test.go
index 67fb277d5c2b0..c28c3ef1d632d 100644
--- a/routers/web/repo/editor_test.go
+++ b/routers/web/repo/editor_test.go
@@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/contexttest"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"github.com/stretchr/testify/assert"
)
@@ -66,7 +67,7 @@ func TestGetClosestParentWithFiles(t *testing.T) {
repo := ctx.Repo.Repository
branch := repo.DefaultBranch
- gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
+ gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo)
defer gitRepo.Close()
commit, _ := gitRepo.GetBranchCommit(branch)
var expectedTreePath string // Should return the root dir, empty string, since there are no subdirs in this repo
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index e36d7092af286..b265cf47548bc 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -29,6 +29,7 @@ import (
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
issue_template "code.gitea.io/gitea/modules/issue/template"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -530,7 +531,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
if pull.BaseRepoID == ctx.Repo.Repository.ID && ctx.Repo.GitRepo != nil {
baseGitRepo = ctx.Repo.GitRepo
} else {
- baseGitRepo, err := git.OpenRepository(ctx, pull.BaseRepo.RepoPath())
+ baseGitRepo, err := gitrepo.OpenRepository(ctx, pull.BaseRepo)
if err != nil {
ctx.ServerError("OpenRepository", err)
return nil
@@ -582,7 +583,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *issues_model.Issue) *git.C
var headBranchSha string
// HeadRepo may be missing
if pull.HeadRepo != nil {
- headGitRepo, err := git.OpenRepository(ctx, pull.HeadRepo.RepoPath())
+ headGitRepo, err := gitrepo.OpenRepository(ctx, pull.HeadRepo)
if err != nil {
ctx.ServerError("OpenRepository", err)
return nil
@@ -1314,9 +1315,9 @@ func MergePullRequest(ctx *context.Context) {
if ctx.Repo != nil && ctx.Repo.Repository != nil && pr.HeadRepoID == ctx.Repo.Repository.ID && ctx.Repo.GitRepo != nil {
headRepo = ctx.Repo.GitRepo
} else {
- headRepo, err = git.OpenRepository(ctx, pr.HeadRepo.RepoPath())
+ headRepo, err = gitrepo.OpenRepository(ctx, pr.HeadRepo)
if err != nil {
- ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
+ ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.FullName()), err)
return
}
defer headRepo.Close()
@@ -1537,9 +1538,9 @@ func CleanUpPullRequest(ctx *context.Context) {
gitBaseRepo = ctx.Repo.GitRepo
} else {
// If not just open it
- gitBaseRepo, err = git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ gitBaseRepo, err = gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
- ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.BaseRepo.RepoPath()), err)
+ ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.BaseRepo.FullName()), err)
return
}
defer gitBaseRepo.Close()
@@ -1552,9 +1553,9 @@ func CleanUpPullRequest(ctx *context.Context) {
gitRepo = ctx.Repo.GitRepo
} else if pr.BaseRepoID != pr.HeadRepoID {
// Otherwise just load it up
- gitRepo, err = git.OpenRepository(ctx, pr.HeadRepo.RepoPath())
+ gitRepo, err = gitrepo.OpenRepository(ctx, pr.HeadRepo)
if err != nil {
- ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
+ ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.FullName()), err)
return
}
defer gitRepo.Close()
diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go
index 4e09f046cf856..5e7b971e67b72 100644
--- a/routers/web/repo/wiki.go
+++ b/routers/web/repo/wiki.go
@@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
@@ -92,7 +93,7 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error)
}
func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, error) {
- wikiRepo, err := git.OpenRepository(ctx, ctx.Repo.Repository.WikiPath())
+ wikiRepo, err := gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository)
if err != nil {
ctx.ServerError("OpenRepository", err)
return nil, nil, err
diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go
index ae050df967a52..d3decdae2deff 100644
--- a/routers/web/repo/wiki_test.go
+++ b/routers/web/repo/wiki_test.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/contexttest"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/forms"
wiki_service "code.gitea.io/gitea/services/wiki"
@@ -26,7 +27,7 @@ const (
)
func wikiEntry(t *testing.T, repo *repo_model.Repository, wikiName wiki_service.WebPath) *git.TreeEntry {
- wikiRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
+ wikiRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo)
assert.NoError(t, err)
defer wikiRepo.Close()
commit, err := wikiRepo.GetBranchCommit("master")
diff --git a/routers/web/shared/user/header.go b/routers/web/shared/user/header.go
index 0f8d64e7b24d3..a2c0abb47e4a1 100644
--- a/routers/web/shared/user/header.go
+++ b/routers/web/shared/user/header.go
@@ -13,6 +13,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/markup/markdown"
@@ -90,7 +91,7 @@ func FindUserProfileReadme(ctx *context.Context, doer *user_model.User) (profile
if err == nil {
perm, err := access_model.GetUserRepoPermission(ctx, profileDbRepo, doer)
if err == nil && !profileDbRepo.IsEmpty && perm.CanRead(unit.TypeCode) {
- if profileGitRepo, err = git.OpenRepository(ctx, profileDbRepo.RepoPath()); err != nil {
+ if profileGitRepo, err = gitrepo.OpenRepository(ctx, profileDbRepo); err != nil {
log.Error("FindUserProfileReadme failed to OpenRepository: %v", err)
} else {
if commit, err := profileGitRepo.GetBranchCommit(profileDbRepo.DefaultBranch); err != nil {
diff --git a/services/actions/notifier_helper.go b/services/actions/notifier_helper.go
index 2a3ffb76f30d2..9900de3d2ecdd 100644
--- a/services/actions/notifier_helper.go
+++ b/services/actions/notifier_helper.go
@@ -20,6 +20,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
actions_module "code.gitea.io/gitea/modules/actions"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -128,7 +129,7 @@ func notify(ctx context.Context, input *notifyInput) error {
return nil
}
- gitRepo, err := git.OpenRepository(context.Background(), input.Repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(context.Background(), input.Repo)
if err != nil {
return fmt.Errorf("git.OpenRepository: %w", err)
}
diff --git a/services/asymkey/sign.go b/services/asymkey/sign.go
index 0c4aac8156934..2f5d76a29334b 100644
--- a/services/asymkey/sign.go
+++ b/services/asymkey/sign.go
@@ -13,8 +13,10 @@ import (
"code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
issues_model "code.gitea.io/gitea/models/issues"
+ repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/setting"
@@ -167,7 +169,8 @@ Loop:
}
// SignWikiCommit determines if we should sign the commits to this repository wiki
-func SignWikiCommit(ctx context.Context, repoWikiPath string, u *user_model.User) (bool, string, *git.Signature, error) {
+func SignWikiCommit(ctx context.Context, repo *repo_model.Repository, u *user_model.User) (bool, string, *git.Signature, error) {
+ repoWikiPath := repo.WikiPath()
rules := signingModeFromStrings(setting.Repository.Signing.Wiki)
signingKey, sig := SigningKey(ctx, repoWikiPath)
if signingKey == "" {
@@ -201,7 +204,7 @@ Loop:
return false, "", nil, &ErrWontSign{twofa}
}
case parentSigned:
- gitRepo, err := git.OpenRepository(ctx, repoWikiPath)
+ gitRepo, err := gitrepo.OpenWikiRepository(ctx, repo)
if err != nil {
return false, "", nil, err
}
diff --git a/services/automerge/automerge.go b/services/automerge/automerge.go
index bf713c44314dd..bd427bef9f731 100644
--- a/services/automerge/automerge.go
+++ b/services/automerge/automerge.go
@@ -17,6 +17,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -111,7 +112,7 @@ func MergeScheduledPullRequest(ctx context.Context, sha string, repo *repo_model
}
func getPullRequestsByHeadSHA(ctx context.Context, sha string, repo *repo_model.Repository, filter func(*issues_model.PullRequest) bool) (map[int64]*issues_model.PullRequest, error) {
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
return nil, err
}
@@ -190,7 +191,7 @@ func handlePull(pullID int64, sha string) {
return
}
- headGitRepo, err := git.OpenRepository(ctx, pr.HeadRepo.RepoPath())
+ headGitRepo, err := gitrepo.OpenRepository(ctx, pr.HeadRepo)
if err != nil {
log.Error("OpenRepository %-v: %v", pr.HeadRepo, err)
return
@@ -246,7 +247,7 @@ func handlePull(pullID int64, sha string) {
return
}
- baseGitRepo, err = git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ baseGitRepo, err = gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
log.Error("OpenRepository %-v: %v", pr.BaseRepo, err)
return
diff --git a/services/convert/pull.go b/services/convert/pull.go
index 7eebe20426c31..6d98121ed54c4 100644
--- a/services/convert/pull.go
+++ b/services/convert/pull.go
@@ -12,6 +12,7 @@ import (
access_model "code.gitea.io/gitea/models/perm/access"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
api "code.gitea.io/gitea/modules/structs"
)
@@ -101,7 +102,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
apiPullRequest.Closed = pr.Issue.ClosedUnix.AsTimePtr()
}
- gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
log.Error("OpenRepository[%s]: %v", pr.BaseRepo.RepoPath(), err)
return nil
@@ -127,7 +128,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
}
if pr.Flow == issues_model.PullRequestFlowAGit {
- gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
log.Error("OpenRepository[%s]: %v", pr.GetGitRefName(), err)
return nil
@@ -154,7 +155,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
apiPullRequest.Head.RepoID = pr.HeadRepo.ID
apiPullRequest.Head.Repository = ToRepo(ctx, pr.HeadRepo, p)
- headGitRepo, err := git.OpenRepository(ctx, pr.HeadRepo.RepoPath())
+ headGitRepo, err := gitrepo.OpenRepository(ctx, pr.HeadRepo)
if err != nil {
log.Error("OpenRepository[%s]: %v", pr.HeadRepo.RepoPath(), err)
return nil
@@ -190,7 +191,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
}
if len(apiPullRequest.Head.Sha) == 0 && len(apiPullRequest.Head.Ref) != 0 {
- baseGitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ baseGitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
log.Error("OpenRepository[%s]: %v", pr.BaseRepo.RepoPath(), err)
return nil
diff --git a/services/doctor/misc.go b/services/doctor/misc.go
index f0b5966b5440d..9300c3a25c9c6 100644
--- a/services/doctor/misc.go
+++ b/services/doctor/misc.go
@@ -16,6 +16,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
@@ -91,7 +92,7 @@ func checkEnablePushOptions(ctx context.Context, logger log.Logger, autofix bool
if err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
numRepos++
- r, err := git.OpenRepository(ctx, repo.RepoPath())
+ r, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
return err
}
diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go
index 5a4392c66775f..7b21d9f4d2438 100644
--- a/services/migrations/gitea_uploader.go
+++ b/services/migrations/gitea_uploader.go
@@ -21,6 +21,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
base_module "code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/label"
"code.gitea.io/gitea/modules/log"
base "code.gitea.io/gitea/modules/migration"
@@ -139,7 +140,7 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
if err != nil {
return err
}
- g.gitRepo, err = git.OpenRepository(g.ctx, r.RepoPath())
+ g.gitRepo, err = gitrepo.OpenRepository(g.ctx, r)
return err
}
diff --git a/services/migrations/gitea_uploader_test.go b/services/migrations/gitea_uploader_test.go
index 4ec0361dfb467..c8102c6b8b71b 100644
--- a/services/migrations/gitea_uploader_test.go
+++ b/services/migrations/gitea_uploader_test.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
base "code.gitea.io/gitea/modules/migration"
@@ -249,7 +250,7 @@ func TestGiteaUploadUpdateGitForPullRequest(t *testing.T) {
Author: &signature,
Message: "Initial Commit",
}))
- fromGitRepo, err := git.OpenRepository(git.DefaultContext, fromRepo.RepoPath())
+ fromGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, fromRepo)
assert.NoError(t, err)
defer fromGitRepo.Close()
baseSHA, err := fromGitRepo.GetBranchCommitID(baseRef)
@@ -292,7 +293,7 @@ func TestGiteaUploadUpdateGitForPullRequest(t *testing.T) {
Author: &signature,
Message: "branch2 commit",
}))
- forkGitRepo, err := git.OpenRepository(git.DefaultContext, forkRepo.RepoPath())
+ forkGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, forkRepo)
assert.NoError(t, err)
defer forkGitRepo.Close()
forkHeadSHA, err := forkGitRepo.GetBranchCommitID(forkHeadRef)
diff --git a/services/mirror/mirror_pull.go b/services/mirror/mirror_pull.go
index 6f03e14ab08bd..3418cf90dfe38 100644
--- a/services/mirror/mirror_pull.go
+++ b/services/mirror/mirror_pull.go
@@ -13,6 +13,7 @@ import (
system_model "code.gitea.io/gitea/models/system"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -300,7 +301,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
log.Error("SyncMirrors [repo: %-v]: %v", m.Repo, err)
}
- gitRepo, err := git.OpenRepository(ctx, repoPath)
+ gitRepo, err := gitrepo.OpenRepository(ctx, m.Repo)
if err != nil {
log.Error("SyncMirrors [repo: %-v]: failed to OpenRepository: %v", m.Repo, err)
return nil, false
@@ -396,7 +397,7 @@ func runSync(ctx context.Context, m *repo_model.Mirror) ([]*mirrorSyncResult, bo
}
log.Trace("SyncMirrors [repo: %-v]: invalidating mirror branch caches...", m.Repo)
- branches, _, err := git.GetBranchesByPath(ctx, m.Repo.RepoPath(), 0, 0)
+ branches, _, err := gitrepo.GetBranchesByPath(ctx, m.Repo, 0, 0)
if err != nil {
log.Error("SyncMirrors [repo: %-v]: failed to GetBranches: %v", m.Repo, err)
return nil, false
@@ -453,7 +454,7 @@ func SyncPullMirror(ctx context.Context, repoID int64) bool {
log.Trace("SyncMirrors [repo: %-v]: no branches updated", m.Repo)
} else {
log.Trace("SyncMirrors [repo: %-v]: %d branches updated", m.Repo, len(results))
- gitRepo, err = git.OpenRepository(ctx, m.Repo.RepoPath())
+ gitRepo, err = gitrepo.OpenRepository(ctx, m.Repo)
if err != nil {
log.Error("SyncMirrors [repo: %-v]: unable to OpenRepository: %v", m.Repo, err)
return false
diff --git a/services/mirror/mirror_push.go b/services/mirror/mirror_push.go
index b117e79faca96..21ba0afeffd6e 100644
--- a/services/mirror/mirror_push.go
+++ b/services/mirror/mirror_push.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -131,7 +132,11 @@ func SyncPushMirror(ctx context.Context, mirrorID int64) bool {
func runPushSync(ctx context.Context, m *repo_model.PushMirror) error {
timeout := time.Duration(setting.Git.Timeout.Mirror) * time.Second
- performPush := func(path string) error {
+ performPush := func(repo *repo_model.Repository, isWiki bool) error {
+ path := repo.RepoPath()
+ if isWiki {
+ path = repo.WikiPath()
+ }
remoteURL, err := git.GetRemoteURL(ctx, path, m.RemoteName)
if err != nil {
log.Error("GetRemoteAddress(%s) Error %v", path, err)
@@ -141,7 +146,12 @@ func runPushSync(ctx context.Context, m *repo_model.PushMirror) error {
if setting.LFS.StartServer {
log.Trace("SyncMirrors [repo: %-v]: syncing LFS objects...", m.Repo)
- gitRepo, err := git.OpenRepository(ctx, path)
+ var gitRepo *git.Repository
+ if isWiki {
+ gitRepo, err = gitrepo.OpenWikiRepository(ctx, repo)
+ } else {
+ gitRepo, err = gitrepo.OpenRepository(ctx, repo)
+ }
if err != nil {
log.Error("OpenRepository: %v", err)
return errors.New("Unexpected error")
@@ -171,16 +181,15 @@ func runPushSync(ctx context.Context, m *repo_model.PushMirror) error {
return nil
}
- err := performPush(m.Repo.RepoPath())
+ err := performPush(m.Repo, false)
if err != nil {
return err
}
if m.Repo.HasWiki() {
- wikiPath := m.Repo.WikiPath()
- _, err := git.GetRemoteAddress(ctx, wikiPath, m.RemoteName)
+ _, err := git.GetRemoteAddress(ctx, m.Repo.WikiPath(), m.RemoteName)
if err == nil {
- err := performPush(wikiPath)
+ err := performPush(m.Repo, true)
if err != nil {
return err
}
diff --git a/services/pull/check.go b/services/pull/check.go
index ebe4c6d61b038..dd6c3ed230141 100644
--- a/services/pull/check.go
+++ b/services/pull/check.go
@@ -20,6 +20,7 @@ import (
"code.gitea.io/gitea/models/unit"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -215,7 +216,7 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
return nil, fmt.Errorf("GetFullCommitID(%s) in %s: %w", prHeadRef, pr.BaseRepo.FullName(), err)
}
- gitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
return nil, fmt.Errorf("%-v OpenRepository: %w", pr.BaseRepo, err)
}
diff --git a/services/pull/comment.go b/services/pull/comment.go
index 14fba52f1e7e3..d538b118d5bf7 100644
--- a/services/pull/comment.go
+++ b/services/pull/comment.go
@@ -9,7 +9,7 @@ import (
issues_model "code.gitea.io/gitea/models/issues"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/json"
)
@@ -17,8 +17,7 @@ import (
// isForcePush will be true if oldCommit isn't on the branch
// Commit on baseBranch will skip
func getCommitIDsFromRepo(ctx context.Context, repo *repo_model.Repository, oldCommitID, newCommitID, baseBranch string) (commitIDs []string, isForcePush bool, err error) {
- repoPath := repo.RepoPath()
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repoPath)
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return nil, false, err
}
diff --git a/services/pull/commit_status.go b/services/pull/commit_status.go
index 39d60380ff202..b73816c7eb225 100644
--- a/services/pull/commit_status.go
+++ b/services/pull/commit_status.go
@@ -11,6 +11,7 @@ import (
git_model "code.gitea.io/gitea/models/git"
issues_model "code.gitea.io/gitea/models/issues"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/structs"
@@ -116,7 +117,7 @@ func GetPullRequestCommitStatusState(ctx context.Context, pr *issues_model.PullR
}
// check if all required status checks are successful
- headGitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.HeadRepo.RepoPath())
+ headGitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.HeadRepo)
if err != nil {
return "", errors.Wrap(err, "OpenRepository")
}
diff --git a/services/pull/merge_rebase.go b/services/pull/merge_rebase.go
index a88f805ef0252..ecf376220e2af 100644
--- a/services/pull/merge_rebase.go
+++ b/services/pull/merge_rebase.go
@@ -9,6 +9,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
)
@@ -57,7 +58,7 @@ func doMergeRebaseFastForward(ctx *mergeContext) error {
}
// Original repo to read template from.
- baseGitRepo, err := git.OpenRepository(ctx, ctx.pr.BaseRepo.RepoPath())
+ baseGitRepo, err := gitrepo.OpenRepository(ctx, ctx.pr.BaseRepo)
if err != nil {
log.Error("Unable to get Git repo for rebase: %v", err)
return err
diff --git a/services/pull/merge_squash.go b/services/pull/merge_squash.go
index f52a2301d906c..197d8102dd960 100644
--- a/services/pull/merge_squash.go
+++ b/services/pull/merge_squash.go
@@ -10,6 +10,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
)
@@ -24,7 +25,7 @@ func getAuthorSignatureSquash(ctx *mergeContext) (*git.Signature, error) {
// Try to get an signature from the same user in one of the commits, as the
// poster email might be private or commits might have a different signature
// than the primary email address of the poster.
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, ctx.tmpBasePath)
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpenPath(ctx, ctx.tmpBasePath)
if err != nil {
log.Error("%-v Unable to open base repository: %v", ctx.pr, err)
return nil, err
diff --git a/services/pull/patch.go b/services/pull/patch.go
index acaff04bda474..12b79a06253d1 100644
--- a/services/pull/patch.go
+++ b/services/pull/patch.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -35,7 +36,7 @@ func DownloadDiffOrPatch(ctx context.Context, pr *issues_model.PullRequest, w io
return err
}
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.BaseRepo)
if err != nil {
return fmt.Errorf("OpenRepository: %w", err)
}
diff --git a/services/pull/pull.go b/services/pull/pull.go
index 930954bdfdfa1..e1ea4357fc5d2 100644
--- a/services/pull/pull.go
+++ b/services/pull/pull.go
@@ -23,6 +23,7 @@ import (
"code.gitea.io/gitea/modules/container"
gitea_context "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
@@ -62,7 +63,7 @@ func NewPullRequest(ctx context.Context, repo *repo_model.Repository, issue *iss
assigneeCommentMap := make(map[int64]*issues_model.Comment)
// add first push codes comment
- baseGitRepo, err := git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ baseGitRepo, err := gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
return err
}
@@ -269,9 +270,9 @@ func checkForInvalidation(ctx context.Context, requests issues_model.PullRequest
if err != nil {
return fmt.Errorf("GetRepositoryByIDCtx: %w", err)
}
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
- return fmt.Errorf("git.OpenRepository: %w", err)
+ return fmt.Errorf("gitrepo.OpenRepository: %w", err)
}
go func() {
// FIXME: graceful: We need to tell the manager we're doing something...
@@ -614,7 +615,7 @@ func CloseBranchPulls(ctx context.Context, doer *user_model.User, repoID int64,
// CloseRepoBranchesPulls close all pull requests which head branches are in the given repository, but only whose base repo is not in the given repository
func CloseRepoBranchesPulls(ctx context.Context, doer *user_model.User, repo *repo_model.Repository) error {
- branches, _, err := git.GetBranchesByPath(ctx, repo.RepoPath(), 0, 0)
+ branches, _, err := gitrepo.GetBranchesByPath(ctx, repo, 0, 0)
if err != nil {
return err
}
@@ -671,7 +672,7 @@ func GetSquashMergeCommitMessages(ctx context.Context, pr *issues_model.PullRequ
}
}
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.HeadRepo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.HeadRepo)
if err != nil {
log.Error("Unable to open head repository: Error: %v", err)
return ""
@@ -845,7 +846,7 @@ func GetIssuesAllCommitStatus(ctx context.Context, issues issues_model.IssueList
}
gitRepo, ok := gitRepos[issue.RepoID]
if !ok {
- gitRepo, err = git.OpenRepository(ctx, issue.Repo.RepoPath())
+ gitRepo, err = gitrepo.OpenRepository(ctx, issue.Repo)
if err != nil {
log.Error("Cannot open git repository %-v for issue #%d[%d]. Error: %v", issue.Repo, issue.Index, issue.ID, err)
continue
@@ -882,7 +883,7 @@ func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, br
if err = pr.LoadBaseRepo(ctx); err != nil {
return false, err
}
- baseGitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
+ baseGitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.BaseRepo)
if err != nil {
return false, err
}
@@ -902,7 +903,7 @@ func IsHeadEqualWithBranch(ctx context.Context, pr *issues_model.PullRequest, br
} else {
var closer io.Closer
- headGitRepo, closer, err = git.RepositoryFromContextOrOpen(ctx, pr.HeadRepo.RepoPath())
+ headGitRepo, closer, err = gitrepo.RepositoryFromContextOrOpen(ctx, pr.HeadRepo)
if err != nil {
return false, err
}
diff --git a/services/pull/pull_test.go b/services/pull/pull_test.go
index d63227a7d5e9c..787910bf760f3 100644
--- a/services/pull/pull_test.go
+++ b/services/pull/pull_test.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models/unit"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"github.com/stretchr/testify/assert"
)
@@ -41,7 +42,7 @@ func TestPullRequest_GetDefaultMergeMessage_InternalTracker(t *testing.T) {
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2})
assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
- gitRepo, err := git.OpenRepository(git.DefaultContext, pr.BaseRepo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, pr.BaseRepo)
assert.NoError(t, err)
defer gitRepo.Close()
@@ -71,7 +72,7 @@ func TestPullRequest_GetDefaultMergeMessage_ExternalTracker(t *testing.T) {
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 2, BaseRepo: baseRepo})
assert.NoError(t, pr.LoadBaseRepo(db.DefaultContext))
- gitRepo, err := git.OpenRepository(git.DefaultContext, pr.BaseRepo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, pr.BaseRepo)
assert.NoError(t, err)
defer gitRepo.Close()
diff --git a/services/pull/review.go b/services/pull/review.go
index e48f3801547dd..d4ea97561253e 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -16,6 +16,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
@@ -170,7 +171,7 @@ func createCodeComment(ctx context.Context, doer *user_model.User, repo *repo_mo
if err := pr.LoadBaseRepo(ctx); err != nil {
return nil, fmt.Errorf("LoadBaseRepo: %w", err)
}
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, pr.BaseRepo)
if err != nil {
return nil, fmt.Errorf("RepositoryFromContextOrOpen: %w", err)
}
diff --git a/services/release/release.go b/services/release/release.go
index f17682ae0f8f6..c1d13126f0b3b 100644
--- a/services/release/release.go
+++ b/services/release/release.go
@@ -16,6 +16,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/repository"
@@ -168,7 +169,7 @@ func CreateNewTag(ctx context.Context, doer *user_model.User, repo *repo_model.R
}
}
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return err
}
diff --git a/services/release/release_test.go b/services/release/release_test.go
index 4b57262981b55..3d0681f1e1710 100644
--- a/services/release/release_test.go
+++ b/services/release/release_test.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/services/attachment"
_ "code.gitea.io/gitea/models/actions"
@@ -29,9 +30,8 @@ func TestRelease_Create(t *testing.T) {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
- repoPath := repo_model.RepoPath(user.Name, repo.Name)
- gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath)
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
assert.NoError(t, err)
defer gitRepo.Close()
@@ -135,9 +135,8 @@ func TestRelease_Update(t *testing.T) {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
- repoPath := repo_model.RepoPath(user.Name, repo.Name)
- gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath)
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
assert.NoError(t, err)
defer gitRepo.Close()
@@ -278,9 +277,8 @@ func TestRelease_createTag(t *testing.T) {
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
- repoPath := repo_model.RepoPath(user.Name, repo.Name)
- gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath)
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
assert.NoError(t, err)
defer gitRepo.Close()
diff --git a/services/repository/adopt.go b/services/repository/adopt.go
index 2e9b0c822f957..bfb965063f33e 100644
--- a/services/repository/adopt.go
+++ b/services/repository/adopt.go
@@ -17,6 +17,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/container"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
@@ -126,7 +127,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
repo.IsEmpty = false
// Don't bother looking this repo in the context it won't be there
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
return fmt.Errorf("openRepository: %w", err)
}
diff --git a/services/repository/archiver/archiver.go b/services/repository/archiver/archiver.go
index c2ad4d484a69e..01c58f0ce402a 100644
--- a/services/repository/archiver/archiver.go
+++ b/services/repository/archiver/archiver.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -209,7 +210,7 @@ func doArchive(ctx context.Context, r *ArchiveRequest) (*repo_model.RepoArchiver
return nil, fmt.Errorf("archiver.LoadRepo failed: %w", err)
}
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
return nil, err
}
diff --git a/services/repository/branch.go b/services/repository/branch.go
index c1e6625ed4761..e2e50297afacd 100644
--- a/services/repository/branch.go
+++ b/services/repository/branch.go
@@ -17,6 +17,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/queue"
@@ -160,7 +161,7 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g
if pr.HasMerged {
baseGitRepo, ok := repoIDToGitRepo[pr.BaseRepoID]
if !ok {
- baseGitRepo, err = git.OpenRepository(ctx, pr.BaseRepo.RepoPath())
+ baseGitRepo, err = gitrepo.OpenRepository(ctx, pr.BaseRepo)
if err != nil {
return nil, fmt.Errorf("OpenRepository: %v", err)
}
@@ -190,13 +191,9 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g
}, nil
}
-func GetBranchCommitID(ctx context.Context, repo *repo_model.Repository, branch string) (string, error) {
- return git.GetBranchCommitID(ctx, repo.RepoPath(), branch)
-}
-
// checkBranchName validates branch name with existing repository branches
func checkBranchName(ctx context.Context, repo *repo_model.Repository, name string) error {
- _, err := git.WalkReferences(ctx, repo.RepoPath(), func(_, refName string) error {
+ _, err := gitrepo.WalkReferences(ctx, repo, func(_, refName string) error {
branchRefName := strings.TrimPrefix(refName, git.BranchPrefix)
switch {
case branchRefName == name:
diff --git a/services/repository/create.go b/services/repository/create.go
index 0e89573343e66..a648c0d816787 100644
--- a/services/repository/create.go
+++ b/services/repository/create.go
@@ -16,6 +16,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/options"
repo_module "code.gitea.io/gitea/modules/repository"
@@ -175,7 +176,7 @@ func initRepository(ctx context.Context, repoPath string, u *user_model.User, re
if len(opts.DefaultBranch) > 0 {
repo.DefaultBranch = opts.DefaultBranch
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
return fmt.Errorf("openRepository: %w", err)
}
diff --git a/services/repository/files/commit.go b/services/repository/files/commit.go
index 048e41e6fdd38..16a15e06a7ccc 100644
--- a/services/repository/files/commit.go
+++ b/services/repository/files/commit.go
@@ -12,6 +12,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/services/automerge"
)
@@ -23,7 +24,7 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato
repoPath := repo.RepoPath()
// confirm that commit is exist
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return fmt.Errorf("OpenRepository[%s]: %w", repoPath, err)
}
diff --git a/services/repository/files/content.go b/services/repository/files/content.go
index 30d62fbcdf7c0..c278d7f8355cc 100644
--- a/services/repository/files/content.go
+++ b/services/repository/files/content.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
@@ -58,7 +59,7 @@ func GetContentsOrList(ctx context.Context, repo *repo_model.Repository, treePat
}
treePath = cleanTreePath
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return nil, err
}
@@ -133,7 +134,7 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref
}
treePath = cleanTreePath
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return nil, err
}
diff --git a/services/repository/files/content_test.go b/services/repository/files/content_test.go
index 3ad3e3ab98b2a..d50847789ace1 100644
--- a/services/repository/files/content_test.go
+++ b/services/repository/files/content_test.go
@@ -6,10 +6,9 @@ package files
import (
"testing"
- repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/contexttest"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
api "code.gitea.io/gitea/modules/structs"
_ "code.gitea.io/gitea/models/actions"
@@ -235,7 +234,7 @@ func TestGetBlobBySHA(t *testing.T) {
ctx.SetParams(":id", "1")
ctx.SetParams(":sha", sha)
- gitRepo, err := git.OpenRepository(ctx, repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name))
+ gitRepo, err := gitrepo.OpenRepository(ctx, ctx.Repo.Repository)
if err != nil {
t.Fail()
}
diff --git a/services/repository/files/file_test.go b/services/repository/files/file_test.go
index 4e67ad1410856..675ddbddb3e8e 100644
--- a/services/repository/files/file_test.go
+++ b/services/repository/files/file_test.go
@@ -8,7 +8,7 @@ import (
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/contexttest"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -109,7 +109,7 @@ func TestGetFileResponseFromCommit(t *testing.T) {
repo := ctx.Repo.Repository
branch := repo.DefaultBranch
treePath := "README.md"
- gitRepo, _ := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, _ := gitrepo.OpenRepository(ctx, repo)
defer gitRepo.Close()
commit, _ := gitRepo.GetBranchCommit(branch)
expectedFileResponse := getExpectedFileResponse()
diff --git a/services/repository/files/patch.go b/services/repository/files/patch.go
index 14f8caaa8cf73..f6d5643dc91ce 100644
--- a/services/repository/files/patch.go
+++ b/services/repository/files/patch.go
@@ -13,6 +13,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/structs"
asymkey_service "code.gitea.io/gitea/services/asymkey"
@@ -42,7 +43,7 @@ func (opts *ApplyDiffPatchOptions) Validate(ctx context.Context, repo *repo_mode
opts.NewBranch = opts.OldBranch
}
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return err
}
diff --git a/services/repository/files/update.go b/services/repository/files/update.go
index 1892043304e29..f223daf3a9fdf 100644
--- a/services/repository/files/update.go
+++ b/services/repository/files/update.go
@@ -16,6 +16,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -78,7 +79,7 @@ func ChangeRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
opts.NewBranch = opts.OldBranch
}
- gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, repo.RepoPath())
+ gitRepo, closer, err := gitrepo.RepositoryFromContextOrOpen(ctx, repo)
if err != nil {
return nil, err
}
diff --git a/services/repository/fork.go b/services/repository/fork.go
index a8ff2717b0688..f9c13a109eba7 100644
--- a/services/repository/fork.go
+++ b/services/repository/fork.go
@@ -14,6 +14,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
repo_module "code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/structs"
@@ -167,7 +168,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
return fmt.Errorf("createDelegateHooks: %w", err)
}
- gitRepo, err := git.OpenRepository(txCtx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(txCtx, repo)
if err != nil {
return fmt.Errorf("OpenRepository: %w", err)
}
@@ -190,7 +191,7 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
log.Error("Copy language stat from oldRepo failed: %v", err)
}
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
log.Error("Open created git repository failed: %v", err)
} else {
diff --git a/services/repository/hooks.go b/services/repository/hooks.go
index 7b82f36b43fdd..97e9e290a3e3d 100644
--- a/services/repository/hooks.go
+++ b/services/repository/hooks.go
@@ -10,7 +10,7 @@ import (
"code.gitea.io/gitea/models/db"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/webhook"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/log"
repo_module "code.gitea.io/gitea/modules/repository"
@@ -52,13 +52,13 @@ func SyncRepositoryHooks(ctx context.Context) error {
// GenerateGitHooks generates git hooks from a template repository
func GenerateGitHooks(ctx context.Context, templateRepo, generateRepo *repo_model.Repository) error {
- generateGitRepo, err := git.OpenRepository(ctx, generateRepo.RepoPath())
+ generateGitRepo, err := gitrepo.OpenRepository(ctx, generateRepo)
if err != nil {
return err
}
defer generateGitRepo.Close()
- templateGitRepo, err := git.OpenRepository(ctx, templateRepo.RepoPath())
+ templateGitRepo, err := gitrepo.OpenRepository(ctx, templateRepo)
if err != nil {
return err
}
diff --git a/services/repository/lfs.go b/services/repository/lfs.go
index b437fda15d578..4504f796bd2f0 100644
--- a/services/repository/lfs.go
+++ b/services/repository/lfs.go
@@ -12,6 +12,7 @@ import (
git_model "code.gitea.io/gitea/models/git"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -69,7 +70,7 @@ func GarbageCollectLFSMetaObjectsForRepo(ctx context.Context, repo *repo_model.R
}
}()
- gitRepo, err := git.OpenRepository(ctx, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
log.Error("Unable to open git repository %-v: %v", repo, err)
return err
diff --git a/services/repository/push.go b/services/repository/push.go
index e86eebde8110b..bedcf6f2524b5 100644
--- a/services/repository/push.go
+++ b/services/repository/push.go
@@ -16,6 +16,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/cache"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -86,17 +87,15 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
return fmt.Errorf("GetRepositoryByOwnerAndName failed: %w", err)
}
- repoPath := repo.RepoPath()
-
- gitRepo, err := git.OpenRepository(ctx, repoPath)
+ gitRepo, err := gitrepo.OpenRepository(ctx, repo)
if err != nil {
- return fmt.Errorf("OpenRepository[%s]: %w", repoPath, err)
+ return fmt.Errorf("OpenRepository[%s]: %w", repo.FullName(), err)
}
defer gitRepo.Close()
objectFormat, err := gitRepo.GetObjectFormat()
if err != nil {
- return fmt.Errorf("unknown repository ObjectFormat [%s]: %w", repoPath, err)
+ return fmt.Errorf("unknown repository ObjectFormat [%s]: %w", repo.FullName(), err)
}
if err = repo_module.UpdateRepoSize(ctx, repo); err != nil {
diff --git a/services/wiki/wiki.go b/services/wiki/wiki.go
index ce54a00da73b4..50d52d3140fe8 100644
--- a/services/wiki/wiki.go
+++ b/services/wiki/wiki.go
@@ -191,7 +191,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
committer := doer.NewGitSig()
- sign, signingKey, signer, _ := asymkey_service.SignWikiCommit(ctx, repo.WikiPath(), doer)
+ sign, signingKey, signer, _ := asymkey_service.SignWikiCommit(ctx, repo, doer)
if sign {
commitTreeOpts.KeyID = signingKey
if repo.GetTrustModel() == repo_model.CommitterTrustModel || repo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel {
@@ -314,7 +314,7 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
committer := doer.NewGitSig()
- sign, signingKey, signer, _ := asymkey_service.SignWikiCommit(ctx, repo.WikiPath(), doer)
+ sign, signingKey, signer, _ := asymkey_service.SignWikiCommit(ctx, repo, doer)
if sign {
commitTreeOpts.KeyID = signingKey
if repo.GetTrustModel() == repo_model.CommitterTrustModel || repo.GetTrustModel() == repo_model.CollaboratorCommitterTrustModel {
diff --git a/services/wiki/wiki_test.go b/services/wiki/wiki_test.go
index 277fa086ac13c..59c77060f2c27 100644
--- a/services/wiki/wiki_test.go
+++ b/services/wiki/wiki_test.go
@@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
_ "code.gitea.io/gitea/models/actions"
@@ -164,7 +165,7 @@ func TestRepository_AddWikiPage(t *testing.T) {
webPath := UserTitleToWebPath("", userTitle)
assert.NoError(t, AddWikiPage(git.DefaultContext, doer, repo, webPath, wikiContent, commitMsg))
// Now need to show that the page has been added:
- gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
+ gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo)
if !assert.NoError(t, err) {
return
}
@@ -212,7 +213,7 @@ func TestRepository_EditWikiPage(t *testing.T) {
assert.NoError(t, EditWikiPage(git.DefaultContext, doer, repo, "Home", webPath, newWikiContent, commitMsg))
// Now need to show that the page has been added:
- gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
+ gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo)
assert.NoError(t, err)
masterTree, err := gitRepo.GetTree(DefaultBranch)
assert.NoError(t, err)
@@ -236,7 +237,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
assert.NoError(t, DeleteWikiPage(git.DefaultContext, doer, repo, "Home"))
// Now need to show that the page has been added:
- gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
+ gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo)
if !assert.NoError(t, err) {
return
}
@@ -251,7 +252,7 @@ func TestRepository_DeleteWikiPage(t *testing.T) {
func TestPrepareWikiFileName(t *testing.T) {
unittest.PrepareTestEnv(t)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
- gitRepo, err := git.OpenRepository(git.DefaultContext, repo.WikiPath())
+ gitRepo, err := gitrepo.OpenWikiRepository(git.DefaultContext, repo)
if !assert.NoError(t, err) {
return
}
diff --git a/tests/integration/api_packages_cargo_test.go b/tests/integration/api_packages_cargo_test.go
index 6b8154af457a6..c0705e0de5cf4 100644
--- a/tests/integration/api_packages_cargo_test.go
+++ b/tests/integration/api_packages_cargo_test.go
@@ -18,7 +18,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/json"
cargo_module "code.gitea.io/gitea/modules/packages/cargo"
"code.gitea.io/gitea/modules/setting"
@@ -78,7 +78,7 @@ func testPackageCargo(t *testing.T, _ *neturl.URL) {
assert.NoError(t, err)
readGitContent := func(t *testing.T, path string) string {
- gitRepo, err := git.OpenRepository(db.DefaultContext, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(db.DefaultContext, repo)
assert.NoError(t, err)
defer gitRepo.Close()
diff --git a/tests/integration/api_releases_test.go b/tests/integration/api_releases_test.go
index e070bd05b5a42..5b1ab76ce97b3 100644
--- a/tests/integration/api_releases_test.go
+++ b/tests/integration/api_releases_test.go
@@ -18,6 +18,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/tests"
@@ -109,7 +110,7 @@ func TestAPICreateAndUpdateRelease(t *testing.T) {
session := loginUser(t, owner.LowerName)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
- gitRepo, err := git.OpenRepository(git.DefaultContext, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
assert.NoError(t, err)
defer gitRepo.Close()
@@ -172,7 +173,7 @@ func TestAPICreateReleaseToDefaultBranchOnExistingTag(t *testing.T) {
session := loginUser(t, owner.LowerName)
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
- gitRepo, err := git.OpenRepository(git.DefaultContext, repo.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
assert.NoError(t, err)
defer gitRepo.Close()
diff --git a/tests/integration/api_repo_file_create_test.go b/tests/integration/api_repo_file_create_test.go
index f78909eb32582..0d192a1fe84ac 100644
--- a/tests/integration/api_repo_file_create_test.go
+++ b/tests/integration/api_repo_file_create_test.go
@@ -18,7 +18,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -167,7 +167,7 @@ func TestAPICreateFile(t *testing.T) {
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &createFileOptions).
AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusCreated)
- gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath())
+ gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1)
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
expectedFileResponse := getExpectedFileResponseForCreate("user2/repo1", commitID, treePath, latestCommit.ID.String())
@@ -285,7 +285,7 @@ func TestAPICreateFile(t *testing.T) {
AddTokenAuth(token2)
resp = MakeRequest(t, req, http.StatusCreated)
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user2", Name: "empty-repo"}) // public repo
- gitRepo, _ := git.OpenRepository(stdCtx.Background(), emptyRepo.RepoPath())
+ gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), emptyRepo)
commitID, _ := gitRepo.GetBranchCommitID(createFileOptions.NewBranchName)
latestCommit, _ := gitRepo.GetCommitByPath(treePath)
expectedFileResponse := getExpectedFileResponseForCreate("user2/empty-repo", commitID, treePath, latestCommit.ID.String())
diff --git a/tests/integration/api_repo_file_update_test.go b/tests/integration/api_repo_file_update_test.go
index 7e88f6cd80360..195a1090c7c03 100644
--- a/tests/integration/api_repo_file_update_test.go
+++ b/tests/integration/api_repo_file_update_test.go
@@ -17,7 +17,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -135,7 +135,7 @@ func TestAPIUpdateFile(t *testing.T) {
req := NewRequestWithJSON(t, "PUT", fmt.Sprintf("/api/v1/repos/%s/%s/contents/%s", user2.Name, repo1.Name, treePath), &updateFileOptions).
AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusOK)
- gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath())
+ gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1)
commitID, _ := gitRepo.GetBranchCommitID(updateFileOptions.NewBranchName)
lasCommit, _ := gitRepo.GetCommitByPath(treePath)
expectedFileResponse := getExpectedFileResponseForUpdate(commitID, treePath, lasCommit.ID.String())
diff --git a/tests/integration/api_repo_files_change_test.go b/tests/integration/api_repo_files_change_test.go
index d500d48b36091..ab5cf19a9c88d 100644
--- a/tests/integration/api_repo_files_change_test.go
+++ b/tests/integration/api_repo_files_change_test.go
@@ -16,7 +16,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
- "code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
@@ -96,7 +96,7 @@ func TestAPIChangeFiles(t *testing.T) {
req := NewRequestWithJSON(t, "POST", fmt.Sprintf("/api/v1/repos/%s/%s/contents", user2.Name, repo1.Name), &changeFilesOptions).
AddTokenAuth(token2)
resp := MakeRequest(t, req, http.StatusCreated)
- gitRepo, _ := git.OpenRepository(stdCtx.Background(), repo1.RepoPath())
+ gitRepo, _ := gitrepo.OpenRepository(stdCtx.Background(), repo1)
commitID, _ := gitRepo.GetBranchCommitID(changeFilesOptions.NewBranchName)
createLasCommit, _ := gitRepo.GetCommitByPath(createTreePath)
updateLastCommit, _ := gitRepo.GetCommitByPath(updateTreePath)
diff --git a/tests/integration/api_repo_get_contents_list_test.go b/tests/integration/api_repo_get_contents_list_test.go
index 86313f5e3b209..1ba74490a30da 100644
--- a/tests/integration/api_repo_get_contents_list_test.go
+++ b/tests/integration/api_repo_get_contents_list_test.go
@@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
repo_service "code.gitea.io/gitea/services/repository"
@@ -71,7 +72,7 @@ func testAPIGetContentsList(t *testing.T, u *url.URL) {
token4 := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
// Get the commit ID of the default branch
- gitRepo, err := git.OpenRepository(git.DefaultContext, repo1.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1)
assert.NoError(t, err)
defer gitRepo.Close()
diff --git a/tests/integration/api_repo_get_contents_test.go b/tests/integration/api_repo_get_contents_test.go
index ffbdfcb0fab81..68a8608117208 100644
--- a/tests/integration/api_repo_get_contents_test.go
+++ b/tests/integration/api_repo_get_contents_test.go
@@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
repo_service "code.gitea.io/gitea/services/repository"
@@ -73,7 +74,7 @@ func testAPIGetContents(t *testing.T, u *url.URL) {
token4 := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeReadRepository)
// Get the commit ID of the default branch
- gitRepo, err := git.OpenRepository(git.DefaultContext, repo1.RepoPath())
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1)
assert.NoError(t, err)
defer gitRepo.Close()
diff --git a/tests/integration/api_repo_git_tags_test.go b/tests/integration/api_repo_git_tags_test.go
index 2e8510ab1b3ae..937f6a829c2cc 100644
--- a/tests/integration/api_repo_git_tags_test.go
+++ b/tests/integration/api_repo_git_tags_test.go
@@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/tests"
@@ -32,7 +33,7 @@ func TestAPIGitTags(t *testing.T) {
_ = git.NewCommand(git.DefaultContext, "config", "user.name").AddDynamicArguments(user.Name).Run(&git.RunOpts{Dir: repo.RepoPath()})
_ = git.NewCommand(git.DefaultContext, "config", "user.email").AddDynamicArguments(user.Email).Run(&git.RunOpts{Dir: repo.RepoPath()})
- gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
+ gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo)
defer gitRepo.Close()
commit, _ := gitRepo.GetBranchCommit("master")
diff --git a/tests/integration/mirror_pull_test.go b/tests/integration/mirror_pull_test.go
index 1e0edd9a2dd07..2e71b80fbb5db 100644
--- a/tests/integration/mirror_pull_test.go
+++ b/tests/integration/mirror_pull_test.go
@@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/repository"
mirror_service "code.gitea.io/gitea/services/mirror"
@@ -54,7 +55,7 @@ func TestMirrorPull(t *testing.T) {
mirror, err := repository.MigrateRepositoryGitData(ctx, user, mirrorRepo, opts, nil)
assert.NoError(t, err)
- gitRepo, err := git.OpenRepository(git.DefaultContext, repoPath)
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo)
assert.NoError(t, err)
defer gitRepo.Close()
diff --git a/tests/integration/mirror_push_test.go b/tests/integration/mirror_push_test.go
index c6f0c856163bd..3dc719593c306 100644
--- a/tests/integration/mirror_push_test.go
+++ b/tests/integration/mirror_push_test.go
@@ -17,6 +17,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
gitea_context "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/migrations"
mirror_service "code.gitea.io/gitea/services/mirror"
@@ -55,14 +56,14 @@ func testMirrorPush(t *testing.T, u *url.URL) {
ok := mirror_service.SyncPushMirror(context.Background(), mirrors[0].ID)
assert.True(t, ok)
- srcGitRepo, err := git.OpenRepository(git.DefaultContext, srcRepo.RepoPath())
+ srcGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, srcRepo)
assert.NoError(t, err)
defer srcGitRepo.Close()
srcCommit, err := srcGitRepo.GetBranchCommit("master")
assert.NoError(t, err)
- mirrorGitRepo, err := git.OpenRepository(git.DefaultContext, mirrorRepo.RepoPath())
+ mirrorGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, mirrorRepo)
assert.NoError(t, err)
defer mirrorGitRepo.Close()
diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go
index 2aa6742a56ac0..fcd7fecd52dd5 100644
--- a/tests/integration/pull_merge_test.go
+++ b/tests/integration/pull_merge_test.go
@@ -25,6 +25,7 @@ import (
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/translation"
@@ -255,7 +256,7 @@ func TestCantMergeConflict(t *testing.T) {
BaseBranch: "base",
})
- gitRepo, err := git.OpenRepository(git.DefaultContext, repo_model.RepoPath(user1.Name, repo1.Name))
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1)
assert.NoError(t, err)
err = pull.Merge(context.Background(), pr, user1, gitRepo, repo_model.MergeStyleMerge, "", "CONFLICT", false)
@@ -348,7 +349,7 @@ func TestCantMergeUnrelated(t *testing.T) {
session.MakeRequest(t, req, http.StatusCreated)
// Now this PR could be marked conflict - or at least a race may occur - so drop down to pure code at this point...
- gitRepo, err := git.OpenRepository(git.DefaultContext, path)
+ gitRepo, err := gitrepo.OpenRepository(git.DefaultContext, repo1)
assert.NoError(t, err)
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{
HeadRepoID: repo1.ID,
diff --git a/tests/integration/repofiles_change_test.go b/tests/integration/repofiles_change_test.go
index e0edf07299b50..19fbd1754cc2f 100644
--- a/tests/integration/repofiles_change_test.go
+++ b/tests/integration/repofiles_change_test.go
@@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/contexttest"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
files_service "code.gitea.io/gitea/services/repository/files"
@@ -262,7 +263,7 @@ func TestChangeRepoFilesForCreate(t *testing.T) {
// asserts
assert.NoError(t, err)
- gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
+ gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo)
defer gitRepo.Close()
commitID, _ := gitRepo.GetBranchCommitID(opts.NewBranch)
@@ -299,7 +300,7 @@ func TestChangeRepoFilesForUpdate(t *testing.T) {
// asserts
assert.NoError(t, err)
- gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
+ gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo)
defer gitRepo.Close()
commit, _ := gitRepo.GetBranchCommit(opts.NewBranch)
@@ -335,7 +336,7 @@ func TestChangeRepoFilesForUpdateWithFileMove(t *testing.T) {
// asserts
assert.NoError(t, err)
- gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
+ gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo)
defer gitRepo.Close()
commit, _ := gitRepo.GetBranchCommit(opts.NewBranch)
@@ -386,7 +387,7 @@ func TestChangeRepoFilesWithoutBranchNames(t *testing.T) {
// asserts
assert.NoError(t, err)
- gitRepo, _ := git.OpenRepository(git.DefaultContext, repo.RepoPath())
+ gitRepo, _ := gitrepo.OpenRepository(git.DefaultContext, repo)
defer gitRepo.Close()
commit, _ := gitRepo.GetBranchCommit(repo.DefaultBranch)
From 61f8ca4906c4c51f9e7e9598417a9674556e670a Mon Sep 17 00:00:00 2001
From: 6543 <6543@obermui.de>
Date: Sun, 28 Jan 2024 00:20:17 +0100
Subject: [PATCH 13/17] Add screenshot for "Profile Readmes" to docs (#28964)
introduced in #23260 ... the docs still looks to empty:
https://docs.gitea.com/usage/profile-readme
this changes it :)
---
docs/content/usage/profile-readme.en-us.md | 4 ++++
docs/content/usage/profile-readme.png | Bin 0 -> 33680 bytes
2 files changed, 4 insertions(+)
create mode 100644 docs/content/usage/profile-readme.png
diff --git a/docs/content/usage/profile-readme.en-us.md b/docs/content/usage/profile-readme.en-us.md
index 339176f7d4a7f..fe42fa2723f16 100644
--- a/docs/content/usage/profile-readme.en-us.md
+++ b/docs/content/usage/profile-readme.en-us.md
@@ -19,3 +19,7 @@ To display a Markdown file in your Gitea user or organization profile page, crea
Gitea will automatically display the contents of the file on your profile, in a new "Overview" above your repositories.
Making the `.profile` repository private will hide the Profile README.
+
+Example of user with `.profile/README.md`:
+
+![profile readme screenshot](./profile-readme.png)
diff --git a/docs/content/usage/profile-readme.png b/docs/content/usage/profile-readme.png
new file mode 100644
index 0000000000000000000000000000000000000000..f8043ad02af3bf13d68b927c3b431b123236c5e6
GIT binary patch
literal 33680
zcmc%wbx>SS^fw3(NeCW-OGqFDNYKG8xCD0@eDEM41oweJa18{P;33%H4uiY9li=<)
z%na=0`+J_Z-mTiIt*zRs{cEPXPao^kr*D7mx#8-nas;^4xBvivKtWzc699M$0{|Xv
zVn0Urd)f3T2?1ppo%#$(4G0I_4(IJibeM(^Iedl-v->{bT=LBEw)sH>~1
zsHjxzK0rZ$A&OTR&ei(*`a4h%z8_i*(Dn6oOMBb1fDRoU-G?10j(79e!-Gm}>+`@a
z5CAY13uuOwV2kH~pxaj5#bTCGBPVGD_q=SZqcdoB8rkcVn;_uK)qBY
zZZS$SY$aK0dHWbGUa>ORAP2YdhBA||QSimZMP2(~d1v0cz7{fHn>QAxFdfdO}S
z_tDWYcVp$6${IdpFF_I8f`S4o3u_vhSNh(m@87?7Dz*s8(k_AxMta+QR8cawc5eC|
z?cm_>#I(`XFD$-s$Vx>FoYq|h8_b4iR5f(^l@9Q|!A?s2;pgL>o0TEyWBl1#Oqg4&
zCdEneTZ2ccv6rumLzEr|kKWAeLU4={NKuMKSqu0fTH2??#t|arnE7zL;S}&AKitYy
zTHGSj{E6PT&meh!b+NUTVa+&mwO3@uUd>!)IayVGK`vHd`7LJdG5xE1TCRyaHhSi~
zVxQwH-r4@1tI#a0>El;)6p*pfx9}Fl#rd5Y7QgXOxpd9JT9YJ?-Epk)&6vn6&S>Ha(=BVcuUucZuu@ys
zuXQ&hsT!NZHPVReVS6HWYz)VH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(kQ;wsf~`0hGH>lwI?cM<=C
z2PE9v&86unX^YmtIkzg?`zEa1^Q#97rd;_B7P3AkLaWMq#JEbRZSI3$)RG%IDT{-(cw@tqe
zsq%eHa7MYA4-mY?16NSsae+hea29x+>!++(LS}r1uNXXZ#&bM`^n?G-=VPLdn>XT~
U60S7hb&5b)K|{V&*2Mom0nOr+O8@`>
literal 0
HcmV?d00001
From d9b3849454e04c1f498c12e29b8c19660cbae328 Mon Sep 17 00:00:00 2001
From: wackbyte
Date: Sun, 28 Jan 2024 07:36:44 -0500
Subject: [PATCH 14/17] Fix inconsistent naming of OAuth 2.0 `ENABLE` setting
(#28951)
Renames it to `ENABLED` to be consistent with other settings and
deprecates it.
I believe this change is necessary because other setting groups such as
`attachment`, `cors`, `mailer`, etc. have an `ENABLED` setting, but
`oauth2` is the only one with an `ENABLE` setting, which could cause
confusion for users.
This is no longer a breaking change because `ENABLE` has been set as
deprecated and as an alias to `ENABLED`.
---
custom/conf/app.example.ini | 2 +-
.../config-cheat-sheet.en-us.md | 2 +-
.../config-cheat-sheet.zh-cn.md | 2 +-
modules/setting/oauth2.go | 19 +++++++++++++------
routers/web/user/setting/applications.go | 4 ++--
routers/web/web.go | 10 +++++-----
6 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini
index b0875123b7b8b..7032e709dbc04 100644
--- a/custom/conf/app.example.ini
+++ b/custom/conf/app.example.ini
@@ -524,7 +524,7 @@ INTERNAL_TOKEN=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Enables OAuth2 provider
-ENABLE = true
+ENABLED = true
;;
;; Algorithm used to sign OAuth2 tokens. Valid values: HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512, EdDSA
;JWT_SIGNING_ALGORITHM = RS256
diff --git a/docs/content/administration/config-cheat-sheet.en-us.md b/docs/content/administration/config-cheat-sheet.en-us.md
index eb9b8d1ae9a43..33732d080bff5 100644
--- a/docs/content/administration/config-cheat-sheet.en-us.md
+++ b/docs/content/administration/config-cheat-sheet.en-us.md
@@ -1107,7 +1107,7 @@ This section only does "set" config, a removed config key from this section won'
## OAuth2 (`oauth2`)
-- `ENABLE`: **true**: Enables OAuth2 provider.
+- `ENABLED`: **true**: Enables OAuth2 provider.
- `ACCESS_TOKEN_EXPIRATION_TIME`: **3600**: Lifetime of an OAuth2 access token in seconds
- `REFRESH_TOKEN_EXPIRATION_TIME`: **730**: Lifetime of an OAuth2 refresh token in hours
- `INVALIDATE_REFRESH_TOKENS`: **false**: Check if refresh token has already been used
diff --git a/docs/content/administration/config-cheat-sheet.zh-cn.md b/docs/content/administration/config-cheat-sheet.zh-cn.md
index 415cba14edced..2cee70daabe98 100644
--- a/docs/content/administration/config-cheat-sheet.zh-cn.md
+++ b/docs/content/administration/config-cheat-sheet.zh-cn.md
@@ -1043,7 +1043,7 @@ Gitea 创建以下非唯一队列:
## OAuth2 (`oauth2`)
-- `ENABLE`: **true**:启用OAuth2提供者。
+- `ENABLED`: **true**:启用OAuth2提供者。
- `ACCESS_TOKEN_EXPIRATION_TIME`:**3600**:OAuth2访问令牌的生命周期,以秒为单位。
- `REFRESH_TOKEN_EXPIRATION_TIME`:**730**:OAuth2刷新令牌的生命周期,以小时为单位。
- `INVALIDATE_REFRESH_TOKENS`:**false**:检查刷新令牌是否已被使用。
diff --git a/modules/setting/oauth2.go b/modules/setting/oauth2.go
index 10cadf03dd32b..0d15e91ef0d6c 100644
--- a/modules/setting/oauth2.go
+++ b/modules/setting/oauth2.go
@@ -93,7 +93,7 @@ func parseScopes(sec ConfigSection, name string) []string {
}
var OAuth2 = struct {
- Enable bool
+ Enabled bool
AccessTokenExpirationTime int64
RefreshTokenExpirationTime int64
InvalidateRefreshTokens bool
@@ -103,7 +103,7 @@ var OAuth2 = struct {
MaxTokenLength int
DefaultApplications []string
}{
- Enable: true,
+ Enabled: true,
AccessTokenExpirationTime: 3600,
RefreshTokenExpirationTime: 730,
InvalidateRefreshTokens: false,
@@ -114,16 +114,23 @@ var OAuth2 = struct {
}
func loadOAuth2From(rootCfg ConfigProvider) {
- if err := rootCfg.Section("oauth2").MapTo(&OAuth2); err != nil {
- log.Fatal("Failed to OAuth2 settings: %v", err)
+ sec := rootCfg.Section("oauth2")
+ if err := sec.MapTo(&OAuth2); err != nil {
+ log.Fatal("Failed to map OAuth2 settings: %v", err)
return
}
- if !OAuth2.Enable {
+ // Handle the rename of ENABLE to ENABLED
+ deprecatedSetting(rootCfg, "oauth2", "ENABLE", "oauth2", "ENABLED", "v1.23.0")
+ if sec.HasKey("ENABLE") && !sec.HasKey("ENABLED") {
+ OAuth2.Enabled = sec.Key("ENABLE").MustBool(OAuth2.Enabled)
+ }
+
+ if !OAuth2.Enabled {
return
}
- OAuth2.JWTSecretBase64 = loadSecret(rootCfg.Section("oauth2"), "JWT_SECRET_URI", "JWT_SECRET")
+ OAuth2.JWTSecretBase64 = loadSecret(sec, "JWT_SECRET_URI", "JWT_SECRET")
if !filepath.IsAbs(OAuth2.JWTSigningPrivateKeyFile) {
OAuth2.JWTSigningPrivateKeyFile = filepath.Join(AppDataPath, OAuth2.JWTSigningPrivateKeyFile)
diff --git a/routers/web/user/setting/applications.go b/routers/web/user/setting/applications.go
index 69a93dbf03ae0..a7e31fd505181 100644
--- a/routers/web/user/setting/applications.go
+++ b/routers/web/user/setting/applications.go
@@ -95,9 +95,9 @@ func loadApplicationsData(ctx *context.Context) {
return
}
ctx.Data["Tokens"] = tokens
- ctx.Data["EnableOAuth2"] = setting.OAuth2.Enable
+ ctx.Data["EnableOAuth2"] = setting.OAuth2.Enabled
ctx.Data["IsAdmin"] = ctx.Doer.IsAdmin
- if setting.OAuth2.Enable {
+ if setting.OAuth2.Enabled {
ctx.Data["Applications"], err = db.Find[auth_model.OAuth2Application](ctx, auth_model.FindOAuth2ApplicationsOptions{
OwnerID: ctx.Doer.ID,
})
diff --git a/routers/web/web.go b/routers/web/web.go
index ff0ce0c2586bb..92cf5132b45b6 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -304,7 +304,7 @@ func registerRoutes(m *web.Route) {
validation.AddBindingRules()
linkAccountEnabled := func(ctx *context.Context) {
- if !setting.Service.EnableOpenIDSignIn && !setting.Service.EnableOpenIDSignUp && !setting.OAuth2.Enable {
+ if !setting.Service.EnableOpenIDSignIn && !setting.Service.EnableOpenIDSignUp && !setting.OAuth2.Enabled {
ctx.Error(http.StatusForbidden)
return
}
@@ -768,7 +768,7 @@ func registerRoutes(m *web.Route) {
m.Post("/delete", admin.DeleteApplication)
})
}, func(ctx *context.Context) {
- if !setting.OAuth2.Enable {
+ if !setting.OAuth2.Enabled {
ctx.Error(http.StatusForbidden)
return
}
@@ -779,7 +779,7 @@ func registerRoutes(m *web.Route) {
addSettingsRunnersRoutes()
addSettingsVariablesRoutes()
})
- }, adminReq, ctxDataSet("EnableOAuth2", setting.OAuth2.Enable, "EnablePackages", setting.Packages.Enabled))
+ }, adminReq, ctxDataSet("EnableOAuth2", setting.OAuth2.Enabled, "EnablePackages", setting.Packages.Enabled))
// ***** END: Admin *****
m.Group("", func() {
@@ -891,7 +891,7 @@ func registerRoutes(m *web.Route) {
m.Post("/delete", org.DeleteOAuth2Application)
})
}, func(ctx *context.Context) {
- if !setting.OAuth2.Enable {
+ if !setting.OAuth2.Enabled {
ctx.Error(http.StatusForbidden)
return
}
@@ -943,7 +943,7 @@ func registerRoutes(m *web.Route) {
m.Post("/rebuild", org.RebuildCargoIndex)
})
}, packagesEnabled)
- }, ctxDataSet("EnableOAuth2", setting.OAuth2.Enable, "EnablePackages", setting.Packages.Enabled, "PageIsOrgSettings", true))
+ }, ctxDataSet("EnableOAuth2", setting.OAuth2.Enabled, "EnablePackages", setting.Packages.Enabled, "PageIsOrgSettings", true))
}, context.OrgAssignment(true, true))
}, reqSignIn)
// ***** END: Organization *****
From dfc1ae15b6a15aaa8487b770b2d2f7b36e171c5e Mon Sep 17 00:00:00 2001
From: Arnaud Morin
Date: Sun, 28 Jan 2024 15:58:00 +0100
Subject: [PATCH 15/17] Fixing small space missing in sample config file
(#28967)
---
custom/conf/app.example.ini | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini
index 7032e709dbc04..363bbcb15133a 100644
--- a/custom/conf/app.example.ini
+++ b/custom/conf/app.example.ini
@@ -431,7 +431,7 @@ SECRET_KEY =
;SECRET_KEY_URI = file:/etc/gitea/secret_key
;;
;; Secret used to validate communication within Gitea binary.
-INTERNAL_TOKEN=
+INTERNAL_TOKEN =
;;
;; Alternative location to specify internal token, instead of this file; you cannot specify both this and INTERNAL_TOKEN, and must pick one
;INTERNAL_TOKEN_URI = file:/etc/gitea/internal_token
From 34633d85f18ff77643302302379078128dd4ddb7 Mon Sep 17 00:00:00 2001
From: Lunny Xiao
Date: Mon, 29 Jan 2024 04:18:15 +0800
Subject: [PATCH 16/17] Fix bug for generated repository object format (#28969)
A repository generated from a template repository should have the same
git ObjectFormat.
---
modules/repository/generate.go | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/modules/repository/generate.go b/modules/repository/generate.go
index b32c4e058e503..013dd8f76f49f 100644
--- a/modules/repository/generate.go
+++ b/modules/repository/generate.go
@@ -224,8 +224,7 @@ func generateRepoCommit(ctx context.Context, repo, templateRepo, generateRepo *r
}
}
- // FIXME: fix the hash
- if err := git.InitRepository(ctx, tmpDir, false, git.Sha1ObjectFormat.Name()); err != nil {
+ if err := git.InitRepository(ctx, tmpDir, false, templateRepo.ObjectFormatName); err != nil {
return err
}
@@ -327,18 +326,19 @@ func (gro GenerateRepoOptions) IsValid() bool {
// GenerateRepository generates a repository from a template
func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templateRepo *repo_model.Repository, opts GenerateRepoOptions) (_ *repo_model.Repository, err error) {
generateRepo := &repo_model.Repository{
- OwnerID: owner.ID,
- Owner: owner,
- OwnerName: owner.Name,
- Name: opts.Name,
- LowerName: strings.ToLower(opts.Name),
- Description: opts.Description,
- DefaultBranch: opts.DefaultBranch,
- IsPrivate: opts.Private,
- IsEmpty: !opts.GitContent || templateRepo.IsEmpty,
- IsFsckEnabled: templateRepo.IsFsckEnabled,
- TemplateID: templateRepo.ID,
- TrustModel: templateRepo.TrustModel,
+ OwnerID: owner.ID,
+ Owner: owner,
+ OwnerName: owner.Name,
+ Name: opts.Name,
+ LowerName: strings.ToLower(opts.Name),
+ Description: opts.Description,
+ DefaultBranch: opts.DefaultBranch,
+ IsPrivate: opts.Private,
+ IsEmpty: !opts.GitContent || templateRepo.IsEmpty,
+ IsFsckEnabled: templateRepo.IsFsckEnabled,
+ TemplateID: templateRepo.ID,
+ TrustModel: templateRepo.TrustModel,
+ ObjectFormatName: templateRepo.ObjectFormatName,
}
if err = CreateRepositoryByExample(ctx, doer, owner, generateRepo, false, false); err != nil {
@@ -358,8 +358,7 @@ func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templ
}
}
- // FIXME - fix the hash
- if err = CheckInitRepository(ctx, owner.Name, generateRepo.Name, git.Sha1ObjectFormat.Name()); err != nil {
+ if err = CheckInitRepository(ctx, owner.Name, generateRepo.Name, generateRepo.ObjectFormatName); err != nil {
return generateRepo, err
}
From 2a50d780f93957223da9494c61bb3181ffa7ff65 Mon Sep 17 00:00:00 2001
From: GiteaBot
Date: Mon, 29 Jan 2024 00:24:21 +0000
Subject: [PATCH 17/17] [skip ci] Updated licenses and gitignores
---
options/license/fmt-exception | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 options/license/fmt-exception
diff --git a/options/license/fmt-exception b/options/license/fmt-exception
new file mode 100644
index 0000000000000..6036f7d360a53
--- /dev/null
+++ b/options/license/fmt-exception
@@ -0,0 +1,6 @@
+--- Optional exception to the license ---
+
+As an exception, if, as a result of your compiling your source code, portions
+of this Software are embedded into a machine-executable object form of such
+source code, you may redistribute such embedded portions in such object form
+without including the above copyright and permission notices.