Skip to content

Commit abd1d2f

Browse files
chore: fix lint issues
1 parent 914bed8 commit abd1d2f

File tree

6 files changed

+12
-47
lines changed

6 files changed

+12
-47
lines changed

routers/web/repo/compare.go

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -865,10 +865,7 @@ func ExcerptBlob(ctx *context.Context) {
865865
direction := ctx.FormString("direction")
866866
filePath := ctx.FormString("path")
867867
gitRepo := ctx.Repo.GitRepo
868-
lastRightCommentIdx := ctx.FormInt("last_left_comment_idx")
869-
rightCommentIdx := ctx.FormInt("left_comment_idx")
870868
fileName := ctx.FormString("file_name")
871-
872869
if ctx.FormBool("pull") {
873870
ctx.Data["PageIsPullFiles"] = true
874871
}
@@ -882,17 +879,17 @@ func ExcerptBlob(ctx *context.Context) {
882879
}
883880
defer gitRepo.Close()
884881
}
885-
886882
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, int64(2))
887-
888883
if err != nil {
889884
ctx.ServerError("GetIssueByIndex", err)
890885
return
891886
}
892-
893887
allComments, err := issues_model.FetchCodeComments(ctx, issue, ctx.Doer, false)
888+
if err != nil {
889+
ctx.ServerError("FetchCodeComments", err)
890+
return
891+
}
894892
lineCommits := allComments[fileName]
895-
896893
chunkSize := gitdiff.BlobExcerptChunkSize
897894
commit, err := gitRepo.GetCommit(commitID)
898895
if err != nil {
@@ -909,17 +906,17 @@ func ExcerptBlob(ctx *context.Context) {
909906
idxRight -= chunkSize
910907
leftHunkSize += chunkSize
911908
rightHunkSize += chunkSize
912-
section.Lines, err = getExcerptLines(commit, filePath, idxLeft-1, idxRight-1, chunkSize, lastRightCommentIdx, rightCommentIdx)
909+
section.Lines, err = getExcerptLines(commit, filePath, idxLeft-1, idxRight-1, chunkSize)
913910
} else if direction == "down" && (idxLeft-lastLeft) > chunkSize {
914-
section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, chunkSize, lastRightCommentIdx, rightCommentIdx)
911+
section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, chunkSize)
915912
lastLeft += chunkSize
916913
lastRight += chunkSize
917914
} else {
918915
offset := -1
919916
if direction == "down" {
920917
offset = 0
921918
}
922-
section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, idxRight-lastRight+offset, lastRightCommentIdx, rightCommentIdx)
919+
section.Lines, err = getExcerptLines(commit, filePath, lastLeft, lastRight, idxRight-lastRight+offset)
923920
leftHunkSize = 0
924921
rightHunkSize = 0
925922
idxLeft = lastLeft
@@ -958,30 +955,19 @@ func ExcerptBlob(ctx *context.Context) {
958955
section.Lines = append(section.Lines, lineSection)
959956
}
960957
}
961-
962958
for _, line := range section.Lines {
963959
if line.SectionInfo != nil {
964-
//for now considerign only right side.
965960
start := int64(line.SectionInfo.LastRightIdx + 1)
966961
end := int64(line.SectionInfo.RightIdx - 1)
967-
968-
//to check section has comments or not.
969-
//1. we can use binary search
970-
//2. we can LastRightCommentIdx, RightCommentIdx, LastLeftCommentIdx, LeftCommentIdx(little complex but fast)
971-
//3. for demo using linear search
972962
for start <= end {
973963
if _, ok := lineCommits[start]; ok {
974964
if !line.SectionInfo.HasComments {
975-
// line.SectionInfo.LastRightCommentIdx = int(start)
976-
// line.SectionInfo.RightCommentIdx = int(start)
977965
line.SectionInfo.HasComments = true
978966
break
979967
}
980-
981968
}
982-
start += 1
969+
start++
983970
}
984-
985971
}
986972
if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {
987973
line.Comments = append(line.Comments, comments...)
@@ -994,7 +980,6 @@ func ExcerptBlob(ctx *context.Context) {
994980
return line.Comments[i].CreatedUnix < line.Comments[j].CreatedUnix
995981
})
996982
}
997-
998983
for _, line := range section.Lines {
999984
for _, comment := range line.Comments {
1000985
if err := comment.LoadAttachments(ctx); err != nil {
@@ -1003,18 +988,15 @@ func ExcerptBlob(ctx *context.Context) {
1003988
}
1004989
}
1005990
}
1006-
1007991
ctx.Data["section"] = section
1008992
ctx.Data["FileNameHash"] = git.HashFilePathForWebUI(filePath)
1009993
ctx.Data["AfterCommitID"] = commitID
1010994
ctx.Data["Anchor"] = anchor
1011995
ctx.Data["Issue"] = issue
1012996
ctx.Data["issue"] = issue.Index
1013-
ctx.Data["SignedUserID"] = ctx.Data["SignedUserID"]
1014997
ctx.Data["CanBlockUser"] = func(blocker, blockee *user_model.User) bool {
1015998
return user_service.CanBlockUser(ctx, ctx.Doer, blocker, blockee)
1016999
}
1017-
10181000
if ctx.Data["SignedUserID"] == nil {
10191001
ctx.Data["SignedUserID"] = ctx.Doer.ID
10201002
}
@@ -1025,7 +1007,7 @@ func ExcerptBlob(ctx *context.Context) {
10251007
ctx.HTML(http.StatusOK, tplBlobExcerpt)
10261008
}
10271009

1028-
func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chunkSize, lastRightCommentIdx, rightCommentIdx int) ([]*gitdiff.DiffLine, error) {
1010+
func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chunkSize int) ([]*gitdiff.DiffLine, error) {
10291011
blob, err := commit.Tree.GetBlobByPath(filePath)
10301012
if err != nil {
10311013
return nil, err
@@ -1052,10 +1034,6 @@ func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chu
10521034
Content: " " + lineText,
10531035
Comments: []*issues_model.Comment{},
10541036
}
1055-
// if diffLine.SectionInfo != nil {
1056-
// diffLine.SectionInfo.LastRightCommentIdx = lastRightCommentIdx
1057-
// diffLine.SectionInfo.RightCommentIdx = rightCommentIdx
1058-
// }
10591037
diffLines = append(diffLines, diffLine)
10601038
}
10611039
if err = scanner.Err(); err != nil {

routers/web/web.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,6 @@ func registerRoutes(m *web.Router) {
15131513
// FIXME: refactor this function, use separate routes for wiki/code
15141514
if ctx.FormBool("pull") {
15151515
ctx.Data["PageIsPullFiles"] = true
1516-
15171516
}
15181517

15191518
if ctx.FormBool("wiki") {

services/gitdiff/gitdiff.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -485,20 +485,14 @@ func (diff *Diff) LoadComments(ctx context.Context, issue *issues_model.Issue, c
485485
if line.SectionInfo != nil {
486486
start := int64(line.SectionInfo.LastRightIdx + 1)
487487
end := int64(line.SectionInfo.RightIdx - 1)
488-
489488
for start <= end {
490489
if _, ok := lineCommits[start]; ok {
491-
if line.SectionInfo.LastRightCommentIdx == 0 {
492-
// line.SectionInfo.LastRightCommentIdx = int(start)
493-
// line.SectionInfo.RightCommentIdx = int(start)
490+
if !line.SectionInfo.HasComments {
494491
line.SectionInfo.HasComments = true
495-
496492
break
497493
}
498-
499494
}
500-
start += 1
501-
495+
start++
502496
}
503497
}
504498
if comments, ok := lineCommits[int64(line.LeftIdx*-1)]; ok {

services/gitdiff/gitdiff_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ func TestDiff_LoadCommentsWithOutdated(t *testing.T) {
615615
}
616616

617617
func TestDiffLine_CanComment(t *testing.T) {
618-
assert.False(t, (&DiffLine{Type: DiffLineSection}).CanComment())
618+
assert.True(t, (&DiffLine{Type: DiffLineSection}).CanComment())
619619
assert.False(t, (&DiffLine{Type: DiffLineAdd, Comments: []*issues_model.Comment{{Content: "bla"}}}).CanComment())
620620
assert.True(t, (&DiffLine{Type: DiffLineAdd}).CanComment())
621621
assert.True(t, (&DiffLine{Type: DiffLineDel}).CanComment())

templates/repo/diff/blob_excerpt.tmpl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,16 @@
9191
<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}}">
9292
{{svg "octicon-fold-down"}}
9393
</button>
94-
test else down blob {{$line.SectionInfo.HasComments}}
9594
{{end}}
9695
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
9796
<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}}">
9897
{{svg "octicon-fold-up"}}
9998
</button>
100-
test else up blob
10199
{{end}}
102100
{{if eq $expandDirection 2}}
103101
<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}}">
104102
{{svg "octicon-fold"}}
105103
</button>
106-
test else both blob
107104
{{end}}
108105
</div>
109106
</div>

templates/repo/diff/section_unified.tmpl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,16 @@
2727
<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}}">
2828
{{svg "octicon-fold-down"}}
2929
</button>
30-
test down
3130
{{end}}
3231
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
3332
<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}}">
3433
{{svg "octicon-fold-up"}}
3534
</button>
36-
test up
3735
{{end}}
3836
{{if eq $expandDirection 2}}
3937
<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}}">
4038
{{svg "octicon-fold"}}
4139
</button>
42-
test fold
4340
{{end}}
4441
</div>
4542
</div>

0 commit comments

Comments
 (0)