Search in sources :

Example 1 with SVNDiffParser

use of org.rstudio.studio.client.workbench.views.vcs.svn.SVNDiffParser in project rstudio by rstudio.

the class SVNReviewPresenter method updateDiff.

private void updateDiff() {
    view_.hideSizeWarning();
    final ArrayList<StatusAndPath> paths = view_.getChangelistTable().getSelectedItems();
    if (paths.size() != 1) {
        clearDiff();
        return;
    }
    final StatusAndPath item = paths.get(0);
    if (!item.getPath().equals(currentFilename_)) {
        clearDiff();
        currentFilename_ = item.getPath();
    }
    // bail if this is an undiffable status
    if (undiffableStatuses_.contains(item.getStatus()))
        return;
    diffInvalidation_.invalidate();
    final Token token = diffInvalidation_.getInvalidationToken();
    server_.svnDiffFile(item.getPath(), view_.getContextLines().getValue(), overrideSizeWarning_, new SimpleRequestCallback<DiffResult>("Diff Error") {

        @Override
        public void onResponseReceived(DiffResult diffResult) {
            if (token.isInvalid())
                return;
            String response = diffResult.getDecodedValue();
            // Use lastResponse_ to prevent unnecessary flicker
            if (response.equals(currentResponse_))
                return;
            currentResponse_ = response;
            currentEncoding_ = diffResult.getSourceEncoding();
            SVNDiffParser parser = new SVNDiffParser(response);
            parser.nextFilePair();
            ArrayList<ChunkOrLine> allLines = new ArrayList<ChunkOrLine>();
            activeChunks_.clear();
            for (DiffChunk chunk; null != (chunk = parser.nextChunk()); ) {
                if (!chunk.shouldIgnore()) {
                    activeChunks_.add(chunk);
                    allLines.add(new ChunkOrLine(chunk));
                }
                for (Line line : chunk.getLines()) allLines.add(new ChunkOrLine(line));
            }
            view_.getLineTableDisplay().setShowActions(!"?".equals(item.getStatus()));
            view_.setData(allLines);
        }

        @Override
        public void onError(ServerError error) {
            JSONNumber size = error.getClientInfo().isNumber();
            if (size != null)
                view_.showSizeWarning((long) size.doubleValue());
            else
                super.onError(error);
        }
    });
}
Also used : SVNDiffParser(org.rstudio.studio.client.workbench.views.vcs.svn.SVNDiffParser) StatusAndPath(org.rstudio.studio.client.common.vcs.StatusAndPath) ServerError(org.rstudio.studio.client.server.ServerError) ArrayList(java.util.ArrayList) Token(org.rstudio.core.client.Invalidation.Token) JSONNumber(com.google.gwt.json.client.JSONNumber) DiffResult(org.rstudio.studio.client.common.vcs.DiffResult)

Aggregations

JSONNumber (com.google.gwt.json.client.JSONNumber)1 ArrayList (java.util.ArrayList)1 Token (org.rstudio.core.client.Invalidation.Token)1 DiffResult (org.rstudio.studio.client.common.vcs.DiffResult)1 StatusAndPath (org.rstudio.studio.client.common.vcs.StatusAndPath)1 ServerError (org.rstudio.studio.client.server.ServerError)1 SVNDiffParser (org.rstudio.studio.client.workbench.views.vcs.svn.SVNDiffParser)1