Class Command
- java.lang.Object
-
- org.eclipse.jgit.internal.storage.reftree.Command
-
public class Command extends java.lang.Object
Command to create, update or delete an entry inside aRefTree
.Unlike
ReceiveCommand
(which can only update a reference to anObjectId
), 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.
-
-
Field Summary
Fields Modifier and Type Field Description private ReceiveCommand
cmd
private Ref
newRef
private Ref
oldRef
private ReceiveCommand.Result
result
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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()
-
-
-
Field Detail
-
oldRef
private final Ref oldRef
-
newRef
private final Ref newRef
-
cmd
private final ReceiveCommand cmd
-
result
private ReceiveCommand.Result result
-
-
Constructor Detail
-
Command
public Command(@Nullable Ref oldRef, @Nullable Ref newRef)
Create a command to create, update or delete a reference.At least one of
oldRef
ornewRef
must be supplied.- Parameters:
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.
-
Command
public Command(RevWalk rw, ReceiveCommand cmd) throws MissingObjectException, java.io.IOException
Construct a RefTree command wrapped around a ReceiveCommand.- Parameters:
rw
- walk instance to peel thenewId
.cmd
- command received from a push client.- Throws:
MissingObjectException
-oldId
ornewId
is missing.java.io.IOException
-oldId
ornewId
cannot be peeled.
-
-
Method Detail
-
abort
public static void abort(java.lang.Iterable<Command> commands, @Nullable java.lang.String why)
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
. Ifwhy
is non-null its contents will be used as the message for the first command status.- Parameters:
commands
- commands to mark as failed.why
- optional message to set on the first aborted command.
-
toRef
static Ref toRef(RevWalk rw, ObjectId id, @Nullable java.lang.String target, java.lang.String name, boolean mustExist) throws MissingObjectException, java.io.IOException
- Throws:
MissingObjectException
java.io.IOException
-
getRefName
public java.lang.String getRefName()
Get name of the reference affected by this command.- Returns:
- name of the reference affected by this command.
-
setResult
public void setResult(ReceiveCommand.Result result)
Set the result of this command.- Parameters:
result
- the command result.
-
setResult
public void setResult(ReceiveCommand.Result result, @Nullable java.lang.String why)
Set the result of this command.- Parameters:
result
- the command result.why
- optional message explaining the result status.
-
getResult
public ReceiveCommand.Result getResult()
Get result of executing this command.- Returns:
- result of executing this command.
-
getMessage
@Nullable public java.lang.String getMessage()
Get optional message explaining command failure.- Returns:
- optional message explaining command failure.
-
getOldRef
@Nullable public Ref getOldRef()
Old peeled reference.- Returns:
- the old reference; null if the command is creating the reference.
-
getNewRef
@Nullable public Ref getNewRef()
New peeled reference.- Returns:
- the new reference; null if the command is deleting the reference.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
append
private static void append(java.lang.StringBuilder s, Ref r, java.lang.String nullName)
-
checkRef
boolean checkRef(@Nullable DirCacheEntry entry)
Check the entry is consistent with either the old or the new ref.- Parameters:
entry
- current entry; null if the entry does not exist.- Returns:
- true if entry matches
getOldRef()
orgetNewRef()
; otherwise false.
-
check
private static boolean check(@Nullable DirCacheEntry cur, @Nullable Ref exp)
-
symref
static ObjectId symref(java.lang.String s)
-
-