mirror of
https://github.com/go-gitea/gitea.git
synced 2025-12-17 00:36:14 +01:00
chore: fix lint issues
This commit is contained in:
parent
914bed86ab
commit
abd1d2f770
@ -865,10 +865,7 @@ func ExcerptBlob(ctx *context.Context) {
|
|||||||
direction := ctx.FormString("direction")
|
direction := ctx.FormString("direction")
|
||||||
filePath := ctx.FormString("path")
|
filePath := ctx.FormString("path")
|
||||||
gitRepo := ctx.Repo.GitRepo
|
gitRepo := ctx.Repo.GitRepo
|
||||||
lastRightCommentIdx := ctx.FormInt("last_left_comment_idx")
|
|
||||||
rightCommentIdx := ctx.FormInt("left_comment_idx")
|
|
||||||
fileName := ctx.FormString("file_name")
|
fileName := ctx.FormString("file_name")
|
||||||
|
|
||||||
if ctx.FormBool("pull") {
|
if ctx.FormBool("pull") {
|
||||||
ctx.Data["PageIsPullFiles"] = true
|
ctx.Data["PageIsPullFiles"] = true
|
||||||
}
|
}
|
||||||
@ -882,17 +879,17 @@ func ExcerptBlob(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
defer gitRepo.Close()
|
defer gitRepo.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, int64(2))
|
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, int64(2))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetIssueByIndex", err)
|
ctx.ServerError("GetIssueByIndex", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
allComments, err := issues_model.FetchCodeComments(ctx, issue, ctx.Doer, false)
|
allComments, err := issues_model.FetchCodeComments(ctx, issue, ctx.Doer, false)
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("FetchCodeComments", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
lineCommits := allComments[fileName]
|
lineCommits := allComments[fileName]
|
||||||
|
|
||||||
chunkSize := gitdiff.BlobExcerptChunkSize
|
chunkSize := gitdiff.BlobExcerptChunkSize
|
||||||
commit, err := gitRepo.GetCommit(commitID)
|
commit, err := gitRepo.GetCommit(commitID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -909,9 +906,9 @@ func ExcerptBlob(ctx *context.Context) {
|
|||||||
idxRight -= chunkSize
|
idxRight -= chunkSize
|
||||||
leftHunkSize += chunkSize
|
leftHunkSize += chunkSize
|
||||||
rightHunkSize += chunkSize
|
rightHunkSize += chunkSize
|
||||||
section.Lines, err = getExcerptLines(commit, filePath, idxLeft-1, idxRight-1, chunkSize, lastRightCommentIdx, rightCommentIdx)
|
section.Lines, err = getExcerptLines(commit, filePath, idxLeft-1, idxRight-1, chunkSize)
|
||||||
} else if direction == "down" && (idxLeft-lastLeft) > chunkSize {
|
} else if direction == "down" && (idxLeft-lastLeft) > chunkSize {
|
||||||
section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, chunkSize, lastRightCommentIdx, rightCommentIdx)
|
section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, chunkSize)
|
||||||
lastLeft += chunkSize
|
lastLeft += chunkSize
|
||||||
lastRight += chunkSize
|
lastRight += chunkSize
|
||||||
} else {
|
} else {
|
||||||
@ -919,7 +916,7 @@ func ExcerptBlob(ctx *context.Context) {
|
|||||||
if direction == "down" {
|
if direction == "down" {
|
||||||
offset = 0
|
offset = 0
|
||||||
}
|
}
|
||||||
section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, idxRight-lastRight+offset, lastRightCommentIdx, rightCommentIdx)
|
section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, idxRight-lastRight+offset)
|
||||||
leftHunkSize = 0
|
leftHunkSize = 0
|
||||||
rightHunkSize = 0
|
rightHunkSize = 0
|
||||||
idxLeft = lastLeft
|
idxLeft = lastLeft
|
||||||
@ -958,30 +955,19 @@ func ExcerptBlob(ctx *context.Context) {
|
|||||||
section.Lines = append(section.Lines, lineSection)
|
section.Lines = append(section.Lines, lineSection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, line := range section.Lines {
|
for _, line := range section.Lines {
|
||||||
if line.SectionInfo != nil {
|
if line.SectionInfo != nil {
|
||||||
//for now considerign only right side.
|
|
||||||
start := int64(line.SectionInfo.LastRightIdx + 1)
|
start := int64(line.SectionInfo.LastRightIdx + 1)
|
||||||
end := int64(line.SectionInfo.RightIdx - 1)
|
end := int64(line.SectionInfo.RightIdx - 1)
|
||||||
|
|
||||||
//to check section has comments or not.
|
|
||||||
//1. we can use binary search
|
|
||||||
//2. we can LastRightCommentIdx, RightCommentIdx, LastLeftCommentIdx, LeftCommentIdx(little complex but fast)
|
|
||||||
//3. for demo using linear search
|
|
||||||
for start <= end {
|
for start <= end {
|
||||||
if _, ok := lineCommits[start]; ok {
|
if _, ok := lineCommits[start]; ok {
|
||||||
if !line.SectionInfo.HasComments {
|
if !line.SectionInfo.HasComments {
|
||||||
// line.SectionInfo.LastRightCommentIdx = int(start)
|
|
||||||
// line.SectionInfo.RightCommentIdx = int(start)
|
|
||||||
line.SectionInfo.HasComments = true
|
line.SectionInfo.HasComments = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
start += 1
|
start++
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
|
if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
|
||||||
line.Comments = append(line.Comments, comments...)
|
line.Comments = append(line.Comments, comments...)
|
||||||
@ -994,7 +980,6 @@ func ExcerptBlob(ctx *context.Context) {
|
|||||||
return line.Comments[i].CreatedUnix < line.Comments[j].CreatedUnix
|
return line.Comments[i].CreatedUnix < line.Comments[j].CreatedUnix
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, line := range section.Lines {
|
for _, line := range section.Lines {
|
||||||
for _, comment := range line.Comments {
|
for _, comment := range line.Comments {
|
||||||
if err := comment.LoadAttachments(ctx); err != nil {
|
if err := comment.LoadAttachments(ctx); err != nil {
|
||||||
@ -1003,18 +988,15 @@ func ExcerptBlob(ctx *context.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["section"] = section
|
ctx.Data["section"] = section
|
||||||
ctx.Data["FileNameHash"] = git.HashFilePathForWebUI(filePath)
|
ctx.Data["FileNameHash"] = git.HashFilePathForWebUI(filePath)
|
||||||
ctx.Data["AfterCommitID"] = commitID
|
ctx.Data["AfterCommitID"] = commitID
|
||||||
ctx.Data["Anchor"] = anchor
|
ctx.Data["Anchor"] = anchor
|
||||||
ctx.Data["Issue"] = issue
|
ctx.Data["Issue"] = issue
|
||||||
ctx.Data["issue"] = issue.Index
|
ctx.Data["issue"] = issue.Index
|
||||||
ctx.Data["SignedUserID"] = ctx.Data["SignedUserID"]
|
|
||||||
ctx.Data["CanBlockUser"] = func(blocker, blockee *user_model.User) bool {
|
ctx.Data["CanBlockUser"] = func(blocker, blockee *user_model.User) bool {
|
||||||
return user_service.CanBlockUser(ctx, ctx.Doer, blocker, blockee)
|
return user_service.CanBlockUser(ctx, ctx.Doer, blocker, blockee)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Data["SignedUserID"] == nil {
|
if ctx.Data["SignedUserID"] == nil {
|
||||||
ctx.Data["SignedUserID"] = ctx.Doer.ID
|
ctx.Data["SignedUserID"] = ctx.Doer.ID
|
||||||
}
|
}
|
||||||
@ -1025,7 +1007,7 @@ func ExcerptBlob(ctx *context.Context) {
|
|||||||
ctx.HTML(http.StatusOK, tplBlobExcerpt)
|
ctx.HTML(http.StatusOK, tplBlobExcerpt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chunkSize, lastRightCommentIdx, rightCommentIdx int) ([]*gitdiff.DiffLine, error) {
|
func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chunkSize int) ([]*gitdiff.DiffLine, error) {
|
||||||
blob, err := commit.Tree.GetBlobByPath(filePath)
|
blob, err := commit.Tree.GetBlobByPath(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -1052,10 +1034,6 @@ func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chu
|
|||||||
Content: " " + lineText,
|
Content: " " + lineText,
|
||||||
Comments: []*issues_model.Comment{},
|
Comments: []*issues_model.Comment{},
|
||||||
}
|
}
|
||||||
// if diffLine.SectionInfo != nil {
|
|
||||||
// diffLine.SectionInfo.LastRightCommentIdx = lastRightCommentIdx
|
|
||||||
// diffLine.SectionInfo.RightCommentIdx = rightCommentIdx
|
|
||||||
// }
|
|
||||||
diffLines = append(diffLines, diffLine)
|
diffLines = append(diffLines, diffLine)
|
||||||
}
|
}
|
||||||
if err = scanner.Err(); err != nil {
|
if err = scanner.Err(); err != nil {
|
||||||
|
|||||||
@ -1513,7 +1513,6 @@ func registerRoutes(m *web.Router) {
|
|||||||
// FIXME: refactor this function, use separate routes for wiki/code
|
// FIXME: refactor this function, use separate routes for wiki/code
|
||||||
if ctx.FormBool("pull") {
|
if ctx.FormBool("pull") {
|
||||||
ctx.Data["PageIsPullFiles"] = true
|
ctx.Data["PageIsPullFiles"] = true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.FormBool("wiki") {
|
if ctx.FormBool("wiki") {
|
||||||
|
|||||||
@ -485,20 +485,14 @@ func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, c
|
|||||||
if line.SectionInfo != nil {
|
if line.SectionInfo != nil {
|
||||||
start := int64(line.SectionInfo.LastRightIdx + 1)
|
start := int64(line.SectionInfo.LastRightIdx + 1)
|
||||||
end := int64(line.SectionInfo.RightIdx - 1)
|
end := int64(line.SectionInfo.RightIdx - 1)
|
||||||
|
|
||||||
for start <= end {
|
for start <= end {
|
||||||
if _, ok := lineCommits[start]; ok {
|
if _, ok := lineCommits[start]; ok {
|
||||||
if line.SectionInfo.LastRightCommentIdx == 0 {
|
if !line.SectionInfo.HasComments {
|
||||||
// line.SectionInfo.LastRightCommentIdx = int(start)
|
|
||||||
// line.SectionInfo.RightCommentIdx = int(start)
|
|
||||||
line.SectionInfo.HasComments = true
|
line.SectionInfo.HasComments = true
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
start += 1
|
start++
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
|
if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
|
||||||
|
|||||||
@ -615,7 +615,7 @@ func TestDiff_LoadCommentsWithOutdated(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDiffLine_CanComment(t *testing.T) {
|
func TestDiffLine_CanComment(t *testing.T) {
|
||||||
assert.False(t, (&DiffLine{Type: DiffLineSection}).CanComment())
|
assert.True(t, (&DiffLine{Type: DiffLineSection}).CanComment())
|
||||||
assert.False(t, (&DiffLine{Type: DiffLineAdd, Comments: []*issues_model.Comment{{Content: "bla"}}}).CanComment())
|
assert.False(t, (&DiffLine{Type: DiffLineAdd, Comments: []*issues_model.Comment{{Content: "bla"}}}).CanComment())
|
||||||
assert.True(t, (&DiffLine{Type: DiffLineAdd}).CanComment())
|
assert.True(t, (&DiffLine{Type: DiffLineAdd}).CanComment())
|
||||||
assert.True(t, (&DiffLine{Type: DiffLineDel}).CanComment())
|
assert.True(t, (&DiffLine{Type: DiffLineDel}).CanComment())
|
||||||
|
|||||||
@ -91,19 +91,16 @@
|
|||||||
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
|
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
|
||||||
{{svg "octicon-fold-down"}}
|
{{svg "octicon-fold-down"}}
|
||||||
</button>
|
</button>
|
||||||
test else down blob {{$line.SectionInfo.HasComments}}
|
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
|
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
|
||||||
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
|
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
|
||||||
{{svg "octicon-fold-up"}}
|
{{svg "octicon-fold-up"}}
|
||||||
</button>
|
</button>
|
||||||
test else up blob
|
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if eq $expandDirection 2}}
|
{{if eq $expandDirection 2}}
|
||||||
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
|
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
|
||||||
{{svg "octicon-fold"}}
|
{{svg "octicon-fold"}}
|
||||||
</button>
|
</button>
|
||||||
test else both blob
|
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -27,19 +27,16 @@
|
|||||||
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
|
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
|
||||||
{{svg "octicon-fold-down"}}
|
{{svg "octicon-fold-down"}}
|
||||||
</button>
|
</button>
|
||||||
test down
|
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
|
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
|
||||||
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
|
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
|
||||||
{{svg "octicon-fold-up"}}
|
{{svg "octicon-fold-up"}}
|
||||||
</button>
|
</button>
|
||||||
test up
|
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if eq $expandDirection 2}}
|
{{if eq $expandDirection 2}}
|
||||||
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
|
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=unified&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
|
||||||
{{svg "octicon-fold"}}
|
{{svg "octicon-fold"}}
|
||||||
</button>
|
</button>
|
||||||
test fold
|
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user