Search in sources :

Example 16 with IncorrectObjectTypeException

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));
    }
}
Also used : IncludedInInfo(com.google.gerrit.extensions.api.changes.IncludedInInfo) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) ExternalIncludedIn(com.google.gerrit.extensions.config.ExternalIncludedIn) Repository(org.eclipse.jgit.lib.Repository) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 17 with IncorrectObjectTypeException

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));
    }
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) AnyObjectId(org.eclipse.jgit.lib.AnyObjectId) BitSet(java.util.BitSet) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) IOException(java.io.IOException)

Example 18 with IncorrectObjectTypeException

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)));
}
Also used : Arrays(java.util.Arrays) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Objects.hash(java.util.Objects.hash) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) ExecutionError(com.google.common.util.concurrent.ExecutionError) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RefDatabase(org.eclipse.jgit.lib.RefDatabase) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Throwables(com.google.common.base.Throwables) RevSort(org.eclipse.jgit.revwalk.RevSort) IOException(java.io.IOException) ObjectId(org.eclipse.jgit.lib.ObjectId) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) R_HEADS(org.eclipse.jgit.lib.Constants.R_HEADS) Stream(java.util.stream.Stream) Ref(org.eclipse.jgit.lib.Ref) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) CacheBuilder(com.google.common.cache.CacheBuilder) R_TAGS(org.eclipse.jgit.lib.Constants.R_TAGS) Cache(com.google.common.cache.Cache) Repository(org.eclipse.jgit.lib.Repository) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) Ref(org.eclipse.jgit.lib.Ref) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 19 with IncorrectObjectTypeException

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);
        }
    }
}
Also used : OutputStream(java.io.OutputStream) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) AbstractTreeIterator(org.eclipse.jgit.treewalk.AbstractTreeIterator) Field(com.google.gitiles.CommitData.Field) Repository(org.eclipse.jgit.lib.Repository) DiffFormatter(org.eclipse.jgit.diff.DiffFormatter) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk)

Example 20 with IncorrectObjectTypeException

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;
}
Also used : SanitizedContent(com.google.template.soy.data.SanitizedContent) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) RevObject(org.eclipse.jgit.revwalk.RevObject) RevTree(org.eclipse.jgit.revwalk.RevTree)

Aggregations

IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)23 MissingObjectException (org.eclipse.jgit.errors.MissingObjectException)13 RevWalk (org.eclipse.jgit.revwalk.RevWalk)13 IOException (java.io.IOException)10 Repository (org.eclipse.jgit.lib.Repository)10 ObjectId (org.eclipse.jgit.lib.ObjectId)9 RevCommit (org.eclipse.jgit.revwalk.RevCommit)9 Ref (org.eclipse.jgit.lib.Ref)4 RevTree (org.eclipse.jgit.revwalk.RevTree)4 Branch (com.google.gerrit.reviewdb.client.Branch)3 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)2 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)2 Project (com.google.gerrit.reviewdb.client.Project)2 Map (java.util.Map)2 AnyObjectId (org.eclipse.jgit.lib.AnyObjectId)2