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