|
23 | 23 | from PyQt5 import QtWidgets
|
24 | 24 | from PyQt5.QtCore import Qt
|
25 | 25 |
|
| 26 | +import pygit2 as git |
| 27 | + |
26 | 28 | ####################################################################################################
|
27 | 29 |
|
28 | 30 | from CodeReview.GUI.Base.MainWindowBase import MainWindowBase
|
@@ -249,25 +251,26 @@ def _show_current_patch(self):
|
249 | 251 | self._diff_window.showMaximized()
|
250 | 252 |
|
251 | 253 | patch = self._diff[self._current_patch]
|
252 |
| - if not patch.is_binary: |
253 |
| - self._logger.info('revision {} '.format(self._current_revision) + patch.new_file_path) |
254 |
| - # print(patch.status, patch.similarity, patch.additions, patch.deletions, patch.is_binary) |
255 |
| - # for hunk in patch.hunks: |
| 254 | + delta = patch.delta |
| 255 | + if not delta.is_binary: |
| 256 | + self._logger.info('revision {} '.format(self._current_revision) + delta.new_file.path) |
| 257 | + # print(delta.status, delta.similarity, delta.additions, delta.deletions, delta.is_binary) |
| 258 | + # for hunk in delta.hunks: |
256 | 259 | # print(hunk.old_start, hunk.old_lines, hunk.new_start, hunk.new_lines, hunk.lines)
|
257 | 260 | repository = self._application.repository
|
258 |
| - if patch.status in ('M', 'R'): |
259 |
| - paths = (patch.old_file_path, patch.new_file_path) |
260 |
| - elif patch.status == 'A': |
261 |
| - paths = (None, patch.new_file_path) |
262 |
| - elif patch.status == 'D': |
263 |
| - paths = (patch.old_file_path, None) |
| 261 | + if delta.status in (git.GIT_DELTA_MODIFIED, git.GIT_DELTA_RENAMED): |
| 262 | + paths = (delta.old_file.path, delta.new_file.path) |
| 263 | + elif delta.status == git.GIT_DELTA_ADDED: |
| 264 | + paths = (None, delta.new_file.path) |
| 265 | + elif delta.status == git.GIT_DELTA_DELETED: |
| 266 | + paths = (delta.old_file.path, None) |
264 | 267 | texts = [repository.file_content(blob_id)
|
265 |
| - for blob_id in (patch.old_id, patch.new_id)] |
266 |
| - metadatas = [dict(path=patch.old_file_path, document_type='file', last_modification_date=None), |
267 |
| - dict(path=patch.new_file_path, document_type='file', last_modification_date=None)] |
| 268 | + for blob_id in (delta.old_file.id, delta.new_file.id)] |
| 269 | + metadatas = [dict(path=delta.old_file.path, document_type='file', last_modification_date=None), |
| 270 | + dict(path=delta.new_file.path, document_type='file', last_modification_date=None)] |
268 | 271 | self._diff_window.diff_documents(paths, texts, metadatas, workdir=repository.workdir)
|
269 | 272 | else:
|
270 |
| - self._logger.info('revision {} Binary '.format(self._current_revision) + patch.new_file_path) |
| 273 | + self._logger.info('revision {} Binary '.format(self._current_revision) + delta.new_file.path) |
271 | 274 | # Fixme: show image pdf ...
|
272 | 275 |
|
273 | 276 | ##############################################
|
|
0 commit comments