Permalink
Browse files

Issue 20: Refactor doCommit into CommitBuilder.write

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
  • Loading branch information...
1 parent b2ec7c7 commit c49e43036f79fe52092699336f4f6a2d7a209b64 @jonas jonas committed Sep 11, 2009
Showing with 10 additions and 16 deletions.
  1. +10 −16 src/org/nbgit/client/CommitBuilder.java
@@ -145,7 +145,16 @@ public CommitBuilder time(long time, int timeZone) {
*/
public void write() throws IOException {
index.write();
- doCommit(index.writeTree());
+ final RefUpdate ru = repository.updateRef(Constants.HEAD);
+ ObjectId[] parentIds;
+ if (ru.getOldObjectId() != null)
+ parentIds = new ObjectId[]{ru.getOldObjectId()};
+ else
+ parentIds = new ObjectId[0];
+
+ ObjectId id = writeCommit(index.writeTree(), parentIds);
+ if (!updateRef(ru, id))
+ logger.output("Failed to update " + ru.getName() + " to commit " + id + ".");
}
private ObjectId writeCommit(ObjectId treeId, ObjectId[] parentIds) throws IOException {
@@ -179,19 +188,4 @@ private String buildReflogMessage() {
return "\tcommit: " + firstLine;
}
- private void doCommit(ObjectId treeId) throws IOException {
- final RefUpdate ru = repository.updateRef(Constants.HEAD);
- ObjectId[] parentIds;
- if (ru.getOldObjectId() != null) {
- parentIds = new ObjectId[]{ru.getOldObjectId()};
- } else {
- parentIds = new ObjectId[0];
- }
- ObjectId id = writeCommit(treeId, parentIds);
-
- if (!updateRef(ru, id)) {
- logger.output("Failed to update " + ru.getName() + " to commit " + id + ".");
- }
- }
-
}

0 comments on commit c49e430

Please sign in to comment.