diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-06-30 17:03:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-30 17:03:05 +0800 |
commit | 65acd1e9ef9eda01fd9b07a72abafa2d7bf83435 (patch) | |
tree | e15f850f961783510651a1eb8cb50b4d0b4091ae /models/git | |
parent | 67bd9d4f1eedb4728031504d0dd09d014c0f3e6f (diff) | |
download | gitea-65acd1e9ef9eda01fd9b07a72abafa2d7bf83435.tar.gz gitea-65acd1e9ef9eda01fd9b07a72abafa2d7bf83435.zip |
Fix branch commit message too long problem (#25588)
When branch's commit CommitMessage is too long, the column maybe too
short.(TEXT 16K for mysql).
This PR will fix it to only store the summary because these message will
only show on branch list or possible future search?
Diffstat (limited to 'models/git')
-rw-r--r-- | models/git/branch.go | 15 | ||||
-rw-r--r-- | models/git/branch_test.go | 11 |
2 files changed, 18 insertions, 8 deletions
diff --git a/models/git/branch.go b/models/git/branch.go index adf8b0a78d..255b230b51 100644 --- a/models/git/branch.go +++ b/models/git/branch.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models/db" repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" @@ -204,14 +205,14 @@ func DeleteBranches(ctx context.Context, repoID, doerID int64, branchIDs []int64 // 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 int64, branchName, commitID, commitMessage string, pusherID int64, commitTime time.Time) error { +func UpdateBranch(ctx context.Context, repoID, pusherID int64, branchName string, commit *git.Commit) error { cnt, err := db.GetEngine(ctx).Where("repo_id=? AND name=?", repoID, branchName). Cols("commit_id, commit_message, pusher_id, commit_time, is_deleted, updated_unix"). Update(&Branch{ - CommitID: commitID, - CommitMessage: commitMessage, + CommitID: commit.ID.String(), + CommitMessage: commit.Summary(), PusherID: pusherID, - CommitTime: timeutil.TimeStamp(commitTime.Unix()), + CommitTime: timeutil.TimeStamp(commit.Committer.When.Unix()), IsDeleted: false, }) if err != nil { @@ -224,10 +225,10 @@ func UpdateBranch(ctx context.Context, repoID int64, branchName, commitID, commi return db.Insert(ctx, &Branch{ RepoID: repoID, Name: branchName, - CommitID: commitID, - CommitMessage: commitMessage, + CommitID: commit.ID.String(), + CommitMessage: commit.Summary(), PusherID: pusherID, - CommitTime: timeutil.TimeStamp(commitTime.Unix()), + CommitTime: timeutil.TimeStamp(commit.Committer.When.Unix()), }) } diff --git a/models/git/branch_test.go b/models/git/branch_test.go index bb63660d07..ba69026927 100644 --- a/models/git/branch_test.go +++ b/models/git/branch_test.go @@ -11,6 +11,7 @@ import ( issues_model "code.gitea.io/gitea/models/issues" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/util" "github.com/stretchr/testify/assert" @@ -28,7 +29,15 @@ func TestAddDeletedBranch(t *testing.T) { secondBranch := unittest.AssertExistsAndLoadBean(t, &git_model.Branch{RepoID: repo.ID, Name: "branch2"}) assert.True(t, secondBranch.IsDeleted) - err := git_model.UpdateBranch(db.DefaultContext, repo.ID, secondBranch.Name, secondBranch.CommitID, secondBranch.CommitMessage, secondBranch.PusherID, secondBranch.CommitTime.AsLocalTime()) + commit := &git.Commit{ + ID: git.MustIDFromString(secondBranch.CommitID), + CommitMessage: secondBranch.CommitMessage, + Committer: &git.Signature{ + When: secondBranch.CommitTime.AsLocalTime(), + }, + } + + err := git_model.UpdateBranch(db.DefaultContext, repo.ID, secondBranch.PusherID, secondBranch.Name, commit) assert.NoError(t, err) } |