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.
-
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.
-
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.
-
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
andFileDiffs
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 returnNone
upon success. This defaults toFalse
.
Returns: The resulting DiffSet stored in the database, if processing succeeded and
validate_only=False
.Return type: 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
andFileDiffs
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 returnNone
upon success. This defaults toFalse
.
Returns: The resulting DiffSet stored in the database, if processing succeeded and
validate_only=False
.Return type: 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.
-