aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2010-06-14 16:53:13 -0700
committerShawn O. Pearce <spearce@spearce.org>2010-06-25 17:46:41 -0700
commit88530a179e2ddfa81de5cc441a27d66521334608 (patch)
tree960de314a128a2a2e8df10db5d8181bbc55b28f6
parentcad10e6640258fd6bc6bc3183e4dbc61e83bf544 (diff)
downloadjgit-88530a179e2ddfa81de5cc441a27d66521334608.tar.gz
jgit-88530a179e2ddfa81de5cc441a27d66521334608.zip
Start using ObjectInserter instead of ObjectWriter
Some newer style APIs are updated to use the newer ObjectInserter interface instead of the now deprecated ObjectWriter. In many of the unit tests we don't bother to release the inserter, these are typically using the file backend which doesn't need a release, but in the future should use an in-memory HashMap based store, which really wouldn't need it either. Change-Id: I91a15e1dc42da68e6715397814e30fbd87fa2e73 Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rw-r--r--org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java54
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java20
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java33
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTestCase.java26
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java93
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/Tag.java11
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java12
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java12
12 files changed, 187 insertions, 107 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
index 279762ac67..dbf4eaf4ce 100644
--- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
+++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
@@ -79,7 +79,7 @@ import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectChecker;
import org.eclipse.jgit.lib.ObjectDirectory;
import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.ObjectWriter;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PackFile;
import org.eclipse.jgit.lib.PackWriter;
import org.eclipse.jgit.lib.PersonIdent;
@@ -128,7 +128,7 @@ public class TestRepository<R extends Repository> {
private final RevWalk pool;
- private final ObjectWriter writer;
+ private final ObjectInserter inserter;
private long now;
@@ -155,7 +155,7 @@ public class TestRepository<R extends Repository> {
public TestRepository(R db, RevWalk rw) throws IOException {
this.db = db;
this.pool = rw;
- this.writer = new ObjectWriter(db);
+ this.inserter = db.newObjectInserter();
this.now = 1236977987000L;
}
@@ -205,7 +205,14 @@ public class TestRepository<R extends Repository> {
* @throws Exception
*/
public RevBlob blob(final byte[] content) throws Exception {
- return pool.lookupBlob(writer.writeBlob(content));
+ ObjectId id;
+ try {
+ id = inserter.insert(Constants.OBJ_BLOB, content);
+ inserter.flush();
+ } finally {
+ inserter.release();
+ }
+ return pool.lookupBlob(id);
}
/**
@@ -241,7 +248,14 @@ public class TestRepository<R extends Repository> {
for (final DirCacheEntry e : entries)
b.add(e);
b.finish();
- return pool.lookupTree(dc.writeTree(writer));
+ ObjectId root;
+ try {
+ root = dc.writeTree(inserter);
+ inserter.flush();
+ } finally {
+ inserter.release();
+ }
+ return pool.lookupTree(root);
}
/**
@@ -351,7 +365,14 @@ public class TestRepository<R extends Repository> {
c.setAuthor(new PersonIdent(author, new Date(now)));
c.setCommitter(new PersonIdent(committer, new Date(now)));
c.setMessage("");
- return pool.lookupCommit(writer.writeCommit(c));
+ ObjectId id;
+ try {
+ id = inserter.insert(Constants.OBJ_COMMIT, inserter.format(c));
+ inserter.flush();
+ } finally {
+ inserter.release();
+ }
+ return pool.lookupCommit(id);
}
/** @return a new commit builder. */
@@ -382,7 +403,14 @@ public class TestRepository<R extends Repository> {
t.setTag(name);
t.setTagger(new PersonIdent(committer, new Date(now)));
t.setMessage("");
- return (RevTag) pool.lookupAny(writer.writeTag(t), Constants.OBJ_TAG);
+ ObjectId id;
+ try {
+ id = inserter.insert(Constants.OBJ_TAG, inserter.format(t));
+ inserter.flush();
+ } finally {
+ inserter.release();
+ }
+ return (RevTag) pool.lookupAny(id, Constants.OBJ_TAG);
}
/**
@@ -777,13 +805,21 @@ public class TestRepository<R extends Repository> {
TestRepository.this.tick(tick);
final Commit c = new Commit(db);
- c.setTreeId(pool.lookupTree(tree.writeTree(writer)));
c.setParentIds(parents.toArray(new RevCommit[parents.size()]));
c.setAuthor(new PersonIdent(author, new Date(now)));
c.setCommitter(new PersonIdent(committer, new Date(now)));
c.setMessage(message);
- self = pool.lookupCommit(writer.writeCommit(c));
+ ObjectId commitId;
+ try {
+ c.setTreeId(tree.writeTree(inserter));
+ commitId = inserter.insert(Constants.OBJ_COMMIT, inserter
+ .format(c));
+ inserter.flush();
+ } finally {
+ inserter.release();
+ }
+ self = pool.lookupCommit(commitId);
if (branch != null)
branch.update(self);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java
index e2a3564662..e57d0f32f8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReadTreeTest.java
@@ -123,11 +123,15 @@ public class ReadTreeTest extends RepositoryTestCase {
}
ObjectId genSha1(String data) {
- ObjectWriter objectWriter = new ObjectWriter(db);
+ ObjectInserter w = db.newObjectInserter();
try {
- return objectWriter.writeBlob(data.getBytes());
+ ObjectId id = w.insert(Constants.OBJ_BLOB, data.getBytes());
+ w.flush();
+ return id;
} catch (IOException e) {
fail(e.toString());
+ } finally {
+ w.release();
}
return null;
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java
index 42e653be37..1b4a11db50 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/CherryPickTest.java
@@ -44,7 +44,8 @@
package org.eclipse.jgit.merge;
-import java.io.ByteArrayInputStream;
+import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
+import static org.eclipse.jgit.lib.Constants.OBJ_COMMIT;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder;
@@ -53,7 +54,7 @@ import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.ObjectWriter;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.treewalk.TreeWalk;
@@ -93,7 +94,7 @@ public class CherryPickTest extends RepositoryTestCase {
t.finish();
}
- final ObjectWriter ow = new ObjectWriter(db);
+ final ObjectInserter ow = db.newObjectInserter();
final ObjectId B = commit(ow, treeB, new ObjectId[] {});
final ObjectId O = commit(ow, treeO, new ObjectId[] { B });
final ObjectId P = commit(ow, treeP, new ObjectId[] { B });
@@ -128,15 +129,17 @@ public class CherryPickTest extends RepositoryTestCase {
.getObjectId(0));
}
- private ObjectId commit(final ObjectWriter ow, final DirCache treeB,
+ private ObjectId commit(final ObjectInserter odi, final DirCache treeB,
final ObjectId[] parentIds) throws Exception {
final Commit c = new Commit(db);
- c.setTreeId(treeB.writeTree(ow));
+ c.setTreeId(treeB.writeTree(odi));
c.setAuthor(new PersonIdent("A U Thor", "a.u.thor", 1L, 0));
c.setCommitter(c.getAuthor());
c.setParentIds(parentIds);
c.setMessage("Tree " + c.getTreeId().name());
- return ow.writeCommit(c);
+ ObjectId id = odi.insert(OBJ_COMMIT, odi.format(c));
+ odi.flush();
+ return id;
}
private DirCacheEntry makeEntry(final String path, final FileMode mode)
@@ -148,9 +151,8 @@ public class CherryPickTest extends RepositoryTestCase {
final String content) throws Exception {
final DirCacheEntry ent = new DirCacheEntry(path);
ent.setFileMode(mode);
- final byte[] contentBytes = Constants.encode(content);
- ent.setObjectId(new ObjectWriter(db).computeBlobSha1(
- contentBytes.length, new ByteArrayInputStream(contentBytes)));
+ ent.setObjectId(new ObjectInserter.Formatter().idFor(OBJ_BLOB,
+ Constants.encode(content)));
return ent;
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java
index 690b166cbc..a4ef2cd643 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SimpleMergeTest.java
@@ -44,7 +44,9 @@
package org.eclipse.jgit.merge;
-import java.io.ByteArrayInputStream;
+import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
+import static org.eclipse.jgit.lib.Constants.OBJ_COMMIT;
+
import java.io.IOException;
import org.eclipse.jgit.dircache.DirCache;
@@ -54,7 +56,7 @@ import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.ObjectWriter;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
import org.eclipse.jgit.treewalk.TreeWalk;
@@ -126,7 +128,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t.finish();
}
- final ObjectWriter ow = new ObjectWriter(db);
+ final ObjectInserter ow = db.newObjectInserter();
final ObjectId b = commit(ow, treeB, new ObjectId[] {});
final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
final ObjectId t = commit(ow, treeT, new ObjectId[] { b });
@@ -177,7 +179,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t.finish();
}
- final ObjectWriter ow = new ObjectWriter(db);
+ final ObjectInserter ow = db.newObjectInserter();
final ObjectId b = commit(ow, treeB, new ObjectId[] {});
final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
final ObjectId t = commit(ow, treeT, new ObjectId[] { b });
@@ -224,7 +226,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t.finish();
}
- final ObjectWriter ow = new ObjectWriter(db);
+ final ObjectInserter ow = db.newObjectInserter();
final ObjectId b = commit(ow, treeB, new ObjectId[] {});
final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
final ObjectId t = commit(ow, treeT, new ObjectId[] { b });
@@ -256,7 +258,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t.finish();
}
- final ObjectWriter ow = new ObjectWriter(db);
+ final ObjectInserter ow = db.newObjectInserter();
final ObjectId b = commit(ow, treeB, new ObjectId[] {});
final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
final ObjectId t = commit(ow, treeT, new ObjectId[] { b });
@@ -288,7 +290,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t.finish();
}
- final ObjectWriter ow = new ObjectWriter(db);
+ final ObjectInserter ow = db.newObjectInserter();
final ObjectId b = commit(ow, treeB, new ObjectId[] {});
final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
final ObjectId t = commit(ow, treeT, new ObjectId[] { b });
@@ -318,7 +320,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t.finish();
}
- final ObjectWriter ow = new ObjectWriter(db);
+ final ObjectInserter ow = db.newObjectInserter();
final ObjectId b = commit(ow, treeB, new ObjectId[] {});
final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
final ObjectId t = commit(ow, treeT, new ObjectId[] { b });
@@ -348,7 +350,7 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
t.finish();
}
- final ObjectWriter ow = new ObjectWriter(db);
+ final ObjectInserter ow = db.newObjectInserter();
final ObjectId b = commit(ow, treeB, new ObjectId[] {});
final ObjectId o = commit(ow, treeO, new ObjectId[] { b });
final ObjectId t = commit(ow, treeT, new ObjectId[] { b });
@@ -363,15 +365,17 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
.getObjectId(0));
}
- private ObjectId commit(final ObjectWriter ow, final DirCache treeB,
+ private ObjectId commit(final ObjectInserter odi, final DirCache treeB,
final ObjectId[] parentIds) throws Exception {
final Commit c = new Commit(db);
- c.setTreeId(treeB.writeTree(ow));
+ c.setTreeId(treeB.writeTree(odi));
c.setAuthor(new PersonIdent("A U Thor", "a.u.thor", 1L, 0));
c.setCommitter(c.getAuthor());
c.setParentIds(parentIds);
c.setMessage("Tree " + c.getTreeId().name());
- return ow.writeCommit(c);
+ ObjectId id = odi.insert(OBJ_COMMIT, odi.format(c));
+ odi.flush();
+ return id;
}
private DirCacheEntry makeEntry(final String path, final FileMode mode)
@@ -383,9 +387,8 @@ public class SimpleMergeTest extends SampleDataRepositoryTestCase {
final String content) throws Exception {
final DirCacheEntry ent = new DirCacheEntry(path);
ent.setFileMode(mode);
- final byte[] contentBytes = Constants.encode(content);
- ent.setObjectId(new ObjectWriter(db).computeBlobSha1(
- contentBytes.length, new ByteArrayInputStream(contentBytes)));
+ ent.setObjectId(new ObjectInserter.Formatter().idFor(OBJ_BLOB,
+ Constants.encode(content)));
return ent;
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTestCase.java
index 1aaefc415f..ad51ac2ddf 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTestCase.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTestCase.java
@@ -43,6 +43,8 @@
package org.eclipse.jgit.treewalk.filter;
+import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
+
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
@@ -52,16 +54,16 @@ import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.ObjectWriter;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.treewalk.TreeWalk;
public class PathSuffixFilterTestCase extends RepositoryTestCase {
public void testNonRecursiveFiltering() throws IOException {
- final ObjectWriter ow = new ObjectWriter(db);
- final ObjectId aSth = ow.writeBlob("a.sth".getBytes());
- final ObjectId aTxt = ow.writeBlob("a.txt".getBytes());
+ final ObjectInserter odi = db.newObjectInserter();
+ final ObjectId aSth = odi.insert(OBJ_BLOB, "a.sth".getBytes());
+ final ObjectId aTxt = odi.insert(OBJ_BLOB, "a.txt".getBytes());
final DirCache dc = DirCache.read(db);
final DirCacheBuilder builder = dc.builder();
final DirCacheEntry aSthEntry = new DirCacheEntry("a.sth");
@@ -73,7 +75,8 @@ public class PathSuffixFilterTestCase extends RepositoryTestCase {
builder.add(aSthEntry);
builder.add(aTxtEntry);
builder.finish();
- final ObjectId treeId = dc.writeTree(ow);
+ final ObjectId treeId = dc.writeTree(odi);
+ odi.flush();
final TreeWalk tw = new TreeWalk(db);
@@ -92,11 +95,11 @@ public class PathSuffixFilterTestCase extends RepositoryTestCase {
}
public void testRecursiveFiltering() throws IOException {
- final ObjectWriter ow = new ObjectWriter(db);
- final ObjectId aSth = ow.writeBlob("a.sth".getBytes());
- final ObjectId aTxt = ow.writeBlob("a.txt".getBytes());
- final ObjectId bSth = ow.writeBlob("b.sth".getBytes());
- final ObjectId bTxt = ow.writeBlob("b.txt".getBytes());
+ final ObjectInserter odi = db.newObjectInserter();
+ final ObjectId aSth = odi.insert(OBJ_BLOB, "a.sth".getBytes());
+ final ObjectId aTxt = odi.insert(OBJ_BLOB, "a.txt".getBytes());
+ final ObjectId bSth = odi.insert(OBJ_BLOB, "b.sth".getBytes());
+ final ObjectId bTxt = odi.insert(OBJ_BLOB, "b.txt".getBytes());
final DirCache dc = DirCache.read(db);
final DirCacheBuilder builder = dc.builder();
final DirCacheEntry aSthEntry = new DirCacheEntry("a.sth");
@@ -116,7 +119,8 @@ public class PathSuffixFilterTestCase extends RepositoryTestCase {
builder.add(bSthEntry);
builder.add(bTxtEntry);
builder.finish();
- final ObjectId treeId = dc.writeTree(ow);
+ final ObjectId treeId = dc.writeTree(odi);
+ odi.flush();
final TreeWalk tw = new TreeWalk(db);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
index eef952e7cd..f12c94b33e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
@@ -54,13 +54,13 @@ import org.eclipse.jgit.errors.UnmergedPathException;
import org.eclipse.jgit.lib.Commit;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.ObjectWriter;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.RefUpdate;
-import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryState;
+import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
@@ -141,52 +141,59 @@ public class CommitCommand extends GitCommand<RevCommit> {
// lock the index
DirCache index = DirCache.lock(repo);
try {
- ObjectWriter repoWriter = new ObjectWriter(repo);
-
- // Write the index as tree to the object database. This may fail
- // for example when the index contains unmerged pathes
- // (unresolved conflicts)
- ObjectId indexTreeId = index.writeTree(repoWriter);
+ ObjectInserter odi = repo.newObjectInserter();
+ try {
+ // Write the index as tree to the object database. This may
+ // fail for example when the index contains unmerged paths
+ // (unresolved conflicts)
+ ObjectId indexTreeId = index.writeTree(odi);
- // Create a Commit object, populate it and write it
- Commit commit = new Commit(repo);
- commit.setCommitter(committer);
- commit.setAuthor(author);
- commit.setMessage(message);
+ // Create a Commit object, populate it and write it
+ Commit commit = new Commit(repo);
+ commit.setCommitter(committer);
+ commit.setAuthor(author);
+ commit.setMessage(message);
- commit.setParentIds(parents.toArray(new ObjectId[]{}));
- commit.setTreeId(indexTreeId);
- ObjectId commitId = repoWriter.writeCommit(commit);
+ commit.setParentIds(parents.toArray(new ObjectId[] {}));
+ commit.setTreeId(indexTreeId);
+ ObjectId commitId = odi.insert(Constants.OBJ_COMMIT, odi
+ .format(commit));
+ odi.flush();
- RevCommit revCommit = new RevWalk(repo).parseCommit(commitId);
- RefUpdate ru = repo.updateRef(Constants.HEAD);
- ru.setNewObjectId(commitId);
- ru.setRefLogMessage("commit : " + revCommit.getShortMessage(),
- false);
+ RevCommit revCommit = new RevWalk(repo)
+ .parseCommit(commitId);
+ RefUpdate ru = repo.updateRef(Constants.HEAD);
+ ru.setNewObjectId(commitId);
+ ru.setRefLogMessage("commit : "
+ + revCommit.getShortMessage(), false);
- ru.setExpectedOldObjectId(headId);
- Result rc = ru.update();
- switch (rc) {
- case NEW:
- case FAST_FORWARD:
- setCallable(false);
- if (state == RepositoryState.MERGING_RESOLVED) {
- // Commit was successful. Now delete the files
- // used for merge commits
- new File(repo.getDirectory(), Constants.MERGE_HEAD)
- .delete();
- new File(repo.getDirectory(), Constants.MERGE_MSG)
- .delete();
+ ru.setExpectedOldObjectId(headId);
+ Result rc = ru.update();
+ switch (rc) {
+ case NEW:
+ case FAST_FORWARD:
+ setCallable(false);
+ if (state == RepositoryState.MERGING_RESOLVED) {
+ // Commit was successful. Now delete the files
+ // used for merge commits
+ new File(repo.getDirectory(), Constants.MERGE_HEAD)
+ .delete();
+ new File(repo.getDirectory(), Constants.MERGE_MSG)
+ .delete();
+ }
+ return revCommit;
+ case REJECTED:
+ case LOCK_FAILURE:
+ throw new ConcurrentRefUpdateException(
+ JGitText.get().couldNotLockHEAD, ru.getRef(),
+ rc);
+ default:
+ throw new JGitInternalException(MessageFormat.format(
+ JGitText.get().updatingRefFailed,
+ Constants.HEAD, commitId.toString(), rc));
}
- return revCommit;
- case REJECTED:
- case LOCK_FAILURE:
- throw new ConcurrentRefUpdateException(
- JGitText.get().couldNotLockHEAD, ru.getRef(), rc);
- default:
- throw new JGitInternalException(MessageFormat.format(
- JGitText.get().updatingRefFailed
- , Constants.HEAD, commitId.toString(), rc));
+ } finally {
+ odi.release();
}
} finally {
index.unlock();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
index 99d5d2eda4..9ced005a45 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
@@ -66,7 +66,7 @@ import org.eclipse.jgit.errors.UnmergedPathException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.LockFile;
import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.ObjectWriter;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.util.IO;
import org.eclipse.jgit.util.MutableInteger;
@@ -772,7 +772,9 @@ public class DirCache {
* Write all index trees to the object store, returning the root tree.
*
* @param ow
- * the writer to use when serializing to the store.
+ * the writer to use when serializing to the store. The caller is
+ * responsible for flushing the inserter before trying to use the
+ * returned tree identity.
* @return identity for the root tree.
* @throws UnmergedPathException
* one or more paths contain higher-order stages (stage > 0),
@@ -783,7 +785,7 @@ public class DirCache {
* @throws IOException
* an unexpected error occurred writing to the object store.
*/
- public ObjectId writeTree(final ObjectWriter ow)
+ public ObjectId writeTree(final ObjectInserter ow)
throws UnmergedPathException, IOException {
return getCacheTree(true).writeTree(sortedEntries, 0, 0, ow);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java
index 144b1a6cfc..e04b797ab3 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java
@@ -57,7 +57,7 @@ import org.eclipse.jgit.errors.UnmergedPathException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.ObjectWriter;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.util.MutableInteger;
import org.eclipse.jgit.util.RawParseUtils;
@@ -311,7 +311,7 @@ public class DirCacheTree {
* an unexpected error occurred writing to the object store.
*/
ObjectId writeTree(final DirCacheEntry[] cache, int cIdx,
- final int pathOffset, final ObjectWriter ow)
+ final int pathOffset, final ObjectInserter ow)
throws UnmergedPathException, IOException {
if (id == null) {
final int endIdx = cIdx + entrySpan;
@@ -346,13 +346,13 @@ public class DirCacheTree {
entryIdx++;
}
- id = ow.writeCanonicalTree(out.toByteArray());
+ id = ow.insert(Constants.OBJ_TREE, out.toByteArray());
}
return id;
}
private int computeSize(final DirCacheEntry[] cache, int cIdx,
- final int pathOffset, final ObjectWriter ow)
+ final int pathOffset, final ObjectInserter ow)
throws UnmergedPathException, IOException {
final int endIdx = cIdx + entrySpan;
int childIdx = 0;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java
index 66dd89120c..be4818aa57 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java
@@ -339,7 +339,14 @@ public class Commit implements Treeish {
public void commit() throws IOException {
if (getCommitId() != null)
throw new IllegalStateException(MessageFormat.format(JGitText.get().commitAlreadyExists, getCommitId()));
- setCommitId(new ObjectWriter(objdb).writeCommit(this));
+ ObjectInserter odi = objdb.getObjectDatabase().newInserter();
+ try {
+ ObjectId id = odi.insert(Constants.OBJ_COMMIT, odi.format(this));
+ odi.flush();
+ setCommitId(id);
+ } finally {
+ odi.release();
+ }
}
public String toString() {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Tag.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Tag.java
index 5b3531eb1f..25a06c9c6c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Tag.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Tag.java
@@ -203,9 +203,14 @@ public class Tag {
final RefUpdate ru;
if (tagger!=null || message!=null || type!=null) {
- ObjectId tagid = new ObjectWriter(objdb).writeTag(this);
- setTagId(tagid);
- id = tagid;
+ ObjectInserter odi = objdb.newObjectInserter();
+ try {
+ id = odi.insert(Constants.OBJ_TAG, odi.format(this));
+ odi.flush();
+ setTagId(id);
+ } finally {
+ odi.release();
+ }
} else {
id = objId;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java
index 38af20fb8f..59b826438e 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/Merger.java
@@ -51,7 +51,7 @@ import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.ObjectWriter;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.WindowCursor;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -73,7 +73,7 @@ public abstract class Merger {
/** A RevWalk for computing merge bases, or listing incoming commits. */
protected final RevWalk walk;
- private ObjectWriter writer;
+ private ObjectInserter inserter;
/** The original objects supplied in the merge; this can be any tree-ish. */
protected RevObject[] sourceObjects;
@@ -105,10 +105,10 @@ public abstract class Merger {
/**
* @return an object writer to create objects in {@link #getRepository()}.
*/
- public ObjectWriter getObjectWriter() {
- if (writer == null)
- writer = new ObjectWriter(getRepository());
- return writer;
+ public ObjectInserter getObjectInserter() {
+ if (inserter == null)
+ inserter = getRepository().newObjectInserter();
+ return inserter;
}
/**
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java
index 6cd244599e..aa2321b4ae 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/StrategySimpleTwoWayInCore.java
@@ -51,6 +51,7 @@ import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.errors.UnmergedPathException;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.eclipse.jgit.treewalk.NameConflictTreeWalk;
@@ -152,7 +153,16 @@ public class StrategySimpleTwoWayInCore extends ThreeWayMergeStrategy {
if (hasConflict)
return false;
try {
- resultTree = cache.writeTree(getObjectWriter());
+ ObjectInserter odi = getObjectInserter();
+ try {
+ resultTree = cache.writeTree(odi);
+ odi.flush();
+ } finally {
+ // We don't know if our caller will release the
+ // inserter, so make sure we do it ourselves.
+ //
+ odi.release();
+ }
return true;
} catch (UnmergedPathException upe) {
resultTree = null;