Search in sources :

Example 26 with CommittedChangeList

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

the class GitDiffProvider method createFileContent.

/**
   * {@inheritDoc}
   */
@Nullable
public ContentRevision createFileContent(VcsRevisionNumber revisionNumber, VirtualFile selectedFile) {
    if (selectedFile.isDirectory()) {
        return null;
    }
    final String path = selectedFile.getPath();
    if (GitUtil.gitRootOrNull(selectedFile) == null) {
        return null;
    }
    // faster, if there were no renames
    FilePath filePath = VcsUtil.getFilePath(path);
    try {
        final CommittedChangesProvider committedChangesProvider = GitVcs.getInstance(myProject).getCommittedChangesProvider();
        final Pair<CommittedChangeList, FilePath> pair = committedChangesProvider.getOneList(selectedFile, revisionNumber);
        if (pair != null) {
            return GitContentRevision.createRevision(pair.getSecond(), revisionNumber, myProject, selectedFile.getCharset());
        }
    } catch (VcsException e) {
        GitVcs.getInstance(myProject).showErrors(Collections.singletonList(e), GitBundle.message("diff.find.error", path));
    }
    try {
        for (VcsFileRevision f : GitHistoryUtils.history(myProject, filePath)) {
            GitFileRevision gitRevision = (GitFileRevision) f;
            if (f.getRevisionNumber().equals(revisionNumber)) {
                return GitContentRevision.createRevision(gitRevision.getPath(), revisionNumber, myProject, selectedFile.getCharset());
            }
        }
        GitContentRevision candidate = (GitContentRevision) GitContentRevision.createRevision(filePath, revisionNumber, myProject, selectedFile.getCharset());
        try {
            candidate.getContent();
            return candidate;
        } catch (VcsException e) {
        // file does not exists
        }
    } catch (VcsException e) {
        GitVcs.getInstance(myProject).showErrors(Collections.singletonList(e), GitBundle.message("diff.find.error", path));
    }
    return null;
}
Also used : GitFileRevision(git4idea.GitFileRevision) GitContentRevision(git4idea.GitContentRevision) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with CommittedChangeList

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

the class ChangeListDetailsAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getRequiredData(PROJECT);
    ChangeList[] changeLists = e.getRequiredData(CHANGE_LISTS);
    showDetailsPopup(project, (CommittedChangeList) changeLists[0]);
}
Also used : Project(com.intellij.openapi.project.Project) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) ChangeList(com.intellij.openapi.vcs.changes.ChangeList)

Example 28 with CommittedChangeList

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

the class ChangesBrowserDialog method initDialog.

private void initDialog(final Project project, final CommittedChangesTableModel changes, final Mode mode) {
    myProject = project;
    myChanges = changes;
    myMode = mode;
    setTitle(VcsBundle.message("dialog.title.changes.browser"));
    setCancelButtonText(CommonBundle.getCloseButtonText());
    final ModalityState currentState = ModalityState.current();
    if ((mode != Mode.Choose) && (ModalityState.NON_MODAL.equals(currentState))) {
        setModal(false);
    }
    myAppender = new AsynchConsumer<List<CommittedChangeList>>() {

        public void finished() {
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    if (ChangesBrowserDialog.this.isShowing()) {
                        myCommittedChangesBrowser.stopLoading();
                    }
                }
            });
        }

        public void consume(final List<CommittedChangeList> committedChangeLists) {
            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    if (ChangesBrowserDialog.this.isShowing()) {
                        final boolean selectFirst = (myChanges.getRowCount() == 0) && (!committedChangeLists.isEmpty());
                        myChanges.addRows(committedChangeLists);
                        if (selectFirst) {
                            myCommittedChangesBrowser.selectFirstIfAny();
                        }
                    }
                }
            });
        }
    };
    init();
    if (myInitRunnable != null) {
        new AdjustComponentWhenShown() {

            @Override
            protected boolean init() {
                myInitRunnable.consume(ChangesBrowserDialog.this);
                return true;
            }
        }.install(myCommittedChangesBrowser);
    }
}
Also used : CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) ModalityState(com.intellij.openapi.application.ModalityState) List(java.util.List) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) AdjustComponentWhenShown(com.intellij.util.ui.AdjustComponentWhenShown)

Example 29 with CommittedChangeList

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

the class ChangesCacheFile method readChangesInterval.

private List<CommittedChangeList> readChangesInterval(final long indexOffset, final int number) throws IOException {
    openStreams();
    try {
        IndexEntry[] entries = readIndexEntriesByOffset(indexOffset, number);
        if (entries.length == 0) {
            return Collections.emptyList();
        }
        final List<CommittedChangeList> result = new ArrayList<>();
        for (IndexEntry entry : entries) {
            final CommittedChangeList changeList = loadChangeListAt(entry.offset);
            result.add(changeList);
        }
        return result;
    } finally {
        closeStreams();
    }
}
Also used : CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList)

Example 30 with CommittedChangeList

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

the class ChangesCacheFile method writeChanges.

public List<CommittedChangeList> writeChanges(final List<CommittedChangeList> changes, @Nullable final List<Boolean> present) throws IOException {
    assert present == null || present.size() == changes.size();
    List<CommittedChangeList> result = new ArrayList<>(changes.size());
    boolean wasEmpty = isEmpty();
    openStreams();
    try {
        if (wasEmpty) {
            myHeaderLoaded = true;
            writeHeader();
        }
        myStream.seek(myStream.length());
        IndexEntry[] entries = readLastIndexEntries(0, changes.size());
        final Iterator<Boolean> iterator = present == null ? null : present.iterator();
        for (CommittedChangeList list : changes) {
            boolean duplicate = false;
            for (IndexEntry entry : entries) {
                if (list.getCommitDate().getTime() == entry.date && list.getNumber() == entry.number) {
                    duplicate = true;
                    break;
                }
            }
            if (duplicate) {
                debug("Skipping duplicate changelist " + list.getNumber());
                continue;
            }
            debug("Writing incoming changelist " + list.getNumber());
            result.add(list);
            long position = myStream.getFilePointer();
            //noinspection unchecked
            myChangesProvider.writeChangeList(myStream, list);
            updateCachedRange(list);
            writeIndexEntry(list.getNumber(), list.getCommitDate().getTime(), position, present == null ? false : iterator.next());
            myIncomingCount++;
        }
        writeHeader();
        myHeaderLoaded = true;
    } finally {
        closeStreams();
    }
    return result;
}
Also used : CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList)

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