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.
-
unmigrated
()[source]¶ Query FileDiffs that store their own diff content.
This will return FileDiffs that were created prior to Review Board 1.7.
Returns: A queryset for filtering FileDiffs that have not been migrated to use some form of deduplicated diff storage mechanism. Return type: django.db.models.query.QuerySet
-
get_migration_counts
()[source]¶ Return 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.
Returns: A dictionary of counts. This will contain the following keys: filediffs
:- The number of unmigrated FileDiff objects.
legacy_file_diff_data
:- The number of unmigrated LegacyFileDiffData objects.
total_count
:- The total count of objects to migrate.
Return type: dict
-
migrate_all
(batch_done_cb=None, counts=None, batch_size=40, max_diffs=None)[source]¶ Migrate 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.
Parameters: - batch_done_cb (callable, optional) –
A function to call after each batch of objects has been processed. This can be used for progress notification.
This should be in the form of:
def on_batch_done(total_diffs_migrated=None, total_count=None, **kwargs): ...
Note that
total_count
may beNone
. - counts (dict, optional) –
A dictionary of counts for calculations.
The only value used is
total_count
, which would be a total number of objects being processed.This is only used for reporting to
batch_done_cb
. If not provided, andbatch_done_cb
is provided, then this method will query the counts itself. - batch_size (int, optional) – The number of objects to process in each batch.
- max_diffs (int, optional) – The maximum number of diffs to migrate.
- batch_done_cb (callable, optional) –
-
-
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.
-