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 modregions(wctx, fname): fctx = wctx.filectx(fname) pctx = fctx.parents() file_data = fctx.data() lines = mdiff.splitnewlines(file_data) if len(pctx) in (1, 2): mod_regions = modified_regions(pctx[0].data(), file_data) if len(pctx) == 2: m2 = modified_regions(pctx[1].data(), file_data) # only the lines that are new in both mod_regions &= m2 else: mod_regions = Regions() mod_regions.add(0, len(lines)) return mod_regions
def modregions(wctx, fname): fctx = wctx.filectx(fname) pctx = fctx.parents() file_data = fctx.data() lines = mdiff.splitnewlines(file_data) if len(pctx) in (1, 2): mod_regions = modified_regions(pctx[0].data(), file_data) if len(pctx) == 2: m2 = modified_regions(pctx[1].data(), file_data) # only the lines that are new in both mod_regions &= m2 else: mod_regions = Regions() mod_regions.append(0, len(lines)) return mod_regions
import re import sys from os.path import dirname, join as joinpath from itertools import count from mercurial import bdiff, mdiff current_dir = dirname(__file__) sys.path.insert(0, current_dir) sys.path.insert(1, joinpath(dirname(current_dir), 'src', 'python')) from m5.util import neg_inf, pos_inf, Region, Regions import sort_includes from file_types import lang_type all_regions = Regions(Region(neg_inf, pos_inf)) tabsize = 8 lead = re.compile(r'^([ \t]+)') trail = re.compile(r'([ \t]+)$') any_control = re.compile(r'\b(if|while|for)[ \t]*[(]') good_control = re.compile(r'\b(if|while|for) [(]') format_types = set(('C', 'C++')) 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: