public class Command
extends java.lang.Object
RefTree
.
Unlike ReceiveCommand
(which can only
update a reference to an ObjectId
), a RefTree
Command can also create, modify or delete symbolic references to a target
reference.
RefTree Commands may wrap a ReceiveCommand
to allow callers to
process an existing ReceiveCommand against a RefTree.
Commands should be passed into
RefTree.apply(java.util.Collection)
for processing.
Modifier and Type | Field and Description |
---|---|
private ReceiveCommand |
cmd |
private Ref |
newRef |
private Ref |
oldRef |
private ReceiveCommand.Result |
result |
Constructor and Description |
---|
Command(Ref oldRef,
Ref newRef)
Create a command to create, update or delete a reference.
|
Command(RevWalk rw,
ReceiveCommand cmd)
Construct a RefTree command wrapped around a ReceiveCommand.
|
Modifier and Type | Method and Description |
---|---|
static void |
abort(java.lang.Iterable<Command> commands,
java.lang.String why)
Set unprocessed commands as failed due to transaction aborted.
|
private static void |
append(java.lang.StringBuilder s,
Ref r,
java.lang.String nullName) |
private static boolean |
check(DirCacheEntry cur,
Ref exp) |
(package private) boolean |
checkRef(DirCacheEntry entry)
Check the entry is consistent with either the old or the new ref.
|
java.lang.String |
getMessage()
Get optional message explaining command failure.
|
Ref |
getNewRef()
New peeled reference.
|
Ref |
getOldRef()
Old peeled reference.
|
java.lang.String |
getRefName()
Get name of the reference affected by this command.
|
ReceiveCommand.Result |
getResult()
Get result of executing this command.
|
void |
setResult(ReceiveCommand.Result result)
Set the result of this command.
|
void |
setResult(ReceiveCommand.Result result,
java.lang.String why)
Set the result of this command.
|
(package private) static ObjectId |
symref(java.lang.String s) |
(package private) static Ref |
toRef(RevWalk rw,
ObjectId id,
java.lang.String target,
java.lang.String name,
boolean mustExist) |
java.lang.String |
toString() |
private final Ref oldRef
private final Ref newRef
private final ReceiveCommand cmd
private ReceiveCommand.Result result
public Command(@Nullable Ref oldRef, @Nullable Ref newRef)
At least one of oldRef
or newRef
must be supplied.
oldRef
- expected value. Null if the ref should not exist.newRef
- desired value, must be peeled if not null and not symbolic.
Null to delete the ref.public Command(RevWalk rw, ReceiveCommand cmd) throws MissingObjectException, java.io.IOException
rw
- walk instance to peel the newId
.cmd
- command received from a push client.MissingObjectException
- oldId
or newId
is missing.java.io.IOException
- oldId
or newId
cannot be peeled.public static void abort(java.lang.Iterable<Command> commands, @Nullable java.lang.String why)
If a command is still
ReceiveCommand.Result.NOT_ATTEMPTED
it
will be set to
ReceiveCommand.Result.REJECTED_OTHER_REASON
.
If why
is non-null its contents will be used as the message for
the first command status.
commands
- commands to mark as failed.why
- optional message to set on the first aborted command.static Ref toRef(RevWalk rw, ObjectId id, @Nullable java.lang.String target, java.lang.String name, boolean mustExist) throws MissingObjectException, java.io.IOException
MissingObjectException
java.io.IOException
public java.lang.String getRefName()
public void setResult(ReceiveCommand.Result result)
result
- the command result.public void setResult(ReceiveCommand.Result result, @Nullable java.lang.String why)
result
- the command result.why
- optional message explaining the result status.public ReceiveCommand.Result getResult()
@Nullable public java.lang.String getMessage()
@Nullable public Ref getOldRef()
@Nullable public Ref getNewRef()
public java.lang.String toString()
toString
in class java.lang.Object
private static void append(java.lang.StringBuilder s, Ref r, java.lang.String nullName)
boolean checkRef(@Nullable DirCacheEntry entry)
entry
- current entry; null if the entry does not exist.getOldRef()
or
getNewRef()
; otherwise false.private static boolean check(@Nullable DirCacheEntry cur, @Nullable Ref exp)
static ObjectId symref(java.lang.String s)