Class ReceiveCommand
- Direct Known Subclasses:
TrackingRefUpdate.Command
ReceivePack
.
This command instance roughly translates to the server side representation of
the RemoteRefUpdate
created by the client.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Result of the update command.static enum
Type of operation requested. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private Boolean
private String
private final String
private final ObjectId
private final String
private final ObjectId
private final String
private Ref
private boolean
private String
private ReceiveCommand.Result
private ReceiveCommand.Type
private boolean
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ReceiveCommand
(String oldTarget, String newTarget, String name) Create a command to switch a symbolic reference's target.private
ReceiveCommand
(String oldSymref, ObjectId newId, String name) Create a command to switch a reference from symbolic to object.private
ReceiveCommand
(ObjectId oldId, String newSymref, String name) Create a command to switch a reference from object to symbolic.ReceiveCommand
(ObjectId oldId, ObjectId newId, String name) Create a new command forReceivePack
.ReceiveCommand
(ObjectId oldId, ObjectId newId, String name, ReceiveCommand.Type type) Create a new command forReceivePack
. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
abort
(Iterable<ReceiveCommand> commands) Set unprocessed commands as failed due to transaction aborted.void
Don't record this update in the ref's associated reflog.void
execute
(ReceivePack rp) Execute this command during a receive-pack session.static List
<ReceiveCommand> filter
(Iterable<ReceiveCommand> in, ReceiveCommand.Result want) Filter a collection of commands according to result.static List
<ReceiveCommand> filter
(List<ReceiveCommand> commands, ReceiveCommand.Result want) Filter a list of commands according to result.Get the message associated with a failure status.getNewId()
Get the requested new value for this ref.Get requested new target for a symbolic reference.getOldId()
Get the old value the client thinks the ref has.Get expected old target for a symbolic reference.getRef()
Get the ref, if this was advertised by the connection.Get the message to include in the reflog.Get the name of the ref being updated.Get the current status code of this command.getType()
Get the type of this command; seeReceiveCommand.Type
.boolean
Check whether this command has a custom reflog message setting that should override defaults in any containingBatchRefUpdate
.Check whether the reflog should be written regardless of repo defaults.boolean
Check whether log has been disabled bydisableRefLog()
.boolean
Check whether the reflog message should include the result of the update, such as fast-forward or force-update.static boolean
Check whether a command failed due to transaction aborted.static ReceiveCommand
Create a command to switch a symbolic reference's target.static ReceiveCommand
Create a command to switch a reference from object to symbolic.(package private) void
reject
(IOException err) void
setForceRefLog
(boolean force) Force writing a reflog for the updated ref.(package private) void
void
setRefLogMessage
(String msg, boolean appendStatus) Set the message to include in the reflog.void
Set the result of this command.void
Set the status of this command.void
Set the status of this command.(package private) void
(package private) void
toString()
static ReceiveCommand
Create a command to switch a reference from symbolic to object.void
updateType
(RevWalk walk) Update the type of this command by checking for fast-forward.
-
Field Details
-
oldId
-
oldSymref
-
newId
-
newSymref
-
name
-
type
-
typeIsCorrect
private boolean typeIsCorrect -
ref
-
status
-
message
-
customRefLog
private boolean customRefLog -
refLogMessage
-
refLogIncludeResult
private boolean refLogIncludeResult -
forceRefLog
-
-
Constructor Details
-
ReceiveCommand
Create a new command forReceivePack
.- Parameters:
oldId
- the expected old object id; must not be null. UseObjectId.zeroId()
to indicate a ref creation.newId
- the new object id; must not be null. UseObjectId.zeroId()
to indicate a ref deletion.name
- name of the ref being affected.
-
ReceiveCommand
Create a new command forReceivePack
.- Parameters:
oldId
- the old object id; must not be null. UseObjectId.zeroId()
to indicate a ref creation.newId
- the new object id; must not be null. UseObjectId.zeroId()
to indicate a ref deletion.name
- name of the ref being affected.type
- type of the command. Must beReceiveCommand.Type.CREATE
ifoldId
is zero, orReceiveCommand.Type.DELETE
ifnewId
is zero.- Since:
- 2.0
-
ReceiveCommand
Create a command to switch a reference from object to symbolic.- Parameters:
oldId
- the old object id; must not be null. UseObjectId.zeroId()
to indicate a ref creation.newSymref
- new target, must begin with"refs/"
. Usenull
to indicate a ref deletion.name
- name of the reference to make symbolic.- Since:
- 4.10
-
ReceiveCommand
Create a command to switch a reference from symbolic to object.- Parameters:
oldSymref
- expected old target. Usenull
to indicate a ref creation.newId
- the new object id; must not be null. UseObjectId.zeroId()
to indicate a ref deletion.name
- name of the reference to convert from symbolic.- Since:
- 4.10
-
ReceiveCommand
Create a command to switch a symbolic reference's target.- Parameters:
oldTarget
- expected old target. Usenull
to indicate a ref creation.newTarget
- new target. Usenull
to indicate a ref deletion.name
- name of the reference to make symbolic.- Since:
- 4.10
-
-
Method Details
-
filter
Filter a collection of commands according to result.- Parameters:
in
- commands to filter.want
- desired status to filter by.- Returns:
- a copy of the command list containing only those commands with the desired status.
- Since:
- 4.2
-
filter
public static List<ReceiveCommand> filter(List<ReceiveCommand> commands, ReceiveCommand.Result want) Filter a list of commands according to result.- Parameters:
commands
- commands to filter.want
- desired status to filter by.- Returns:
- a copy of the command list containing only those commands with the desired status.
- Since:
- 2.0
-
abort
Set unprocessed commands as failed due to transaction aborted.If a command is still
ReceiveCommand.Result.NOT_ATTEMPTED
it will be set toReceiveCommand.Result.REJECTED_OTHER_REASON
.- Parameters:
commands
- commands to mark as failed.- Since:
- 4.2
-
isTransactionAborted
Check whether a command failed due to transaction aborted.- Parameters:
cmd
- command.- Returns:
- whether the command failed due to transaction aborted, as in
abort(Iterable)
. - Since:
- 4.9
-
link
public static ReceiveCommand link(@NonNull ObjectId oldId, @NonNull String newTarget, @NonNull String name) Create a command to switch a reference from object to symbolic.- Parameters:
oldId
- expected oldId. May bezeroId
to create.newTarget
- new target; must begin with"refs/"
.name
- name of the reference to make symbolic.- Returns:
- command instance.
- Since:
- 4.10
-
link
public static ReceiveCommand link(@Nullable String oldTarget, @NonNull String newTarget, @NonNull String name) Create a command to switch a symbolic reference's target.- Parameters:
oldTarget
- expected old target. May be null to create.newTarget
- new target; must begin with"refs/"
.name
- name of the reference to make symbolic.- Returns:
- command instance.
- Since:
- 4.10
-
unlink
public static ReceiveCommand unlink(@NonNull String oldTarget, @NonNull ObjectId newId, @NonNull String name) Create a command to switch a reference from symbolic to object.- Parameters:
oldTarget
- expected old target.newId
- new object identifier. May bezeroId()
to delete.name
- name of the reference to convert from symbolic.- Returns:
- command instance.
- Since:
- 4.10
-
getOldId
Get the old value the client thinks the ref has.- Returns:
- the old value the client thinks the ref has.
-
getOldSymref
Get expected old target for a symbolic reference.- Returns:
- expected old target for a symbolic reference.
- Since:
- 4.10
-
getNewId
Get the requested new value for this ref.- Returns:
- the requested new value for this ref.
-
getNewSymref
Get requested new target for a symbolic reference.- Returns:
- requested new target for a symbolic reference.
- Since:
- 4.10
-
getRefName
Get the name of the ref being updated.- Returns:
- the name of the ref being updated.
-
getType
Get the type of this command; seeReceiveCommand.Type
.- Returns:
- the type of this command; see
ReceiveCommand.Type
.
-
getRef
Get the ref, if this was advertised by the connection.- Returns:
- the ref, if this was advertised by the connection.
-
getResult
Get the current status code of this command.- Returns:
- the current status code of this command.
-
getMessage
Get the message associated with a failure status.- Returns:
- the message associated with a failure status.
-
setRefLogMessage
Set the message to include in the reflog.Overrides the default set by
setRefLogMessage
on any containingBatchRefUpdate
.- Parameters:
msg
- the message to describe this change. If null and appendStatus is false, the reflog will not be updated.appendStatus
- true if the status of the ref change (fast-forward or forced-update) should be appended to the user supplied message.- Since:
- 4.9
-
disableRefLog
public void disableRefLog()Don't record this update in the ref's associated reflog.Equivalent to
setRefLogMessage(null, false)
.- Since:
- 4.9
-
setForceRefLog
public void setForceRefLog(boolean force) Force writing a reflog for the updated ref.- Parameters:
force
- whether to force.- Since:
- 4.9
-
hasCustomRefLog
public boolean hasCustomRefLog()Check whether this command has a custom reflog message setting that should override defaults in any containingBatchRefUpdate
.Does not take into account whether
#setForceRefLog(boolean)
has been called.- Returns:
- whether a custom reflog is set.
- Since:
- 4.9
-
isRefLogDisabled
public boolean isRefLogDisabled()Check whether log has been disabled bydisableRefLog()
.- Returns:
- true if disabled.
- Since:
- 4.9
-
getRefLogMessage
Get the message to include in the reflog.- Returns:
- message the caller wants to include in the reflog; null if the update should not be logged.
- Since:
- 4.9
-
isRefLogIncludingResult
public boolean isRefLogIncludingResult()Check whether the reflog message should include the result of the update, such as fast-forward or force-update.- Returns:
- true if the message should include the result.
- Since:
- 4.9
-
isForceRefLog
Check whether the reflog should be written regardless of repo defaults.- Returns:
- whether force writing is enabled;
null
if#setForceRefLog(boolean)
was never called. - Since:
- 4.9
-
setResult
Set the status of this command.- Parameters:
s
- the new status code for this command.
-
setResult
Set the status of this command.- Parameters:
s
- new status code for this command.m
- optional message explaining the new status.
-
updateType
Update the type of this command by checking for fast-forward.If the command's current type is UPDATE, a merge test will be performed using the supplied RevWalk to determine if
getOldId()
is fully merged intogetNewId()
. If some commits are not merged the update type is changed toReceiveCommand.Type.UPDATE_NONFASTFORWARD
.- Parameters:
walk
- an instance to perform the merge test with. The caller must allocate and release this object.- Throws:
IOException
- either oldId or newId is not accessible in the repository used by the RevWalk. This usually indicates data corruption, and the command cannot be processed.
-
execute
Execute this command during a receive-pack session.Sets the status of the command as a side effect.
- Parameters:
rp
- receive-pack session.- Since:
- 5.6
-
setRef
-
setType
-
setTypeFastForwardUpdate
void setTypeFastForwardUpdate() -
setResult
Set the result of this command.- Parameters:
r
- the new result code for this command.
-
reject
-
toString
-