use of org.eclipse.jgit.errors.IncorrectObjectTypeException in project gerrit by GerritCodeReview.
the class IncludedInResolver method parseCommits.
/** Parse commit of ref and store the relation between ref and commit. */
private void parseCommits(final Collection<Ref> refs) throws IOException {
if (commitToRef != null) {
return;
}
commitToRef = LinkedListMultimap.create();
for (Ref ref : refs) {
final RevCommit commit;
try {
commit = rw.parseCommit(ref.getObjectId());
} catch (IncorrectObjectTypeException notCommit) {
//
continue;
} catch (MissingObjectException notHere) {
// Log the problem with this branch, but keep processing.
//
log.warn("Reference " + ref.getName() + " in " + repo.getDirectory() + " points to dangling object " + ref.getObjectId());
continue;
}
commitToRef.put(commit, ref.getName());
}
tipsByCommitTime = Lists.newArrayList(commitToRef.keySet());
sortOlderFirst(tipsByCommitTime);
}
use of org.eclipse.jgit.errors.IncorrectObjectTypeException in project gerrit by GerritCodeReview.
the class SubmitStrategyOp method getAlreadyMergedCommit.
private CodeReviewCommit getAlreadyMergedCommit(RepoContext ctx) throws IOException {
CodeReviewCommit tip = args.mergeTip.getInitialTip();
if (tip == null) {
return null;
}
CodeReviewRevWalk rw = (CodeReviewRevWalk) ctx.getRevWalk();
Change.Id id = getId();
String refPrefix = id.toRefPrefix();
Map<String, ObjectId> refs = ctx.getRepoView().getRefs(refPrefix);
List<CodeReviewCommit> commits = new ArrayList<>(refs.size());
for (Map.Entry<String, ObjectId> e : refs.entrySet()) {
PatchSet.Id psId = PatchSet.Id.fromRef(refPrefix + e.getKey());
if (psId == null) {
continue;
}
try {
CodeReviewCommit c = rw.parseCommit(e.getValue());
c.setPatchsetId(psId);
commits.add(c);
} catch (MissingObjectException | IncorrectObjectTypeException ex) {
// Bogus ref, can't be merged into tip so we don't care.
continue;
}
}
Collections.sort(commits, ReviewDbUtil.intKeyOrdering().reverse().onResultOf(c -> c.getPatchsetId()));
CodeReviewCommit result = MergeUtil.findAnyMergedInto(rw, commits, tip);
if (result == null) {
return null;
}
// Some patch set of this change is actually merged into the target
// branch, most likely because a previous run of MergeOp failed after
// updateRepo, during updateChange.
//
// Do the best we can to clean this up: mark the change as merged and set
// the current patch set. Don't touch the dest branch at all. This can
// lead to some odd situations like another change in the set merging in
// a different patch set of this change, but that's unavoidable at this
// point. At least the change will end up in the right state.
//
// TODO(dborowitz): Consider deleting later junk patch set refs. They
// presumably don't have PatchSets pointing to them.
rw.parseBody(result);
result.add(args.canMergeFlag);
PatchSet.Id psId = result.getPatchsetId();
result.copyFrom(toMerge);
// Got overwriten by copyFrom.
result.setPatchsetId(psId);
result.setStatusCode(CommitMergeStatus.ALREADY_MERGED);
args.commitStatus.put(result);
return result;
}
use of org.eclipse.jgit.errors.IncorrectObjectTypeException in project gitiles by GerritCodeReview.
the class RevisionServlet method doGetHtml.
@Override
protected void doGetHtml(HttpServletRequest req, HttpServletResponse res) throws IOException {
GitilesView view = ViewFilter.getView(req);
Repository repo = ServletUtils.getRepository(req);
GitilesAccess access = getAccess(req);
Config cfg = getAccess(req).getConfig();
try (RevWalk walk = new RevWalk(repo)) {
DateFormatter df = new DateFormatter(access, Format.DEFAULT);
List<RevObject> objects = listObjects(walk, view.getRevision());
List<Map<String, ?>> soyObjects = Lists.newArrayListWithCapacity(objects.size());
boolean hasBlob = false;
boolean hasReadme = false;
// TODO(sop): Allow caching commits by SHA-1 when no S cookie is sent.
for (RevObject obj : objects) {
try {
switch(obj.getType()) {
case OBJ_COMMIT:
soyObjects.add(ImmutableMap.of("type", Constants.TYPE_COMMIT, "data", new CommitSoyData().setLinkifier(linkifier).setRevWalk(walk).setArchiveFormat(getArchiveFormat(access)).toSoyData(req, (RevCommit) obj, COMMIT_SOY_FIELDS, df)));
break;
case OBJ_TREE:
Map<String, Object> tree = new TreeSoyData(walk.getObjectReader(), view, cfg, (RevTree) obj, req.getRequestURI()).toSoyData(obj);
soyObjects.add(ImmutableMap.of("type", Constants.TYPE_TREE, "data", tree));
hasReadme = tree.containsKey("readmeHtml");
break;
case OBJ_BLOB:
soyObjects.add(ImmutableMap.of("type", Constants.TYPE_BLOB, "data", new BlobSoyData(walk.getObjectReader(), view).toSoyData(obj)));
hasBlob = true;
break;
case OBJ_TAG:
soyObjects.add(ImmutableMap.of("type", Constants.TYPE_TAG, "data", new TagSoyData(linkifier, req).toSoyData((RevTag) obj, df)));
break;
default:
log.warn("Bad object type for {}: {}", ObjectId.toString(obj.getId()), obj.getType());
res.setStatus(SC_NOT_FOUND);
return;
}
} catch (MissingObjectException e) {
log.warn("Missing object " + ObjectId.toString(obj.getId()), e);
res.setStatus(SC_NOT_FOUND);
return;
} catch (IncorrectObjectTypeException e) {
log.warn("Incorrect object type for " + ObjectId.toString(obj.getId()), e);
res.setStatus(SC_NOT_FOUND);
return;
}
}
renderHtml(req, res, "gitiles.revisionDetail", ImmutableMap.of("title", view.getRevision().getName(), "objects", soyObjects, "hasBlob", hasBlob, "hasReadme", hasReadme));
}
}
use of org.eclipse.jgit.errors.IncorrectObjectTypeException in project gitiles by GerritCodeReview.
the class BlameServlet method resolveBlob.
private static ObjectId resolveBlob(GitilesView view, RevWalk rw, ObjectId commitId) throws IOException {
try {
if (commitId == null || Strings.isNullOrEmpty(view.getPathPart())) {
return null;
}
RevTree tree = rw.parseTree(commitId);
TreeWalk tw = TreeWalk.forPath(rw.getObjectReader(), view.getPathPart(), tree);
if (tw == null || (tw.getRawMode(0) & FileMode.TYPE_MASK) != FileMode.TYPE_FILE) {
return null;
}
return tw.getObjectId(0);
} catch (IncorrectObjectTypeException e) {
return null;
}
}
use of org.eclipse.jgit.errors.IncorrectObjectTypeException 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);
}
}
Aggregations