Jump to >

reviewboard.diffviewer.chunk_generator

class NoWrapperHtmlFormatter(*args, **kwargs)[source]

Bases: pygments.formatters.html.HtmlFormatter

An HTML Formatter for Pygments that doesn’t wrap items in a div.

__init__(*args, **kwargs)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

class RawDiffChunkGenerator(old, new, orig_filename, modified_filename, enable_syntax_highlighting=True, encoding_list=None, diff_compat=2)[source]

Bases: object

A generator for chunks for a diff that can be used for rendering.

Each chunk represents an insert, delete, replace, or equal section. It contains all the data needed to render the portion of the diff.

This is general-purpose and meant to operate on strings each consisting of at least one line of text, or lists of lines of text.

If the caller passes lists of lines instead of strings, then the caller will also be responsible for applying any syntax highlighting and dealing with newline differences.

NEWLINES_RE = <_sre.SRE_Pattern object>[source]
STYLED_MAX_LINE_LEN = 1000[source]
STYLED_MAX_LIMIT_BYTES = 200000[source]
STYLED_EXT_BLACKLIST = (u'.txt',)[source]
TAB_SIZE = 8[source]
__init__(old, new, orig_filename, modified_filename, enable_syntax_highlighting=True, encoding_list=None, diff_compat=2)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

get_opcode_generator()[source]

Return the DiffOpcodeGenerator used to generate diff opcodes.

get_chunks(cache_key=None)[source]

Return the chunks for the given diff information.

If a cache key is provided and there are chunks already computed in the cache, they will be yielded. Otherwise, new chunks will be generated, stored in cache (given a cache key), and yielded.

get_chunks_uncached()[source]

Yield the list of chunks, bypassing the cache.

generate_chunks(old, new)[source]

Generate chunks for the difference between two strings.

The strings will be normalized, ensuring they’re of the proper encoding and ensuring they have consistent newlines. They’re then syntax-highlighted (if requested).

Once the strings are ready, chunks are built from the strings and yielded to the caller. Each chunk represents information on an equal, inserted, deleted, or replaced set of lines.

The number of lines of each chunk type are stored in the counts dictionary, which can then be accessed after yielding all chunks.

normalize_source_string(s)[source]

Normalize a source string of text to use for the diff.

This will normalize the encoding of the string and the newlines, returning a tuple containing the normalized string and a list of lines split from the source.

Both the original and modified strings used for the diff will be normalized independently.

This is only used if the caller passes a string instead of a list for the original or new values.

Subclasses can override this to provide custom behavior.

normalize_source_list(l)[source]

Normalize a list of source lines to use for the diff.

This will normalize the encoding of the lines.

Both the original and modified lists of lines used for the diff will be normalized independently.

This is only used if the caller passes a list instead of a string for the original or new values.

Subclasses can override this to provide custom behavior.

normalize_path_for_display(filename)[source]

Normalize a file path for display to the user.

By default, this returns the filename as-is. Subclasses can override the behavior to return a variant of the filename.

get_line_changed_regions(old_line_num, old_line, new_line_num, new_line)[source]

Return information on changes between two lines.

This returns a tuple containing a list of tuples of ranges in the old line, and a list of tuples of ranges in the new line, that should be highlighted.

This defaults to simply wrapping get_line_changed_regions() from diffutils. Subclasses can override to provide custom behavior.

class DiffChunkGenerator(request, filediff, interfilediff=None, force_interdiff=False, enable_syntax_highlighting=True)[source]

Bases: reviewboard.diffviewer.chunk_generator.RawDiffChunkGenerator

A generator for chunks for a FileDiff that can be used for rendering.

Each chunk represents an insert, delete, replace, or equal section. It contains all the data needed to render the portion of the diff.

There are three ways this can operate, based on provided parameters.

  1. filediff, no interfilediff - Returns chunks for a single filediff. This is the usual way people look at diffs in the diff viewer.

    In this mode, we get the original file based on the filediff and then patch it to get the resulting file.

    This is also used for interdiffs where the source revision has no equivalent modified file but the interdiff revision does. It’s no different than a standard diff.

  2. filediff, interfilediff - Returns chunks showing the changes between a source filediff and the interdiff.

    This is the typical mode used when showing the changes between two diffs. It requires that the file is included in both revisions of a diffset.

  3. filediff, no interfilediff, force_interdiff - Returns chunks showing the changes between a source diff and an unmodified version of the diff.

    This is used when the source revision in the diffset contains modifications to a file which have then been reverted in the interdiff revision. We don’t actually have an interfilediff in this case, so we have to indicate that we are indeed in interdiff mode so that we can special-case this and not grab a patched file for the interdiff version.

__init__(request, filediff, interfilediff=None, force_interdiff=False, enable_syntax_highlighting=True)[source]

x.__init__(…) initializes x; see help(type(x)) for signature

make_cache_key()[source]

Create a cache key for any generated chunks.

get_opcode_generator()[source]

Return the DiffOpcodeGenerator used to generate diff opcodes.

get_chunks()[source]

Return the chunks for the given diff information.

If the file is binary or is an added or deleted 0-length file, or if the file has moved with no additional changes, then an empty list of chunks will be returned.

If there are chunks already computed in the cache, they will be yielded. Otherwise, new chunks will be generated, stored in cache, and yielded.

get_chunks_uncached()[source]

Yield the list of chunks, bypassing the cache.

normalize_path_for_display(filename)[source]
compute_chunk_last_header(lines, numlines, meta, last_header=None)[source]

Computes information for the displayed function/class headers.

This will record the displayed headers, their line numbers, and expansion offsets relative to the header’s collapsed line range.

The last_header variable, if provided, will be modified, which is important when processing several chunks at once. It will also be returned as a convenience.

get_diff_chunk_generator_class()[source]

Returns the DiffChunkGenerator class used for generating chunks.

set_diff_chunk_generator_class(renderer)[source]

Sets the DiffChunkGenerator class used for generating chunks.

get_diff_chunk_generator(*args, **kwargs)[source]

Returns a DiffChunkGenerator instance used for generating chunks.