use of org.eclipse.jgit.diff.DiffEntry in project jphp by jphp-compiler.
the class WrapGit method diff.
@Signature
public Memory diff(ArrayMemory settings) throws GitAPIException {
DiffCommand command = getWrappedObject().diff();
if (settings != null) {
command.setCached(settings.valueOfIndex("cached").toBoolean());
Memory contextLines = settings.valueOfIndex("contextLines");
if (contextLines.isNotNull()) {
command.setContextLines(contextLines.toInteger());
}
Memory destPrefix = settings.valueOfIndex("destPrefix");
if (destPrefix.isNotNull()) {
command.setDestinationPrefix(destPrefix.toString());
}
Memory sourcePrefix = settings.valueOfIndex("sourcePrefix");
if (sourcePrefix.isNotNull()) {
command.setSourcePrefix(sourcePrefix.toString());
}
command.setShowNameAndStatusOnly(settings.valueOfIndex("showNameAndStatusOnly").toBoolean());
Memory pathFilter = settings.valueOfIndex("pathFilter");
if (pathFilter.isNotNull()) {
command.setPathFilter(PathFilter.create(pathFilter.toString()));
}
}
List<DiffEntry> call = command.call();
return GitUtils.valueOfDiffEntries(call);
}
use of org.eclipse.jgit.diff.DiffEntry in project curiostack by curioswitch.
the class CurioGenericCiPlugin method computeAffectedFiles.
private static Set<String> computeAffectedFiles(Git git, CanonicalTreeParser oldTreeParser, CanonicalTreeParser newTreeParser) {
final List<DiffEntry> diffs;
try {
diffs = git.diff().setNewTree(newTreeParser).setOldTree(oldTreeParser).setShowNameAndStatusOnly(true).call();
} catch (GitAPIException e) {
throw new IllegalStateException(e);
}
Set<String> affectedRelativePaths = new HashSet<>();
for (DiffEntry diff : diffs) {
switch(diff.getChangeType()) {
case ADD:
case MODIFY:
case COPY:
affectedRelativePaths.add(diff.getNewPath());
break;
case DELETE:
affectedRelativePaths.add(diff.getOldPath());
break;
case RENAME:
affectedRelativePaths.add(diff.getNewPath());
affectedRelativePaths.add(diff.getOldPath());
break;
}
}
return affectedRelativePaths.stream().filter(path -> !IGNORED_ROOT_FILES.contains(path)).collect(toImmutableSet());
}
use of org.eclipse.jgit.diff.DiffEntry in project egit by eclipse.
the class GitHistoryPage method createFollowFilter.
private FollowFilter createFollowFilter(String path, DiffConfig diffConfig) {
FollowFilter followFilter = FollowFilter.create(path, diffConfig);
followFilter.setRenameCallback(new RenameCallback() {
@Override
public void renamed(DiffEntry entry) {
renameTracker.getCallback().renamed(entry);
if (fileViewerInterestingPaths != null) {
fileViewerInterestingPaths.add(entry.getOldPath());
fileViewerInterestingPaths.add(entry.getNewPath());
}
}
});
return followFilter;
}
use of org.eclipse.jgit.diff.DiffEntry in project egit by eclipse.
the class CreatePatchOperation method execute.
@Override
public void execute(IProgressMonitor monitor) throws CoreException {
try (final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final DiffFormatter diffFmt = createDiffFormatter(outputStream, monitor)) {
diffFmt.setContext(contextLines);
final StringBuilder sb = new StringBuilder();
if (headerFormat != null && headerFormat != DiffHeaderFormat.NONE) {
writeGitPatchHeader(sb);
}
diffFmt.setRepository(repository);
diffFmt.setPathFilter(pathFilter);
if (commit != null) {
List<DiffEntry> diffs = diffFmt.scan(getParentId(), commit.getId());
for (DiffEntry ent : diffs) {
String path;
if (ChangeType.DELETE.equals(ent.getChangeType())) {
path = ent.getOldPath();
} else {
path = ent.getNewPath();
}
currentEncoding = CompareCoreUtils.getResourceEncoding(repository, path);
diffFmt.format(ent);
}
} else {
diffFmt.format(new DirCacheIterator(repository.readDirCache()), new FileTreeIterator(repository));
}
diffFmt.flush();
appendOutputStream(sb, outputStream);
if (DiffHeaderFormat.WORKSPACE == headerFormat) {
updateWorkspacePatchPrefixes(sb, diffFmt);
}
patchContent = sb.toString();
} catch (IOException e) {
Activator.logError(CoreText.CreatePatchOperation_patchFileCouldNotBeWritten, e);
}
}
use of org.eclipse.jgit.diff.DiffEntry in project egit by eclipse.
the class BlameRevision method calculateDiffToParent.
private Diff calculateDiffToParent(RevCommit parentCommit) {
try (ObjectReader reader = repository.newObjectReader()) {
DiffEntry diffEntry = CompareCoreUtils.getChangeDiffEntry(repository, sourcePath, commit, parentCommit, reader);
if (diffEntry == null)
return null;
RawText oldText = readText(diffEntry.getOldId(), reader);
RawText newText = readText(diffEntry.getNewId(), reader);
StoredConfig config = repository.getConfig();
DiffAlgorithm diffAlgorithm = DiffAlgorithm.getAlgorithm(config.getEnum(ConfigConstants.CONFIG_DIFF_SECTION, null, ConfigConstants.CONFIG_KEY_ALGORITHM, SupportedAlgorithm.HISTOGRAM));
EditList editList = diffAlgorithm.diff(RawTextComparator.DEFAULT, oldText, newText);
return new Diff(diffEntry.getOldPath(), oldText, newText, editList);
} catch (IOException e) {
return null;
}
}
Aggregations