Package com.google.gerrit.server.patch
Class DiffUtil
- java.lang.Object
-
- com.google.gerrit.server.patch.DiffUtil
-
public class DiffUtil extends Object
A utility class used by the diff cache interfacesGitModifiedFilesCache
andModifiedFilesCache
.
-
-
Constructor Summary
Constructors Constructor Description DiffUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
areRelated(org.eclipse.jgit.revwalk.RevCommit commitA, org.eclipse.jgit.revwalk.RevCommit commitB)
Returns true if the commitA and commitB parameters are parent/child, if they have a common parent, or if any of them is a root or merge commit.static String
cleanPatch(BinaryResult bin)
static String
cleanPatch(String patch)
static void
getFormattedDiff(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.lib.ObjectReader reader, org.eclipse.jgit.revwalk.RevTree baseTree, org.eclipse.jgit.revwalk.RevTree childTree, String path, OutputStream out)
static void
getFormattedDiff(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevCommit baseCommit, org.eclipse.jgit.revwalk.RevCommit childCommit, String path, OutputStream out)
Get formatted diff between the given commits, either for a single path if specified, or for the full trees.static Optional<String>
getPatchHeader(String patch)
static org.eclipse.jgit.revwalk.RevCommit
getRevCommit(org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.ObjectId commitId)
Returns the RevCommit object given the 20 bytes commitId SHA-1 hash.static org.eclipse.jgit.lib.ObjectId
getTreeId(org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.ObjectId commitId)
Returns the Git tree object ID pointed to by the commitId parameter.static com.google.common.collect.ImmutableList<ModifiedFile>
mergeRewrittenModifiedFiles(List<ModifiedFile> modifiedFiles)
Return themodifiedFiles
input list while merging rewritten entries.static String
removePatchHeader(String patch)
static int
stringSize(String str)
-
-
-
Method Detail
-
mergeRewrittenModifiedFiles
public static com.google.common.collect.ImmutableList<ModifiedFile> mergeRewrittenModifiedFiles(List<ModifiedFile> modifiedFiles)
Return themodifiedFiles
input list while merging rewritten entries.Background: In some cases, JGit returns two diff entries (ADDED/DELETED, RENAMED/DELETED, etc...) for the same file path. This happens e.g. when a file's mode is changed between patchsets, for example converting a symlink file to a regular file. We identify this case and return a single modified file with changeType =
Patch.ChangeType.REWRITE
.
-
getTreeId
public static org.eclipse.jgit.lib.ObjectId getTreeId(org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.ObjectId commitId) throws IOException
Returns the Git tree object ID pointed to by the commitId parameter.- Parameters:
rw
- aRevWalk
of an opened repository that is used to walk the commit graph.commitId
- 20 bytes commitId SHA-1 hash.- Returns:
- Git tree object ID pointed to by the commitId.
- Throws:
IOException
-
getRevCommit
public static org.eclipse.jgit.revwalk.RevCommit getRevCommit(org.eclipse.jgit.revwalk.RevWalk rw, org.eclipse.jgit.lib.ObjectId commitId) throws IOException
Returns the RevCommit object given the 20 bytes commitId SHA-1 hash.- Parameters:
rw
- aRevWalk
of an opened repository that is used to walk the commit graph.commitId
- 20 bytes commitId SHA-1 hash- Returns:
- The RevCommit representing the commit in Git
- Throws:
IOException
- a pack file or loose object could not be read while parsing the commits.
-
areRelated
public static boolean areRelated(org.eclipse.jgit.revwalk.RevCommit commitA, org.eclipse.jgit.revwalk.RevCommit commitB)
Returns true if the commitA and commitB parameters are parent/child, if they have a common parent, or if any of them is a root or merge commit.
-
stringSize
public static int stringSize(String str)
-
getFormattedDiff
public static void getFormattedDiff(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.revwalk.RevCommit baseCommit, org.eclipse.jgit.revwalk.RevCommit childCommit, String path, OutputStream out) throws IOException
Get formatted diff between the given commits, either for a single path if specified, or for the full trees.- Parameters:
repo
- to get the diff frombaseCommit
- to compare withchildCommit
- to comparepath
- to narrow the diff toout
- to append the diff to- Throws:
IOException
- if the diff couldn't be written
-
getFormattedDiff
public static void getFormattedDiff(org.eclipse.jgit.lib.Repository repo, org.eclipse.jgit.lib.ObjectReader reader, org.eclipse.jgit.revwalk.RevTree baseTree, org.eclipse.jgit.revwalk.RevTree childTree, String path, OutputStream out) throws IOException
- Throws:
IOException
-
cleanPatch
public static String cleanPatch(BinaryResult bin) throws IOException
- Throws:
IOException
-
-