Package com._1c.g5.v8.dt.compare.git
Class GitCompareUtils
- java.lang.Object
-
- com._1c.g5.v8.dt.compare.git.GitCompareUtils
-
public final class GitCompareUtils extends Object
Utility class to Git infrastructure and the EDT mechanism of comparison and merge.
-
-
Field Summary
Fields Modifier and Type Field Description static int
COMMIT_HASH_PREFIX_LENGTH
The prefix length of commit hash.static String
INDEX
The index revision identifier.
-
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 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 aRevCommit
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 aRevCommit
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
-
INDEX
public static final String INDEX
The index revision identifier.- See Also:
- Constant Field Values
-
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 benull
secondCommit
- the second commit, cannot benull
revWalk
- theRevWalk
instance, cannot benull
- 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 aRevCommit
for the given ref name.- Parameters:
repository
- the target Git repository, cannot benull
refName
- the given ref name, cannot benull
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, nevernull
- 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 aRevCommit
for the given ref name.- Parameters:
repository
- the target Git repository, cannot benull
revWalk
- theRevWalk
instance, cannot benull
refName
- the given ref name, cannot benull
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, nevernull
- 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 benull
diffs
- the diff entries between compared/merged refs, cannot benull
filePathConverter
- the qualified name file path converter, cannot benull
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 benull
mainCommit
- the main side commit to compare, may benull
otherCommit
- the other side commit to compare, may benull
useIndex
- tells whether to use index for other sidepathsToFilter
- the paths to filter on; paths should be relative to the root of the repository, cannot benull
monitor
- the progress monitor to indicate progress, cannot benull
- 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 benull
- 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 benull
- 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 benull
revCommit
- the rev commit, cannot benull
filePath
- the relative file path the input stream to get for, cannot benull
monitor
- the progress monitor to indicate progress, may benull
- Returns:
- the input stream, may be
null
- Throws:
IOException
- if an error occursorg.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 benull
filePath
- the relative file path the input stream to get for, cannot benull
monitor
- the progress monitor to indicate progress, may benull
- 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 benull
- 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 benull
- 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 benull
- Returns:
- empty string if commit equals
null
, commit short name otherwise
-
-