Example usage for org.eclipse.jgit.lib Ref getPeeledObjectId

List of usage examples for org.eclipse.jgit.lib Ref getPeeledObjectId

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Ref getPeeledObjectId.

Prototype

@Nullable
ObjectId getPeeledObjectId();

Source Link

Document

Cached value of ref^{} (the ref peeled to commit).

Usage

From source file:com.benhumphreys.jgitcassandra.store.RefStore.java

License:Apache License

/**
 * Inserts a single ref into the database
 *
 * @throws IllegalStateException if the reference concrete type is not
 *                               one of the four handled classes
 *                               (@see RefType).
 *//*from ww  w.  j a v a 2  s .  c  om*/
private void putRef(String name, Ref r) throws IOException {
    if (r instanceof SymbolicRef) {
        putRow(name, RefType.SYMBOLIC, r.getTarget().getName(), "");
    } else if (r instanceof ObjectIdRef.PeeledNonTag) {
        putRow(name, RefType.PEELED_NONTAG, r.getObjectId().name(), "");
    } else if (r instanceof ObjectIdRef.PeeledTag) {
        putRow(name, RefType.PEELED_TAG, r.getObjectId().name(), r.getPeeledObjectId().toString());
    } else if (r instanceof ObjectIdRef.Unpeeled) {
        putRow(name, RefType.UNPEELED, r.getObjectId().name(), "");
    } else {
        throw new IllegalStateException("Unhandled ref type: " + r);
    }
}

From source file:com.buildautomation.jgit.api.ListTags.java

License:Apache License

public static void listTags() throws IOException, GitAPIException {
    try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
        try (Git git = new Git(repository)) {
            List<Ref> call = git.tagList().call();
            for (Ref ref : call) {
                System.out.println("Tag: " + ref + " " + ref.getName() + " " + ref.getObjectId().getName());

                // fetch all commits for this tag
                LogCommand log = git.log();

                Ref peeledRef = repository.peel(ref);
                if (peeledRef.getPeeledObjectId() != null) {
                    log.add(peeledRef.getPeeledObjectId());
                } else {
                    log.add(ref.getObjectId());
                }/*w ww.  j  a  va2s  .  co m*/

                Iterable<RevCommit> logs = log.call();
                for (RevCommit rev : logs) {
                    System.out.println("Commit: "
                            + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
                }
            }
        }
    }
}

From source file:com.github.checkstyle.github.NotesBuilder.java

License:Open Source License

/**
 * Returns actual SHA-1 object by commit reference.
 * @param repo git repository./*from  w  w  w  . j a  va  2  s.  co  m*/
 * @param ref string representation of commit reference.
 * @return actual SHA-1 object.
 * @throws IOException if an I/O error occurs.
 */
private static ObjectId getActualRefObjectId(Repository repo, String ref) throws IOException {
    final ObjectId actualObjectId;
    final Ref referenceObj = repo.findRef(ref);
    if (referenceObj == null) {
        actualObjectId = repo.resolve(ref);
    } else {
        final Ref repoPeeled = repo.peel(referenceObj);
        actualObjectId = Optional.ofNullable(repoPeeled.getPeeledObjectId()).orElse(referenceObj.getObjectId());
    }
    return actualObjectId;
}

From source file:com.github.checkstyle.NotesBuilder.java

License:Open Source License

/**
 * Returns actual SHA-1 object by commit reference.
 * @param repo git repository./*from w  w w  .  j av  a  2s .co  m*/
 * @param ref string representation of commit reference.
 * @return actual SHA-1 object.
 * @throws IOException if an I/O error occurs.
 */
private static ObjectId getActualRefObjectId(Repository repo, String ref) throws IOException {
    final ObjectId actualObjectId;
    final Ref referenceObj = repo.getRef(ref);
    if (referenceObj == null) {
        actualObjectId = repo.resolve(ref);
    } else {
        final Ref repoPeeled = repo.peel(referenceObj);
        actualObjectId = Optional.ofNullable(repoPeeled.getPeeledObjectId()).orElse(referenceObj.getObjectId());
    }
    return actualObjectId;
}

From source file:com.github.kaitoy.goslings.server.dao.jgit.ReferenceDaoImpl.java

License:Open Source License

/**
 * this method converts a {@link Ref} object to {@link Tag} object.
 *
 * @param ref a {@link Ref} object representing a tag.
 * @return a new {@link Tag} instance./*  w  w  w.  j a  v a2 s  . com*/
 */
private Tag convertToTag(Ref ref) {
    ObjectId peeledObjId = ref.getPeeledObjectId();
    if (peeledObjId == null) {
        // lightweight tag
        return new Tag(ref.getName(), null, ref.getObjectId().getName());
    } else {
        // annotated tag
        return new Tag(ref.getName(), ref.getObjectId().getName(), peeledObjId.getName());
    }
}

From source file:com.google.gerrit.server.git.TagMatcher.java

License:Apache License

boolean isReachable(Ref tagRef) {
    tagRef = db.peel(tagRef);//from w  w w .  j a  va2s.  c o  m

    ObjectId tagObj = tagRef.getPeeledObjectId();
    if (tagObj == null) {
        tagObj = tagRef.getObjectId();
        if (tagObj == null) {
            return false;
        }
    }

    Tag tag = tags.lookupTag(tagObj);
    if (tag == null) {
        if (rebuiltForNewTags) {
            return false;
        }

        rebuiltForNewTags = true;
        holder.rebuildForNewTags(cache, this);
        return isReachable(tagRef);
    }

    return tag.has(mask);
}

From source file:com.google.gerrit.server.git.TagSet.java

License:Apache License

private void addTag(TagWalk rw, Ref ref) {
    ObjectId id = ref.getPeeledObjectId();
    if (id == null) {
        id = ref.getObjectId();/*from   w  ww  .j ava 2 s  .  c  om*/
    }

    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));
    }
}

From source file:com.google.gitiles.VisibilityCache.java

License:Open Source License

private boolean isVisible(Repository repo, RevWalk walk, ObjectId id) throws IOException {
    RevCommit commit;//w ww  .jav a2  s.  com
    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> allRefs = repo.getRefDatabase().getRefs(RefDatabase.ALL).values();
    for (Ref ref : allRefs) {
        ref = repo.getRefDatabase().peel(ref);
        if (id.equals(ref.getObjectId()) || id.equals(ref.getPeeledObjectId())) {
            return true;
        }
    }

    // Check heads first under the assumption that most requests are for refs
    // close to a head. Tags tend to be much further back in history and just
    // clutter up the priority queue in the common case.
    return isReachableFrom(walk, commit, filter(allRefs, refStartsWith(Constants.R_HEADS)))
            || isReachableFrom(walk, commit, filter(allRefs, refStartsWith(Constants.R_TAGS)))
            || isReachableFrom(walk, commit, filter(allRefs, not(refStartsWith("refs/changes/"))));
}

From source file:com.google.gitiles.VisibilityCache.java

License:Open Source License

private boolean isReachableFrom(RevWalk walk, RevCommit commit, Collection<Ref> refs) throws IOException {
    walk.reset();//from  w  w  w .j  av a 2  s  .  c o m
    if (topoSort) {
        walk.sort(RevSort.TOPO);
    }
    walk.markStart(commit);
    for (Ref ref : refs) {
        if (ref.getPeeledObjectId() != null) {
            markUninteresting(walk, ref.getPeeledObjectId());
        } else {
            markUninteresting(walk, ref.getObjectId());
        }
    }
    // If the commit is reachable from any branch head, it will appear to be
    // uninteresting to the RevWalk and no output will be produced.
    return walk.next() == null;
}

From source file:com.peergreen.configuration.git.GitManager.java

License:Apache License

public ObjectId getObjectidForVersion(Version version) throws RepositoryException {
    Ref ref = null;

    try {/*from www.j a v a  2s.c om*/
        ref = repository.getRef(version.getName());
    } catch (IOException e) {
        throw new RepositoryException("Cannot get revision for the given version '" + version.getName() + "'",
                e);
    }
    if (ref != null) {
        ObjectId id = ref.getPeeledObjectId();
        if (id == null) {
            id = ref.getObjectId();
        }

        return id;
    }
    return null;
}