[gedit-plugins] Two small bugfixes: real paths and gui.encoding are now used Now paths are normalized and replaced b



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

    Two small bugfixes: 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 |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/plugins/git/git/viewactivatable.py b/plugins/git/git/viewactivatable.py
index 9595976..ab54db3 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,20 +134,29 @@ class GitViewActivatable(GObject.Object, Gedit.ViewActivatable):
             commit = repo.lookup(head.get_target(), Ggit.Commit)
             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)
-            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
-            if len(self.file_contents_list) > 0:
+            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]