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);
}
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);
}
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;
}
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);
}
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);
}
Aggregations