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