reviewboard.diffviewer.managers¶
Managers for reviewboard.diffviewer.models.
- class FileDiffManager(*args, **kwargs)[source]¶
Bases:
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:
- 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:
- 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.
- __slotnames__ = []¶
- class RawFileDiffDataManager(*args, **kwargs)[source]¶
Bases:
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]¶
Return or create a new stored entry for diff data.
- Parameters:
data (
bytes
) – The diff data to store or return an entry for.- Returns:
The entry for the diff data.
- Return type:
reviewboard.diffviewer.models.raw_file_diff_data.RawFileDiffData
- Raises:
TypeError – The data passed in was not a bytes string.
- __slotnames__ = []¶
- class BaseDiffManager(*args, **kwargs)[source]¶
Bases:
Manager
A base manager class for creating models out of uploaded diffs
- create_from_data(*args, **kwargs)[source]¶
Create a model instance from data.
Subclasses must implement this method.
See
create_from_upload()
for the fields that will be passed to this method.- Returns:
The model instance.
- Return type:
- create_from_upload(repository, diff_file, parent_diff_file=None, request=None, validate_only=False, **kwargs)[source]¶
Create a model instance from a form upload.
This parses a diff and optional parent diff covering one or more files, validates, and constructs either:
a
DiffSet
or
and the child
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.
This function also accepts a number of keyword arguments when creating a
DiffCommit
. In that case, the following fields are required (except for the committer fields when the underlying SCM does not distinguish between author and committer):- 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.request (
django.http.HttpRequest
, optional) – The current HTTP request, if any. This will result in better logging.validate_only (
bool
, optional) – Whether to just validate and not save. IfTrue
, then this won’t populate the database at all and will returnNone
upon success. This defaults toFalse
.**kwargs (
dict
) –Additional keyword arguments to pass to
create_from_data()
.See
create_from_data()
andDiffCommitManager.create_from_data()
for acceptable keyword arguments.
- 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.
- class DiffCommitManager(*args, **kwargs)[source]¶
Bases:
BaseDiffManager
A custom manager for DiffCommit objects.
This includes utilities for creating diffsets based on the data from form uploads, webapi requests, and upstream repositories.
- by_diffset_ids(diffset_ids)[source]¶
Return the commits grouped by DiffSet IDs.
- Parameters:
diffset_ids (
list
ofint
) – The primary keys of the DiffSets to retrieve commits for.- Returns:
A mapping of
DiffSet
primary keys to lists ofDiffCommits
.- Return type:
- create_from_data(repository, diff_file_name, diff_file_contents, parent_diff_file_name, parent_diff_file_contents, diffset, commit_id, parent_id, commit_message, author_name, author_email, author_date, validation_info=None, request=None, committer_name=None, committer_email=None, committer_date=None, base_commit_id=None, check_existence=True, validate_only=False)[source]¶
Create a DiffCommit from raw diff data.
- Parameters:
repository (
reviewboard.scmtools.models.Repository
) – The repository the diff was posted against.diff_file_name (
unicode
) – The name of the diff file.diff_file_contents (
bytes
) – The contents of the diff file.parent_diff_file_name (
unicode
) – The name of the parent diff file.parent_diff_file_contents (
bytes
) – The contents of the parent diff file.diffset (
reviewboard.diffviewer.models.diffset.DiffSet
) – The DiffSet to attach the created DiffCommit to.commit_id (
unicode
) – The unique identifier of the commit.parent_id (
unicode
) – The unique identifier of the parent commit.commit_message (
unicode
) – The commit message.author_name (
unicode
) – The author’s name.author_email (
unicode
) – The author’s e-mail address.author_date (
datetime.datetime
) – The date and time that the commit was authored.request (
django.http.HttpRequest
, optional) – The HTTP request from the client.validation_info (
dict
, optional) – A dictionary of parsed validation information from theValidateDiffCommitResource
.committer_name (
unicode
, optional) – The committer’s name.committer_email (
unicode
, optional) – The committer’s e-mail address.committer_date (
datetime.datetime
, optional) – The date and time that the commit was committed.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 or not existence checks should be performed against the upstream repository.validate_only (
bool
, optional) – Whether to just validate and not save. IfTrue
, then this won’t populate the database at all and will returnNone
upon success. This defaults toFalse
.
- Returns:
The created model instance.
- Return type:
- __slotnames__ = []¶
- class DiffSetManager(*args, **kwargs)[source]¶
Bases:
BaseDiffManager
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_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.diffset_history.DiffSetHistory
, optional) – The history object to associate the DiffSet with. This is not required if usingvalidate_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 toTrue
.validate_only (
bool
, optional) – Whether to just validate and not save. IfTrue
, then this won’t populate the database at all and will returnNone
upon success. This defaults toFalse
.**kwargs (
dict
) – Additional keyword arguments.
- 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.
- create_empty(repository, diffset_history=None, **kwargs)[source]¶
Create a DiffSet with no attached FileDiffs.
An empty DiffSet must be created before
DiffCommits
can be added to it. When the DiffCommits are created, theFileDiffs
will be attached to the DiffSet.- Parameters:
repository (
reviewboard.scmtools.models.Repository
) – The repository to create the DiffSet in.diffset_history (
reviewboard.diffviewer.models.diffset_history.DiffSetHistory
, optional) – An optional DiffSetHistory instance to attach the DiffSet to.**kwargs (
dict
) – Additional keyword arguments to pass tocreate()
.
- Returns:
The created DiffSet.
- Return type:
- __slotnames__ = []¶