Make the default encoding when reading commits UTF-8
When reading commits the system default encoding was used if no encoding was specified in the commit. The patch modifies the test to add a check that commit message was encoded correctly (the test fails on old implementation if system encoding is not UTF-8) and fixes Commit.decode() method to use UTF-8 if encoding is not specified in the commit object. Change-Id: I27101da3c2eb6edd0c4a9e4c0523e48b286e3cd5 Signed-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
aa08a022f1
commit
982515cf10
|
@ -344,6 +344,9 @@ public void test023_createCommitNonAnullii() throws IOException {
|
||||||
commit.setMessage("\u00dcbergeeks");
|
commit.setMessage("\u00dcbergeeks");
|
||||||
ObjectId cid = new ObjectWriter(db).writeCommit(commit);
|
ObjectId cid = new ObjectWriter(db).writeCommit(commit);
|
||||||
assertEquals("4680908112778718f37e686cbebcc912730b3154", cid.name());
|
assertEquals("4680908112778718f37e686cbebcc912730b3154", cid.name());
|
||||||
|
Commit loadedCommit = db.mapCommit(cid);
|
||||||
|
assertNotSame(loadedCommit, commit);
|
||||||
|
assertEquals(commit.getMessage(), loadedCommit.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test024_createCommitNonAscii() throws IOException {
|
public void test024_createCommitNonAscii() throws IOException {
|
||||||
|
|
|
@ -305,17 +305,13 @@ private void decode() {
|
||||||
br.read(readBuf);
|
br.read(readBuf);
|
||||||
int msgstart = readBuf.length != 0 ? ( readBuf[0] == '\n' ? 1 : 0 ) : 0;
|
int msgstart = readBuf.length != 0 ? ( readBuf[0] == '\n' ? 1 : 0 ) : 0;
|
||||||
|
|
||||||
if (encoding != null) {
|
// If encoding is not specified, the default for commit is UTF-8
|
||||||
// TODO: this isn't reliable so we need to guess the encoding from the actual content
|
if (encoding == null) encoding = Constants.CHARSET;
|
||||||
author = new PersonIdent(new String(rawAuthor.getBytes(),encoding.name()));
|
|
||||||
committer = new PersonIdent(new String(rawCommitter.getBytes(),encoding.name()));
|
// TODO: this isn't reliable so we need to guess the encoding from the actual content
|
||||||
message = new String(readBuf,msgstart, readBuf.length-msgstart, encoding.name());
|
author = new PersonIdent(new String(rawAuthor.getBytes(),encoding.name()));
|
||||||
} else {
|
committer = new PersonIdent(new String(rawCommitter.getBytes(),encoding.name()));
|
||||||
// TODO: use config setting / platform / ascii / iso-latin
|
message = new String(readBuf,msgstart, readBuf.length-msgstart, encoding.name());
|
||||||
author = new PersonIdent(new String(rawAuthor.getBytes()));
|
|
||||||
committer = new PersonIdent(new String(rawCommitter.getBytes()));
|
|
||||||
message = new String(readBuf, msgstart, readBuf.length-msgstart);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in New Issue