[gedit-plugins/gnome-3-14] real paths and gui.encoding are now used



commit 2e57d16670b2928ab7f89c5cd71d76c51750acbe
Author: Jacek Pliszka <Jacek Pliszka hp com>
Date:   Sat Nov 21 20:24:51 2015 +0100

    real paths and gui.encoding are now used
    
    Now paths are normalized and replaced by real paths so symlinks are
    resolved and should work now. Also gui.encoding is now taken into
    account so set it in .git/config if you work with non-UTF8 files.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=706455

 plugins/git/git/viewactivatable.py |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/plugins/git/git/viewactivatable.py b/plugins/git/git/viewactivatable.py
index e32a163..6ad26f7 100644
--- a/plugins/git/git/viewactivatable.py
+++ b/plugins/git/git/viewactivatable.py
@@ -23,6 +23,8 @@ from .appactivatable import GitAppActivatable
 from .diffrenderer import DiffType, DiffRenderer
 from .windowactivatable import GitWindowActivatable
 
+import sys
+import os.path
 import difflib
 
 
@@ -132,19 +134,29 @@ class GitViewActivatable(GObject.Object, Gedit.ViewActivatable):
             commit = repo.lookup(head.get_target(), Ggit.Commit.__gtype__)
             tree = commit.get_tree()
 
-            relative_path = repo.get_workdir().get_relative_path(self.location)
+            relative_path = os.path.relpath(
+                os.path.normpath(os.path.realpath(self.location.get_path())),
+                repo.get_workdir().get_path()
+            )
 
             entry = tree.get_by_path(relative_path)
             file_blob = repo.lookup(entry.get_id(), Ggit.Blob.__gtype__)
-            file_contents = file_blob.get_raw_content().decode('utf-8')
+            try:
+                gitconfig = repo.get_config()
+                encoding = gitconfig.get_string('gui.encoding')
+            except GLib.Error:
+                encoding = 'utf8'
+            file_contents = file_blob.get_raw_content().decode(encoding)
             self.file_contents_list = file_contents.splitlines()
 
             # Remove the last empty line added by gedit automatically
-            last_item = self.file_contents_list[-1]
-            if last_item[-1:] == '\n':
-                self.file_contents_list[-1] = last_item[:-1]
+            if self.file_contents_list:
+                last_item = self.file_contents_list[-1]
+                if last_item[-1:] == '\n':
+                    self.file_contents_list[-1] = last_item[:-1]
 
         except GLib.Error:
+            print("GLib.Error", sys.exc_info()[0])
             # New file in a git repository
             self.file_contents_list = []
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]