[PATCH 4/7] Extract lockAndWriteFile method in RefDatabase for reuse

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Charles O'Farrell <charleso@xxxxxxxxxxxx>
---
 .../src/org/spearce/jgit/lib/RefDatabase.java      |   25 ++++++++++++--------
 1 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
index 3e68a8d..3d8280d 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefDatabase.java
@@ -158,16 +158,7 @@ class RefDatabase {
 	 */
 	void link(final String name, final String target) throws IOException {
 		final byte[] content = ("ref: " + target + "\n").getBytes(CHAR_ENC);
-		final LockFile lck = new LockFile(fileForRef(name));
-		if (!lck.lock())
-			throw new ObjectWritingException("Unable to lock " + name);
-		try {
-			lck.write(content);
-		} catch (IOException ioe) {
-			throw new ObjectWritingException("Unable to write " + name, ioe);
-		}
-		if (!lck.commit())
-			throw new ObjectWritingException("Unable to write " + name);
+		lockAndWriteFile(fileForRef(name), content);
 		setModified();
 		db.fireRefsMaybeChanged();
 	}
@@ -427,6 +418,20 @@ class RefDatabase {
 		}
 	}
 
+	private void lockAndWriteFile(File file, byte[] content) throws IOException {
+		String name = file.getName();
+		final LockFile lck = new LockFile(file);
+		if (!lck.lock())
+			throw new ObjectWritingException("Unable to lock " + name);
+		try {
+			lck.write(content);
+		} catch (IOException ioe) {
+			throw new ObjectWritingException("Unable to write " + name, ioe);
+		}
+		if (!lck.commit())
+			throw new ObjectWritingException("Unable to write " + name);
+	}
+
 	private static String readLine(final File file)
 			throws FileNotFoundException, IOException {
 		final BufferedReader br = openReader(file);
-- 
1.6.0.rc2.35.g04c6e

--
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

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux