| 193 | |
| 194 | |
| 195 | def diff(patch, stream=sys.stdout.write): |
| 196 | # Diff header |
| 197 | |
| 198 | old_fp = patch.delta.old_file.path |
| 199 | new_fp = patch.delta.new_file.path |
| 200 | puts('Diff of file "{0}"'.format(old_fp), stream=stream) |
| 201 | if old_fp != new_fp: |
| 202 | puts(colored.cyan(' (renamed to {0})'.format(new_fp)), stream=stream) |
| 203 | puts(stream=stream) |
| 204 | |
| 205 | if patch.delta.is_binary: |
| 206 | puts('Not showing diffs for binary file', stream=stream) |
| 207 | return |
| 208 | |
| 209 | additions = patch.line_stats[1] |
| 210 | deletions = patch.line_stats[2] |
| 211 | if (not additions) and (not deletions): |
| 212 | puts('No diffs to output for file', stream=stream) |
| 213 | return |
| 214 | |
| 215 | put_s = lambda num: '' if num == 1 else 's' |
| 216 | puts('{0} line{1} added'.format(additions, put_s(additions)), stream=stream) |
| 217 | puts('{0} line{1} removed'.format(deletions, put_s(deletions)), stream=stream) |
| 218 | puts(stream=stream) |
| 219 | |
| 220 | # Diff body |
| 221 | |
| 222 | for hunk in patch.hunks: |
| 223 | puts(stream=stream) |
| 224 | _hunk(hunk, stream=stream) |
| 225 | |
| 226 | puts(stream=stream) |
| 227 | puts(stream=stream) |
| 228 | |
| 229 | |
| 230 | def _hunk(hunk, stream=sys.stdout.write): |