Search in sources :

Example 11 with IndexDiffCacheEntry

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];
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) IOException(java.io.IOException) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 12 with IndexDiffCacheEntry

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Repository(org.eclipse.jgit.lib.Repository) IPath(org.eclipse.core.runtime.IPath) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) Collection(java.util.Collection) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache)

Example 13 with IndexDiffCacheEntry

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);
}
Also used : IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache)

Example 14 with IndexDiffCacheEntry

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DirCache(org.eclipse.jgit.dircache.DirCache) DirCacheBuilder(org.eclipse.jgit.dircache.DirCacheBuilder) LockFailedException(org.eclipse.jgit.errors.LockFailedException) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping) IOException(java.io.IOException) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData)

Example 15 with IndexDiffCacheEntry

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry)

Aggregations

IndexDiffCacheEntry (org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry)17 IndexDiffCache (org.eclipse.egit.core.internal.indexdiff.IndexDiffCache)8 IndexDiffData (org.eclipse.egit.core.internal.indexdiff.IndexDiffData)8 Repository (org.eclipse.jgit.lib.Repository)5 Collection (java.util.Collection)4 IOException (java.io.IOException)3 IFile (org.eclipse.core.resources.IFile)3 IResource (org.eclipse.core.resources.IResource)3 IPath (org.eclipse.core.runtime.IPath)3 Map (java.util.Map)2 CoreException (org.eclipse.core.runtime.CoreException)2 Path (org.eclipse.core.runtime.Path)2 RepositoryMapping (org.eclipse.egit.core.project.RepositoryMapping)2 Test (org.junit.Test)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1