Permalink
Browse files

Issue 20; Refactor ref updating to separate method in CommitBuilder

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
  • Loading branch information...
1 parent 71c1cc4 commit adbe824b3e5b6314363bff01624bcd355de5d3d0 @jonas jonas committed Sep 11, 2009
Showing with 12 additions and 12 deletions.
  1. +12 −12 src/org/nbgit/client/CommitBuilder.java
@@ -148,6 +148,15 @@ public void write() throws IOException {
doCommit(index.writeTree());
}
+ private boolean updateRef(RefUpdate ru, ObjectId id) throws IOException {
+ ru.setNewObjectId(id);
+ ru.setRefLogMessage(buildReflogMessage(), false);
+ ru.update();
+ return ru.getOldObjectId() != null
+ ? ru.getResult() == RefUpdate.Result.FAST_FORWARD
+ : ru.getResult() == RefUpdate.Result.NEW;
+ }
+
private String buildReflogMessage() {
String firstLine = message;
int newlineIndex = message.indexOf("\n");
@@ -175,19 +184,10 @@ private void doCommit(ObjectId treeId) throws IOException {
commit.setCommitter(personIdent);
ObjectWriter writer = new ObjectWriter(repository);
- commit.setCommitId(writer.writeCommit(commit));
+ ObjectId id = writer.writeCommit(commit);
- ru.setNewObjectId(commit.getCommitId());
- ru.setRefLogMessage(buildReflogMessage(), false);
- ru.update();
- boolean ok;
- if (ru.getOldObjectId() != null) {
- ok = ru.getResult() == RefUpdate.Result.FAST_FORWARD;
- } else {
- ok = ru.getResult() == RefUpdate.Result.NEW;
- }
- if (!ok) {
- logger.output("Failed to update " + ru.getName() + " to commit " + commit.getCommitId() + ".");
+ if (!updateRef(ru, id)) {
+ logger.output("Failed to update " + ru.getName() + " to commit " + id + ".");
}
}

0 comments on commit adbe824

Please sign in to comment.