##// END OF EJS Templates
diffs: add commit id argument and use id of filediff for identifying...
dan -
r1135:95e7a256 default
parent child Browse files
Show More
@@ -1,412 +1,412 b''
1 1 <%def name="diff_line_anchor(filename, line, type)"><%
2 2 return '%s_%s_%i' % (h.safeid(filename), type, line)
3 3 %></%def>
4 4
5 5 <%def name="action_class(action)"><%
6 6 return {
7 7 '-': 'cb-deletion',
8 8 '+': 'cb-addition',
9 9 ' ': 'cb-context',
10 10 }.get(action, 'cb-empty')
11 11 %></%def>
12 12
13 13 <%def name="op_class(op_id)"><%
14 14 return {
15 15 DEL_FILENODE: 'deletion', # file deleted
16 16 BIN_FILENODE: 'warning' # binary diff hidden
17 17 }.get(op_id, 'addition')
18 18 %></%def>
19 19
20 20 <%def name="link_for(**kw)"><%
21 21 new_args = request.GET.mixed()
22 22 new_args.update(kw)
23 23 return h.url('', **new_args)
24 24 %></%def>
25 25
26 <%def name="render_diffset(diffset,
26 <%def name="render_diffset(diffset, commit_id=None,
27 27
28 28 # collapse all file diff entries when there are more than this amount of files in the diff
29 29 collapse_when_files_over=20,
30 30
31 31 # collapse lines in the diff when more than this amount of lines changed in the file diff
32 32 lines_changed_limit=500,
33 33
34 34 # add a ruler at to the output
35 35 ruler_at_chars=0,
36 36 )">
37 37 <%
38 38 # TODO: dan: move this to an argument - and set a cookie so that it is saved
39 39 # default option for future requests
40 40 diff_mode = request.GET.get('diffmode', 'sideside')
41 41 if diff_mode not in ('sideside', 'unified'):
42 42 diff_mode = 'sideside'
43 43
44 44 collapse_all = len(diffset.files) > collapse_when_files_over
45 45 %>
46 46
47 47 %if diff_mode == 'sideside':
48 48 <style>
49 49 .wrapper {
50 50 max-width: 1600px !important;
51 51 }
52 52 </style>
53 53 %endif
54 54 %if ruler_at_chars:
55 55 <style>
56 56 .diff table.cb .cb-content:after {
57 57 content: "";
58 58 border-left: 1px solid blue;
59 59 position: absolute;
60 60 top: 0;
61 61 height: 18px;
62 62 opacity: .2;
63 63 z-index: 10;
64 64 ## +5 to account for diff action (+/-)
65 65 left: ${ruler_at_chars + 5}ch;
66 66 </style>
67 67 %endif
68 68 % if diffset.limited_diff:
69 69 <div class="alert alert-warning">
70 70 ${_('The requested commit is too big and content was truncated.')} <a href="${link_for(fulldiff=1)}" onclick="return confirm('${_("Showing a big diff might take some time and resources, continue?")}')">${_('Show full diff')}</a>
71 71 </div>
72 72 % endif
73 73
74 74 <div class="cs_files">
75 75 <div class="cs_files_title">
76 76 %if diffset.files:
77 77 <div class="pull-right">
78 78 <div class="btn-group">
79 79 <a
80 80 class="btn ${diff_mode == 'sideside' and 'btn-primary'} tooltip"
81 81 title="${_('View side by side')}"
82 82 href="${link_for(diffmode='sideside')}">
83 83 <span>${_('Side by Side')}</span>
84 84 </a>
85 85 <a
86 86 class="btn ${diff_mode == 'unified' and 'btn-primary'} tooltip"
87 87 title="${_('View unified')}" href="${link_for(diffmode='unified')}">
88 88 <span>${_('Unified')}</span>
89 89 </a>
90 90 </div>
91 91 </div>
92 92 <div class="pull-left">
93 93 <div class="btn-group">
94 94 <a
95 95 class="btn"
96 96 href="#"
97 97 onclick="$('input[class=diff-collapse-state]').prop('checked', false); return false">${_('Expand All')}</a>
98 98 <a
99 99 class="btn"
100 100 href="#"
101 101 onclick="$('input[class=diff-collapse-state]').prop('checked', true); return false">${_('Collapse All')}</a>
102 102 </div>
103 103 </div>
104 104 %endif
105 105 <h2 style="padding: 5px; text-align: center;">
106 106 %if diffset.limited_diff:
107 107 ${ungettext('%(num)s file changed', '%(num)s files changed', diffset.changed_files) % {'num': diffset.changed_files}}
108 108 %else:
109 109 ${ungettext('%(num)s file changed: %(linesadd)s inserted, ''%(linesdel)s deleted',
110 110 '%(num)s files changed: %(linesadd)s inserted, %(linesdel)s deleted', diffset.changed_files) % {'num': diffset.changed_files, 'linesadd': diffset.lines_added, 'linesdel': diffset.lines_deleted}}
111 111 %endif
112 112 </h2>
113 113 </div>
114 114
115 115 %if not diffset.files:
116 116 <p class="empty_data">${_('No files')}</p>
117 117 %endif
118 118
119 119 <div class="filediffs">
120 120 %for i, filediff in enumerate(diffset.files):
121 121 <%
122 122 lines_changed = filediff['patch']['stats']['added'] + filediff['patch']['stats']['deleted']
123 123 over_lines_changed_limit = lines_changed > lines_changed_limit
124 124 %>
125 <input ${collapse_all and 'checked' or ''} class="diff-collapse-state" id="diff-collapse-${i}" type="checkbox">
125 <input ${collapse_all and 'checked' or ''} class="diff-collapse-state" id="diff-collapse-${id(filediff)}" type="checkbox">
126 126 <div
127 127 class="diff"
128 128 data-f-path="${filediff['patch']['filename']}"
129 id="a_${h.FID('', filediff['patch']['filename'])}">
130 <label for="diff-collapse-${i}" class="diff-heading">
129 id="a_${h.FID(commit_id or '', filediff['patch']['filename'])}">
130 <label for="diff-collapse-${id(filediff)}" class="diff-heading">
131 131 <div class="diff-collapse-indicator"></div>
132 132 ${diff_ops(filediff)}
133 133 </label>
134 134 ${diff_menu(filediff)}
135 135 <table class="cb cb-diff-${diff_mode} code-highlight ${over_lines_changed_limit and 'cb-collapsed' or ''}">
136 136 %if not filediff.hunks:
137 137 %for op_id, op_text in filediff['patch']['stats']['ops'].items():
138 138 <tr>
139 139 <td class="cb-text cb-${op_class(op_id)}" ${diff_mode == 'unified' and 'colspan=3' or 'colspan=4'}>
140 140 %if op_id == DEL_FILENODE:
141 141 ${_('File was deleted')}
142 142 %elif op_id == BIN_FILENODE:
143 143 ${_('Binary file hidden')}
144 144 %else:
145 145 ${op_text}
146 146 %endif
147 147 </td>
148 148 </tr>
149 149 %endfor
150 150 %endif
151 151 %if over_lines_changed_limit:
152 152 <tr class="cb-warning cb-collapser">
153 153 <td class="cb-text" ${diff_mode == 'unified' and 'colspan=3' or 'colspan=4'}>
154 154 ${_('This diff has been collapsed as it changes many lines, (%i lines changed)' % lines_changed)}
155 155 <a href="#" class="cb-expand"
156 156 onclick="$(this).closest('table').removeClass('cb-collapsed'); return false;">${_('Show them')}
157 157 </a>
158 158 <a href="#" class="cb-collapse"
159 159 onclick="$(this).closest('table').addClass('cb-collapsed'); return false;">${_('Hide them')}
160 160 </a>
161 161 </td>
162 162 </tr>
163 163 %endif
164 164 %if filediff.patch['is_limited_diff']:
165 165 <tr class="cb-warning cb-collapser">
166 166 <td class="cb-text" ${diff_mode == 'unified' and 'colspan=3' or 'colspan=4'}>
167 167 ${_('The requested commit is too big and content was truncated.')} <a href="${link_for(fulldiff=1)}" onclick="return confirm('${_("Showing a big diff might take some time and resources, continue?")}')">${_('Show full diff')}</a>
168 168 </td>
169 169 </tr>
170 170 %endif
171 171 %for hunk in filediff.hunks:
172 172 <tr class="cb-hunk">
173 173 <td ${diff_mode == 'unified' and 'colspan=2' or ''}>
174 174 ## TODO: dan: add ajax loading of more context here
175 175 ## <a href="#">
176 176 <i class="icon-more"></i>
177 177 ## </a>
178 178 </td>
179 179 <td ${diff_mode == 'sideside' and 'colspan=3' or ''}>
180 180 @@
181 181 -${hunk.source_start},${hunk.source_length}
182 182 +${hunk.target_start},${hunk.target_length}
183 183 ${hunk.section_header}
184 184 </td>
185 185 </tr>
186 186 %if diff_mode == 'unified':
187 187 ${render_hunk_lines_unified(hunk)}
188 188 %elif diff_mode == 'sideside':
189 189 ${render_hunk_lines_sideside(hunk)}
190 190 %else:
191 191 <tr class="cb-line">
192 192 <td>unknown diff mode</td>
193 193 </tr>
194 194 %endif
195 195 %endfor
196 196 </table>
197 197 </div>
198 198 %endfor
199 199 </div>
200 200 </div>
201 201 </%def>
202 202
203 203 <%def name="diff_ops(filediff)">
204 204 <%
205 205 stats = filediff['patch']['stats']
206 206 from rhodecode.lib.diffs import NEW_FILENODE, DEL_FILENODE, \
207 207 MOD_FILENODE, RENAMED_FILENODE, CHMOD_FILENODE, BIN_FILENODE
208 208 %>
209 209 <span class="diff-pill">
210 210 %if filediff.source_file_path and filediff.target_file_path:
211 211 %if filediff.source_file_path != filediff.target_file_path: # file was renamed
212 212 <strong>${filediff.target_file_path}</strong> β¬… <del>${filediff.source_file_path}</del>
213 213 %else:
214 214 ## file was modified
215 215 <strong>${filediff.source_file_path}</strong>
216 216 %endif
217 217 %else:
218 218 %if filediff.source_file_path:
219 219 ## file was deleted
220 220 <strong>${filediff.source_file_path}</strong>
221 221 %else:
222 222 ## file was added
223 223 <strong>${filediff.target_file_path}</strong>
224 224 %endif
225 225 %endif
226 226 </span>
227 227 <span class="diff-pill-group" style="float: left">
228 228 %if filediff.patch['is_limited_diff']:
229 229 <span class="diff-pill tooltip" op="limited" title="The stats for this diff are not complete">limited diff</span>
230 230 %endif
231 231 %if RENAMED_FILENODE in stats['ops']:
232 232 <span class="diff-pill" op="renamed">renamed</span>
233 233 %endif
234 234
235 235 %if NEW_FILENODE in stats['ops']:
236 236 <span class="diff-pill" op="created">created</span>
237 237 %if filediff['target_mode'].startswith('120'):
238 238 <span class="diff-pill" op="symlink">symlink</span>
239 239 %else:
240 240 <span class="diff-pill" op="mode">${nice_mode(filediff['target_mode'])}</span>
241 241 %endif
242 242 %endif
243 243
244 244 %if DEL_FILENODE in stats['ops']:
245 245 <span class="diff-pill" op="removed">removed</span>
246 246 %endif
247 247
248 248 %if CHMOD_FILENODE in stats['ops']:
249 249 <span class="diff-pill" op="mode">
250 250 ${nice_mode(filediff['source_mode'])} ➑ ${nice_mode(filediff['target_mode'])}
251 251 </span>
252 252 %endif
253 253 </span>
254 254
255 <a class="diff-pill diff-anchor" href="#a_${h.FID('', filediff.patch['filename'])}">ΒΆ</a>
255 <a class="diff-pill diff-anchor" href="#a_${h.FID(commit_id or '', filediff.patch['filename'])}">ΒΆ</a>
256 256
257 257 <span class="diff-pill-group" style="float: right">
258 258 %if BIN_FILENODE in stats['ops']:
259 259 <span class="diff-pill" op="binary">binary</span>
260 260 %if MOD_FILENODE in stats['ops']:
261 261 <span class="diff-pill" op="modified">modified</span>
262 262 %endif
263 263 %endif
264 %if stats['added']:
265 <span class="diff-pill" op="added">+${stats['added']}</span>
266 %endif
264 267 %if stats['deleted']:
265 268 <span class="diff-pill" op="deleted">-${stats['deleted']}</span>
266 269 %endif
267 %if stats['added']:
268 <span class="diff-pill" op="added">+${stats['added']}</span>
269 %endif
270 270 </span>
271 271
272 272 </%def>
273 273
274 274 <%def name="nice_mode(filemode)">
275 275 ${filemode.startswith('100') and filemode[3:] or filemode}
276 276 </%def>
277 277
278 278 <%def name="diff_menu(filediff)">
279 279 <div class="diff-menu">
280 280 %if filediff.diffset.source_ref:
281 281 %if filediff.patch['operation'] in ['D', 'M']:
282 282 <a
283 283 class="tooltip"
284 284 href="${h.url('files_home',repo_name=c.repo_name,f_path=filediff.source_file_path,revision=filediff.diffset.source_ref)}"
285 285 title="${h.tooltip(_('Show file at commit: %(commit_id)s') % {'commit_id': filediff.diffset.source_ref[:12]})}"
286 286 >
287 287 ${_('Show file before')}
288 288 </a>
289 289 %else:
290 290 <span
291 291 class="tooltip"
292 292 title="${h.tooltip(_('File no longer present at commit: %(commit_id)s') % {'commit_id': filediff.diffset.source_ref[:12]})}"
293 293 >
294 294 ${_('Show file before')}
295 295 </span>
296 296 %endif
297 297 %if filediff.patch['operation'] in ['A', 'M']:
298 298 <a
299 299 class="tooltip"
300 300 href="${h.url('files_home',repo_name=c.repo_name,f_path=filediff.target_file_path,revision=filediff.diffset.target_ref)}"
301 301 title="${h.tooltip(_('Show file at commit: %(commit_id)s') % {'commit_id': filediff.diffset.target_ref[:12]})}"
302 302 >
303 303 ${_('Show file after')}
304 304 </a>
305 305 %else:
306 306 <span
307 307 class="tooltip"
308 308 title="${h.tooltip(_('File no longer present at commit: %(commit_id)s') % {'commit_id': filediff.diffset.target_ref[:12]})}"
309 309 >
310 310 ${_('Show file after')}
311 311 </span>
312 312 %endif
313 313 <a
314 314 class="tooltip"
315 315 title="${h.tooltip(_('Raw diff'))}"
316 316 href="${h.url('files_diff_home',repo_name=c.repo_name,f_path=filediff.target_file_path,diff2=filediff.diffset.target_ref,diff1=filediff.diffset.source_ref,diff='raw')}"
317 317 >
318 318 ${_('Raw diff')}
319 319 </a>
320 320 <a
321 321 class="tooltip"
322 322 title="${h.tooltip(_('Download diff'))}"
323 323 href="${h.url('files_diff_home',repo_name=c.repo_name,f_path=filediff.target_file_path,diff2=filediff.diffset.target_ref,diff1=filediff.diffset.source_ref,diff='download')}"
324 324 >
325 325 ${_('Download diff')}
326 326 </a>
327 327 %endif
328 328 </div>
329 329 </%def>
330 330
331 331
332 332 <%def name="render_hunk_lines_sideside(hunk)">
333 333 %for i, line in enumerate(hunk.sideside):
334 334 <%
335 335 old_line_anchor, new_line_anchor = None, None
336 336 if line.original.lineno:
337 337 old_line_anchor = diff_line_anchor(hunk.filediff.source_file_path, line.original.lineno, 'o')
338 338 if line.modified.lineno:
339 339 new_line_anchor = diff_line_anchor(hunk.filediff.target_file_path, line.modified.lineno, 'n')
340 340 %>
341 341 <tr class="cb-line">
342 342 <td class="cb-lineno ${action_class(line.original.action)}"
343 343 data-line-number="${line.original.lineno}"
344 344 %if old_line_anchor:
345 345 id="${old_line_anchor}"
346 346 %endif
347 347 >
348 348 %if line.original.lineno:
349 349 <a name="${old_line_anchor}" href="#${old_line_anchor}">${line.original.lineno}</a>
350 350 %endif
351 351 </td>
352 352 <td class="cb-content ${action_class(line.original.action)}"
353 353 data-line-number="o${line.original.lineno}"
354 354 ><span class="cb-code">${line.original.action} ${line.original.content or '' | n}</span>
355 355 </td>
356 356 <td class="cb-lineno ${action_class(line.modified.action)}"
357 357 data-line-number="${line.modified.lineno}"
358 358 %if new_line_anchor:
359 359 id="${new_line_anchor}"
360 360 %endif
361 361 >
362 362 %if line.modified.lineno:
363 363 <a name="${new_line_anchor}" href="#${new_line_anchor}">${line.modified.lineno}</a>
364 364 %endif
365 365 </td>
366 366 <td class="cb-content ${action_class(line.modified.action)}"
367 367 data-line-number="n${line.modified.lineno}"
368 368 >
369 369 <span class="cb-code">${line.modified.action} ${line.modified.content or '' | n}</span>
370 370 </td>
371 371 </tr>
372 372 %endfor
373 373 </%def>
374 374
375 375
376 376 <%def name="render_hunk_lines_unified(hunk)">
377 377 %for old_line_no, new_line_no, action, content in hunk.unified:
378 378 <%
379 379 old_line_anchor, new_line_anchor = None, None
380 380 if old_line_no:
381 381 old_line_anchor = diff_line_anchor(hunk.filediff.source_file_path, old_line_no, 'o')
382 382 if new_line_no:
383 383 new_line_anchor = diff_line_anchor(hunk.filediff.target_file_path, new_line_no, 'n')
384 384 %>
385 385 <tr class="cb-line">
386 386 <td class="cb-lineno ${action_class(action)}"
387 387 data-line-number="${old_line_no}"
388 388 %if old_line_anchor:
389 389 id="${old_line_anchor}"
390 390 %endif
391 391 >
392 392 %if old_line_anchor:
393 393 <a name="${old_line_anchor}" href="#${old_line_anchor}">${old_line_no}</a>
394 394 %endif
395 395 </td>
396 396 <td class="cb-lineno ${action_class(action)}"
397 397 data-line-number="${new_line_no}"
398 398 %if new_line_anchor:
399 399 id="${new_line_anchor}"
400 400 %endif
401 401 >
402 402 %if new_line_anchor:
403 403 <a name="${new_line_anchor}" href="#${new_line_anchor}">${new_line_no}</a>
404 404 %endif
405 405 </td>
406 406 <td class="cb-content ${action_class(action)}"
407 407 data-line-number="${new_line_no and 'n' or 'o'}${new_line_no or old_line_no}"
408 408 ><span class="cb-code">${action} ${content or '' | n}</span>
409 409 </td>
410 410 </tr>
411 411 %endfor
412 412 </%def>
General Comments 0
You need to be logged in to leave comments. Login now