use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData 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.IndexDiffData 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.IndexDiffData in project egit by eclipse.
the class StagingView method updateCommitButtons.
private void updateCommitButtons() {
IndexDiffData indexDiff;
if (cacheEntry != null) {
indexDiff = cacheEntry.getIndexDiff();
} else {
Repository repo = currentRepository;
if (repo == null) {
indexDiff = null;
} else {
indexDiff = doReload(repo);
}
}
boolean indexDiffAvailable = indexDiffAvailable(indexDiff);
boolean noConflicts = noConflicts(indexDiff);
boolean commitEnabled = !isCommitBlocked() && noConflicts && indexDiffAvailable;
boolean commitAndPushEnabled = commitAndPushEnabled(commitEnabled);
commitButton.setEnabled(commitEnabled);
commitAndPushButton.setEnabled(commitAndPushEnabled);
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.
the class StagingViewContentProvider method inputChanged.
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if (!(newInput instanceof StagingViewUpdate))
return;
StagingViewUpdate update = (StagingViewUpdate) newInput;
if (update.repository == null || update.indexDiff == null) {
content = new StagingEntry[0];
treeRoots = new Object[0];
compactTreeRoots = new Object[0];
return;
}
if (update.repository != repository) {
treeRoots = null;
compactTreeRoots = null;
}
repository = update.repository;
Set<StagingEntry> nodes = new TreeSet<>(new Comparator<StagingEntry>() {
@Override
public int compare(StagingEntry o1, StagingEntry o2) {
return o1.getPath().compareTo(o2.getPath());
}
});
if (update.changedResources != null && !update.changedResources.isEmpty()) {
nodes.addAll(Arrays.asList(content));
for (String res : update.changedResources) for (StagingEntry entry : content) if (entry.getPath().equals(res))
nodes.remove(entry);
}
final IndexDiffData indexDiff = update.indexDiff;
if (unstagedSection) {
for (String file : indexDiff.getMissing()) if (indexDiff.getChanged().contains(file))
nodes.add(new StagingEntry(repository, MISSING_AND_CHANGED, file));
else
nodes.add(new StagingEntry(repository, MISSING, file));
for (String file : indexDiff.getModified()) if (indexDiff.getChanged().contains(file))
nodes.add(new StagingEntry(repository, MODIFIED_AND_CHANGED, file));
else if (indexDiff.getAdded().contains(file))
nodes.add(new StagingEntry(repository, MODIFIED_AND_ADDED, file));
else
nodes.add(new StagingEntry(repository, MODIFIED, file));
for (String file : indexDiff.getUntracked()) nodes.add(new StagingEntry(repository, UNTRACKED, file));
for (String file : indexDiff.getConflicting()) nodes.add(new StagingEntry(repository, CONFLICTING, file));
} else {
for (String file : indexDiff.getAdded()) nodes.add(new StagingEntry(repository, ADDED, file));
for (String file : indexDiff.getChanged()) nodes.add(new StagingEntry(repository, CHANGED, file));
for (String file : indexDiff.getRemoved()) nodes.add(new StagingEntry(repository, REMOVED, file));
}
setSymlinkFileMode(indexDiff, nodes);
setSubmoduleFileMode(indexDiff, nodes);
content = nodes.toArray(new StagingEntry[nodes.size()]);
Arrays.sort(content, comparator);
treeRoots = null;
compactTreeRoots = null;
}
use of org.eclipse.egit.core.internal.indexdiff.IndexDiffData in project egit by eclipse.
the class RepositoryUtil method hasChanges.
/**
* Determines whether the given {@link Repository} has any changes by
* checking the {@link IndexDiffCacheEntry} of the repository.
*
* @param repository
* to check
* @return {@code true} if the repository has any changes, {@code false}
* otherwise
*/
public static boolean hasChanges(@NonNull Repository repository) {
IndexDiffCacheEntry entry = Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(repository);
IndexDiffData data = entry != null ? entry.getIndexDiff() : null;
return data != null && data.hasChanges();
}
Aggregations