Skip to content

Commit a07e862

Browse files
Merge branch 'main' into fix-tmpl
2 parents 3828f30 + 321cbcb commit a07e862

File tree

31 files changed

+591
-231
lines changed

31 files changed

+591
-231
lines changed

models/actions/run_job.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"code.gitea.io/gitea/models/db"
13+
repo_model "code.gitea.io/gitea/models/repo"
1314
"code.gitea.io/gitea/modules/timeutil"
1415
"code.gitea.io/gitea/modules/util"
1516

@@ -19,11 +20,12 @@ import (
1920
// ActionRunJob represents a job of a run
2021
type ActionRunJob struct {
2122
ID int64
22-
RunID int64 `xorm:"index"`
23-
Run *ActionRun `xorm:"-"`
24-
RepoID int64 `xorm:"index"`
25-
OwnerID int64 `xorm:"index"`
26-
CommitSHA string `xorm:"index"`
23+
RunID int64 `xorm:"index"`
24+
Run *ActionRun `xorm:"-"`
25+
RepoID int64 `xorm:"index"`
26+
Repo *repo_model.Repository `xorm:"-"`
27+
OwnerID int64 `xorm:"index"`
28+
CommitSHA string `xorm:"index"`
2729
IsForkPullRequest bool
2830
Name string `xorm:"VARCHAR(255)"`
2931
Attempt int64
@@ -58,6 +60,17 @@ func (job *ActionRunJob) LoadRun(ctx context.Context) error {
5860
return nil
5961
}
6062

63+
func (job *ActionRunJob) LoadRepo(ctx context.Context) error {
64+
if job.Repo == nil {
65+
repo, err := repo_model.GetRepositoryByID(ctx, job.RepoID)
66+
if err != nil {
67+
return err
68+
}
69+
job.Repo = repo
70+
}
71+
return nil
72+
}
73+
6174
// LoadAttributes load Run if not loaded
6275
func (job *ActionRunJob) LoadAttributes(ctx context.Context) error {
6376
if job == nil {
@@ -83,7 +96,7 @@ func GetRunJobByID(ctx context.Context, id int64) (*ActionRunJob, error) {
8396
return &job, nil
8497
}
8598

86-
func GetRunJobsByRunID(ctx context.Context, runID int64) ([]*ActionRunJob, error) {
99+
func GetRunJobsByRunID(ctx context.Context, runID int64) (ActionJobList, error) {
87100
var jobs []*ActionRunJob
88101
if err := db.GetEngine(ctx).Where("run_id=?", runID).OrderBy("id").Find(&jobs); err != nil {
89102
return nil, err

models/actions/run_job_list.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88

99
"code.gitea.io/gitea/models/db"
10+
repo_model "code.gitea.io/gitea/models/repo"
1011
"code.gitea.io/gitea/modules/container"
1112
"code.gitea.io/gitea/modules/timeutil"
1213

@@ -21,7 +22,33 @@ func (jobs ActionJobList) GetRunIDs() []int64 {
2122
})
2223
}
2324

25+
func (jobs ActionJobList) LoadRepos(ctx context.Context) error {
26+
repoIDs := container.FilterSlice(jobs, func(j *ActionRunJob) (int64, bool) {
27+
return j.RepoID, j.RepoID != 0 && j.Repo == nil
28+
})
29+
if len(repoIDs) == 0 {
30+
return nil
31+
}
32+
33+
repos := make(map[int64]*repo_model.Repository, len(repoIDs))
34+
if err := db.GetEngine(ctx).In("id", repoIDs).Find(&repos); err != nil {
35+
return err
36+
}
37+
for _, j := range jobs {
38+
if j.RepoID > 0 && j.Repo == nil {
39+
j.Repo = repos[j.RepoID]
40+
}
41+
}
42+
return nil
43+
}
44+
2445
func (jobs ActionJobList) LoadRuns(ctx context.Context, withRepo bool) error {
46+
if withRepo {
47+
if err := jobs.LoadRepos(ctx); err != nil {
48+
return err
49+
}
50+
}
51+
2552
runIDs := jobs.GetRunIDs()
2653
runs := make(map[int64]*ActionRun, len(runIDs))
2754
if err := db.GetEngine(ctx).In("id", runIDs).Find(&runs); err != nil {
@@ -30,15 +57,9 @@ func (jobs ActionJobList) LoadRuns(ctx context.Context, withRepo bool) error {
3057
for _, j := range jobs {
3158
if j.RunID > 0 && j.Run == nil {
3259
j.Run = runs[j.RunID]
60+
j.Run.Repo = j.Repo
3361
}
3462
}
35-
if withRepo {
36-
var runsList RunList = make([]*ActionRun, 0, len(runs))
37-
for _, r := range runs {
38-
runsList = append(runsList, r)
39-
}
40-
return runsList.LoadRepos(ctx)
41-
}
4263
return nil
4364
}
4465

modules/git/batch.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,26 @@ type Batch struct {
1414
Writer WriteCloserError
1515
}
1616

17-
func (repo *Repository) NewBatch(ctx context.Context) (*Batch, error) {
17+
// NewBatch creates a new batch for the given repository, the Close must be invoked before release the batch
18+
func NewBatch(ctx context.Context, repoPath string) (*Batch, error) {
1819
// 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!
19-
if err := ensureValidGitRepository(ctx, repo.Path); err != nil {
20+
if err := ensureValidGitRepository(ctx, repoPath); err != nil {
2021
return nil, err
2122
}
2223

2324
var batch Batch
24-
batch.Writer, batch.Reader, batch.cancel = catFileBatch(ctx, repo.Path)
25+
batch.Writer, batch.Reader, batch.cancel = catFileBatch(ctx, repoPath)
2526
return &batch, nil
2627
}
2728

28-
func (repo *Repository) NewBatchCheck(ctx context.Context) (*Batch, error) {
29+
func NewBatchCheck(ctx context.Context, repoPath string) (*Batch, error) {
2930
// 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!
30-
if err := ensureValidGitRepository(ctx, repo.Path); err != nil {
31+
if err := ensureValidGitRepository(ctx, repoPath); err != nil {
3132
return nil, err
3233
}
3334

3435
var check Batch
35-
check.Writer, check.Reader, check.cancel = catFileBatchCheck(ctx, repo.Path)
36+
check.Writer, check.Reader, check.cancel = catFileBatchCheck(ctx, repoPath)
3637
return &check, nil
3738
}
3839

modules/git/command.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,10 @@ func (c *Command) run(ctx context.Context, skip int, opts *RunOpts) error {
350350
// We need to check if the context is canceled by the program on Windows.
351351
// This is because Windows does not have signal checking when terminating the process.
352352
// It always returns exit code 1, unlike Linux, which has many exit codes for signals.
353+
// `err.Error()` returns "exit status 1" when using the `git check-attr` command after the context is canceled.
353354
if runtime.GOOS == "windows" &&
354355
err != nil &&
355-
err.Error() == "" &&
356+
(err.Error() == "" || err.Error() == "exit status 1") &&
356357
cmd.ProcessState.ExitCode() == 1 &&
357358
ctx.Err() == context.Canceled {
358359
return ctx.Err()

modules/git/repo_attribute.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ func (wr *nulSeparatedAttributeWriter) Write(p []byte) (n int, err error) {
280280
}
281281
}
282282
wr.tmp = append(wr.tmp, p...)
283-
return len(p), nil
283+
return l, nil
284284
}
285285

286286
func (wr *nulSeparatedAttributeWriter) ReadAttribute() <-chan attributeTriple {

modules/git/repo_base_nogogit.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func OpenRepository(ctx context.Context, repoPath string) (*Repository, error) {
6767
func (repo *Repository) CatFileBatch(ctx context.Context) (WriteCloserError, *bufio.Reader, func(), error) {
6868
if repo.batch == nil {
6969
var err error
70-
repo.batch, err = repo.NewBatch(ctx)
70+
repo.batch, err = NewBatch(ctx, repo.Path)
7171
if err != nil {
7272
return nil, nil, nil, err
7373
}
@@ -81,7 +81,7 @@ func (repo *Repository) CatFileBatch(ctx context.Context) (WriteCloserError, *bu
8181
}
8282

8383
log.Debug("Opening temporary cat file batch for: %s", repo.Path)
84-
tempBatch, err := repo.NewBatch(ctx)
84+
tempBatch, err := NewBatch(ctx, repo.Path)
8585
if err != nil {
8686
return nil, nil, nil, err
8787
}
@@ -92,7 +92,7 @@ func (repo *Repository) CatFileBatch(ctx context.Context) (WriteCloserError, *bu
9292
func (repo *Repository) CatFileBatchCheck(ctx context.Context) (WriteCloserError, *bufio.Reader, func(), error) {
9393
if repo.check == nil {
9494
var err error
95-
repo.check, err = repo.NewBatchCheck(ctx)
95+
repo.check, err = NewBatchCheck(ctx, repo.Path)
9696
if err != nil {
9797
return nil, nil, nil, err
9898
}
@@ -106,7 +106,7 @@ func (repo *Repository) CatFileBatchCheck(ctx context.Context) (WriteCloserError
106106
}
107107

108108
log.Debug("Opening temporary cat file batch-check for: %s", repo.Path)
109-
tempBatchCheck, err := repo.NewBatchCheck(ctx)
109+
tempBatchCheck, err := NewBatchCheck(ctx, repo.Path)
110110
if err != nil {
111111
return nil, nil, nil, err
112112
}

modules/indexer/code/bleve/bleve.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"code.gitea.io/gitea/modules/analyze"
1717
"code.gitea.io/gitea/modules/charset"
1818
"code.gitea.io/gitea/modules/git"
19-
"code.gitea.io/gitea/modules/gitrepo"
2019
"code.gitea.io/gitea/modules/indexer"
2120
path_filter "code.gitea.io/gitea/modules/indexer/code/bleve/token/path"
2221
"code.gitea.io/gitea/modules/indexer/code/internal"
@@ -217,12 +216,7 @@ func (b *Indexer) addDelete(filename string, repo *repo_model.Repository, batch
217216
func (b *Indexer) Index(ctx context.Context, repo *repo_model.Repository, sha string, changes *internal.RepoChanges) error {
218217
batch := inner_bleve.NewFlushingBatch(b.inner.Indexer, maxBatchSize)
219218
if len(changes.Updates) > 0 {
220-
r, err := gitrepo.OpenRepository(ctx, repo)
221-
if err != nil {
222-
return err
223-
}
224-
defer r.Close()
225-
gitBatch, err := r.NewBatch(ctx)
219+
gitBatch, err := git.NewBatch(ctx, repo.RepoPath())
226220
if err != nil {
227221
return err
228222
}

modules/indexer/code/elasticsearch/elasticsearch.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"code.gitea.io/gitea/modules/analyze"
1616
"code.gitea.io/gitea/modules/charset"
1717
"code.gitea.io/gitea/modules/git"
18-
"code.gitea.io/gitea/modules/gitrepo"
1918
"code.gitea.io/gitea/modules/indexer"
2019
"code.gitea.io/gitea/modules/indexer/code/internal"
2120
indexer_internal "code.gitea.io/gitea/modules/indexer/internal"
@@ -209,12 +208,7 @@ func (b *Indexer) addDelete(filename string, repo *repo_model.Repository) elasti
209208
func (b *Indexer) Index(ctx context.Context, repo *repo_model.Repository, sha string, changes *internal.RepoChanges) error {
210209
reqs := make([]elastic.BulkableRequest, 0)
211210
if len(changes.Updates) > 0 {
212-
r, err := gitrepo.OpenRepository(ctx, repo)
213-
if err != nil {
214-
return err
215-
}
216-
defer r.Close()
217-
batch, err := r.NewBatch(ctx)
211+
batch, err := git.NewBatch(ctx, repo.RepoPath())
218212
if err != nil {
219213
return err
220214
}

modules/templates/util_avatar.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ func AvatarHTML(src string, size int, class, name string) template.HTML {
3434
name = "avatar"
3535
}
3636

37-
return template.HTML(`<img loading="lazy" class="` + class + `" src="` + src + `" title="` + html.EscapeString(name) + `" width="` + sizeStr + `" height="` + sizeStr + `"/>`)
37+
// use empty alt, otherwise if the image fails to load, the width will follow the "alt" text's width
38+
return template.HTML(`<img loading="lazy" alt="" class="` + class + `" src="` + src + `" title="` + html.EscapeString(name) + `" width="` + sizeStr + `" height="` + sizeStr + `"/>`)
3839
}
3940

4041
// Avatar renders user avatars. args: user, size (int), class (string)

options/locale/locale_ja-JP.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ copy_type_unsupported=このファイルタイプはコピーできません
113113
write=書き込み
114114
preview=プレビュー
115115
loading=読み込み中…
116+
files=ファイル
116117

117118
error=エラー
118119
error404=アクセスしようとしたページは<strong>存在しない</strong>か、閲覧が<strong>許可されていません</strong>。
@@ -456,6 +457,7 @@ oauth_signup_submit=アカウント登録完了
456457
oauth_signin_tab=既存アカウントにリンク
457458
oauth_signin_title=リンク先アカウント認可のためサインイン
458459
oauth_signin_submit=アカウントにリンク
460+
oauth.signin.error.general=認可リクエストの処理中にエラーが発生しました: %s 。このエラーが解決しない場合は、サイト管理者に問い合わせてください。
459461
oauth.signin.error.access_denied=認可リクエストが拒否されました。
460462
oauth.signin.error.temporarily_unavailable=認証サーバーが一時的に利用できないため、認可に失敗しました。後でもう一度やり直してください。
461463
oauth_callback_unable_auto_reg=自動登録が有効になっていますが、OAuth2プロバイダー %[1]s の応答はフィールド %[2]s が不足しており、自動でアカウントを作成することができません。 アカウントを作成またはリンクするか、サイト管理者に問い合わせてください。
@@ -1406,6 +1408,7 @@ commits.signed_by_untrusted_user_unmatched=コミッターと一致しない信
14061408
commits.gpg_key_id=GPGキーID
14071409
commits.ssh_key_fingerprint=SSH鍵のフィンガープリント
14081410
commits.view_path=この時点を表示
1411+
commits.view_file_diff=このファイルの、このコミットでの変更内容を表示
14091412

14101413
commit.operations=操作
14111414
commit.revert=リバート

0 commit comments

Comments
 (0)