Search in sources :

Example 1 with IndexDiffCacheEntry

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry in project egit by eclipse.

the class ResourceUtil method saveLocalHistory.

/**
 * Save local history.
 *
 * @param repository
 */
public static void saveLocalHistory(@NonNull Repository repository) {
    IndexDiffCacheEntry indexDiffCacheEntry = org.eclipse.egit.core.Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(repository);
    if (indexDiffCacheEntry == null) {
        return;
    }
    IndexDiffData indexDiffData = indexDiffCacheEntry.getIndexDiff();
    if (indexDiffData != null) {
        Collection<IResource> changedResources = indexDiffData.getChangedResources();
        for (IResource changedResource : changedResources) {
            if (changedResource instanceof IFile && changedResource.exists()) {
                try {
                    ResourceUtil.saveLocalHistory(changedResource);
                } catch (CoreException e) {
                    // Ignore error. Failure to save local history must
                    // not interfere with the operation.
                    Activator.logError(MessageFormat.format(CoreText.ResourceUtil_SaveLocalHistoryFailed, changedResource), e);
                }
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData) IResource(org.eclipse.core.resources.IResource)

Example 2 with IndexDiffCacheEntry

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry in project egit by eclipse.

the class ConnectProviderOperation method connectProject.

private void connectProject(Entry<IProject, File> entry, MultiStatus ms, IProgressMonitor monitor) throws CoreException {
    IProject project = entry.getKey();
    String taskName = NLS.bind(CoreText.ConnectProviderOperation_ConnectingProject, project.getName());
    SubMonitor subMon = SubMonitor.convert(monitor, taskName, 100);
    if (GitTraceLocation.CORE.isActive()) {
        GitTraceLocation.getTrace().trace(GitTraceLocation.CORE.getLocation(), taskName);
    }
    RepositoryFinder finder = new RepositoryFinder(project);
    finder.setFindInChildren(false);
    Collection<RepositoryMapping> repos = finder.find(subMon.newChild(50));
    if (repos.isEmpty()) {
        ms.add(Activator.error(NLS.bind(CoreText.ConnectProviderOperation_NoRepositoriesError, project.getName()), null));
        return;
    }
    RepositoryMapping actualMapping = findActualRepository(repos, entry.getValue());
    if (actualMapping == null) {
        ms.add(Activator.error(NLS.bind(CoreText.ConnectProviderOperation_UnexpectedRepositoryError, new Object[] { project.getName(), entry.getValue().toString(), repos.toString() }), null));
        return;
    }
    GitProjectData projectData = new GitProjectData(project);
    try {
        projectData.setRepositoryMappings(Arrays.asList(actualMapping));
        projectData.store();
        GitProjectData.add(project, projectData);
    } catch (CoreException ce) {
        ms.add(ce.getStatus());
        deleteGitProvider(ms, project);
        return;
    } catch (RuntimeException ce) {
        ms.add(Activator.error(ce.getMessage(), ce));
        deleteGitProvider(ms, project);
        return;
    }
    RepositoryProvider.map(project, GitProvider.ID);
    IPath gitPath = actualMapping.getGitDirAbsolutePath();
    if (refreshResources) {
        touchGitResources(project, subMon.newChild(10));
        project.refreshLocal(IResource.DEPTH_INFINITE, subMon.newChild(30));
        if (gitPath != null) {
            try {
                Repository repository = org.eclipse.egit.core.Activator.getDefault().getRepositoryCache().lookupRepository(gitPath.toFile());
                IndexDiffCacheEntry cacheEntry = org.eclipse.egit.core.Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(repository);
                if (cacheEntry != null) {
                    cacheEntry.refresh();
                }
            } catch (IOException e) {
                Activator.logError(e.getMessage(), e);
            }
        }
    } else {
        subMon.worked(40);
    }
    autoIgnoreDerivedResources(project, subMon.newChild(10));
    if (gitPath != null) {
        autoIgnoreWorkspaceMetaData(gitPath.toFile());
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) RepositoryFinder(org.eclipse.egit.core.project.RepositoryFinder) SubMonitor(org.eclipse.core.runtime.SubMonitor) IOException(java.io.IOException) GitProjectData(org.eclipse.egit.core.project.GitProjectData) IProject(org.eclipse.core.resources.IProject) Repository(org.eclipse.jgit.lib.Repository) CoreException(org.eclipse.core.runtime.CoreException) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) RepositoryMapping(org.eclipse.egit.core.project.RepositoryMapping)

Example 3 with IndexDiffCacheEntry

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry in project egit by eclipse.

the class DeletePathsOperation method refreshIndexDiffCache.

private void refreshIndexDiffCache(List<IPath> refreshCachePaths, boolean refreshAll) {
    Map<Repository, Collection<String>> resourcesByRepository = ResourceUtil.splitPathsByRepository(refreshCachePaths);
    for (Map.Entry<Repository, Collection<String>> entry : resourcesByRepository.entrySet()) {
        Repository repository = entry.getKey();
        Collection<String> files = entry.getValue();
        IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
        IndexDiffCacheEntry cacheEntry = cache.getIndexDiffCacheEntry(repository);
        if (cacheEntry != null)
            if (refreshAll)
                cacheEntry.refresh();
            else
                cacheEntry.refreshFiles(files);
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) Collection(java.util.Collection) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) Map(java.util.Map)

Example 4 with IndexDiffCacheEntry

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry in project egit by eclipse.

the class GitScopeOperation method promptForInputChange.

@Override
protected boolean promptForInputChange(String requestPreviewMessage, IProgressMonitor monitor) {
    List<IResource> relevantResources = getRelevantResources();
    Map<Repository, Collection<String>> pathsByRepo = ResourceUtil.splitResourcesByRepository(relevantResources);
    for (Map.Entry<Repository, Collection<String>> entry : pathsByRepo.entrySet()) {
        Repository repository = entry.getKey();
        Collection<String> paths = entry.getValue();
        IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
        if (cache == null)
            continue;
        IndexDiffCacheEntry cacheEntry = cache.getIndexDiffCacheEntry(repository);
        if (cacheEntry == null)
            continue;
        IndexDiffData indexDiff = cacheEntry.getIndexDiff();
        if (indexDiff == null)
            continue;
        if (hasAnyPathChanged(paths, indexDiff))
            return super.promptForInputChange(requestPreviewMessage, monitor);
    }
    return false;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) Collection(java.util.Collection) IndexDiffCache(org.eclipse.egit.core.internal.indexdiff.IndexDiffCache) Map(java.util.Map) IResource(org.eclipse.core.resources.IResource) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData)

Example 5 with IndexDiffCacheEntry

use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry in project egit by eclipse.

the class StagingView method doReload.

private IndexDiffData doReload(@NonNull final Repository repository) {
    IndexDiffCacheEntry entry = org.eclipse.egit.core.Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(repository);
    if (cacheEntry != null && cacheEntry != entry)
        cacheEntry.removeIndexDiffChangedListener(myIndexDiffListener);
    cacheEntry = entry;
    cacheEntry.addIndexDiffChangedListener(myIndexDiffListener);
    return cacheEntry.getIndexDiff();
}
Also used : 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