@@ -865,10 +865,7 @@ func ExcerptBlob(ctx *context.Context) {
865
865
direction := ctx .FormString ("direction" )
866
866
filePath := ctx .FormString ("path" )
867
867
gitRepo := ctx .Repo .GitRepo
868
- lastRightCommentIdx := ctx .FormInt ("last_left_comment_idx" )
869
- rightCommentIdx := ctx .FormInt ("left_comment_idx" )
870
868
fileName := ctx .FormString ("file_name" )
871
-
872
869
if ctx .FormBool ("pull" ) {
873
870
ctx .Data ["PageIsPullFiles" ] = true
874
871
}
@@ -882,17 +879,17 @@ func ExcerptBlob(ctx *context.Context) {
882
879
}
883
880
defer gitRepo .Close ()
884
881
}
885
-
886
882
issue , err := issues_model .GetIssueByIndex (ctx , ctx .Repo .Repository .ID , int64 (2 ))
887
-
888
883
if err != nil {
889
884
ctx .ServerError ("GetIssueByIndex" , err )
890
885
return
891
886
}
892
-
893
887
allComments , err := issues_model .FetchCodeComments (ctx , issue , ctx .Doer , false )
888
+ if err != nil {
889
+ ctx .ServerError ("FetchCodeComments" , err )
890
+ return
891
+ }
894
892
lineCommits := allComments [fileName ]
895
-
896
893
chunkSize := gitdiff .BlobExcerptChunkSize
897
894
commit , err := gitRepo .GetCommit (commitID )
898
895
if err != nil {
@@ -909,17 +906,17 @@ func ExcerptBlob(ctx *context.Context) {
909
906
idxRight -= chunkSize
910
907
leftHunkSize += chunkSize
911
908
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 )
913
910
} 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 )
915
912
lastLeft += chunkSize
916
913
lastRight += chunkSize
917
914
} else {
918
915
offset := - 1
919
916
if direction == "down" {
920
917
offset = 0
921
918
}
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 )
923
920
leftHunkSize = 0
924
921
rightHunkSize = 0
925
922
idxLeft = lastLeft
@@ -958,30 +955,19 @@ func ExcerptBlob(ctx *context.Context) {
958
955
section .Lines = append (section .Lines , lineSection )
959
956
}
960
957
}
961
-
962
958
for _ , line := range section .Lines {
963
959
if line .SectionInfo != nil {
964
- //for now considerign only right side.
965
960
start := int64 (line .SectionInfo .LastRightIdx + 1 )
966
961
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
972
962
for start <= end {
973
963
if _ , ok := lineCommits [start ]; ok {
974
964
if ! line .SectionInfo .HasComments {
975
- // line.SectionInfo.LastRightCommentIdx = int(start)
976
- // line.SectionInfo.RightCommentIdx = int(start)
977
965
line .SectionInfo .HasComments = true
978
966
break
979
967
}
980
-
981
968
}
982
- start += 1
969
+ start ++
983
970
}
984
-
985
971
}
986
972
if comments , ok := lineCommits [int64 (line .LeftIdx * - 1 )]; ok {
987
973
line .Comments = append (line .Comments , comments ... )
@@ -994,7 +980,6 @@ func ExcerptBlob(ctx *context.Context) {
994
980
return line .Comments [i ].CreatedUnix < line .Comments [j ].CreatedUnix
995
981
})
996
982
}
997
-
998
983
for _ , line := range section .Lines {
999
984
for _ , comment := range line .Comments {
1000
985
if err := comment .LoadAttachments (ctx ); err != nil {
@@ -1003,18 +988,15 @@ func ExcerptBlob(ctx *context.Context) {
1003
988
}
1004
989
}
1005
990
}
1006
-
1007
991
ctx .Data ["section" ] = section
1008
992
ctx .Data ["FileNameHash" ] = git .HashFilePathForWebUI (filePath )
1009
993
ctx .Data ["AfterCommitID" ] = commitID
1010
994
ctx .Data ["Anchor" ] = anchor
1011
995
ctx .Data ["Issue" ] = issue
1012
996
ctx .Data ["issue" ] = issue .Index
1013
- ctx .Data ["SignedUserID" ] = ctx .Data ["SignedUserID" ]
1014
997
ctx .Data ["CanBlockUser" ] = func (blocker , blockee * user_model.User ) bool {
1015
998
return user_service .CanBlockUser (ctx , ctx .Doer , blocker , blockee )
1016
999
}
1017
-
1018
1000
if ctx .Data ["SignedUserID" ] == nil {
1019
1001
ctx .Data ["SignedUserID" ] = ctx .Doer .ID
1020
1002
}
@@ -1025,7 +1007,7 @@ func ExcerptBlob(ctx *context.Context) {
1025
1007
ctx .HTML (http .StatusOK , tplBlobExcerpt )
1026
1008
}
1027
1009
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 ) {
1029
1011
blob , err := commit .Tree .GetBlobByPath (filePath )
1030
1012
if err != nil {
1031
1013
return nil , err
@@ -1052,10 +1034,6 @@ func getExcerptLines(commit *git.Commit, filePath string, idxLeft, idxRight, chu
1052
1034
Content : " " + lineText ,
1053
1035
Comments : []* issues_model.Comment {},
1054
1036
}
1055
- // if diffLine.SectionInfo != nil {
1056
- // diffLine.SectionInfo.LastRightCommentIdx = lastRightCommentIdx
1057
- // diffLine.SectionInfo.RightCommentIdx = rightCommentIdx
1058
- // }
1059
1037
diffLines = append (diffLines , diffLine )
1060
1038
}
1061
1039
if err = scanner .Err (); err != nil {
0 commit comments