Search in sources :

Example 16 with ChangeBrowserSettings

use of com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings in project intellij-community by JetBrains.

the class CommittedChangesCache method refreshCache.

// todo: fix - would externally loaded necessarily for file? i.e. just not efficient now
private List<CommittedChangeList> refreshCache(final ChangesCacheFile cacheFile) throws VcsException, IOException {
    final List<CommittedChangeList> newLists = new ArrayList<>();
    final CachingCommittedChangesProvider provider = cacheFile.getProvider();
    final RepositoryLocation location = cacheFile.getLocation();
    final Pair<Long, List<CommittedChangeList>> externalLists = myExternallyLoadedChangeLists.get(location.getKey());
    final long latestChangeList = getLatestListForFile(cacheFile);
    if ((externalLists != null) && (latestChangeList == externalLists.first.longValue())) {
        newLists.addAll(appendLoadedChanges(cacheFile, location, externalLists.second));
        myExternallyLoadedChangeLists.clear();
    }
    final ChangeBrowserSettings defaultSettings = provider.createDefaultSettings();
    int maxCount = 0;
    if (provider.refreshCacheByNumber()) {
        final long number = cacheFile.getLastCachedChangelist();
        debug("Refreshing cache for " + location + " since #" + number);
        if (number >= 0) {
            defaultSettings.CHANGE_AFTER = Long.toString(number);
            defaultSettings.USE_CHANGE_AFTER_FILTER = true;
        } else {
            maxCount = myState.getInitialCount();
        }
    } else {
        final Date date = cacheFile.getLastCachedDate();
        debug("Refreshing cache for " + location + " since " + date);
        defaultSettings.setDateAfter(date);
        defaultSettings.USE_DATE_AFTER_FILTER = true;
    }
    defaultSettings.STRICTLY_AFTER = true;
    final List<CommittedChangeList> newChanges = provider.getCommittedChanges(defaultSettings, location, maxCount);
    debug("Loaded " + newChanges.size() + " new changelists");
    newLists.addAll(appendLoadedChanges(cacheFile, location, newChanges));
    return newLists;
}
Also used : ChangeBrowserSettings(com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList)

Example 17 with ChangeBrowserSettings

use of com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings in project intellij-community by JetBrains.

the class BrowseChangesAction method actionPerformed.

public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    VirtualFile file = e.getRequiredData(CommonDataKeys.VIRTUAL_FILE);
    AbstractVcs vcs = notNull(getVcsForFile(file, project));
    CommittedChangesProvider provider = notNull(vcs.getCommittedChangesProvider());
    ChangeBrowserSettings settings = vcs.getConfiguration().CHANGE_BROWSER_SETTINGS.computeIfAbsent(vcs.getName(), key -> provider.createDefaultSettings());
    CommittedChangesFilterDialog dialog = new CommittedChangesFilterDialog(project, provider.createFilterUI(true), settings);
    if (dialog.showAndGet()) {
        showChanges(vcs, file, settings);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ChangeBrowserSettings(com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings) CommittedChangesFilterDialog(com.intellij.openapi.vcs.changes.committed.CommittedChangesFilterDialog) CommittedChangesProvider(com.intellij.openapi.vcs.CommittedChangesProvider) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs)

Example 18 with ChangeBrowserSettings

use of com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings in project intellij-community by JetBrains.

the class AbstractVcsHelperImpl method getRemoteList.

@Nullable
public static CommittedChangeList getRemoteList(@NotNull AbstractVcs vcs, @NotNull VcsRevisionNumber revision, @NotNull VirtualFile nonLocal) throws VcsException {
    final CommittedChangesProvider provider = vcs.getCommittedChangesProvider();
    final RepositoryLocation local = provider.getForNonLocal(nonLocal);
    if (local != null) {
        final String number = revision.asString();
        final ChangeBrowserSettings settings = provider.createDefaultSettings();
        final List<CommittedChangeList> changes = provider.getCommittedChanges(settings, local, provider.getUnlimitedCountValue());
        if (changes != null) {
            for (CommittedChangeList change : changes) {
                if (number.equals(String.valueOf(change.getNumber()))) {
                    return change;
                }
            }
        }
    }
    return null;
}
Also used : ChangeBrowserSettings(com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with ChangeBrowserSettings

use of com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings in project intellij-community by JetBrains.

the class AbstractVcsHelperImpl method loadAndShowCommittedChangesDetails.

@Override
public void loadAndShowCommittedChangesDetails(@NotNull final Project project, @NotNull final VcsRevisionNumber revision, @NotNull final VirtualFile virtualFile, @NotNull VcsKey vcsKey, @Nullable final RepositoryLocation location, final boolean isNonLocal) {
    final AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).findVcsByName(vcsKey.getName());
    if (vcs == null)
        return;
    final CommittedChangesProvider provider = vcs.getCommittedChangesProvider();
    if (provider == null)
        return;
    if (isNonLocal && provider.getForNonLocal(virtualFile) == null)
        return;
    final String title = VcsBundle.message("paths.affected.in.revision", revision instanceof ShortVcsRevisionNumber ? ((ShortVcsRevisionNumber) revision).toShortString() : revision.asString());
    final CommittedChangeList[] list = new CommittedChangeList[1];
    final FilePath[] targetPath = new FilePath[1];
    final VcsException[] exc = new VcsException[1];
    final BackgroundableActionLock lock = BackgroundableActionLock.getLock(project, VcsBackgroundableActions.COMMITTED_CHANGES_DETAILS, revision, virtualFile.getPath());
    if (lock.isLocked())
        return;
    lock.lock();
    Task.Backgroundable task = new Task.Backgroundable(project, title, true) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            try {
                if (!isNonLocal) {
                    final Pair<CommittedChangeList, FilePath> pair = provider.getOneList(virtualFile, revision);
                    if (pair != null) {
                        list[0] = pair.getFirst();
                        targetPath[0] = pair.getSecond();
                    }
                } else {
                    if (location != null) {
                        final ChangeBrowserSettings settings = provider.createDefaultSettings();
                        settings.USE_CHANGE_BEFORE_FILTER = true;
                        settings.CHANGE_BEFORE = revision.asString();
                        final List<CommittedChangeList> changes = provider.getCommittedChanges(settings, location, 1);
                        if (changes != null && changes.size() == 1) {
                            list[0] = changes.get(0);
                        }
                    } else {
                        list[0] = getRemoteList(vcs, revision, virtualFile);
                    }
                }
            } catch (VcsException e) {
                exc[0] = e;
            }
        }

        @Override
        public void onCancel() {
            lock.unlock();
        }

        @Override
        public void onSuccess() {
            lock.unlock();
            if (exc[0] != null) {
                showError(exc[0], failedText(virtualFile, revision));
            } else if (list[0] == null) {
                Messages.showErrorDialog(project, failedText(virtualFile, revision), getTitle());
            } else {
                VirtualFile navigateToFile = targetPath[0] != null ? new VcsVirtualFile(targetPath[0].getPath(), null, VcsFileSystem.getInstance()) : virtualFile;
                showChangesListBrowser(list[0], navigateToFile, title);
            }
        }
    };
    // we can's use runProcessWithProgressAsynchronously(task) because then ModalityState.NON_MODAL would be used
    CoreProgressManager progressManager = (CoreProgressManager) ProgressManager.getInstance();
    progressManager.runProcessWithProgressAsynchronously(task, new BackgroundableProcessIndicator(task), null, ModalityState.current());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsVirtualFile(com.intellij.openapi.vcs.vfs.VcsVirtualFile) CoreProgressManager(com.intellij.openapi.progress.impl.CoreProgressManager) Task(com.intellij.openapi.progress.Task) VcsVirtualFile(com.intellij.openapi.vcs.vfs.VcsVirtualFile) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) NotNull(org.jetbrains.annotations.NotNull) ChangeBrowserSettings(com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator)

Example 20 with ChangeBrowserSettings

use of com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings in project intellij-community by JetBrains.

the class ChangesCacheFile method readChanges.

public List<CommittedChangeList> readChanges(final ChangeBrowserSettings settings, final int maxCount) throws IOException {
    final List<CommittedChangeList> result = new ArrayList<>();
    final ChangeBrowserSettings.Filter filter = settings.createFilter();
    openStreams();
    try {
        if (maxCount == 0) {
            // skip header
            myStream.seek(HEADER_SIZE);
            while (myStream.getFilePointer() < myStream.length()) {
                CommittedChangeList changeList = myChangesProvider.readChangeList(myLocation, myStream);
                if (filter.accepts(changeList)) {
                    result.add(changeList);
                }
            }
        } else if (!settings.isAnyFilterSpecified()) {
            IndexEntry[] entries = readLastIndexEntries(0, maxCount);
            for (IndexEntry entry : entries) {
                myStream.seek(entry.offset);
                result.add(myChangesProvider.readChangeList(myLocation, myStream));
            }
        } else {
            int offset = 0;
            while (result.size() < maxCount) {
                IndexEntry[] entries = readLastIndexEntries(offset, 1);
                if (entries.length == 0) {
                    break;
                }
                CommittedChangeList changeList = loadChangeListAt(entries[0].offset);
                if (filter.accepts(changeList)) {
                    result.add(0, changeList);
                }
                offset++;
            }
        }
        return result;
    } finally {
        closeStreams();
    }
}
Also used : ChangeBrowserSettings(com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList)

Aggregations

ChangeBrowserSettings (com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings)29 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 SvnChangeList (org.jetbrains.idea.svn.history.SvnChangeList)16 SvnRepositoryLocation (org.jetbrains.idea.svn.history.SvnRepositoryLocation)15 Test (org.junit.Test)14 CommittedChangeList (com.intellij.openapi.vcs.versionBrowser.CommittedChangeList)9 SvnVcs (org.jetbrains.idea.svn.SvnVcs)9 File (java.io.File)7 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)5 Pair (com.intellij.openapi.util.Pair)4 NotNull (org.jetbrains.annotations.NotNull)4 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)3 ChangesBrowserSettingsEditor (com.intellij.openapi.vcs.versionBrowser.ChangesBrowserSettingsEditor)3 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)2 ApplicationManager.getApplication (com.intellij.openapi.application.ApplicationManager.getApplication)2 Logger (com.intellij.openapi.diagnostic.Logger)2 ProgressManager.progress (com.intellij.openapi.progress.ProgressManager.progress)2 ProgressManager.progress2 (com.intellij.openapi.progress.ProgressManager.progress2)2 FileUtil (com.intellij.openapi.util.io.FileUtil)2 Registry (com.intellij.openapi.util.registry.Registry)2