Search in sources :

Example 1 with GitFileRevision

use of git4idea.GitFileRevision in project intellij-community by JetBrains.

the class GitAnnotationProvider method annotate.

@NotNull
@Override
public FileAnnotation annotate(@NotNull final FilePath path, @NotNull final VcsRevisionNumber revision) throws VcsException {
    GitFileRevision fileRevision = new GitFileRevision(myProject, path, (GitRevisionNumber) revision);
    VcsVirtualFile file = new VcsVirtualFile(path.getPath(), fileRevision, VcsFileSystem.getInstance());
    return annotate(path, revision, file);
}
Also used : VcsVirtualFile(com.intellij.openapi.vcs.vfs.VcsVirtualFile) GitFileRevision(git4idea.GitFileRevision) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GitFileRevision

use of git4idea.GitFileRevision in project intellij-community by JetBrains.

the class GitFileAnnotation method getPreviousFileRevisionProvider.

@Nullable
@Override
public PreviousFileRevisionProvider getPreviousFileRevisionProvider() {
    return new PreviousFileRevisionProvider() {

        @Nullable
        @Override
        public VcsFileRevision getPreviousRevision(int lineNumber) {
            LineInfo lineInfo = getLineInfo(lineNumber);
            if (lineInfo == null)
                return null;
            VcsFileRevision previousFileRevision = lineInfo.getPreviousFileRevision();
            if (previousFileRevision != null)
                return previousFileRevision;
            GitRevisionNumber revisionNumber = lineInfo.getRevisionNumber();
            if (myRevisions != null && myRevisionMap != null && myRevisionMap.contains(revisionNumber)) {
                int index = myRevisionMap.get(revisionNumber);
                if (index + 1 < myRevisions.size()) {
                    return myRevisions.get(index + 1);
                }
            }
            return null;
        }

        @Nullable
        @Override
        public VcsFileRevision getLastRevision() {
            if (myBaseRevision instanceof GitRevisionNumber) {
                return new GitFileRevision(myProject, VcsUtil.getFilePath(myFile), (GitRevisionNumber) myBaseRevision);
            } else {
                return ContainerUtil.getFirstItem(getRevisions());
            }
        }
    };
}
Also used : GitRevisionNumber(git4idea.GitRevisionNumber) GitFileRevision(git4idea.GitFileRevision) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with GitFileRevision

use of git4idea.GitFileRevision 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 4 with GitFileRevision

use of git4idea.GitFileRevision in project intellij-community by JetBrains.

the class GitDiffFromHistoryHandler method showDiffForOne.

@Override
public void showDiffForOne(@NotNull AnActionEvent e, @NotNull Project project, @NotNull FilePath filePath, @NotNull VcsFileRevision previousRevision, @NotNull VcsFileRevision revision) {
    GitFileRevision rev = (GitFileRevision) revision;
    Collection<String> parents = rev.getParents();
    if (parents.size() < 2) {
        super.showDiffForOne(e, project, filePath, previousRevision, revision);
    } else {
        // merge
        showDiffForMergeCommit(e, filePath, rev, parents);
    }
}
Also used : GitFileRevision(git4idea.GitFileRevision)

Example 5 with GitFileRevision

use of git4idea.GitFileRevision in project intellij-community by JetBrains.

the class GitMergeProvider method loadRevisions.

@Override
@NotNull
public MergeData loadRevisions(@NotNull final VirtualFile file) throws VcsException {
    final MergeData mergeData = new MergeData();
    final VirtualFile root = GitUtil.getGitRoot(file);
    final FilePath path = VcsUtil.getFilePath(file.getPath());
    VcsRunnable runnable = new VcsRunnable() {

        @Override
        @SuppressWarnings({ "ConstantConditions" })
        public void run() throws VcsException {
            GitFileRevision original = new GitFileRevision(myProject, path, new GitRevisionNumber(":" + ORIGINAL_REVISION_NUM));
            GitFileRevision current = new GitFileRevision(myProject, path, new GitRevisionNumber(":" + yoursRevision(root)));
            GitFileRevision last = new GitFileRevision(myProject, path, new GitRevisionNumber(":" + theirsRevision(root)));
            try {
                try {
                    mergeData.ORIGINAL = original.getContent();
                } catch (Exception ex) {
                    /// This could happen in case if rebasing.
                    try {
                        mergeData.ORIGINAL = file.contentsToByteArray();
                    } catch (IOException e) {
                        LOG.error(e);
                        mergeData.ORIGINAL = ArrayUtil.EMPTY_BYTE_ARRAY;
                    }
                }
                mergeData.CURRENT = loadRevisionCatchingErrors(current);
                mergeData.LAST = loadRevisionCatchingErrors(last);
                // TODO: can be done once for a root
                mergeData.CURRENT_REVISION_NUMBER = findCurrentRevisionNumber(root);
                mergeData.LAST_REVISION_NUMBER = findLastRevisionNumber(root);
                mergeData.ORIGINAL_REVISION_NUMBER = findOriginalRevisionNumber(root, mergeData.CURRENT_REVISION_NUMBER, mergeData.LAST_REVISION_NUMBER);
                Trinity<String, String, String> blobs = getAffectedBlobs(root, file);
                mergeData.CURRENT_FILE_PATH = getBlobPathInRevision(root, file, blobs.getFirst(), mergeData.CURRENT_REVISION_NUMBER);
                mergeData.ORIGINAL_FILE_PATH = getBlobPathInRevision(root, file, blobs.getSecond(), mergeData.ORIGINAL_REVISION_NUMBER);
                mergeData.LAST_FILE_PATH = getBlobPathInRevision(root, file, blobs.getThird(), mergeData.LAST_REVISION_NUMBER);
            } catch (IOException e) {
                throw new IllegalStateException("Failed to load file content", e);
            }
        }
    };
    VcsUtil.runVcsProcessWithProgress(runnable, GitBundle.message("merge.load.files"), false, myProject);
    return mergeData;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePath(com.intellij.openapi.vcs.FilePath) VcsRunnable(com.intellij.vcsUtil.VcsRunnable) GitRevisionNumber(git4idea.GitRevisionNumber) GitFileRevision(git4idea.GitFileRevision) MergeData(com.intellij.openapi.vcs.merge.MergeData) IOException(java.io.IOException) VcsException(com.intellij.openapi.vcs.VcsException) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GitFileRevision (git4idea.GitFileRevision)9 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)5 NotNull (org.jetbrains.annotations.NotNull)4 FilePath (com.intellij.openapi.vcs.FilePath)3 Nullable (org.jetbrains.annotations.Nullable)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 GitRevisionNumber (git4idea.GitRevisionNumber)2 Project (com.intellij.openapi.project.Project)1 VcsException (com.intellij.openapi.vcs.VcsException)1 Change (com.intellij.openapi.vcs.changes.Change)1 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)1 MergeData (com.intellij.openapi.vcs.merge.MergeData)1 CommittedChangeList (com.intellij.openapi.vcs.versionBrowser.CommittedChangeList)1 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)1 VcsRunnable (com.intellij.vcsUtil.VcsRunnable)1 GitContentRevision (git4idea.GitContentRevision)1 GitRepository (git4idea.repo.GitRepository)1 File (java.io.File)1 IOException (java.io.IOException)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1