use of org.eclipse.jgit.lib.ObjectReader in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method newPatchSet.
protected Change newPatchSet(TestRepository<Repo> repo, Change c) throws Exception {
// Add a new file so the patch set is not a trivial rebase, to avoid default
// Code-Review label copying.
int n = c.currentPatchSetId().get() + 1;
RevCommit commit = repo.parseBody(repo.commit().message("message").add("file" + n, "contents " + n).create());
ChangeControl ctl = changeControlFactory.controlFor(db, c, user);
PatchSetInserter inserter = patchSetFactory.create(ctl, new PatchSet.Id(c.getId(), n), commit).setNotify(NotifyHandling.NONE).setFireRevisionCreated(false).setValidate(false);
try (BatchUpdate bu = updateFactory.create(db, c.getProject(), user, TimeUtil.nowTs());
ObjectInserter oi = repo.getRepository().newObjectInserter();
ObjectReader reader = oi.newReader();
RevWalk rw = new RevWalk(reader)) {
bu.setRepository(repo.getRepository(), rw, oi);
bu.addOp(c.getId(), inserter);
bu.execute();
}
return inserter.getChange();
}
use of org.eclipse.jgit.lib.ObjectReader in project gitiles by GerritCodeReview.
the class DocServlet method doGetHtml.
@Override
protected void doGetHtml(HttpServletRequest req, HttpServletResponse res) throws IOException {
MarkdownConfig cfg = MarkdownConfig.get(getAccess(req).getConfig());
if (!cfg.render) {
res.setStatus(SC_NOT_FOUND);
return;
}
GitilesView view = ViewFilter.getView(req);
Repository repo = ServletUtils.getRepository(req);
try (RevWalk rw = new RevWalk(repo)) {
ObjectReader reader = rw.getObjectReader();
String path = view.getPathPart();
RevTree root;
try {
root = rw.parseTree(view.getRevision().getId());
} catch (IncorrectObjectTypeException e) {
res.setStatus(SC_NOT_FOUND);
return;
}
MarkdownFile srcmd = findFile(rw, root, path);
if (srcmd == null) {
res.setStatus(SC_NOT_FOUND);
return;
}
MarkdownFile navmd = findFile(rw, root, NAVBAR_MD);
String curEtag = etag(srcmd, navmd);
if (etagMatch(req, curEtag)) {
res.setStatus(SC_NOT_MODIFIED);
return;
}
view = view.toBuilder().setPathPart(srcmd.path).build();
try {
srcmd.read(reader, cfg);
if (navmd != null) {
navmd.read(reader, cfg);
}
} catch (LargeObjectException.ExceedsLimit errBig) {
fileTooBig(res, view, errBig);
return;
} catch (IOException err) {
readError(res, view, err);
return;
}
MarkdownToHtml.Builder fmt = MarkdownToHtml.builder().setConfig(cfg).setGitilesView(view).setRequestUri(req.getRequestURI()).setReader(reader).setRootTree(root);
res.setHeader(HttpHeaders.ETAG, curEtag);
showDoc(req, res, view, cfg, fmt, navmd, srcmd);
}
}
use of org.eclipse.jgit.lib.ObjectReader in project gerrit by GerritCodeReview.
the class TreeCreator method readBaseTree.
private DirCache readBaseTree(Repository repository) throws IOException {
try (ObjectReader objectReader = repository.newObjectReader()) {
DirCache dirCache = DirCache.newInCore();
DirCacheBuilder dirCacheBuilder = dirCache.builder();
dirCacheBuilder.addTree(new byte[0], DirCacheEntry.STAGE_0, objectReader, baseCommit.getTree());
dirCacheBuilder.finish();
return dirCache;
}
}
use of org.eclipse.jgit.lib.ObjectReader in project gerrit by GerritCodeReview.
the class AutoMerger method commit.
private RevCommit commit(Repository repo, RevWalk rw, @Nullable InMemoryInserter tmpIns, ObjectInserter ins, String refName, ObjectId tree, RevCommit merge) throws IOException {
rw.parseHeaders(merge);
// For maximum stability, choose a single ident using the committer time of
// the input commit, using the server name and timezone.
PersonIdent ident = new PersonIdent(gerritIdent, merge.getCommitterIdent().getWhen(), gerritIdent.getTimeZone());
CommitBuilder cb = new CommitBuilder();
cb.setAuthor(ident);
cb.setCommitter(ident);
cb.setTreeId(tree);
cb.setMessage("Auto-merge of " + merge.name() + '\n');
for (RevCommit p : merge.getParents()) {
cb.addParentId(p);
}
if (!save) {
checkArgument(tmpIns != null);
try (ObjectReader tmpReader = tmpIns.newReader();
RevWalk tmpRw = new RevWalk(tmpReader)) {
return tmpRw.parseCommit(tmpIns.insert(cb));
}
}
checkArgument(tmpIns == null);
checkArgument(!(ins instanceof InMemoryInserter));
ObjectId commitId = ins.insert(cb);
ins.flush();
RefUpdate ru = repo.updateRef(refName);
ru.setNewObjectId(commitId);
ru.disableRefLog();
ru.forceUpdate();
return rw.parseCommit(commitId);
}
use of org.eclipse.jgit.lib.ObjectReader in project gerrit by GerritCodeReview.
the class NoteDbUpdateManager method openRepo.
private OpenRepo openRepo(Project.NameKey p) throws IOException {
// Closed by OpenRepo#close.
Repository repo = repoManager.openRepository(p);
// Closed by OpenRepo#close.
ObjectInserter ins = repo.newObjectInserter();
// Not closed by OpenRepo#close.
ObjectReader reader = ins.newReader();
try (RevWalk rw = new RevWalk(reader)) {
// Doesn't escape OpenRepo constructor.
return new OpenRepo(repo, rw, ins, new ChainedReceiveCommands(repo), true) {
@Override
public void close() {
reader.close();
super.close();
}
};
}
}
Aggregations