@@ -865,7 +865,6 @@ func ExcerptBlob(ctx *context.Context) {
865865 direction := ctx .FormString ("direction" )
866866 filePath := ctx .FormString ("path" )
867867 gitRepo := ctx .Repo .GitRepo
868- fileName := ctx .FormString ("file_name" )
869868 if ctx .FormBool ("pull" ) {
870869 ctx .Data ["PageIsPullFiles" ] = true
871870 }
@@ -879,17 +878,6 @@ func ExcerptBlob(ctx *context.Context) {
879878 }
880879 defer gitRepo .Close ()
881880 }
882- issue , err := issues_model .GetIssueByIndex (ctx , ctx .Repo .Repository .ID , int64 (2 ))
883- if err != nil {
884- ctx .ServerError ("GetIssueByIndex" , err )
885- return
886- }
887- allComments , err := issues_model .FetchCodeComments (ctx , issue , ctx .Doer , false )
888- if err != nil {
889- ctx .ServerError ("FetchCodeComments" , err )
890- return
891- }
892- lineCommits := allComments [fileName ]
893881 chunkSize := gitdiff .BlobExcerptChunkSize
894882 commit , err := gitRepo .GetCommit (commitID )
895883 if err != nil {
@@ -955,45 +943,59 @@ func ExcerptBlob(ctx *context.Context) {
955943 section .Lines = append (section .Lines , lineSection )
956944 }
957945 }
958- for _ , line := range section .Lines {
959- if line .SectionInfo != nil {
960- start := int64 (line .SectionInfo .LastRightIdx + 1 )
961- end := int64 (line .SectionInfo .RightIdx - 1 )
962- for start <= end {
963- if _ , ok := lineCommits [start ]; ok {
964- if ! line .SectionInfo .HasComments {
965- line .SectionInfo .HasComments = true
966- break
946+ issueIndex := ctx .FormInt64 ("issue_index" )
947+ if ctx .FormBool ("pull" ) && issueIndex > 0 {
948+ issue , err := issues_model .GetIssueByIndex (ctx , ctx .Repo .Repository .ID , issueIndex )
949+ if issue == nil {
950+ ctx .ServerError ("GetIssueByIndex" , err )
951+ return
952+ }
953+ allComments , err := issues_model .FetchCodeComments (ctx , issue , ctx .Doer , false )
954+ if err != nil {
955+ ctx .ServerError ("FetchCodeComments" , err )
956+ return
957+ }
958+ lineCommits := allComments [filePath ]
959+ for _ , line := range section .Lines {
960+ if line .SectionInfo != nil {
961+ start := int64 (line .SectionInfo .LastRightIdx + 1 )
962+ end := int64 (line .SectionInfo .RightIdx - 1 )
963+ for start <= end {
964+ if _ , ok := lineCommits [start ]; ok {
965+ if ! line .SectionInfo .HasComments {
966+ line .SectionInfo .HasComments = true
967+ break
968+ }
967969 }
970+ start ++
968971 }
969- start ++
970972 }
971- }
972- if comments , ok := lineCommits [int64 (line .LeftIdx * - 1 )]; ok {
973- line .Comments = append (line .Comments , comments ... )
974- }
975- if comments , ok := lineCommits [int64 (line .RightIdx )]; ok {
976- line .Comments = append (line .Comments , comments ... )
977- }
973+ if comments , ok := lineCommits [int64 (line .LeftIdx * - 1 )]; ok {
974+ line .Comments = append (line .Comments , comments ... )
975+ }
976+ if comments , ok := lineCommits [int64 (line .RightIdx )]; ok {
977+ line .Comments = append (line .Comments , comments ... )
978+ }
978979
979- sort .SliceStable (line .Comments , func (i , j int ) bool {
980- return line .Comments [i ].CreatedUnix < line .Comments [j ].CreatedUnix
981- })
982- }
983- for _ , line := range section .Lines {
984- for _ , comment := range line .Comments {
985- if err := comment .LoadAttachments (ctx ); err != nil {
986- ctx .ServerError ("LoadAttachments" , err )
987- return
980+ sort .SliceStable (line .Comments , func (i , j int ) bool {
981+ return line .Comments [i ].CreatedUnix < line .Comments [j ].CreatedUnix
982+ })
983+ }
984+ for _ , line := range section .Lines {
985+ for _ , comment := range line .Comments {
986+ if err := comment .LoadAttachments (ctx ); err != nil {
987+ ctx .ServerError ("LoadAttachments" , err )
988+ return
989+ }
988990 }
989991 }
992+ ctx .Data ["Issue" ] = issue
993+ ctx .Data ["IssueIndex" ] = issue .Index
990994 }
991995 ctx .Data ["section" ] = section
992996 ctx .Data ["FileNameHash" ] = git .HashFilePathForWebUI (filePath )
993997 ctx .Data ["AfterCommitID" ] = commitID
994998 ctx .Data ["Anchor" ] = anchor
995- ctx .Data ["Issue" ] = issue
996- ctx .Data ["issue" ] = issue .Index
997999 ctx .Data ["CanBlockUser" ] = func (blocker , blockee * user_model.User ) bool {
9981000 return user_service .CanBlockUser (ctx , ctx .Doer , blocker , blockee )
9991001 }
0 commit comments