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