Example #1
0
  public void testWriteTree() throws Exception {

    insertAndAdd(points1, lines1);

    Tuple<ObjectId, BoundingBox> result = index.writeTree(repo.getHead());

    // this new root tree must exist on the repo db, but is not set as the current head. In
    // fact, it is headless, as there's no commit pointing to it. CommitOp does that.
    ObjectId newRootTreeId = result.getFirst();

    assertNotNull(newRootTreeId);
    assertFalse(repo.getRootTreeId().equals(newRootTreeId));
    // but the index staged root shall be pointing to it
    // assertEquals(newRootTreeId, index.getStaged().getId());

    RevTree tree = repo.getTree(newRootTreeId);
    assertEquals(2, tree.size().intValue());

    ObjectDatabase odb = repo.getObjectDatabase();

    assertNotNull(odb.getTreeChild(tree, pointsNs, pointsName, points1.getIdentifier().getID()));

    assertNotNull(odb.getTreeChild(tree, linesNs, linesName, lines1.getIdentifier().getID()));

    // simulate a commit so the repo head points to this new tree
    ObjectInserter objectInserter = repo.newObjectInserter();
    RevCommit commit = new RevCommit(ObjectId.NULL);
    commit.setTreeId(newRootTreeId);
    ObjectId commitId =
        objectInserter.insert(WrappedSerialisingFactory.getInstance().createCommitWriter(commit));
    final Ref newHead = repo.updateRef(new Ref(Ref.HEAD, commitId, TYPE.COMMIT));

    index.deleted(linesNs, linesName, lines1.getIdentifier().getID());
    index.stage(new NullProgressListener());

    result = index.writeTree(new Ref("", newRootTreeId, TYPE.TREE));

    newRootTreeId = result.getFirst();
    assertNotNull(newRootTreeId);
    assertFalse(repo.getRootTreeId().equals(newRootTreeId));

    tree = repo.getTree(newRootTreeId);
    assertNotNull(odb.getTreeChild(tree, pointsNs, pointsName, points1.getIdentifier().getID()));

    assertNull(odb.getTreeChild(tree, linesNs, linesName, lines1.getIdentifier().getID()));
  }
Example #2
0
  public void testWriteTree2() throws Exception {

    final ObjectDatabase repoDb = repo.getObjectDatabase();

    // insert and commit feature1_1
    final ObjectId oId1_1 = insertAndAdd(points1);

    final ObjectId newRepoTreeId1;
    {
      Tuple<ObjectId, BoundingBox> writeResult;
      writeResult = index.writeTree(repo.getHead());

      newRepoTreeId1 = writeResult.getFirst();
      // assertEquals(index.getDatabase().getStagedRootRef().getObjectId(), newRepoTreeId1);

      RevTree newRepoTree = repoDb.getTree(newRepoTreeId1);

      System.err.println("++++++++++ new repo tree 1: " + newRepoTreeId1 + " ++++++++++++");
      newRepoTree.accept(new PrintVisitor(repoDb, new PrintWriter(System.err)));
      // check feature1_1 is there
      assertEquals(
          oId1_1, repoDb.getTreeChild(newRepoTree, pointsNs, pointsName, idP1).getObjectId());
    }

    // insert and add (stage) points2, points3, and lines1
    final ObjectId oId1_2 = insertAndAdd(points2);
    final ObjectId oId1_3 = insertAndAdd(points3);
    final ObjectId oId2_1 = insertAndAdd(lines1);

    { // simulate a commit so the repo head points to this new tree
      ObjectInserter objectInserter = repo.newObjectInserter();
      RevCommit commit = new RevCommit(ObjectId.NULL);
      commit.setTreeId(newRepoTreeId1);
      ObjectId commitId =
          objectInserter.insert(WrappedSerialisingFactory.getInstance().createCommitWriter(commit));
      final Ref newHead = repo.updateRef(new Ref(Ref.HEAD, commitId, TYPE.COMMIT));
    }

    final ObjectId newRepoTreeId2;
    {
      Tuple<ObjectId, BoundingBox> writeResult;
      // write comparing the the previously generated tree instead of the repository HEAD, as
      // it was not updated (no commit op was performed)
      Ref repoRootRef = new Ref("", newRepoTreeId1, TYPE.TREE);
      writeResult = index.writeTree(repoRootRef);

      newRepoTreeId2 = writeResult.getFirst();
      // assertEquals(index.getDatabase().getStagedRootRef().getObjectId(), newRepoTreeId2);

      System.err.println("++++++++ new root 2:" + newRepoTreeId2 + " ++++++++++");
      RevTree newRepoTree = repoDb.getTree(newRepoTreeId2);

      newRepoTree.accept(new PrintVisitor(repoDb, new PrintWriter(System.err)));

      // check feature1_2, feature1_2 and feature2_1
      Ref treeChild;
      assertNotNull(treeChild = repoDb.getTreeChild(newRepoTree, pointsNs, pointsName, idP2));
      assertEquals(oId1_2, treeChild.getObjectId());

      assertNotNull(treeChild = repoDb.getTreeChild(newRepoTree, pointsNs, pointsName, idP3));
      assertEquals(oId1_3, treeChild.getObjectId());

      assertNotNull(treeChild = repoDb.getTreeChild(newRepoTree, linesNs, linesName, idL1));
      assertEquals(oId2_1, treeChild.getObjectId());

      // as well as feature1_1 from the previous commit
      assertNotNull(treeChild = repoDb.getTreeChild(newRepoTree, pointsNs, pointsName, idP1));
      assertEquals(oId1_1, treeChild.getObjectId());
    }

    { // simulate a commit so the repo head points to this new tree
      ObjectInserter objectInserter = repo.newObjectInserter();
      RevCommit commit = new RevCommit(ObjectId.NULL);
      commit.setTreeId(newRepoTreeId2);
      ObjectId commitId =
          objectInserter.insert(WrappedSerialisingFactory.getInstance().createCommitWriter(commit));
      final Ref newHead = repo.updateRef(new Ref(Ref.HEAD, commitId, TYPE.COMMIT));
    }

    // delete feature1_1, feature1_3, and feature2_1
    assertTrue(deleteAndAdd(points1));
    assertTrue(deleteAndAdd(points3));
    assertTrue(deleteAndAdd(lines1));
    // and insert feature2_2
    final ObjectId oId2_2 = insertAndAdd(lines2);

    final ObjectId newRepoTreeId3;
    {
      Tuple<ObjectId, BoundingBox> writeResult;
      // write comparing the the previously generated tree instead of the repository HEAD, as
      // it was not updated (no commit op was performed)
      Ref repoRootRef = new Ref("", newRepoTreeId2, TYPE.TREE);
      writeResult = index.writeTree(repoRootRef);

      newRepoTreeId3 = writeResult.getFirst();
      // assertEquals(index.getDatabase().getStagedRootRef().getObjectId(), newRepoTreeId3);

      System.err.println("++++++++ new root 3:" + newRepoTreeId3 + " ++++++++++");
      RevTree newRepoTree = repoDb.getTree(newRepoTreeId3);

      newRepoTree.accept(new PrintVisitor(repoDb, new PrintWriter(System.err)));

      // and check only feature1_2 and feature2_2 remain
      assertNull(repoDb.getTreeChild(newRepoTree, pointsNs, pointsName, idP1));
      assertNull(repoDb.getTreeChild(newRepoTree, pointsNs, pointsName, idP3));
      assertNull(repoDb.getTreeChild(newRepoTree, linesNs, linesName, idL3));

      assertEquals(
          oId1_2, repoDb.getTreeChild(newRepoTree, pointsNs, pointsName, idP2).getObjectId());
      assertEquals(
          oId2_2, repoDb.getTreeChild(newRepoTree, linesNs, linesName, idL2).getObjectId());
    }
  }