def get_lines( self, start=0, end=None ): # Special case optimisation for if we have no edits at all if len( self.edits ) == 0: return self.staticdiffmodel.get_lines( start, end ) # TODO: Call something like self.staticdiffmodel.is_before_end( end ). # This can return early in most cases, meaning we don't need to # wait for diff to diff the whole model. num_lines = self.get_num_lines() if end is None or end > num_lines: end = num_lines # Create an array to hold the results. This array starts off containing # ints to indicate which line number should be inserted in which place, # and as edits are found for each line number, the ints are replaced # with DiffLine objects. editing_lines = list( EditingLine( line_num ) for line_num in xrange( start, end ) ) # Loop through all edits in reverse order, noting the # edit number (so that we can decide which edits should cause # an "edited" flag to be set), and applying them to the # list of lines we have made. for edit_num, edit in diffidenttools.reversed_enumerate( self.edits ): any_gaps_left = edit.apply_to( editing_lines, edit_num, self.save_points ) if not any_gaps_left: break ret = list( edited_line.create_filled_in_diffline( self.staticdiffmodel ) for edited_line in editing_lines ) return ret
def reversed_enumerate_empty(): assert( len( tuple( diffidenttools.reversed_enumerate( [] ) ) ) == 0 )
def reversed_enumerate(): assert( tuple( diffidenttools.reversed_enumerate( ["a", "b", "c"] ) ) == ( (2, "c"), (1, "b"), (0, "a") ) )