@@ -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 {
0 commit comments