Jump to >

reviewboard.diffviewer.parser

class ParsedDiffFile[source]

Bases: object

A parsed file from a diff.

This stores information on a single file represented in a diff, including the contents of that file’s diff, as parsed by DiffParser or one of its subclasses.

Parsers should set the attributes on this based on the contents of the diff, and should add any data found in the diff.

This class is meant to be used internally and by subclasses of DiffParser.

__init__()[source]

Initialize the parsed file information.

data[source]

The data for this diff.

This must be accessed after finalize() has been called.

finalize()[source]

Finalize the parsed diff.

This makes the diff data available to consumers and closes the buffer for writing.

prepend_data(data)[source]

Prepend data to the buffer.

Parameters:data (bytes) – The data to prepend.
append_data(data)[source]

Append data to the buffer.

Parameters:data (bytes) – The data to append.
class DiffParser(data)[source]

Bases: object

Parses diff files into fragments, taking into account special fields present in certain types of diffs.

INDEX_SEP = '==================================================================='[source]
__init__(data)[source]

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

parse()[source]

Parses the diff, returning a list of File objects representing each file in the diff.

parse_diff_line(linenum, info)[source]
parse_change_header(linenum)[source]

Parses part of the diff beginning at the specified line number, trying to find a diff header.

parse_special_header(linenum, info)[source]

Parses part of a diff beginning at the specified line number, trying to find a special diff header. This usually occurs before the standard diff header.

The line number returned is the line after the special header, which can be multiple lines long.

parse_diff_header(linenum, info)[source]

Parses part of a diff beginning at the specified line number, trying to find a standard diff header.

The line number returned is the line after the special header, which can be multiple lines long.

parse_after_headers(linenum, info)[source]

Parses data after the diff headers but before the data.

By default, this does nothing, but a DiffParser subclass can override to look for special headers before the content.

parse_filename_header(s, linenum)[source]
raw_diff(diffset)[source]

Returns a raw diff as a string.

The returned diff as composed of all FileDiffs in the provided diffset.

get_orig_commit_id()[source]

Returns the commit ID of the original revision for the diff.

This is overridden by tools that only use commit IDs, not file revision IDs.

normalize_diff_filename(filename)[source]

Normalize filenames in diffs.

This strips off any leading slashes, which might occur due to differences in various diffing methods or APIs.