Skip to content

Commit 2653ac9

Browse files
lunnywxiaoguangGiteaBot
authored
Extend comment treepath length (go-gitea#35389)
Extend the maximum length of comment.treepath from 255 to 4000 characters. All databases supported by Gitea allow VARCHAR fields of 4000, so compatibility is ensured. Git itself does not impose a strict limit on path length. On Windows, the `core.longpaths` setting has already been enabled to handle long file paths. Fix go-gitea#33716 --------- Signed-off-by: wxiaoguang <[email protected]> Co-authored-by: wxiaoguang <[email protected]> Co-authored-by: Giteabot <[email protected]>
1 parent b76e69f commit 2653ac9

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

models/issues/comment.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ type Comment struct {
279279
DependentIssue *Issue `xorm:"-"`
280280

281281
CommitID int64
282-
Line int64 // - previous line / + proposed line
283-
TreePath string
282+
Line int64 // - previous line / + proposed line
283+
TreePath string `xorm:"VARCHAR(4000)"` // SQLServer only supports up to 4000
284284
Content string `xorm:"LONGTEXT"`
285285
ContentVersion int `xorm:"NOT NULL DEFAULT 0"`
286286
RenderedContent template.HTML `xorm:"-"`

models/migrations/migrations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ func prepareMigrationTasks() []*migration {
393393

394394
// Gitea 1.24.0 ends at database version 321
395395
newMigration(321, "Use LONGTEXT for some columns and fix review_state.updated_files column", v1_25.UseLongTextInSomeColumnsAndFixBugs),
396+
newMigration(322, "Extend comment tree_path length limit", v1_25.ExtendCommentTreePathLength),
396397
}
397398
return preparedMigrations
398399
}

models/migrations/v1_25/v322.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_25
5+
6+
import (
7+
"code.gitea.io/gitea/models/migrations/base"
8+
9+
"xorm.io/xorm"
10+
"xorm.io/xorm/schemas"
11+
)
12+
13+
func ExtendCommentTreePathLength(x *xorm.Engine) error {
14+
dbType := x.Dialect().URI().DBType
15+
if dbType == schemas.SQLITE { // For SQLITE, varchar or char will always be represented as TEXT
16+
return nil
17+
}
18+
19+
return base.ModifyColumn(x, "comment", &schemas.Column{
20+
Name: "tree_path",
21+
SQLType: schemas.SQLType{
22+
Name: "VARCHAR",
23+
},
24+
Length: 4000,
25+
Nullable: true, // To keep compatible as nullable
26+
DefaultIsEmpty: true,
27+
})
28+
}

0 commit comments

Comments
 (0)