Class Command


  • public class Command
    extends java.lang.Object
    Command to create, update or delete an entry inside a 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.

    • 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 or newRef 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 the newId.
        cmd - command received from a push client.
        Throws:
        MissingObjectException - oldId or newId is missing.
        java.io.IOException - oldId or newId 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 to ReceiveCommand.Result.REJECTED_OTHER_REASON. If why 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.
      • 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 class java.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() or getNewRef(); otherwise false.
      • symref

        static ObjectId symref​(java.lang.String s)