[gitg] Improve runtime error for non-thread-safe detection



commit d4d999f9901d50673f93269229359d36182354d8
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Tue Jan 7 00:56:23 2014 +0100

    Improve runtime error for non-thread-safe detection
    
    https://bugzilla.gnome.org/show_bug.cgi?id=721664

 gitg/gitg.vala         |   36 +++++++++++++++++++++++++++++++++++-
 libgitg/gitg-init.vala |   27 +++++++++++++++++++++++++--
 2 files changed, 60 insertions(+), 3 deletions(-)
---
diff --git a/gitg/gitg.vala b/gitg/gitg.vala
index 0d23a25..2459cbd 100644
--- a/gitg/gitg.vala
+++ b/gitg/gitg.vala
@@ -24,6 +24,25 @@ private const string version = Config.VERSION;
 
 public class Main
 {
+       private static void init_error(string[] args, string msg)
+       {
+               Gtk.init(ref args);
+
+               var dlg = new Gtk.MessageDialog(null,
+                                               0,
+                                               Gtk.MessageType.ERROR,
+                                               Gtk.ButtonsType.CLOSE,
+                                               "%s",
+                                               msg);
+
+               dlg.window_position = Gtk.WindowPosition.CENTER;
+
+               dlg.response.connect(() => { Gtk.main_quit(); });
+               dlg.show();
+
+               Gtk.main();
+       }
+
        public static int main(string[] args)
        {
                Intl.setlocale(LocaleCategory.ALL, "");
@@ -34,7 +53,22 @@ public class Main
                Environment.set_prgname("gitg");
                Environment.set_application_name(_("gitg"));
 
-               Gitg.init();
+               try
+               {
+                       Gitg.init();
+               }
+               catch (Error e)
+               {
+                       if (e is Gitg.InitError.THREADS_UNSAFE)
+                       {
+                               var errmsg = _("We are terribly sorry, but gitg requires libgit2 (a library 
on which gitg depends) to be compiled with threading support.\n\nIf you manually compiled libgit2, then 
please configure libgit2 with -DTHREADSAFE:BOOL=ON.\n\nOtherwise, report a bug in your distributions' bug 
reporting system for providing libgit2 without threading support.");
+
+                               init_error(args, errmsg);
+                               error("%s", errmsg);
+                       }
+
+                       Process.exit(1);
+               }
 
                // Make sure to pull in gd symbols since libgd gets linked statically
                Gd.ensure_types();
diff --git a/libgitg/gitg-init.vala b/libgitg/gitg-init.vala
index 42e0895..2e54bf7 100644
--- a/libgitg/gitg-init.vala
+++ b/libgitg/gitg-init.vala
@@ -20,11 +20,34 @@
 namespace Gitg
 {
 
-public void init()
+public errordomain InitError
 {
+       THREADS_UNSAFE
+}
+
+private static bool gitg_inited = false;
+private static InitError? gitg_initerr = null;
+
+public void init() throws Error
+{
+       if (gitg_inited)
+       {
+               if (gitg_initerr != null)
+               {
+                       throw gitg_initerr;
+               }
+
+               return;
+       }
+
+       gitg_inited = true;
+
        if ((Ggit.get_capabilities() & Ggit.CapFlags.THREADS) == 0)
        {
-               error("libgit2 must be built with threading support in order to run gitg");
+               gitg_initerr = new InitError.THREADS_UNSAFE("no thread support");
+       
+               warning("libgit2 must be built with threading support in order to run gitg");
+               throw gitg_initerr;
        }
 
        Ggit.init();


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