use of org.eclipse.jgit.errors.LargeObjectException in project gerrit by GerritCodeReview.
the class RulesCache method read.
private String read(Project.NameKey project, ObjectId rulesId) throws CompileException {
try (Repository git = gitMgr.openRepository(project)) {
try {
ObjectLoader ldr = git.open(rulesId, Constants.OBJ_BLOB);
byte[] raw = ldr.getCachedBytes(maxSrcBytes);
return RawParseUtils.decode(raw);
} catch (LargeObjectException e) {
throw new CompileException("rules of " + project + " are too large", e);
} catch (RuntimeException | IOException e) {
throw new CompileException("Cannot load rules of " + project, e);
}
} catch (IOException e) {
throw new CompileException("Cannot open repository " + project, e);
}
}
use of org.eclipse.jgit.errors.LargeObjectException in project gitiles by GerritCodeReview.
the class PathServlet method doGetText.
@Override
protected void doGetText(HttpServletRequest req, HttpServletResponse res) throws IOException {
GitilesView view = ViewFilter.getView(req);
Repository repo = ServletUtils.getRepository(req);
try (RevWalk rw = new RevWalk(repo);
WalkResult wr = WalkResult.forPath(rw, view, false)) {
if (wr == null) {
res.setStatus(SC_NOT_FOUND);
return;
}
// which would be bad.
switch(wr.type) {
case SYMLINK:
case REGULAR_FILE:
case EXECUTABLE_FILE:
writeBlobText(req, res, wr);
break;
case TREE:
writeTreeText(req, res, wr);
break;
case GITLINK:
default:
renderTextError(req, res, SC_NOT_FOUND, "Not a file");
break;
}
} catch (LargeObjectException e) {
res.setStatus(SC_INTERNAL_SERVER_ERROR);
}
}
use of org.eclipse.jgit.errors.LargeObjectException in project gerrit by GerritCodeReview.
the class FileContentUtil method downloadContent.
public BinaryResult downloadContent(ProjectState project, ObjectId revstr, String path, @Nullable Integer parent) throws ResourceNotFoundException, IOException {
try (Repository repo = openRepository(project);
RevWalk rw = new RevWalk(repo)) {
String suffix = "new";
RevCommit commit = rw.parseCommit(revstr);
if (parent != null && parent > 0) {
if (commit.getParentCount() == 1) {
suffix = "old";
} else {
suffix = "old" + parent;
}
commit = rw.parseCommit(commit.getParent(parent - 1));
}
ObjectReader reader = rw.getObjectReader();
TreeWalk tw = TreeWalk.forPath(reader, path, commit.getTree());
if (tw == null) {
throw new ResourceNotFoundException();
}
int mode = tw.getFileMode(0).getObjectType();
if (mode != Constants.OBJ_BLOB) {
throw new ResourceNotFoundException();
}
ObjectId id = tw.getObjectId(0);
ObjectLoader obj = repo.open(id, OBJ_BLOB);
byte[] raw;
try {
raw = obj.getCachedBytes(MAX_SIZE);
} catch (LargeObjectException e) {
raw = null;
}
MimeType contentType = registry.getMimeType(path, raw);
return registry.isSafeInline(contentType) ? wrapBlob(path, obj, raw, contentType, suffix) : zipBlob(path, obj, commit, suffix);
}
}
use of org.eclipse.jgit.errors.LargeObjectException in project gerrit by GerritCodeReview.
the class FileContentUtil method getContent.
public BinaryResult getContent(Repository repo, ProjectState project, ObjectId revstr, String path) throws IOException, ResourceNotFoundException {
try (RevWalk rw = new RevWalk(repo)) {
RevCommit commit = rw.parseCommit(revstr);
ObjectReader reader = rw.getObjectReader();
TreeWalk tw = TreeWalk.forPath(reader, path, commit.getTree());
if (tw == null) {
throw new ResourceNotFoundException();
}
org.eclipse.jgit.lib.FileMode mode = tw.getFileMode(0);
ObjectId id = tw.getObjectId(0);
if (mode == org.eclipse.jgit.lib.FileMode.GITLINK) {
return BinaryResult.create(id.name()).setContentType(X_GIT_GITLINK).base64();
}
ObjectLoader obj = repo.open(id, OBJ_BLOB);
byte[] raw;
try {
raw = obj.getCachedBytes(MAX_SIZE);
} catch (LargeObjectException e) {
raw = null;
}
String type;
if (mode == org.eclipse.jgit.lib.FileMode.SYMLINK) {
type = X_GIT_SYMLINK;
} else {
type = registry.getMimeType(path, raw).toString();
type = resolveContentType(project, path, FileMode.FILE, type);
}
return asBinaryResult(raw, obj).setContentType(type).base64();
}
}
use of org.eclipse.jgit.errors.LargeObjectException in project gitiles by GerritCodeReview.
the class BlobSoyData method toSoyData.
public Map<String, Object> toSoyData(String path, ObjectId blobId) throws MissingObjectException, IOException {
Map<String, Object> data = Maps.newHashMapWithExpectedSize(4);
data.put("sha", ObjectId.toString(blobId));
ObjectLoader loader = reader.open(blobId, Constants.OBJ_BLOB);
String content;
try {
byte[] raw = loader.getCachedBytes(MAX_FILE_SIZE);
content = !RawText.isBinary(raw) ? RawParseUtils.decode(raw) : null;
} catch (LargeObjectException.OutOfMemory e) {
throw e;
} catch (LargeObjectException e) {
content = null;
}
if (content != null) {
data.put("lines", prettify(path, content));
if (path != null && path.endsWith(".md")) {
data.put("docUrl", GitilesView.doc().copyFrom(view).toUrl());
}
} else {
data.put("lines", null);
data.put("size", Long.toString(loader.getSize()));
}
if (path != null && view.getRevision().getPeeledType() == OBJ_COMMIT) {
data.put("fileUrl", GitilesView.path().copyFrom(view).toUrl());
data.put("logUrl", GitilesView.log().copyFrom(view).toUrl());
data.put("blameUrl", GitilesView.blame().copyFrom(view).toUrl());
}
return data;
}
Aggregations