Class DefaultSVNDiffGenerator

java.lang.Object
org.tmatesoft.svn.core.wc.DefaultSVNDiffGenerator
All Implemented Interfaces:
ISVNDiffGenerator
Direct Known Subclasses:
DefaultSVNCommandLineDiffGenerator, DefaultSVNGNUDiffGenerator

public class DefaultSVNDiffGenerator extends java.lang.Object implements ISVNDiffGenerator
DefaultSVNDiffGenerator is a default implementation of ISVNDiffGenerator.

By default, if there's no any specified implementation of the diff generator's interface, SVNKit uses this default implementation. To set a custom diff driver use setDiffGenerator().

Since:
1.2
Version:
1.3
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final java.io.InputStream
     
    protected static final java.lang.String
     
    private java.lang.String
     
    private java.lang.String
     
    private java.io.File
     
    private java.lang.String
     
     
    private java.lang.String
     
    private byte[]
     
    private boolean
     
    private boolean
     
    private boolean
     
    private boolean
     
    private boolean
     
    private boolean
     
    private ISVNOptions
     
    private java.util.Collection
     
    protected static final java.lang.String
     
    protected static final java.lang.String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a DefaultSVNDiffGenerator.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    createBadRelativePathError(java.lang.String path)
     
    java.io.File
    Creates a temporary directory for diff files.
    void
    displayAddedDirectory(java.lang.String path, java.lang.String rev1, java.lang.String rev2)
    Does nothing.
    protected void
    displayBinary(java.io.OutputStream os, java.lang.String mimeType1, java.lang.String mimeType2)
     
    void
    displayDeletedDirectory(java.lang.String path, java.lang.String rev1, java.lang.String rev2)
    Does nothing.
    void
    displayFileDiff(java.lang.String path, java.io.File file1, java.io.File file2, java.lang.String rev1, java.lang.String rev2, java.lang.String mimeType1, java.lang.String mimeType2, java.io.OutputStream result)
    Writes the difference between file1 and file2 as they are seen in rev1 and rev2 to result.
    protected boolean
    displayHeader(java.io.OutputStream os, java.lang.String path, boolean deleted)
     
    protected void
    displayHeaderFields(java.io.OutputStream os, java.lang.String label1, java.lang.String label2)
     
    private void
    displayMergeInfoDiff(java.io.ByteArrayOutputStream baos, java.lang.String oldValue, java.lang.String newValue)
     
    void
    displayPropDiff(java.lang.String path, SVNProperties baseProps, SVNProperties diff, java.io.OutputStream result)
    Produces properties difference and writes it to result.
    protected java.io.File
     
    Gets the diff options that are used by this generator.
    protected java.lang.String
    getDisplayPath(java.lang.String path)
     
    java.lang.String
    Returns the encoding used for diff output.
    byte[]
    Returns the EOL marker bytes being in use.
    protected java.lang.String
     
    java.lang.String
    Returns the encoding specified by svnkit.global-charset option of the global configuration.
    protected java.lang.String
    getLabel(java.lang.String path, java.lang.String revToken)
     
    protected ISVNOptions
     
    private byte[]
    getPropertyAsBytes(SVNPropertyValue value, java.lang.String encoding)
     
    boolean
    Says whether this generator is using any special (non-native) charset for outputting diffs.
    boolean
    Says whether this generator is using any special (non-native) EOL bytes for outputting diffs.
    void
    init(java.lang.String anchorPath1, java.lang.String anchorPath2)
    Initializes this generator with old and new diff anchor paths.
    boolean
    Tells whether added files must be diffed also.
    boolean
    Tells whether deleted files must be diffed also.
    boolean
    Tells whether deleted files must be diffed also.
    boolean
    Says if unversioned files are also diffed or ignored.
    boolean
    Tells if this generator forced binary files diff.
    protected boolean
    isHeaderForced(java.io.File file1, java.io.File file2)
     
    void
    setBasePath(java.io.File basePath)
    Sets the base path that must be stripped from the front of the paths of compared files.
    void
    setDiffAdded(boolean isDiffAdded)
    Enables or disables diffing added files.
    void
    setDiffCopied(boolean isDiffCopied)
    Enables or disables copied files diffing.
    void
    setDiffDeleted(boolean isDiffDeleted)
    Enables or disables diffing deleted files.
    void
    Sets diff options containing diff rules.
    void
    setDiffUnversioned(boolean diffUnversioned)
    Includes or not unversioned files into diff processing.
    void
    setEncoding(java.lang.String encoding)
    Sets the encoding to use for diff output.
    void
    setEOL(byte[] eol)
    Sets the EOL bytes to use in diff output.
    void
    setExternalDiffCommand(java.lang.String command)
    Sets an external diff program for producing the difference between files.
    void
    setFallbackToAbsolutePath(boolean fallback)
    Controls whether error is reported on failure to compute relative display path, or absolute path is used instead.
    void
    setForcedBinaryDiff(boolean forced)
    Sets whether binary files diff must be forced or not.
    void
    Sets global run-time options.
    void
    setRawDiffOptions(java.util.Collection options)
    Sets a collection of raw (String) diff options.
    protected boolean
     

    Methods inherited from class java.lang.Object

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

    • PROPERTIES_SEPARATOR

      protected static final java.lang.String PROPERTIES_SEPARATOR
      See Also:
    • HEADER_SEPARATOR

      protected static final java.lang.String HEADER_SEPARATOR
      See Also:
    • WC_REVISION_LABEL

      protected static final java.lang.String WC_REVISION_LABEL
      See Also:
    • EMPTY_FILE_IS

      protected static final java.io.InputStream EMPTY_FILE_IS
    • myIsForcedBinaryDiff

      private boolean myIsForcedBinaryDiff
    • myAnchorPath1

      private java.lang.String myAnchorPath1
    • myAnchorPath2

      private java.lang.String myAnchorPath2
    • myOptions

      private ISVNOptions myOptions
    • myEncoding

      private java.lang.String myEncoding
    • myEOL

      private byte[] myEOL
    • myIsDiffDeleted

      private boolean myIsDiffDeleted
    • myIsDiffAdded

      private boolean myIsDiffAdded
    • myIsDiffCopied

      private boolean myIsDiffCopied
    • myBasePath

      private java.io.File myBasePath
    • myIsDiffUnversioned

      private boolean myIsDiffUnversioned
    • myDiffOptions

      private SVNDiffOptions myDiffOptions
    • myRawDiffOptions

      private java.util.Collection myRawDiffOptions
    • myDiffCommand

      private java.lang.String myDiffCommand
    • myIsUseAbsolutePaths

      private boolean myIsUseAbsolutePaths
  • Constructor Details

    • DefaultSVNDiffGenerator

      public DefaultSVNDiffGenerator()
      Constructs a DefaultSVNDiffGenerator.
  • Method Details

    • init

      public void init(java.lang.String anchorPath1, java.lang.String anchorPath2)
      Initializes this generator with old and new diff anchor paths.
      Specified by:
      init in interface ISVNDiffGenerator
      Parameters:
      anchorPath1 - an old path/URL
      anchorPath2 - a new path/URL
    • setDiffOptions

      public void setDiffOptions(SVNDiffOptions options)
      Sets diff options containing diff rules.
      Parameters:
      options - diff options
    • setRawDiffOptions

      public void setRawDiffOptions(java.util.Collection options)
      Sets a collection of raw (String) diff options.
      Parameters:
      options - raw options
    • setOptions

      public void setOptions(ISVNOptions options)
      Sets global run-time options.
      Parameters:
      options - options implementation
    • setExternalDiffCommand

      public void setExternalDiffCommand(java.lang.String command)
      Sets an external diff program for producing the difference between files.
      Parameters:
      command - external diff program
    • setBasePath

      public void setBasePath(java.io.File basePath)
      Sets the base path that must be stripped from the front of the paths of compared files. If basePath is not null but is not a parent path of the target, this will lead to an error during diff.

      Note: basePath doesn't affect the path index generated by external diff programs.

      Specified by:
      setBasePath in interface ISVNDiffGenerator
      Parameters:
      basePath - common parent path to strip off the displayed paths
    • setFallbackToAbsolutePath

      public void setFallbackToAbsolutePath(boolean fallback)
      Controls whether error is reported on failure to compute relative display path, or absolute path is used instead.
      Parameters:
      fallback - true to make generator use absolute path when relative path could not be computed.
    • setDiffDeleted

      public void setDiffDeleted(boolean isDiffDeleted)
      Enables or disables diffing deleted files.
      Specified by:
      setDiffDeleted in interface ISVNDiffGenerator
      Parameters:
      isDiffDeleted -
      See Also:
    • isDiffDeleted

      public boolean isDiffDeleted()
      Tells whether deleted files must be diffed also.
      Specified by:
      isDiffDeleted in interface ISVNDiffGenerator
      Returns:
      true if deleted files must be diffed also
      See Also:
    • setDiffAdded

      public void setDiffAdded(boolean isDiffAdded)
      Enables or disables diffing added files.
      Specified by:
      setDiffAdded in interface ISVNDiffGenerator
      Parameters:
      isDiffAdded -
      See Also:
    • isDiffAdded

      public boolean isDiffAdded()
      Tells whether added files must be diffed also.
      Specified by:
      isDiffAdded in interface ISVNDiffGenerator
      Returns:
      true if added files must be diffed also
      See Also:
    • setDiffCopied

      public void setDiffCopied(boolean isDiffCopied)
      Enables or disables copied files diffing.
      Specified by:
      setDiffCopied in interface ISVNDiffGenerator
      Parameters:
      isDiffCopied -
      See Also:
    • isDiffCopied

      public boolean isDiffCopied()
      Tells whether deleted files must be diffed also.
      Specified by:
      isDiffCopied in interface ISVNDiffGenerator
      Returns:
      true if copied files must be diffed also
      See Also:
    • getDiffOptions

      public SVNDiffOptions getDiffOptions()
      Gets the diff options that are used by this generator. Creates a new one if none was used before.
      Returns:
      diff options
    • getDisplayPath

      protected java.lang.String getDisplayPath(java.lang.String path) throws SVNException
      Throws:
      SVNException
    • setForcedBinaryDiff

      public void setForcedBinaryDiff(boolean forced)
      Sets whether binary files diff must be forced or not.
      Specified by:
      setForcedBinaryDiff in interface ISVNDiffGenerator
      Parameters:
      forced - whether to force binary diff or not
    • isForcedBinaryDiff

      public boolean isForcedBinaryDiff()
      Tells if this generator forced binary files diff.
      Specified by:
      isForcedBinaryDiff in interface ISVNDiffGenerator
      Returns:
      true if forces; otherwise false
    • displayPropDiff

      public void displayPropDiff(java.lang.String path, SVNProperties baseProps, SVNProperties diff, java.io.OutputStream result) throws SVNException
      Produces properties difference and writes it to result.
      Specified by:
      displayPropDiff in interface ISVNDiffGenerator
      Parameters:
      path -
      baseProps -
      diff -
      result -
      Throws:
      SVNException - in the following cases:
    • getPropertyAsBytes

      private byte[] getPropertyAsBytes(SVNPropertyValue value, java.lang.String encoding)
    • getBasePath

      protected java.io.File getBasePath()
    • displayFileDiff

      public void displayFileDiff(java.lang.String path, java.io.File file1, java.io.File file2, java.lang.String rev1, java.lang.String rev2, java.lang.String mimeType1, java.lang.String mimeType2, java.io.OutputStream result) throws SVNException
      Writes the difference between file1 and file2 as they are seen in rev1 and rev2 to result.
      Specified by:
      displayFileDiff in interface ISVNDiffGenerator
      Parameters:
      path -
      file1 -
      file2 -
      rev1 -
      rev2 -
      mimeType1 -
      mimeType2 -
      result -
      Throws:
      SVNException - in the following cases:
    • setEncoding

      public void setEncoding(java.lang.String encoding)
      Sets the encoding to use for diff output.
      Specified by:
      setEncoding in interface ISVNDiffGenerator
      Parameters:
      encoding - charset name
    • getEncoding

      public java.lang.String getEncoding()
      Returns the encoding used for diff output.
      Specified by:
      getEncoding in interface ISVNDiffGenerator
      Returns:
      charset name
    • hasEncoding

      public boolean hasEncoding()
      Says whether this generator is using any special (non-native) charset for outputting diffs.
      Returns:
      true if yes; otherwise false
    • hasEOL

      public boolean hasEOL()
      Says whether this generator is using any special (non-native) EOL bytes for outputting diffs.
      Returns:
      true if yes; otherwise false
    • getGlobalEncoding

      public java.lang.String getGlobalEncoding()
      Returns the encoding specified by svnkit.global-charset option of the global configuration.
      Returns:
      global charset name
    • setEOL

      public void setEOL(byte[] eol)
      Sets the EOL bytes to use in diff output.
      Specified by:
      setEOL in interface ISVNDiffGenerator
      Parameters:
      eol - EOL bytes
    • getEOL

      public byte[] getEOL()
      Returns the EOL marker bytes being in use. If no EOL bytes were provided, uses native EOL fetched from the options.
      Specified by:
      getEOL in interface ISVNDiffGenerator
      Returns:
      EOL bytes
    • createTempDirectory

      public java.io.File createTempDirectory() throws SVNException
      Creates a temporary directory for diff files.
      Specified by:
      createTempDirectory in interface ISVNDiffGenerator
      Returns:
      returns the temp directory
      Throws:
      SVNException
    • isDiffUnversioned

      public boolean isDiffUnversioned()
      Says if unversioned files are also diffed or ignored.

      By default unversioned files are ignored.

      Specified by:
      isDiffUnversioned in interface ISVNDiffGenerator
      Returns:
      true if diffed, false if ignored
      See Also:
    • setDiffUnversioned

      public void setDiffUnversioned(boolean diffUnversioned)
      Includes or not unversioned files into diff processing.

      If a diff operation is invoked on a versioned directory and diffUnversioned is true then all unversioned files that may be met in the directory will be processed as added. Otherwise if diffUnversioned is false such files are ignored.

      By default unversioned files are ignored.

      Specified by:
      setDiffUnversioned in interface ISVNDiffGenerator
      Parameters:
      diffUnversioned - controls whether to diff unversioned files or not
      See Also:
    • displayDeletedDirectory

      public void displayDeletedDirectory(java.lang.String path, java.lang.String rev1, java.lang.String rev2) throws SVNException
      Does nothing.
      Specified by:
      displayDeletedDirectory in interface ISVNDiffGenerator
      Parameters:
      path - a directory path
      rev1 - the first diff revision
      rev2 - the second diff revision
      Throws:
      SVNException
    • displayAddedDirectory

      public void displayAddedDirectory(java.lang.String path, java.lang.String rev1, java.lang.String rev2) throws SVNException
      Does nothing.
      Specified by:
      displayAddedDirectory in interface ISVNDiffGenerator
      Parameters:
      path - a directory path
      rev1 - the first diff revision
      rev2 - the second diff revision
      Throws:
      SVNException
    • getExternalDiffCommand

      protected java.lang.String getExternalDiffCommand()
    • getOptions

      protected ISVNOptions getOptions()
    • displayBinary

      protected void displayBinary(java.io.OutputStream os, java.lang.String mimeType1, java.lang.String mimeType2) throws java.io.IOException
      Throws:
      java.io.IOException
    • displayHeader

      protected boolean displayHeader(java.io.OutputStream os, java.lang.String path, boolean deleted) throws java.io.IOException
      Throws:
      java.io.IOException
    • displayHeaderFields

      protected void displayHeaderFields(java.io.OutputStream os, java.lang.String label1, java.lang.String label2) throws java.io.IOException
      Throws:
      java.io.IOException
    • isHeaderForced

      protected boolean isHeaderForced(java.io.File file1, java.io.File file2)
    • useLocalFileSeparatorChar

      protected boolean useLocalFileSeparatorChar()
    • getLabel

      protected java.lang.String getLabel(java.lang.String path, java.lang.String revToken)
    • displayMergeInfoDiff

      private void displayMergeInfoDiff(java.io.ByteArrayOutputStream baos, java.lang.String oldValue, java.lang.String newValue) throws SVNException, java.io.IOException
      Throws:
      SVNException
      java.io.IOException
    • createBadRelativePathError

      private void createBadRelativePathError(java.lang.String path) throws SVNException
      Throws:
      SVNException