Skip to content

Commit 69ca301

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Use strict protocol check when redirect (go-gitea#29642) Update various logos and unify their filenames (go-gitea#29637) Tweak actions color and borders (go-gitea#29640) Add download URL for executable files (go-gitea#28260) Move all login and account creation page labels to be above inputs (go-gitea#29432) Avoid issue info panic (go-gitea#29625) Cache repository default branch commit status to reduce query on commit status table (go-gitea#29444) Avoid unexpected panic in graceful manager (go-gitea#29629) Add a link for the recently pushed branch notification (go-gitea#29627) Fix wrong header of org project view page (go-gitea#29626) Detect broken git hooks (go-gitea#29494) Sync branches to DB immediately when handle git hook calling (go-gitea#29493) Fix wrong line number in code search result (go-gitea#29260) Make wiki default branch name changable (go-gitea#29603) A small refactor for agit implementation (go-gitea#29614) Update Twitter Logo (go-gitea#29621) Fix 500 error when adding PR comment (go-gitea#29622)
2 parents 810335f + c72e1a7 commit 69ca301

Some content is hidden

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

74 files changed

+955
-424
lines changed

models/activities/action.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,14 @@ func (a *Action) GetCreate() time.Time {
393393
return a.CreatedUnix.AsTime()
394394
}
395395

396-
// GetIssueInfos returns a list of issues associated with
397-
// the action.
396+
// GetIssueInfos returns a list of associated information with the action.
398397
func (a *Action) GetIssueInfos() []string {
399-
return strings.SplitN(a.Content, "|", 3)
398+
// make sure it always returns 3 elements, because there are some access to the a[1] and a[2] without checking the length
399+
ret := strings.SplitN(a.Content, "|", 3)
400+
for len(ret) < 3 {
401+
ret = append(ret, "")
402+
}
403+
return ret
400404
}
401405

402406
// GetIssueTitle returns the title of first issue associated with the action.

models/git/branch.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ func GetBranch(ctx context.Context, repoID int64, branchName string) (*Branch, e
158158
return &branch, nil
159159
}
160160

161+
func GetBranches(ctx context.Context, repoID int64, branchNames []string) ([]*Branch, error) {
162+
branches := make([]*Branch, 0, len(branchNames))
163+
return branches, db.GetEngine(ctx).Where("repo_id=?", repoID).In("name", branchNames).Find(&branches)
164+
}
165+
161166
func AddBranches(ctx context.Context, branches []*Branch) error {
162167
for _, branch := range branches {
163168
if _, err := db.GetEngine(ctx).Insert(branch); err != nil {

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@ var migrations = []Migration{
562562
NewMigration("Use Slug instead of ID for Badges", v1_22.UseSlugInsteadOfIDForBadges),
563563
// v288 -> v289
564564
NewMigration("Add user_blocking table", v1_22.AddUserBlockingTable),
565+
// v289 -> v290
566+
NewMigration("Add default_wiki_branch to repository table", v1_22.AddDefaultWikiBranch),
565567
}
566568

567569
// GetCurrentDBVersion returns the current db version

models/migrations/v1_22/v289.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_22 //nolint
5+
6+
import "xorm.io/xorm"
7+
8+
func AddDefaultWikiBranch(x *xorm.Engine) error {
9+
type Repository struct {
10+
ID int64
11+
DefaultWikiBranch string
12+
}
13+
if err := x.Sync(&Repository{}); err != nil {
14+
return err
15+
}
16+
_, err := x.Exec("UPDATE `repository` SET default_wiki_branch = 'master' WHERE (default_wiki_branch IS NULL) OR (default_wiki_branch = '')")
17+
return err
18+
}

models/repo/repo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ type Repository struct {
136136
OriginalServiceType api.GitServiceType `xorm:"index"`
137137
OriginalURL string `xorm:"VARCHAR(2048)"`
138138
DefaultBranch string
139+
DefaultWikiBranch string
139140

140141
NumWatches int
141142
NumStars int
@@ -285,6 +286,9 @@ func (repo *Repository) AfterLoad() {
285286
repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones
286287
repo.NumOpenProjects = repo.NumProjects - repo.NumClosedProjects
287288
repo.NumOpenActionRuns = repo.NumActionRuns - repo.NumClosedActionRuns
289+
if repo.DefaultWikiBranch == "" {
290+
repo.DefaultWikiBranch = setting.Repository.DefaultBranch
291+
}
288292
}
289293

290294
// LoadAttributes loads attributes of the repository.

modules/git/repo_base_gogit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ package git
88

99
import (
1010
"context"
11-
"errors"
1211
"path/filepath"
1312

1413
gitealog "code.gitea.io/gitea/modules/log"
1514
"code.gitea.io/gitea/modules/setting"
15+
"code.gitea.io/gitea/modules/util"
1616

1717
"github.com/go-git/go-billy/v5"
1818
"github.com/go-git/go-billy/v5/osfs"
@@ -52,7 +52,7 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
5252
if err != nil {
5353
return nil, err
5454
} else if !isDir(repoPath) {
55-
return nil, errors.New("no such file or directory")
55+
return nil, util.NewNotExistErrorf("no such file or directory")
5656
}
5757

5858
fs := osfs.New(repoPath)

modules/git/repo_base_nogogit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ package git
99
import (
1010
"bufio"
1111
"context"
12-
"errors"
1312
"path/filepath"
1413

1514
"code.gitea.io/gitea/modules/log"
15+
"code.gitea.io/gitea/modules/util"
1616
)
1717

1818
func init() {
@@ -54,7 +54,7 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
5454
if err != nil {
5555
return nil, err
5656
} else if !isDir(repoPath) {
57-
return nil, errors.New("no such file or directory")
57+
return nil, util.NewNotExistErrorf("no such file or directory")
5858
}
5959

6060
// Now because of some insanity with git cat-file not immediately failing if not run in a valid git directory we need to run git rev-parse first!

modules/graceful/manager_unix.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@ func (g *Manager) start() {
5959
go func() {
6060
defer close(startupDone)
6161
// Wait till we're done getting all the listeners and then close the unused ones
62-
g.createServerWaitGroup.Wait()
62+
func() {
63+
// FIXME: there is a fundamental design problem of the "manager" and the "wait group".
64+
// If nothing has started, the "Wait" just panics: sync: WaitGroup is reused before previous Wait has returned
65+
// There is no clear solution besides a complete rewriting of the "manager"
66+
defer func() {
67+
_ = recover()
68+
}()
69+
g.createServerWaitGroup.Wait()
70+
}()
6371
// Ignore the error here there's not much we can do with it, they're logged in the CloseProvidedListeners function
6472
_ = CloseProvidedListeners()
6573
g.notify(readyMsg)

modules/graceful/manager_windows.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,15 @@ func (g *Manager) awaitServer(limit time.Duration) bool {
150150
c := make(chan struct{})
151151
go func() {
152152
defer close(c)
153-
g.createServerWaitGroup.Wait()
153+
func() {
154+
// FIXME: there is a fundamental design problem of the "manager" and the "wait group".
155+
// If nothing has started, the "Wait" just panics: sync: WaitGroup is reused before previous Wait has returned
156+
// There is no clear solution besides a complete rewriting of the "manager"
157+
defer func() {
158+
_ = recover()
159+
}()
160+
g.createServerWaitGroup.Wait()
161+
}()
154162
}()
155163
if limit > 0 {
156164
select {

modules/indexer/code/search.go

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ import (
1616

1717
// Result a search result to display
1818
type Result struct {
19-
RepoID int64
20-
Filename string
21-
CommitID string
22-
UpdatedUnix timeutil.TimeStamp
23-
Language string
24-
Color string
25-
LineNumbers []int
26-
FormattedLines template.HTML
19+
RepoID int64
20+
Filename string
21+
CommitID string
22+
UpdatedUnix timeutil.TimeStamp
23+
Language string
24+
Color string
25+
Lines []ResultLine
26+
}
27+
28+
type ResultLine struct {
29+
Num int
30+
FormattedContent template.HTML
2731
}
2832

2933
type SearchResultLanguages = internal.SearchResultLanguages
@@ -70,7 +74,7 @@ func searchResult(result *internal.SearchResult, startIndex, endIndex int) (*Res
7074
var formattedLinesBuffer bytes.Buffer
7175

7276
contentLines := strings.SplitAfter(result.Content[startIndex:endIndex], "\n")
73-
lineNumbers := make([]int, len(contentLines))
77+
lines := make([]ResultLine, 0, len(contentLines))
7478
index := startIndex
7579
for i, line := range contentLines {
7680
var err error
@@ -93,21 +97,29 @@ func searchResult(result *internal.SearchResult, startIndex, endIndex int) (*Res
9397
return nil, err
9498
}
9599

96-
lineNumbers[i] = startLineNum + i
100+
lines = append(lines, ResultLine{Num: startLineNum + i})
97101
index += len(line)
98102
}
99103

100-
highlighted, _ := highlight.Code(result.Filename, "", formattedLinesBuffer.String())
104+
// we should highlight the whole code block first, otherwise it doesn't work well with multiple line highlighting
105+
hl, _ := highlight.Code(result.Filename, "", formattedLinesBuffer.String())
106+
highlightedLines := strings.Split(string(hl), "\n")
107+
108+
// The lines outputted by highlight.Code might not match the original lines, because "highlight" removes the last `\n`
109+
lines = lines[:min(len(highlightedLines), len(lines))]
110+
highlightedLines = highlightedLines[:len(lines)]
111+
for i := 0; i < len(lines); i++ {
112+
lines[i].FormattedContent = template.HTML(highlightedLines[i])
113+
}
101114

102115
return &Result{
103-
RepoID: result.RepoID,
104-
Filename: result.Filename,
105-
CommitID: result.CommitID,
106-
UpdatedUnix: result.UpdatedUnix,
107-
Language: result.Language,
108-
Color: result.Color,
109-
LineNumbers: lineNumbers,
110-
FormattedLines: highlighted,
116+
RepoID: result.RepoID,
117+
Filename: result.Filename,
118+
CommitID: result.CommitID,
119+
UpdatedUnix: result.UpdatedUnix,
120+
Language: result.Language,
121+
Color: result.Color,
122+
Lines: lines,
111123
}, nil
112124
}
113125

options/locale/locale_en-US.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,8 @@ settings.branches.add_new_rule = Add New Rule
20922092
settings.advanced_settings = Advanced Settings
20932093
settings.wiki_desc = Enable Repository Wiki
20942094
settings.use_internal_wiki = Use Built-In Wiki
2095+
settings.default_wiki_branch_name = Default Wiki Branch Name
2096+
settings.failed_to_change_default_wiki_branch = Failed to change the default wiki branch.
20952097
settings.use_external_wiki = Use External Wiki
20962098
settings.external_wiki_url = External Wiki URL
20972099
settings.external_wiki_url_error = The external wiki URL is not a valid URL.
@@ -2641,6 +2643,7 @@ find_file.no_matching = No matching file found
26412643
error.csv.too_large = Can't render this file because it is too large.
26422644
error.csv.unexpected = Can't render this file because it contains an unexpected character in line %d and column %d.
26432645
error.csv.invalid_field_count = Can't render this file because it has a wrong number of fields in line %d.
2646+
error.broken_git_hook = Git hooks of this repository seem to be broken. Please follow the <a target="_blank" rel="noreferrer" href="%s">documentation</a> to fix them, then push some commits to refresh the status.
26442647
26452648
[graphs]
26462649
component_loading = Loading %s...

public/assets/img/svg/gitea-bitbucket.svg

Lines changed: 1 addition & 1 deletion
Loading

public/assets/img/svg/gitea-facebook.svg

Lines changed: 1 addition & 1 deletion
Loading

public/assets/img/svg/gitea-jetbrains.svg

Lines changed: 1 addition & 0 deletions
Loading

public/assets/img/svg/gitea-microsoftonline.svg

Lines changed: 1 addition & 1 deletion
Loading

0 commit comments

Comments
 (0)