Skip to content

Commit 62fbca3

Browse files
zeripath6543
andauthored
Show diff on rename with diff changes (#15338) (#15340)
Backport #15338 More recent versions of git have increased support for detection of renames meaning that a rename with diff changes is now supported. Although ParsePatch supports this - our templates do not and the simplest solution is simply to show the diff. Fix #15335 Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent 223dddb commit 62fbca3

File tree

1 file changed

+127
-131
lines changed

1 file changed

+127
-131
lines changed

templates/repo/diff/box.tmpl

+127-131
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,12 @@
5757
<div class="diff-file-box diff-box file-content">
5858
<h4 class="ui top attached normal header rounded">
5959
<div class="diff-counter count ui left">
60-
{{if not $file.IsRenamed}}
61-
<span class="add" data-line="{{.Addition}}">+ {{.Addition}}</span>
62-
<span class="bar">
63-
<div class="pull-left add"></div>
64-
<div class="pull-left del"></div>
65-
</span>
66-
<span class="del" data-line="{{.Deletion}}">- {{.Deletion}}</span>
67-
{{end}}
60+
<span class="add" data-line="{{.Addition}}">+ {{.Addition}}</span>
61+
<span class="bar">
62+
<div class="pull-left add"></div>
63+
<div class="pull-left del"></div>
64+
</span>
65+
<span class="del" data-line="{{.Deletion}}">- {{.Deletion}}</span>
6866
</div>
6967
<span class="file">{{$file.Name}}</span>
7068
<div>{{$.i18n.Tr "repo.diff.file_suppressed"}}</div>
@@ -97,7 +95,7 @@
9795
<div class="diff-counter count">
9896
{{if $file.IsBin}}
9997
{{$.i18n.Tr "repo.diff.bin"}}
100-
{{else if not $file.IsRenamed}}
98+
{{else}}
10199
<span class="add" data-line="{{.Addition}}">+ {{.Addition}}</span>
102100
<span class="bar">
103101
<div class="pull-left add"></div>
@@ -119,138 +117,136 @@
119117
{{end}}
120118
</h4>
121119
<div class="diff-file-body ui attached unstackable table segment">
122-
{{if ne $file.Type 4}}
123-
<div class="file-body file-code has-context-menu code-diff {{if $.IsSplitStyle}}code-diff-split{{else}}code-diff-unified{{end}}">
124-
<table class="chroma">
125-
<tbody>
126-
{{if $isImage}}
127-
{{template "repo/diff/image_diff" dict "file" . "root" $}}
128-
{{else}}
129-
{{if $.IsSplitStyle}}
130-
{{range $j, $section := $file.Sections}}
131-
{{range $k, $line := $section.Lines}}
132-
<tr class="{{DiffLineTypeToStr .GetType}}-code nl-{{$k}} ol-{{$k}}">
133-
{{if eq .GetType 4}}
134-
<td class="lines-num lines-num-old">
135-
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5) }}
136-
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{$.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=down" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
137-
{{svg "octicon-fold-down"}}
138-
</a>
120+
<div class="file-body file-code has-context-menu code-diff {{if $.IsSplitStyle}}code-diff-split{{else}}code-diff-unified{{end}}">
121+
<table class="chroma">
122+
<tbody>
123+
{{if $isImage}}
124+
{{template "repo/diff/image_diff" dict "file" . "root" $}}
125+
{{else}}
126+
{{if $.IsSplitStyle}}
127+
{{range $j, $section := $file.Sections}}
128+
{{range $k, $line := $section.Lines}}
129+
<tr class="{{DiffLineTypeToStr .GetType}}-code nl-{{$k}} ol-{{$k}}">
130+
{{if eq .GetType 4}}
131+
<td class="lines-num lines-num-old">
132+
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 5) }}
133+
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{$.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=down" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
134+
{{svg "octicon-fold-down"}}
135+
</a>
136+
{{end}}
137+
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4) }}
138+
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{$.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=up" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
139+
{{svg "octicon-fold-up"}}
140+
</a>
141+
{{end}}
142+
{{if eq $line.GetExpandDirection 2}}
143+
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{$.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
144+
{{svg "octicon-fold"}}
145+
</a>
146+
{{end}}
147+
</td>
148+
<td colspan="5" class="lines-code lines-code-old "><span class="mono wrap">{{$section.GetComputedInlineDiffFor $line}}</span></td>
149+
{{else}}
150+
<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}"></span></td>
151+
<td class="lines-type-marker lines-type-marker-old">{{if $line.LeftIdx}}<span class="mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span>{{end}}</td>
152+
<td class="lines-code lines-code-old halfwidth">{{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 2))}}<a class="ui green button add-code-comment add-code-comment-left" data-path="{{$file.Name}}" data-side="left" data-idx="{{$line.LeftIdx}}" data-type-marker="+"></a>{{end}}<span class="mono wrap">{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</span></td>
153+
<td class="lines-num lines-num-new" data-line-num="{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}"><span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}"></span></td>
154+
<td class="lines-type-marker lines-type-marker-new">{{if $line.RightIdx}}<span class="mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span>{{end}}</td>
155+
<td class="lines-code lines-code-new halfwidth">{{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 3))}}<a class="ui green button add-code-comment add-code-comment-right" data-path="{{$file.Name}}" data-side="right" data-idx="{{$line.RightIdx}}" data-type-marker="+"></a>{{end}}<span class="mono wrap">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</span></td>
156+
{{end}}
157+
</tr>
158+
{{if gt (len $line.Comments) 0}}
159+
{{$resolved := (index $line.Comments 0).IsResolved}}
160+
{{$resolveDoer := (index $line.Comments 0).ResolveDoer}}
161+
{{$isNotPending := (not (eq (index $line.Comments 0).Review.Type 0))}}
162+
<tr class="add-code-comment">
163+
<td class="lines-num"></td>
164+
<td class="lines-type-marker"></td>
165+
<td class="add-comment-left">
166+
<div class="conversation-holder">
167+
{{if and $resolved (eq $line.GetCommentSide "previous")}}
168+
<div class="ui top attached header">
169+
<span class="ui grey text left"><b>{{$resolveDoer.Name}}</b> {{$.i18n.Tr "repo.issues.review.resolved_by"}}</span>
170+
<button id="show-outdated-{{(index $line.Comments 0).ID}}" data-comment="{{(index $line.Comments 0).ID}}" class="ui compact right labeled button show-outdated">
171+
{{svg "octicon-unfold"}}
172+
{{$.i18n.Tr "repo.issues.review.show_resolved"}}
173+
</button>
174+
<button id="hide-outdated-{{(index $line.Comments 0).ID}}" data-comment="{{(index $line.Comments 0).ID}}" class="hide ui compact right labeled button hide-outdated">
175+
{{svg "octicon-fold"}}
176+
{{$.i18n.Tr "repo.issues.review.hide_resolved"}}
177+
</button>
178+
</div>
139179
{{end}}
140-
{{if or (eq $line.GetExpandDirection 3) (eq $line.GetExpandDirection 4) }}
141-
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{$.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=up" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
142-
{{svg "octicon-fold-up"}}
143-
</a>
180+
{{if eq $line.GetCommentSide "previous"}}
181+
<div id="code-comments-{{(index $line.Comments 0).ID}}" class="field comment-code-cloud {{if $resolved}}hide{{end}}">
182+
<div class="comment-list">
183+
<ui class="ui comments">
184+
{{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}}
185+
</ui>
186+
</div>
187+
{{template "repo/diff/comment_form_datahandler" dict "reply" (index $line.Comments 0).ReviewID "hidden" true "root" $ "comment" (index $line.Comments 0)}}
188+
{{if and $.CanMarkConversation $isNotPending}}
189+
<button class="ui icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-comment-id="{{(index $line.Comments 0).ID}}" data-update-url="{{$.RepoLink}}/issues/resolve_conversation" >
190+
{{if $resolved}}
191+
{{$.i18n.Tr "repo.issues.review.un_resolve_conversation"}}
192+
{{else}}
193+
{{$.i18n.Tr "repo.issues.review.resolve_conversation"}}
194+
{{end}}
195+
</button>
196+
{{end}}
197+
</div>
144198
{{end}}
145-
{{if eq $line.GetExpandDirection 2}}
146-
<a role="button" class="blob-excerpt" data-url="{{$.RepoLink}}/blob_excerpt/{{$.AfterCommitID}}" data-query="{{$line.GetBlobExcerptQuery}}&style=split&direction=" data-anchor="diff-{{Sha1 $file.Name}}K{{$line.SectionInfo.RightIdx}}">
147-
{{svg "octicon-fold"}}
148-
</a>
199+
</div>
200+
</td>
201+
<td class="lines-num"></td>
202+
<td class="lines-type-marker"></td>
203+
<td class="add-comment-right">
204+
<div class="conversation-holder">
205+
{{if and $resolved (eq $line.GetCommentSide "proposed")}}
206+
<div class="ui top attached header">
207+
<span class="ui grey text left"><b>{{$resolveDoer.Name}}</b> {{$.i18n.Tr "repo.issues.review.resolved_by"}}</span>
208+
<button id="show-outdated-{{(index $line.Comments 0).ID}}" data-comment="{{(index $line.Comments 0).ID}}" class="ui compact right labeled button show-outdated">
209+
{{svg "octicon-unfold"}}
210+
{{$.i18n.Tr "repo.issues.review.show_resolved"}}
211+
</button>
212+
<button id="hide-outdated-{{(index $line.Comments 0).ID}}" data-comment="{{(index $line.Comments 0).ID}}" class="hide ui compact right labeled button hide-outdated">
213+
{{svg "octicon-fold"}}
214+
{{$.i18n.Tr "repo.issues.review.hide_resolved"}}
215+
</button>
216+
</div>
149217
{{end}}
150-
</td>
151-
<td colspan="5" class="lines-code lines-code-old "><span class="mono wrap">{{$section.GetComputedInlineDiffFor $line}}</span></td>
152-
{{else}}
153-
<td class="lines-num lines-num-old" data-line-num="{{if $line.LeftIdx}}{{$line.LeftIdx}}{{end}}"><span rel="{{if $line.LeftIdx}}diff-{{Sha1 $file.Name}}L{{$line.LeftIdx}}{{end}}"></span></td>
154-
<td class="lines-type-marker lines-type-marker-old">{{if $line.LeftIdx}}<span class="mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span>{{end}}</td>
155-
<td class="lines-code lines-code-old halfwidth">{{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 2))}}<a class="ui green button add-code-comment add-code-comment-left" data-path="{{$file.Name}}" data-side="left" data-idx="{{$line.LeftIdx}}" data-type-marker="+"></a>{{end}}<span class="mono wrap">{{if $line.LeftIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</span></td>
156-
<td class="lines-num lines-num-new" data-line-num="{{if $line.RightIdx}}{{$line.RightIdx}}{{end}}"><span rel="{{if $line.RightIdx}}diff-{{Sha1 $file.Name}}R{{$line.RightIdx}}{{end}}"></span></td>
157-
<td class="lines-type-marker lines-type-marker-new">{{if $line.RightIdx}}<span class="mono" data-type-marker="{{$line.GetLineTypeMarker}}"></span>{{end}}</td>
158-
<td class="lines-code lines-code-new halfwidth">{{if and $.SignedUserID $line.CanComment $.PageIsPullFiles (not (eq .GetType 3))}}<a class="ui green button add-code-comment add-code-comment-right" data-path="{{$file.Name}}" data-side="right" data-idx="{{$line.RightIdx}}" data-type-marker="+"></a>{{end}}<span class="mono wrap">{{if $line.RightIdx}}{{$section.GetComputedInlineDiffFor $line}}{{end}}</span></td>
159-
{{end}}
160-
</tr>
161-
{{if gt (len $line.Comments) 0}}
162-
{{$resolved := (index $line.Comments 0).IsResolved}}
163-
{{$resolveDoer := (index $line.Comments 0).ResolveDoer}}
164-
{{$isNotPending := (not (eq (index $line.Comments 0).Review.Type 0))}}
165-
<tr class="add-code-comment">
166-
<td class="lines-num"></td>
167-
<td class="lines-type-marker"></td>
168-
<td class="add-comment-left">
169-
<div class="conversation-holder">
170-
{{if and $resolved (eq $line.GetCommentSide "previous")}}
171-
<div class="ui top attached header">
172-
<span class="ui grey text left"><b>{{$resolveDoer.Name}}</b> {{$.i18n.Tr "repo.issues.review.resolved_by"}}</span>
173-
<button id="show-outdated-{{(index $line.Comments 0).ID}}" data-comment="{{(index $line.Comments 0).ID}}" class="ui compact right labeled button show-outdated">
174-
{{svg "octicon-unfold"}}
175-
{{$.i18n.Tr "repo.issues.review.show_resolved"}}
176-
</button>
177-
<button id="hide-outdated-{{(index $line.Comments 0).ID}}" data-comment="{{(index $line.Comments 0).ID}}" class="hide ui compact right labeled button hide-outdated">
178-
{{svg "octicon-fold"}}
179-
{{$.i18n.Tr "repo.issues.review.hide_resolved"}}
180-
</button>
218+
{{if eq $line.GetCommentSide "proposed"}}
219+
<div id="code-comments-{{(index $line.Comments 0).ID}}" class="field comment-code-cloud {{if $resolved}}hide{{end}}">
220+
<div class="comment-list">
221+
<ui class="ui comments">
222+
{{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}}
223+
</ui>
181224
</div>
182-
{{end}}
183-
{{if eq $line.GetCommentSide "previous"}}
184-
<div id="code-comments-{{(index $line.Comments 0).ID}}" class="field comment-code-cloud {{if $resolved}}hide{{end}}">
185-
<div class="comment-list">
186-
<ui class="ui comments">
187-
{{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}}
188-
</ui>
189-
</div>
190225
{{template "repo/diff/comment_form_datahandler" dict "reply" (index $line.Comments 0).ReviewID "hidden" true "root" $ "comment" (index $line.Comments 0)}}
191-
{{if and $.CanMarkConversation $isNotPending}}
192-
<button class="ui icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-comment-id="{{(index $line.Comments 0).ID}}" data-update-url="{{$.RepoLink}}/issues/resolve_conversation" >
193-
{{if $resolved}}
194-
{{$.i18n.Tr "repo.issues.review.un_resolve_conversation"}}
195-
{{else}}
196-
{{$.i18n.Tr "repo.issues.review.resolve_conversation"}}
197-
{{end}}
198-
</button>
199-
{{end}}
200-
</div>
201-
{{end}}
202-
</div>
203-
</td>
204-
<td class="lines-num"></td>
205-
<td class="lines-type-marker"></td>
206-
<td class="add-comment-right">
207-
<div class="conversation-holder">
208-
{{if and $resolved (eq $line.GetCommentSide "proposed")}}
209-
<div class="ui top attached header">
210-
<span class="ui grey text left"><b>{{$resolveDoer.Name}}</b> {{$.i18n.Tr "repo.issues.review.resolved_by"}}</span>
211-
<button id="show-outdated-{{(index $line.Comments 0).ID}}" data-comment="{{(index $line.Comments 0).ID}}" class="ui compact right labeled button show-outdated">
212-
{{svg "octicon-unfold"}}
213-
{{$.i18n.Tr "repo.issues.review.show_resolved"}}
214-
</button>
215-
<button id="hide-outdated-{{(index $line.Comments 0).ID}}" data-comment="{{(index $line.Comments 0).ID}}" class="hide ui compact right labeled button hide-outdated">
216-
{{svg "octicon-fold"}}
217-
{{$.i18n.Tr "repo.issues.review.hide_resolved"}}
226+
{{if and $.CanMarkConversation $isNotPending}}
227+
<button class="ui icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-comment-id="{{(index $line.Comments 0).ID}}" data-update-url="{{$.RepoLink}}/issues/resolve_conversation" >
228+
{{if $resolved}}
229+
{{$.i18n.Tr "repo.issues.review.un_resolve_conversation"}}
230+
{{else}}
231+
{{$.i18n.Tr "repo.issues.review.resolve_conversation"}}
232+
{{end}}
218233
</button>
219-
</div>
220-
{{end}}
221-
{{if eq $line.GetCommentSide "proposed"}}
222-
<div id="code-comments-{{(index $line.Comments 0).ID}}" class="field comment-code-cloud {{if $resolved}}hide{{end}}">
223-
<div class="comment-list">
224-
<ui class="ui comments">
225-
{{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}}
226-
</ui>
227-
</div>
228-
{{template "repo/diff/comment_form_datahandler" dict "reply" (index $line.Comments 0).ReviewID "hidden" true "root" $ "comment" (index $line.Comments 0)}}
229-
{{if and $.CanMarkConversation $isNotPending}}
230-
<button class="ui icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-comment-id="{{(index $line.Comments 0).ID}}" data-update-url="{{$.RepoLink}}/issues/resolve_conversation" >
231-
{{if $resolved}}
232-
{{$.i18n.Tr "repo.issues.review.un_resolve_conversation"}}
233-
{{else}}
234-
{{$.i18n.Tr "repo.issues.review.resolve_conversation"}}
235-
{{end}}
236-
</button>
237-
{{end}}
238-
</div>
239-
{{end}}
240-
</div>
241-
</td>
242-
</tr>
243-
{{end}}
234+
{{end}}
235+
</div>
236+
{{end}}
237+
</div>
238+
</td>
239+
</tr>
244240
{{end}}
245241
{{end}}
246-
{{else}}
247-
{{template "repo/diff/section_unified" dict "file" . "root" $}}
248242
{{end}}
243+
{{else}}
244+
{{template "repo/diff/section_unified" dict "file" . "root" $}}
249245
{{end}}
250-
</tbody>
251-
</table>
252-
</div>
253-
{{end}}
246+
{{end}}
247+
</tbody>
248+
</table>
249+
</div>
254250
</div>
255251
</div>
256252
{{end}}

0 commit comments

Comments
 (0)