Skip to content

Commit cd2db30

Browse files
libgit2 upgrade fixes
1 parent 333ccb6 commit cd2db30

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

CodeReview/GUI/LogBrowser/CommitTableModel.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import logging
2222

23-
####################################################################################################
23+
import pygit2 as git
2424

2525
from PyQt5 import QtCore, QtGui, QtWidgets
2626
from PyQt5.QtCore import Qt
@@ -53,6 +53,13 @@ class CommitTableModel(QtCore.QAbstractTableModel):
5353
'Similarity',
5454
)
5555

56+
__status_to_letter__ = {
57+
git.GIT_DELTA_DELETED: 'D',
58+
git.GIT_DELTA_MODIFIED: 'M',
59+
git.GIT_DELTA_ADDED: 'A',
60+
git.GIT_DELTA_RENAMED: 'R',
61+
}
62+
5663
##############################################
5764

5865
def __init__(self):
@@ -70,13 +77,15 @@ def update(self, diff):
7077
self._number_of_rows = 0
7178

7279
for patch in diff:
73-
if patch.new_file_path != patch.old_file_path:
74-
new_file_path = patch.new_file_path
75-
similarity = ' {} %'.format(patch.similarity)
80+
delta = patch.delta
81+
if delta.new_file.path != delta.old_file.path:
82+
new_file_path = delta.new_file.path
83+
similarity = ' {} %'.format(delta.similarity)
7684
else:
7785
new_file_path = ''
7886
similarity = ''
79-
row = (patch.status, patch.old_file_path, new_file_path, similarity, patch)
87+
status = self.__status_to_letter__[delta.status]
88+
row = (status, delta.old_file.path, new_file_path, similarity, patch)
8089
self._rows.append(row)
8190

8291
self._number_of_rows = len(self._rows)

CodeReview/GUI/LogBrowser/LogBrowserMainWindow.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from PyQt5 import QtWidgets
2424
from PyQt5.QtCore import Qt
2525

26+
import pygit2 as git
27+
2628
####################################################################################################
2729

2830
from CodeReview.GUI.Base.MainWindowBase import MainWindowBase
@@ -249,25 +251,26 @@ def _show_current_patch(self):
249251
self._diff_window.showMaximized()
250252

251253
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:
256259
# print(hunk.old_start, hunk.old_lines, hunk.new_start, hunk.new_lines, hunk.lines)
257260
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)
264267
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)]
268271
self._diff_window.diff_documents(paths, texts, metadatas, workdir=repository.workdir)
269272
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)
271274
# Fixme: show image pdf ...
272275

273276
##############################################

CodeReview/Repository/Git.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ def diff(self, a=None, b=None, cached=False, path_filter=None):
8787
diff.find_similar()
8888
# flags, rename_threshold, copy_threshold, rename_from_rewrite_threshold, break_rewrite_threshold, rename_limit
8989
for patch in diff:
90-
if path_filter and not patch.old_file_path.startswith(path_filter):
91-
# self._logger.info('Skip ' + patch.old_file_path)
90+
delta = patch.delta
91+
if path_filter and not delta.old_file.path.startswith(path_filter):
92+
# self._logger.info('Skip ' + delta.old_file.path)
9293
continue
9394
patches.append(patch)
9495

0 commit comments

Comments
 (0)