Skip to content

Commit efba6c4

Browse files
chore: remove issue index and minro template changes
1 parent ccd797a commit efba6c4

File tree

5 files changed

+58
-55
lines changed

5 files changed

+58
-55
lines changed

routers/web/repo/compare.go

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

routers/web/repo/pull.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ func getPullInfo(ctx *context.Context) (issue *issues_model.Issue, ok bool) {
128128
}
129129
ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, emoji.ReplaceAliases(issue.Title))
130130
ctx.Data["Issue"] = issue
131+
ctx.Data["IssueIndex"] = issue.Index
131132

132133
if !issue.IsPull {
133134
ctx.NotFound("ViewPullCommits", nil)

templates/repo/diff/blob_excerpt.tmpl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
</div>
1616
<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
1717
{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
18-
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
18+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&issue_index={{$.IssueIndex}}">
1919
{{svg "octicon-fold-down"}}
2020
</button>
2121
{{end}}
2222
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
23-
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
23+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&issue_index={{$.IssueIndex}}">
2424
{{svg "octicon-fold-up"}}
2525
</button>
2626
{{end}}
2727
{{if eq $expandDirection 2}}
28-
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}&file_name={{$.section.FileName}}">
28+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$.RepoLink}}/blob_excerpt/{{PathEscape $.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.PageIsWiki}}&pull={{$.PageIsPullFiles}}&anchor={{$.Anchor}}}&issue_index={{$.IssueIndex}}">
2929
{{svg "octicon-fold"}}
3030
</button>
3131
{{end}}
@@ -88,17 +88,17 @@
8888
</div>
8989
<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
9090
{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
91-
<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}}">
91+
<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}}}&issue_index={{$.IssueIndex}}">
9292
{{svg "octicon-fold-down"}}
9393
</button>
9494
{{end}}
9595
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
96-
<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}}">
96+
<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}}}&issue_index={{$.IssueIndex}}">
9797
{{svg "octicon-fold-up"}}
9898
</button>
9999
{{end}}
100100
{{if eq $expandDirection 2}}
101-
<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}}">
101+
<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}}}&issue_index={{$.IssueIndex}}">
102102
{{svg "octicon-fold"}}
103103
</button>
104104
{{end}}
@@ -117,9 +117,7 @@
117117
{{svg "octicon-plus"}}
118118
</button>
119119
{{end}}
120-
<code {{if $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"{{else}}class="code-inner"{{end}}>
121-
{{$inlineDiff.Content}}
122-
</code>
120+
<code {{if $inlineDiff.EscapeStatus.Escaped}}class="code-inner has-escaped" title="{{template "repo/diff/escape_title" dict "diff" $inlineDiff}}"{{else}}class="code-inner"{{end}}>{{$inlineDiff.Content}}</code>
123121
</td>
124122
</tr>
125123
{{if $line.Comments}}

templates/repo/diff/section_split.tmpl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{{$file := .file}}
22
{{$blobExcerptRepoLink := or ctx.RootData.CommitRepoLink ctx.RootData.RepoLink}}
3+
{{$issueIndex := or ctx.RootData.IssueIndex $.root.IssueIndex}}
34
<colgroup>
45
<col width="50">
56
<col width="10">
@@ -28,17 +29,17 @@
2829
</div>
2930
<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
3031
{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
31-
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
32+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=down&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&issue_index={{$issueIndex}}">
3233
{{svg "octicon-fold-down"}}
3334
</button>
3435
{{end}}
3536
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
36-
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
37+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=up&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&issue_index={{$issueIndex}}">
3738
{{svg "octicon-fold-up"}}
3839
</button>
3940
{{end}}
4041
{{if eq $expandDirection 2}}
41-
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&file_name={{$section.FileName}}">
42+
<button class="code-expander-button" hx-target="closest tr" hx-get="{{$blobExcerptRepoLink}}/blob_excerpt/{{PathEscape $.root.AfterCommitID}}?{{$line.GetBlobExcerptQuery}}&style=split&direction=&wiki={{$.root.PageIsWiki}}&pull={{$.root.PageIsPullFiles}}&anchor=diff-{{$file.NameHash}}K{{$line.SectionInfo.RightIdx}}&issue_index={{$issueIndex}}">
4243
{{svg "octicon-fold"}}
4344
</button>
4445
{{end}}

templates/repo/diff/section_unified.tmpl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{{$file := .file}}
22
{{$blobExcerptRepoLink := or ctx.RootData.CommitRepoLink ctx.RootData.RepoLink}}
3+
{{$issueIndex := or ctx.RootData.IssueIndex $.root.IssueIndex}}
34
<colgroup>
45
<col width="50">
56
<col width="50">
@@ -24,17 +25,17 @@
2425
</div>
2526
<div class="code-expander-buttons" data-expand-direction="{{$expandDirection}}">
2627
{{if or (eq $expandDirection 3) (eq $expandDirection 5)}}
27-
<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}}">
28+
<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}}&issue_index={{$issueIndex}}">
2829
{{svg "octicon-fold-down"}}
2930
</button>
3031
{{end}}
3132
{{if or (eq $expandDirection 3) (eq $expandDirection 4)}}
32-
<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}}">
33+
<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}}&issue_index={{$issueIndex}}">
3334
{{svg "octicon-fold-up"}}
3435
</button>
3536
{{end}}
3637
{{if eq $expandDirection 2}}
37-
<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}}">
38+
<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}}&issue_index={{$issueIndex}}">
3839
{{svg "octicon-fold"}}
3940
</button>
4041
{{end}}

0 commit comments

Comments
 (0)