Search in sources :

Example 1 with GitLineHandlerAdapter

use of git4idea.commands.GitLineHandlerAdapter in project intellij-community by JetBrains.

the class GitMergeProvider method doGetBlobPathInRevision.

@Nullable
private FilePath doGetBlobPathInRevision(@NotNull final VirtualFile root, @NotNull final String blob, @NotNull VcsRevisionNumber revision, @Nullable VirtualFile file) {
    final FilePath[] result = new FilePath[1];
    final boolean[] pathAmbiguous = new boolean[1];
    GitLineHandler h = new GitLineHandler(myProject, root, GitCommand.LS_TREE);
    h.addParameters(revision.asString());
    if (file != null) {
        h.endOptions();
        h.addRelativeFiles(Collections.singleton(file));
    } else {
        h.addParameters("-r");
        h.endOptions();
    }
    h.addLineListener(new GitLineHandlerAdapter() {

        @Override
        public void onLineAvailable(String line, Key outputType) {
            if (outputType != ProcessOutputTypes.STDOUT)
                return;
            if (!line.contains(blob))
                return;
            if (pathAmbiguous[0])
                return;
            try {
                StringScanner s = new StringScanner(line);
                // permissions
                s.spaceToken();
                // type
                String type = s.spaceToken();
                // blob
                String recordBlob = s.tabToken();
                FilePath file = VcsUtil.getFilePath(root, GitUtil.unescapePath(s.line()));
                if (!"blob".equals(type))
                    return;
                if (!blob.equals(recordBlob))
                    return;
                if (result[0] == null) {
                    result[0] = file;
                } else {
                    // there are multiple files with given content in this revision.
                    // we don't know which is right, so do not return any
                    pathAmbiguous[0] = true;
                }
            } catch (VcsException e) {
                LOG.warn(e);
            }
        }
    });
    h.runInCurrentThread(null);
    if (pathAmbiguous[0])
        return null;
    return result[0];
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) GitLineHandler(git4idea.commands.GitLineHandler) VcsException(com.intellij.openapi.vcs.VcsException) GitLineHandlerAdapter(git4idea.commands.GitLineHandlerAdapter) StringScanner(git4idea.util.StringScanner) Key(com.intellij.openapi.util.Key) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Key (com.intellij.openapi.util.Key)1 FilePath (com.intellij.openapi.vcs.FilePath)1 VcsException (com.intellij.openapi.vcs.VcsException)1 GitLineHandler (git4idea.commands.GitLineHandler)1 GitLineHandlerAdapter (git4idea.commands.GitLineHandlerAdapter)1 StringScanner (git4idea.util.StringScanner)1 Nullable (org.jetbrains.annotations.Nullable)1