##// END OF EJS Templates
git: switched diff to libgit2
marcink -
r755:114e4e43 default
parent child Browse files
Show More
@@ -927,11 +927,20 b' class GitRemote(RemoteBase):'
927 927 return _tree_items(repo_id, tree_id)
928 928
929 929 @reraise_safe_exceptions
930 def diff(self, wire, commit_id_1, commit_id_2, file_filter, opt_ignorews, context):
930 def diff_2(self, wire, commit_id_1, commit_id_2, file_filter, opt_ignorews, context):
931 """
932 Old version that uses subprocess to call diff
933 """
931 934
932 935 flags = [
933 '-U%s' % context, '--full-index', '--binary', '--patch',
934 '--find-renames', '--abbrev=40']
936 '-U%s' % context, '--patch',
937 '--binary',
938 '--find-renames',
939 '--no-indent-heuristic',
940 # '--indent-heuristic',
941 #'--full-index',
942 #'--abbrev=40'
943 ]
935 944
936 945 if opt_ignorews:
937 946 flags.append('--ignore-all-space')
@@ -956,8 +965,37 b' class GitRemote(RemoteBase):'
956 965 x += 1
957 966 # Append new line just like 'diff' command do
958 967 diff = '\n'.join(lines[x:]) + '\n'
968 return diff
959 969
960 return diff
970 @reraise_safe_exceptions
971 def diff(self, wire, commit_id_1, commit_id_2, file_filter, opt_ignorews, context):
972 repo_init = self._factory.repo_libgit2(wire)
973 with repo_init as repo:
974 swap = True
975 flags = 0
976 flags |= pygit2.GIT_DIFF_SHOW_BINARY
977
978 if opt_ignorews:
979 flags |= pygit2.GIT_DIFF_IGNORE_WHITESPACE
980
981 if commit_id_1 == self.EMPTY_COMMIT:
982 comm1 = repo[commit_id_2]
983 diff_obj = comm1.tree.diff_to_tree(
984 flags=flags, context_lines=context, swap=swap)
985
986 else:
987 comm1 = repo[commit_id_2]
988 comm2 = repo[commit_id_1]
989 diff_obj = comm1.tree.diff_to_tree(
990 comm2.tree, flags=flags, context_lines=context, swap=swap)
991
992 diff_obj.find_similar(flags=pygit2.GIT_DIFF_FIND_RENAMES)
993
994 if file_filter:
995 for p in diff_obj:
996 if p.delta.old_file.path == file_filter:
997 return p.patch
998 return diff_obj.patch
961 999
962 1000 @reraise_safe_exceptions
963 1001 def node_history(self, wire, commit_id, path, limit):
General Comments 0
You need to be logged in to leave comments. Login now