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

项目: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);
    }
}
项目:gerrit    文件:VisibleRefFilter.java   
private Map<String, Ref> addUsersSelfSymref(Map<String, Ref> refs) {
  if (user.get().isIdentifiedUser()) {
    Ref r = refs.get(RefNames.refsUsers(user.get().getAccountId()));
    if (r != null) {
      SymbolicRef s = new SymbolicRef(REFS_USERS_SELF, r);
      refs = new HashMap<>(refs);
      refs.put(s.getName(), s);
    }
  }
  return refs;
}
项目: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);
    }
}
项目:cloudata    文件:CloudRefDatabase.java   
static RefData toModel(RepositoryData repositoryData, Ref ref) {
  RefData.Builder data = RefData.newBuilder();

  String name = ref.getName();
  if (name != null) {
    data.setName(name);
  }

  if (ref instanceof SymbolicRef) {
    Ref target = ref.getTarget();
    if (target == null) {
      throw new IllegalStateException();
    }

    if (target instanceof Unpeeled) {
      String targetName = target.getName();
      if (targetName != null) {
        data.setTargetName(targetName);
      } else {
        throw new IllegalStateException();
      }
    } else {
      throw new IllegalArgumentException();
    }
  } else if (ref instanceof PeeledNonTag) {
    ObjectId objectId = ref.getObjectId();
    if (objectId != null) {
      byte[] buf = new byte[20];
      objectId.copyRawTo(buf, 0);
      data.setObjectId(ByteString.copyFrom(buf));
    } else {
      throw new IllegalArgumentException();
    }
  } else {
    throw new IllegalArgumentException();
  }

  data.setRepositoryId(repositoryData.getRepositoryId());
  return data.build();
}