Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.TreeFormatter


  ObjectId writeTree(final DirCacheEntry[] cache, int cIdx,
      final int pathOffset, final ObjectInserter ow)
      throws UnmergedPathException, IOException {
    if (id == null) {
      final int endIdx = cIdx + entrySpan;
      final TreeFormatter fmt = new TreeFormatter(computeSize(cache,
          cIdx, pathOffset, ow));
      int childIdx = 0;
      int entryIdx = cIdx;

      while (entryIdx < endIdx) {
        final DirCacheEntry e = cache[entryIdx];
        final byte[] ep = e.path;
        if (childIdx < childCnt) {
          final DirCacheTree st = children[childIdx];
          if (st.contains(ep, pathOffset, ep.length)) {
            fmt.append(st.encodedName, TREE, st.id);
            entryIdx += st.entrySpan;
            childIdx++;
            continue;
          }
        }

        fmt.append(ep, pathOffset, ep.length - pathOffset, e
            .getFileMode(), e.idBuffer(), e.idOffset());
        entryIdx++;
      }

      id = ow.insert(fmt);
View Full Code Here


  }

  private TreeFormatter build() {
    byte[] nameBuf = new byte[OBJECT_ID_STRING_LENGTH];
    int nameLen = OBJECT_ID_STRING_LENGTH - prefixLen;
    TreeFormatter fmt = new TreeFormatter(treeSize(nameLen));
    NonNoteEntry e = nonNotes;

    for (int i = 0; i < cnt; i++) {
      Note n = notes[i];

      n.copyTo(nameBuf, 0);

      while (e != null
          && e.pathCompare(nameBuf, prefixLen, nameLen, REGULAR_FILE) < 0) {
        e.format(fmt);
        e = e.next;
      }

      fmt.append(nameBuf, prefixLen, nameLen, REGULAR_FILE, n.getData());
    }

    for (; e != null; e = e.next)
      e.format(fmt);
    return fmt;
View Full Code Here

  }

  private TreeFormatter build(boolean insert, ObjectInserter inserter)
      throws IOException {
    byte[] nameBuf = new byte[2];
    TreeFormatter fmt = new TreeFormatter(treeSize());
    NonNoteEntry e = nonNotes;

    for (int cell = 0; cell < 256; cell++) {
      NoteBucket b = table[cell];
      if (b == null)
        continue;

      nameBuf[0] = hexchar[cell >>> 4];
      nameBuf[1] = hexchar[cell & 0x0f];

      while (e != null && e.pathCompare(nameBuf, 0, 2, TREE) < 0) {
        e.format(fmt);
        e = e.next;
      }

      ObjectId id;
      if (insert) {
        id = b.writeTree(inserter);
      } else {
        id = b.getTreeId();
      }
      fmt.append(nameBuf, 0, 2, TREE, id);
    }

    for (; e != null; e = e.next)
      e.format(fmt);
    return fmt;
View Full Code Here

        // Create a blob object to insert into a tree
        ObjectId blobId = odi.insert(Constants.OBJ_BLOB,
            message.getBytes(Constants.CHARACTER_ENCODING));

        // Create a tree object to reference from a commit
        TreeFormatter tree = new TreeFormatter();
        tree.append(".branch", FileMode.REGULAR_FILE, blobId);
        ObjectId treeId = odi.insert(tree);

        // Create a commit object
        CommitBuilder commit = new CommitBuilder();
        commit.setAuthor(author);
View Full Code Here

        // Create a blob object to insert into a tree
        ObjectId blobId = odi.insert(Constants.OBJ_BLOB,
            message.getBytes(Constants.CHARACTER_ENCODING));

        // Create a tree object to reference from a commit
        TreeFormatter tree = new TreeFormatter();
        tree.append(".branch", FileMode.REGULAR_FILE, blobId);
        ObjectId treeId = odi.insert(tree);

        // Create a commit object
        CommitBuilder commit = new CommitBuilder();
        commit.setAuthor(author);
View Full Code Here

  ObjectId writeTree(final DirCacheEntry[] cache, int cIdx,
      final int pathOffset, final ObjectInserter ow)
      throws UnmergedPathException, IOException {
    if (id == null) {
      final int endIdx = cIdx + entrySpan;
      final TreeFormatter fmt = new TreeFormatter(computeSize(cache,
          cIdx, pathOffset, ow));
      int childIdx = 0;
      int entryIdx = cIdx;

      while (entryIdx < endIdx) {
        final DirCacheEntry e = cache[entryIdx];
        final byte[] ep = e.path;
        if (childIdx < childCnt) {
          final DirCacheTree st = children[childIdx];
          if (st.contains(ep, pathOffset, ep.length)) {
            fmt.append(st.encodedName, TREE, st.id);
            entryIdx += st.entrySpan;
            childIdx++;
            continue;
          }
        }

        fmt.append(ep, pathOffset, ep.length - pathOffset, e
            .getFileMode(), e.idBuffer(), e.idOffset());
        entryIdx++;
      }

      id = ow.insert(fmt);
View Full Code Here

    // open when we create it we won't write the object file out as a loose
    // object (as it already exists in the pack).
    //
    final Repository newdb = createBareRepository();
    final ObjectInserter oi = newdb.newObjectInserter();
    final ObjectId treeId = oi.insert(new TreeFormatter());
    oi.release();

    assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", treeId.name());
    final File o = new File(new File(new File(newdb.getDirectory(),
        "objects"), "4b"), "825dc642cb6eb9a060e54bf8d69288fbee4904");
View Full Code Here

  @Test
  public void test002_WriteEmptyTree2() throws IOException {
    // File shouldn't exist as it is in a test pack.
    //
    final ObjectId treeId = insertTree(new TreeFormatter());
    assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", treeId.name());
    final File o = new File(new File(
        new File(db.getDirectory(), "objects"), "4b"),
        "825dc642cb6eb9a060e54bf8d69288fbee4904");
    assertFalse("Exists " + o, o.isFile());
View Full Code Here

    }
  }

  @Test
  public void test009_CreateCommitOldFormat() throws IOException {
    final ObjectId treeId = insertTree(new TreeFormatter());
    final CommitBuilder c = new CommitBuilder();
    c.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
    c.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
    c.setMessage("A Commit\n");
    c.setTreeId(treeId);
View Full Code Here

    final ObjectInserter oi = db.newObjectInserter();
    try {
      final ObjectId blobId = oi.insert(Constants.OBJ_BLOB,
          "and this is the data in me\n".getBytes(Constants.CHARSET
              .name()));
      TreeFormatter fmt = new TreeFormatter();
      fmt.append("i-am-a-file", FileMode.REGULAR_FILE, blobId);
      treeId = oi.insert(fmt);
      oi.flush();
    } finally {
      oi.release();
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.lib.TreeFormatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.