本文整理匯總了Java中org.eclipse.jgit.diff.DiffFormatter.setDetectRenames方法的典型用法代碼示例。如果您正苦於以下問題:Java DiffFormatter.setDetectRenames方法的具體用法?Java DiffFormatter.setDetectRenames怎麽用?Java DiffFormatter.setDetectRenames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jgit.diff.DiffFormatter
的用法示例。
在下文中一共展示了DiffFormatter.setDetectRenames方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPaths
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private List<DiffEntry> getPaths(Repository repository, RevCommit rev)
throws MissingObjectException, IncorrectObjectTypeException,
IOException {
RevCommit parent = null;
List<DiffEntry> diffs = null;
RevWalk rw = new RevWalk(repository);
DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
df.setRepository(repository);
df.setDiffComparator(RawTextComparator.DEFAULT);
df.setDetectRenames(true);
if (rev.getParentCount() > 0 && rev.getParent(0) != null) {
parent = rw.parseCommit(rev.getParent(0).getId());
diffs = df.scan(parent.getTree(), rev.getTree());
} else {
diffs = df.scan(new EmptyTreeIterator(), new CanonicalTreeParser(
null, rw.getObjectReader(), rev.getTree()));
}
return diffs;
}
示例2: listFilesChangedInCommit
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private HashSet<String> listFilesChangedInCommit(Repository repository, AnyObjectId beforeID, AnyObjectId afterID) throws MissingObjectException, IncorrectObjectTypeException, IOException
{
log.info("calculating files changed in commit");
HashSet<String> result = new HashSet<>();
RevWalk rw = new RevWalk(repository);
RevCommit commitBefore = rw.parseCommit(beforeID);
RevCommit commitAfter = rw.parseCommit(afterID);
DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
df.setRepository(repository);
df.setDiffComparator(RawTextComparator.DEFAULT);
df.setDetectRenames(true);
List<DiffEntry> diffs = df.scan(commitBefore.getTree(), commitAfter.getTree());
for (DiffEntry diff : diffs)
{
result.add(diff.getNewPath());
}
log.debug("Files changed between commits commit: {} and {} - {}", beforeID.getName(), afterID, result);
return result;
}
示例3: formatHtmlDiff
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private void formatHtmlDiff(OutputStream out,
Repository repo, RevWalk walk,
AbstractTreeIterator oldTree, AbstractTreeIterator newTree,
String path)
throws IOException {
DiffFormatter diff = new HtmlDiffFormatter(renderer, out);
try {
if (!path.equals("")) {
diff.setPathFilter(PathFilter.create(path));
}
diff.setRepository(repo);
diff.setDetectRenames(true);
diff.format(oldTree, newTree);
} finally {
diff.release();
}
}
示例4: testDiffRenameDetectionProblem
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
public void testDiffRenameDetectionProblem () throws Exception {
File file = new File(workDir, "file");
File renamed = new File(workDir, "renamed");
File patchFile = new File(workDir.getParentFile(), "diff.patch");
write(file, "hey, i will be renamed\n");
add(file);
commit(file);
file.renameTo(renamed);
write(renamed, "hey, i will be renamed\nand now i am\n");
OutputStream out = new BufferedOutputStream(new FileOutputStream(patchFile));
DiffFormatter formatter = new DiffFormatter(out);
formatter.setRepository(repository);
ObjectReader or = null;
try {
formatter.setDetectRenames(true);
AbstractTreeIterator firstTree = new DirCacheIterator(repository.readDirCache());;
AbstractTreeIterator secondTree = new FileTreeIterator(repository);
formatter.format(firstTree, secondTree);
formatter.flush();
fail("Fixed in JGit, modify and simplify the sources in ExportDiff command");
} catch (IOException ex) {
assertEquals("Missing blob 7b34a309b8dbae2686c9e597efef28a612e48aff", ex.getMessage());
} finally {
if (or != null) {
or.release();
}
formatter.release();
}
}
示例5: generatePatches
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
public void generatePatches() throws Exception {
git.add().addFilepattern(".").call();
git.commit().setMessage("generate patches").call();
DiffFormatter formatter = new DiffFormatter(null);
formatter.setRepository(git.getRepository());
formatter.setDiffComparator(RawTextComparator.DEFAULT);
formatter.setDetectRenames(true);
List<DiffEntry> entries = formatter.scan(getSrcCommit().getTree(), getHead());
getChangedFiles().forEach((path) -> {
for (DiffEntry entry : entries) {
Path diffPath = Paths.get(entry.getPath(DiffEntry.Side.NEW));
if (diffPath.equals(path)) {
File patchFile = new File(this.patchDirectory, diffPath.getFileName() + ".patch");
try {
DiffFormatter diffFormatter = new DiffFormatter(new FileOutputStream
(patchFile));
diffFormatter.setRepository(git.getRepository());
diffFormatter.setDiffComparator(RawTextComparator.DEFAULT);
diffFormatter.setContext(3);
diffFormatter.format(entry);
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
}
示例6: getChangedFiles
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
public List<Path> getChangedFiles() throws IOException {
List<Path> changedFiles = new ArrayList<>();
RevWalk revWalk = new RevWalk(git.getRepository());
AnyObjectId headId = git.getRepository().resolve(Constants.HEAD);
RevCommit head = revWalk.parseCommit(headId);
DiffFormatter formatter = new DiffFormatter(null);
formatter.setRepository(git.getRepository());
formatter.setDiffComparator(RawTextComparator.DEFAULT);
formatter.setDetectRenames(true);
List<DiffEntry> entries = formatter.scan(getSrcCommit().getTree(), head);
entries.forEach((diffEntry -> changedFiles.add(Paths.get(diffEntry.getPath(DiffEntry.Side.NEW)))));
return changedFiles;
}
示例7: createDiffFormatter
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
protected static DiffFormatter createDiffFormatter(Repository r, OutputStream buffer) {
DiffFormatter formatter = new DiffFormatter(buffer);
formatter.setRepository(r);
formatter.setDiffComparator(RawTextComparator.DEFAULT);
formatter.setDetectRenames(true);
return formatter;
}
示例8: getDiffFormatter
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
/**
* Get diff formatter.
*
* @param filePath optional filter for diff
* @return diff formater
*/
private DiffFormatter getDiffFormatter(String filePath) {
final DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
df.setRepository(repository);
df.setDiffComparator(RawTextComparator.DEFAULT);
df.setDetectRenames(true);
if (filePath != null) {
df.setPathFilter(PathFilter.create(filePath));
}
return df;
}
示例9: walkFilesInCommit
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private void walkFilesInCommit(
Git gitClient,
RevCommit commit,
List<SourceCodeFileAnalyzerPlugin> analyzers,
MetricsProcessor metricsProcessor)
throws IOException {
commit = CommitUtils.getCommit(gitClient.getRepository(), commit.getId());
logger.info("starting analysis of commit {}", commit.getName());
DiffFormatter diffFormatter = new DiffFormatter(DisabledOutputStream.INSTANCE);
diffFormatter.setRepository(gitClient.getRepository());
diffFormatter.setDiffComparator(RawTextComparator.DEFAULT);
diffFormatter.setDetectRenames(true);
ObjectId parentId = null;
if (commit.getParentCount() > 0) {
// TODO: support multiple parents
parentId = commit.getParent(0).getId();
}
List<DiffEntry> diffs = diffFormatter.scan(parentId, commit);
for (DiffEntry diff : diffs) {
String filePath = diff.getPath(DiffEntry.Side.NEW);
byte[] fileContent =
BlobUtils.getRawContent(gitClient.getRepository(), commit.getId(), filePath);
FileMetrics metrics = fileAnalyzer.analyzeFile(analyzers, filePath, fileContent);
FileMetricsWithChangeType metricsWithChangeType =
new FileMetricsWithChangeType(
metrics, changeTypeMapper.jgitToCoderadar(diff.getChangeType()));
metricsProcessor.processMetrics(metricsWithChangeType, gitClient, commit.getId(), filePath);
}
metricsProcessor.onCommitFinished(gitClient, commit.getId());
}
示例10: indexToWorkingTree
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
/**
* Show changes between index and working tree.
*
* @param formatter diff formatter
* @return list of diff entries
* @throws IOException if any i/o errors occurs
*/
private List<DiffEntry> indexToWorkingTree(DiffFormatter formatter) throws IOException {
DirCache dirCache = null;
ObjectReader reader = repository.newObjectReader();
List<DiffEntry> diff;
try {
dirCache = repository.lockDirCache();
DirCacheIterator iterA = new DirCacheIterator(dirCache);
FileTreeIterator iterB = new FileTreeIterator(repository);
// Seems bug in DiffFormatter when work with working. Disable detect
// renames by formatter and do it later.
formatter.setDetectRenames(false);
diff = formatter.scan(iterA, iterB);
if (!params.isNoRenames()) {
// Detect renames.
RenameDetector renameDetector = createRenameDetector();
ContentSource.Pair sourcePairReader =
new ContentSource.Pair(ContentSource.create(reader), ContentSource.create(iterB));
renameDetector.addAll(diff);
diff = renameDetector.compute(sourcePairReader, NullProgressMonitor.INSTANCE);
}
} finally {
reader.close();
if (dirCache != null) {
dirCache.unlock();
}
}
return diff;
}
示例11: commitToWorkingTree
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
/**
* Show changes between specified revision and working tree.
*
* @param commitId id of commit
* @param formatter diff formatter
* @return list of diff entries
* @throws IOException if any i/o errors occurs
*/
private List<DiffEntry> commitToWorkingTree(String commitId, DiffFormatter formatter)
throws IOException {
ObjectId commitA = repository.resolve(commitId);
if (commitA == null) {
File heads = new File(repository.getWorkTree().getPath() + "/.git/refs/heads");
if (heads.exists() && heads.list().length == 0) {
return Collections.emptyList();
}
throw new IllegalArgumentException("Invalid commit id " + commitId);
}
RevTree treeA;
try (RevWalk revWalkA = new RevWalk(repository)) {
treeA = revWalkA.parseTree(commitA);
}
List<DiffEntry> diff;
try (ObjectReader reader = repository.newObjectReader()) {
CanonicalTreeParser iterA = new CanonicalTreeParser();
iterA.reset(reader, treeA);
FileTreeIterator iterB = new FileTreeIterator(repository);
// Seems bug in DiffFormatter when work with working. Disable detect
// renames by formatter and do it later.
formatter.setDetectRenames(false);
diff = formatter.scan(iterA, iterB);
if (!params.isNoRenames()) {
// Detect renames.
RenameDetector renameDetector = createRenameDetector();
ContentSource.Pair sourcePairReader =
new ContentSource.Pair(ContentSource.create(reader), ContentSource.create(iterB));
renameDetector.addAll(diff);
diff = renameDetector.compute(sourcePairReader, NullProgressMonitor.INSTANCE);
}
}
return diff;
}
示例12: commitToIndex
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
/**
* Show changes between specified revision and index. If <code>commitId == null</code> then view
* changes between HEAD and index.
*
* @param commitId id of commit, pass <code>null</code> is the same as pass HEAD
* @param formatter diff formatter
* @return list of diff entries
* @throws IOException if any i/o errors occurs
*/
private List<DiffEntry> commitToIndex(String commitId, DiffFormatter formatter)
throws IOException {
if (commitId == null) {
commitId = Constants.HEAD;
}
ObjectId commitA = repository.resolve(commitId);
if (commitA == null) {
throw new IllegalArgumentException("Invalid commit id " + commitId);
}
RevTree treeA;
try (RevWalk revWalkA = new RevWalk(repository)) {
treeA = revWalkA.parseTree(commitA);
}
DirCache dirCache = null;
List<DiffEntry> diff;
try (ObjectReader reader = repository.newObjectReader()) {
dirCache = repository.lockDirCache();
CanonicalTreeParser iterA = new CanonicalTreeParser();
iterA.reset(reader, treeA);
DirCacheIterator iterB = new DirCacheIterator(dirCache);
if (!params.isNoRenames()) {
// Use embedded RenameDetector it works well with index and
// revision history.
formatter.setDetectRenames(true);
int renameLimit = params.getRenameLimit();
if (renameLimit > 0) {
formatter.getRenameDetector().setRenameLimit(renameLimit);
}
}
diff = formatter.scan(iterA, iterB);
} finally {
if (dirCache != null) {
dirCache.unlock();
}
}
return diff;
}
示例13: commitToCommit
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
/**
* Show changes between specified two revisions and index. If <code>commitAId == null</code> then
* view changes between HEAD and revision commitBId.
*
* @param commitAId id of commit A, pass <code>null</code> is the same as pass HEAD
* @param commitBId id of commit B
* @param formatter diff formatter
* @return list of diff entries
* @throws IOException if any i/o errors occurs
*/
private List<DiffEntry> commitToCommit(
String commitAId, String commitBId, DiffFormatter formatter) throws IOException {
if (commitAId == null) {
commitAId = Constants.HEAD;
}
ObjectId commitA = repository.resolve(commitAId);
if (commitA == null) {
throw new IllegalArgumentException("Invalid commit id " + commitAId);
}
ObjectId commitB = repository.resolve(commitBId);
if (commitB == null) {
throw new IllegalArgumentException("Invalid commit id " + commitBId);
}
RevTree treeA;
try (RevWalk revWalkA = new RevWalk(repository)) {
treeA = revWalkA.parseTree(commitA);
}
RevTree treeB;
try (RevWalk revWalkB = new RevWalk(repository)) {
treeB = revWalkB.parseTree(commitB);
}
if (!params.isNoRenames()) {
// Use embedded RenameDetector it works well with index and revision
// history.
formatter.setDetectRenames(true);
int renameLimit = params.getRenameLimit();
if (renameLimit > 0) {
formatter.getRenameDetector().setRenameLimit(renameLimit);
}
}
return formatter.scan(treeA, treeB);
}
示例14: getShortMessage
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
public ArrayList<String> getShortMessage() {
for (RevCommit revision : walk) {
shortMessage.add(revision.getShortMessage());
//[LOG] logger.debug(revision.getShortMessage());
DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
df.setRepository(repository);
df.setDiffComparator(RawTextComparator.DEFAULT);
df.setDetectRenames(true);
RevCommit parent = null;
if(revision.getParentCount()!=0) {
try {
parent = walk.parseCommit(revision.getParent(0).getId());
RevTree tree = revision.getTree();
List<DiffEntry> diffs = df.scan(parent.getTree(), revision.getTree());
for (DiffEntry diff : diffs) {
String changeType = diff.getChangeType().name();
if(changeType.equals(ADD)|| changeType.equals(MODIFY))
{
//[LOG] logger.debug(diff.getChangeType().name());
//[LOG] logger.debug(diff.getNewPath());
tempCommitHistory.add(diff.getNewPath());
}
}
}catch (IOException ex) {
//[LOG] logger.debug("IOException", ex);
}
}
commitSHA.add(commitCount,revision.name());
commitHistory.add(commitCount++,new ArrayList<String>(tempCommitHistory));
tempCommitHistory.clear();
}
walk.reset();
return shortMessage;
}
示例15: getChangesForCommitedFiles
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private List<Change> getChangesForCommitedFiles(String hash) throws IOException {
RevWalk revWalk = new RevWalk(git.getRepository());
RevCommit commit = revWalk.parseCommit(ObjectId.fromString(hash));
if (commit.getParentCount() > 1) {
revWalk.close();
return new ArrayList<Change>();
}
RevCommit parentCommit = commit.getParentCount() > 0
? revWalk.parseCommit(ObjectId.fromString(commit.getParent(0).getName()))
: null;
DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
df.setBinaryFileThreshold(2048);
df.setRepository(git.getRepository());
df.setDiffComparator(RawTextComparator.DEFAULT);
df.setDetectRenames(true);
List<DiffEntry> diffEntries = df.scan(parentCommit, commit);
df.close();
revWalk.close();
List<Change> changes = new ArrayList<Change>();
for (DiffEntry entry : diffEntries) {
Change change = new Change(entry.getNewPath(), entry.getOldPath(), 0, 0,
ChangeType.valueOf(entry.getChangeType().name()));
analyzeDiff(change, entry);
changes.add(change);
}
return changes;
}