Skip to content

Commit 32e3e22

Browse files
authored
Merge branch 'main' into lunny/add_repo_mirror_lock
2 parents 12c33de + 7e8168f commit 32e3e22

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1366
-363
lines changed

models/actions/runner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type ActionRunner struct {
5757

5858
// Store labels defined in state file (default: .runner file) of `act_runner`
5959
AgentLabels []string `xorm:"TEXT"`
60+
// Store if this is a runner that only ever get one single job assigned
61+
Ephemeral bool `xorm:"ephemeral NOT NULL DEFAULT false"`
6062

6163
Created timeutil.TimeStamp `xorm:"created"`
6264
Updated timeutil.TimeStamp `xorm:"updated"`

models/migrations/migrations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ func prepareMigrationTasks() []*migration {
375375
newMigration(312, "Add DeleteBranchAfterMerge to AutoMerge", v1_24.AddDeleteBranchAfterMergeForAutoMerge),
376376
newMigration(313, "Move PinOrder from issue table to a new table issue_pin", v1_24.MovePinOrderToTableIssuePin),
377377
newMigration(314, "Update OwnerID as zero for repository level action tables", v1_24.UpdateOwnerIDOfRepoLevelActionsTables),
378+
newMigration(315, "Add Ephemeral to ActionRunner", v1_24.AddEphemeralToActionRunner),
378379
}
379380
return preparedMigrations
380381
}

models/migrations/v1_24/v315.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_24 //nolint
5+
6+
import (
7+
"xorm.io/xorm"
8+
)
9+
10+
func AddEphemeralToActionRunner(x *xorm.Engine) error {
11+
type ActionRunner struct {
12+
Ephemeral bool `xorm:"ephemeral NOT NULL DEFAULT false"`
13+
}
14+
15+
return x.Sync(new(ActionRunner))
16+
}

models/user/setting_keys.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const (
1010
SettingsKeyDiffWhitespaceBehavior = "diff.whitespace_behaviour"
1111
// SettingsKeyShowOutdatedComments is the setting key wether or not to show outdated comments in PRs
1212
SettingsKeyShowOutdatedComments = "comment_code.show_outdated"
13+
1314
// UserActivityPubPrivPem is user's private key
1415
UserActivityPubPrivPem = "activitypub.priv_pem"
1516
// UserActivityPubPubPem is user's public key
@@ -18,4 +19,6 @@ const (
1819
SignupIP = "signup.ip"
1920
// SignupUserAgent is the user agent that the user signed up with
2021
SignupUserAgent = "signup.user_agent"
22+
23+
SettingsKeyCodeViewShowFileTree = "code_view.show_file_tree"
2124
)

modules/fileicon/material.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (m *MaterialIconProvider) loadData() {
6262
log.Debug("Loaded material icon rules and SVG images")
6363
}
6464

65-
func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name, svg string) template.HTML {
65+
func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name, svg, extraClass string) template.HTML {
6666
data := ctx.GetData()
6767
renderedSVGs, _ := data["_RenderedSVGs"].(map[string]bool)
6868
if renderedSVGs == nil {
@@ -75,7 +75,7 @@ func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name
7575
panic("Invalid SVG icon")
7676
}
7777
svgID := "svg-mfi-" + name
78-
svgCommonAttrs := `class="svg fileicon" width="16" height="16" aria-hidden="true"`
78+
svgCommonAttrs := `class="svg git-entry-icon ` + extraClass + `" width="16" height="16" aria-hidden="true"`
7979
posOuterBefore := strings.IndexByte(svg, '>')
8080
if renderedSVGs[svgID] && posOuterBefore != -1 {
8181
return template.HTML(`<svg ` + svgCommonAttrs + `><use xlink:href="#` + svgID + `"></use></svg>`)
@@ -92,18 +92,28 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr
9292

9393
if entry.IsLink() {
9494
if te, err := entry.FollowLink(); err == nil && te.IsDir() {
95-
return svg.RenderHTML("material-folder-symlink")
95+
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
96+
return svg.RenderHTML("material-folder-symlink", 16, "octicon-file-directory-symlink")
9697
}
9798
return svg.RenderHTML("octicon-file-symlink-file") // TODO: find some better icons for them
9899
}
99100

100101
name := m.findIconNameByGit(entry)
101102
if name == "folder" {
102103
// the material icon pack's "folder" icon doesn't look good, so use our built-in one
103-
return svg.RenderHTML("material-folder-generic")
104+
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
105+
return svg.RenderHTML("material-folder-generic", 16, "octicon-file-directory-fill")
104106
}
105107
if iconSVG, ok := m.svgs[name]; ok && iconSVG != "" {
106-
return m.renderFileIconSVG(ctx, name, iconSVG)
108+
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
109+
extraClass := "octicon-file"
110+
switch {
111+
case entry.IsDir():
112+
extraClass = "octicon-file-directory-fill"
113+
case entry.IsSubModule():
114+
extraClass = "octicon-file-submodule"
115+
}
116+
return m.renderFileIconSVG(ctx, name, iconSVG, extraClass)
107117
}
108118
return svg.RenderHTML("octicon-file")
109119
}

modules/git/parse_nogogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func ParseTreeEntries(data []byte) ([]*TreeEntry, error) {
1919
return parseTreeEntries(data, nil)
2020
}
2121

22-
// parseTreeEntries FIXME this function's design is not right, it should make the caller read all data into memory
22+
// parseTreeEntries FIXME this function's design is not right, it should not make the caller read all data into memory
2323
func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) {
2424
entries := make([]*TreeEntry, 0, bytes.Count(data, []byte{'\n'})+1)
2525
for pos := 0; pos < len(data); {

modules/git/tree_blob_gogit.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func (t *Tree) GetTreeEntryByPath(relpath string) (*TreeEntry, error) {
2121
return &TreeEntry{
2222
ID: t.ID,
2323
// Type: ObjectTree,
24+
ptree: t,
2425
gogitTreeEntry: &object.TreeEntry{
2526
Name: "",
2627
Mode: filemode.Dir,

modules/gitrepo/gitrepo.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package gitrepo
55

66
import (
77
"context"
8+
"fmt"
89
"io"
910
"path/filepath"
1011
"strings"
@@ -20,8 +21,12 @@ type Repository interface {
2021
GetOwnerName() string
2122
}
2223

24+
func absPath(owner, name string) string {
25+
return filepath.Join(setting.RepoRootPath, strings.ToLower(owner), strings.ToLower(name)+".git")
26+
}
27+
2328
func repoPath(repo Repository) string {
24-
return filepath.Join(setting.RepoRootPath, strings.ToLower(repo.GetOwnerName()), strings.ToLower(repo.GetName())+".git")
29+
return absPath(repo.GetOwnerName(), repo.GetName())
2530
}
2631

2732
func wikiPath(repo Repository) string {
@@ -69,3 +74,22 @@ func RepositoryFromRequestContextOrOpen(ctx reqctx.RequestContext, repo Reposito
6974
ctx.SetContextValue(ck, gitRepo)
7075
return gitRepo, nil
7176
}
77+
78+
// IsRepositoryExist returns true if the repository directory exists in the disk
79+
func IsRepositoryExist(ctx context.Context, repo Repository) (bool, error) {
80+
return util.IsExist(repoPath(repo))
81+
}
82+
83+
// DeleteRepository deletes the repository directory from the disk
84+
func DeleteRepository(ctx context.Context, repo Repository) error {
85+
return util.RemoveAll(repoPath(repo))
86+
}
87+
88+
// RenameRepository renames a repository's name on disk
89+
func RenameRepository(ctx context.Context, repo Repository, newName string) error {
90+
newRepoPath := absPath(repo.GetOwnerName(), newName)
91+
if err := util.Rename(repoPath(repo), newRepoPath); err != nil {
92+
return fmt.Errorf("rename repository directory: %w", err)
93+
}
94+
return nil
95+
}

modules/indexer/code/bleve/bleve.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"code.gitea.io/gitea/modules/setting"
2626
"code.gitea.io/gitea/modules/timeutil"
2727
"code.gitea.io/gitea/modules/typesniffer"
28+
"code.gitea.io/gitea/modules/util"
2829

2930
"github.com/blevesearch/bleve/v2"
3031
analyzer_custom "github.com/blevesearch/bleve/v2/analysis/analyzer/custom"
@@ -272,14 +273,18 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int
272273
pathQuery.FieldVal = "Filename"
273274
pathQuery.SetBoost(10)
274275

275-
if opts.SearchMode == indexer.SearchModeExact {
276+
searchMode := util.IfZero(opts.SearchMode, b.SupportedSearchModes()[0].ModeValue)
277+
if searchMode == indexer.SearchModeExact {
278+
// 1.21 used NewPrefixQuery, but it seems not working well, and later releases changed to NewMatchPhraseQuery
276279
q := bleve.NewMatchPhraseQuery(opts.Keyword)
280+
q.Analyzer = repoIndexerAnalyzer
277281
q.FieldVal = "Content"
278282
contentQuery = q
279283
} else /* words */ {
280284
q := bleve.NewMatchQuery(opts.Keyword)
281285
q.FieldVal = "Content"
282-
if opts.SearchMode == indexer.SearchModeFuzzy {
286+
q.Analyzer = repoIndexerAnalyzer
287+
if searchMode == indexer.SearchModeFuzzy {
283288
// this logic doesn't seem right, it is only used to pass the test-case `Keyword: "dESCRIPTION"`, which doesn't seem to be a real-life use-case.
284289
q.Fuzziness = inner_bleve.GuessFuzzinessByKeyword(opts.Keyword)
285290
} else {

modules/indexer/code/elasticsearch/elasticsearch.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"code.gitea.io/gitea/modules/setting"
2626
"code.gitea.io/gitea/modules/timeutil"
2727
"code.gitea.io/gitea/modules/typesniffer"
28+
"code.gitea.io/gitea/modules/util"
2829

2930
"github.com/go-enry/go-enry/v2"
3031
"github.com/olivere/elastic/v7"
@@ -365,7 +366,9 @@ func extractAggs(searchResult *elastic.SearchResult) []*internal.SearchResultLan
365366
// Search searches for codes and language stats by given conditions.
366367
func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int64, []*internal.SearchResult, []*internal.SearchResultLanguages, error) {
367368
var contentQuery elastic.Query
368-
if opts.SearchMode == indexer.SearchModeExact {
369+
searchMode := util.IfZero(opts.SearchMode, b.SupportedSearchModes()[0].ModeValue)
370+
if searchMode == indexer.SearchModeExact {
371+
// 1.21 used NewMultiMatchQuery().Type(esMultiMatchTypePhrasePrefix), but later releases changed to NewMatchPhraseQuery
369372
contentQuery = elastic.NewMatchPhraseQuery("content", opts.Keyword)
370373
} else /* words */ {
371374
contentQuery = elastic.NewMultiMatchQuery("content", opts.Keyword).Type(esMultiMatchTypeBestFields).Operator("and")

0 commit comments

Comments
 (0)