Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.ObjectWriter


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

  public void test023_createCommitNonAnullii() 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);
    Commit commit = new Commit(db);
    commit.setTreeId(almostEmptyTreeId);
    commit.setAuthor(new PersonIdent("Joe H\u00e4cker","joe@example.com",4294967295000L,60));
    commit.setCommitter(new PersonIdent("Joe Hacker","joe2@example.com",4294967295000L,60));
    commit.setEncoding("UTF-8");
    commit.setMessage("\u00dcbergeeks");
    ObjectId cid = new ObjectWriter(db).writeCommit(commit);
    assertEquals("4680908112778718f37e686cbebcc912730b3154", cid.name());
    Commit loadedCommit = db.mapCommit(cid);
    assertNotSame(loadedCommit, commit);
    assertEquals(commit.getMessage(), loadedCommit.getMessage());
  }
View Full Code Here


    assertNotSame(loadedCommit, commit);
    assertEquals(commit.getMessage(), loadedCommit.getMessage());
  }

  public void test024_createCommitNonAscii() 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);
    Commit commit = new Commit(db);
    commit.setTreeId(almostEmptyTreeId);
    commit.setAuthor(new PersonIdent("Joe H\u00e4cker","joe@example.com",4294967295000L,60));
    commit.setCommitter(new PersonIdent("Joe Hacker","joe2@example.com",4294967295000L,60));
    commit.setEncoding("ISO-8859-1");
    commit.setMessage("\u00dcbergeeks");
    ObjectId cid = new ObjectWriter(db).writeCommit(commit);
    assertEquals("2979b39d385014b33287054b87f77bcb3ecb5ebf", cid.name());
  }
View Full Code Here

  public void test025_computeSha1NoStore() throws IOException {
    byte[] data = "test025 some data, more than 16 bytes to get good coverage"
        .getBytes("ISO-8859-1");
    // TODO: but we do not test legacy header writing
    final ObjectId id = new ObjectWriter(db).computeBlobSha1(data.length,
        new ByteArrayInputStream(data));
    assertEquals("4f561df5ecf0dfbd53a0dc0f37262fef075d9dde", id.name());
  }
View Full Code Here

  private RevObject writeBlob(final Repository repo, final String data)
      throws IOException {
    final RevWalk revWalk = new RevWalk(repo);
    final byte[] bytes = Constants.encode(data);
    final ObjectWriter ow = new ObjectWriter(repo);
    final ObjectId id = ow.writeBlob(bytes);
    try {
      parse(id);
      fail("Object " + id.name() + " should not exist in test repository");
    } catch (MissingObjectException e) {
      // Ok
View Full Code Here

    if (filepatterns.contains("."))
      addAll = true;

    try {
      dc = repo.lockDirCache();
      ObjectWriter ow = new ObjectWriter(repo);
      DirCacheIterator c;

      DirCacheBuilder builder = dc.builder();
      final TreeWalk tw = new TreeWalk(repo);
      tw.reset();
      tw.addTree(new DirCacheBuildIterator(builder));
      if (workingTreeIterator == null)
        workingTreeIterator = new FileTreeIterator(repo);
      tw.addTree(workingTreeIterator);
      tw.setRecursive(true);
      if (!addAll)
        tw.setFilter(PathFilterGroup.createFromStrings(filepatterns));

      String lastAddedFile = null;

      while (tw.next()) {
        String path = tw.getPathString();

        final File file = new File(repo.getWorkTree(), path);
        WorkingTreeIterator f = tw.getTree(1, WorkingTreeIterator.class);
        if (tw.getTree(0, DirCacheIterator.class) == null &&
            f != null && f.isEntryIgnored()) {
          // file is not in index but is ignored, do nothing
        }
        // In case of an existing merge conflict the
        // DirCacheBuildIterator iterates over all stages of
        // this path, we however want to add only one
        // new DirCacheEntry per path.
        else if (!(path.equals(lastAddedFile))) {
          if (!(update && tw.getTree(0, DirCacheIterator.class) == null)) {
            if (f != null) { // the file exists
              DirCacheEntry entry = new DirCacheEntry(path);
              entry.setLength((int)f.getEntryLength());
              entry.setLastModified(f.getEntryLastModified());
              entry.setFileMode(f.getEntryFileMode());
              entry.setObjectId(ow.writeBlob(file));

              builder.add(entry);
              lastAddedFile = path;
            } else if (!update){
              c = tw.getTree(0, DirCacheIterator.class);
View Full Code Here

        commit.setTreeId(treeId);
        commit.setMessage(message.replaceAll("\r", "\n"));
        commit.setAuthor(personIdent);
        commit.setCommitter(personIdent);

        ObjectWriter writer = new ObjectWriter(repository);
        return writer.writeCommit(commit);
    }
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.