use of org.eclipse.jgit.errors.IncorrectObjectTypeException in project gerrit by GerritCodeReview.
the class IncludedIn method apply.
public IncludedInInfo apply(Project.NameKey project, String revisionId) throws RestApiException, IOException {
try (Repository r = repoManager.openRepository(project);
RevWalk rw = new RevWalk(r)) {
rw.setRetainBody(false);
RevCommit rev;
try {
rev = rw.parseCommit(ObjectId.fromString(revisionId));
} catch (IncorrectObjectTypeException err) {
throw new BadRequestException(err.getMessage());
} catch (MissingObjectException err) {
throw new ResourceConflictException(err.getMessage());
}
IncludedInResolver.Result d = IncludedInResolver.resolve(r, rw, rev);
ListMultimap<String, String> external = MultimapBuilder.hashKeys().arrayListValues().build();
for (ExternalIncludedIn ext : externalIncludedIn) {
ListMultimap<String, String> extIncludedIns = ext.getIncludedIn(project.get(), rev.name(), d.getTags(), d.getBranches());
if (extIncludedIns != null) {
external.putAll(extIncludedIns);
}
}
return new IncludedInInfo(d.getBranches(), d.getTags(), (!external.isEmpty() ? external.asMap() : null));
}
}
use of org.eclipse.jgit.errors.IncorrectObjectTypeException in project gerrit by GerritCodeReview.
the class TagSet method addTag.
private void addTag(TagWalk rw, Ref ref) {
ObjectId id = ref.getPeeledObjectId();
if (id == null) {
id = ref.getObjectId();
}
if (!tags.contains(id)) {
BitSet flags;
try {
flags = ((TagCommit) rw.parseCommit(id)).refFlags;
} catch (IncorrectObjectTypeException notCommit) {
flags = new BitSet();
} catch (IOException e) {
log.warn("Error on " + ref.getName() + " of " + projectName, e);
flags = new BitSet();
}
tags.add(new Tag(id, flags));
}
}
use of org.eclipse.jgit.errors.IncorrectObjectTypeException in project gitiles by GerritCodeReview.
the class VisibilityCache method isVisible.
private boolean isVisible(Repository repo, RevWalk walk, ObjectId id, Collection<ObjectId> knownReachable) throws IOException {
RevCommit commit;
try {
commit = walk.parseCommit(id);
} catch (IncorrectObjectTypeException e) {
return false;
}
// If any reference directly points at the requested object, permit display. Common for displays
// of pending patch sets in Gerrit Code Review, or bookmarks to the commit a tag points at.
Collection<Ref> all = repo.getRefDatabase().getRefs(RefDatabase.ALL).values();
for (Ref ref : all) {
ref = repo.getRefDatabase().peel(ref);
if (id.equals(ref.getObjectId()) || id.equals(ref.getPeeledObjectId())) {
return true;
}
}
// case.
return isReachableFrom(walk, commit, knownReachable) || isReachableFromRefs(walk, commit, all.stream().filter(r -> refStartsWith(r, R_HEADS))) || isReachableFromRefs(walk, commit, all.stream().filter(r -> refStartsWith(r, R_TAGS))) || isReachableFromRefs(walk, commit, all.stream().filter(r -> otherRefs(r)));
}
use of org.eclipse.jgit.errors.IncorrectObjectTypeException in project gitiles by GerritCodeReview.
the class DiffServlet method doGetHtml.
@Override
protected void doGetHtml(HttpServletRequest req, HttpServletResponse res) throws IOException {
GitilesView view = ViewFilter.getView(req);
Repository repo = ServletUtils.getRepository(req);
try (RevWalk walk = new RevWalk(repo);
TreeWalk tw = newTreeWalk(walk, view)) {
boolean showCommit;
boolean isFile;
AbstractTreeIterator oldTree;
AbstractTreeIterator newTree;
try {
if (tw == null && !view.getPathPart().isEmpty()) {
res.setStatus(SC_NOT_FOUND);
return;
}
isFile = tw != null && isFile(tw);
// If we are viewing the diff between a commit and one of its parents,
// include the commit detail in the rendered page.
showCommit = isParentOf(walk, view.getOldRevision(), view.getRevision());
oldTree = getTreeIterator(walk, view.getOldRevision().getId());
newTree = getTreeIterator(walk, view.getRevision().getId());
} catch (MissingObjectException | IncorrectObjectTypeException e) {
res.setStatus(SC_NOT_FOUND);
return;
}
Map<String, Object> data = getData(req);
data.put("title", "Diff - " + view.getRevisionRange());
if (showCommit) {
Set<Field> fs = CommitSoyData.DEFAULT_FIELDS;
if (isFile) {
fs = Field.setOf(fs, Field.PARENT_BLAME_URL);
}
GitilesAccess access = getAccess(req);
DateFormatter df = new DateFormatter(access, Format.DEFAULT);
data.put("commit", new CommitSoyData().setLinkifier(linkifier).setArchiveFormat(getArchiveFormat(access)).toSoyData(req, walk.parseCommit(view.getRevision().getId()), fs, df));
}
if (!data.containsKey("repositoryName") && (view.getRepositoryName() != null)) {
data.put("repositoryName", view.getRepositoryName());
}
if (!data.containsKey("breadcrumbs")) {
data.put("breadcrumbs", view.getBreadcrumbs());
}
setCacheHeaders(req, res);
try (OutputStream out = startRenderStreamingHtml(req, res, "gitiles.diffDetail", data);
DiffFormatter diff = new HtmlDiffFormatter(renderer, view, out)) {
formatDiff(repo, oldTree, newTree, view.getPathPart(), diff);
}
}
}
use of org.eclipse.jgit.errors.IncorrectObjectTypeException 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