Add parent parameter to GetContent
PolyGerrit has a hard time showing the diff view for binary files like images. To get the base, it has to request it separately using the parent commit SHA1, which is expensive. This commit adds a 'parent' parameter to GetContent in the same way that it is done for DownloadContent. This way, PolyGerrit can use the same endpoint and avoid expensive permission checks since users who can see a change are also allowed to see the base commit. Change-Id: Id6b4d0ea994282d9b4942f9ec1a8f4071a1064b1
This commit is contained in:
@@ -21,6 +21,7 @@ import static com.google.gerrit.extensions.api.changes.SubmittedTogetherOption.N
|
||||
import static com.google.gerrit.reviewdb.client.Patch.COMMIT_MSG;
|
||||
import static com.google.gerrit.reviewdb.client.Patch.MERGE_LIST;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.eclipse.jgit.lib.Constants.HEAD;
|
||||
import static org.eclipse.jgit.lib.Constants.R_TAGS;
|
||||
@@ -110,6 +111,7 @@ import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -1237,4 +1239,18 @@ public abstract class AbstractDaemonTest {
|
||||
projectsToWatch.add(pwi);
|
||||
gApi.accounts().self().setWatchedProjects(projectsToWatch);
|
||||
}
|
||||
|
||||
protected void assertContent(PushOneCommit.Result pushResult, String path, String expectedContent)
|
||||
throws Exception {
|
||||
BinaryResult bin =
|
||||
gApi.changes()
|
||||
.id(pushResult.getChangeId())
|
||||
.revision(pushResult.getCommit().name())
|
||||
.file(path)
|
||||
.content();
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
bin.writeTo(os);
|
||||
String res = new String(os.toByteArray(), UTF_8);
|
||||
assertThat(res).isEqualTo(expectedContent);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user