use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry in project egit by eclipse.
the class CommitActionHandler method getIndexDiffData.
private IndexDiffData getIndexDiffData(@NonNull final Repository repository, @NonNull final Collection<IProject> projects) {
IndexDiffCacheEntry diffCacheEntry = org.eclipse.egit.core.Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(repository);
IndexDiffData diff = null;
if (diffCacheEntry != null) {
diff = diffCacheEntry.getIndexDiff();
}
if (diff != null) {
return diff;
}
final IndexDiffData[] result = { null };
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
result[0] = new IndexDiffData(CommitUI.getIndexDiff(repository, projects.toArray(new IProject[projects.size()]), monitor));
} catch (IOException e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
Activator.handleError(UIText.CommitAction_errorComputingDiffs, e.getCause(), true);
return null;
} catch (InterruptedException e) {
return null;
}
return result[0];
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry in project egit by eclipse.
the class MergeToolActionHandler method isEnabled.
@Override
public boolean isEnabled() {
IPath[] paths = getSelectedLocations();
Map<Repository, Collection<String>> pathsByRepository = ResourceUtil.splitPathsByRepository(Arrays.asList(paths));
Set<Repository> repos = pathsByRepository.keySet();
if (repos.size() != 1)
return false;
Repository repo = repos.iterator().next();
Collection<String> selectedRepoPaths = pathsByRepository.get(repo);
if (selectedRepoPaths.isEmpty())
return false;
IndexDiffCache cache = org.eclipse.egit.core.Activator.getDefault().getIndexDiffCache();
if (cache == null)
return false;
IndexDiffCacheEntry entry = cache.getIndexDiffCacheEntry(repo);
if (entry == null || entry.getIndexDiff() == null)
return false;
Set<String> conflictingFiles = entry.getIndexDiff().getConflicting();
if (conflictingFiles.isEmpty())
return false;
for (String selectedRepoPath : selectedRepoPaths) {
Path selectedPath = new Path(selectedRepoPath);
for (String conflictingFile : conflictingFiles) if (selectedPath.isPrefixOf(new Path(conflictingFile)))
return true;
}
return false;
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry in project egit by eclipse.
the class DeletePathsOperationTest method initIndexDiffCache.
private static void initIndexDiffCache(Repository repository) throws Exception {
IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
IndexDiffCacheEntry cacheEntry = cache.getIndexDiffCacheEntry(repository);
assertNotNull(cacheEntry);
Job.getJobManager().join(JobFamilies.INDEX_DIFF_CACHE_UPDATE, null);
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry in project egit by eclipse.
the class GitMoveDeleteHook method deleteFile.
@Override
public boolean deleteFile(final IResourceTree tree, final IFile file, final int updateFlags, final IProgressMonitor monitor) {
if (!org.eclipse.egit.core.Activator.autoStageDeletion()) {
return false;
}
// Linked resources are not files, hence not tracked by git
if (file.isLinked())
return false;
final boolean force = (updateFlags & IResource.FORCE) == IResource.FORCE;
if (!force && !tree.isSynchronized(file, IResource.DEPTH_ZERO))
return false;
final RepositoryMapping map = RepositoryMapping.getMapping(file);
if (map == null)
return false;
String repoRelativePath = map.getRepoRelativePath(file);
IndexDiffCache indexDiffCache = Activator.getDefault().getIndexDiffCache();
IndexDiffCacheEntry indexDiffCacheEntry = indexDiffCache.getIndexDiffCacheEntry(map.getRepository());
if (indexDiffCacheEntry == null) {
return false;
}
IndexDiffData indexDiff = indexDiffCacheEntry.getIndexDiff();
if (indexDiff != null) {
if (indexDiff.getUntracked().contains(repoRelativePath))
return false;
if (indexDiff.getIgnoredNotInIndex().contains(repoRelativePath))
return false;
}
if (!file.exists())
return false;
if (file.isDerived())
return false;
DirCache dirc = null;
try {
dirc = map.getRepository().lockDirCache();
final int first = dirc.findEntry(repoRelativePath);
if (first < 0) {
dirc.unlock();
return false;
}
final DirCacheBuilder edit = dirc.builder();
if (first > 0)
edit.keep(0, first);
final int next = dirc.nextEntry(first);
if (next < dirc.getEntryCount())
edit.keep(next, dirc.getEntryCount() - next);
if (!edit.commit())
tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, null));
tree.standardDeleteFile(file, updateFlags, monitor);
} catch (LockFailedException e) {
// FIXME The index is currently locked. This notably happens during
// rebase operations. auto-staging deletions should be queued... and
// the queued job will have to double-check whether the file has
// truly been deleted or if it was only deleted to be replaced by
// another version.
// This hook only exists to automatically add changes to the index.
// If the index is currently locked, do not accept the
// responsibility of deleting the file, return false to tell the
// workspace it can continue with the standard deletion. The user
// will have to stage the deletion later on _if_ this was truly
// needed, which won't happen for calls triggered by merge
// operations from the merge strategies.
Activator.getDefault().getLog().log(new Status(IStatus.WARNING, Activator.getPluginId(), MessageFormat.format(CoreText.MoveDeleteHook_cannotAutoStageDeletion, file.getLocation())));
return FINISH_FOR_ME;
} catch (IOException e) {
tree.failed(new Status(IStatus.ERROR, Activator.getPluginId(), 0, CoreText.MoveDeleteHook_operationError, e));
} finally {
if (dirc != null)
dirc.unlock();
}
return true;
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry in project egit by eclipse.
the class LocalNonWorkspaceTypedElement method refreshRepositoryState.
private boolean refreshRepositoryState(@NonNull Repository repo) {
IPath repositoryRoot = new Path(repo.getWorkTree().getPath());
IPath relativePath = path.makeRelativeTo(repositoryRoot);
IndexDiffCacheEntry indexDiffCacheForRepository = org.eclipse.egit.core.Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(repo);
if (indexDiffCacheForRepository != null) {
indexDiffCacheForRepository.refreshFiles(Collections.singleton(relativePath.toString()));
return true;
}
return false;
}
Aggregations