Search in sources :

Example 1 with IndexDiffData

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);
                }
            }
        }
    }
}
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 IndexDiffData

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;
}
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 3 with IndexDiffData

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);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData)

Example 4 with IndexDiffData

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;
}
Also used : TreeSet(java.util.TreeSet) StagingViewUpdate(org.eclipse.egit.ui.internal.staging.StagingView.StagingViewUpdate) IndexDiffData(org.eclipse.egit.core.internal.indexdiff.IndexDiffData)

Example 5 with IndexDiffData

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

Aggregations

IndexDiffData (org.eclipse.egit.core.internal.indexdiff.IndexDiffData)47 Test (org.junit.Test)34 IResource (org.eclipse.core.resources.IResource)14 File (java.io.File)11 IFile (org.eclipse.core.resources.IFile)10 IndexDiffCacheEntry (org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry)9 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 IFolder (org.eclipse.core.resources.IFolder)4 MergeResult (org.eclipse.jgit.api.MergeResult)4 Repository (org.eclipse.jgit.lib.Repository)4 IOException (java.io.IOException)3 CoreException (org.eclipse.core.runtime.CoreException)3 IndexDiffCache (org.eclipse.egit.core.internal.indexdiff.IndexDiffCache)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IndexDiffChangedListener (org.eclipse.egit.core.internal.indexdiff.IndexDiffChangedListener)2