Search in sources :

Example 1 with ObjectWalk

use of org.eclipse.jgit.revwalk.ObjectWalk in project egit by eclipse.

the class GitSynchronizeData method updateRevs.

/**
 * Recalculates source, destination and ancestor Rev commits
 *
 * @throws IOException
 */
public void updateRevs() throws IOException {
    try (ObjectWalk ow = new ObjectWalk(repo)) {
        ow.setRetainBody(true);
        srcRevCommit = getCommit(srcRev, ow);
        dstRevCommit = getCommit(dstRev, ow);
    }
    if (this.dstRevCommit != null && this.srcRevCommit != null)
        this.ancestorRevCommit = getCommonAncestor(repo, this.srcRevCommit, this.dstRevCommit);
    else
        this.ancestorRevCommit = null;
}
Also used : ObjectWalk(org.eclipse.jgit.revwalk.ObjectWalk)

Example 2 with ObjectWalk

use of org.eclipse.jgit.revwalk.ObjectWalk in project gerrit by GerritCodeReview.

the class RefUtil method verifyConnected.

public static RevWalk verifyConnected(Repository repo, ObjectId revid) throws InvalidRevisionException {
    try {
        ObjectWalk rw = new ObjectWalk(repo);
        try {
            rw.markStart(rw.parseCommit(revid));
        } catch (IncorrectObjectTypeException err) {
            throw new InvalidRevisionException(revid.name(), err);
        }
        RefDatabase refDb = repo.getRefDatabase();
        Iterable<Ref> refs = Iterables.concat(refDb.getRefsByPrefix(Constants.R_HEADS), refDb.getRefsByPrefix(Constants.R_TAGS));
        Ref rc = refDb.exactRef(RefNames.REFS_CONFIG);
        if (rc != null) {
            refs = Iterables.concat(refs, Collections.singleton(rc));
        }
        for (Ref r : refs) {
            try {
                rw.markUninteresting(rw.parseAny(r.getObjectId()));
            } catch (MissingObjectException err) {
                continue;
            }
        }
        rw.checkConnectivity();
        return rw;
    } catch (IncorrectObjectTypeException | MissingObjectException err) {
        throw new InvalidRevisionException(revid.name(), err);
    } catch (IOException err) {
        logger.atSevere().withCause(err).log("Repository \"%s\" may be corrupt; suggest running git fsck", repo.getDirectory());
        throw new InvalidRevisionException(revid.name());
    }
}
Also used : ObjectWalk(org.eclipse.jgit.revwalk.ObjectWalk) Ref(org.eclipse.jgit.lib.Ref) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) IOException(java.io.IOException) RefDatabase(org.eclipse.jgit.lib.RefDatabase) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException)

Aggregations

ObjectWalk (org.eclipse.jgit.revwalk.ObjectWalk)2 IOException (java.io.IOException)1 IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)1 MissingObjectException (org.eclipse.jgit.errors.MissingObjectException)1 Ref (org.eclipse.jgit.lib.Ref)1 RefDatabase (org.eclipse.jgit.lib.RefDatabase)1