Interface ScmCommandFactory
commands
which provide basic SCM functionality such as creating repositories, retrieving
commits and viewing diffs. Each method accepts a set of CommandParameters
which are used to control the
command's behaviour and output.
In general, commands fall into two categories:
- Paged: Accept a
PageRequest
describing the page of output that should be returned and return an object graph when the command is executed - Streamed: Accept a callback to receive output and return
Void
(usuallynull
) when the command is executed
Note: The repository
against which created commands will operate was specified when the factory
was retrieved from the ScmService
, and cannot be changed.
Plugin developers: This is probably not the interface you want to use. The API provides services whose functionality is backed by the SCM. Using those services automatically chooses the correct SCM based on the repository, and provides a more stable, compatible API. In general, the functionality of this command factory is exposed by:
The documentation for each method on this interface includes a link to the API service method or methods which expose it.-
Method Summary
Modifier and TypeMethodDescriptionblame
(BlameCommandParameters parameters, PageRequest pageRequest) Retrieves blame (also sometimes referred to as annotations) for a file at a given revision.branches
(BranchesCommandParameters parameters, BranchCallback callback) branches
(BranchesCommandParameters parameters, PageRequest pageRequest) changes
(ChangesCommandParameters parameters, ChangeCallback callback) changes
(ChangesCommandParameters parameters, PageRequest pageRequest) changesets
(ChangesetsCommandParameters parameters, PageRequest pageRequest) Retrieves a page ofchangesets
given a set ofcommit IDs
, where each changeset includes the first page ofchanges
between a requested commit and its first parent.commit
(CommitCommandParameters parameters) Retrievesdetails
for the specified commit.commits
(CommitsCommandParameters parameters, CommitCallback callback) Streams commits which match the providedparameters
to the provided callback.commits
(CommitsCommandParameters parameters, PageRequest pageRequest) Retrieves apage
of commits matching the specifiedparameters
.commonAncestor
(CommonAncestorCommandParameters parameters) Retrieves the common ancestor for the provided commitsResolves the default branch for the specified repository.diff
(DiffCommandParameters parameters, DiffContentCallback callback) Streams a diff between twocommits
.diff
(DiffCommandParameters parameters, TypeAwareOutputSupplier outputSupplier) Streams a diff between twocommits
.diffStatsSummary
(DiffStatsSummaryCommandParameters parameters) Retrieves the diff stats summary between twocommits
.directory
(DirectoryCommandParameters parameters, ContentTreeCallback callback, PageRequest pageRequest) Streams thetree nodes
(files, subdirectories and submodules) in the specifieddirectory
.file
(FileCommandParameters parameters, FileContentCallback callback, PageRequest pageRequest) Streams the contents of thespecified file
.rawFile
(RawFileCommandParameters parameters, TypeAwareOutputSupplier outputSupplier) Streams the raw content of the given file after performing a best effort detection of its MIME type.refs
(RefsCommandParameters parameters, RefCallback callback) Streams all of therefs
in the repository.repositorySize
(Repository repository, RepositorySizeCommandParameters parameters) Calculates thesize
for the specified repository.resolveCommits
(ResolveCommitsCommandParameters parameters) Resolves revisions provided onparameters
to the referenced commit ID.resolveRef
(ResolveRefCommandParameters parameters) Resolves the specifiedrefId
, which may be a:branch name
tag name
commit hash
If therefId
should be resolved to a specific type, thattype
should be set to allow the SCM to restrict its search.resolveRefs
(ResolveRefsCommandParameters parameters) Resolves refs from the ref IDs provided onparameters
, which may be one ofbranch name
tag name
commit hash
Callers can specify on theparameters
whether a provided ID is expected to resolve to abranch
,tag
, or aref of unknown type
.size
(SizeCommandParameters parameters) Retrieves the size of the file at the requested path at the specified commit.tags
(TagsCommandParameters parameters, TagCallback callback) Streamstags
ordered either alphabetically or by modification and optionally filtered.tags
(TagsCommandParameters parameters, PageRequest pageRequest) traverseCommits
(TraversalCallback callback) Streams all of the commits in the repository reachable from any branch or tag, traversed in topological order.type
(TypeCommandParameters parameters)
-
Method Details
-
blame
@Nonnull Command<Page<Blame>> blame(@Nonnull BlameCommandParameters parameters, @Nonnull PageRequest pageRequest) Retrieves blame (also sometimes referred to as annotations) for a file at a given revision.The
PageRequest
provided determines the lines in the file for which blame is calculated, and only lines within the scope of the page request will be returned. However, because adjacent lines may bespanned
by a singleauthor
, the number of distinctBlame
objects returned will frequently be less than thelimit
.- Parameters:
parameters
- parameters describing the file and revision used to calculate blamepageRequest
- describes the set of lines in the file to calculate blame for- Returns:
- a command which, when executed, will return the calculated
Blame
for the specified file and revision for the requested set of lines - Since:
- 5.0
- See Also:
-
branches
@Nonnull Command<Void> branches(@Nonnull BranchesCommandParameters parameters, @Nonnull BranchCallback callback) Retrieves aCommand
which, when executed, will streambranches
ordered either alphabetically or by modification and optionally filtered.When no explicit order is requested, the default ordering depends on whether a filter was provided:
- If filtering, branches default to
alphabetical
order - Otherwise, branches default to
modification
order
- Parameters:
parameters
- parameters describing desired order and filter textcallback
- the callback to receive streamed branches- Returns:
- a command which, when executed, will stream branches
- Since:
- 4.6
- See Also:
- If filtering, branches default to
-
branches
@Nonnull Command<Page<Branch>> branches(@Nonnull BranchesCommandParameters parameters, @Nonnull PageRequest pageRequest) Retrieves apage
ofbranches
ordered either alphabetically or by modification and optionally filtered.When no explicit order is requested, the default ordering depends on whether a filter was provided:
- If filtering, branches default to
alphabetical
order - Otherwise, branches default to
modification
order
- Parameters:
parameters
- parameters describing desired order and filter textpageRequest
- describes the set of branches to return- Returns:
- a command which, when executed, will return the requested page of branches
- See Also:
- If filtering, branches default to
-
changes
@Nonnull Command<Void> changes(@Nonnull ChangesCommandParameters parameters, @Nonnull ChangeCallback callback) Retrieves aCommand
which, when executed, will streamchanges
describing modifications made between two revisions, optionally filtered by path.If no explicit
"since"
revision is specified, it defaults to the parent of the"until"
revision. If the "until" revision specifies a merge commit (a commit with multiple parents), no changes will be returned.Note: Some
changes
, such ascopies
andmoves
, affect more than one path. When filtering by path, if both paths are not available the change's type may not be correctly detected by some SCMs.- Parameters:
parameters
- parameters describing the revisions to compare and paths to filter bycallback
- the callback to receive streamed commits- Returns:
- a command which, when executed, will stream changes
- See Also:
-
changes
@Nonnull Command<Page<Change>> changes(@Nonnull ChangesCommandParameters parameters, @Nonnull PageRequest pageRequest) Retrieves apage
ofchanges
describing the modifications made between two revisions, optionally filtered by path.If no explicit
"since"
revision is specified, it defaults to the parent of the"until"
revision. If the "until" revision specifies a merge commit (a commit with multiple parents), no changes will be returned.Note: Some
changes
, such ascopies
andmoves
, affect more than one path. When filtering by path, if both paths are not available the change's type may not be correctly detected by some SCMs.- Parameters:
parameters
- parameters describing the revisions to compare and paths to filter bypageRequest
- describes the set of changes to return- Returns:
- a command which, when executed, will return the requested page of changes
- See Also:
-
changesets
@Nonnull Command<Page<Changeset>> changesets(@Nonnull ChangesetsCommandParameters parameters, @Nonnull PageRequest pageRequest) Retrieves a page ofchangesets
given a set ofcommit IDs
, where each changeset includes the first page ofchanges
between a requested commit and its first parent.- Parameters:
parameters
- parameters describing the changesets to retrievepageRequest
- describes the page of changesets to retrieve- Returns:
- a command which, when executed, will retrieve a page of changesets
- See Also:
-
commonAncestor
Retrieves the common ancestor for the provided commits- Parameters:
parameters
- parameters describing which common ancestor to retrieve- Returns:
- a command which, when executed, returns the common ancestor of the provided commits. If the provided
commits do not have a common ancestor, the command returns
null
. - Since:
- 5.0
-
commit
Retrievesdetails
for the specified commit.If a
path
is provided, theCommit
returned may not be for the specifiedcommit
. Instead, that commit is used as a starting point and details for the first commit in its ancestry which affects that path are returned.- Parameters:
parameters
- parameters describing the commit to retrieve details for- Returns:
- a command which, when executed, will return details for the specified commit
- See Also:
-
commits
@Nonnull Command<Void> commits(@Nonnull CommitsCommandParameters parameters, @Nonnull CommitCallback callback) Streams commits which match the providedparameters
to the provided callback.- Parameters:
parameters
- parameters describing the commits to retrievecallback
- a callback to receive the streamed commits- Returns:
- a command which, when executed, will stream commits to the provided callback
- Throws:
UnsupportedOperationException
- if asecondary repository
is provided ancross- repository
operations are not supported- See Also:
-
commits
@Nonnull Command<Page<Commit>> commits(@Nonnull CommitsCommandParameters parameters, @Nonnull PageRequest pageRequest) Retrieves apage
of commits matching the specifiedparameters
.If the
SCM supports
cross-repository
operations, asecondary repository
may be provided. Otherwise, it must be omitted or match the target repository.- Parameters:
parameters
- parameters describing which commits to retrievepageRequest
- describes the set of commits to return- Returns:
- a command which, when executed, will retrieve a page of commits
- Throws:
UnsupportedOperationException
- if asecondary repository
was provided and the underlying SCM does not supportcross-repository
operations- See Also:
-
defaultBranch
Resolves the default branch for the specified repository.The returned command may throw
NoDefaultBranchException
, when executed, if the specified repository does not have a resolvable default branch. This might happen, for example, on a new repository with no commits, or if the only commits to a repository have been to a branch other than the default branch.- Returns:
- a command which, when executed, will retrieve the repository's default branch
- Throws:
NoDefaultBranchException
- if the repository does not have a resolvable default branch- See Also:
-
diff
@Nonnull Command<Void> diff(@Nonnull DiffCommandParameters parameters, @Nonnull DiffContentCallback callback) Streams a diff between twocommits
.- Parameters:
parameters
- parameters describing the diff to streamcallback
- the callback to receive the streamed diff- Returns:
- a command which, when executed, will stream the requested diff
- See Also:
-
diff
@Nonnull Command<Void> diff(@Nonnull DiffCommandParameters parameters, @Nonnull TypeAwareOutputSupplier outputSupplier) Streams a diff between twocommits
.- Parameters:
parameters
- parameters describing the diff to streamoutputSupplier
- a supplier which will provide an output stream- Returns:
- a command which, when executed, will stream the requested diff
- Since:
- 6.7
- See Also:
-
diffStatsSummary
@Nonnull Command<DiffStatsSummary> diffStatsSummary(@Nonnull DiffStatsSummaryCommandParameters parameters) Retrieves the diff stats summary between twocommits
.The stats summary include the total number of modified files, added lines, and deleted lines.
- Parameters:
parameters
- parameters describing the diff- Returns:
- a command which, when executed, will return the
diff stats summary
for the commits. - Since:
- 9.1
-
directory
@Nonnull Command<Void> directory(@Nonnull DirectoryCommandParameters parameters, @Nonnull ContentTreeCallback callback, @Nonnull PageRequest pageRequest) Streams thetree nodes
(files, subdirectories and submodules) in the specifieddirectory
.- Parameters:
parameters
- parameters providing the directory to stream and the revision to stream it forcallback
- the callback to receive the streamed nodespageRequest
- describes the set of nodes to stream- Returns:
- a command which, when executed, will stream the requested directory's contents
- See Also:
-
file
@Nonnull Command<Void> file(@Nonnull FileCommandParameters parameters, @Nonnull FileContentCallback callback, @Nonnull PageRequest pageRequest) Streams the contents of thespecified file
.- Parameters:
parameters
- parameters describing the file to stream and the revision to stream it forcallback
- the callback to receive the streamed contentpageRequest
- describes the set of lines in the file to stream- Returns:
- a command which, when executed, will stream the requested file's content
- See Also:
-
rawFile
@Nonnull Command<Void> rawFile(@Nonnull RawFileCommandParameters parameters, @Nonnull TypeAwareOutputSupplier outputSupplier) Streams the raw content of the given file after performing a best effort detection of its MIME type. That MIME type will be used to retrieve anOutputStream
from the provided supplier, and the file's raw content will then be written to the returned stream.- Parameters:
parameters
- parameters used to specify the path and version of the file to streamoutputSupplier
- the supplier which, when given a content type, will provide an output stream- Returns:
- a command which, when executed, will determine the file's type and then stream its data
- See Also:
-
refs
@Nonnull Command<Void> refs(@Nonnull RefsCommandParameters parameters, @Nonnull RefCallback callback) Streams all of therefs
in the repository. The exact specification for what "refs" includes is an SCM-specific detail, but it will generally include all branches and tags in the repository.Note: This method is not exposed via the service API. It is only available directly on the SCM API.
- Parameters:
parameters
- parameters to allow evolving the SPI over timecallback
- the ref callback that will be called for each ref- Returns:
- a command which, when executed, will stream repository refs
- Since:
- 6.4
-
repositorySize
@Nonnull Command<RepositorySize> repositorySize(@Nonnull Repository repository, @Nonnull RepositorySizeCommandParameters parameters) Calculates thesize
for the specified repository.Note: Calculating the size can be an expensive operation. The returned value may be a best effort estimation of the repository size.
- Parameters:
repository
- the repository for which size needs to be calculated.parameters
- the additional parameters (if any) for the size calculation.- Returns:
- a command which, when executed, will return the
size
of the given repository. - Since:
- 7.14
- See Also:
-
resolveCommits
@Nonnull Command<Map<String,String>> resolveCommits(@Nonnull ResolveCommitsCommandParameters parameters) Resolves revisions provided onparameters
to the referenced commit ID. Revisions specified onparameters
can be anything that the SCM can resolve to commit IDs, including branch and tag names.The command returns a
map
from the provided revision to the resolved commit ID. If a revision could not be resolved, no value is returned in the map.- Parameters:
parameters
- parameters describing the revisions to resolve- Returns:
- a command which, when executed, will resolve the requested revisions to a commit ID.
- Since:
- 7.14
-
resolveRef
Resolves the specifiedrefId
, which may be a: If therefId
should be resolved to a specific type, thattype
should be set to allow the SCM to restrict its search.If a hash is provided, it will be resolved to the branch or tag it is the tip of. If it is not the tip of any branch or tag, it will resolve to
null
. If atype
was specified, the hash will only be resolved against that type.When a hash is provided and resolves to multiple branches, tags or a combination of both, it is left to the SCM implementation to determine the result. SCM implementors are encouraged to choose a tag over a branch, and to return the "first" branch or tag, ordered alphabetically, but this is not enforced.
- Parameters:
parameters
- parameters describing the ref to resolve- Returns:
- a command which, when executed, will resolve the specified ref
- Since:
- 4.6
- See Also:
-
resolveRefs
Resolves refs from the ref IDs provided onparameters
, which may be one of Callers can specify on theparameters
whether a provided ID is expected to resolve to abranch
,tag
, or aref of unknown type
.If hashes are provided, they will be resolved to branches or tags they are the tip of. If they are not the tip of any branch or tag, they will resolve to
null
and will not be included in the returned map.When a hash is provided and resolves to multiple branches, tags or a combination of both, it is left to the SCM implementation to determine the result. SCM implementors are encouraged to choose a tag over a branch, and to return the "first" branch or tag, ordered alphabetically, but this is not enforced.
- Parameters:
parameters
- describes the ref IDs to resolve- Returns:
- a command which, when executed, will resolve the specified refs
- Since:
- 4.4
- See Also:
-
size
Retrieves the size of the file at the requested path at the specified commit. If the path identifies a directory, submodule or other non-file type, the command will returnnull
.- Parameters:
parameters
- parameters describing the commit and path to retrieve the size for- Returns:
- a command which, when executed, will return the size of the requested path at the specified commit
- Since:
- 7.7
- See Also:
-
tags
@Nonnull Command<Void> tags(@Nonnull TagsCommandParameters parameters, @Nonnull TagCallback callback) Streamstags
ordered either alphabetically or by modification and optionally filtered.When no explicit order is requested, the default ordering depends on whether a filter was provided:
- If filtering, tags default to
alphabetical
order - Otherwise, tags default to
modification
order
- Parameters:
parameters
- parameters describing desired order and filter textcallback
- a callback to receive the streamed commits- Returns:
- a command which, when executed, will stream tags to the provided callback
- See Also:
- If filtering, tags default to
-
tags
@Nonnull Command<Page<Tag>> tags(@Nonnull TagsCommandParameters parameters, @Nonnull PageRequest pageRequest) Retrieves apage
oftags
ordered either alphabetically or by modification and optionally filtered.When no explicit order is requested, the default ordering depends on whether a filter was provided:
- If filtering, tags default to
alphabetical
order - Otherwise, tags default to
modification
order
- Parameters:
parameters
- parameters describing desired order and filter textpageRequest
- describes the set of tags to return- Returns:
- a command which, when executed, will return the requested page of tags
- See Also:
- If filtering, tags default to
-
traverseCommits
Streams all of the commits in the repository reachable from any branch or tag, traversed in topological order.- Parameters:
callback
- the callback to receive the streamed commits- Returns:
- a command which, when executed, will stream a topological traversal of all of the commits in the repository
- See Also:
-
type
Retrieves thetype
for the specifiedpath
at the requested revision, if the path is present. Note that the same path might have different types between revisions but the root entry ("", "\" or "/") will always be adirectory
.- Parameters:
parameters
- parameters describing the path to check, and the revision to check it for- Returns:
- a command which, when executed, will return the requested path's type
- See Also:
-