Class ReceiveCommand


  • public class ReceiveCommand
    extends Object
    A command being processed by ReceivePack.

    This command instance roughly translates to the server side representation of the RemoteRefUpdate created by the client.

    • Method Detail

      • filter

        public static List<ReceiveCommand> filter​(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 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
      • 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
                                          String newTarget,
                                          @NonNull
                                          String name)
        Create a command to switch a reference from object to symbolic.
        Parameters:
        oldId - expected oldId. May be zeroId 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 be zeroId() 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 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 String getNewSymref()
        Get requested new target for a symbolic reference.
        Returns:
        requested new target for a symbolic reference.
        Since:
        4.10
      • getRefName

        public String getRefName()
        Get the name of the ref being updated.
        Returns:
        the name of the ref being updated.
      • 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 String getMessage()
        Get the message associated with a failure status.
        Returns:
        the message associated with a failure status.
      • setRefLogMessage

        public void setRefLogMessage​(String msg,
                                     boolean appendStatus)
        Set the message to include in the reflog.

        Overrides the default set by setRefLogMessage on any containing BatchRefUpdate.

        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 containing BatchRefUpdate.

        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 by disableRefLog().
        Returns:
        true if disabled.
        Since:
        4.9
      • getRefLogMessage

        @Nullable
        public 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 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,
                              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 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 into getNewId(). If some commits are not merged the update type is changed to ReceiveCommand.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

        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
      • setResult

        public void setResult​(RefUpdate.Result r)
        Set the result of this command.
        Parameters:
        r - the new result code for this command.