Class GitCompareUtils


  • public final class GitCompareUtils
    extends Object
    Utility class to Git infrastructure and the EDT mechanism of comparison and merge.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static ComparisonScope buildComparisonScope​(String projectPath, List<FileDiff> diffs, IQualifiedNameFilePathConverter filePathConverter, boolean isThreeWay)
      Builds a comparison scope according to given diffs.
      static List<String> findAddedProjectPaths​(List<FileDiff> diffs)
      Finds the added project paths from the given collection of diffs.
      static List<String> findDeletedProjectPaths​(List<FileDiff> diffs)
      Finds the deleted project paths from the given collection of diffs.
      static List<FileDiff> findDiffs​(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.revwalk.RevCommit mainCommit, org.eclipse.jgit.revwalk.RevCommit otherCommit, boolean useIndex, List<String> pathsToFilter, org.eclipse.core.runtime.IProgressMonitor monitor)
      Returns file diffs for the main and other commits.
      static List<FileDiff> findProjectDiffs​(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.revwalk.RevCommit mainCommit, org.eclipse.jgit.revwalk.RevCommit otherCommit, boolean useIndex, String projectPath, List<String> pathsToFilter, org.eclipse.core.runtime.IProgressMonitor monitor)
      Returns file diffs for the main and other commits for the given project.
      static org.eclipse.jgit.revwalk.RevCommit getBaseCommit​(org.eclipse.jgit.revwalk.RevCommit firstCommit, org.eclipse.jgit.revwalk.RevCommit secondCommit, org.eclipse.jgit.revwalk.RevWalk revWalk)
      Returns the base commit of the two given commits.
      static String getCommitShortName​(org.eclipse.jgit.revwalk.RevCommit revCommit)
      Returns commit short name.
      static org.eclipse.jgit.revwalk.RevCommit getRevCommit​(org.eclipse.jgit.lib.Repository repository, String refName, boolean load)
      Returns a RevCommit for the given ref name.
      static org.eclipse.jgit.revwalk.RevCommit getRevCommit​(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.revwalk.RevWalk revWalk, String refName, boolean load)
      Returns a RevCommit for the given ref name.
      static InputStream getStreamByFileName​(org.eclipse.jgit.lib.Repository repository, org.eclipse.jgit.revwalk.RevCommit revCommit, String filePath, org.eclipse.core.runtime.IProgressMonitor monitor)
      Returns an input stream for the given rev commit and file path.
      static InputStream getStreamByFileNameFromIndex​(org.eclipse.jgit.lib.Repository repository, String filePath, org.eclipse.core.runtime.IProgressMonitor monitor)
      Returns an input stream for the given file path from the Git index.
      static boolean isV8Project​(Path projectPath)
      Checks whether the project associated with the given path is V8 project.
      static String replaceBackslash​(String path)
      Replaces all backslashes to slashes in the specified path.
    • Field Detail

      • COMMIT_HASH_PREFIX_LENGTH

        public static final int COMMIT_HASH_PREFIX_LENGTH
        The prefix length of commit hash.
        See Also:
        Constant Field Values
    • Method Detail

      • getBaseCommit

        public static org.eclipse.jgit.revwalk.RevCommit getBaseCommit​(org.eclipse.jgit.revwalk.RevCommit firstCommit,
                                                                       org.eclipse.jgit.revwalk.RevCommit secondCommit,
                                                                       org.eclipse.jgit.revwalk.RevWalk revWalk)
                                                                throws IOException
        Returns the base commit of the two given commits.
        Parameters:
        firstCommit - the first commit, cannot be null
        secondCommit - the second commit, cannot be null
        revWalk - the RevWalk instance, cannot be null
        Returns:
        the base commit or null if there is no base commit
        Throws:
        IOException - if failed to get the base commit
      • getRevCommit

        public static org.eclipse.jgit.revwalk.RevCommit getRevCommit​(org.eclipse.jgit.lib.Repository repository,
                                                                      String refName,
                                                                      boolean load)
                                                               throws IOException
        Returns a RevCommit for the given ref name.
        Parameters:
        repository - the target Git repository, cannot be null
        refName - the given ref name, cannot be null
        load - true if it needed to load rev commit, false if it needed to look up only
        Returns:
        the RevCommit associated with the given ref name, never null
        Throws:
        IOException - if failed to find or load rev commit
      • getRevCommit

        public static org.eclipse.jgit.revwalk.RevCommit getRevCommit​(org.eclipse.jgit.lib.Repository repository,
                                                                      org.eclipse.jgit.revwalk.RevWalk revWalk,
                                                                      String refName,
                                                                      boolean load)
                                                               throws IOException
        Returns a RevCommit for the given ref name.
        Parameters:
        repository - the target Git repository, cannot be null
        revWalk - the RevWalk instance, cannot be null
        refName - the given ref name, cannot be null
        load - true if it needed to load rev commit, false if it needed to look up only
        Returns:
        the RevCommit associated with the given ref name, never null
        Throws:
        IOException - if failed to find or load rev commit
      • buildComparisonScope

        public static ComparisonScope buildComparisonScope​(String projectPath,
                                                           List<FileDiff> diffs,
                                                           IQualifiedNameFilePathConverter filePathConverter,
                                                           boolean isThreeWay)
        Builds a comparison scope according to given diffs.
        Parameters:
        projectPath - the project path relative to repository root, cannot be null
        diffs - the diff entries between compared/merged refs, cannot be null
        filePathConverter - the qualified name file path converter, cannot be null
        isThreeWay - tells whether the comparison is three-way
        Returns:
        the comparison scope, never null
      • findDiffs

        public static List<FileDiff> findDiffs​(org.eclipse.jgit.lib.Repository repository,
                                               org.eclipse.jgit.revwalk.RevCommit mainCommit,
                                               org.eclipse.jgit.revwalk.RevCommit otherCommit,
                                               boolean useIndex,
                                               List<String> pathsToFilter,
                                               org.eclipse.core.runtime.IProgressMonitor monitor)
                                        throws IOException
        Returns file diffs for the main and other commits.
        Parameters:
        repository - the target Git repository, cannot be null
        mainCommit - the main side commit to compare, may be null
        otherCommit - the other side commit to compare, may be null
        useIndex - tells whether to use index for other side
        pathsToFilter - the paths to filter on; paths should be relative to the root of the repository, cannot be null
        monitor - the progress monitor to indicate progress, cannot be null
        Returns:
        the file diffs for the main and other commits, never null
        Throws:
        IOException - if failed to read the Git repository
      • findProjectDiffs

        public static List<FileDiff> findProjectDiffs​(org.eclipse.jgit.lib.Repository repository,
                                                      org.eclipse.jgit.revwalk.RevCommit mainCommit,
                                                      org.eclipse.jgit.revwalk.RevCommit otherCommit,
                                                      boolean useIndex,
                                                      String projectPath,
                                                      List<String> pathsToFilter,
                                                      org.eclipse.core.runtime.IProgressMonitor monitor)
                                               throws IOException
        Returns file diffs for the main and other commits for the given project. Also handles diffs of the deleted files for projects that have been created or updated base on the libraries.
        Parameters:
        repository - the target Git repository, cannot be null
        mainCommit - the main side commit to compare, may be null
        otherCommit - the other side commit to compare, may be null
        useIndex - tells whether to use index for other side
        projectPath - the path to project; the path should be relative to the root of the repository, cannot be null
        pathsToFilter - the paths to filter on; paths should be relative to the root of the repository, cannot be null
        monitor - the progress monitor to indicate progress, cannot be null
        Returns:
        the file diffs for the main and other commits, never null
        Throws:
        IOException - if failed to read the Git repository
      • isV8Project

        public static boolean isV8Project​(Path projectPath)
        Checks whether the project associated with the given path is V8 project.
        Parameters:
        projectPath - the project folder path, cannot be null
        Returns:
        true if the target project is V8 project, false otherwise
      • replaceBackslash

        public static String replaceBackslash​(String path)
        Replaces all backslashes to slashes in the specified path.
        Parameters:
        path - the path to replace backslashes in, cannot be null
        Returns:
        the path with replaced backslashes to slashes, never null
      • getStreamByFileName

        public static InputStream getStreamByFileName​(org.eclipse.jgit.lib.Repository repository,
                                                      org.eclipse.jgit.revwalk.RevCommit revCommit,
                                                      String filePath,
                                                      org.eclipse.core.runtime.IProgressMonitor monitor)
                                               throws IOException,
                                                      org.eclipse.core.runtime.CoreException
        Returns an input stream for the given rev commit and file path.
        Parameters:
        repository - the Git repository, cannot be null
        revCommit - the rev commit, cannot be null
        filePath - the relative file path the input stream to get for, cannot be null
        monitor - the progress monitor to indicate progress, may be null
        Returns:
        the input stream, may be null
        Throws:
        IOException - if an error occurs
        org.eclipse.core.runtime.CoreException - if the contents of this storage could not be accessed
      • getStreamByFileNameFromIndex

        public static InputStream getStreamByFileNameFromIndex​(org.eclipse.jgit.lib.Repository repository,
                                                               String filePath,
                                                               org.eclipse.core.runtime.IProgressMonitor monitor)
                                                        throws org.eclipse.core.runtime.CoreException
        Returns an input stream for the given file path from the Git index.
        Parameters:
        repository - the Git repository, cannot be null
        filePath - the relative file path the input stream to get for, cannot be null
        monitor - the progress monitor to indicate progress, may be null
        Returns:
        the input stream, may be null
        Throws:
        org.eclipse.core.runtime.CoreException - if the contents of this storage could not be accessed
      • findDeletedProjectPaths

        public static List<String> findDeletedProjectPaths​(List<FileDiff> diffs)
        Finds the deleted project paths from the given collection of diffs.
        Parameters:
        diffs - the collection of diffs, cannot be null
        Returns:
        the list of deleted project paths, never null
      • findAddedProjectPaths

        public static List<String> findAddedProjectPaths​(List<FileDiff> diffs)
        Finds the added project paths from the given collection of diffs.
        Parameters:
        diffs - the collection of diffs, cannot be null
        Returns:
        the list of deleted project paths, never null
      • getCommitShortName

        public static String getCommitShortName​(org.eclipse.jgit.revwalk.RevCommit revCommit)
        Returns commit short name.
        Parameters:
        revCommit - git commit which short name will be returned, can be null
        Returns:
        empty string if commit equals null, commit short name otherwise