Search in sources :

Example 16 with MissingObjectException

use of org.eclipse.jgit.errors.MissingObjectException in project jwt by emweb.

the class Git method treeSize.

public int treeSize(ObjectId treeId) {
    if (treeId.id == null)
        return 0;
    try {
        RevWalk walk = new RevWalk(repository, 0);
        RevTree tree = walk.parseTree(treeId.id);
        TreeWalk treeWalk = new TreeWalk(repository);
        treeWalk.addTree(tree);
        treeWalk.setRecursive(false);
        int count = 0;
        while (treeWalk.next()) ++count;
        return count;
    } catch (MissingObjectException e) {
        throw new RuntimeException(e);
    } catch (IncorrectObjectTypeException e) {
        throw new RuntimeException(e);
    } catch (CorruptObjectException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : CorruptObjectException(org.eclipse.jgit.errors.CorruptObjectException) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.DepthWalk.RevWalk) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevTree(org.eclipse.jgit.revwalk.RevTree) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException)

Example 17 with MissingObjectException

use of org.eclipse.jgit.errors.MissingObjectException in project repairnator by Spirals-Team.

the class GitHelper method getLastKnowParent.

private String getLastKnowParent(GitHub gh, GHRepository ghRepo, Git git, String oldCommitSha, AbstractStep step) throws IOException {
    showGitHubRateInformation(gh, step);
    // get the deleted
    GHCommit commit = ghRepo.getCommit(oldCommitSha);
    // commit from GH
    List<String> commitParents = commit.getParentSHA1s();
    if (commitParents.isEmpty()) {
        step.addStepError("The following commit does not have any parent in GitHub: " + oldCommitSha + ". It cannot be resolved.");
        return null;
    }
    if (commitParents.size() > 1) {
        this.getLogger().debug("Step " + step.getName() + " - The commit has more than one parent : " + commit.getHtmlUrl());
    }
    String parent = commitParents.get(0);
    try {
        ObjectId commitObject = git.getRepository().resolve(parent);
        git.getRepository().open(commitObject);
        return parent;
    } catch (MissingObjectException e) {
        return getLastKnowParent(gh, ghRepo, git, parent, step);
    }
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException)

Example 18 with MissingObjectException

use of org.eclipse.jgit.errors.MissingObjectException 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 19 with MissingObjectException

use of org.eclipse.jgit.errors.MissingObjectException in project egit by eclipse.

the class GitBlobStorage method open.

private InputStream open() throws IOException, CoreException, IncorrectObjectTypeException {
    if (blobId == null)
        return new ByteArrayInputStream(new byte[0]);
    try {
        WorkingTreeOptions workingTreeOptions = db.getConfig().get(WorkingTreeOptions.KEY);
        final InputStream objectInputStream = db.open(blobId, Constants.OBJ_BLOB).openStream();
        switch(workingTreeOptions.getAutoCRLF()) {
            case INPUT:
            // itself should ignore line endings.
            case FALSE:
                return objectInputStream;
            case TRUE:
            default:
                return new AutoCRLFInputStream(objectInputStream, true);
        }
    } catch (MissingObjectException notFound) {
        throw new CoreException(Activator.error(NLS.bind(CoreText.BlobStorage_blobNotFound, blobId.name(), path), notFound));
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) AutoCRLFInputStream(org.eclipse.jgit.util.io.AutoCRLFInputStream) InputStream(java.io.InputStream) AutoCRLFInputStream(org.eclipse.jgit.util.io.AutoCRLFInputStream) WorkingTreeOptions(org.eclipse.jgit.treewalk.WorkingTreeOptions) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException)

Example 20 with MissingObjectException

use of org.eclipse.jgit.errors.MissingObjectException in project gerrit by GerritCodeReview.

the class IncludedIn method apply.

public IncludedInInfo apply(Project.NameKey project, String revisionId) throws RestApiException, IOException, PermissionBackendException {
    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());
        }
        RefDatabase refDb = r.getRefDatabase();
        Collection<Ref> tags = refDb.getRefsByPrefix(Constants.R_TAGS);
        Collection<Ref> branches = refDb.getRefsByPrefix(Constants.R_HEADS);
        List<Ref> allTagsAndBranches = Lists.newArrayListWithCapacity(tags.size() + branches.size());
        allTagsAndBranches.addAll(tags);
        allTagsAndBranches.addAll(branches);
        Set<String> allMatchingTagsAndBranches = rw.getMergedInto(rev, IncludedInUtil.getSortedRefs(allTagsAndBranches, rw)).stream().map(Ref::getName).collect(Collectors.toSet());
        // Filter branches and tags according to their visbility by the user
        ImmutableSortedSet<String> filteredBranches = sortedShortNames(filterReadableRefs(project, getMatchingRefNames(allMatchingTagsAndBranches, branches)));
        ImmutableSortedSet<String> filteredTags = sortedShortNames(filterReadableRefs(project, getMatchingRefNames(allMatchingTagsAndBranches, tags)));
        ListMultimap<String, String> external = MultimapBuilder.hashKeys().arrayListValues().build();
        externalIncludedIn.runEach(ext -> {
            ListMultimap<String, String> extIncludedIns = ext.getIncludedIn(project.get(), rev.name(), filteredBranches, filteredTags);
            if (extIncludedIns != null) {
                external.putAll(extIncludedIns);
            }
        });
        return new IncludedInInfo(filteredBranches, filteredTags, (!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) RefDatabase(org.eclipse.jgit.lib.RefDatabase) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) Repository(org.eclipse.jgit.lib.Repository) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Ref(org.eclipse.jgit.lib.Ref) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

MissingObjectException (org.eclipse.jgit.errors.MissingObjectException)31 IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)22 ObjectId (org.eclipse.jgit.lib.ObjectId)17 RevCommit (org.eclipse.jgit.revwalk.RevCommit)16 RevWalk (org.eclipse.jgit.revwalk.RevWalk)16 IOException (java.io.IOException)13 Repository (org.eclipse.jgit.lib.Repository)12 ArrayList (java.util.ArrayList)7 Ref (org.eclipse.jgit.lib.Ref)6 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)5 Map (java.util.Map)5 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Iterables (com.google.common.collect.Iterables)3 Nullable (com.google.gerrit.common.Nullable)3 Change (com.google.gerrit.entities.Change)3 PatchSet (com.google.gerrit.entities.PatchSet)3 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)3 InvalidObjectIdException (org.eclipse.jgit.errors.InvalidObjectIdException)3