Class ReceiveCommand
- java.lang.Object
-
- org.eclipse.jgit.transport.ReceiveCommand
-
- Direct Known Subclasses:
TrackingRefUpdate.Command
public class ReceiveCommand extends java.lang.Object
A command being processed byReceivePack
.This command instance roughly translates to the server side representation of the
RemoteRefUpdate
created by the client.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ReceiveCommand.Result
Result of the update command.static class
ReceiveCommand.Type
Type of operation requested.
-
Field Summary
Fields Modifier and Type Field Description private boolean
customRefLog
private java.lang.Boolean
forceRefLog
private java.lang.String
message
private java.lang.String
name
private ObjectId
newId
private java.lang.String
newSymref
private ObjectId
oldId
private java.lang.String
oldSymref
private Ref
ref
private boolean
refLogIncludeResult
private java.lang.String
refLogMessage
private ReceiveCommand.Result
status
private ReceiveCommand.Type
type
private boolean
typeIsCorrect
-
Constructor Summary
Constructors Modifier Constructor Description private
ReceiveCommand(java.lang.String oldTarget, java.lang.String newTarget, java.lang.String name)
Create a command to switch a symbolic reference's target.private
ReceiveCommand(java.lang.String oldSymref, ObjectId newId, java.lang.String name)
Create a command to switch a reference from symbolic to object.private
ReceiveCommand(ObjectId oldId, java.lang.String newSymref, java.lang.String name)
Create a command to switch a reference from object to symbolic.ReceiveCommand(ObjectId oldId, ObjectId newId, java.lang.String name)
Create a new command forReceivePack
.ReceiveCommand(ObjectId oldId, ObjectId newId, java.lang.String name, ReceiveCommand.Type type)
Create a new command forReceivePack
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
abort(java.lang.Iterable<ReceiveCommand> commands)
Set unprocessed commands as failed due to transaction aborted.void
disableRefLog()
Don't record this update in the ref's associated reflog.void
execute(ReceivePack rp)
Execute this command during a receive-pack session.static java.util.List<ReceiveCommand>
filter(java.lang.Iterable<ReceiveCommand> in, ReceiveCommand.Result want)
Filter a collection of commands according to result.static java.util.List<ReceiveCommand>
filter(java.util.List<ReceiveCommand> commands, ReceiveCommand.Result want)
Filter a list of commands according to result.java.lang.String
getMessage()
Get the message associated with a failure status.ObjectId
getNewId()
Get the requested new value for this ref.java.lang.String
getNewSymref()
Get requested new target for a symbolic reference.ObjectId
getOldId()
Get the old value the client thinks the ref has.java.lang.String
getOldSymref()
Get expected old target for a symbolic reference.Ref
getRef()
Get the ref, if this was advertised by the connection.java.lang.String
getRefLogMessage()
Get the message to include in the reflog.java.lang.String
getRefName()
Get the name of the ref being updated.ReceiveCommand.Result
getResult()
Get the current status code of this command.ReceiveCommand.Type
getType()
Get the type of this command; seeReceiveCommand.Type
.boolean
hasCustomRefLog()
Check whether this command has a custom reflog message setting that should override defaults in any containingBatchRefUpdate
.java.lang.Boolean
isForceRefLog()
Check whether the reflog should be written regardless of repo defaults.boolean
isRefLogDisabled()
Check whether log has been disabled bydisableRefLog()
.boolean
isRefLogIncludingResult()
Check whether the reflog message should include the result of the update, such as fast-forward or force-update.static boolean
isTransactionAborted(ReceiveCommand cmd)
Check whether a command failed due to transaction aborted.static ReceiveCommand
link(java.lang.String oldTarget, java.lang.String newTarget, java.lang.String name)
Create a command to switch a symbolic reference's target.static ReceiveCommand
link(ObjectId oldId, java.lang.String newTarget, java.lang.String name)
Create a command to switch a reference from object to symbolic.(package private) void
reject(java.io.IOException err)
void
setForceRefLog(boolean force)
Force writing a reflog for the updated ref.(package private) void
setRef(Ref r)
void
setRefLogMessage(java.lang.String msg, boolean appendStatus)
Set the message to include in the reflog.void
setResult(RefUpdate.Result r)
Set the result of this command.void
setResult(ReceiveCommand.Result s)
Set the status of this command.void
setResult(ReceiveCommand.Result s, java.lang.String m)
Set the status of this command.(package private) void
setType(ReceiveCommand.Type t)
(package private) void
setTypeFastForwardUpdate()
java.lang.String
toString()
static ReceiveCommand
unlink(java.lang.String oldTarget, ObjectId newId, java.lang.String name)
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 Detail
-
oldId
private final ObjectId oldId
-
oldSymref
private final java.lang.String oldSymref
-
newId
private final ObjectId newId
-
newSymref
private final java.lang.String newSymref
-
name
private final java.lang.String name
-
type
private ReceiveCommand.Type type
-
typeIsCorrect
private boolean typeIsCorrect
-
ref
private Ref ref
-
status
private ReceiveCommand.Result status
-
message
private java.lang.String message
-
customRefLog
private boolean customRefLog
-
refLogMessage
private java.lang.String refLogMessage
-
refLogIncludeResult
private boolean refLogIncludeResult
-
forceRefLog
private java.lang.Boolean forceRefLog
-
-
Constructor Detail
-
ReceiveCommand
public ReceiveCommand(ObjectId oldId, ObjectId newId, java.lang.String name)
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
public ReceiveCommand(ObjectId oldId, ObjectId newId, java.lang.String name, ReceiveCommand.Type type)
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
private ReceiveCommand(ObjectId oldId, java.lang.String newSymref, java.lang.String name)
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
private ReceiveCommand(java.lang.String oldSymref, ObjectId newId, java.lang.String name)
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
private ReceiveCommand(@Nullable java.lang.String oldTarget, java.lang.String newTarget, java.lang.String name)
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 Detail
-
filter
public static java.util.List<ReceiveCommand> filter(java.lang.Iterable<ReceiveCommand> in, ReceiveCommand.Result want)
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 java.util.List<ReceiveCommand> filter(java.util.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
public static void abort(java.lang.Iterable<ReceiveCommand> commands)
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
public static boolean isTransactionAborted(ReceiveCommand cmd)
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 java.lang.String newTarget, @NonNull java.lang.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 java.lang.String oldTarget, @NonNull java.lang.String newTarget, @NonNull java.lang.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 java.lang.String oldTarget, @NonNull ObjectId newId, @NonNull java.lang.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
public ObjectId getOldId()
Get the old value the client thinks the ref has.- Returns:
- the old value the client thinks the ref has.
-
getOldSymref
@Nullable public java.lang.String getOldSymref()
Get expected old target for a symbolic reference.- Returns:
- expected old target for a symbolic reference.
- Since:
- 4.10
-
getNewId
public ObjectId getNewId()
Get the requested new value for this ref.- Returns:
- the requested new value for this ref.
-
getNewSymref
@Nullable public java.lang.String getNewSymref()
Get requested new target for a symbolic reference.- Returns:
- requested new target for a symbolic reference.
- Since:
- 4.10
-
getRefName
public java.lang.String getRefName()
Get the name of the ref being updated.- Returns:
- the name of the ref being updated.
-
getType
public ReceiveCommand.Type getType()
Get the type of this command; seeReceiveCommand.Type
.- Returns:
- the type of this command; see
ReceiveCommand.Type
.
-
getRef
public Ref getRef()
Get the ref, if this was advertised by the connection.- Returns:
- the ref, if this was advertised by the connection.
-
getResult
public ReceiveCommand.Result getResult()
Get the current status code of this command.- Returns:
- the current status code of this command.
-
getMessage
public java.lang.String getMessage()
Get the message associated with a failure status.- Returns:
- the message associated with a failure status.
-
setRefLogMessage
public void setRefLogMessage(java.lang.String msg, boolean appendStatus)
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
@Nullable public java.lang.String 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
@Nullable public java.lang.Boolean 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
public void setResult(ReceiveCommand.Result s)
Set the status of this command.- Parameters:
s
- the new status code for this command.
-
setResult
public void setResult(ReceiveCommand.Result s, java.lang.String m)
Set the status of this command.- Parameters:
s
- new status code for this command.m
- optional message explaining the new status.
-
updateType
public void updateType(RevWalk walk) throws java.io.IOException
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:
java.io.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
public void execute(ReceivePack rp)
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
void setRef(Ref r)
-
setType
void setType(ReceiveCommand.Type t)
-
setTypeFastForwardUpdate
void setTypeFastForwardUpdate()
-
setResult
public void setResult(RefUpdate.Result r)
Set the result of this command.- Parameters:
r
- the new result code for this command.
-
reject
void reject(java.io.IOException err)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-