Browse Source

Simplify LockFile write(ObjectId) case

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>
stable-0.10
Shawn O. Pearce 14 years ago
parent
commit
cfa3f365d6
  1. 25
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java

25
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/LockFile.java

@ -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);
}
/**

Loading…
Cancel
Save