{"thread":{"id":"21149","subject":"[JGIT PATCH v2] The default encoding for reading commits is UTF-8 rather than system default","startedAt":"2009-10-07T16:26:40Z","lastAt":"2009-10-07T16:26:40Z","messageCount":1,"participants":["Constantine Plotnikov"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"124336","messageId":"1254932800-3788-1-git-send-email-constantine.plotnikov@gmail.com","threadId":"21149","inReplyTo":null,"subject":"[JGIT PATCH v2] The default encoding for reading commits is UTF-8 rather than system default","fromName":"Constantine Plotnikov","fromEmail":"constantine.plotnikov@gmail.com","sentAt":"2009-10-07T16:26:40Z","receivedAt":"2009-10-07T16:26:40Z","isPatch":true,"sender":{"key":"constantine.plotnikov@gmail.com","avatar":null},"body":"When reading commits the system default encoding was used if no encoding\nwas specified in the commit. The patch modifies test to add a check that\ncommit message was encoded correctly (the test fails on old implementation\nif system encoding is not UTF-8) and fixes Commit.decode() method to use\nUTF-8 is encoding is not specified in the commit object.\n\nSigned-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>\n---\n\nThis version is over eclipse.org packages.\n\nSee man git-commit (the section \"DISCUSSION\"), for justification why\nUTF-8 should be used. Note that this was already correctly implemented\nin ObjectWriter.writeCommit(...) method. But Commit.decode() was not\nimplemented in the same way for some reason.\n \n .../tst/org/eclipse/jgit/lib/T0003_Basic.java      |    3 +++\n .../src/org/eclipse/jgit/lib/Commit.java           |   18 +++++++-----------\n 2 files changed, 10 insertions(+), 11 deletions(-)\n\ndiff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java\nindex 98fb794..f3bc9b1 100644\n--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java\n+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java\n@@ -348,6 +348,9 @@ public void test023_createCommitNonAnullii() throws IOException {\n \t\tcommit.setMessage(\"\\u00dcbergeeks\");\n \t\tObjectId cid = new ObjectWriter(db).writeCommit(commit);\n \t\tassertEquals(\"4680908112778718f37e686cbebcc912730b3154\", cid.name());\n+\t\tCommit loadedCommit = db.mapCommit(cid);\n+\t\tassertNotSame(loadedCommit, commit);\n+\t\tassertEquals(commit.getMessage(), loadedCommit.getMessage());\n \t}\n \n \tpublic void test024_createCommitNonAscii() throws IOException {\ndiff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java\nindex b2cf9b1..430cddc 100644\n--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java\n+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Commit.java\n@@ -299,17 +299,13 @@ private void decode() {\n \t\t\t\tbr.read(readBuf);\n \t\t\t\tint msgstart = readBuf.length != 0 ? ( readBuf[0] == '\\n' ? 1 : 0 ) : 0;\n \n-\t\t\t\tif (encoding != null) {\n-\t\t\t\t\t// TODO: this isn't reliable so we need to guess the encoding from the actual content\n-\t\t\t\t\tauthor = new PersonIdent(new String(rawAuthor.getBytes(),encoding.name()));\n-\t\t\t\t\tcommitter = new PersonIdent(new String(rawCommitter.getBytes(),encoding.name()));\n-\t\t\t\t\tmessage = new String(readBuf,msgstart, readBuf.length-msgstart, encoding.name());\n-\t\t\t\t} else {\n-\t\t\t\t\t// TODO: use config setting / platform / ascii / iso-latin\n-\t\t\t\t\tauthor = new PersonIdent(new String(rawAuthor.getBytes()));\n-\t\t\t\t\tcommitter = new PersonIdent(new String(rawCommitter.getBytes()));\n-\t\t\t\t\tmessage = new String(readBuf, msgstart, readBuf.length-msgstart);\n-\t\t\t\t}\n+\t\t\t\t// If encoding is not specified, the default for commit is UTF-8\n+\t\t\t\tif (encoding == null) encoding = Constants.CHARSET;\n+\n+\t\t\t\t// TODO: this isn't reliable so we need to guess the encoding from the actual content\n+\t\t\t\tauthor = new PersonIdent(new String(rawAuthor.getBytes(),encoding.name()));\n+\t\t\t\tcommitter = new PersonIdent(new String(rawCommitter.getBytes(),encoding.name()));\n+\t\t\t\tmessage = new String(readBuf,msgstart, readBuf.length-msgstart, encoding.name());\n \t\t\t} catch (IOException e) {\n \t\t\t\te.printStackTrace();\n \t\t\t} finally {\n-- \n1.6.1.2\n"}]}