[gitg: 5/5] Protect against null repository



commit 24c0060181a25c13b4df97b306aa43eee5f483c7
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Sun Dec 21 21:22:48 2014 +0100

    Protect against null repository

 gitg/history/gitg-history.vala |   47 +++++++++++++++++++++++----------------
 1 files changed, 28 insertions(+), 19 deletions(-)
---
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index 6215e02..1da862d 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -287,6 +287,12 @@ namespace GitgHistory
                private void store_changed_mainline()
                {
                        var repo = application.repository;
+
+                       if (repo == null)
+                       {
+                               return;
+                       }
+
                        Ggit.Config config;
 
                        try
@@ -674,32 +680,35 @@ namespace GitgHistory
 
                        var permanent = new Ggit.OId[0];
 
-                       foreach (var ml in d_mainline)
+                       if (application.repository != null)
                        {
-                               Ggit.OId id;
-
-                               try
+                               foreach (var ml in d_mainline)
                                {
-                                       id = id_for_ref(application.repository.lookup_reference(ml));
-                               } catch { continue; }
+                                       Ggit.OId id;
 
-                               if (id != null && perm_uniq.add(id))
-                               {
-                                       permanent += id;
+                                       try
+                                       {
+                                               id = id_for_ref(application.repository.lookup_reference(ml));
+                                       } catch { continue; }
+
+                                       if (id != null && perm_uniq.add(id))
+                                       {
+                                               permanent += id;
+                                       }
                                }
-                       }
 
-                       if (d_settings.get_boolean("mainline-head"))
-                       {
-                               try
+                               if (d_settings.get_boolean("mainline-head"))
                                {
-                                       var head = id_for_ref(application.repository.get_head());
-
-                                       if (head != null && perm_uniq.add(head))
+                                       try
                                        {
-                                               permanent += head;
-                                       }
-                               } catch {}
+                                               var head = id_for_ref(application.repository.get_head());
+
+                                               if (head != null && perm_uniq.add(head))
+                                               {
+                                                       permanent += head;
+                                               }
+                                       } catch {}
+                               }
                        }
 
                        foreach (var r in d_main.refs_list.selection)


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