Search in sources :

Example 6 with MissingObjectException

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

the class DiffServlet method doGetText.

@Override
protected void doGetText(HttpServletRequest req, HttpServletResponse res) throws IOException {
    GitilesView view = ViewFilter.getView(req);
    Repository repo = ServletUtils.getRepository(req);
    try (RevWalk walk = new RevWalk(repo)) {
        AbstractTreeIterator oldTree;
        AbstractTreeIterator newTree;
        try {
            oldTree = getTreeIterator(walk, view.getOldRevision().getId());
            newTree = getTreeIterator(walk, view.getRevision().getId());
        } catch (MissingObjectException | IncorrectObjectTypeException e) {
            res.setStatus(SC_NOT_FOUND);
            return;
        }
        try (Writer writer = startRenderText(req, res);
            OutputStream out = BaseEncoding.base64().encodingStream(writer);
            DiffFormatter diff = new DiffFormatter(out)) {
            formatDiff(repo, oldTree, newTree, view.getPathPart(), diff);
        }
    }
}
Also used : AbstractTreeIterator(org.eclipse.jgit.treewalk.AbstractTreeIterator) Repository(org.eclipse.jgit.lib.Repository) OutputStream(java.io.OutputStream) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) DiffFormatter(org.eclipse.jgit.diff.DiffFormatter) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) Writer(java.io.Writer)

Example 7 with MissingObjectException

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

the class GitHistoryPage method markStartRef.

private void markStartRef(RevWalk walk, Ref ref) throws IOException, IncorrectObjectTypeException {
    try {
        RevObject refTarget = walk.parseAny(ref.getLeaf().getObjectId());
        RevObject peeled = walk.peel(refTarget);
        if (peeled instanceof RevCommit)
            walk.markStart((RevCommit) peeled);
    } catch (MissingObjectException e) {
    // If there is a ref which points to Nirvana then we should simply
    // ignore this ref. We should not let a corrupt ref cause that the
    // history view is not filled at all
    }
}
Also used : RevObject(org.eclipse.jgit.revwalk.RevObject) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 8 with MissingObjectException

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

the class RefContentProposal method getDescription.

@Override
public String getDescription() {
    if (objectId == null) {
        return null;
    } else if (upstream && objectId.equals(ObjectId.zeroId())) {
        return refName + '\n' + UIText.RefContentProposal_newRemoteObject;
    }
    try (ObjectReader reader = db.newObjectReader()) {
        ObjectLoader loader = null;
        try {
            loader = reader.open(objectId);
        } catch (MissingObjectException e) {
            if (upstream) {
                return refName + '\n' + objectId.abbreviate(7).name() + // $NON-NLS-1$
                " - " + UIText.RefContentProposal_unknownRemoteObject;
            }
            throw e;
        }
        final StringBuilder sb = new StringBuilder();
        sb.append(refName);
        sb.append('\n');
        sb.append(reader.abbreviate(objectId).name());
        // $NON-NLS-1$
        sb.append(" - ");
        switch(loader.getType()) {
            case Constants.OBJ_COMMIT:
                try (RevWalk rw = new RevWalk(db)) {
                    RevCommit c = rw.parseCommit(objectId);
                    appendObjectSummary(sb, UIText.RefContentProposal_commit, c.getAuthorIdent(), c.getFullMessage());
                }
                break;
            case Constants.OBJ_TAG:
                try (RevWalk rw = new RevWalk(db)) {
                    RevTag t = rw.parseTag(objectId);
                    appendObjectSummary(sb, UIText.RefContentProposal_tag, t.getTaggerIdent(), t.getFullMessage());
                }
                break;
            case Constants.OBJ_TREE:
                sb.append(UIText.RefContentProposal_tree);
                break;
            case Constants.OBJ_BLOB:
                sb.append(UIText.RefContentProposal_blob);
                break;
            default:
                sb.append(UIText.RefContentProposal_unknownObject);
        }
        return sb.toString();
    } catch (IOException e) {
        Activator.logError(NLS.bind(UIText.RefContentProposal_errorReadingObject, objectId, refName), e);
        return null;
    }
}
Also used : RevTag(org.eclipse.jgit.revwalk.RevTag) ObjectReader(org.eclipse.jgit.lib.ObjectReader) ObjectLoader(org.eclipse.jgit.lib.ObjectLoader) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 9 with MissingObjectException

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

the class GitHelper method testCommitExistence.

/**
 * Test if a commit exists in the given git repository
 *
 * @param git
 * @param oldCommitSha
 * @return oldCommitSha if the commit exists in the repo, a new commit SHA
 *         if the commit has been retrieved from GitHub and applied back, or
 *         null if the retrieve failed.
 */
public String testCommitExistence(Git git, String oldCommitSha, AbstractStep step, Build build) {
    try {
        ObjectId commitObject = git.getRepository().resolve(oldCommitSha);
        git.getRepository().open(commitObject);
        return oldCommitSha;
    } catch (MissingObjectException e) {
        return retrieveAndApplyCommitFromGithub(git, oldCommitSha, step, build);
    } catch (IOException e) {
        step.addStepError("Error while testing commit: " + e);
    }
    return null;
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) IOException(java.io.IOException) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException)

Example 10 with MissingObjectException

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

the class WalkSorter method byCommit.

private ListMultimap<RevCommit, PatchSetData> byCommit(RevWalk rw, Collection<ChangeData> in) throws IOException {
    ListMultimap<RevCommit, PatchSetData> byCommit = MultimapBuilder.hashKeys(in.size()).arrayListValues(1).build();
    for (ChangeData cd : in) {
        PatchSet maxPs = null;
        for (PatchSet ps : cd.patchSets()) {
            if (shouldInclude(ps) && (maxPs == null || ps.id().get() > maxPs.id().get())) {
                maxPs = ps;
            }
        }
        if (maxPs == null) {
            // No patch sets matched.
            continue;
        }
        try {
            RevCommit c = rw.parseCommit(maxPs.commitId());
            byCommit.put(c, PatchSetData.create(cd, maxPs, c));
        } catch (MissingObjectException | IncorrectObjectTypeException e) {
            logger.atWarning().withCause(e).log("missing commit %s for patch set %s", maxPs.commitId().name(), maxPs.id());
        }
    }
    return byCommit;
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) ChangeData(com.google.gerrit.server.query.change.ChangeData) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) 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