From: Shawn O. Pearce <spearce@xxxxxxxxxxx> This permits micro-update steps (or otherwise uninteresting states) to be skipped in the reflog. Signed-off-by: Robin Rosenberg <robin.rosenberg@xxxxxxxxxx> Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx> --- .../tst/org/spearce/jgit/lib/RefUpdateTest.java | 1 + .../src/org/spearce/jgit/lib/RefUpdate.java | 56 +++++++++++++++---- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefUpdateTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefUpdateTest.java index 6b1975a..84653c8 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefUpdateTest.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/RefUpdateTest.java @@ -126,6 +126,7 @@ public void testDeleteLooseAndItsDirectory() throws IOException { RefUpdate updateRef = db.updateRef("refs/heads/z/c"); updateRef.setNewObjectId(pid); updateRef.setForceUpdate(true); + updateRef.setRefLogMessage("new test ref", false); Result update = updateRef.update(); assertEquals(Result.NEW, update); // internal assertTrue(new File(db.getDirectory(), Constants.R_HEADS + "z") diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java index a9ab73b..8044c6e 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java @@ -165,6 +165,7 @@ RefUpdate(final RefDatabase r, final Ref ref, final File f) { this.ref = ref; oldValue = ref.getObjectId(); looseFile = f; + refLogMessage = ""; } /** @return the repository the updated ref resides in */ @@ -264,7 +265,8 @@ public void setRefLogIdent(final PersonIdent pi) { /** * Get the message to include in the reflog. * - * @return message the caller wants to include in the reflog. + * @return message the caller wants to include in the reflog; null if the + * update should not be logged. */ public String getRefLogMessage() { return refLogMessage; @@ -274,15 +276,29 @@ public String getRefLogMessage() { * Set the message to include in the reflog. * * @param msg - * the message to describe this change. + * the message to describe this change. It may be null + * if appendStatus is null in order not to append to the reflog * @param appendStatus * true if the status of the ref change (fast-forward or * forced-update) should be appended to the user supplied * message. */ public void setRefLogMessage(final String msg, final boolean appendStatus) { - refLogMessage = msg; - refLogIncludeResult = appendStatus; + if (msg == null && !appendStatus) + disableRefLog(); + else if (msg == null && appendStatus) { + refLogMessage = ""; + refLogIncludeResult = true; + } else { + refLogMessage = msg; + refLogIncludeResult = appendStatus; + } + } + + /** Don't record this update in the ref's associated reflog. */ + public void disableRefLog() { + refLogMessage = null; + refLogIncludeResult = false; } /** @@ -471,21 +487,37 @@ private Result updateStore(final LockFile lock, final Result status) lock.setNeedStatInformation(true); lock.write(newValue); String msg = getRefLogMessage(); - if (msg != null && refLogIncludeResult) { - if (status == Result.FORCED) - msg += ": forced-update"; - else if (status == Result.FAST_FORWARD) - msg += ": fast forward"; - else if (status == Result.NEW) - msg += ": created"; + if (msg != null) { + if (refLogIncludeResult) { + String strResult = toResultString(status); + if (strResult != null) { + if (msg.length() > 0) + msg = msg + ": " + strResult; + else + msg = strResult; + } + } + RefLogWriter.append(this, msg); } - RefLogWriter.append(this, msg); if (!lock.commit()) return Result.LOCK_FAILURE; db.stored(this.ref.getOrigName(), ref.getName(), newValue, lock.getCommitLastModified()); return status; } + private static String toResultString(final Result status) { + switch (status) { + case FORCED: + return "forced-update"; + case FAST_FORWARD: + return "fast forward"; + case NEW: + return "created"; + default: + return null; + } + } + /** * Handle the abstraction of storing a ref update. This is because both * updating and deleting of a ref have merge testing in common. -- 1.6.3.2.199.g7340d -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html