Search in sources :

Example 6 with EclipseGitProgressTransformer

use of org.eclipse.egit.core.EclipseGitProgressTransformer 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 7 with EclipseGitProgressTransformer

use of org.eclipse.egit.core.EclipseGitProgressTransformer 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 8 with EclipseGitProgressTransformer

use of org.eclipse.egit.core.EclipseGitProgressTransformer 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 9 with EclipseGitProgressTransformer

use of org.eclipse.egit.core.EclipseGitProgressTransformer in project egit by eclipse.

the class SubmoduleUpdateOperation method execute.

@Override
public void execute(final IProgressMonitor monitor) throws CoreException {
    IWorkspaceRunnable action = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor pm) throws CoreException {
            RepositoryUtil util = Activator.getDefault().getRepositoryUtil();
            SubMonitor progress = SubMonitor.convert(pm, 4);
            progress.setTaskName(MessageFormat.format(CoreText.SubmoduleUpdateOperation_updating, util.getRepositoryName(repository)));
            Git git = Git.wrap(repository);
            Collection<String> updated = null;
            try {
                SubmoduleInitCommand init = git.submoduleInit();
                for (String path : paths) init.addPath(path);
                init.call();
                progress.worked(1);
                SubmoduleUpdateCommand update = git.submoduleUpdate();
                for (String path : paths) update.addPath(path);
                update.setProgressMonitor(new EclipseGitProgressTransformer(progress.newChild(2)));
                MergeStrategy strategy = Activator.getDefault().getPreferredMergeStrategy();
                if (strategy != null) {
                    update.setStrategy(strategy);
                }
                update.setCallback(new CloneCommand.Callback() {

                    @Override
                    public void initializedSubmodules(Collection<String> submodules) {
                    // Nothing to do
                    }

                    @Override
                    public void cloningSubmodule(String path) {
                        progress.setTaskName(MessageFormat.format(CoreText.SubmoduleUpdateOperation_cloning, util.getRepositoryName(repository), path));
                    }

                    @Override
                    public void checkingOut(AnyObjectId commit, String path) {
                    // Nothing to do
                    }
                });
                updated = update.call();
                SubMonitor refreshMonitor = progress.newChild(1).setWorkRemaining(updated.size());
                for (String path : updated) {
                    Repository subRepo = SubmoduleWalk.getSubmoduleRepository(repository, path);
                    if (subRepo != null) {
                        ProjectUtil.refreshValidProjects(ProjectUtil.getValidOpenProjects(subRepo), refreshMonitor.newChild(1));
                    } else {
                        refreshMonitor.worked(1);
                    }
                }
            } catch (GitAPIException e) {
                throw new TeamException(e.getLocalizedMessage(), e.getCause());
            } catch (IOException e) {
                throw new TeamException(e.getLocalizedMessage(), e.getCause());
            } finally {
                if (updated != null && !updated.isEmpty()) {
                    repository.notifyIndexChanged();
                }
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, monitor);
}
Also used : CloneCommand(org.eclipse.jgit.api.CloneCommand) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) SubmoduleUpdateCommand(org.eclipse.jgit.api.SubmoduleUpdateCommand) MergeStrategy(org.eclipse.jgit.merge.MergeStrategy) SubMonitor(org.eclipse.core.runtime.SubMonitor) EclipseGitProgressTransformer(org.eclipse.egit.core.EclipseGitProgressTransformer) IOException(java.io.IOException) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) AnyObjectId(org.eclipse.jgit.lib.AnyObjectId) TeamException(org.eclipse.team.core.TeamException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) SubmoduleInitCommand(org.eclipse.jgit.api.SubmoduleInitCommand)

Example 10 with EclipseGitProgressTransformer

use of org.eclipse.egit.core.EclipseGitProgressTransformer in project egit by eclipse.

the class RebaseOperation method execute.

@Override
public void execute(IProgressMonitor m) throws CoreException {
    if (result != null)
        throw new CoreException(new Status(IStatus.ERROR, Activator.getPluginId(), CoreText.OperationAlreadyExecuted));
    final IProject[] validProjects = ProjectUtil.getValidOpenProjects(repository);
    IWorkspaceRunnable action = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor actMonitor) throws CoreException {
            SubMonitor progress = SubMonitor.convert(actMonitor, 2);
            try (Git git = new Git(repository)) {
                RebaseCommand cmd = git.rebase().setProgressMonitor(new EclipseGitProgressTransformer(progress.newChild(1)));
                MergeStrategy strategy = Activator.getDefault().getPreferredMergeStrategy();
                if (strategy != null) {
                    cmd.setStrategy(strategy);
                }
                if (handler != null) {
                    cmd.runInteractively(handler, true);
                }
                if (operation == Operation.BEGIN) {
                    cmd.setPreserveMerges(preserveMerges);
                    result = cmd.setUpstream(ref.getName()).call();
                } else {
                    result = cmd.setOperation(operation).call();
                }
            } catch (JGitInternalException | GitAPIException e) {
                throw new CoreException(Activator.error(e.getMessage(), e));
            } finally {
                if (refreshNeeded()) {
                    ProjectUtil.refreshValidProjects(validProjects, progress.newChild(1));
                }
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(action, getSchedulingRule(), IWorkspace.AVOID_UPDATE, m);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) RebaseCommand(org.eclipse.jgit.api.RebaseCommand) MergeStrategy(org.eclipse.jgit.merge.MergeStrategy) SubMonitor(org.eclipse.core.runtime.SubMonitor) EclipseGitProgressTransformer(org.eclipse.egit.core.EclipseGitProgressTransformer) IProject(org.eclipse.core.resources.IProject) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Git(org.eclipse.jgit.api.Git) CoreException(org.eclipse.core.runtime.CoreException) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException)

Aggregations

EclipseGitProgressTransformer (org.eclipse.egit.core.EclipseGitProgressTransformer)12 SubMonitor (org.eclipse.core.runtime.SubMonitor)7 Git (org.eclipse.jgit.api.Git)7 IProject (org.eclipse.core.resources.IProject)5 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)5 CoreException (org.eclipse.core.runtime.CoreException)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)5 JGitInternalException (org.eclipse.jgit.api.errors.JGitInternalException)4 Repository (org.eclipse.jgit.lib.Repository)4 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 IndexDiff (org.eclipse.jgit.lib.IndexDiff)3 MergeStrategy (org.eclipse.jgit.merge.MergeStrategy)3 Collection (java.util.Collection)2 CloneCommand (org.eclipse.jgit.api.CloneCommand)2 AnyObjectId (org.eclipse.jgit.lib.AnyObjectId)2 Ref (org.eclipse.jgit.lib.Ref)2