Class GitDiffer
java.lang.Object
org.variantsync.diffdetective.diff.git.GitDiffer
This class creates a GitDiff-object from a git repository (Git-object).
The commits from the repository are first filtered using the given DiffFilter. Then a CommitDiff is created for each commit. File changes in each commit are filtered using the given DiffFilter. 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
Modifier and TypeFieldDescriptionprivate static final Pattern
private static final Pattern
private static final Pattern
private final DiffFilter
private final org.eclipse.jgit.api.Git
private static final Pattern
private static final Pattern
private final PatchDiffParseOptions
-
Constructor Summary
ConstructorDescriptionGitDiffer
(Repository repository) Create a differ operating on the given repository. -
Method Summary
Modifier and TypeMethodDescriptioncreateCommitDiff
(String commitHash) static CommitDiffResult
createCommitDiff
(org.eclipse.jgit.api.Git git, DiffFilter diffFilter, org.eclipse.jgit.revwalk.RevCommit parentCommit, org.eclipse.jgit.revwalk.RevCommit childCommit, PatchDiffParseOptions parseOptions) Creates a CommitDiff that describes all changes made by the given childCommit to the given parentCommit.createCommitDiff
(org.eclipse.jgit.revwalk.RevCommit revCommit) static CommitDiffResult
createCommitDiffFromFirstParent
(org.eclipse.jgit.api.Git git, DiffFilter diffFilter, org.eclipse.jgit.revwalk.RevCommit currentCommit, PatchDiffParseOptions parseOptions) Creates a CommitDiff from a given commit.static CommitDiffResult
createWorkingTreeDiff
(org.eclipse.jgit.api.Git git, DiffFilter diffFilter, org.eclipse.jgit.revwalk.RevCommit commit, PatchDiffParseOptions parseOptions) The same ascreateCommitDiff(Git, DiffFilter, RevCommit, RevCommit, PatchDiffParseOptions)
but diffs the given commit against the current working tree.static BufferedReader
getBeforeFullFile
(org.eclipse.jgit.api.Git git, org.eclipse.jgit.revwalk.RevCommit commit, String filename) Gets the full content of a file before a commit.org.eclipse.jgit.revwalk.RevCommit
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.org.eclipse.jgit.api.Git
Returns the internal representation of this differs repository.private static CommitDiffResult
getPatchDiffs
(org.eclipse.jgit.api.Git git, DiffFilter diffFilter, PatchDiffParseOptions parseOptions, 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.private org.variantsync.functjonal.iteration.Yield<org.eclipse.jgit.revwalk.RevCommit>
yieldAllValidIn
(Iterator<org.eclipse.jgit.revwalk.RevCommit> commitsIterator) Filters all undesired commits from the given set of commits using theDiffFilter
of this differs repository.org.variantsync.functjonal.iteration.Yield<org.eclipse.jgit.revwalk.RevCommit>
Returns all commits in the repository's history.org.variantsync.functjonal.iteration.Yield<org.eclipse.jgit.revwalk.RevCommit>
yieldRevCommitsAfter
(Function<org.eclipse.jgit.revwalk.RevCommit, org.eclipse.jgit.revwalk.RevCommit> f) The same asyieldRevCommits()
but applies the given function f to each commit before returning it.
-
Field Details
-
BOM_PATTERN
-
DIFF_HUNK_PATTERN
-
GIT_HEADER_PATTERN
-
DIFF_HEADER_PATTERN
-
NO_NEWLINE_PATTERN
-
git
private final org.eclipse.jgit.api.Git git -
diffFilter
-
parseOptions
-
-
Constructor Details
-
GitDiffer
Create a differ operating on the given repository.- Parameters:
repository
- The repository for whose history to obtain diffs.
-
-
Method Details
-
yieldRevCommits
public org.variantsync.functjonal.iteration.Yield<org.eclipse.jgit.revwalk.RevCommit> yieldRevCommits()Returns all commits in the repository's history. -
yieldRevCommitsAfter
public org.variantsync.functjonal.iteration.Yield<org.eclipse.jgit.revwalk.RevCommit> yieldRevCommitsAfter(Function<org.eclipse.jgit.revwalk.RevCommit, org.eclipse.jgit.revwalk.RevCommit> f) The same asyieldRevCommits()
but applies the given function f to each commit before returning it.- Parameters:
f
- A function to map over all commits before they can be accessed. Each returned commit was processed by f exactly once.- Returns:
- All commits in the repository's history after applying the given function to each commit.
-
yieldAllValidIn
private org.variantsync.functjonal.iteration.Yield<org.eclipse.jgit.revwalk.RevCommit> yieldAllValidIn(Iterator<org.eclipse.jgit.revwalk.RevCommit> commitsIterator) Filters all undesired commits from the given set of commits using theDiffFilter
of this differs repository.- Parameters:
commitsIterator
- Commits to filter.- Returns:
- All commits from the given set that should not be filtered.
- See Also:
-
getCommit
- Throws:
IOException
-
createCommitDiff
- Throws:
IOException
-
createCommitDiff
-
createCommitDiffFromFirstParent
public static CommitDiffResult createCommitDiffFromFirstParent(org.eclipse.jgit.api.Git git, DiffFilter diffFilter, org.eclipse.jgit.revwalk.RevCommit currentCommit, PatchDiffParseOptions parseOptions) 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.- Parameters:
git
- The git repo which the commit stems from.currentCommit
- The commit from which to create a CommitDiffparseOptions
-- Returns:
- The CommitDiff of the given commit
-
createCommitDiff
public static CommitDiffResult createCommitDiff(org.eclipse.jgit.api.Git git, DiffFilter diffFilter, org.eclipse.jgit.revwalk.RevCommit parentCommit, org.eclipse.jgit.revwalk.RevCommit childCommit, PatchDiffParseOptions parseOptions) Creates a CommitDiff that describes all changes made by the given childCommit to the given parentCommit.- Parameters:
git
- The git repo which the commits stem from.- Returns:
- The CommitDiff describing all changes between the two commits.
-
createWorkingTreeDiff
public static CommitDiffResult createWorkingTreeDiff(org.eclipse.jgit.api.Git git, DiffFilter diffFilter, org.eclipse.jgit.revwalk.RevCommit commit, PatchDiffParseOptions parseOptions) The same ascreateCommitDiff(Git, DiffFilter, RevCommit, RevCommit, PatchDiffParseOptions)
but diffs the given commit against the current working tree.- Parameters:
git
- The git repo which the commit stems fromcommit
- The commit which the working tree is compared withparseOptions
-PatchDiffParseOptions
- Returns:
- The CommitDiff of the given commit
-
getPatchDiffs
private static CommitDiffResult getPatchDiffs(org.eclipse.jgit.api.Git git, DiffFilter diffFilter, PatchDiffParseOptions parseOptions, 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.- Parameters:
git
- The git repo which the commit stems fromdiffFilter
-DiffFilter
parseOptions
-PatchDiffParseOptions
prevTreeParser
- 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(org.eclipse.jgit.api.Git git, org.eclipse.jgit.revwalk.RevCommit commit, String filename) throws IOException Gets the full content of a file before a commit.- Parameters:
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
-
getJGitRepo
public org.eclipse.jgit.api.Git getJGitRepo()Returns the internal representation of this differs repository.
-