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:
Edwin Kempin
2016-02-09 17:33:59 +01:00
parent 0b7c40fa76
commit a021dbf9fe
3 changed files with 103 additions and 0 deletions

View File

@@ -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);
}
}
}

View File

@@ -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;