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

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

Introduction

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

Prototype

boolean isPeeled();

Source Link

Document

Whether the Ref represents a peeled tag.

Usage

From source file:fr.obeo.ariadne.ide.connector.git.internal.explorer.GitExplorer.java

License:Open Source License

/**
 * Computes the references, branches and tags of the Git repository and map them in the Ariadne
 * repository.//  ww w.ja  va2s  .c o  m
 * 
 * @param gitRepository
 *            The Git repository
 * @param ariadneRepository
 *            The Ariadne repository
 * @param monitor
 *            The progress monitor
 */
private void computeReferences(Repository gitRepository, fr.obeo.ariadne.model.scm.Repository ariadneRepository,
        IProgressMonitor monitor) {
    monitor.subTask(AriadneGitConnectorMessage.getString("GitExplorer.ComputingReferences")); //$NON-NLS-1$

    Map<String, Ref> allRefs = gitRepository.getAllRefs();
    for (Entry<String, Ref> entry : allRefs.entrySet()) {
        String key = entry.getKey();
        Ref reference = entry.getValue();

        ObjectId linkedObject = null;
        if (reference.isPeeled()) {
            linkedObject = this.getLinkedObject(reference);
        } else {
            if (reference.isSymbolic()) {
                linkedObject = this.getLinkedObject(reference.getLeaf());
            } else {
                linkedObject = this.getLinkedObject(reference);
            }
        }

        RevCommit commit = null;

        Set<RevCommit> keySet = this.commit2ariadneCommit.keySet();
        for (RevCommit revCommit : keySet) {
            if (revCommit.getId().equals(linkedObject)) {
                commit = revCommit;
            }
        }

        if (commit != null) {
            if (gitRepository.getTags().containsKey(key)) {
                // tag
                Tag tag = ScmFactory.eINSTANCE.createTag();
                tag.setCommit(this.commit2ariadneCommit.get(commit));
                tag.setName(reference.getName());
                ariadneRepository.getTags().add(tag);
            } else {
                // branch
                Branch branch = ScmFactory.eINSTANCE.createBranch();
                branch.setCommit(this.commit2ariadneCommit.get(commit));
                branch.setName(reference.getName());
                ariadneRepository.getBranches().add(branch);
            }
        } else {
            // A branch linked to something else than a commit...
        }
        monitor.worked(1);
    }
}

From source file:org.chodavarapu.jgitaws.repositories.RefRepository.java

License:Eclipse Distribution License

public Observable<Boolean> compareAndPut(String repositoryName, Ref oldRef, Ref newRef) {
    boolean isSymbolic = newRef.isSymbolic();
    boolean isPeeled = newRef.isPeeled();
    String target = newRef.isSymbolic() ? newRef.getTarget().getName() : newRef.getObjectId().name();

    logger.debug("Saving ref {} -> {} in repository {}", newRef.getName(), target, repositoryName);

    UpdateItemSpec updateSpec = new UpdateItemSpec()
            .withPrimaryKey(new PrimaryKey(new KeyAttribute(REPOSITORY_NAME_ATTRIBUTE, repositoryName),
                    new KeyAttribute(NAME_ATTRIBUTE, newRef.getName())));

    StringBuilder updateExpression = new StringBuilder(COMPARE_AND_PUT_EXPRESSION);
    ValueMap valueMap = new ValueMap().withString(":target", target).withBoolean(":isSymbolic", isSymbolic)
            .withBoolean(":isPeeled", isPeeled);

    if (isPeeled && newRef.getPeeledObjectId() != null) {
        updateExpression.append(", ");
        updateExpression.append(PEELED_TARGET_ATTRIBUTE);
        updateExpression.append(" = :peeledTarget");
        valueMap = valueMap.withString(":peeledTarget", newRef.getPeeledObjectId().name());
    }//from   w  ww  .j av  a  2s  . co  m

    if (oldRef != null && oldRef.getStorage() != Ref.Storage.NEW) {
        String expected = oldRef.isSymbolic() ? oldRef.getTarget().getName() : oldRef.getObjectId().name();
        updateSpec = updateSpec.withConditionExpression("#target = :expected")
                .withNameMap(new NameMap().with("#target", TARGET_ATTRIBUTE));
        valueMap = valueMap.withString(":expected", expected);
    }

    updateSpec = updateSpec.withUpdateExpression(updateExpression.toString()).withValueMap(valueMap);

    return configuration.getDynamoClient()
            .updateItem(configuration.getRefsTableName(), updateSpec, tableCreator).map(v -> true)
            .doOnNext(v -> logger.debug("Saved ref {} in repository {}", newRef.getName(), repositoryName))
            .onErrorReturn(t -> false);
}

From source file:org.eclipse.orion.server.git.jobs.LogCommand.java

License:Eclipse Distribution License

/**
 * Add all refs as commits to start the graph traversal from.
 *
 * @see #add(AnyObjectId)/*  w w w. j  av  a  2 s.  c  om*/
 * @return {@code this}
 * @throws IOException
 *             the references could not be accessed
 */
public LogCommand all() throws IOException {
    Map<String, Ref> refs = getRepository().getRefDatabase().getRefs(ALL);
    for (Ref ref : refs.values()) {
        if (!ref.isPeeled())
            ref = getRepository().peel(ref);

        ObjectId objectId = ref.getPeeledObjectId();
        if (objectId == null)
            objectId = ref.getObjectId();
        RevCommit commit = null;
        try {
            commit = walk.parseCommit(objectId);
        } catch (MissingObjectException e) {
            // ignore: the ref points to an object that does not exist;
            // it should be ignored as traversal starting point.
        } catch (IncorrectObjectTypeException e) {
            // ignore: the ref points to an object that is not a commit
            // (e.g. a tree or a blob);
            // it should be ignored as traversal starting point.
        }
        if (commit != null)
            add(commit);
    }
    return this;
}