本文整理匯總了Java中org.eclipse.jgit.diff.DiffFormatter.scan方法的典型用法代碼示例。如果您正苦於以下問題:Java DiffFormatter.scan方法的具體用法?Java DiffFormatter.scan怎麽用?Java DiffFormatter.scan使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jgit.diff.DiffFormatter
的用法示例。
在下文中一共展示了DiffFormatter.scan方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fillLastModifiedCommits
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private void fillLastModifiedCommits(ObjectId start, String basePath) throws IOException, GitAPIException {
Map<String, ObjectId> objects = lastModifiedCommits.get(start);
if (objects == null) {
objects = new TreeMap<>();
}
DiffFormatter diffFmt = new DiffFormatter(NullOutputStream.INSTANCE);
diffFmt.setRepository(getGitRepository());
LogCommand log = new Git(getGitRepository()).log();
if (!basePath.isEmpty()) {
log.addPath(basePath);
}
for(RevCommit c: log.call()) {
final RevTree a = c.getParentCount() > 0 ? c.getParent(0).getTree() : null;
final RevTree b = c.getTree();
for(DiffEntry diff: diffFmt.scan(a, b)) {
objects.put(diff.getNewPath(), c.getId());
}
}
lastModifiedCommits.put(start, objects);
}
示例2: 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;
}
示例3: getScmItems
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
/**
* Get list of files in given revision.
*
* @param revCommit rev commit instance
* @param filePath optional value to filter list of changed files
* @return list of files in given revision
* @throws IOException
*/
public ArrayList<ScmItem> getScmItems(RevCommit revCommit, String filePath) {
try (RevWalk rw = new RevWalk(repository)) {
ArrayList<ScmItem> rez = new ArrayList<>();
if (revCommit != null) {
final DiffFormatter df = getDiffFormatter(filePath);
final List<DiffEntry> diffs;
try {
diffs = df.scan(
revCommit.getParentCount() > 0 ? rw.parseCommit(revCommit.getParent(0).getId()).getTree() : null,
revCommit.getTree());
diffs.stream()
.map(this::adaptDiffEntry)
.collect(Collectors.toCollection(() -> rez));
} catch (IOException e) {
log.log(Level.SEVERE, "Cannot collect items from rev commit", e);
}
}
rw.dispose();
return rez;
}
}
示例4: isInPath
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private boolean isInPath(Repository repository, RevWalk walk, RevCommit commit) throws IOException {
if (commit.getParentCount() == 0) {
RevTree tree = commit.getTree();
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(pathFilter);
return treeWalk.next();
}
} else {
DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE);
df.setRepository(repository);
df.setPathFilter(pathFilter);
RevCommit parent = walk.parseCommit(commit.getParent(0).getId());
List<DiffEntry> diffs = df.scan(parent.getTree(), commit.getTree());
return !diffs.isEmpty();
}
}
示例5: emptyToCommit
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
/**
* Show changes between specified revision and empty 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> emptyToCommit(String commitId, DiffFormatter formatter)
throws IOException {
ObjectId commit = repository.resolve(commitId);
checkArgument(commit != null, "Invalid commit id " + commitId);
RevTree tree;
try (RevWalk revWalkA = new RevWalk(repository)) {
tree = revWalkA.parseTree(commit);
}
List<DiffEntry> diff;
try (ObjectReader reader = repository.newObjectReader()) {
CanonicalTreeParser iterator = new CanonicalTreeParser();
iterator.reset(reader, tree);
diff = formatter.scan(new EmptyTreeIterator(), iterator);
}
return diff;
}
示例6: 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;
}
示例7: addCommitParents
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
private void addCommitParents(final RevWalk rw, final DiffFormatter df, final RevCommit revCommit, final GitCommit gitCommit) throws IOException {
for (int i = 0; i < revCommit.getParentCount(); i++) {
ObjectId parentId = revCommit.getParent(i).getId();
RevCommit parent = rw.parseCommit(parentId);
List<DiffEntry> diffs = df.scan(parent.getTree(), revCommit.getTree());
for (DiffEntry diff : diffs) {
final GitChange gitChange = new GitChange(
diff.getChangeType().name(),
diff.getOldPath(),
diff.getNewPath()
);
logger.debug(gitChange.toString());
gitCommit.getGitChanges().add(gitChange);
}
String parentSha = ObjectId.toString(parentId);
final GitCommit parentCommit = retrieveCommit(parentSha);
gitCommit.getParents().add(parentCommit);
}
}
示例8: 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();
}
}
}
});
}
示例9: 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;
}
示例10: saveDiff
import org.eclipse.jgit.diff.DiffFormatter; //導入方法依賴的package包/類
/**
* Save given fileName at tree/revision into output stream.
*
* @param treeName tree name
* @param revisionName revision name
* @param fileName file name in repository
* @return absolute path to saved diff file
*/
public String saveDiff(String treeName, String revisionName,
String fileName) throws Exception {
final File temp = File.createTempFile(Const.TEMP_FILE_PREFIX, Const.DIFF_EXTENSION);
GitRepositoryService.deleteOnExit(temp);
try (Git git = new Git(repository);
RevWalk rw = new RevWalk(repository);
OutputStream outputStream = new FileOutputStream(temp)) {
final LogCommand cmd = git.log()
.add(repository.resolve(treeName))
.setRevFilter(new SingleRevisionFilter(revisionName))
.addPath(fileName);
final Iterable<RevCommit> revCommits = cmd.call();
final RevCommit revCommit = revCommits.iterator().next();
if (revCommit != null) {
final DiffFormatter df = getDiffFormatter(fileName);
final List<DiffEntry> diffs = df.scan(
revCommit.getParentCount() > 0 ? rw.parseCommit(revCommit.getParent(0).getId()).getTree() : null,
revCommit.getTree());
final DiffEntry diffEntry = diffs.get(0);
try (DiffFormatter formatter = new DiffFormatter(outputStream)) {
formatter.setRepository(repository);
formatter.format(diffEntry);
}
}
rw.dispose();
}
return temp.getAbsolutePath();
}
示例11: 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());
}
示例12: 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;
}
示例13: 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;
}
示例14: 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;
}
示例15: 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);
}