Skip to content

Commit 34a84af

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: refactor: decouple context from migration structs (go-gitea#33399) Move gitgraph from modules to services layer (go-gitea#33527) Add go wrapper around git diff-tree --raw -r -M (go-gitea#33369) [skip ci] Updated translations via Crowdin Update MAINTAINERS (go-gitea#33529) Add cropping support when modifying the user/org/repo avatar (go-gitea#33498) [skip ci] Updated translations via Crowdin Add alphabetical project sorting (go-gitea#33504) Refactor gitdiff test (go-gitea#33507)
2 parents 6b2b9ca + 1ec8d80 commit 34a84af

Some content is hidden

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

60 files changed

+1216
-576
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,4 @@ Kemal Zebari <[email protected]> (@kemzeb)
6363
Rowan Bohde <[email protected]> (@bohde)
6464
hiifong <[email protected]> (@hiifong)
6565
metiftikci <[email protected]> (@metiftikci)
66+
Christopher Homberger <[email protected]> (@ChristopherHX)

models/project/project.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ func GetSearchOrderByBySortType(sortType string) db.SearchOrderBy {
244244
return db.SearchOrderByRecentUpdated
245245
case "leastupdate":
246246
return db.SearchOrderByLeastUpdated
247+
case "alphabetically":
248+
return "title ASC"
249+
case "reversealphabetically":
250+
return "title DESC"
247251
default:
248252
return db.SearchOrderByNewest
249253
}

modules/git/parse.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,9 @@ func parseLsTreeLine(line []byte) (*LsTreeEntry, error) {
4646
entry.Size = optional.Some(size)
4747
}
4848

49-
switch string(entryMode) {
50-
case "100644":
51-
entry.EntryMode = EntryModeBlob
52-
case "100755":
53-
entry.EntryMode = EntryModeExec
54-
case "120000":
55-
entry.EntryMode = EntryModeSymlink
56-
case "160000":
57-
entry.EntryMode = EntryModeCommit
58-
case "040000", "040755": // git uses 040000 for tree object, but some users may get 040755 for unknown reasons
59-
entry.EntryMode = EntryModeTree
60-
default:
61-
return nil, fmt.Errorf("unknown type: %v", string(entryMode))
49+
entry.EntryMode, err = ParseEntryMode(string(entryMode))
50+
if err != nil || entry.EntryMode == EntryModeNoEntry {
51+
return nil, fmt.Errorf("invalid ls-tree output (invalid mode): %q, err: %w", line, err)
6252
}
6353

6454
entry.ID, err = NewIDFromString(string(entryObjectID))

modules/git/tree_entry_mode.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@
33

44
package git
55

6-
import "strconv"
6+
import (
7+
"fmt"
8+
"strconv"
9+
)
710

811
// EntryMode the type of the object in the git tree
912
type EntryMode int
1013

1114
// There are only a few file modes in Git. They look like unix file modes, but they can only be
1215
// one of these.
1316
const (
17+
// EntryModeNoEntry is possible if the file was added or removed in a commit. In the case of
18+
// added the base commit will not have the file in its tree so a mode of 0o000000 is used.
19+
EntryModeNoEntry EntryMode = 0o000000
1420
// EntryModeBlob
1521
EntryModeBlob EntryMode = 0o100644
1622
// EntryModeExec
@@ -33,3 +39,22 @@ func ToEntryMode(value string) EntryMode {
3339
v, _ := strconv.ParseInt(value, 8, 32)
3440
return EntryMode(v)
3541
}
42+
43+
func ParseEntryMode(mode string) (EntryMode, error) {
44+
switch mode {
45+
case "000000":
46+
return EntryModeNoEntry, nil
47+
case "100644":
48+
return EntryModeBlob, nil
49+
case "100755":
50+
return EntryModeExec, nil
51+
case "120000":
52+
return EntryModeSymlink, nil
53+
case "160000":
54+
return EntryModeCommit, nil
55+
case "040000", "040755": // git uses 040000 for tree object, but some users may get 040755 for unknown reasons
56+
return EntryModeTree, nil
57+
default:
58+
return 0, fmt.Errorf("unparsable entry mode: %s", mode)
59+
}
60+
}

modules/migration/downloader.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ import (
1212

1313
// Downloader downloads the site repo information
1414
type Downloader interface {
15-
SetContext(context.Context)
16-
GetRepoInfo() (*Repository, error)
17-
GetTopics() ([]string, error)
18-
GetMilestones() ([]*Milestone, error)
19-
GetReleases() ([]*Release, error)
20-
GetLabels() ([]*Label, error)
21-
GetIssues(page, perPage int) ([]*Issue, bool, error)
22-
GetComments(commentable Commentable) ([]*Comment, bool, error)
23-
GetAllComments(page, perPage int) ([]*Comment, bool, error)
15+
GetRepoInfo(ctx context.Context) (*Repository, error)
16+
GetTopics(ctx context.Context) ([]string, error)
17+
GetMilestones(ctx context.Context) ([]*Milestone, error)
18+
GetReleases(ctx context.Context) ([]*Release, error)
19+
GetLabels(ctx context.Context) ([]*Label, error)
20+
GetIssues(ctx context.Context, page, perPage int) ([]*Issue, bool, error)
21+
GetComments(ctx context.Context, commentable Commentable) ([]*Comment, bool, error)
22+
GetAllComments(ctx context.Context, page, perPage int) ([]*Comment, bool, error)
2423
SupportGetRepoComments() bool
25-
GetPullRequests(page, perPage int) ([]*PullRequest, bool, error)
26-
GetReviews(reviewable Reviewable) ([]*Review, error)
24+
GetPullRequests(ctx context.Context, page, perPage int) ([]*PullRequest, bool, error)
25+
GetReviews(ctx context.Context, reviewable Reviewable) ([]*Review, error)
2726
FormatCloneURL(opts MigrateOptions, remoteAddr string) (string, error)
2827
}
2928

modules/migration/null_downloader.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,56 +13,53 @@ type NullDownloader struct{}
1313

1414
var _ Downloader = &NullDownloader{}
1515

16-
// SetContext set context
17-
func (n NullDownloader) SetContext(_ context.Context) {}
18-
1916
// GetRepoInfo returns a repository information
20-
func (n NullDownloader) GetRepoInfo() (*Repository, error) {
17+
func (n NullDownloader) GetRepoInfo(_ context.Context) (*Repository, error) {
2118
return nil, ErrNotSupported{Entity: "RepoInfo"}
2219
}
2320

2421
// GetTopics return repository topics
25-
func (n NullDownloader) GetTopics() ([]string, error) {
22+
func (n NullDownloader) GetTopics(_ context.Context) ([]string, error) {
2623
return nil, ErrNotSupported{Entity: "Topics"}
2724
}
2825

2926
// GetMilestones returns milestones
30-
func (n NullDownloader) GetMilestones() ([]*Milestone, error) {
27+
func (n NullDownloader) GetMilestones(_ context.Context) ([]*Milestone, error) {
3128
return nil, ErrNotSupported{Entity: "Milestones"}
3229
}
3330

3431
// GetReleases returns releases
35-
func (n NullDownloader) GetReleases() ([]*Release, error) {
32+
func (n NullDownloader) GetReleases(_ context.Context) ([]*Release, error) {
3633
return nil, ErrNotSupported{Entity: "Releases"}
3734
}
3835

3936
// GetLabels returns labels
40-
func (n NullDownloader) GetLabels() ([]*Label, error) {
37+
func (n NullDownloader) GetLabels(_ context.Context) ([]*Label, error) {
4138
return nil, ErrNotSupported{Entity: "Labels"}
4239
}
4340

4441
// GetIssues returns issues according start and limit
45-
func (n NullDownloader) GetIssues(page, perPage int) ([]*Issue, bool, error) {
42+
func (n NullDownloader) GetIssues(_ context.Context, page, perPage int) ([]*Issue, bool, error) {
4643
return nil, false, ErrNotSupported{Entity: "Issues"}
4744
}
4845

4946
// GetComments returns comments of an issue or PR
50-
func (n NullDownloader) GetComments(commentable Commentable) ([]*Comment, bool, error) {
47+
func (n NullDownloader) GetComments(_ context.Context, commentable Commentable) ([]*Comment, bool, error) {
5148
return nil, false, ErrNotSupported{Entity: "Comments"}
5249
}
5350

5451
// GetAllComments returns paginated comments
55-
func (n NullDownloader) GetAllComments(page, perPage int) ([]*Comment, bool, error) {
52+
func (n NullDownloader) GetAllComments(_ context.Context, page, perPage int) ([]*Comment, bool, error) {
5653
return nil, false, ErrNotSupported{Entity: "AllComments"}
5754
}
5855

5956
// GetPullRequests returns pull requests according page and perPage
60-
func (n NullDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, bool, error) {
57+
func (n NullDownloader) GetPullRequests(_ context.Context, page, perPage int) ([]*PullRequest, bool, error) {
6158
return nil, false, ErrNotSupported{Entity: "PullRequests"}
6259
}
6360

6461
// GetReviews returns pull requests review
65-
func (n NullDownloader) GetReviews(reviewable Reviewable) ([]*Review, error) {
62+
func (n NullDownloader) GetReviews(_ context.Context, reviewable Reviewable) ([]*Review, error) {
6663
return nil, ErrNotSupported{Entity: "Reviews"}
6764
}
6865

modules/migration/retry_downloader.go

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,144 +49,137 @@ func (d *RetryDownloader) retry(work func() error) error {
4949
return err
5050
}
5151

52-
// SetContext set context
53-
func (d *RetryDownloader) SetContext(ctx context.Context) {
54-
d.ctx = ctx
55-
d.Downloader.SetContext(ctx)
56-
}
57-
5852
// GetRepoInfo returns a repository information with retry
59-
func (d *RetryDownloader) GetRepoInfo() (*Repository, error) {
53+
func (d *RetryDownloader) GetRepoInfo(ctx context.Context) (*Repository, error) {
6054
var (
6155
repo *Repository
6256
err error
6357
)
6458

6559
err = d.retry(func() error {
66-
repo, err = d.Downloader.GetRepoInfo()
60+
repo, err = d.Downloader.GetRepoInfo(ctx)
6761
return err
6862
})
6963

7064
return repo, err
7165
}
7266

7367
// GetTopics returns a repository's topics with retry
74-
func (d *RetryDownloader) GetTopics() ([]string, error) {
68+
func (d *RetryDownloader) GetTopics(ctx context.Context) ([]string, error) {
7569
var (
7670
topics []string
7771
err error
7872
)
7973

8074
err = d.retry(func() error {
81-
topics, err = d.Downloader.GetTopics()
75+
topics, err = d.Downloader.GetTopics(ctx)
8276
return err
8377
})
8478

8579
return topics, err
8680
}
8781

8882
// GetMilestones returns a repository's milestones with retry
89-
func (d *RetryDownloader) GetMilestones() ([]*Milestone, error) {
83+
func (d *RetryDownloader) GetMilestones(ctx context.Context) ([]*Milestone, error) {
9084
var (
9185
milestones []*Milestone
9286
err error
9387
)
9488

9589
err = d.retry(func() error {
96-
milestones, err = d.Downloader.GetMilestones()
90+
milestones, err = d.Downloader.GetMilestones(ctx)
9791
return err
9892
})
9993

10094
return milestones, err
10195
}
10296

10397
// GetReleases returns a repository's releases with retry
104-
func (d *RetryDownloader) GetReleases() ([]*Release, error) {
98+
func (d *RetryDownloader) GetReleases(ctx context.Context) ([]*Release, error) {
10599
var (
106100
releases []*Release
107101
err error
108102
)
109103

110104
err = d.retry(func() error {
111-
releases, err = d.Downloader.GetReleases()
105+
releases, err = d.Downloader.GetReleases(ctx)
112106
return err
113107
})
114108

115109
return releases, err
116110
}
117111

118112
// GetLabels returns a repository's labels with retry
119-
func (d *RetryDownloader) GetLabels() ([]*Label, error) {
113+
func (d *RetryDownloader) GetLabels(ctx context.Context) ([]*Label, error) {
120114
var (
121115
labels []*Label
122116
err error
123117
)
124118

125119
err = d.retry(func() error {
126-
labels, err = d.Downloader.GetLabels()
120+
labels, err = d.Downloader.GetLabels(ctx)
127121
return err
128122
})
129123

130124
return labels, err
131125
}
132126

133127
// GetIssues returns a repository's issues with retry
134-
func (d *RetryDownloader) GetIssues(page, perPage int) ([]*Issue, bool, error) {
128+
func (d *RetryDownloader) GetIssues(ctx context.Context, page, perPage int) ([]*Issue, bool, error) {
135129
var (
136130
issues []*Issue
137131
isEnd bool
138132
err error
139133
)
140134

141135
err = d.retry(func() error {
142-
issues, isEnd, err = d.Downloader.GetIssues(page, perPage)
136+
issues, isEnd, err = d.Downloader.GetIssues(ctx, page, perPage)
143137
return err
144138
})
145139

146140
return issues, isEnd, err
147141
}
148142

149143
// GetComments returns a repository's comments with retry
150-
func (d *RetryDownloader) GetComments(commentable Commentable) ([]*Comment, bool, error) {
144+
func (d *RetryDownloader) GetComments(ctx context.Context, commentable Commentable) ([]*Comment, bool, error) {
151145
var (
152146
comments []*Comment
153147
isEnd bool
154148
err error
155149
)
156150

157151
err = d.retry(func() error {
158-
comments, isEnd, err = d.Downloader.GetComments(commentable)
152+
comments, isEnd, err = d.Downloader.GetComments(ctx, commentable)
159153
return err
160154
})
161155

162156
return comments, isEnd, err
163157
}
164158

165159
// GetPullRequests returns a repository's pull requests with retry
166-
func (d *RetryDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, bool, error) {
160+
func (d *RetryDownloader) GetPullRequests(ctx context.Context, page, perPage int) ([]*PullRequest, bool, error) {
167161
var (
168162
prs []*PullRequest
169163
err error
170164
isEnd bool
171165
)
172166

173167
err = d.retry(func() error {
174-
prs, isEnd, err = d.Downloader.GetPullRequests(page, perPage)
168+
prs, isEnd, err = d.Downloader.GetPullRequests(ctx, page, perPage)
175169
return err
176170
})
177171

178172
return prs, isEnd, err
179173
}
180174

181175
// GetReviews returns pull requests reviews
182-
func (d *RetryDownloader) GetReviews(reviewable Reviewable) ([]*Review, error) {
176+
func (d *RetryDownloader) GetReviews(ctx context.Context, reviewable Reviewable) ([]*Review, error) {
183177
var (
184178
reviews []*Review
185179
err error
186180
)
187-
188181
err = d.retry(func() error {
189-
reviews, err = d.Downloader.GetReviews(reviewable)
182+
reviews, err = d.Downloader.GetReviews(ctx, reviewable)
190183
return err
191184
})
192185

modules/migration/uploader.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44

55
package migration
66

7+
import "context"
8+
79
// Uploader uploads all the information of one repository
810
type Uploader interface {
911
MaxBatchInsertSize(tp string) int
10-
CreateRepo(repo *Repository, opts MigrateOptions) error
11-
CreateTopics(topic ...string) error
12-
CreateMilestones(milestones ...*Milestone) error
13-
CreateReleases(releases ...*Release) error
14-
SyncTags() error
15-
CreateLabels(labels ...*Label) error
16-
CreateIssues(issues ...*Issue) error
17-
CreateComments(comments ...*Comment) error
18-
CreatePullRequests(prs ...*PullRequest) error
19-
CreateReviews(reviews ...*Review) error
12+
CreateRepo(ctx context.Context, repo *Repository, opts MigrateOptions) error
13+
CreateTopics(ctx context.Context, topic ...string) error
14+
CreateMilestones(ctx context.Context, milestones ...*Milestone) error
15+
CreateReleases(ctx context.Context, releases ...*Release) error
16+
SyncTags(ctx context.Context) error
17+
CreateLabels(ctx context.Context, labels ...*Label) error
18+
CreateIssues(ctx context.Context, issues ...*Issue) error
19+
CreateComments(ctx context.Context, comments ...*Comment) error
20+
CreatePullRequests(ctx context.Context, prs ...*PullRequest) error
21+
CreateReviews(ctx context.Context, reviews ...*Review) error
2022
Rollback() error
21-
Finish() error
23+
Finish(ctx context.Context) error
2224
Close()
2325
}

options/locale/locale_ga-IE.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,8 @@ settings.event_fork=Forc
23302330
settings.event_fork_desc=Forcadh stóras.
23312331
settings.event_wiki=Vicí
23322332
settings.event_wiki_desc=Leathanach Vicí cruthaithe, athainmnithe, curtha in eagar nó scriosta.
2333+
settings.event_statuses=Stádais
2334+
settings.event_statuses_desc=Nuashonraíodh Stádas Commit ón API.
23332335
settings.event_release=Scaoileadh
23342336
settings.event_release_desc=Scaoileadh foilsithe, nuashonraithe nó scriosta i stóras.
23352337
settings.event_push=Brúigh

options/locale/locale_pt-PT.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2330,6 +2330,8 @@ settings.event_fork=Derivar
23302330
settings.event_fork_desc=Feita a derivação do repositório.
23312331
settings.event_wiki=Wiki
23322332
settings.event_wiki_desc=Página do wiki criada, renomeada, editada ou eliminada.
2333+
settings.event_statuses=Estados
2334+
settings.event_statuses_desc=Estado do cometimento modificado através da API.
23332335
settings.event_release=Lançamento
23342336
settings.event_release_desc=Lançamento publicado, modificado ou eliminado num repositório.
23352337
settings.event_push=Enviar

0 commit comments

Comments
 (0)