reviewboard.diffviewer.opcode_generator¶
The diff opcode generator.
- class MoveRange(start: int, end: int, groups: list[tuple[DiffOpcodeWithMetadata, int]] | None = None)[source]¶
Bases:
objectStores information on a move range.
This will store the start and end of the range, and all groups that are a part of it.
- __init__(start: int, end: int, groups: list[tuple[DiffOpcodeWithMetadata, int]] | None = None) None[source]¶
Initialize the object.
- groups: list[tuple[DiffOpcodeWithMetadata, int]]¶
The opcodes in the range.
This is a list of tuples where the first element is the opcode, and the second is the index into the opcode generator’s groups list.
- property last_group: tuple[DiffOpcodeWithMetadata, int][source]¶
The last group in the move range.
- Raises:
IndexError – The move range was empty.
- class DiffOpcodeGenerator(differ: Differ, diff: bytes | None = None, interdiff: bytes | None = None, request: HttpRequest | None = None, *, diff_settings: DiffSettings | None = None, **kwargs)[source]¶
Bases:
objectThe diff opcode generator.
- inserts: list[DiffOpcodeWithMetadata]¶
A list of all opcodes involving inserted lines.
This will contain both pure inserts as well as replaces.
- removes: dict[str, list[tuple[int, DiffOpcodeWithMetadata, int]]]¶
A mapping for working with removed lines.
This is a mapping from the line content of a removed line to a list of potential opcodes relating to that removal. The values in that list are tuples of the original line number, the opcode, and the index of that opcode in the
groupslist.
- __init__(differ: Differ, diff: bytes | None = None, interdiff: bytes | None = None, request: HttpRequest | None = None, *, diff_settings: DiffSettings | None = None, **kwargs) None[source]¶
Initialize the opcode generator.
Changed in version 7.0.4: Added the
diff_settingsparameter.Changed in version 3.0.18: Added the
requestand**kwargsparameters.- Parameters:
differ (
reviewboard.diffviewer.differ.Differ) – The differ being used to generate the diff.diff (
bytes, optional) – The raw contents for the diff.interdiff (
bytes, optional) – The raw contents for the diff on the other end of an interdiff range, if generating an interdiff.request (
django.http.HttpRequest) – The HTTP request from the client.diff_settings (
reviewboard.diffviewer.settings.DiffSettings, optional) –The diff settings object.
New in version 7.0.4.
**kwargs (
dict) – Additional keyword arguments, for future expansion.
- diff_settings: DiffSettings¶
The diff settings object.
New in version 7.0.4.
- __iter__() Iterator[DiffOpcodeWithMetadata][source]¶
Yield opcodes from the differ with extra metadata.
This is a wrapper around a differ’s get_opcodes function, which returns extra metadata along with each range. That metadata includes information on moved blocks of code and whitespace-only lines.
- Yields:
reviewboard.diffviewer.differ.DiffOpcode– The opcodes in the diff.
- get_diff_opcode_generator_class() type[reviewboard.diffviewer.opcode_generator.DiffOpcodeGenerator][source]¶
Return the DiffOpcodeGenerator class used for generating opcodes.
- Returns:
The opcode generator class.
- Return type:
- set_diff_opcode_generator_class(renderer: type[reviewboard.diffviewer.opcode_generator.DiffOpcodeGenerator]) None[source]¶
Set the DiffOpcodeGenerator class used for generating opcodes.
- Parameters:
renderer (
type) – The opcode generator class.
- get_diff_opcode_generator(*args, **kwargs) DiffOpcodeGenerator[source]¶
Return a DiffOpcodeGenerator instance used for generating opcodes.
- Parameters:
- Returns:
The new opcode generator.
- Return type: