Skip to content
Closed
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
274ed54
feat: phase 1 changes: add comments feat to unchanged lines in the pu…
rajesh-jonnalagadda Nov 11, 2024
914bed8
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 11, 2024
abd1d2f
chore: fix lint issues
rajesh-jonnalagadda Nov 11, 2024
f03359e
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 11, 2024
a03abb5
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 11, 2024
ccd797a
chore: fixed the tmpl lint issues
rajesh-jonnalagadda Nov 11, 2024
efba6c4
chore: remove issue index and minro template changes
rajesh-jonnalagadda Nov 11, 2024
28c512d
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 12, 2024
e41d7f8
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 12, 2024
d9aa349
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 13, 2024
b387e41
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 14, 2024
f5a83a7
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 18, 2024
a8ace20
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 22, 2024
7f0c5e4
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 23, 2024
2db63b1
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 24, 2024
fa4c61e
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 26, 2024
40826dd
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 26, 2024
7d0c8e3
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 27, 2024
0f6708c
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 27, 2024
ea285c2
chore: fix the extra comment icon at the end and change the icon pointer
rajesh-jonnalagadda Nov 27, 2024
d36fece
Merge branch 'feat-32257-add-comments-unchanged-lines-and-show' of gi…
rajesh-jonnalagadda Nov 27, 2024
819dd08
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 28, 2024
5d9651b
chore: fix the comment context menu drop down
rajesh-jonnalagadda Nov 28, 2024
17deb2c
Merge branch 'feat-32257-add-comments-unchanged-lines-and-show' of gi…
rajesh-jonnalagadda Nov 28, 2024
65ef174
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 28, 2024
728fc12
chore: fix backedn-lint issues
rajesh-jonnalagadda Nov 28, 2024
24da8ef
Merge branch 'feat-32257-add-comments-unchanged-lines-and-show' of gi…
rajesh-jonnalagadda Nov 28, 2024
bf3535a
chore: fix lint issue
rajesh-jonnalagadda Nov 28, 2024
904fb52
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Nov 29, 2024
e6e314b
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 2, 2024
bcaf4aa
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 2, 2024
c1e4d57
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 4, 2024
5289da2
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 5, 2024
510d8ba
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 5, 2024
649201d
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 6, 2024
50bab1b
chore: remove the add comment on the line section. fix the hsaComment…
rajesh-jonnalagadda Dec 6, 2024
780d483
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 6, 2024
f8197d7
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 6, 2024
959e149
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 7, 2024
b5531f8
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 9, 2024
67343d6
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 9, 2024
96849dd
chore: handle feedback
rajesh-jonnalagadda Dec 10, 2024
2413513
Merge branch 'feat-32257-add-comments-unchanged-lines-and-show' of gi…
rajesh-jonnalagadda Dec 10, 2024
5dd1004
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 10, 2024
51a70e3
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 11, 2024
8d6b3c3
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 13, 2024
d8eeb08
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 16, 2024
aefc475
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Dec 22, 2024
fe0efb8
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Feb 21, 2025
646d2c3
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Feb 22, 2025
0ef3d06
Merge remote-tracking branch 'origin' into feat-32257-add-comments-un…
rajesh-jonnalagadda Mar 2, 2025
a68fbd5
chore: remove unwanted class in script
rajesh-jonnalagadda Mar 2, 2025
b4836dd
Merge branch 'feat-32258-add-comments-unchanged-lines-and-show' of gi…
rajesh-jonnalagadda Mar 2, 2025
ebad7a3
chore: fix lint issues
rajesh-jonnalagadda Mar 2, 2025
38b0d57
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Mar 3, 2025
c5aa6db
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Mar 5, 2025
df2ee8b
chore: resolve conflict
rajesh-jonnalagadda Mar 5, 2025
9515007
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Mar 5, 2025
b06d3c1
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Apr 8, 2025
419c15b
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Apr 12, 2025
e9dd2ea
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Apr 17, 2025
29dcbda
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Apr 25, 2025
c71abf2
Merge branch 'main' into feat-32257-add-comments-unchanged-lines-and-…
rajesh-jonnalagadda Jun 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 78 additions & 7 deletions routers/web/repo/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"net/http"
"net/url"
"path/filepath"
"sort"
"strings"

"code.gitea.io/gitea/models/db"
Expand All @@ -39,6 +40,7 @@ import (
"code.gitea.io/gitea/services/context"
"code.gitea.io/gitea/services/context/upload"
"code.gitea.io/gitea/services/gitdiff"
user_service "code.gitea.io/gitea/services/user"
)

const (
Expand Down Expand Up @@ -863,6 +865,10 @@ func ExcerptBlob(ctx *context.Context) {
direction := ctx.FormString("direction")
filePath := ctx.FormString("path")
gitRepo := ctx.Repo.GitRepo
if ctx.FormBool("pull") {
ctx.Data["PageIsPullFiles"] = true
}

if ctx.FormBool("wiki") {
var err error
gitRepo, err = gitrepo.OpenWikiRepository(ctx, ctx.Repo.Repository)
Expand All @@ -881,6 +887,7 @@ func ExcerptBlob(ctx *context.Context) {
section := &gitdiff.DiffSection{
FileName: filePath,
Name: filePath,
Lines: []*gitdiff.DiffLine{},
}
if direction == "up" && (idxLeft-lastLeft) > chunkSize {
idxLeft -= chunkSize
Expand Down Expand Up @@ -917,25 +924,88 @@ func ExcerptBlob(ctx *context.Context) {
Type: gitdiff.DiffLineSection,
Content: lineText,
SectionInfo: &gitdiff.DiffLineSectionInfo{
Path: filePath,
LastLeftIdx: lastLeft,
LastRightIdx: lastRight,
LeftIdx: idxLeft,
RightIdx: idxRight,
LeftHunkSize: leftHunkSize,
RightHunkSize: rightHunkSize,
Path: filePath,
LastLeftIdx: lastLeft,
LastRightIdx: lastRight,
LeftIdx: idxLeft,
RightIdx: idxRight,
LeftHunkSize: leftHunkSize,
RightHunkSize: rightHunkSize,
HasComments: false,
LastRightCommentIdx: 0,
RightCommentIdx: 0,
},
Comments: nil,
}
if direction == "up" {
section.Lines = append([]*gitdiff.DiffLine{lineSection}, section.Lines...)
} else if direction == "down" {
section.Lines = append(section.Lines, lineSection)
}
}
issueIndex := ctx.FormInt64("issue_index")
if ctx.FormBool("pull") && issueIndex > 0 {
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, issueIndex)
if issue == nil {
ctx.ServerError("GetIssueByIndex", err)
return
}
allComments, err := issues_model.FetchCodeComments(ctx, issue, ctx.Doer, false)
if err != nil {
ctx.ServerError("FetchCodeComments", err)
return
}
lineCommits := allComments[filePath]
for index, line := range section.Lines {
if line.SectionInfo != nil && line.Type == 4 && !(line.SectionInfo.LastRightIdx == 0 && index+1 == len(section.Lines)) {
start := int64(line.SectionInfo.LastRightIdx + 1)
end := int64(line.SectionInfo.RightIdx - 1)
for start <= end {
if _, ok := lineCommits[start]; ok {
if !line.SectionInfo.HasComments {
line.SectionInfo.HasComments = true
break
}
}
start++
}
}
if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
line.Comments = append(line.Comments, comments...)
}
if comments, ok := lineCommits[int64(line.RightIdx)]; ok {
line.Comments = append(line.Comments, comments...)
}

sort.SliceStable(line.Comments, func(i, j int) bool {
return line.Comments[i].CreatedUnix < line.Comments[j].CreatedUnix
})
}
for _, line := range section.Lines {
for _, comment := range line.Comments {
if err := comment.LoadAttachments(ctx); err != nil {
ctx.ServerError("LoadAttachments", err)
return
}
}
}
ctx.Data["Issue"] = issue
ctx.Data["IssueIndex"] = issue.Index
}
ctx.Data["section"] = section
ctx.Data["FileNameHash"] = git.HashFilePathForWebUI(filePath)
ctx.Data["AfterCommitID"] = commitID
ctx.Data["Anchor"] = anchor
ctx.Data["CanBlockUser"] = func(blocker, blockee *user_model.User) bool {
return user_service.CanBlockUser(ctx, ctx.Doer, blocker, blockee)
}
if ctx.Data["SignedUserID"] == nil {
ctx.Data["SignedUserID"] = ctx.Doer.ID
}
ctx.Data["SignedUser"] = ctx.Doer
ctx.Data["IsSigned"] = ctx.Doer != nil
ctx.Data["Repository"] = ctx.Repo.Repository
ctx.Data["Permission"] = &ctx.Repo.Permission
ctx.HTML(http.StatusOK, tplBlobExcerpt)
}

Expand Down Expand Up @@ -964,6 +1034,7 @@ func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chu
RightIdx: line + 1,
Type: gitdiff.DiffLinePlain,
Content: " " + lineText,
Comments: []*issues_model.Comment{},
}
diffLines = append(diffLines, diffLine)
}
Expand Down
1 change: 1 addition & 0 deletions routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func getPullInfo(ctx *context.Context) (issue *issues_model.Issue, ok bool) {
}
ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, emoji.ReplaceAliases(issue.Title))
ctx.Data["Issue"] = issue
ctx.Data["IssueIndex"] = issue.Index

if !issue.IsPull {
ctx.NotFound("ViewPullCommits", nil)
Expand Down
4 changes: 4 additions & 0 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,10 @@ func registerRoutes(m *web.Router) {
m.Get("/{sha}", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.ExcerptBlob)
}, func(ctx *context.Context) gocontext.CancelFunc {
// FIXME: refactor this function, use separate routes for wiki/code
if ctx.FormBool("pull") {
ctx.Data["PageIsPullFiles"] = true
}

if ctx.FormBool("wiki") {
ctx.Data["PageIsWiki"] = true
repo.MustEnableWiki(ctx)
Expand Down
67 changes: 47 additions & 20 deletions services/gitdiff/gitdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,16 @@ type DiffLine struct {

// DiffLineSectionInfo represents diff line section meta data
type DiffLineSectionInfo struct {
Path string
LastLeftIdx int
LastRightIdx int
LeftIdx int
RightIdx int
LeftHunkSize int
RightHunkSize int
Path string
LastLeftIdx int
LastRightIdx int
LeftIdx int
RightIdx int
LeftHunkSize int
RightHunkSize int
HasComments bool
LastRightCommentIdx int
RightCommentIdx int
}

// BlobExcerptChunkSize represent max lines of excerpt
Expand Down Expand Up @@ -143,10 +146,12 @@ func (d *DiffLine) GetBlobExcerptQuery() string {
"last_left=%d&last_right=%d&"+
"left=%d&right=%d&"+
"left_hunk_size=%d&right_hunk_size=%d&"+
"last_rightt_comment_idx=%d&right_comment_idx=%d&"+
"path=%s",
d.SectionInfo.LastLeftIdx, d.SectionInfo.LastRightIdx,
d.SectionInfo.LeftIdx, d.SectionInfo.RightIdx,
d.SectionInfo.LeftHunkSize, d.SectionInfo.RightHunkSize,
d.SectionInfo.LastRightCommentIdx, d.SectionInfo.RightCommentIdx,
url.QueryEscape(d.SectionInfo.Path))
return query
}
Expand All @@ -170,13 +175,16 @@ func getDiffLineSectionInfo(treePath, line string, lastLeftIdx, lastRightIdx int
leftLine, leftHunk, rightLine, righHunk := git.ParseDiffHunkString(line)

return &DiffLineSectionInfo{
Path: treePath,
LastLeftIdx: lastLeftIdx,
LastRightIdx: lastRightIdx,
LeftIdx: leftLine,
RightIdx: rightLine,
LeftHunkSize: leftHunk,
RightHunkSize: righHunk,
Path: treePath,
LastLeftIdx: lastLeftIdx,
LastRightIdx: lastRightIdx,
LeftIdx: leftLine,
RightIdx: rightLine,
LeftHunkSize: leftHunk,
RightHunkSize: righHunk,
HasComments: false,
LastRightCommentIdx: 0,
RightCommentIdx: 0,
}
}

Expand Down Expand Up @@ -396,11 +404,14 @@ func (diffFile *DiffFile) GetTailSection(gitRepo *git.Repository, leftCommit, ri
Type: DiffLineSection,
Content: " ",
SectionInfo: &DiffLineSectionInfo{
Path: diffFile.Name,
LastLeftIdx: lastLine.LeftIdx,
LastRightIdx: lastLine.RightIdx,
LeftIdx: leftLineCount,
RightIdx: rightLineCount,
Path: diffFile.Name,
LastLeftIdx: lastLine.LeftIdx,
LastRightIdx: lastLine.RightIdx,
LeftIdx: leftLineCount,
RightIdx: rightLineCount,
HasComments: false,
LastRightCommentIdx: 0,
RightCommentIdx: 0,
},
}
tailSection := &DiffSection{FileName: diffFile.Name, Lines: []*DiffLine{tailDiffLine}}
Expand Down Expand Up @@ -458,16 +469,32 @@ type Diff struct {
NumViewedFiles int // user-specific
}

// function (section *DiffSection) GetType() int {

// LoadComments loads comments into each line
func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, currentUser *user_model.User, showOutdatedComments bool) error {
allComments, err := issues_model.FetchCodeComments(ctx, issue, currentUser, showOutdatedComments)
if err != nil {
return err
}

for _, file := range diff.Files {
if lineCommits, ok := allComments[file.Name]; ok {
for _, section := range file.Sections {
for _, line := range section.Lines {
for index, line := range section.Lines {
if line.SectionInfo != nil && line.Type == 4 && !(line.SectionInfo.LastRightIdx == 0 && index+1 == len(section.Lines)) {
start := int64(line.SectionInfo.LastRightIdx + 1)
end := int64(line.SectionInfo.RightIdx - 1)
for start <= end {
if _, ok := lineCommits[start]; ok {
if !line.SectionInfo.HasComments {
line.SectionInfo.HasComments = true
break
}
}
start++
}
}
if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
line.Comments = append(line.Comments, comments...)
}
Expand Down
17 changes: 10 additions & 7 deletions services/repository/files/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ func TestGetDiffPreview(t *testing.T) {
Content: "@@ -1,3 +1,4 @@",
Comments: nil,
SectionInfo: &gitdiff.DiffLineSectionInfo{
Path: "README.md",
LastLeftIdx: 0,
LastRightIdx: 0,
LeftIdx: 1,
RightIdx: 1,
LeftHunkSize: 3,
RightHunkSize: 4,
Path: "README.md",
LastLeftIdx: 0,
LastRightIdx: 0,
LeftIdx: 1,
RightIdx: 1,
LeftHunkSize: 3,
RightHunkSize: 4,
HasComments: false,
LastRightCommentIdx: 0,
RightCommentIdx: 0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test which has the comment.

},
},
{
Expand Down
Loading
Loading