mercurial/mdiff.py
changeset 515 03f27b1381f9
parent 432 3b9e3d3d2810
child 582 df8a5a0098d4
equal deleted inserted replaced
514:874e577e332e 515:03f27b1381f9
    45 
    45 
    46 def sortdiff(a, b):
    46 def sortdiff(a, b):
    47     la = lb = 0
    47     la = lb = 0
    48     lena = len(a)
    48     lena = len(a)
    49     lenb = len(b)
    49     lenb = len(b)
    50     
    50 
    51     while 1:
    51     while 1:
    52         am, bm, = la, lb
    52         am, bm, = la, lb
    53 
    53 
    54         # walk over matching lines
    54         # walk over matching lines
    55         while lb < lenb and la < lena and a[la] == b[lb] :
    55         while lb < lenb and la < lena and a[la] == b[lb] :
    63         while la < lena and lb < lenb and b[lb] < a[la]:
    63         while la < lena and lb < lenb and b[lb] < a[la]:
    64             lb += 1
    64             lb += 1
    65 
    65 
    66         if lb >= lenb:
    66         if lb >= lenb:
    67             break
    67             break
    68         
    68 
    69         # skip mismatched lines from a
    69         # skip mismatched lines from a
    70         while la < lena and lb < lenb and b[lb] > a[la]:
    70         while la < lena and lb < lenb and b[lb] > a[la]:
    71             la += 1
    71             la += 1
    72 
    72 
    73         if la >= lena:
    73         if la >= lena:
    74             break
    74             break
    75         
    75 
    76     yield (lena, lenb, 0)
    76     yield (lena, lenb, 0)
    77 
    77 
    78 def diff(a, b, sorted=0):
    78 def diff(a, b, sorted=0):
    79     if not a:
    79     if not a:
    80         s = "".join(b)
    80         s = "".join(b)
    98         s = "".join(b[lb:bm])
    98         s = "".join(b[lb:bm])
    99         if am > la or s:
    99         if am > la or s:
   100             bin.append(struct.pack(">lll", p[la], p[am], len(s)) + s)
   100             bin.append(struct.pack(">lll", p[la], p[am], len(s)) + s)
   101         la = am + size
   101         la = am + size
   102         lb = bm + size
   102         lb = bm + size
   103     
   103 
   104     return "".join(bin)
   104     return "".join(bin)
   105 
   105 
   106 def patchtext(bin):
   106 def patchtext(bin):
   107     pos = 0
   107     pos = 0
   108     t = []
   108     t = []