From 962e648e6353609d7c40ef2282d3e6a6e6f005a9 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 10 Jun 2009 23:22:21 +0200 Subject: [PATCH] Do not write to the reflog unless the refupdate logmessage is set This permits micro-update steps (or otherwise uninteresting states) to be skipped in the reflog. Signed-off-by: Robin Rosenberg Signed-off-by: Shawn O. Pearce --- .../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 b14f19af..a7ac3cb0 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 class RefUpdateTest extends RepositoryTestCase { 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 a9ab73be..8044c6ea 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 @@ public class RefUpdate { this.ref = ref; oldValue = ref.getObjectId(); looseFile = f; + refLogMessage = ""; } /** @return the repository the updated ref resides in */ @@ -264,7 +265,8 @@ public class RefUpdate { /** * 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 class RefUpdate { * 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 @@ public class RefUpdate { 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. -- 2.11.4.GIT