aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/api
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 /org.eclipse.jgit/src/org/eclipse/jgit/api
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>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/api')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java93
1 files changed, 50 insertions, 43 deletions
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();