Search in sources :

Example 6 with WorkingTreeIterator

use of org.eclipse.jgit.treewalk.WorkingTreeIterator in project egit by eclipse.

the class IndexDiffCacheEntry method calcIndexDiffDataFull.

private IndexDiffData calcIndexDiffDataFull(IProgressMonitor monitor, String jobName, Repository repository) throws IOException {
    EclipseGitProgressTransformer jgitMonitor = new EclipseGitProgressTransformer(monitor);
    IndexDiff newIndexDiff;
    WorkingTreeIterator iterator = IteratorService.createInitialIterator(repository);
    if (iterator == null)
        // workspace is closed
        return null;
    newIndexDiff = new IndexDiff(repository, Constants.HEAD, iterator);
    newIndexDiff.diff(jgitMonitor, 0, 0, jobName);
    return new IndexDiffData(newIndexDiff);
}
Also used : WorkingTreeIterator(org.eclipse.jgit.treewalk.WorkingTreeIterator) EclipseGitProgressTransformer(org.eclipse.egit.core.EclipseGitProgressTransformer) IndexDiff(org.eclipse.jgit.lib.IndexDiff)

Example 7 with WorkingTreeIterator

use of org.eclipse.jgit.treewalk.WorkingTreeIterator in project egit by eclipse.

the class CommitUI method getIndexDiff.

/**
 * Calculates a fresh {@link IndexDiff} for the given repository.
 *
 * @param repository
 *            to compute the {@link IndexDiff} for
 * @param selectedProjects
 *            of the repository; used to get an estimate for the progress
 *            monitor; may be empty
 * @param monitor
 *            for progress reporting and cancellation
 * @return the {@link IndexDiff}
 * @throws IOException
 *             if an error occurred
 * @throws OperationCanceledException
 *             if the operation was cancelled
 */
public static IndexDiff getIndexDiff(Repository repository, IProject[] selectedProjects, IProgressMonitor monitor) throws IOException, OperationCanceledException {
    SubMonitor progress = SubMonitor.convert(monitor, UIText.CommitActionHandler_calculatingChanges, 1000);
    EclipseGitProgressTransformer jgitMonitor = new EclipseGitProgressTransformer(progress);
    CountingVisitor counter = new CountingVisitor();
    for (IProject p : selectedProjects) {
        try {
            p.accept(counter);
        } catch (CoreException e) {
        // ignore
        }
    }
    WorkingTreeIterator it = IteratorService.createInitialIterator(repository);
    if (it == null) {
        // Workspace is closed
        throw new OperationCanceledException();
    }
    IndexDiff diff = new IndexDiff(repository, Constants.HEAD, it);
    diff.diff(jgitMonitor, counter.count, 0, NLS.bind(UIText.CommitActionHandler_repository, repository.getDirectory().getPath()));
    if (progress.isCanceled()) {
        throw new OperationCanceledException();
    }
    return diff;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) WorkingTreeIterator(org.eclipse.jgit.treewalk.WorkingTreeIterator) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubMonitor(org.eclipse.core.runtime.SubMonitor) EclipseGitProgressTransformer(org.eclipse.egit.core.EclipseGitProgressTransformer) IProject(org.eclipse.core.resources.IProject) IndexDiff(org.eclipse.jgit.lib.IndexDiff)

Example 8 with WorkingTreeIterator

use of org.eclipse.jgit.treewalk.WorkingTreeIterator in project egit by eclipse.

the class IgnoreOperation method pruneFolder.

private void pruneFolder(IPath folder, Collection<String> files, IProgressMonitor monitor) throws IOException {
    if (files.isEmpty()) {
        return;
    }
    Repository repository = Activator.getDefault().getRepositoryCache().getRepository(folder);
    if (repository == null || repository.isBare()) {
        files.clear();
        return;
    }
    WorkingTreeIterator treeIterator = IteratorService.createInitialIterator(repository);
    if (treeIterator == null) {
        files.clear();
        return;
    }
    IPath repoRelativePath = folder.makeRelativeTo(new Path(repository.getWorkTree().getAbsolutePath()));
    if (repoRelativePath.equals(folder)) {
        files.clear();
        return;
    }
    Collection<String> repoRelative = new HashSet<>(files.size());
    for (String file : files) {
        repoRelative.add(repoRelativePath.append(file).toPortableString());
    }
    // Remove all entries,then re-add only those found during the tree walk
    // that are not ignored already
    files.clear();
    try (TreeWalk walk = new TreeWalk(repository)) {
        walk.addTree(treeIterator);
        walk.setFilter(PathFilterGroup.createFromStrings(repoRelative));
        while (walk.next()) {
            if (monitor.isCanceled()) {
                return;
            }
            WorkingTreeIterator workingTreeIterator = walk.getTree(0, WorkingTreeIterator.class);
            if (repoRelative.contains(walk.getPathString())) {
                if (!workingTreeIterator.isEntryIgnored()) {
                    files.add(walk.getNameString());
                }
            } else if (workingTreeIterator.getEntryFileMode().equals(FileMode.TREE)) {
                walk.enterSubtree();
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Repository(org.eclipse.jgit.lib.Repository) WorkingTreeIterator(org.eclipse.jgit.treewalk.WorkingTreeIterator) IPath(org.eclipse.core.runtime.IPath) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

WorkingTreeIterator (org.eclipse.jgit.treewalk.WorkingTreeIterator)8 EclipseGitProgressTransformer (org.eclipse.egit.core.EclipseGitProgressTransformer)3 IndexDiff (org.eclipse.jgit.lib.IndexDiff)3 Repository (org.eclipse.jgit.lib.Repository)3 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)3 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 FileTreeIterator (org.eclipse.jgit.treewalk.FileTreeIterator)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Nonnull (javax.annotation.Nonnull)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)1