Map /diff REST API result with JSNI
Define all members of the /diff API as JSNI glue so the result can be trivially accepted within the GWT UI. This change includes a DiffApi helper to build the request. has_skip() can be used to identify files where there is missing context and syntax highlighting might not work correctly. text_a() and text_b() are example placeholders to recreate a file from available lines. Performing layout with CodeMirror or another UI system may be more complex than these functions. Change-Id: Ie519a24725576e73b6a5ffec0326ceb30b090add
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.client.diff;
|
||||
|
||||
import com.google.gerrit.client.changes.ChangeApi;
|
||||
import com.google.gerrit.client.rpc.RestApi;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
public class DiffApi {
|
||||
public enum IgnoreWhitespace {
|
||||
NONE, TRAILING, CHANGED, ALL;
|
||||
};
|
||||
|
||||
public static DiffApi diff(PatchSet.Id id, String path) {
|
||||
return new DiffApi(ChangeApi.revision(id)
|
||||
.view("files").id(path)
|
||||
.view("diff"));
|
||||
}
|
||||
|
||||
private final RestApi call;
|
||||
|
||||
private DiffApi(RestApi call) {
|
||||
this.call = call;
|
||||
}
|
||||
|
||||
public DiffApi base(PatchSet.Id id) {
|
||||
call.addParameter("base", id.get());
|
||||
return this;
|
||||
}
|
||||
|
||||
public DiffApi ignoreWhitespace(IgnoreWhitespace w) {
|
||||
if (w != null && w != IgnoreWhitespace.NONE) {
|
||||
call.addParameter("ignore-whitespace", w);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public DiffApi intraline() {
|
||||
call.addParameterTrue("intraline");
|
||||
return this;
|
||||
}
|
||||
|
||||
public DiffApi wholeFile() {
|
||||
call.addParameter("context", "ALL");
|
||||
return this;
|
||||
}
|
||||
|
||||
public DiffApi context(int lines) {
|
||||
call.addParameter("context", lines);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void get(AsyncCallback<DiffInfo> cb) {
|
||||
call.get(cb);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user