use of org.eclipse.jgit.revwalk.RevObject in project gerrit by GerritCodeReview.
the class ReceiveCommits method parseCreate.
private void parseCreate(ReceiveCommand cmd) {
RevObject obj;
try {
obj = rp.getRevWalk().parseAny(cmd.getNewId());
} catch (IOException err) {
logError("Invalid object " + cmd.getNewId().name() + " for " + cmd.getRefName() + " creation", err);
reject(cmd, "invalid object");
return;
}
logDebug("Creating {}", cmd);
if (isHead(cmd) && !isCommit(cmd)) {
return;
}
RefControl ctl = projectControl.controlForRef(cmd.getRefName());
if (ctl.canCreate(db, rp.getRepository(), obj)) {
if (!validRefOperation(cmd)) {
return;
}
validateNewCommits(ctl, cmd);
actualCommands.add(cmd);
} else {
reject(cmd, "prohibited by Gerrit: create access denied for " + cmd.getRefName());
}
}
use of org.eclipse.jgit.revwalk.RevObject in project gerrit by GerritCodeReview.
the class ProjectConfigTest method text.
private String text(RevCommit rev, String path) throws Exception {
RevObject blob = util.get(rev.getTree(), path);
byte[] data = db.open(blob).getCachedBytes(Integer.MAX_VALUE);
return RawParseUtils.decode(data);
}
use of org.eclipse.jgit.revwalk.RevObject in project gerrit by GerritCodeReview.
the class PatchListLoader method readPatchList.
public PatchList readPatchList(Repository repo, RevWalk rw, ObjectInserter ins) throws IOException, PatchListNotAvailableException {
ObjectReader reader = rw.getObjectReader();
checkArgument(reader.getCreatedFromInserter() == ins);
RawTextComparator cmp = comparatorFor(key.getWhitespace());
try (DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE)) {
RevCommit b = rw.parseCommit(key.getNewId());
RevObject a = aFor(key, repo, rw, ins, b);
if (a == null) {
// TODO(sop) Remove this case.
// This is an octopus merge commit which should be compared against the
// auto-merge. However since we don't support computing the auto-merge
// for octopus merge commits, we fall back to diffing against the first
// parent, even though this wasn't what was requested.
//
ComparisonType comparisonType = ComparisonType.againstParent(1);
PatchListEntry[] entries = new PatchListEntry[2];
entries[0] = newCommitMessage(cmp, reader, null, b);
entries[1] = newMergeList(cmp, reader, null, b, comparisonType);
return new PatchList(a, b, true, comparisonType, entries);
}
ComparisonType comparisonType = getComparisonType(a, b);
RevCommit aCommit = a instanceof RevCommit ? (RevCommit) a : null;
RevTree aTree = rw.parseTree(a);
RevTree bTree = b.getTree();
df.setReader(reader, repo.getConfig());
df.setDiffComparator(cmp);
df.setDetectRenames(true);
List<DiffEntry> diffEntries = df.scan(aTree, bTree);
Set<String> paths = null;
if (key.getOldId() != null && b.getParentCount() == 1) {
PatchListKey newKey = PatchListKey.againstDefaultBase(key.getNewId(), key.getWhitespace());
PatchListKey oldKey = PatchListKey.againstDefaultBase(key.getOldId(), key.getWhitespace());
paths = Stream.concat(patchListCache.get(newKey, project).getPatches().stream(), patchListCache.get(oldKey, project).getPatches().stream()).map(PatchListEntry::getNewName).collect(toSet());
}
int cnt = diffEntries.size();
List<PatchListEntry> entries = new ArrayList<>();
entries.add(newCommitMessage(cmp, reader, comparisonType.isAgainstParentOrAutoMerge() ? null : aCommit, b));
boolean isMerge = b.getParentCount() > 1;
if (isMerge) {
entries.add(newMergeList(cmp, reader, comparisonType.isAgainstParentOrAutoMerge() ? null : aCommit, b, comparisonType));
}
for (int i = 0; i < cnt; i++) {
DiffEntry e = diffEntries.get(i);
if (paths == null || paths.contains(e.getNewPath()) || paths.contains(e.getOldPath())) {
FileHeader fh = toFileHeader(key, df, e);
long oldSize = getFileSize(reader, e.getOldMode(), e.getOldPath(), aTree);
long newSize = getFileSize(reader, e.getNewMode(), e.getNewPath(), bTree);
entries.add(newEntry(aTree, fh, newSize, newSize - oldSize));
}
}
return new PatchList(a, b, isMerge, comparisonType, entries.toArray(new PatchListEntry[entries.size()]));
}
}
use of org.eclipse.jgit.revwalk.RevObject in project gitiles by GerritCodeReview.
the class RevisionServlet method doGetJson.
@Override
protected void doGetJson(HttpServletRequest req, HttpServletResponse res) throws IOException {
GitilesView view = ViewFilter.getView(req);
Repository repo = ServletUtils.getRepository(req);
try (RevWalk walk = new RevWalk(repo)) {
DateFormatter df = new DateFormatter(getAccess(req), Format.DEFAULT);
RevObject obj = walk.parseAny(view.getRevision().getId());
switch(obj.getType()) {
case OBJ_COMMIT:
renderJson(req, res, new CommitJsonData().setRevWalk(walk).toJsonData(req, (RevCommit) obj, COMMIT_JSON_FIELDS, df), Commit.class);
break;
default:
// TODO(dborowitz): Support showing other types.
res.setStatus(SC_NOT_FOUND);
break;
}
}
}
use of org.eclipse.jgit.revwalk.RevObject in project gitiles by GerritCodeReview.
the class RepositoryIndexServlet method renderReadme.
private static Map<String, Object> renderReadme(HttpServletRequest req, RevWalk walk, GitilesView view, Config cfg, RevObject head) throws IOException {
RevTree rootTree;
try {
rootTree = walk.parseTree(head);
} catch (IncorrectObjectTypeException notTreeish) {
return null;
}
ReadmeHelper readme = new ReadmeHelper(walk.getObjectReader(), GitilesView.path().copyFrom(view).setRevision(Revision.HEAD).setPathPart("/").build(), MarkdownConfig.get(cfg), rootTree, req.getRequestURI());
readme.scanTree(rootTree);
if (readme.isPresent()) {
SanitizedContent html = readme.render();
if (html != null) {
return ImmutableMap.<String, Object>of("readmeHtml", html);
}
}
return null;
}
Aggregations