mercurial/patch.py
changeset 46030 2cf61e66c6d0
parent 45942 89a2afe31e82
parent 46020 210f9b8d7bbd
child 46246 416ecdaa12df
equal deleted inserted replaced
46018:8b0a3ff5ed12 46030:2cf61e66c6d0
  2728 
  2728 
  2729 
  2729 
  2730 def diffsinglehunkinline(hunklines):
  2730 def diffsinglehunkinline(hunklines):
  2731     """yield tokens for a list of lines in a single hunk, with inline colors"""
  2731     """yield tokens for a list of lines in a single hunk, with inline colors"""
  2732     # prepare deleted, and inserted content
  2732     # prepare deleted, and inserted content
  2733     a = b''
  2733     a = bytearray()
  2734     b = b''
  2734     b = bytearray()
  2735     for line in hunklines:
  2735     for line in hunklines:
  2736         if line[0:1] == b'-':
  2736         if line[0:1] == b'-':
  2737             a += line[1:]
  2737             a += line[1:]
  2738         elif line[0:1] == b'+':
  2738         elif line[0:1] == b'+':
  2739             b += line[1:]
  2739             b += line[1:]
  2743     if not a or not b:
  2743     if not a or not b:
  2744         for t in diffsinglehunk(hunklines):
  2744         for t in diffsinglehunk(hunklines):
  2745             yield t
  2745             yield t
  2746         return
  2746         return
  2747     # re-split the content into words
  2747     # re-split the content into words
  2748     al = wordsplitter.findall(a)
  2748     al = wordsplitter.findall(bytes(a))
  2749     bl = wordsplitter.findall(b)
  2749     bl = wordsplitter.findall(bytes(b))
  2750     # re-arrange the words to lines since the diff algorithm is line-based
  2750     # re-arrange the words to lines since the diff algorithm is line-based
  2751     aln = [s if s == b'\n' else s + b'\n' for s in al]
  2751     aln = [s if s == b'\n' else s + b'\n' for s in al]
  2752     bln = [s if s == b'\n' else s + b'\n' for s in bl]
  2752     bln = [s if s == b'\n' else s + b'\n' for s in bl]
  2753     an = b''.join(aln)
  2753     an = b''.join(aln)
  2754     bn = b''.join(bln)
  2754     bn = b''.join(bln)