本文整理匯總了Java中org.eclipse.jgit.diff.DiffFormatter類的典型用法代碼示例。如果您正苦於以下問題:Java DiffFormatter類的具體用法?Java DiffFormatter怎麽用?Java DiffFormatter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DiffFormatter類屬於org.eclipse.jgit.diff包,在下文中一共展示了DiffFormatter類的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: blockingPreviewDiff
import org.eclipse.jgit.diff.DiffFormatter; //導入依賴的package包/類
private Map<String, Change<?>> blockingPreviewDiff(Revision baseRevision, Iterable<Change<?>> changes) {
requireNonNull(baseRevision, "baseRevision");
requireNonNull(changes, "changes");
baseRevision = blockingNormalize(baseRevision);
try (ObjectReader reader = jGitRepository.newObjectReader();
RevWalk revWalk = new RevWalk(reader);
DiffFormatter diffFormatter = new DiffFormatter(NullOutputStream.INSTANCE)) {
final ObjectId baseTreeId = toTreeId(revWalk, baseRevision);
final DirCache dirCache = DirCache.newInCore();
final int numEdits = applyChanges(baseRevision, baseTreeId, dirCache, changes);
if (numEdits == 0) {
return Collections.emptyMap();
}
CanonicalTreeParser p = new CanonicalTreeParser();
p.reset(reader, baseTreeId);
diffFormatter.setRepository(jGitRepository);
List<DiffEntry> result = diffFormatter.scan(p, new DirCacheIterator(dirCache));
return toChangeMap(result);
} catch (IOException e) {
throw new StorageException("failed to perform a dry-run diff", e);
}
}
示例4: 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;
}
}
示例5: 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();
}
}
示例6: 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;
}
示例7: getDiffBetweenCommits
import org.eclipse.jgit.diff.DiffFormatter; //導入依賴的package包/類
public String getDiffBetweenCommits(int commitIndex) throws IOException,GitAPIException{
if(commitIndex+1==commitCount)
return "Nothing to Diff. This is first commit";
AbstractTreeIterator current = prepareTreeParser(repository,commitSHA.get(commitIndex));
AbstractTreeIterator parent = prepareTreeParser(repository,commitSHA.get(++commitIndex));
ObjectReader reader = repository.newObjectReader();
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
// finally get the list of changed files
Git git = new Git(repository) ;
List<DiffEntry> diff = git.diff().
setOldTree(parent).
setNewTree(current).
//TODO Set the path filter to filter out the selected file
//setPathFilter(PathFilter.create("README.md")).
call();
for (DiffEntry entry : diff) {
System.out.println("Entry: " + entry + ", from: " + entry.getOldId() + ", to: " + entry.getNewId());
DiffFormatter formatter = new DiffFormatter(byteStream) ;
formatter.setRepository(repository);
formatter.format(entry);
}
// System.out.println(byteStream.toString());
String diffContent = byteStream.toString();
return byteStream.toString();
}
示例8: diffWhitespaceLineEndings
import org.eclipse.jgit.diff.DiffFormatter; //導入依賴的package包/類
/**
* Returns a git-style diff between the two unix strings.
*
* Output has no trailing newlines.
*
* Boolean args determine whether whitespace or line endings will be visible.
*/
private static String diffWhitespaceLineEndings(String dirty, String clean, boolean whitespace, boolean lineEndings) throws IOException {
dirty = visibleWhitespaceLineEndings(dirty, whitespace, lineEndings);
clean = visibleWhitespaceLineEndings(clean, whitespace, lineEndings);
RawText a = new RawText(dirty.getBytes(StandardCharsets.UTF_8));
RawText b = new RawText(clean.getBytes(StandardCharsets.UTF_8));
EditList edits = new EditList();
edits.addAll(MyersDiff.INSTANCE.diff(RawTextComparator.DEFAULT, a, b));
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (DiffFormatter formatter = new DiffFormatter(out)) {
formatter.format(edits, a, b);
}
String formatted = out.toString(StandardCharsets.UTF_8.name());
// we don't need the diff to show this, since we display newlines ourselves
formatted = formatted.replace("\\ No newline at end of file\n", "");
return NEWLINE_MATCHER.trimTrailingFrom(formatted);
}
示例9: getRelevantPatchListEntries
import org.eclipse.jgit.diff.DiffFormatter; //導入依賴的package包/類
private List<PatchListEntry> getRelevantPatchListEntries(
List<DiffEntry> parentDiffEntries,
RevCommit parentCommitA,
RevCommit parentCommitB,
Set<String> touchedFilePaths,
DiffFormatter diffFormatter)
throws IOException {
List<PatchListEntry> parentPatchListEntries = new ArrayList<>(parentDiffEntries.size());
for (DiffEntry parentDiffEntry : parentDiffEntries) {
if (!isTouched(touchedFilePaths, parentDiffEntry)) {
continue;
}
FileHeader fileHeader = toFileHeader(parentCommitB, diffFormatter, parentDiffEntry);
// The code which uses this PatchListEntry doesn't care about the last three parameters. As
// they are expensive to compute, we use arbitrary values for them.
PatchListEntry patchListEntry =
newEntry(parentCommitA.getTree(), fileHeader, ImmutableSet.of(), 0, 0);
parentPatchListEntries.add(patchListEntry);
}
return parentPatchListEntries;
}
示例10: getPatchListEntry
import org.eclipse.jgit.diff.DiffFormatter; //導入依賴的package包/類
private Optional<PatchListEntry> getPatchListEntry(
ObjectReader objectReader,
DiffFormatter diffFormatter,
DiffEntry diffEntry,
RevTree treeA,
RevTree treeB,
Set<ContextAwareEdit> editsDueToRebase)
throws IOException {
FileHeader fileHeader = toFileHeader(key.getNewId(), diffFormatter, diffEntry);
long oldSize = getFileSize(objectReader, diffEntry.getOldMode(), diffEntry.getOldPath(), treeA);
long newSize = getFileSize(objectReader, diffEntry.getNewMode(), diffEntry.getNewPath(), treeB);
Set<Edit> contentEditsDueToRebase = getContentEdits(editsDueToRebase);
PatchListEntry patchListEntry =
newEntry(treeA, fileHeader, contentEditsDueToRebase, newSize, newSize - oldSize);
// All edits in a file are due to rebase -> exclude the file from the diff.
if (EditTransformer.toEdits(patchListEntry).allMatch(editsDueToRebase::contains)) {
return Optional.empty();
}
return Optional.of(patchListEntry);
}
示例11: getDiffString
import org.eclipse.jgit.diff.DiffFormatter; //導入依賴的package包/類
private String getDiffString() throws GitAPIException, IOException {
ObjectId head = this.repo.resolve("HEAD");
if(head == null) return "";
// The following code is largely written by Tk421 on StackOverflow
// (http://stackoverflow.com/q/23486483)
// Thanks! NOTE: comments are mine.
ByteArrayOutputStream diffOutputStream = new ByteArrayOutputStream();
DiffFormatter formatter = new DiffFormatter(diffOutputStream);
formatter.setRepository(this.repo);
formatter.setPathFilter(PathFilter.create(this.pathFilter.replaceAll("\\\\","/")));
AbstractTreeIterator commitTreeIterator = prepareTreeParser(this.repo, head.getName());
FileTreeIterator workTreeIterator = new FileTreeIterator(this.repo);
// Scan gets difference between the two iterators.
formatter.format(commitTreeIterator, workTreeIterator);
return diffOutputStream.toString();
}
示例12: execute
import org.eclipse.jgit.diff.DiffFormatter; //導入依賴的package包/類
public List<FileDiff> execute() {
final List<FileDiff> diffs = new ArrayList<>();
final List<DiffEntry> result = git.listDiffs(git.getTreeFromRef(this.branchA),
git.getTreeFromRef(this.branchB));
final DiffFormatter formatter = createFormatter();
result.forEach(elem -> {
final FileHeader header = getFileHeader(formatter,
elem);
header.toEditList().forEach(edit -> diffs.add(createFileDiff(elem,
header,
edit)));
});
return diffs;
}
示例13: 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;
}
示例14: getFilesInRange
import org.eclipse.jgit.diff.DiffFormatter; //導入依賴的package包/類
/**
* Returns the list of files changed in a specified commit. If the repository does not exist or is empty, an empty list is returned.
*
* @param repository
* @param startCommit
* earliest commit
* @param endCommit
* most recent commit. if null, HEAD is assumed.
* @return list of files changed in a commit range
*/
public static List<PathChangeModel> getFilesInRange(Repository repository, RevCommit startCommit, RevCommit endCommit) {
List<PathChangeModel> list = new ArrayList<PathChangeModel>();
if (!hasCommits(repository)) {
return list;
}
try (DiffFormatter df = new DiffFormatter(null)) {
df.setRepository(repository);
df.setDiffComparator(RawTextComparator.DEFAULT);
df.setDetectRenames(true);
List<DiffEntry> diffEntries = df.scan(startCommit.getTree(), endCommit.getTree());
for (DiffEntry diff : diffEntries) {
PathChangeModel pcm = PathChangeModel.from(diff, endCommit.getName());
list.add(pcm);
}
Collections.sort(list);
} catch (Throwable t) {
error(t, repository, "{0} failed to determine files in range {1}..{2}!", startCommit, endCommit);
}
return list;
}
示例15: 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);
}
}