Gerrit API: Allow to get file diff with options
Change-Id: Ia743166df6bc5f7bcaf88d426eba3a4bd1d02379 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -74,4 +74,35 @@ class FileApiImpl implements FileApi {
|
||||
throw new RestApiException("Cannot retrieve diff", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiffRequest diffRequest() {
|
||||
return new DiffRequest() {
|
||||
@Override
|
||||
public DiffInfo get() throws RestApiException {
|
||||
return FileApiImpl.this.get(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private DiffInfo get(DiffRequest r) throws RestApiException {
|
||||
GetDiff diff = getDiff.get();
|
||||
if (r.getBase() != null) {
|
||||
diff.setBase(r.getBase());
|
||||
}
|
||||
if (r.getContext() != null) {
|
||||
diff.setContext(r.getContext());
|
||||
}
|
||||
if (r.getIntraline() != null) {
|
||||
diff.setIntraline(r.getIntraline());
|
||||
}
|
||||
if (r.getWhitespace() != null) {
|
||||
diff.setWhitespace(r.getWhitespace());
|
||||
}
|
||||
try {
|
||||
return diff.apply(file).value();
|
||||
} catch (IOException | InvalidChangeOperationException | OrmException e) {
|
||||
throw new RestApiException("Cannot retrieve diff", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,6 +272,21 @@ public class GetDiff implements RestReadView<FileResource> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GetDiff setContext(int context) {
|
||||
this.context = context;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GetDiff setIntraline(boolean intraline) {
|
||||
this.intraline = intraline;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GetDiff setWhitespace(Whitespace whitespace) {
|
||||
this.whitespace = whitespace;
|
||||
return this;
|
||||
}
|
||||
|
||||
private static class Content {
|
||||
final List<ContentEntry> lines;
|
||||
final SparseFileContent fileA;
|
||||
|
||||
Reference in New Issue
Block a user