[gitg] Fix assumptions on existing working directory



commit 7848a4c1e5c31f5e8ca792a79bdae618c0388935
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Thu Aug 18 13:02:33 2016 +0200

    Fix assumptions on existing working directory

 libgitg/gitg-diff-view-file-info.vala          |    7 ++++---
 libgitg/gitg-diff-view-file-renderer-text.vala |   11 +++++++++--
 2 files changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/libgitg/gitg-diff-view-file-info.vala b/libgitg/gitg-diff-view-file-info.vala
index ac87b8c..5d78dab 100644
--- a/libgitg/gitg-diff-view-file-info.vala
+++ b/libgitg/gitg-diff-view-file-info.vala
@@ -28,7 +28,8 @@ class Gitg.DiffViewFileInfo : Object
                        return;
                }
 
-               var location = repository.get_workdir().get_child(path);
+               var workdir = repository.get_workdir();
+               File location = workdir != null ? workdir.get_child(path) : null;
 
                if (!from_workdir)
                {
@@ -46,7 +47,7 @@ class Gitg.DiffViewFileInfo : Object
                        var bytes = new Bytes(blob.get_raw_content());
                        new_file_input_stream = new GLib.MemoryInputStream.from_bytes(bytes);
                }
-               else
+               else if (location != null)
                {
                        // Try to read from disk
                        try
@@ -64,7 +65,7 @@ class Gitg.DiffViewFileInfo : Object
                if (seekable != null && seekable.can_seek())
                {
                        // Read a little bit of content to guess the type
-                       yield guess_content_type(new_file_input_stream, location.get_basename(), cancellable);
+                       yield guess_content_type(new_file_input_stream, location != null ? 
location.get_basename() : null, cancellable);
 
                        try
                        {
diff --git a/libgitg/gitg-diff-view-file-renderer-text.vala b/libgitg/gitg-diff-view-file-renderer-text.vala
index 576b181..0ddae6d 100644
--- a/libgitg/gitg-diff-view-file-renderer-text.vala
+++ b/libgitg/gitg-diff-view-file-renderer-text.vala
@@ -283,7 +283,14 @@ class Gitg.DiffViewFileRendererText : Gtk.SourceView, DiffSelectable, DiffViewFi
                        return null;
                }
 
-               return repository.get_workdir().get_child(path);
+               var workdir = repository.get_workdir();
+
+               if (workdir == null)
+               {
+                       return null;
+               }
+
+               return workdir.get_child(path);
        }
 
        private async void init_highlighting_buffer_new(Cancellable cancellable)
@@ -373,7 +380,7 @@ class Gitg.DiffViewFileRendererText : Gtk.SourceView, DiffSelectable, DiffViewFi
        private async Gtk.SourceBuffer? init_highlighting_buffer_from_stream(Ggit.DiffFile file, File 
location, InputStream stream, string content_type, Cancellable cancellable)
        {
                var manager = Gtk.SourceLanguageManager.get_default();
-               var language = manager.guess_language(location.get_basename(), content_type);
+               var language = manager.guess_language(location != null ? location.get_basename() : null, 
content_type);
 
                if (language == null)
                {


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