use of org.eclipse.jgit.lib.ObjectLoader in project gerrit by GerritCodeReview.
the class ConfigChangeIT method readProjectConfig.
private Config readProjectConfig() throws Exception {
RevWalk rw = testRepo.getRevWalk();
RevTree tree = rw.parseTree(testRepo.getRepository().resolve("HEAD"));
RevObject obj = rw.parseAny(testRepo.get(tree, "project.config"));
ObjectLoader loader = rw.getObjectReader().open(obj);
String text = new String(loader.getCachedBytes(), UTF_8);
Config cfg = new Config();
cfg.fromText(text);
return cfg;
}
use of org.eclipse.jgit.lib.ObjectLoader in project gitiles by GerritCodeReview.
the class RevisionServlet method doGetText.
@Override
protected void doGetText(HttpServletRequest req, HttpServletResponse res) throws IOException {
GitilesView view = ViewFilter.getView(req);
Repository repo = ServletUtils.getRepository(req);
try (ObjectReader reader = repo.newObjectReader()) {
ObjectLoader loader = reader.open(view.getRevision().getId());
if (loader.getType() != OBJ_COMMIT) {
res.setStatus(SC_NOT_FOUND);
} else {
PathServlet.setTypeHeader(res, loader.getType());
try (Writer writer = startRenderText(req, res);
OutputStream out = BaseEncoding.base64().encodingStream(writer)) {
loader.copyTo(out);
}
}
}
}
use of org.eclipse.jgit.lib.ObjectLoader in project gitiles by GerritCodeReview.
the class PathServlet method showSymlink.
private void showSymlink(HttpServletRequest req, HttpServletResponse res, WalkResult wr) throws IOException {
GitilesView view = ViewFilter.getView(req);
Map<String, Object> data = Maps.newHashMap();
ObjectLoader loader = wr.getObjectReader().open(wr.id, OBJ_BLOB);
String target;
try {
target = RawParseUtils.decode(loader.getCachedBytes(TreeSoyData.MAX_SYMLINK_SIZE));
} catch (LargeObjectException.OutOfMemory e) {
throw e;
} catch (LargeObjectException e) {
data.put("sha", ObjectId.toString(wr.id));
data.put("data", null);
data.put("size", Long.toString(loader.getSize()));
renderHtml(req, res, "gitiles.pathDetail", ImmutableMap.of("title", ViewFilter.getView(req).getPathPart(), "breadcrumbs", view.getBreadcrumbs(wr.hasSingleTree), "type", FileType.REGULAR_FILE.toString(), "data", data));
return;
}
String url = resolveTargetUrl(GitilesView.path().copyFrom(view).setPathPart(dirname(view.getPathPart())).build(), target);
data.put("title", view.getPathPart());
data.put("target", target);
if (url != null) {
data.put("targetUrl", url);
}
// TODO(sop): Allow caching files by SHA-1 when no S cookie is sent.
renderHtml(req, res, "gitiles.pathDetail", ImmutableMap.of("title", ViewFilter.getView(req).getPathPart(), "breadcrumbs", view.getBreadcrumbs(wr.hasSingleTree), "type", FileType.SYMLINK.toString(), "data", data));
}
use of org.eclipse.jgit.lib.ObjectLoader 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;
}
use of org.eclipse.jgit.lib.ObjectLoader in project archi-modelrepository-plugin by archi-contribs.
the class MergeConflictHandler method extractModel.
/**
* Extract a model from either our latest commit or their latest online commit
* ref = "refs/head/master" or "origin/master"
* @throws CanceledException
*/
private IArchimateModel extractModel(String ref) throws IOException, CanceledException {
// $NON-NLS-1$ //$NON-NLS-2$
File tmpFolder = new File(System.getProperty("java.io.tmpdir"), "org.archicontribs.modelrepository.tmp");
FileUtils.deleteFolder(tmpFolder);
tmpFolder.mkdirs();
try (Repository repository = Git.open(fArchiRepo.getLocalRepositoryFolder()).getRepository()) {
RevCommit commit = null;
// A RevWalk walks over commits based on some filtering that is defined
try (RevWalk revWalk = new RevWalk(repository)) {
// We are interested in the origin master branch
ObjectId objectID = repository.resolve(ref);
if (objectID != null) {
commit = revWalk.parseCommit(objectID);
}
revWalk.dispose();
}
if (commit == null) {
throw new IOException(Messages.MergeConflictHandler_1);
}
// Walk the tree and get the contents of the commit
try (TreeWalk treeWalk = new TreeWalk(repository)) {
treeWalk.addTree(commit.getTree());
treeWalk.setRecursive(true);
while (treeWalk.next()) {
if (fProgressMonitor != null && fProgressMonitor.isCanceled()) {
throw new CanceledException(Messages.MergeConflictHandler_2);
}
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = repository.open(objectId);
File file = new File(tmpFolder, treeWalk.getPathString());
file.getParentFile().mkdirs();
try (FileOutputStream out = new FileOutputStream(file)) {
loader.copyTo(out);
}
}
}
}
// Load it
GraficoModelImporter importer = new GraficoModelImporter(tmpFolder);
IArchimateModel model = importer.importAsModel();
FileUtils.deleteFolder(tmpFolder);
return model;
}
Aggregations