git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/7] Refactor of RefUpdate force to call common updateImpl instead of duplication

From
Charles O'Farrell <charleso@charleso.org>
Date
Aug 14, 2008, 10:13 UTC
Message-ID
<1218708829-8175-3-git-send-email-charleso@charleso.org>
In-Reply-To
<1218708829-8175-2-git-send-email-charleso@charleso.org>
Signed-off-by: Charles O'Farrell <charleso@charleso.org>
---
 .../src/org/spearce/jgit/lib/RefUpdate.java        |   38 ++++---------------
 1 files changed, 8 insertions(+), 30 deletions(-)
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 369cb37..1b38fce 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java
@@ -266,31 +266,8 @@ public class RefUpdate {
 	 *             an unexpected IO error occurred while writing changes.
 	 */
 	public Result forceUpdate() throws IOException {
-		requireCanDoUpdate();
-		try {
-			return result = forceUpdateImpl();
-		} catch (IOException x) {
-			result = Result.IO_FAILURE;
-			throw x;
-		}
-	}
-
-	private Result forceUpdateImpl() throws IOException {
-		final LockFile lock;
-
-		lock = new LockFile(looseFile);
-		if (!lock.lock())
-			return Result.LOCK_FAILURE;
-		try {
-			oldValue = db.idOf(name);
-			if (oldValue == null)
-				return store(lock, Result.NEW);
-			if (oldValue.equals(newValue))
-				return Result.NO_CHANGE;
-			return store(lock, Result.FORCED);
-		} finally {
-			lock.unlock();
-		}
+		force = true;
+		return update();
 	}
 
 	/**
@@ -347,6 +324,12 @@ public class RefUpdate {
 			if (oldValue == null)
 				return store(lock, Result.NEW);
 
+			if (isForceUpdate()) {
+				if (oldValue.equals(newValue))
+					return Result.NO_CHANGE;
+				return store(lock, Result.FORCED);
+			}
+
 			newObj = walk.parseAny(newValue);
 			oldObj = walk.parseAny(oldValue);
 			if (newObj == oldObj)
@@ -355,13 +338,8 @@ public class RefUpdate {
 			if (newObj instanceof RevCommit && oldObj instanceof RevCommit) {
 				if (walk.isMergedInto((RevCommit) oldObj, (RevCommit) newObj))
 					return store(lock, Result.FAST_FORWARD);
-				if (isForceUpdate())
-					return store(lock, Result.FORCED);
-				return Result.REJECTED;
 			}
 
-			if (isForceUpdate())
-				return store(lock, Result.FORCED);
 			return Result.REJECTED;
 		} finally {
 			lock.unlock();
-- 
1.6.0.rc2.35.g04c6e
Previous: Charles O'FarrellNext: Charles O'Farrell
Message 3 of 11 in “jgit: Branch command now supports deletion”
  1. 0/7 jgit: Branch command now supports deletionCharles O'Farrell, Aug 14, 2008
  2. 1/7 Refactor of WalkRemoteObjectDatabase ref writing into common classCharles O'Farrell, Aug 14, 2008
  3. 2/7 Refactor of RefUpdate force to call common updateImpl instead of duplicationCharles O'Farrell, Aug 14, 2008
  4. 3/7 Minor refactor of constants, including log and ROOT_DIRCharles O'Farrell, Aug 14, 2008
  5. 4/7 Extract lockAndWriteFile method in RefDatabase for reuseCharles O'Farrell, Aug 14, 2008
  6. 5/7 Added removePackedRef method to RefDatabase for packed branch deletionCharles O'Farrell, Aug 14, 2008
  7. 6/7 Added ref deletion to RefUpdateCharles O'Farrell, Aug 14, 2008
  8. 7/7 jgit: Added branch deletion to jgit commandCharles O'Farrell, Aug 14, 2008
  9. Shawn O. PearceAug 14, 2008
  10. 2/7 Refactor of RefUpdate force to call common updateImpl instead of duplicationCharles O'Farrell, Aug 15, 2008
  11. 6/7 Added ref deletion to RefUpdateCharles O'Farrell, Aug 15, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.