aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-08-23 10:59:30 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-08-23 10:59:30 -0700
commit32466c33bae19aff03b95a02e0b7e72d4e2f11b8 (patch)
treeea652da99f86f53f8db72c40be8b027b75276ed3 /org.eclipse.jgit.test/tst/org/eclipse/jgit/storage
parent9d5b926ed164e8ee88d3b8b1e525d699adda01ba (diff)
downloadjgit-32466c33bae19aff03b95a02e0b7e72d4e2f11b8.tar.gz
jgit-32466c33bae19aff03b95a02e0b7e72d4e2f11b8.zip
Delete deprecated ObjectWriter
ObjectWriter is a deprecated API that people shouldn't be using. So get rid of it in favor of the ObjectInserter API. Change-Id: I6218bcb26b6b9ffb64e3e470dba5dca2e0a62fd4 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/storage')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ConcurrentRepackTest.java12
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java52
2 files changed, 45 insertions, 19 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ConcurrentRepackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ConcurrentRepackTest.java
index c8f2aad759..7608a51f22 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ConcurrentRepackTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/ConcurrentRepackTest.java
@@ -57,8 +57,8 @@ import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.ObjectLoader;
-import org.eclipse.jgit.lib.ObjectWriter;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.revwalk.RevObject;
@@ -265,8 +265,14 @@ public class ConcurrentRepackTest extends RepositoryTestCase {
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);
+ final ObjectInserter inserter = repo.newObjectInserter();
+ final ObjectId id;
+ try {
+ id = inserter.insert(Constants.OBJ_BLOB, bytes);
+ inserter.flush();
+ } finally {
+ inserter.release();
+ }
try {
parse(id);
fail("Object " + id.name() + " should not exist in test repository");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java
index 0352a40bfd..baa35f274b 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java
@@ -46,7 +46,6 @@
package org.eclipse.jgit.storage.file;
-import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
@@ -67,7 +66,6 @@ import org.eclipse.jgit.lib.FileTreeEntry;
import org.eclipse.jgit.lib.ObjectDatabase;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
-import org.eclipse.jgit.lib.ObjectWriter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
@@ -294,7 +292,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
public void test003_WriteShouldBeEmptyTree() throws IOException {
final Tree t = new Tree(db);
- final ObjectId emptyId = new ObjectWriter(db).writeBlob(new byte[0]);
+ final ObjectId emptyId = insertEmptyBlob();
t.addFile("should-be-empty").setId(emptyId);
t.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);
assertEquals("7bb943559a305bdd6bdee2cef6e5df2413c3d30a", t.getId()
@@ -419,7 +417,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
}
public void test012_SubtreeExternalSorting() throws IOException {
- final ObjectId emptyBlob = new ObjectWriter(db).writeBlob(new byte[0]);
+ final ObjectId emptyBlob = insertEmptyBlob();
final Tree t = new Tree(db);
final FileTreeEntry e0 = t.addFile("a-");
final FileTreeEntry e1 = t.addFile("a-b");
@@ -439,7 +437,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
}
public void test020_createBlobTag() throws IOException {
- final ObjectId emptyId = new ObjectWriter(db).writeBlob(new byte[0]);
+ final ObjectId emptyId = insertEmptyBlob();
final TagBuilder t = new TagBuilder();
t.setObjectId(emptyId, Constants.OBJ_BLOB);
t.setTag("test020");
@@ -456,10 +454,10 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
}
public void test021_createTreeTag() throws IOException {
- final ObjectId emptyId = new ObjectWriter(db).writeBlob(new byte[0]);
+ final ObjectId emptyId = insertEmptyBlob();
final Tree almostEmptyTree = new Tree(db);
almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
- final ObjectId almostEmptyTreeId = new ObjectWriter(db).writeTree(almostEmptyTree);
+ final ObjectId almostEmptyTreeId = insertTree(almostEmptyTree);
final TagBuilder t = new TagBuilder();
t.setObjectId(almostEmptyTreeId, Constants.OBJ_TREE);
t.setTag("test021");
@@ -476,10 +474,10 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
}
public void test022_createCommitTag() throws IOException {
- final ObjectId emptyId = new ObjectWriter(db).writeBlob(new byte[0]);
+ final ObjectId emptyId = insertEmptyBlob();
final Tree almostEmptyTree = new Tree(db);
almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
- final ObjectId almostEmptyTreeId = new ObjectWriter(db).writeTree(almostEmptyTree);
+ final ObjectId almostEmptyTreeId = insertTree(almostEmptyTree);
final CommitBuilder almostEmptyCommit = new CommitBuilder();
almostEmptyCommit.setAuthor(new PersonIdent(author, 1154236443000L, -2 * 60)); // not exactly the same
almostEmptyCommit.setCommitter(new PersonIdent(author, 1154236443000L, -2 * 60));
@@ -502,10 +500,10 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
}
public void test023_createCommitNonAnullii() throws IOException {
- final ObjectId emptyId = new ObjectWriter(db).writeBlob(new byte[0]);
+ final ObjectId emptyId = insertEmptyBlob();
final Tree almostEmptyTree = new Tree(db);
almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
- final ObjectId almostEmptyTreeId = new ObjectWriter(db).writeTree(almostEmptyTree);
+ final ObjectId almostEmptyTreeId = insertTree(almostEmptyTree);
CommitBuilder commit = new CommitBuilder();
commit.setTreeId(almostEmptyTreeId);
commit.setAuthor(new PersonIdent("Joe H\u00e4cker","joe@example.com",4294967295000L,60));
@@ -520,10 +518,10 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
}
public void test024_createCommitNonAscii() throws IOException {
- final ObjectId emptyId = new ObjectWriter(db).writeBlob(new byte[0]);
+ final ObjectId emptyId = insertEmptyBlob();
final Tree almostEmptyTree = new Tree(db);
almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
- final ObjectId almostEmptyTreeId = new ObjectWriter(db).writeTree(almostEmptyTree);
+ final ObjectId almostEmptyTreeId = insertTree(almostEmptyTree);
CommitBuilder commit = new CommitBuilder();
commit.setTreeId(almostEmptyTreeId);
commit.setAuthor(new PersonIdent("Joe H\u00e4cker","joe@example.com",4294967295000L,60));
@@ -537,9 +535,8 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
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));
+ final ObjectId id = new ObjectInserter.Formatter().idFor(
+ Constants.OBJ_BLOB, data);
assertEquals("4f561df5ecf0dfbd53a0dc0f37262fef075d9dde", id.name());
}
@@ -693,6 +690,29 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
}
+ private ObjectId insertEmptyBlob() throws IOException {
+ final ObjectId emptyId;
+ ObjectInserter oi = db.newObjectInserter();
+ try {
+ emptyId = oi.insert(Constants.OBJ_BLOB, new byte[] {});
+ oi.flush();
+ } finally {
+ oi.release();
+ }
+ return emptyId;
+ }
+
+ private ObjectId insertTree(Tree tree) throws IOException {
+ ObjectInserter oi = db.newObjectInserter();
+ try {
+ ObjectId id = oi.insert(Constants.OBJ_TREE, tree.format());
+ oi.flush();
+ return id;
+ } finally {
+ oi.release();
+ }
+ }
+
private ObjectId insertCommit(final CommitBuilder builder) throws IOException,
UnsupportedEncodingException {
ObjectInserter oi = db.newObjectInserter();