Improve runtime error for non-thread-safe detection

https://bugzilla.gnome.org/show_bug.cgi?id=721664
This commit is contained in:
Jesse van den Kieboom 2014-01-07 00:56:23 +01:00
parent 270350f2c0
commit d4d999f990
2 changed files with 60 additions and 3 deletions

View file

@ -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();

View file

@ -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();