Java 类org.eclipse.jgit.lib.ObjectIdRef 实例源码

项目:appformer    文件:GetRef.java   
public Ref execute() {
    try {
        final Ref value = repo.getRefDatabase().getRef(name);
        if (value != null) {
            return value;
        }
        final ObjectId treeRef = repo.resolve(name + "^{tree}");
        if (treeRef != null) {
            final ObjectLoader loader = repo.getObjectDatabase().newReader().open(treeRef);
            if (loader.getType() == OBJ_TREE) {
                return new ObjectIdRef.PeeledTag(Ref.Storage.NEW,
                                                 name,
                                                 ObjectId.fromString(name),
                                                 treeRef);
            }
        }
    } catch (final Exception ignored) {
    }
    return null;
}
项目:appformer    文件:RefTreeUpdateCommand.java   
private void symRef(final Git git,
                    final String name,
                    final String dst)
        throws java.io.IOException {
    commit(git.getRepository(),
           null,
           (reader, tree) -> {
               Ref old = tree.exactRef(reader,
                                       name);
               Ref newx = tree.exactRef(reader,
                                        dst);
               final Command n;
               if (newx != null) {
                   n = new Command(old,
                                   new SymbolicRef(name,
                                                   newx));
               } else {
                   n = new Command(old,
                                   new SymbolicRef(name,
                                                   new ObjectIdRef.Unpeeled(Ref.Storage.NEW,
                                                                            dst,
                                                                            null)));
               }
               return tree.apply(Collections.singleton(n));
           });
}
项目:jgit-cassandra    文件:RefStore.java   
/**
 * Parses a Cassandra refs table row and converts it to a Ref
 *
 * @param row a single Cassandra row to parse
 * @return a ref, or null if the "row" parameter is null
 * @throws IOException           if an exception occurs when communicating to the
 *                               database
 * @throws IllegalStateException if the "type" field read back from the
 *                               database is not one of the four handled
 *                               types (@see RefType).
 */
private Ref rowToRef(Row row) throws IOException {
    if (row == null) {
        return null;
    }

    final String name = row.getString("name");
    final String value = row.getString("value");
    final int refType = row.getInt("type");

    if (refType == RefType.PEELED_NONTAG.getValue()) {
        return new ObjectIdRef.PeeledNonTag(Ref.Storage.NETWORK, name,
                ObjectId.fromString(value));
    } else if (refType == RefType.PEELED_TAG.getValue()) {
        final String auxValue = row.getString("aux_value");
        return new ObjectIdRef.PeeledTag(Ref.Storage.NETWORK, name,
                ObjectId.fromString(value),
                ObjectId.fromString(auxValue));
    } else if (refType == RefType.UNPEELED.getValue()) {
        return new ObjectIdRef.Unpeeled(Ref.Storage.NETWORK, name,
                ObjectId.fromString(value));
    } else if (refType == RefType.SYMBOLIC.getValue()) {
        return new SymbolicRef(name, get(value));
    } else {
        throw new IllegalStateException("Unhandled ref type: " + refType);
    }
}
项目:jgit-cassandra    文件:RefStore.java   
/**
 * Inserts a single ref into the database
 *
 * @throws IllegalStateException if the reference concrete type is not
 *                               one of the four handled classes
 *                               (@see RefType).
 */
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);
    }
}
项目:appformer    文件:RefTreeUpdateCommand.java   
private static Ref toRef(final RevWalk rw,
                         final ObjectId id,
                         final String name,
                         final boolean mustExist) throws IOException {
    if (ObjectId.zeroId().equals(id)) {
        return null;
    }

    try {
        RevObject o = rw.parseAny(id);
        if (o instanceof RevTag) {
            RevObject p = rw.peel(o);
            return new ObjectIdRef.PeeledTag(NETWORK,
                                             name,
                                             id,
                                             p.copy());
        }
        return new ObjectIdRef.PeeledNonTag(NETWORK,
                                            name,
                                            id);
    } catch (MissingObjectException e) {
        if (mustExist) {
            throw e;
        }
        return new ObjectIdRef.Unpeeled(NETWORK,
                                        name,
                                        id);
    }
}
项目:jgit-cassandra    文件:RefStore.java   
/**
 * Parses a Cassandra refs table row and converts it to a Ref
 *
 * @param row a single Cassandra row to parse
 * @return a ref, or null if the "row" parameter is null
 * @throws IOException           if an exception occurs when communicating to the
 *                               database
 * @throws IllegalStateException if the "type" field read back from the
 *                               database is not one of the four handled
 *                               types (@see RefType).
 */
private Ref rowToRef(Row row) throws IOException {
    if (row == null) {
        return null;
    }

    final String name = row.getString("name");
    final String value = row.getString("value");
    final int refType = row.getInt("type");

    if (refType == RefType.PEELED_NONTAG.getValue()) {
        return new ObjectIdRef.PeeledNonTag(Ref.Storage.NETWORK, name,
                ObjectId.fromString(value));
    } else if (refType == RefType.PEELED_TAG.getValue()) {
        final String auxValue = row.getString("aux_value");
        return new ObjectIdRef.PeeledTag(Ref.Storage.NETWORK, name,
                ObjectId.fromString(value),
                ObjectId.fromString(auxValue));
    } else if (refType == RefType.UNPEELED.getValue()) {
        return new ObjectIdRef.Unpeeled(Ref.Storage.NETWORK, name,
                ObjectId.fromString(value));
    } else if (refType == RefType.SYMBOLIC.getValue()) {
        return new SymbolicRef(name, get(value));
    } else {
        throw new IllegalStateException("Unhandled ref type: " + refType);
    }
}
项目:jgit-cassandra    文件:RefStore.java   
/**
 * Inserts a single ref into the database
 *
 * @throws IllegalStateException if the reference concrete type is not
 *                               one of the four handled classes
 *                               (@see RefType).
 */
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);
    }
}
项目:git-client-plugin    文件:BranchTest.java   
public BranchTest() {
    this.branchSHA1 = "fa71f704f9b90fa1f857d1623f3fe33fa2277ca9";
    this.branchName = "origin/master";
    this.branchHead = ObjectId.fromString(branchSHA1);
    this.refPrefix = "refs/remotes/";
    this.branchRef = new ObjectIdRef.PeeledNonTag(Ref.Storage.NEW, refPrefix + branchName, branchHead);
    this.branch = new Branch(branchName, branchHead);
    this.branchFromRef = new Branch(branchRef);
}
项目:git-client-plugin    文件:BranchTest.java   
@Test
public void constructorRefArgStripped() {
    Ref ref = new ObjectIdRef.PeeledNonTag(Ref.Storage.LOOSE, refPrefix + branchName, branchHead);
    Branch strippedBranch = new Branch(ref);
    assertThat(strippedBranch.getName(), is(branchName));
}