]> source.dussan.org Git - jgit.git/commitdiff
Simplify LockFile write(ObjectId) case 82/1882/1
authorShawn O. Pearce <spearce@spearce.org>
Wed, 10 Nov 2010 03:12:24 +0000 (19:12 -0800)
committerShawn O. Pearce <spearce@spearce.org>
Wed, 10 Nov 2010 03:13:13 +0000 (19:13 -0800)
The ObjectId (for a ref) can be easily reformatted into a temporary
byte[] and then passed off to write(byte[]), removing the duplicated
code that existed in both write methods.

Change-Id: I09740658e070d5f22682333a2e0d325fd1c4a6cb
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java

index e8bc3e2cfdd2e94391e7a1e13f690cb09bf2f551..1a4952ad0f1520dd1ede37ec2d6561e2bd0c7be4 100644 (file)
@@ -44,7 +44,6 @@
 
 package org.eclipse.jgit.storage.file;
 
-import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -229,26 +228,10 @@ public class LockFile {
         *             before throwing the underlying exception to the caller.
         */
        public void write(final ObjectId id) throws IOException {
-               requireLock();
-               try {
-                       final BufferedOutputStream b;
-                       b = new BufferedOutputStream(os, Constants.OBJECT_ID_STRING_LENGTH + 1);
-                       id.copyTo(b);
-                       b.write('\n');
-                       b.flush();
-                       fLck.release();
-                       b.close();
-                       os = null;
-               } catch (IOException ioe) {
-                       unlock();
-                       throw ioe;
-               } catch (RuntimeException ioe) {
-                       unlock();
-                       throw ioe;
-               } catch (Error ioe) {
-                       unlock();
-                       throw ioe;
-               }
+               byte[] buf = new byte[Constants.OBJECT_ID_STRING_LENGTH + 1];
+               id.copyTo(buf, 0);
+               buf[Constants.OBJECT_ID_STRING_LENGTH] = '\n';
+               write(buf);
        }
 
        /**