diff --git a/modelmigration/migrations.go b/modelmigration/migrations.go index c160e7f1938..f1e0fc25bed 100644 --- a/modelmigration/migrations.go +++ b/modelmigration/migrations.go @@ -437,6 +437,7 @@ func prepareMigrationTasks() []*migration { newMigration(358, "Track previous remember-me token hashes", v29.AddPreviousAuthTokenHash), newMigration(359, "Add stage and number columns to action_task_step", v29.AddStageAndNumberToActionTaskStep), newMigration(360, "Move branch protection settings to JSON", v29.MoveBranchProtectionConfigToJSON), + newMigration(361, "Drop legacy commit_id column from comment", v29.DropCommentCommitID), } return preparedMigrations } diff --git a/modelmigration/v29/v361.go b/modelmigration/v29/v361.go new file mode 100644 index 00000000000..985efce0b0c --- /dev/null +++ b/modelmigration/v29/v361.go @@ -0,0 +1,21 @@ +// Copyright 2026 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v29 + +import ( + "context" + + "gitea.dev/modelmigration/base" +) + +func DropCommentCommitID(ctx context.Context, x base.EngineMigration) error { + exists, err := x.Dialect().IsColumnExist(x.DB(), ctx, "comment", "commit_id") + if err != nil || !exists { + return err + } + + return base.EngineTransaction(x, func(sess base.Session) error { + return base.DropTableColumns(sess, "comment", "commit_id") + }) +} diff --git a/modules/templates/util_dict.go b/modules/templates/util_dict.go index 09dc838d6bf..127e906ef52 100644 --- a/modules/templates/util_dict.go +++ b/modules/templates/util_dict.go @@ -15,23 +15,7 @@ import ( "gitea.dev/modules/setting" ) -func dictMerge(base map[string]any, arg any) bool { - if arg == nil { - return true - } - rv := reflect.ValueOf(arg) - if rv.Kind() == reflect.Map { - for _, k := range rv.MapKeys() { - base[k.String()] = rv.MapIndex(k).Interface() - } - return true - } - return false -} - // dict is a helper function for creating a map[string]any from a list of key-value pairs. -// If the key is dot ".", the value is merged into the base map, just like Golang template's dot syntax: dot means current -// The dot syntax is highly discouraged because it might cause unclear key conflicts. It's always good to use explicit keys. func dict(args ...any) (map[string]any, error) { if len(args)%2 != 0 { return nil, errors.New("invalid dict constructor syntax: must have key-value pairs") @@ -42,13 +26,7 @@ func dict(args ...any) (map[string]any, error) { if !ok { return nil, fmt.Errorf("invalid dict constructor syntax: unable to merge args[%d]", i) } - if key == "." { - if ok = dictMerge(m, args[i+1]); !ok { - return nil, fmt.Errorf("invalid dict constructor syntax: dot arg[%d] must be followed by a dict", i) - } - } else { - m[key] = args[i+1] - } + m[key] = args[i+1] } return m, nil } diff --git a/modules/templates/util_test.go b/modules/templates/util_test.go index 88b05485af0..608a8f230a8 100644 --- a/modules/templates/util_test.go +++ b/modules/templates/util_test.go @@ -18,18 +18,17 @@ func TestDict(t *testing.T) { args []any want map[string]any }{ + {nil, M{}}, + {[]any{"a", nil}, M{"a": nil}}, {[]any{"a", 1, "b", 2}, M{"a": 1, "b": 2}}, - {[]any{".", M{"base": 1}, "b", 2}, M{"base": 1, "b": 2}}, - {[]any{"a", 1, ".", M{"extra": 2}}, M{"a": 1, "extra": 2}}, - {[]any{"a", 1, ".", map[string]int{"int": 2}}, M{"a": 1, "int": 2}}, - {[]any{".", nil, "b", 2}, M{"b": 2}}, + {[]any{"a", 1, "a", 2}, M{"a": 2}}, + {[]any{"nested", map[string]int{"int": 2}}, M{"nested": map[string]int{"int": 2}}}, } for _, c := range cases { got, err := dict(c.args...) - if assert.NoError(t, err) { - assert.Equal(t, c.want, got) - } + assert.NoError(t, err) + assert.Equal(t, c.want, got) } bads := []struct { @@ -38,6 +37,7 @@ func TestDict(t *testing.T) { {[]any{"a", 1, "b"}}, {[]any{1}}, {[]any{struct{}{}}}, + {[]any{1, "value"}}, } for _, c := range bads { _, err := dict(c.args...) diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index ad7fc8906b6..65914bc117f 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -142,12 +142,13 @@ const ( MaxFullFileHighlightTimeLimit = 2 * time.Second ) -// GetType returns the type of DiffLine. -func (d *DiffLine) GetType() int { - return int(d.Type) -} +func (d *DiffLine) IsDiffLinePlain() bool { return d.Type == DiffLinePlain } +func (d *DiffLine) IsDiffLineAdd() bool { return d.Type == DiffLineAdd } +func (d *DiffLine) IsDiffLineDel() bool { return d.Type == DiffLineDel } +func (d *DiffLine) IsDiffLineSection() bool { return d.Type == DiffLineSection } -// GetHTMLDiffLineType returns the diff line type name for HTML +// GetHTMLDiffLineType returns the diff line type name for HTML, +// it will generate CSS names for styles ".del-code", ".add-code", ".same-code", ".tag-code" func (d *DiffLine) GetHTMLDiffLineType() string { switch d.Type { case DiffLineAdd: diff --git a/templates/repo/diff/blob_excerpt.tmpl b/templates/repo/diff/blob_excerpt.tmpl index a2dcf0d0910..da6c6cd9f55 100644 --- a/templates/repo/diff/blob_excerpt.tmpl +++ b/templates/repo/diff/blob_excerpt.tmpl @@ -1,9 +1,9 @@ {{$diffBlobExcerptData := .DiffBlobExcerptData}} {{$canCreateComment := and ctx.RootData.SignedUserID $diffBlobExcerptData.PullIssueIndex}} {{if $.IsSplitStyle}} - {{range $k, $line := $.section.Lines}} -