Class GitDiffer
java.lang.Object
org.variantsync.diffdetective.diff.git.GitDiffer
This class provides utility functions for obtaining diffs from git
repositories
.
Then a CommitDiff
is created for each commit.
File changes in each commit are filtered using the DiffFilter
of the repository
.
Then a PatchDiff
is created from each file change.
Finally, each patch is parsed to a VariationDiff
.
- Author:
- Soeren Viegener, Paul Maximilian Bittner
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CommitDiffResult
createCommitDiff
(Repository repository, org.eclipse.jgit.revwalk.RevCommit parentCommit, org.eclipse.jgit.revwalk.RevCommit childCommit) Creates a CommitDiff that describes all changes made by the given childCommit to the given parentCommit.static CommitDiffResult
createCommitDiffFromFirstParent
(Repository repository, String commitHash) static CommitDiffResult
createCommitDiffFromFirstParent
(Repository repository, org.eclipse.jgit.revwalk.RevCommit currentCommit) Creates a CommitDiff from a given commit.static CommitDiffResult
createWorkingTreeDiff
(Repository repository, org.eclipse.jgit.revwalk.RevCommit commit) The same ascreateCommitDiff(Repository, RevCommit, RevCommit)
but diffs the given commit against the current working tree.static BufferedReader
getBeforeFullFile
(Repository repository, org.eclipse.jgit.revwalk.RevCommit commit, String filename) Gets the full content of a file before a commit.static String
getFullDiff
(BufferedReader beforeFile, BufferedReader gitDiff) Creates a full git diff from a file before the change and the git diff containing only the changed lines.private static CommitDiffResult
getPatchDiffs
(Repository repository, org.eclipse.jgit.treewalk.AbstractTreeIterator prevTreeParser, org.eclipse.jgit.treewalk.AbstractTreeIterator currentTreeParser, org.eclipse.jgit.revwalk.RevCommit parentCommit, org.eclipse.jgit.revwalk.RevCommit childCommit) Obtains the CommitDiff between two commit's trees.
-
Field Details
-
BOM_PATTERN
-
DIFF_HUNK_PATTERN
-
GIT_HEADER_PATTERN
-
DIFF_HEADER_PATTERN
-
NO_NEWLINE_PATTERN
-
-
Constructor Details
-
GitDiffer
private GitDiffer()
-
-
Method Details
-
createCommitDiffFromFirstParent
public static CommitDiffResult createCommitDiffFromFirstParent(Repository repository, String commitHash) throws IOException - Throws:
IOException
-
createCommitDiffFromFirstParent
public static CommitDiffResult createCommitDiffFromFirstParent(Repository repository, org.eclipse.jgit.revwalk.RevCommit currentCommit) Creates a CommitDiff from a given commit. For this, the git diff is retrieved using JGit. For each file in the diff, a PatchDiff is created.This honors the
diff filter
and theparser options
of the repository.- Parameters:
repository
- The git repo which the commit stems from.currentCommit
- The commit from which to create a CommitDiff- Returns:
- The CommitDiff of the given commit
-
createCommitDiff
public static CommitDiffResult createCommitDiff(Repository repository, org.eclipse.jgit.revwalk.RevCommit parentCommit, org.eclipse.jgit.revwalk.RevCommit childCommit) Creates a CommitDiff that describes all changes made by the given childCommit to the given parentCommit.This honors the
diff filter
and theparser options
of the repository.- Parameters:
repository
- The git repo which the commit stems from.- Returns:
- The CommitDiff describing all changes between the two commits.
-
createWorkingTreeDiff
public static CommitDiffResult createWorkingTreeDiff(Repository repository, org.eclipse.jgit.revwalk.RevCommit commit) The same ascreateCommitDiff(Repository, RevCommit, RevCommit)
but diffs the given commit against the current working tree.- Parameters:
repository
- The git repo which the commit stems fromcommit
- The commit which the working tree is compared with- Returns:
- The CommitDiff of the given commit
-
getPatchDiffs
private static CommitDiffResult getPatchDiffs(Repository repository, org.eclipse.jgit.treewalk.AbstractTreeIterator prevTreeParser, org.eclipse.jgit.treewalk.AbstractTreeIterator currentTreeParser, org.eclipse.jgit.revwalk.RevCommit parentCommit, org.eclipse.jgit.revwalk.RevCommit childCommit) Obtains the CommitDiff between two commit's trees.This honors the
diff filter
and theparser options
of the repository.- Parameters:
repository
- The git repo which the commit stems fromprevTreeParser
- The tree parser for parentCommitcurrentTreeParser
- The tree parser for childCommit or the working treeparentCommit
- TheRevCommit
for the parent commitchildCommit
- TheRevCommit
for the child commit (equal to parentCommit if working tree is requested)- Returns:
CommitDiffResult
-
getFullDiff
Creates a full git diff from a file before the change and the git diff containing only the changed lines.- Parameters:
beforeFile
- The full file before the changegitDiff
- The git diff containing only the changed lines- Returns:
- A full git diff containing the complete file and all changes
-
getBeforeFullFile
public static BufferedReader getBeforeFullFile(Repository repository, org.eclipse.jgit.revwalk.RevCommit commit, String filename) throws IOException Gets the full content of a file before a commit.- Parameters:
repository
- The repository which containscommit
commit
- The commit in which the file was changedfilename
- The name of the file- Returns:
- The full content of the file before the commit
- Throws:
IOException
-