Beispiel #1
0
 /**
  * Parse a commit from its canonical format.
  *
  * <p>This method inserts the commit directly into the caller supplied revision pool, making it
  * appear as though the commit exists in the repository, even if it doesn't. The repository under
  * the pool is not affected.
  *
  * @param rw the revision pool to allocate the commit within. The commit's tree and parent
  *     pointers will be obtained from this pool.
  * @param raw the canonical formatted commit to be parsed.
  * @return the parsed commit, in an isolated revision pool that is not available to the caller.
  * @throws IOException in case of RevWalk initialization fails
  */
 public static RevCommit parse(RevWalk rw, byte[] raw) throws IOException {
   ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
   boolean retain = rw.isRetainBody();
   rw.setRetainBody(true);
   RevCommit r = rw.lookupCommit(fmt.idFor(Constants.OBJ_COMMIT, raw));
   r.parseCanonical(rw, raw);
   rw.setRetainBody(retain);
   return r;
 }
Beispiel #2
0
 /**
  * Parse an annotated tag from its canonical format.
  *
  * <p>This method inserts the tag directly into the caller supplied revision pool, making it
  * appear as though the tag exists in the repository, even if it doesn't. The repository under the
  * pool is not affected.
  *
  * @param rw the revision pool to allocate the tag within. The tag's object pointer will be
  *     obtained from this pool.
  * @param raw the canonical formatted tag to be parsed.
  * @return the parsed tag, in an isolated revision pool that is not available to the caller.
  * @throws CorruptObjectException the tag contains a malformed header that cannot be handled.
  */
 public static RevTag parse(RevWalk rw, byte[] raw) throws CorruptObjectException {
   ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
   boolean retain = rw.isRetainBody();
   rw.setRetainBody(true);
   RevTag r = rw.lookupTag(fmt.idFor(Constants.OBJ_TAG, raw));
   r.parseCanonical(rw, raw);
   rw.setRetainBody(retain);
   return r;
 }
Beispiel #3
0
  void parseCanonical(final RevWalk walk, final byte[] raw) throws IOException {
    if (!walk.shallowCommitsInitialized) walk.initializeShallowCommits();

    final MutableObjectId idBuffer = walk.idBuffer;
    idBuffer.fromString(raw, 5);
    tree = walk.lookupTree(idBuffer);

    int ptr = 46;
    if (parents == null) {
      RevCommit[] pList = new RevCommit[1];
      int nParents = 0;
      for (; ; ) {
        if (raw[ptr] != 'p') break;
        idBuffer.fromString(raw, ptr + 7);
        final RevCommit p = walk.lookupCommit(idBuffer);
        if (nParents == 0) pList[nParents++] = p;
        else if (nParents == 1) {
          pList = new RevCommit[] {pList[0], p};
          nParents = 2;
        } else {
          if (pList.length <= nParents) {
            RevCommit[] old = pList;
            pList = new RevCommit[pList.length + 32];
            System.arraycopy(old, 0, pList, 0, nParents);
          }
          pList[nParents++] = p;
        }
        ptr += 48;
      }
      if (nParents != pList.length) {
        RevCommit[] old = pList;
        pList = new RevCommit[nParents];
        System.arraycopy(old, 0, pList, 0, nParents);
      }
      parents = pList;
    }

    // extract time from "committer "
    ptr = RawParseUtils.committer(raw, ptr);
    if (ptr > 0) {
      ptr = RawParseUtils.nextLF(raw, ptr, '>');

      // In 2038 commitTime will overflow unless it is changed to long.
      commitTime = RawParseUtils.parseBase10(raw, ptr, null);
    }

    if (walk.isRetainBody()) buffer = raw;
    flags |= PARSED;
  }
Beispiel #4
0
  void parseCanonical(final RevWalk walk, final byte[] rawTag) throws CorruptObjectException {
    final MutableInteger pos = new MutableInteger();
    final int oType;

    pos.value = 53; // "object $sha1\ntype "
    oType = Constants.decodeTypeString(this, rawTag, (byte) '\n', pos);
    walk.idBuffer.fromString(rawTag, 7);
    object = walk.lookupAny(walk.idBuffer, oType);

    int p = pos.value += 4; // "tag "
    final int nameEnd = RawParseUtils.nextLF(rawTag, p) - 1;
    tagName = RawParseUtils.decode(Constants.CHARSET, rawTag, p, nameEnd);

    if (walk.isRetainBody()) buffer = rawTag;
    flags |= PARSED;
  }