def get_patched_content(self): """Get self.patched_content, computing it if necessary. This is the content of the file after applying this patch. Returns: a Content instance. Raises: engine.FetchError: If there was a problem fetching the old content. """ try: if self.patched_content is not None: return self.patched_content except db.Error: # This may happen when a Content entity was deleted behind our # back. self.patched_content = None old_lines = self.get_content().text.splitlines(True) logging.info('Creating patched_content for %s', self.filename) chunks = patching.ParsePatchToChunks(self.lines, self.filename) new_lines = [] for _, _, new in patching.PatchChunks(old_lines, chunks): new_lines.extend(new) text = db.Text(''.join(new_lines)) patched_content = Content(text=text, parent=self) patched_content.put() self.patched_content = patched_content self.put() return patched_content
def _RenderDiffTableRows(request, old_lines, chunks, patch, colwidth=DEFAULT_COLUMN_WIDTH, debug=False): """Internal version of RenderDiffTableRows(). Args: The same as for RenderDiffTableRows. Yields: Tuples (tag, row) where tag is an indication of the row type. """ old_dict = {} new_dict = {} if patch: old_dict, new_dict = _GetComments(request) old_max, new_max = _ComputeLineCounts(old_lines, chunks) return _TableRowGenerator(patch, old_dict, old_max, 'old', patch, new_dict, new_max, 'new', patching.PatchChunks(old_lines, chunks), colwidth, debug)
def _apply_patch(old_lines, patch_name, dif_lines): new_lines = [] chunks = patching.ParsePatchToChunks(dif_lines, patch_name) for tag, old, new in patching.PatchChunks(old_lines, chunks): new_lines.extend(new) return ''.join(new_lines)