Search in sources :

Example 6 with CommittedChangeList

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

the class HgCachingCommittedChangesProvider method getCommittedChanges.

public List<CommittedChangeList> getCommittedChanges(ChangeBrowserSettings changeBrowserSettings, RepositoryLocation repositoryLocation, int maxCount) throws VcsException {
    VirtualFile root = ((HgRepositoryLocation) repositoryLocation).getRoot();
    HgFile hgFile = new HgFile(root, VcsUtil.getFilePath(root.getPath()));
    List<CommittedChangeList> result = new LinkedList<>();
    HgLogCommand hgLogCommand = new HgLogCommand(project);
    hgLogCommand.setLogFile(false);
    List<String> args = null;
    if (changeBrowserSettings != null) {
        HgLogArgsBuilder argsBuilder = new HgLogArgsBuilder(changeBrowserSettings);
        args = argsBuilder.getLogArgs();
        if (args.isEmpty()) {
            maxCount = maxCount == 0 ? VcsConfiguration.getInstance(project).MAXIMUM_HISTORY_ROWS : maxCount;
        }
    }
    final List<HgFileRevision> localRevisions;
    localRevisions = hgLogCommand.execute(hgFile, maxCount == 0 ? -1 : maxCount, true, args);
    Collections.reverse(localRevisions);
    for (HgFileRevision revision : localRevisions) {
        HgRevisionNumber vcsRevisionNumber = revision.getRevisionNumber();
        List<HgRevisionNumber> parents = vcsRevisionNumber.getParents();
        // can have no parents if it is a root
        HgRevisionNumber firstParent = parents.isEmpty() ? null : parents.get(0);
        List<Change> changes = new ArrayList<>();
        for (String file : revision.getModifiedFiles()) {
            changes.add(createChange(root, file, firstParent, file, vcsRevisionNumber, FileStatus.MODIFIED));
        }
        for (String file : revision.getAddedFiles()) {
            changes.add(createChange(root, null, null, file, vcsRevisionNumber, FileStatus.ADDED));
        }
        for (String file : revision.getDeletedFiles()) {
            changes.add(createChange(root, file, firstParent, null, vcsRevisionNumber, FileStatus.DELETED));
        }
        for (Map.Entry<String, String> copiedFile : revision.getMovedFiles().entrySet()) {
            changes.add(createChange(root, copiedFile.getKey(), firstParent, copiedFile.getValue(), vcsRevisionNumber, HgChangeProvider.RENAMED));
        }
        result.add(new HgCommittedChangeList(myVcs, vcsRevisionNumber, revision.getBranchName(), revision.getCommitMessage(), revision.getAuthor(), revision.getRevisionDate(), changes));
    }
    Collections.reverse(result);
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) Change(com.intellij.openapi.vcs.changes.Change) HgLogCommand(org.zmlx.hg4idea.command.HgLogCommand)

Example 7 with CommittedChangeList

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

the class HgCachingCommittedChangesProvider method getOneList.

@Override
public Pair<CommittedChangeList, FilePath> getOneList(VirtualFile file, VcsRevisionNumber number) throws VcsException {
    final ChangeBrowserSettings settings = createDefaultSettings();
    settings.USE_CHANGE_AFTER_FILTER = true;
    settings.USE_CHANGE_BEFORE_FILTER = true;
    settings.CHANGE_AFTER = number.asString();
    settings.CHANGE_BEFORE = number.asString();
    // todo implement in proper way
    VirtualFile localVirtualFile = HgUtil.convertToLocalVirtualFile(file);
    if (localVirtualFile == null) {
        return null;
    }
    final FilePath filePath = VcsUtil.getFilePath(localVirtualFile);
    final CommittedChangeList list = getCommittedChangesForRevision(getLocationFor(filePath), number.asString());
    if (list != null) {
        return new Pair<>(list, filePath);
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ChangeBrowserSettings(com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) Pair(com.intellij.openapi.util.Pair)

Example 8 with CommittedChangeList

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

the class CachedProvider method getEarliestRevision.

public long getEarliestRevision() {
    if (myEarliestKeepedRevision == -1) {
        try {
            while (myIterator.hasNext()) {
                final ChangesBunch changesBunch = myIterator.next();
                if (changesBunch == null) {
                    break;
                }
                addToLoaded(changesBunch);
                final List<CommittedChangeList> list = myAlreadyReaded.getList();
                if (!list.isEmpty()) {
                    myEarliestKeepedRevision = list.get(0).getNumber();
                    break;
                }
            }
        } catch (SwitchRevisionsProviderException e) {
            // means that committed cache now should be queried instead of internally cached
            // just return -1 -> queries will be redirected
            myEarliestKeepedRevision = -1;
        }
    }
    return myEarliestKeepedRevision;
}
Also used : CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) ChangesBunch(com.intellij.openapi.vcs.changes.committed.ChangesBunch)

Example 9 with CommittedChangeList

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

the class CachedProvider method createFromLoaded.

@Nullable
private Fragment createFromLoaded(final ChangesBunch loadedBunch, final long earliestRevision, final long oldestRevision, final int desirableSize, final boolean includeYoungest, final boolean includeOldest, final boolean consistent) {
    boolean consistentWithPrevious = loadedBunch.isConsistentWithPrevious();
    boolean consistentWithYounger = consistent;
    final List<CommittedChangeList> list = loadedBunch.getList();
    final List<CommittedChangeList> sublist = new ArrayList<>();
    for (int i = 0; i < list.size(); i++) {
        final CommittedChangeList changeList = list.get(i);
        if ((!includeOldest) && (changeList.getNumber() == oldestRevision)) {
            continue;
        }
        if (changeList.getNumber() == earliestRevision) {
            consistentWithYounger = true;
        }
        if ((earliestRevision == -1) || (changeList.getNumber() < earliestRevision) || (includeYoungest && (changeList.getNumber() == earliestRevision))) {
            sublist.add(changeList);
        }
        if ((sublist.size() == desirableSize) || (changeList.getNumber() < oldestRevision)) {
            if (!consistentWithPrevious) {
                consistentWithPrevious = (i > 0);
            }
            break;
        }
    }
    if (!myHadBeenAccessed) {
        myHadBeenAccessed = (!sublist.isEmpty());
    }
    return (sublist.isEmpty()) ? null : new Fragment(myOrigin, sublist, consistentWithPrevious, consistentWithYounger, loadedBunch);
}
Also used : CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) ArrayList(java.util.ArrayList) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with CommittedChangeList

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

the class ShowDiffFromAnnotation method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final int actualNumber = currentLine;
    if (actualNumber < 0)
        return;
    final VcsRevisionNumber revisionNumber = myFileAnnotation.getLineRevisionNumber(actualNumber);
    if (revisionNumber != null) {
        final VcsException[] exc = new VcsException[1];
        final List<Change> changes = new LinkedList<>();
        final FilePath[] targetPath = new FilePath[1];
        ProgressManager.getInstance().run(new Task.Backgroundable(myVcs.getProject(), "Loading revision " + revisionNumber.asString() + " contents", true) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                final CommittedChangesProvider provider = myVcs.getCommittedChangesProvider();
                try {
                    final Pair<CommittedChangeList, FilePath> pair = provider.getOneList(myFile, revisionNumber);
                    if (pair == null || pair.getFirst() == null) {
                        VcsBalloonProblemNotifier.showOverChangesView(myVcs.getProject(), "Can not load data for show diff", MessageType.ERROR);
                        return;
                    }
                    targetPath[0] = pair.getSecond() == null ? VcsUtil.getFilePath(myFile) : pair.getSecond();
                    final CommittedChangeList cl = pair.getFirst();
                    changes.addAll(cl.getChanges());
                    Collections.sort(changes, ChangesComparator.getInstance(true));
                } catch (VcsException e1) {
                    exc[0] = e1;
                }
            }

            @Override
            public void onSuccess() {
                if (exc[0] != null) {
                    VcsBalloonProblemNotifier.showOverChangesView(myVcs.getProject(), "Can not show diff: " + exc[0].getMessage(), MessageType.ERROR);
                } else if (!changes.isEmpty()) {
                    int idx = findSelfInList(changes, targetPath[0]);
                    final ShowDiffContext context = new ShowDiffContext(DiffDialogHints.FRAME);
                    if (idx != -1) {
                        context.putChangeContext(changes.get(idx), DiffUserDataKeysEx.NAVIGATION_CONTEXT, createDiffNavigationContext(actualNumber));
                    }
                    if (ChangeListManager.getInstance(myVcs.getProject()).isFreezedWithNotification(null))
                        return;
                    ShowDiffAction.showDiffForChange(myVcs.getProject(), changes, idx, context);
                }
            }
        });
    }
}
Also used : Task(com.intellij.openapi.progress.Task) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) ShowDiffContext(com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext) Change(com.intellij.openapi.vcs.changes.Change) LinkedList(java.util.LinkedList) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsRevisionNumber(com.intellij.openapi.vcs.history.VcsRevisionNumber) Pair(com.intellij.openapi.util.Pair)

Aggregations

CommittedChangeList (com.intellij.openapi.vcs.versionBrowser.CommittedChangeList)45 ChangeBrowserSettings (com.intellij.openapi.vcs.versionBrowser.ChangeBrowserSettings)8 Nullable (org.jetbrains.annotations.Nullable)8 Change (com.intellij.openapi.vcs.changes.Change)7 ChangesBunch (com.intellij.openapi.vcs.changes.committed.ChangesBunch)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 ChangeList (com.intellij.openapi.vcs.changes.ChangeList)4 NotNull (org.jetbrains.annotations.NotNull)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Project (com.intellij.openapi.project.Project)3 Pair (com.intellij.openapi.util.Pair)3 List (java.util.List)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 Application (com.intellij.openapi.application.Application)2 Task (com.intellij.openapi.progress.Task)2 Ref (com.intellij.openapi.util.Ref)2 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)2 VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)2 ChangesBrowserSettingsEditor (com.intellij.openapi.vcs.versionBrowser.ChangesBrowserSettingsEditor)2 IOException (java.io.IOException)2