Search in sources :

Example 36 with VcsFileRevision

use of com.intellij.openapi.vcs.history.VcsFileRevision 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 37 with VcsFileRevision

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

the class MergeSourceDetailsAction method enabled.

private boolean enabled(final AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null)
        return false;
    final VirtualFile revisionVirtualFile = e.getData(VcsDataKeys.VCS_VIRTUAL_FILE);
    if (revisionVirtualFile == null)
        return false;
    final VcsFileRevision revision = e.getData(VcsDataKeys.VCS_FILE_REVISION);
    if (revision == null)
        return false;
    if (!(revision instanceof SvnFileRevision))
        return false;
    return !((SvnFileRevision) revision).getMergeSources().isEmpty();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision)

Example 38 with VcsFileRevision

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

the class GitCommittedChangeListProvider method getOneList.

@Override
public Pair<CommittedChangeList, FilePath> getOneList(final VirtualFile file, final VcsRevisionNumber number) throws VcsException {
    FilePath filePath = VcsUtil.getFilePath(file);
    final List<GitHeavyCommit> gitCommits = GitHistoryUtils.commitsDetails(myProject, filePath, new SymbolicRefs(), Collections.singletonList(number.asString()));
    if (gitCommits.size() != 1) {
        return null;
    }
    final GitHeavyCommit gitCommit = gitCommits.get(0);
    CommittedChangeList commit = new GitCommittedChangeList(gitCommit.getDescription() + " (" + gitCommit.getShortHash().getString() + ")", gitCommit.getDescription(), gitCommit.getAuthor(), (GitRevisionNumber) number, new Date(gitCommit.getAuthorTime()), gitCommit.getChanges(), assertNotNull(GitVcs.getInstance(myProject)), true);
    final Collection<Change> changes = commit.getChanges();
    if (changes.size() == 1) {
        Change change = changes.iterator().next();
        return Pair.create(commit, ChangesUtil.getFilePath(change));
    }
    for (Change change : changes) {
        if (change.getAfterRevision() != null && FileUtil.filesEqual(filePath.getIOFile(), change.getAfterRevision().getFile().getIOFile())) {
            return Pair.create(commit, filePath);
        }
    }
    final String afterTime = "--after=" + GitUtil.gitTime(gitCommit.getDate());
    final List<VcsFileRevision> history = GitHistoryUtils.history(myProject, filePath, (VirtualFile) null, afterTime);
    if (history.isEmpty()) {
        return Pair.create(commit, filePath);
    }
    return Pair.create(commit, ((GitFileRevision) history.get(history.size() - 1)).getPath());
}
Also used : SymbolicRefs(git4idea.history.browser.SymbolicRefs) GitHeavyCommit(git4idea.history.browser.GitHeavyCommit) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) Change(com.intellij.openapi.vcs.changes.Change) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision)

Example 39 with VcsFileRevision

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

the class GitHistoryUtilsTest method testCyclicRename.

// Inspired by IDEA-89347
@Test
public void testCyclicRename() throws Exception {
    List<TestCommit> commits = new ArrayList<>();
    File source = mkdir("source");
    File initialFile = touch("source/PostHighlightingPass.java", "Initial content");
    String initMessage = "Created PostHighlightingPass.java in source";
    addCommit(initMessage);
    String hash = last();
    commits.add(new TestCommit(hash, initMessage, initialFile.getPath()));
    String filePath = initialFile.getPath();
    commits.add(modify(filePath));
    TestCommit commit = move(filePath, mkdir("codeInside-impl"), "Moved from source to codeInside-impl");
    filePath = commit.myPath;
    commits.add(commit);
    commits.add(modify(filePath));
    commit = move(filePath, mkdir("codeInside"), "Moved from codeInside-impl to codeInside");
    filePath = commit.myPath;
    commits.add(commit);
    commits.add(modify(filePath));
    commit = move(filePath, mkdir("lang-impl"), "Moved from codeInside to lang-impl");
    filePath = commit.myPath;
    commits.add(commit);
    commits.add(modify(filePath));
    commit = move(filePath, source, "Moved from lang-impl back to source");
    filePath = commit.myPath;
    commits.add(commit);
    commits.add(modify(filePath));
    commit = move(filePath, mkdir("java"), "Moved from source to java");
    filePath = commit.myPath;
    commits.add(commit);
    commits.add(modify(filePath));
    Collections.reverse(commits);
    VirtualFile vFile = VcsUtil.getVirtualFileWithRefresh(new File(filePath));
    assertNotNull(vFile);
    List<VcsFileRevision> history = GitHistoryUtils.history(myProject, VcsUtil.getFilePath(vFile));
    assertEquals("History size doesn't match. Actual history: \n" + toReadable(history), commits.size(), history.size());
    assertEquals("History is different.", toReadable(commits), toReadable(history));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Test(org.testng.annotations.Test) GitSingleRepoTest(git4idea.test.GitSingleRepoTest)

Example 40 with VcsFileRevision

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

the class GitHistoryUtilsTest method toReadable.

@NotNull
private String toReadable(@NotNull Collection<VcsFileRevision> history) {
    int maxSubjectLength = findMaxLength(history, new Function<VcsFileRevision, String>() {

        @Override
        public String fun(VcsFileRevision revision) {
            return revision.getCommitMessage();
        }
    });
    StringBuilder sb = new StringBuilder();
    for (VcsFileRevision revision : history) {
        GitFileRevision rev = (GitFileRevision) revision;
        String relPath = FileUtil.getRelativePath(new File(myProjectPath), rev.getPath().getIOFile());
        sb.append(String.format("%s  %-" + maxSubjectLength + "s  %s%n", getShortHash(rev.getHash()), rev.getCommitMessage(), relPath));
    }
    return sb.toString();
}
Also used : GitFileRevision(git4idea.GitFileRevision) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)44 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 Nullable (org.jetbrains.annotations.Nullable)13 FilePath (com.intellij.openapi.vcs.FilePath)12 Project (com.intellij.openapi.project.Project)10 VcsHistoryProvider (com.intellij.openapi.vcs.history.VcsHistoryProvider)8 VcsHistorySession (com.intellij.openapi.vcs.history.VcsHistorySession)7 VcsRevisionNumber (com.intellij.openapi.vcs.history.VcsRevisionNumber)7 VcsKey (com.intellij.openapi.vcs.VcsKey)5 VcsAbstractHistorySession (com.intellij.openapi.vcs.history.VcsAbstractHistorySession)5 VcsAppendableHistorySessionPartner (com.intellij.openapi.vcs.history.VcsAppendableHistorySessionPartner)5 Semaphore (com.intellij.util.concurrency.Semaphore)5 GitFileRevision (git4idea.GitFileRevision)5 Test (org.junit.Test)5 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)4 NotNull (org.jetbrains.annotations.NotNull)4 Annotation (com.intellij.cvsSupport2.cvsoperations.cvsAnnotate.Annotation)3 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)3 FileAnnotation (com.intellij.openapi.vcs.annotate.FileAnnotation)3 HashMap (com.intellij.util.containers.HashMap)3