diff options
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java index a9522452b6..349b8197db 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectInserter.java @@ -53,6 +53,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; import java.security.MessageDigest; import java.text.MessageFormat; @@ -304,10 +305,7 @@ public abstract class ObjectInserter { */ public final byte[] format(Commit commit) throws UnsupportedEncodingException { - String encoding = commit.getEncoding(); - if (encoding == null) - encoding = Constants.CHARACTER_ENCODING; - + Charset encoding = commit.getEncoding(); ByteArrayOutputStream os = new ByteArrayOutputStream(); OutputStreamWriter w = new OutputStreamWriter(os, encoding); try { @@ -316,11 +314,10 @@ public abstract class ObjectInserter { commit.getTreeId().copyTo(os); os.write('\n'); - ObjectId[] ps = commit.getParentIds(); - for (int i = 0; i < ps.length; ++i) { + for (ObjectId p : commit.getParentIds()) { os.write(hparent); os.write(' '); - ps[i].copyTo(os); + p.copyTo(os); os.write('\n'); } @@ -336,16 +333,19 @@ public abstract class ObjectInserter { w.flush(); os.write('\n'); - if (!encoding.equals(Constants.CHARACTER_ENCODING)) { + if (encoding != Constants.CHARSET) { os.write(hencoding); os.write(' '); - os.write(Constants.encodeASCII(encoding)); + os.write(Constants.encodeASCII(encoding.name())); os.write('\n'); } os.write('\n'); - w.write(commit.getMessage()); - w.flush(); + + if (commit.getMessage() != null) { + w.write(commit.getMessage()); + w.flush(); + } } catch (IOException err) { // This should never occur, the only way to get it above is // for the ByteArrayOutputStream to throw, but it doesn't. |