def modified_regions(old_data, new_data): regions = Regions() beg = None for pbeg, pend, fbeg, fend in bdiff.blocks(old_data, new_data): if beg is not None and beg != fbeg: regions.append(beg, fbeg) beg = fend return regions
def make_offsets(ws1, ws2): offsets_map={} blk=blocks('\n'.join(ws1),'\n'.join(ws2)) for i1,i2,j1,j2 in blk: if i2>i1: for i,j in izip(xrange(i1,i2),xrange(j1,j2)): offsets_map[i]=j return offsets_map
def modified_lines(old_data, new_data, max_lines): from itertools import count from mercurial import bdiff, mdiff modified = set() counter = count() for pbeg, pend, fbeg, fend in bdiff.blocks(old_data, new_data): for i in counter: if i < fbeg: modified.add(i) elif i + 1 >= fend: break elif i > max_lines: break return modified