Search in sources :

Example 86 with FilePath

use of com.intellij.openapi.vcs.FilePath 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)

Example 87 with FilePath

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

the class GitMergeUpdater method getFilesOverwrittenByMerge.

// parses the output of merge conflict returning files which would be overwritten by merge. These files will be stashed.
private List<FilePath> getFilesOverwrittenByMerge(@NotNull List<String> mergeOutput) {
    final List<FilePath> paths = new ArrayList<>();
    for (String line : mergeOutput) {
        if (StringUtil.isEmptyOrSpaces(line)) {
            continue;
        }
        if (line.contains("Please, commit your changes or stash them before you can merge")) {
            break;
        }
        line = line.trim();
        final String path;
        try {
            path = myRoot.getPath() + "/" + GitUtil.unescapePath(line);
            final File file = new File(path);
            if (file.exists()) {
                paths.add(VcsUtil.getFilePath(file, false));
            }
        } catch (VcsException e) {
        // just continue
        }
    }
    return paths;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VcsException(com.intellij.openapi.vcs.VcsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 88 with FilePath

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

the class GitSimplePathsBrowser method createBrowser.

@NotNull
private static FilePathChangesTreeList createBrowser(@NotNull Project project, @NotNull Collection<String> absolutePaths) {
    List<FilePath> filePaths = toFilePaths(absolutePaths);
    FilePathChangesTreeList browser = new FilePathChangesTreeList(project, filePaths, false, false, null, null);
    browser.setChangesToDisplay(filePaths);
    return browser;
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) FilePathChangesTreeList(com.intellij.openapi.vcs.changes.ui.FilePathChangesTreeList) NotNull(org.jetbrains.annotations.NotNull)

Example 89 with FilePath

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

the class GitVFSListener method performForceMove.

private void performForceMove(@NotNull List<MovedFileInfo> files) {
    Map<FilePath, MovedFileInfo> filesToMove = map2Map(files, (info) -> Pair.create(VcsUtil.getFilePath(info.myNewPath), info));
    Set<File> toRefresh = newHashSet();
    performBackgroundOperation(filesToMove.keySet(), "Moving Files...", new LongOperationPerRootExecutor() {

        @Override
        public void execute(@NotNull VirtualFile root, @NotNull List<FilePath> files) throws VcsException {
            for (FilePath file : files) {
                GitHandler h = new GitSimpleHandler(myProject, root, GitCommand.MV);
                MovedFileInfo info = filesToMove.get(file);
                h.addParameters("-f", info.myOldPath, info.myNewPath);
                h.runInCurrentThread(null);
                toRefresh.add(new File(info.myOldPath));
                toRefresh.add(new File(info.myNewPath));
            }
        }

        @Override
        public Collection<File> getFilesToRefresh() {
            return toRefresh;
        }
    });
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitSimpleHandler(git4idea.commands.GitSimpleHandler) GitHandler(git4idea.commands.GitHandler) VcsException(com.intellij.openapi.vcs.VcsException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 90 with FilePath

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

the class GithubOpenInBrowserAction method getDataFromHistory.

@Nullable
private static CommitData getDataFromHistory(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    FilePath filePath = e.getData(VcsDataKeys.FILE_PATH);
    VcsFileRevision fileRevision = e.getData(VcsDataKeys.VCS_FILE_REVISION);
    if (project == null || filePath == null || fileRevision == null)
        return null;
    if (!(fileRevision instanceof GitFileRevision))
        return null;
    GitRepository repository = GitUtil.getRepositoryManager(project).getRepositoryForFile(filePath);
    if (repository == null || !GithubUtil.isRepositoryOnGitHub(repository))
        return null;
    return new CommitData(project, repository, fileRevision.getRevisionNumber().asString());
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository) GitFileRevision(git4idea.GitFileRevision) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FilePath (com.intellij.openapi.vcs.FilePath)167 VirtualFile (com.intellij.openapi.vfs.VirtualFile)68 NotNull (org.jetbrains.annotations.NotNull)43 VcsException (com.intellij.openapi.vcs.VcsException)34 File (java.io.File)30 Change (com.intellij.openapi.vcs.changes.Change)26 Nullable (org.jetbrains.annotations.Nullable)22 Project (com.intellij.openapi.project.Project)20 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)15 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)13 FileStatus (com.intellij.openapi.vcs.FileStatus)10 AbstractVcs (com.intellij.openapi.vcs.AbstractVcs)8 GitRepository (git4idea.repo.GitRepository)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Test (org.junit.Test)6 StringUtil (com.intellij.openapi.util.text.StringUtil)5 Logger (com.intellij.openapi.diagnostic.Logger)4