Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.ObjectWriter


  private DirCacheEntry makeFile(final String path) throws Exception {
    final byte[] pathBytes = Constants.encode(path);
    final DirCacheEntry ent = new DirCacheEntry(path);
    ent.setFileMode(REGULAR_FILE);
    ent.setObjectId(new ObjectWriter(db).computeBlobSha1(pathBytes.length,
        new ByteArrayInputStream(pathBytes)));
    return ent;
  }
View Full Code Here


    } finally {
      br.close();
    }

    pm.beginTask("Rewriting commits", queue.size());
    final ObjectWriter ow = new ObjectWriter(db);
    final ObjectId emptyTree = ow.writeTree(new Tree(db));
    final PersonIdent me = new PersonIdent("jgit rebuild-commitgraph",
        "rebuild-commitgraph@localhost");
    while (!queue.isEmpty()) {
      final ListIterator<ToRewrite> itr = queue
          .listIterator(queue.size());
      queue = new ArrayList<ToRewrite>();
      REWRITE: while (itr.hasPrevious()) {
        final ToRewrite t = itr.previous();
        final ObjectId[] newParents = new ObjectId[t.oldParents.length];
        for (int k = 0; k < t.oldParents.length; k++) {
          final ToRewrite p = toRewrite.get(t.oldParents[k]);
          if (p != null) {
            if (p.newId == null) {
              // Must defer until after the parent is rewritten.
              queue.add(t);
              continue REWRITE;
            } else {
              newParents[k] = p.newId;
            }
          } else {
            // We have the old parent object. Use it.
            //
            newParents[k] = t.oldParents[k];
          }
        }

        final Commit newc = new Commit(db);
        newc.setTreeId(emptyTree);
        newc.setAuthor(new PersonIdent(me, new Date(t.commitTime)));
        newc.setCommitter(newc.getAuthor());
        newc.setParentIds(newParents);
        newc.setMessage("ORIGINAL " + t.oldId.name() + "\n");
        t.newId = ow.writeCommit(newc);
        rewrites.put(t.oldId, t.newId);
        pm.update(1);
      }
    }
    pm.endTask();
View Full Code Here

  private DirCacheEntry makeEntry(final String path, final FileMode mode)
      throws Exception {
    final byte[] pathBytes = Constants.encode(path);
    final DirCacheEntry ent = new DirCacheEntry(path);
    ent.setFileMode(mode);
    ent.setObjectId(new ObjectWriter(db).computeBlobSha1(pathBytes.length,
        new ByteArrayInputStream(pathBytes)));
    return ent;
  }
View Full Code Here

      B.setId(bId);

      Tree A_A = A.addTree("A");
      Tree A_B = A.addTree("B");

      final ObjectWriter ow = new ObjectWriter(db);
      A_A.setId(ow.writeTree(A_A));
      A_B.setId(ow.writeTree(A_B));
      A.setId(ow.writeTree(A));
      root.setId(ow.writeTree(root));

      tree_root = rw.parseTree(root.getId());
      tree_A = rw.parseTree(A.getId());
      tree_AB = rw.parseTree(A_A.getId());
      assertSame(tree_AB, rw.parseTree(A_B.getId()));
View Full Code Here

import org.eclipse.jgit.treewalk.filter.TreeFilter;

public class TreeWalkBasicDiffTest extends RepositoryTestCase {
  public void testMissingSubtree_DetectFileAdded_FileModified()
      throws Exception {
    final ObjectWriter ow = new ObjectWriter(db);
    final ObjectId aFileId = ow.writeBlob("a".getBytes());
    final ObjectId bFileId = ow.writeBlob("b".getBytes());
    final ObjectId cFileId1 = ow.writeBlob("c-1".getBytes());
    final ObjectId cFileId2 = ow.writeBlob("c-2".getBytes());

    // Create sub-a/empty, sub-c/empty = hello.
    final ObjectId oldTree;
    {
      final Tree root = new Tree(db);
      {
        final Tree subA = root.addTree("sub-a");
        subA.addFile("empty").setId(aFileId);
        subA.setId(ow.writeTree(subA));
      }
      {
        final Tree subC = root.addTree("sub-c");
        subC.addFile("empty").setId(cFileId1);
        subC.setId(ow.writeTree(subC));
      }
      oldTree = ow.writeTree(root);
    }

    // Create sub-a/empty, sub-b/empty, sub-c/empty.
    final ObjectId newTree;
    {
      final Tree root = new Tree(db);
      {
        final Tree subA = root.addTree("sub-a");
        subA.addFile("empty").setId(aFileId);
        subA.setId(ow.writeTree(subA));
      }
      {
        final Tree subB = root.addTree("sub-b");
        subB.addFile("empty").setId(bFileId);
        subB.setId(ow.writeTree(subB));
      }
      {
        final Tree subC = root.addTree("sub-c");
        subC.addFile("empty").setId(cFileId2);
        subC.setId(ow.writeTree(subC));
      }
      newTree = ow.writeTree(root);
    }

    final TreeWalk tw = new TreeWalk(db);
    tw.reset(new ObjectId[] { oldTree, newTree });
    tw.setRecursive(true);
View Full Code Here

    assertFalse("Exists " + o, o.isFile());
  }

  public void test003_WriteShouldBeEmptyTree() throws IOException {
    final Tree t = new Tree(db);
    final ObjectId emptyId = new ObjectWriter(db).writeBlob(new byte[0]);
    t.addFile("should-be-empty").setId(emptyId);
    t.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);
    assertEquals("7bb943559a305bdd6bdee2cef6e5df2413c3d30a", t.getId()
        .name());
View Full Code Here

    assertEquals(c.getAuthor(), c2.getAuthor());
    assertEquals(c.getCommitter(), c2.getCommitter());
  }

  public void test012_SubtreeExternalSorting() throws IOException {
    final ObjectId emptyBlob = new ObjectWriter(db).writeBlob(new byte[0]);
    final Tree t = new Tree(db);
    final FileTreeEntry e0 = t.addFile("a-");
    final FileTreeEntry e1 = t.addFile("a-b");
    final FileTreeEntry e2 = t.addFile("a/b");
    final FileTreeEntry e3 = t.addFile("a=");
View Full Code Here

    assertEquals(ObjectId.fromString("b47a8f0a4190f7572e11212769090523e23eb1ea"),
        t.getId());
  }

  public void test020_createBlobTag() throws IOException {
    final ObjectId emptyId = new ObjectWriter(db).writeBlob(new byte[0]);
    final Tag t = new Tag(db);
    t.setObjId(emptyId);
    t.setType("blob");
    t.setTag("test020");
    t.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
 
View Full Code Here

    // We do not repeat the plain tag test for other object types
  }

  public void test021_createTreeTag() throws IOException {
    final ObjectId emptyId = new ObjectWriter(db).writeBlob(new byte[0]);
    final Tree almostEmptyTree = new Tree(db);
    almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
    final ObjectId almostEmptyTreeId = new ObjectWriter(db).writeTree(almostEmptyTree);
    final Tag t = new Tag(db);
    t.setObjId(almostEmptyTreeId);
    t.setType("tree");
    t.setTag("test021");
    t.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
 
View Full Code Here

    assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.getAuthor());
    assertEquals("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag.getObjId().name());
  }

  public void test022_createCommitTag() throws IOException {
    final ObjectId emptyId = new ObjectWriter(db).writeBlob(new byte[0]);
    final Tree almostEmptyTree = new Tree(db);
    almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
    final ObjectId almostEmptyTreeId = new ObjectWriter(db).writeTree(almostEmptyTree);
    final Commit almostEmptyCommit = new Commit(db);
    almostEmptyCommit.setAuthor(new PersonIdent(author, 1154236443000L, -2 * 60)); // not exactly the same
    almostEmptyCommit.setCommitter(new PersonIdent(author, 1154236443000L, -2 * 60));
    almostEmptyCommit.setMessage("test022\n");
    almostEmptyCommit.setTreeId(almostEmptyTreeId);
    ObjectId almostEmptyCommitId = new ObjectWriter(db).writeCommit(almostEmptyCommit);
    final Tag t = new Tag(db);
    t.setObjId(almostEmptyCommitId);
    t.setType("commit");
    t.setTag("test022");
    t.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
 
View Full Code Here

TOP

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

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.