git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [EGIT PATCH] Use the possible resources's specific encoding for quickdiff
@ 2008-12-20 23:14 Robin Rosenberg
  0 siblings, 0 replies; only message in thread
From: Robin Rosenberg @ 2008-12-20 23:14 UTC (permalink / raw)
  To: spearce; +Cc: git, Robin Rosenberg

Encoding can be defined in many places. It could be defined for a specific
resource, workspace, JVM invocation or platform. Let Eclipse handle the
logic. We always ask for the current revisions encoding, which in theory
could be different from the encoding specified for the version we are
retrieving.

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 .../egit/ui/internal/decorators/GitDocument.java   |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --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
index a985a68..a9c0c7d 100644
--- 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
@@ -9,8 +9,10 @@
 
 import java.io.IOException;
 
+import org.eclipse.core.resources.IEncodedStorage;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.text.Document;
 import org.eclipse.team.core.RepositoryProvider;
 import org.spearce.egit.core.GitProvider;
@@ -66,7 +68,23 @@ void populate() throws IOException {
 			Activator.trace("(GitQuickDiffProvider) compareTo: " + baseline);
 			ObjectLoader loader = repository.openBlob(blobEnry.getId());
 			byte[] bytes = loader.getBytes();
-			String s = new String(bytes); // FIXME Platform default charset. should be Eclipse default
+			String charset;
+			// Get the encoding for the current version. As a matter of
+			// principle one might want to use the eclipse settings for the
+			// version we are retrieving as that may be defined by the
+			// project settings, but there is no historic API for this.
+			IEncodedStorage encodedStorage = ((IEncodedStorage)resource);
+			try {
+				if (encodedStorage != null)
+					charset = encodedStorage.getCharset();
+				else
+					charset = resource.getParent().getDefaultCharset();
+			} catch (CoreException e) {
+				charset = Constants.CHARACTER_ENCODING;
+			}
+			// Finally we could consider validating the content with respect
+			// to the content. We don't do that here.
+			String s = new String(bytes, charset);
 			set(s);
 			Activator.trace("(GitQuickDiffProvider) has reference doc, size=" + s.length() + " bytes");
 		} else {
-- 
1.6.1.rc3.56.gd0306

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2008-12-20 23:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-20 23:14 [EGIT PATCH] Use the possible resources's specific encoding for quickdiff Robin Rosenberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).