[meld/Python3] filediff: Fix DiffChunk sorting tuple-of-maybe-tuples (bgo#767744)
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld/Python3] filediff: Fix DiffChunk sorting tuple-of-maybe-tuples (bgo#767744)
- Date: Thu, 16 Jun 2016 21:26:16 +0000 (UTC)
commit bc1878d13c93ffa7e405202679063238ecf44b7e
Author: Kai Willadsen <kai willadsen gmail com>
Date: Fri Jun 17 07:19:54 2016 +1000
filediff: Fix DiffChunk sorting tuple-of-maybe-tuples (bgo#767744)
We were sorting a tuple of DiffChunk-or-None elements, which no longer
compare in Python 3. In addition, the sort (which I believe exists only
so that we rehighlight in a predictable order) was doing a native
sort, which resulted in sorting first based on chunk type.
With this change, we handle None in merged chunks correctly (by
ignoring it) and sort based on a chunk's start location in the middle
column.
meld/diffutil.py | 7 +++++++
meld/filediff.py | 8 ++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/meld/diffutil.py b/meld/diffutil.py
index 2475cf2..da8097b 100644
--- a/meld/diffutil.py
+++ b/meld/diffutil.py
@@ -29,6 +29,13 @@ opcode_reverse = {
}
+def merged_chunk_order(merged_chunk):
+ if not merged_chunk:
+ return 0
+ chunk = merged_chunk[0] or merged_chunk[1]
+ return chunk.start_a
+
+
def reverse_chunk(chunk):
tag = opcode_reverse[chunk[0]]
return DiffChunk._make((tag, chunk[3], chunk[4], chunk[1], chunk[2]))
diff --git a/meld/filediff.py b/meld/filediff.py
index 0fefee9..83f0aa2 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -1209,8 +1209,12 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
# We need to clear removed and modified chunks, and need to
# re-highlight added and modified chunks.
- need_clearing = sorted(list(removed_chunks))
- need_highlighting = sorted(list(added_chunks) + [modified_chunks])
+ need_clearing = sorted(
+ list(removed_chunks),
+ key=diffutil.merged_chunk_order)
+ need_highlighting = sorted(
+ list(added_chunks) + [modified_chunks],
+ key=diffutil.merged_chunk_order)
alltags = [b.get_tag_table().lookup("inline") for b in self.textbuffer]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]