Search in sources :

Example 6 with VcsHistorySession

use of com.intellij.openapi.vcs.history.VcsHistorySession in project intellij-community by JetBrains.

the class HgHistoryTest method renameShouldPreserveFileHistory.

/**
   * 1. Make initial version of a file (create, add, commit).
   * 2. Rename file (rename, commit).
   * 3. Update file (modify, commit).
   * 4. Get the file history.
   * 5. Verify revision contents and the current revision.
   */
@Test
public void renameShouldPreserveFileHistory() throws Exception {
    int versions = 0;
    fillFile(myProjectDir, new String[] { AFILE }, INITIAL_FILE_CONTENT);
    addAll();
    commitAll("initial content");
    versions++;
    runHgOnProjectRepo("rename", AFILE, BFILE);
    commitAll("file renamed");
    versions++;
    fillFile(myProjectDir, new String[] { BFILE }, UPDATED_FILE_CONTENT);
    commitAll("updated content");
    versions++;
    final VcsHistorySession session = getHistorySession(BFILE);
    final List<VcsFileRevision> revisions = session.getRevisionList();
    loadAllRevisions(revisions);
    assertEquals(revisions.size(), versions);
    assertTrue(session.isCurrentRevision(revisions.get(0).getRevisionNumber()));
    assertEquals(revisions.get(0).getContent(), UPDATED_FILE_CONTENT.getBytes());
    assertEquals(revisions.get(2).getContent(), INITIAL_FILE_CONTENT.getBytes());
}
Also used : VcsHistorySession(com.intellij.openapi.vcs.history.VcsHistorySession) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Test(org.testng.annotations.Test)

Example 7 with VcsHistorySession

use of com.intellij.openapi.vcs.history.VcsHistorySession in project intellij-community by JetBrains.

the class SrcFileAnnotator method loadFromVersionControl.

@Nullable
private byte[] loadFromVersionControl(long date, VirtualFile f) {
    try {
        final AbstractVcs vcs = VcsUtil.getVcsFor(myProject, f);
        if (vcs == null)
            return null;
        final VcsHistoryProvider historyProvider = vcs.getVcsHistoryProvider();
        if (historyProvider == null)
            return null;
        final FilePath filePath = VcsContextFactory.SERVICE.getInstance().createFilePathOn(f);
        final VcsHistorySession session = historyProvider.createSessionFor(filePath);
        if (session == null)
            return null;
        final List<VcsFileRevision> list = session.getRevisionList();
        if (list != null) {
            for (VcsFileRevision revision : list) {
                final Date revisionDate = revision.getRevisionDate();
                if (revisionDate == null) {
                    return null;
                }
                if (revisionDate.getTime() < date) {
                    return revision.loadContent();
                }
            }
        }
    } catch (Exception e) {
        LOG.info(e);
        return null;
    }
    return null;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VcsHistorySession(com.intellij.openapi.vcs.history.VcsHistorySession) VcsHistoryProvider(com.intellij.openapi.vcs.history.VcsHistoryProvider) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) AbstractVcs(com.intellij.openapi.vcs.AbstractVcs) FilesTooBigForDiffException(com.intellij.util.diff.FilesTooBigForDiffException) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with VcsHistorySession

use of com.intellij.openapi.vcs.history.VcsHistorySession in project intellij-community by JetBrains.

the class GitDiffFromHistoryHandler method showDiffForMergeCommit.

private void showDiffForMergeCommit(@NotNull final AnActionEvent event, @NotNull final FilePath filePath, @NotNull final GitFileRevision rev, @NotNull final Collection<String> parents) {
    VcsHistorySession session = event.getData(VcsDataKeys.HISTORY_SESSION);
    List<VcsFileRevision> revisions = session != null ? session.getRevisionList() : null;
    checkIfFileWasTouchedAndFindParentsInBackground(filePath, rev, parents, revisions, new Consumer<MergeCommitPreCheckInfo>() {

        @Override
        public void consume(MergeCommitPreCheckInfo info) {
            if (!info.wasFileTouched()) {
                String message = String.format("There were no changes in %s in this merge commit, besides those which were made in both branches", filePath.getName());
                VcsBalloonProblemNotifier.showOverVersionControlView(GitDiffFromHistoryHandler.this.myProject, message, MessageType.INFO);
            }
            showPopup(event, rev, filePath, info.getParents());
        }
    });
}
Also used : VcsHistorySession(com.intellij.openapi.vcs.history.VcsHistorySession) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision)

Aggregations

VcsHistorySession (com.intellij.openapi.vcs.history.VcsHistorySession)8 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)7 VcsHistoryProvider (com.intellij.openapi.vcs.history.VcsHistoryProvider)3 Nullable (org.jetbrains.annotations.Nullable)3 Project (com.intellij.openapi.project.Project)2 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Test (org.testng.annotations.Test)2 FileHyperlinkInfo (com.intellij.execution.filters.FileHyperlinkInfo)1 HyperlinkInfo (com.intellij.execution.filters.HyperlinkInfo)1 EditorHyperlinkSupport (com.intellij.execution.impl.EditorHyperlinkSupport)1 AllIcons (com.intellij.icons.AllIcons)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Editor (com.intellij.openapi.editor.Editor)1 ColorKey (com.intellij.openapi.editor.colors.ColorKey)1 EditorFontType (com.intellij.openapi.editor.colors.EditorFontType)1 EditorGutterComponentEx (com.intellij.openapi.editor.ex.EditorGutterComponentEx)1