Skip to content

Commit d5fa2e7

Browse files
wxiaoguangzeripath
andauthored
Fix restore repo bug, clarify the problem of ForeignIndex (#22776)
Fix #22581 TLDR: #18446 made a mess with ForeignIndex and triggered a design flaw/bug of #16356, then a quick patch #21271 helped #18446, then the the bug was re-triggered by #21721 . Related: * #16356 * BasicIssueContext https://github.com/go-gitea/gitea/pull/16356/files#diff-7938eb670d42a5ead6b08121e16aa4537a4d716c1cf37923c70470020fb9d036R16-R27 * #18446 * If some issues were dumped without ForeignIndex, then they would be imported as ForeignIndex=0 https://github.com/go-gitea/gitea/pull/18446/files#diff-1624a3e715d8fc70edf2db1630642b7d6517f8c359cc69d58c3958b34ba4ce5eR38-R39 * #21271 * It patched the above bug (somewhat), made the issues without ForeignIndex could have the same value as LocalIndex * #21721 * It re-triggered the zero-ForeignIndex bug. ps: I am not sure whether the changes in `GetForeignIndex` are ideal (at least, now it has almost the same behavior as BasicIssueContext in #16356), it's just a quick fix. Feel free to edit on this PR directly or replace it. Co-authored-by: zeripath <art27@cantab.net>
1 parent 3ae78bc commit d5fa2e7

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

modules/migration/comment.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import "time"
88

99
// Commentable can be commented upon
1010
type Commentable interface {
11-
GetLocalIndex() int64
12-
GetForeignIndex() int64
11+
Reviewable
1312
GetContext() DownloaderContext
1413
}
1514

modules/migration/issue.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ func (issue *Issue) GetExternalName() string { return issue.PosterName }
3434
// GetExternalID ExternalUserMigrated interface
3535
func (issue *Issue) GetExternalID() int64 { return issue.PosterID }
3636

37-
func (issue *Issue) GetLocalIndex() int64 { return issue.Number }
38-
func (issue *Issue) GetForeignIndex() int64 { return issue.ForeignIndex }
37+
func (issue *Issue) GetLocalIndex() int64 { return issue.Number }
38+
39+
func (issue *Issue) GetForeignIndex() int64 {
40+
// see the comment of Reviewable.GetForeignIndex
41+
// if there is no ForeignIndex, then use LocalIndex
42+
if issue.ForeignIndex == 0 {
43+
return issue.Number
44+
}
45+
return issue.ForeignIndex
46+
}
47+
3948
func (issue *Issue) GetContext() DownloaderContext { return issue.Context }

modules/migration/review.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ import "time"
88
// Reviewable can be reviewed
99
type Reviewable interface {
1010
GetLocalIndex() int64
11+
12+
// GetForeignIndex presents the foreign index, which could be misused:
13+
// For example, if there are 2 Gitea sites: site-A exports a dataset, then site-B imports it:
14+
// * if site-A exports files by using its LocalIndex
15+
// * from site-A's view, LocalIndex is site-A's IssueIndex while ForeignIndex is site-B's IssueIndex
16+
// * but from site-B's view, LocalIndex is site-B's IssueIndex while ForeignIndex is site-A's IssueIndex
17+
//
18+
// So the exporting/importing must be paired, but the meaning of them looks confusing then:
19+
// * either site-A and site-B both use LocalIndex during dumping/restoring
20+
// * or site-A and site-B both use ForeignIndex
1121
GetForeignIndex() int64
1222
}
1323

@@ -37,7 +47,7 @@ type Review struct {
3747
// GetExternalName ExternalUserMigrated interface
3848
func (r *Review) GetExternalName() string { return r.ReviewerName }
3949

40-
// ExternalID ExternalUserMigrated interface
50+
// GetExternalID ExternalUserMigrated interface
4151
func (r *Review) GetExternalID() int64 { return r.ReviewerID }
4252

4353
// ReviewComment represents a review comment

0 commit comments

Comments
 (0)