Class TextBuiltin

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected RevWalk argWalk
      RevWalk used during command line parsing, if it was required.
      private java.lang.String commandName  
      protected Repository db
      Git repository the command was invoked within.
      protected java.io.OutputStream errs
      Error output stream, typically this is standard error.
      protected ThrowingPrintWriter errw
      Error writer, typically this is standard error.
      protected java.lang.String gitdir
      Directory supplied via --git-dir command line option.
      private boolean help  
      protected java.io.InputStream ins
      Input stream, typically this is standard input.
      protected java.io.OutputStream outs
      Stream to output to, typically this is standard output.
      protected ThrowingPrintWriter outw
      Writer to output to, typically this is standard output.
      private SshDriver sshDriver  
    • Constructor Summary

      Constructors 
      Constructor Description
      TextBuiltin()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) java.lang.String abbreviateRef​(java.lang.String dst, boolean abbreviateRemote)  
      static boolean containsHelp​(java.lang.String[] args)
      Check if the arguments contain a help option
      protected static Die die​(boolean aborted)
      Exit the command
      protected static Die die​(boolean aborted, java.lang.Throwable cause)
      Exit the command
      protected static Die die​(java.lang.String why)
      Exit the command with an error message
      protected static Die die​(java.lang.String why, java.lang.Throwable cause)
      Exit the command with an error message and an exception
      void execute​(java.lang.String[] args)
      Parse arguments and run this command.
      ThrowingPrintWriter getErrorWriter()
      Get error writer
      private java.nio.charset.Charset getLogOutputEncodingCharset​(Repository repository)
      Get the log output encoding specified in the repository's i18n.logOutputEncoding configuration.
      ThrowingPrintWriter getOutputWriter()
      Get output writer
      Repository getRepository()
      Get the repository
      protected java.util.ResourceBundle getResourceBundle()
      Get resource bundle with localized texts
      protected void init​(Repository repository, java.lang.String gitDir)
      Initialize the command to work with a repository.
      void initRaw​(Repository repository, java.lang.String gitDir, java.io.InputStream input, java.io.OutputStream output, java.io.OutputStream error)
      Initializes the command to work with a repository, including setting the output and error streams.
      protected void parseArguments​(java.lang.String[] args)
      Parses the command line arguments prior to running.
      protected void printUsage​(java.lang.String message, CmdLineParser clp)
      Print usage help text.
      void printUsageAndExit​(java.lang.String message, CmdLineParser clp)
      Print an error message and the usage line
      void printUsageAndExit​(CmdLineParser clp)
      Print the usage line
      protected boolean requiresRepository()
      If this command requires a repository.
      (package private) ObjectId resolve​(java.lang.String s)  
      protected abstract void run()
      Perform the actions of this command.
      (package private) void setCommandName​(java.lang.String name)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • commandName

        private java.lang.String commandName
      • help

        private boolean help
      • ins

        protected java.io.InputStream ins
        Input stream, typically this is standard input.
        Since:
        3.4
      • outw

        protected ThrowingPrintWriter outw
        Writer to output to, typically this is standard output.
        Since:
        2.2
      • outs

        protected java.io.OutputStream outs
        Stream to output to, typically this is standard output.
        Since:
        2.2
      • errw

        protected ThrowingPrintWriter errw
        Error writer, typically this is standard error.
        Since:
        3.4
      • errs

        protected java.io.OutputStream errs
        Error output stream, typically this is standard error.
        Since:
        3.4
      • db

        protected Repository db
        Git repository the command was invoked within.
      • gitdir

        protected java.lang.String gitdir
        Directory supplied via --git-dir command line option.
      • argWalk

        protected RevWalk argWalk
        RevWalk used during command line parsing, if it was required.
    • Constructor Detail

      • TextBuiltin

        public TextBuiltin()
    • Method Detail

      • setCommandName

        final void setCommandName​(java.lang.String name)
      • requiresRepository

        protected boolean requiresRepository()
        If this command requires a repository.
        Returns:
        true if db/getRepository() is required
      • initRaw

        public void initRaw​(Repository repository,
                            java.lang.String gitDir,
                            java.io.InputStream input,
                            java.io.OutputStream output,
                            java.io.OutputStream error)
        Initializes the command to work with a repository, including setting the output and error streams.
        Parameters:
        repository - the opened repository that the command should work on.
        gitDir - value of the --git-dir command line option, if repository is null.
        input - input stream from which input will be read
        output - output stream to which output will be written
        error - error stream to which errors will be written
        Since:
        4.9
      • getLogOutputEncodingCharset

        private java.nio.charset.Charset getLogOutputEncodingCharset​(Repository repository)
        Get the log output encoding specified in the repository's i18n.logOutputEncoding configuration.
        Parameters:
        repository - the repository.
        Returns:
        Charset corresponding to i18n.logOutputEncoding, or UTF_8.
      • init

        protected void init​(Repository repository,
                            java.lang.String gitDir)
        Initialize the command to work with a repository.
        Parameters:
        repository - the opened repository that the command should work on.
        gitDir - value of the --git-dir command line option, if repository is null.
      • execute

        public final void execute​(java.lang.String[] args)
                           throws java.lang.Exception
        Parse arguments and run this command.
        Parameters:
        args - command line arguments passed after the command name.
        Throws:
        java.lang.Exception - an error occurred while processing the command. The main framework will catch the exception and print a message on standard error.
      • parseArguments

        protected void parseArguments​(java.lang.String[] args)
                               throws java.io.IOException
        Parses the command line arguments prior to running.

        This method should only be invoked by execute(String[]), prior to calling run(). The default implementation parses all arguments into this object's instance fields.

        Parameters:
        args - the arguments supplied on the command line, if any.
        Throws:
        java.io.IOException
      • printUsageAndExit

        public void printUsageAndExit​(CmdLineParser clp)
                               throws java.io.IOException
        Print the usage line
        Parameters:
        clp - a CmdLineParser object.
        Throws:
        java.io.IOException
      • printUsageAndExit

        public void printUsageAndExit​(java.lang.String message,
                                      CmdLineParser clp)
                               throws java.io.IOException
        Print an error message and the usage line
        Parameters:
        message - a String object.
        clp - a CmdLineParser object.
        Throws:
        java.io.IOException
      • printUsage

        protected void printUsage​(java.lang.String message,
                                  CmdLineParser clp)
                           throws java.io.IOException
        Print usage help text.
        Parameters:
        message - non null
        clp - parser used to print options
        Throws:
        java.io.IOException
        Since:
        4.2
      • getErrorWriter

        public ThrowingPrintWriter getErrorWriter()
        Get error writer
        Returns:
        error writer, typically this is standard error.
        Since:
        4.2
      • getOutputWriter

        public ThrowingPrintWriter getOutputWriter()
        Get output writer
        Returns:
        output writer, typically this is standard output.
        Since:
        4.9
      • getResourceBundle

        protected java.util.ResourceBundle getResourceBundle()
        Get resource bundle with localized texts
        Returns:
        the resource bundle that will be passed to args4j for purpose of string localization
      • run

        protected abstract void run()
                             throws java.lang.Exception
        Perform the actions of this command.

        This method should only be invoked by execute(String[]).

        Throws:
        java.lang.Exception - an error occurred while processing the command. The main framework will catch the exception and print a message on standard error.
      • getRepository

        public Repository getRepository()
        Get the repository
        Returns:
        the repository this command accesses.
      • resolve

        ObjectId resolve​(java.lang.String s)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • die

        protected static Die die​(java.lang.String why)
        Exit the command with an error message
        Parameters:
        why - textual explanation
        Returns:
        a runtime exception the caller is expected to throw
      • die

        protected static Die die​(java.lang.String why,
                                 java.lang.Throwable cause)
        Exit the command with an error message and an exception
        Parameters:
        why - textual explanation
        cause - why the command has failed.
        Returns:
        a runtime exception the caller is expected to throw
      • die

        protected static Die die​(boolean aborted)
        Exit the command
        Parameters:
        aborted - boolean indicating that the execution has been aborted before running
        Returns:
        a runtime exception the caller is expected to throw
        Since:
        3.4
      • die

        protected static Die die​(boolean aborted,
                                 java.lang.Throwable cause)
        Exit the command
        Parameters:
        aborted - boolean indicating that the execution has been aborted before running
        cause - why the command has failed.
        Returns:
        a runtime exception the caller is expected to throw
        Since:
        4.2
      • abbreviateRef

        java.lang.String abbreviateRef​(java.lang.String dst,
                                       boolean abbreviateRemote)
      • containsHelp

        public static boolean containsHelp​(java.lang.String[] args)
        Check if the arguments contain a help option
        Parameters:
        args - non null
        Returns:
        true if the given array contains help option
        Since:
        4.2