Search in sources :

Example 1 with IndexDiff

use of org.eclipse.jgit.lib.IndexDiff in project egit by eclipse.

the class IndexDiffCacheEntry method calcIndexDiffDataIncremental.

private IndexDiffData calcIndexDiffDataIncremental(IProgressMonitor monitor, String jobName, Repository repository, Collection<String> filesToUpdate, Collection<IResource> resourcesToUpdate) throws IOException {
    if (indexDiffData == null)
        // -> do full refresh instead
        return calcIndexDiffDataFull(monitor, jobName, repository);
    EclipseGitProgressTransformer jgitMonitor = new EclipseGitProgressTransformer(monitor);
    List<String> treeFilterPaths = calcTreeFilterPaths(filesToUpdate);
    WorkingTreeIterator iterator = IteratorService.createInitialIterator(repository);
    if (iterator == null)
        // workspace is closed
        return null;
    IndexDiff diffForChangedResources = new IndexDiff(repository, Constants.HEAD, iterator);
    diffForChangedResources.setFilter(PathFilterGroup.createFromStrings(treeFilterPaths));
    diffForChangedResources.diff(jgitMonitor, 0, 0, jobName);
    IndexDiffData previous = indexDiffData;
    if (previous == null) {
        // but the updateJob is still running (and about to cancel).
        return null;
    }
    return new IndexDiffData(previous, filesToUpdate, resourcesToUpdate, diffForChangedResources);
}
Also used : WorkingTreeIterator(org.eclipse.jgit.treewalk.WorkingTreeIterator) EclipseGitProgressTransformer(org.eclipse.egit.core.EclipseGitProgressTransformer) IndexDiff(org.eclipse.jgit.lib.IndexDiff)

Example 2 with IndexDiff

use of org.eclipse.jgit.lib.IndexDiff in project egit by eclipse.

the class CommitViewerComparator method getFileStatus.

/**
 * Retrieve file status
 * @param path
 * @return file status
 * @throws IOException
 */
private Status getFileStatus(String path) throws IOException {
    FileTreeIterator fileTreeIterator = new FileTreeIterator(repository);
    IndexDiff indexDiff = new IndexDiff(repository, Constants.HEAD, fileTreeIterator);
    Set<String> repositoryPaths = Collections.singleton(path);
    indexDiff.setFilter(PathFilterGroup.createFromStrings(repositoryPaths));
    // $NON-NLS-1$
    indexDiff.diff(null, 0, 0, "");
    return getFileStatus(path, indexDiff);
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) FileTreeIterator(org.eclipse.jgit.treewalk.FileTreeIterator) IndexDiff(org.eclipse.jgit.lib.IndexDiff)

Example 3 with IndexDiff

use of org.eclipse.jgit.lib.IndexDiff 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 4 with IndexDiff

use of org.eclipse.jgit.lib.IndexDiff 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)

Aggregations

IndexDiff (org.eclipse.jgit.lib.IndexDiff)4 EclipseGitProgressTransformer (org.eclipse.egit.core.EclipseGitProgressTransformer)3 WorkingTreeIterator (org.eclipse.jgit.treewalk.WorkingTreeIterator)3 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 StyledString (org.eclipse.jface.viewers.StyledString)1 FileTreeIterator (org.eclipse.jgit.treewalk.FileTreeIterator)1