reviewboard.diffviewer.differ¶
Base definitions for differ implementations.
- class DiffCompatVersion[source]¶
Bases:
objectDiff compatibility versions.
- DiffOpcodeTag¶
The potential values for opcode tags.
New in version 8.0.
alias of
Literal[‘delete’, ‘equal’, ‘filtered-equal’, ‘insert’, ‘replace’]
- DiffOpcode¶
The structure used for opcodes.
New in version 8.0.
alias of
tuple[Literal[‘delete’, ‘equal’, ‘filtered-equal’, ‘insert’, ‘replace’],int,int,int,int]
- DiffOpcodeWithMetadata¶
The structure used for opcodes with metadata.
New in version 8.0.
alias of
tuple[Literal[‘delete’, ‘equal’, ‘filtered-equal’, ‘insert’, ‘replace’],int,int,int,int,dict[str,Any] |None]
- class Differ(a: Sequence[str], b: Sequence[str], ignore_space: bool = False, compat_version: int = 2)[source]¶
Bases:
objectBase class for differs.
- __init__(a: Sequence[str], b: Sequence[str], ignore_space: bool = False, compat_version: int = 2) None[source]¶
Initialize the differ.
- compat_version: int¶
The diff compatibility version.
Changed in version 8.0: Changed to not allow
Nonevalues.
- interesting_line_regexes: list[tuple[str, Pattern[str]]]¶
Regular expressions for finding interesting lines.
- interesting_lines: tuple[dict[str, list[tuple[int, str]]], dict[str, list[tuple[int, str]]]]¶
Interesting lines in the file.
Changed in version 8.0: Changed from a 2-element list to a 2-tuple.
- add_interesting_line_regex(name: str, regex: Pattern[str]) None[source]¶
Register a regular expression used to look for interesting lines.
All interesting lines found that match the regular expression will be stored and tagged with the given name. Callers can use get_interesting_lines to get the results.
- Parameters:
name (
str) – The name of the regex to register.regex (
re.Pattern) – The compiled regular expression.
- add_interesting_lines_for_headers(filename: str) None[source]¶
Register patterns for interesting lines for headers.
This is a convenience over add_interesting_line_regex that will watch for headers (functions, classes, etc.) for the file type matching the given filename.
- Parameters:
filename (
str) – The filename of the file being diffed.
- get_interesting_lines(name: str, is_modified_file: bool) list[tuple[int, str]][source]¶
Return the interesting lines tagged with the given name.
- Parameters:
- Returns:
A list of interesting lines in the file. Each item is a 2-tuple of (line number, line).
- Return type:
- get_opcodes() Iterator[DiffOpcode][source]¶
Yield the opcodes for the diff.
- Yields:
DiffOpcode– The opcodes for the diff.
- get_differ(a: Sequence[str], b: Sequence[str], ignore_space: bool = False, compat_version: int = 2) Differ[source]¶
Return a differ for with the given settings.
By default, this will return the MyersDiffer. Older differs can be used by specifying a compat_version, but this is only for really ancient diffs, currently.
- Parameters:
- Returns:
The new differ instance.
- Return type:
- Raises:
reviewboard.diffviewer.errors.DiffCompatError – The compatibility version was not valid.