Exemplo n.º 1
0
 def _auto_merge(self, using, texts):
     """Automatically merge two sequences of change blocks"""
     l0, h0, l1, h1, l2, h2 = self._merge_blocks(using)
     if h0 - l0 == h2 - l2 and texts[0][l0:h0] == texts[2][l2:h2]:
         if l1 != h1 and l0 == h0:
             tag = "delete"
         elif l1 != h1:
             tag = "replace"
         else:
             tag = "insert"
     else:
         tag = "conflict"
     out0 = DiffChunk._make((tag, l1, h1, l0, h0))
     out1 = DiffChunk._make((tag, l1, h1, l2, h2))
     yield out0, out1
Exemplo n.º 2
0
 def _auto_merge(self, using, texts):
     """Automatically merge two sequences of change blocks"""
     l0, h0, l1, h1, l2, h2 = self._merge_blocks(using)
     if h0 - l0 == h2 - l2 and texts[0][l0:h0] == texts[2][l2:h2]:
         if l1 != h1 and l0 == h0:
             tag = "delete"
         elif l1 != h1:
             tag = "replace"
         else:
             tag = "insert"
     else:
         tag = "conflict"
     out0 = DiffChunk._make((tag, l1, h1, l0, h0))
     out1 = DiffChunk._make((tag, l1, h1, l2, h2))
     yield out0, out1
Exemplo n.º 3
0
 def offset(c, start, o1, o2):
     """Offset a chunk by o1/o2 if it's after the inserted lines"""
     if c is None:
         return None
     start_a = c.start_a + (o1 if c.start_a > start else 0)
     end_a = c.end_a + (o1 if c.end_a > start else 0)
     start_b = c.start_b + (o2 if c.start_b > start else 0)
     end_b = c.end_b + (o2 if c.end_b > start else 0)
     return DiffChunk._make((c.tag, start_a, end_a, start_b, end_b))
Exemplo n.º 4
0
 def offset(c, start, o1, o2):
     """Offset a chunk by o1/o2 if it's after the inserted lines"""
     if c is None:
         return None
     start_a = c.start_a + (o1 if c.start_a > start else 0)
     end_a = c.end_a + (o1 if c.end_a > start else 0)
     start_b = c.start_b + (o2 if c.start_b > start else 0)
     end_b = c.end_b + (o2 if c.end_b > start else 0)
     return DiffChunk._make((c.tag, start_a, end_a, start_b, end_b))
Exemplo n.º 5
0
def consume_blank_lines(chunk, texts, pane1, pane2):
    if chunk is None:
        return None

    def _find_blank_lines(txt, lo, hi):
        while lo < hi and not txt[lo]:
            lo += 1
        while lo < hi and not txt[hi - 1]:
            hi -= 1
        return lo, hi

    tag = chunk.tag
    c1, c2 = _find_blank_lines(texts[pane1], chunk[1], chunk[2])
    c3, c4 = _find_blank_lines(texts[pane2], chunk[3], chunk[4])

    if c1 == c2 and c3 == c4:
        return None
    if c1 == c2 and tag == "replace":
        tag = "insert"
    elif c3 == c4 and tag == "replace":
        tag = "delete"
    return DiffChunk._make((tag, c1, c2, c3, c4))
Exemplo n.º 6
0
def consume_blank_lines(chunk, texts, pane1, pane2):
    if chunk is None:
        return None

    def _find_blank_lines(txt, lo, hi):
        while lo < hi and not txt[lo]:
            lo += 1
        while lo < hi and not txt[hi - 1]:
            hi -= 1
        return lo, hi

    tag = chunk.tag
    c1, c2 = _find_blank_lines(texts[pane1], chunk[1], chunk[2])
    c3, c4 = _find_blank_lines(texts[pane2], chunk[3], chunk[4])

    if c1 == c2 and c3 == c4:
        return None
    if c1 == c2 and tag == "replace":
        tag = "insert"
    elif c3 == c4 and tag == "replace":
        tag = "delete"
    return DiffChunk._make((tag, c1, c2, c3, c4))
Exemplo n.º 7
0
def reverse_chunk(chunk):
    tag = opcode_reverse[chunk[0]]
    return DiffChunk._make((tag, chunk[3], chunk[4], chunk[1], chunk[2]))
Exemplo n.º 8
0
 def offset(c, o1, o2):
     return DiffChunk._make(
         (c[0], c[1] + o1, c[2] + o1, c[3] + o2, c[4] + o2))
Exemplo n.º 9
0
def reverse_chunk(chunk):
    tag = opcode_reverse[chunk[0]]
    return DiffChunk._make((tag, chunk[3], chunk[4], chunk[1], chunk[2]))
Exemplo n.º 10
0
 def offset(c, o1, o2):
     return DiffChunk._make((c[0], c[1] + o1, c[2] + o1,
                             c[3] + o2, c[4] + o2))
Exemplo n.º 11
0
def make_chunk(chunk_type):
    return DiffChunk(chunk_type, 0, 1, 0, 1)
Exemplo n.º 12
0
 def make_last_line_chunk(buf):
     end = buf.get_line_count()
     last = end - 1
     return DiffChunk('delete', last, end, last, end)