Search in sources :

Example 46 with DiffEntry

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);
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) Memory(php.runtime.Memory) DiffEntry(org.eclipse.jgit.diff.DiffEntry) Signature(php.runtime.annotation.Reflection.Signature)

Example 47 with DiffEntry

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());
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) CanonicalTreeParser(org.eclipse.jgit.treewalk.CanonicalTreeParser) JavaPlugin(org.gradle.api.plugins.JavaPlugin) Function(java.util.function.Function) HashSet(java.util.HashSet) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Task(org.gradle.api.Task) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Path(java.nio.file.Path) ImmutableSet(com.google.common.collect.ImmutableSet) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Project(org.gradle.api.Project) Set(java.util.Set) IOException(java.io.IOException) Constants(org.eclipse.jgit.lib.Constants) Collectors(java.util.stream.Collectors) RevTree(org.eclipse.jgit.revwalk.RevTree) ObjectId(org.eclipse.jgit.lib.ObjectId) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Paths(java.nio.file.Paths) Ref(org.eclipse.jgit.lib.Ref) Git(org.eclipse.jgit.api.Git) DiffEntry(org.eclipse.jgit.diff.DiffEntry) Collections(java.util.Collections) ObjectReader(org.eclipse.jgit.lib.ObjectReader) Plugin(org.gradle.api.Plugin) DiffEntry(org.eclipse.jgit.diff.DiffEntry) HashSet(java.util.HashSet)

Example 48 with DiffEntry

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;
}
Also used : FollowFilter(org.eclipse.jgit.revwalk.FollowFilter) RenameCallback(org.eclipse.jgit.revwalk.RenameCallback) DiffEntry(org.eclipse.jgit.diff.DiffEntry)

Example 49 with DiffEntry

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);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) DirCacheIterator(org.eclipse.jgit.dircache.DirCacheIterator) IOException(java.io.IOException) DiffFormatter(org.eclipse.jgit.diff.DiffFormatter) FileTreeIterator(org.eclipse.jgit.treewalk.FileTreeIterator) DiffEntry(org.eclipse.jgit.diff.DiffEntry)

Example 50 with DiffEntry

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;
    }
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) DiffAlgorithm(org.eclipse.jgit.diff.DiffAlgorithm) ObjectReader(org.eclipse.jgit.lib.ObjectReader) EditList(org.eclipse.jgit.diff.EditList) IOException(java.io.IOException) RawText(org.eclipse.jgit.diff.RawText) DiffEntry(org.eclipse.jgit.diff.DiffEntry)

Aggregations

DiffEntry (org.eclipse.jgit.diff.DiffEntry)66 RevCommit (org.eclipse.jgit.revwalk.RevCommit)24 RevWalk (org.eclipse.jgit.revwalk.RevWalk)23 DiffFormatter (org.eclipse.jgit.diff.DiffFormatter)22 ObjectReader (org.eclipse.jgit.lib.ObjectReader)21 CanonicalTreeParser (org.eclipse.jgit.treewalk.CanonicalTreeParser)20 IOException (java.io.IOException)19 Git (org.eclipse.jgit.api.Git)18 ObjectId (org.eclipse.jgit.lib.ObjectId)15 ArrayList (java.util.ArrayList)14 File (java.io.File)13 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)12 RevTree (org.eclipse.jgit.revwalk.RevTree)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 Path (java.nio.file.Path)8 Test (org.junit.Test)8 FileTreeIterator (org.eclipse.jgit.treewalk.FileTreeIterator)7 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)7 Ref (org.eclipse.jgit.lib.Ref)6 Repository (org.eclipse.jgit.lib.Repository)6