Jump to >

This documentation covers Review Board 2.5. You can see the latest Review Board documentation or all other versions.

reviewboard.diffviewer.managers

class FileDiffManager[source]

Bases: django.db.models.manager.Manager

A manager for FileDiff objects.

This contains utility methods for locating FileDiffs that haven’t been migrated to use RawFileDiffData.

MIGRATE_OBJECT_LIMIT = 200[source]
unmigrated()[source]

Queries FileDiffs that store their own diff content.

get_migration_counts()[source]

Returns the number of items that need to be migrated.

The result is a dictionary containing a breakdown of the various counts, and the total count of all items for display.

migrate_all(batch_done_cb=None, counts=None, batch_size=40)[source]

Migrates diff content in FileDiffs to use RawFileDiffData.

This will run through all unmigrated FileDiffs and migrate them, condensing their storage needs and removing the content from FileDiffs.

This will return a dictionary with the result of the process.

class RawFileDiffDataManager[source]

Bases: django.db.models.manager.Manager

A custom manager for RawFileDiffData.

This provides conveniences for creating an entry based on a LegacyFileDiffData object.

process_diff_data(data)[source]

Processes a diff, returning the resulting content and compression.

If the content would benefit from being compressed, this will return the compressed content and the value for the compression flag. Otherwise, it will return the raw content.

get_or_create_from_data(data)[source]
create_from_legacy(legacy, save=True)[source]
class DiffSetManager[source]

Bases: django.db.models.manager.Manager

A custom manager for DiffSet objects.

This includes utilities for creating diffsets based on the data from form uploads, webapi requests, and upstream repositories.

HEADER_EXTENSIONS = [u’h’, u’H’, u’hh’, u’hpp’, u’hxx’, u’h++’][source]
IMPL_EXTENSIONS = [u’c’, u’C’, u’cc’, u’cpp’, u’cxx’, u’c++’, u’m’, u’mm’, u’M’][source]
create_from_upload(repository, diff_file, parent_diff_file=None, diffset_history=None, basedir=None, request=None, base_commit_id=None, validate_only=False, **kwargs)[source]

Create a DiffSet from a form upload.

This parses a diff and optional parent diff covering one or more files, validates, and constructs DiffSets and FileDiffs representing the diff.

This can optionally validate the diff without saving anything to the database. In this case, no value will be returned. Instead, callers should take any result as success.

Parameters:
  • repository (reviewboard.scmtools.models.Repository) – The repository the diff applies to.
  • diff_file (django.core.files.uploadedfile.UploadedFile) – The diff file uploaded in the form.
  • parent_diff_file (django.core.files.uploadedfile.UploadedFile, optional) – The parent diff file uploaded in the form.
  • diffset_history (reviewboard.diffviewer.models.DiffSetHistory, optional) – The history object to associate the DiffSet with. This is not required if using validate_only=True.
  • basedir (unicode, optional) – The base directory to prepend to all file paths in the diff.
  • request (django.http.HttpRequest, optional) – The current HTTP request, if any. This will result in better logging.
  • base_commit_id (unicode, optional) – The ID of the commit that the diff is based upon. This is needed by some SCMs or hosting services to properly look up files, if the diffs represent blob IDs instead of commit IDs and the service doesn’t support those lookups.
  • validate_only (bool, optional) – Whether to just validate and not save. If True, then this won’t populate the database at all and will return None upon success. This defaults to False.
Returns:

The resulting DiffSet stored in the database, if processing succeeded and validate_only=False.

Return type:

reviewboard.diffviewer.models.DiffSet

Raises:
  • reviewboard.diffviewer.errors.DiffParserError – There was an error parsing the main diff or parent diff.
  • reviewboard.diffviewer.errors.DiffTooBigError – The diff file was too big to be uploaded, based on the configured maximum diff size in settings.
  • reviewboard.diffviewer.errors.EmptyDiffError – The provided diff file did not contain any file changes.
  • reviewboard.scmtools.core.FileNotFoundError – A file specified in the diff could not be found in the repository.
  • reviewboard.scmtools.core.SCMError – There was an error talking to the repository when validating the existence of a file.
  • reviewboard.scmtools.git.ShortSHA1Error – A SHA1 specified in the diff was in the short form, which could not be used to look up the file. This is applicable only to Git.
create_from_data(repository, diff_file_name, diff_file_contents, parent_diff_file_name=None, parent_diff_file_contents=None, diffset_history=None, basedir=None, request=None, base_commit_id=None, check_existence=True, validate_only=False, **kwargs)[source]

Create a DiffSet from raw diff data.

This parses a diff and optional parent diff covering one or more files, validates, and constructs DiffSets and FileDiffs representing the diff.

This can optionally validate the diff without saving anything to the database. In this case, no value will be returned. Instead, callers should take any result as success.

Parameters:
  • repository (reviewboard.scmtools.models.Repository) – The repository the diff applies to.
  • diff_file_name (unicode) – The filename of the main diff file.
  • diff_file_contents (bytes) – The contents of the main diff file.
  • parent_diff_file_name (unicode, optional) – The filename of the parent diff, if one is provided.
  • parent_diff_file_contents (bytes, optional) – The contents of the parent diff, if one is provided.
  • diffset_history (reviewboard.diffviewer.models.DiffSetHistory, optional) – The history object to associate the DiffSet with. This is not required if using validate_only=True.
  • basedir (unicode, optional) – The base directory to prepend to all file paths in the diff.
  • request (django.http.HttpRequest, optional) – The current HTTP request, if any. This will result in better logging.
  • base_commit_id (unicode, optional) – The ID of the commit that the diff is based upon. This is needed by some SCMs or hosting services to properly look up files, if the diffs represent blob IDs instead of commit IDs and the service doesn’t support those lookups.
  • check_existence (bool, optional) – Whether to check for file existence as part of the validation process. This defaults to True.
  • validate_only (bool, optional) – Whether to just validate and not save. If True, then this won’t populate the database at all and will return None upon success. This defaults to False.
Returns:

The resulting DiffSet stored in the database, if processing succeeded and validate_only=False.

Return type:

reviewboard.diffviewer.models.DiffSet

Raises:
  • reviewboard.diffviewer.errors.DiffParserError – There was an error parsing the main diff or parent diff.
  • reviewboard.diffviewer.errors.EmptyDiffError – The provided diff file did not contain any file changes.
  • reviewboard.scmtools.core.FileNotFoundError – A file specified in the diff could not be found in the repository.
  • reviewboard.scmtools.core.SCMError – There was an error talking to the repository when validating the existence of a file.
  • reviewboard.scmtools.git.ShortSHA1Error – A SHA1 specified in the diff was in the short form, which could not be used to look up the file. This is applicable only to Git.