| OLD | NEW |
| 1 # Copyright 2008 Google Inc. | 1 # Copyright 2008 Google Inc. |
| 2 # | 2 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 3 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. | 4 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at | 5 # You may obtain a copy of the License at |
| 6 # | 6 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 7 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 8 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 9 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 10 # distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 162 matching lines...) | | Loading... |
| 173 url = base | 173 url = base |
| 174 if not url.endswith('/'): | 174 if not url.endswith('/'): |
| 175 url += '/' | 175 url += '/' |
| 176 url += filename | 176 url += filename |
| 177 if rev is not None: | 177 if rev is not None: |
| 178 url += '?rev=%s' % rev | 178 url += '?rev=%s' % rev |
| 179 return url | 179 return url |
| 180 | 180 |
| 181 | 181 |
| 182 DEFAULT_CONTEXT = 10 | 182 DEFAULT_CONTEXT = 10 |
| 183 | 183 DEFAULT_COLUMN_WIDTH = 80 |
| 184 | 184 |
| 185 def RenderDiffTableRows(request, old_lines, chunks, patch, | 185 def RenderDiffTableRows(request, old_lines, chunks, patch, |
| 186 colwidth=80, debug=False, context=DEFAULT_CONTEXT): | 186 colwidth=DEFAULT_COLUMN_WIDTH, debug=False, context=DEFA
ULT_CONTEXT): |
Andi Albrecht
2008年11月04日 14:11:29
Line too long and missing blank line above "def Re
|
| 187 """Render the HTML table rows for a side-by-side diff for a patch. | 187 """Render the HTML table rows for a side-by-side diff for a patch. |
| 188 | 188 |
| 189 Args: | 189 Args: |
| 190 request: Django Request object. | 190 request: Django Request object. |
| 191 old_lines: List of lines representing the original file. | 191 old_lines: List of lines representing the original file. |
| 192 chunks: List of chunks as returned by patching.ParsePatchToChunks(). | 192 chunks: List of chunks as returned by patching.ParsePatchToChunks(). |
| 193 patch: A models.Patch instance. | 193 patch: A models.Patch instance. |
| 194 colwidth: Optional column width (default 80). | 194 colwidth: Optional column width (default 80). |
| 195 debug: Optional debugging flag (default False). | 195 debug: Optional debugging flag (default False). |
| 196 context: Maximum number of rows surrounding a change (default CONTEXT). | 196 context: Maximum number of rows surrounding a change (default CONTEXT). |
| 197 | 197 |
| 198 Yields: | 198 Yields: |
| 199 Strings, each of which represents the text rendering one complete | 199 Strings, each of which represents the text rendering one complete |
| 200 pair of lines of the side-by-side diff, possibly including comments. | 200 pair of lines of the side-by-side diff, possibly including comments. |
| 201 Each yielded string may consist of several <tr> elements. | 201 Each yielded string may consist of several <tr> elements. |
| 202 """ | 202 """ |
| 203 rows = _RenderDiffTableRows(request, old_lines, chunks, patch, | 203 rows = _RenderDiffTableRows(request, old_lines, chunks, patch, |
| 204 colwidth, debug) | 204 colwidth, debug) |
| 205 return _CleanupTableRowsGenerator(rows, context) | 205 return _CleanupTableRowsGenerator(rows, context) |
| 206 | 206 |
| 207 | 207 |
| 208 def RenderDiff2TableRows(request, old_lines, old_patch, new_lines, new_patch, | 208 def RenderDiff2TableRows(request, old_lines, old_patch, new_lines, new_patch, |
| 209 colwidth=80, debug=False, context=DEFAULT_CONTEXT): | 209 colwidth=DEFAULT_COLUMN_WIDTH, debug=False, context=DEF
AULT_CONTEXT): |
| 210 """Render the HTML table rows for a side-by-side diff between two patches. | 210 """Render the HTML table rows for a side-by-side diff between two patches. |
| 211 | 211 |
| 212 Args: | 212 Args: |
| 213 request: Django Request object. | 213 request: Django Request object. |
| 214 old_lines: List of lines representing the patched file on the left. | 214 old_lines: List of lines representing the patched file on the left. |
| 215 old_patch: The models.Patch instance corresponding to old_lines. | 215 old_patch: The models.Patch instance corresponding to old_lines. |
| 216 new_lines: List of lines representing the patched file on the right. | 216 new_lines: List of lines representing the patched file on the right. |
| 217 new_patch: The models.Patch instance corresponding to new_lines. | 217 new_patch: The models.Patch instance corresponding to new_lines. |
| 218 colwidth: Optional column width (default 80). | 218 colwidth: Optional column width (default 80). |
| 219 debug: Optional debugging flag (default False). | 219 debug: Optional debugging flag (default False). |
| (...skipping 77 matching lines...) | | Loading... |
| 297 'style="background:lightblue">' | 297 'style="background:lightblue">' |
| 298 '(...skipping <span id="skipcount-%d">%d</span> matching lines...) ' | 298 '(...skipping <span id="skipcount-%d">%d</span> matching lines...) ' |
| 299 '<span id="skiplinks-%d">%s</span>' | 299 '<span id="skiplinks-%d">%s</span>' |
| 300 '</td></tr>\n' % (last_id, last_id, skip, | 300 '</td></tr>\n' % (last_id, last_id, skip, |
| 301 last_id, expand_link)) | 301 last_id, expand_link)) |
| 302 for t in buffer[-context:]: | 302 for t in buffer[-context:]: |
| 303 yield t | 303 yield t |
| 304 | 304 |
| 305 | 305 |
| 306 def _RenderDiff2TableRows(request, old_lines, old_patch, new_lines, new_patch, | 306 def _RenderDiff2TableRows(request, old_lines, old_patch, new_lines, new_patch, |
| 307 colwidth=80, debug=False): | 307 colwidth=DEFAULT_COLUMN_WIDTH, debug=False): |
| 308 """Internal version of RenderDiff2TableRows(). | 308 """Internal version of RenderDiff2TableRows(). |
| 309 | 309 |
| 310 Args: | 310 Args: |
| 311 The same as for RenderDiff2TableRows. | 311 The same as for RenderDiff2TableRows. |
| 312 | 312 |
| 313 Yields: | 313 Yields: |
| 314 Tuples (tag, row) where tag is an indication of the row type. | 314 Tuples (tag, row) where tag is an indication of the row type. |
| 315 """ | 315 """ |
| 316 old_dict = {} | 316 old_dict = {} |
| 317 new_dict = {} | 317 new_dict = {} |
| (...skipping 51 matching lines...) | | Loading... |
| 369 comment.complete(request.patch) | 369 comment.complete(request.patch) |
| 370 if comment.left: | 370 if comment.left: |
| 371 dct = old_dict | 371 dct = old_dict |
| 372 else: | 372 else: |
| 373 dct = new_dict | 373 dct = new_dict |
| 374 dct.setdefault(comment.lineno, []).append(comment) | 374 dct.setdefault(comment.lineno, []).append(comment) |
| 375 return old_dict, new_dict | 375 return old_dict, new_dict |
| 376 | 376 |
| 377 | 377 |
| 378 def _RenderDiffTableRows(request, old_lines, chunks, patch, | 378 def _RenderDiffTableRows(request, old_lines, chunks, patch, |
| 379 colwidth=80, debug=False): | 379 colwidth=DEFAULT_COLUMN_WIDTH, debug=False): |
| 380 """Internal version of RenderDiffTableRows(). | 380 """Internal version of RenderDiffTableRows(). |
| 381 | 381 |
| 382 Args: | 382 Args: |
| 383 The same as for RenderDiffTableRows. | 383 The same as for RenderDiffTableRows. |
| 384 | 384 |
| 385 Yields: | 385 Yields: |
| 386 Tuples (tag, row) where tag is an indication of the row type. | 386 Tuples (tag, row) where tag is an indication of the row type. |
| 387 """ | 387 """ |
| 388 old_dict = {} | 388 old_dict = {} |
| 389 new_dict = {} | 389 new_dict = {} |
| 390 if patch: | 390 if patch: |
| 391 old_dict, new_dict = _GetComments(request) | 391 old_dict, new_dict = _GetComments(request) |
| 392 old_max, new_max = _ComputeLineCounts(old_lines, chunks) | 392 old_max, new_max = _ComputeLineCounts(old_lines, chunks) |
| 393 return _TableRowGenerator(patch, old_dict, old_max, 'old', | 393 return _TableRowGenerator(patch, old_dict, old_max, 'old', |
| 394 patch, new_dict, new_max, 'new', | 394 patch, new_dict, new_max, 'new', |
| 395 patching.PatchChunks(old_lines, chunks), | 395 patching.PatchChunks(old_lines, chunks), |
| 396 colwidth, debug) | 396 colwidth, debug) |
| 397 | 397 |
| 398 | 398 |
| 399 def _TableRowGenerator(old_patch, old_dict, old_max, old_snapshot, | 399 def _TableRowGenerator(old_patch, old_dict, old_max, old_snapshot, |
| 400 new_patch, new_dict, new_max, new_snapshot, | 400 new_patch, new_dict, new_max, new_snapshot, |
| 401 triple_iterator, colwidth=80, debug=False): | 401 triple_iterator, colwidth=DEFAULT_COLUMN_WIDTH, debug=Fal
se): |
| 402 """Helper function to render side-by-side table rows. | 402 """Helper function to render side-by-side table rows. |
| 403 | 403 |
| 404 Args: | 404 Args: |
| 405 old_patch: First models.Patch instance. | 405 old_patch: First models.Patch instance. |
| 406 old_dict: Dictionary with line numbers as keys and comments as values (left) | 406 old_dict: Dictionary with line numbers as keys and comments as values (left) |
| 407 old_max: Line count of the patch on the left. | 407 old_max: Line count of the patch on the left. |
| 408 old_snapshot: A tag used in the comments form. | 408 old_snapshot: A tag used in the comments form. |
| 409 new_patch: Second models.Patch instance. | 409 new_patch: Second models.Patch instance. |
| 410 new_dict: Same as old_dict, but for the right side. | 410 new_dict: Same as old_dict, but for the right side. |
| 411 new_max: Line count of the patch on the right. | 411 new_max: Line count of the patch on the right. |
| (...skipping 383 matching lines...) | | Loading... |
| 795 Args: | 795 Args: |
| 796 text: a string. | 796 text: a string. |
| 797 | 797 |
| 798 Returns: | 798 Returns: |
| 799 A db.Text instance. | 799 A db.Text instance. |
| 800 """ | 800 """ |
| 801 try: | 801 try: |
| 802 return db.Text(text, encoding='utf-8') | 802 return db.Text(text, encoding='utf-8') |
| 803 except UnicodeDecodeError: | 803 except UnicodeDecodeError: |
| 804 return db.Text(text, encoding='latin-1') | 804 return db.Text(text, encoding='latin-1') |
| OLD | NEW |