-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Also sync DB branches on push if necessary #28361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
1856b43
083ab55
a036d14
f413a5f
c28c7c5
18646a2
a3d8eb1
e6146c0
dc7828e
68698fe
c6874c7
72669dc
f4f4bc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ package repository | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
git_model "code.gitea.io/gitea/models/git" | ||
|
@@ -13,8 +14,45 @@ import ( | |
"code.gitea.io/gitea/modules/git" | ||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/timeutil" | ||
"code.gitea.io/gitea/modules/util" | ||
) | ||
|
||
// UpdateBranch updates the branch information in the database. If the branch exist, it will update latest commit of this branch information | ||
// If it doest not exist, insert a new record into database | ||
func UpdateBranch(ctx context.Context, repoID, pusherID int64, branchName string, commit *git.Commit) error { | ||
cnt, err := git_model.UpdateBranch(ctx, repoID, pusherID, branchName, commit) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That function is completely wrong here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you think that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. I move the function to service layer and renamed function name to |
||
if err != nil { | ||
return fmt.Errorf("git_model.UpdateBranch %d:%s failed: %v", repoID, branchName, err) | ||
} | ||
if cnt > 0 { // if branch does exist, so it's a normal update | ||
return nil | ||
} | ||
|
||
// if user haven't visit UI but directly push to a branch after upgrading from 1.20 -> 1.21, | ||
// we cannot simply insert the branch but need to check we have branches or not | ||
totalBranches, err := db.Count[git_model.Branch](ctx, &git_model.FindBranchOptions{ | ||
RepoID: repoID, | ||
IsDeletedBranch: util.OptionalBoolFalse, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
if totalBranches == 0 { | ||
lunny marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if _, err = SyncRepoBranches(ctx, repoID, pusherID); err != nil { | ||
return fmt.Errorf("repo_module.SyncRepoBranches %d:%s failed: %v", repoID, branchName, err) | ||
} | ||
return nil | ||
} | ||
return db.Insert(ctx, &git_model.Branch{ | ||
RepoID: repoID, | ||
Name: branchName, | ||
CommitID: commit.ID.String(), | ||
CommitMessage: commit.Summary(), | ||
PusherID: pusherID, | ||
CommitTime: timeutil.TimeStamp(commit.Committer.When.Unix()), | ||
}) | ||
} | ||
|
||
// SyncRepoBranches synchronizes branch table with repository branches | ||
func SyncRepoBranches(ctx context.Context, repoID, doerID int64) (int64, error) { | ||
repo, err := repo_model.GetRepositoryByID(ctx, repoID) | ||
|
Uh oh!
There was an error while loading. Please reload this page.