{"thread":{"id":"16812","subject":"[EGIT PATCH] Use the possible resources's specific encoding for quickdiff","startedAt":"2008-12-20T23:14:28Z","lastAt":"2008-12-20T23:14:28Z","messageCount":1,"participants":["Robin Rosenberg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"98462","messageId":"1229814868-13916-1-git-send-email-robin.rosenberg@dewire.com","threadId":"16812","inReplyTo":null,"subject":"[EGIT PATCH] Use the possible resources's specific encoding for quickdiff","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2008-12-20T23:14:28Z","receivedAt":"2008-12-20T23:14:28Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"Encoding can be defined in many places. It could be defined for a specific\nresource, workspace, JVM invocation or platform. Let Eclipse handle the\nlogic. We always ask for the current revisions encoding, which in theory\ncould be different from the encoding specified for the version we are\nretrieving.\n\nSigned-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n .../egit/ui/internal/decorators/GitDocument.java   |   20 +++++++++++++++++++-\n 1 files changed, 19 insertions(+), 1 deletions(-)\n\ndiff --git a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitDocument.java b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitDocument.java\nindex a985a68..a9c0c7d 100644\n--- a/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitDocument.java\n+++ b/org.spearce.egit.ui/src/org/spearce/egit/ui/internal/decorators/GitDocument.java\n@@ -9,8 +9,10 @@\n \n import java.io.IOException;\n \n+import org.eclipse.core.resources.IEncodedStorage;\n import org.eclipse.core.resources.IProject;\n import org.eclipse.core.resources.IResource;\n+import org.eclipse.core.runtime.CoreException;\n import org.eclipse.jface.text.Document;\n import org.eclipse.team.core.RepositoryProvider;\n import org.spearce.egit.core.GitProvider;\n@@ -66,7 +68,23 @@ void populate() throws IOException {\n \t\t\tActivator.trace(\"(GitQuickDiffProvider) compareTo: \" + baseline);\n \t\t\tObjectLoader loader = repository.openBlob(blobEnry.getId());\n \t\t\tbyte[] bytes = loader.getBytes();\n-\t\t\tString s = new String(bytes); // FIXME Platform default charset. should be Eclipse default\n+\t\t\tString charset;\n+\t\t\t// Get the encoding for the current version. As a matter of\n+\t\t\t// principle one might want to use the eclipse settings for the\n+\t\t\t// version we are retrieving as that may be defined by the\n+\t\t\t// project settings, but there is no historic API for this.\n+\t\t\tIEncodedStorage encodedStorage = ((IEncodedStorage)resource);\n+\t\t\ttry {\n+\t\t\t\tif (encodedStorage != null)\n+\t\t\t\t\tcharset = encodedStorage.getCharset();\n+\t\t\t\telse\n+\t\t\t\t\tcharset = resource.getParent().getDefaultCharset();\n+\t\t\t} catch (CoreException e) {\n+\t\t\t\tcharset = Constants.CHARACTER_ENCODING;\n+\t\t\t}\n+\t\t\t// Finally we could consider validating the content with respect\n+\t\t\t// to the content. We don't do that here.\n+\t\t\tString s = new String(bytes, charset);\n \t\t\tset(s);\n \t\t\tActivator.trace(\"(GitQuickDiffProvider) has reference doc, size=\" + s.length() + \" bytes\");\n \t\t} else {\n-- \n1.6.1.rc3.56.gd0306\n"}]}