use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.
the class ShowBlameActionHandlerTest method createJavaProjectAndCommitToRepository.
private IJavaProject createJavaProjectAndCommitToRepository() throws Exception {
Repository myRepository = createLocalTestRepository(REPO1);
File gitDir = myRepository.getDirectory();
IJavaProject jProject = createJavaProject(myRepository, JAVA_PROJECT_NAME);
IProject project = jProject.getProject();
try {
new ConnectProviderOperation(project, gitDir).execute(null);
} catch (Exception e) {
Activator.logError("Failed to connect project to repository", e);
}
assertConnected(project);
// Check in at least the java file
IFolder folder = project.getFolder(SRC_FOLDER_NAME).getFolder(PACKAGE_NAME);
IFile file = folder.getFile(JAVA_FILE_NAME);
IFile[] commitables = new IFile[] { file };
ArrayList<IFile> untracked = new ArrayList<IFile>();
untracked.addAll(Arrays.asList(commitables));
// commit to master
CommitOperation op = new CommitOperation(commitables, untracked, TestUtil.TESTAUTHOR, TestUtil.TESTCOMMITTER, "Initial commit");
op.execute(null);
// Make sure cache entry is already listening for changes
IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
cache.getIndexDiffCacheEntry(lookupRepository(gitDir));
return jProject;
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache 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.IndexDiffCache in project egit by eclipse.
the class Activator method start.
@Override
public void start(final BundleContext context) throws Exception {
super.start(context);
pluginId = context.getBundle().getSymbolicName();
Config.setTypedConfigGetter(new ReportingTypedConfigGetter());
// we want to be notified about debug options changes
Dictionary<String, String> props = new Hashtable<String, String>(4);
props.put(DebugOptions.LISTENER_SYMBOLICNAME, pluginId);
context.registerService(DebugOptionsListener.class.getName(), this, props);
setupSSH(context);
setupProxy(context);
repositoryCache = new RepositoryCache();
indexDiffCache = new IndexDiffCache();
try {
GitProjectData.reconfigureWindowCache();
} catch (RuntimeException e) {
logError(CoreText.Activator_ReconfigureWindowCacheError, e);
}
GitProjectData.attachToWorkspace();
repositoryUtil = new RepositoryUtil();
secureStore = new EGitSecureStore(SecurePreferencesFactory.getDefault());
registerAutoShareProjects();
registerAutoIgnoreDerivedResources();
registerPreDeleteResourceChangeListener();
registerMergeStrategyRegistryListener();
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache in project egit by eclipse.
the class RepositoryCache method prune.
private void prune() {
List<File> toRemove = new ArrayList<>();
synchronized (repositoryCache) {
for (Iterator<Map.Entry<File, Reference<Repository>>> i = repositoryCache.entrySet().iterator(); i.hasNext(); ) {
Map.Entry<File, Reference<Repository>> entry = i.next();
Repository repository = entry.getValue().get();
if (repository == null || !repository.getDirectory().exists()) {
i.remove();
toRemove.add(entry.getKey());
}
}
}
IndexDiffCache cache = Activator.getDefault().getIndexDiffCache();
if (cache != null) {
for (File f : toRemove) {
cache.remove(f);
}
}
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffCache 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;
}
Aggregations