[gnome-builder] git: move git preferences to the git plugin
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] git: move git preferences to the git plugin
- Date: Wed, 27 Jan 2016 12:05:06 +0000 (UTC)
commit 93f85854ce8d10a19a750a99f36de2d92c8f7ef1
Author: Christian Hergert <chergert redhat com>
Date: Wed Jan 27 13:04:40 2016 +0100
git: move git preferences to the git plugin
configure.ac | 37 -----
libide/ide-application.c | 1 -
libide/preferences/ide-preferences-builtin.c | 109 ---------------
plugins/git/Makefile.am | 4 +
plugins/git/configure.ac | 57 ++++++++-
plugins/git/ide-git-plugin.c | 4 +
plugins/git/ide-git-preferences-addin.c | 185 ++++++++++++++++++++++++++
plugins/git/ide-git-preferences-addin.h | 32 +++++
8 files changed, 280 insertions(+), 149 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d0f8729..dbd0ad9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -169,7 +169,6 @@ dnl ***********************************************************************
m4_define([gtk_required_version], [3.19.7])
m4_define([glib_required_version], [2.47.4])
m4_define([gtksourceview_required_version], [3.19.4])
-m4_define([ggit_required_version], [0.23.7])
m4_define([gobject_introspection_version], [1.47.1])
m4_define([pygobject_required_version], [3.19.3])
m4_define([libxml_required_version], [2.9.0])
@@ -183,12 +182,10 @@ PKG_CHECK_MODULES(GD, [gtk+-3.0 >= gtk_required_version])
PKG_CHECK_MODULES(GEDIT, [glib-2.0 >= glib_required_version
gtk+-3.0 >= gtk_required_version])
PKG_CHECK_MODULES(ICONS, [gio-2.0 >= glib_required_version])
-PKG_CHECK_MODULES(LIBGITG, [libgit2-glib-1.0 >= ggit_required_version])
PKG_CHECK_MODULES(LIBIDE, [gio-2.0 >= glib_required_version
gio-unix-2.0 >= glib_required_version
gtk+-3.0 >= gtk_required_version
gtksourceview-3.0 >= gtksourceview_required_version
- libgit2-glib-1.0 >= ggit_required_version
libpeas-1.0 >= peas_required_version
libxml-2.0 >= libxml_required_version
pangoft2 >= pangoft2_required_version])
@@ -206,40 +203,6 @@ PKG_CHECK_MODULES(XML, [gio-2.0 >= glib_required_version
dnl ***********************************************************************
-dnl Be extra careful about libgit2-glib requirements
-dnl ***********************************************************************
-# FIXME: Move git to a plugin. Requires abstraction in new-project-dialog.
-cflags_save="${CFLAGS}"
-libs_save="${LIBS}"
-CFLAGS="${CFLAGS} ${LIBGITG_CFLAGS}"
-LIBS="${LIBS} ${LIBGITG_LIBS}"
-# Thread-Safe
-AC_MSG_CHECKING([for thread-safe support in libgit2])
-AC_TRY_RUN([
- #include <libgit2-glib/ggit.h>
- int
- main(int argc, const char *argv[])
- {
- ggit_init ();
- return ((ggit_get_features() & GGIT_FEATURE_THREADS) != 0) ? 0 : 1;
- }
-],[AC_MSG_RESULT([yes])],[AC_MSG_ERROR([no, please recompile a threadsafe version of libgit2
(-DTHREADSAFE:BOOL=ON)])])
-# SSH
-AC_MSG_CHECKING([for SSH support in libgit2])
-AC_TRY_RUN([
- #include <libgit2-glib/ggit.h>
- int
- main(int argc, const char *argv[])
- {
- ggit_init ();
- return ((ggit_get_features() & GGIT_FEATURE_SSH) != 0) ? 0 : 1;
- }
-],[AC_MSG_RESULT([yes])],[AC_MSG_ERROR([no, please recompile a libgit2 with ssh support])])
-CFLAGS="${cflags_save}"
-LIBS="${libs_save}"
-
-
-dnl ***********************************************************************
dnl Check for supported plugins
dnl ***********************************************************************
m4_include([plugins/autotools/configure.ac])
diff --git a/libide/ide-application.c b/libide/ide-application.c
index 772bec7..a62ae9d 100644
--- a/libide/ide-application.c
+++ b/libide/ide-application.c
@@ -25,7 +25,6 @@
#include <glib/gi18n.h>
#include <girepository.h>
#include <gtksourceview/gtksource.h>
-#include <libgit2-glib/ggit.h>
#include <locale.h>
#include <stdlib.h>
#ifdef __linux
diff --git a/libide/preferences/ide-preferences-builtin.c b/libide/preferences/ide-preferences-builtin.c
index 458afd7..455934b 100644
--- a/libide/preferences/ide-preferences-builtin.c
+++ b/libide/preferences/ide-preferences-builtin.c
@@ -18,7 +18,6 @@
#include <glib/gi18n.h>
#include <gtksourceview/gtksource.h>
-#include <libgit2-glib/ggit.h>
#include <libpeas/peas.h>
#include "ide-macros.h"
@@ -175,113 +174,6 @@ ide_preferences_builtin_register_snippets (IdePreferences *preferences)
ide_preferences_add_switch (preferences, "snippets", "completion", "org.gnome.builder.code-insight",
"snippet-completion", NULL, NULL, _("Code snippets"), _("Use code fragments to increase typing efficiency"),
NULL, 0);
}
-static gchar *
-read_config_string (GgitConfig *orig_config,
- const gchar *key,
- GError **error)
-{
- GgitConfig *config;
- const gchar *value;
- gchar *ret;
-
- g_assert (GGIT_IS_CONFIG (orig_config));
- g_assert (key != NULL);
-
- config = ggit_config_snapshot (orig_config, error);
- if (config == NULL)
- return NULL;
-
- value = ggit_config_get_string (config, key, error);
-
- ret = value ? g_strdup (value) : NULL;
-
- g_clear_object (&config);
-
- return ret;
-}
-
-static void
-author_changed_cb (IdePreferencesEntry *entry,
- const gchar *text,
- GgitConfig *config)
-{
- g_assert (IDE_IS_PREFERENCES_ENTRY (entry));
- g_assert (text != NULL);
- g_assert (GGIT_IS_CONFIG (config));
-
- ggit_config_set_string (config, "user.name", text, NULL);
-}
-
-static void
-email_changed_cb (IdePreferencesEntry *entry,
- const gchar *text,
- GgitConfig *config)
-{
- g_assert (IDE_IS_PREFERENCES_ENTRY (entry));
- g_assert (text != NULL);
- g_assert (GGIT_IS_CONFIG (config));
-
- ggit_config_set_string (config, "user.email", text, NULL);
-}
-
-static void
-ide_preferences_builtin_register_vcs (IdePreferences *preferences)
-{
- g_autofree gchar *author_text = NULL;
- g_autofree gchar *email_text = NULL;
- g_autoptr(GFile) global_file = NULL;
- GgitConfig *config;
- GtkSizeGroup *size_group;
- GtkWidget *author;
- GtkWidget *email;
-
- ide_preferences_add_page (preferences, "vcs", _("Version Control"), 600);
-
- if (!(global_file = ggit_config_find_global ()))
- {
- g_autofree gchar *path = NULL;
-
- path = g_build_filename (g_get_home_dir (), ".gitconfig", NULL);
- global_file = g_file_new_for_path (path);
- }
-
- config = ggit_config_new_from_file (global_file, NULL);
- g_object_set_data_full (G_OBJECT (preferences), "GGIT_CONFIG", config, g_object_unref);
-
- author_text = read_config_string (config, "user.name", NULL);
- author = g_object_new (IDE_TYPE_PREFERENCES_ENTRY,
- "text", author_text,
- "title", "Author",
- "visible", TRUE,
- NULL);
- g_signal_connect_object (author,
- "changed",
- G_CALLBACK (author_changed_cb),
- config,
- 0);
-
- email_text = read_config_string (config, "user.email", NULL);
- email = g_object_new (IDE_TYPE_PREFERENCES_ENTRY,
- "text", email_text,
- "title", "Email",
- "visible", TRUE,
- NULL);
- g_signal_connect_object (email,
- "changed",
- G_CALLBACK (email_changed_cb),
- config,
- 0);
-
- ide_preferences_add_list_group (preferences, "vcs", "attribution", _("Attribution"), 0);
- ide_preferences_add_custom (preferences, "vcs", "attribution", author, NULL, 0);
- ide_preferences_add_custom (preferences, "vcs", "attribution", email, NULL, 0);
-
- size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
- gtk_size_group_add_widget (size_group, ide_preferences_entry_get_title_widget (IDE_PREFERENCES_ENTRY
(author)));
- gtk_size_group_add_widget (size_group, ide_preferences_entry_get_title_widget (IDE_PREFERENCES_ENTRY
(email)));
- g_clear_object (&size_group);
-}
-
static void
ide_preferences_builtin_register_languages (IdePreferences *preferences)
{
@@ -360,7 +252,6 @@ _ide_preferences_builtin_register (IdePreferences *preferences)
ide_preferences_builtin_register_code_insight (preferences);
ide_preferences_builtin_register_snippets (preferences);
ide_preferences_builtin_register_keyboard (preferences);
- ide_preferences_builtin_register_vcs (preferences);
ide_preferences_builtin_register_plugins (preferences);
ide_preferences_builtin_register_build (preferences);
}
diff --git a/plugins/git/Makefile.am b/plugins/git/Makefile.am
index 0202f70..5468df0 100644
--- a/plugins/git/Makefile.am
+++ b/plugins/git/Makefile.am
@@ -17,6 +17,8 @@ libgit_plugin_la_SOURCES = \
ide-git-genesis-addin.c \
ide-git-genesis-addin.h \
ide-git-plugin.c \
+ ide-git-preferences-addin.c \
+ ide-git-preferences-addin.h \
ide-git-remote-callbacks.c \
ide-git-remote-callbacks.h \
ide-git-vcs.c \
@@ -29,6 +31,7 @@ nodist_libgit_plugin_la_SOURCES = \
libgit_plugin_la_CFLAGS = \
$(LIBIDE_CFLAGS) \
+ $(GIT_CFLAGS) \
$(OPTIMIZE_CFLAGS) \
-I$(top_srcdir)/libide \
-I$(top_srcdir)/contrib/egg \
@@ -37,6 +40,7 @@ libgit_plugin_la_CFLAGS = \
libgit_plugin_la_LIBADD = $(GIT_LIBS)
libgit_plugin_la_LDFLAGS = \
+ $(GIT_LIBS) \
$(OPTIMIZE_LDFLAGS) \
-avoid-version \
-module \
diff --git a/plugins/git/configure.ac b/plugins/git/configure.ac
index dac9f1c..55095de 100644
--- a/plugins/git/configure.ac
+++ b/plugins/git/configure.ac
@@ -1,3 +1,56 @@
-PKG_CHECK_MODULES(GIT, [libgit2-glib-1.0 >= 0.23.7], [enable_git_plugin=yes], [enable_git_plugin=no])
-AM_CONDITIONAL(ENABLE_GIT_PLUGIN, test x$enable_git_plugin != xno)
+m4_define([ggit_required_version], [0.23.7])
+
+# --enable-git-plugin=yes/no/auto
+AC_ARG_ENABLE([git-plugin],
+ [AS_HELP_STRING([--enable-git-plugin=@<:@yes/no/auto@:>@],
+ [Build with support for git.])],
+ [enable_git_plugin=$enableval],
+ [enable_git_plugin=auto])
+
+AS_IF([test "$enable_git_plugin" != no],[
+ PKG_CHECK_MODULES(GIT,
+ [libgit2-glib-1.0 >= ggit_required_version],
+ [have_git=yes],
+ [have_git=no])
+
+ AS_IF([test "$enable_git_plugin" = "yes" && "$have_git" = "no"],[
+ AC_MSG_ERROR([--enable-git-plugin requires libgit2-glib-1.0 >= ggit_required_version])
+ ])
+
+ enable_git_plugin=yes
+
+ dnl ***********************************************************************
+ dnl Be extra careful about libgit2-glib requirements
+ dnl ***********************************************************************
+ cflags_save="${CFLAGS}"
+ libs_save="${LIBS}"
+ CFLAGS="${CFLAGS} ${GIT_CFLAGS}"
+ LIBS="${LIBS} ${GIT_LIBS}"
+ # Thread-Safe
+ AC_MSG_CHECKING([for thread-safe support in libgit2])
+ AC_TRY_RUN([
+ #include <libgit2-glib/ggit.h>
+ int
+ main(int argc, const char *argv[])
+ {
+ ggit_init ();
+ return ((ggit_get_features() & GGIT_FEATURE_THREADS) != 0) ? 0 : 1;
+ }
+ ],[AC_MSG_RESULT([yes])],[AC_MSG_ERROR([no, please recompile a threadsafe version of libgit2
(-DTHREADSAFE:BOOL=ON)])])
+ # SSH
+ AC_MSG_CHECKING([for SSH support in libgit2])
+ AC_TRY_RUN([
+ #include <libgit2-glib/ggit.h>
+ int
+ main(int argc, const char *argv[])
+ {
+ ggit_init ();
+ return ((ggit_get_features() & GGIT_FEATURE_SSH) != 0) ? 0 : 1;
+ }
+ ],[AC_MSG_RESULT([yes])],[AC_MSG_ERROR([no, please recompile a libgit2 with ssh support])])
+ CFLAGS="${cflags_save}"
+ LIBS="${libs_save}"
+])
+
+AM_CONDITIONAL(ENABLE_GIT_PLUGIN, test x$enable_git_plugin = xyes)
AC_CONFIG_FILES([plugins/git/Makefile])
diff --git a/plugins/git/ide-git-plugin.c b/plugins/git/ide-git-plugin.c
index 90e236e..2442769 100644
--- a/plugins/git/ide-git-plugin.c
+++ b/plugins/git/ide-git-plugin.c
@@ -20,6 +20,7 @@
#include <ide.h>
#include "ide-git-genesis-addin.h"
+#include "ide-git-preferences-addin.h"
#include "ide-git-vcs.h"
static gboolean
@@ -56,6 +57,9 @@ peas_register_types (PeasObjectModule *module)
IDE_TYPE_VCS,
IDE_TYPE_GIT_VCS);
peas_object_module_register_extension_type (module,
+ IDE_TYPE_PREFERENCES_ADDIN,
+ IDE_TYPE_GIT_PREFERENCES_ADDIN);
+ peas_object_module_register_extension_type (module,
IDE_TYPE_GENESIS_ADDIN,
IDE_TYPE_GIT_GENESIS_ADDIN);
}
diff --git a/plugins/git/ide-git-preferences-addin.c b/plugins/git/ide-git-preferences-addin.c
new file mode 100644
index 0000000..528cff8
--- /dev/null
+++ b/plugins/git/ide-git-preferences-addin.c
@@ -0,0 +1,185 @@
+/* ide-git-preferences-addin.c
+ *
+ * Copyright (C) 2016 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+#include <libgit2-glib/ggit.h>
+
+/* Semi public API */
+#include "preferences/ide-preferences-entry.h"
+
+#include "ide-git-preferences-addin.h"
+
+struct _IdeGitPreferencesAddin
+{
+ GObject parent_instance;
+};
+
+static void preferences_addin_iface_init (IdePreferencesAddinInterface *iface);
+
+G_DEFINE_TYPE_EXTENDED (IdeGitPreferencesAddin, ide_git_preferences_addin, G_TYPE_OBJECT, 0,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_PREFERENCES_ADDIN,
+ preferences_addin_iface_init))
+
+static void
+ide_git_preferences_addin_class_init (IdeGitPreferencesAddinClass *klass)
+{
+}
+
+static void
+ide_git_preferences_addin_init (IdeGitPreferencesAddin *self)
+{
+}
+
+static gchar *
+read_config_string (GgitConfig *orig_config,
+ const gchar *key,
+ GError **error)
+{
+ GgitConfig *config;
+ const gchar *value;
+ gchar *ret;
+
+ g_assert (GGIT_IS_CONFIG (orig_config));
+ g_assert (key != NULL);
+
+ config = ggit_config_snapshot (orig_config, error);
+ if (config == NULL)
+ return NULL;
+
+ value = ggit_config_get_string (config, key, error);
+
+ ret = value ? g_strdup (value) : NULL;
+
+ g_clear_object (&config);
+
+ return ret;
+}
+
+static void
+author_changed_cb (IdePreferencesEntry *entry,
+ const gchar *text,
+ GgitConfig *config)
+{
+ g_assert (IDE_IS_PREFERENCES_ENTRY (entry));
+ g_assert (text != NULL);
+ g_assert (GGIT_IS_CONFIG (config));
+
+ ggit_config_set_string (config, "user.name", text, NULL);
+}
+
+static void
+email_changed_cb (IdePreferencesEntry *entry,
+ const gchar *text,
+ GgitConfig *config)
+{
+ g_assert (IDE_IS_PREFERENCES_ENTRY (entry));
+ g_assert (text != NULL);
+ g_assert (GGIT_IS_CONFIG (config));
+
+ ggit_config_set_string (config, "user.email", text, NULL);
+}
+
+static void
+register_git (IdePreferences *preferences)
+{
+ g_autofree gchar *author_text = NULL;
+ g_autofree gchar *email_text = NULL;
+ g_autoptr(GFile) global_file = NULL;
+ GgitConfig *config;
+ GtkSizeGroup *size_group;
+ GtkWidget *author;
+ GtkWidget *email;
+
+ ide_preferences_add_page (preferences, "git", _("Version Control"), 600);
+
+ if (!(global_file = ggit_config_find_global ()))
+ {
+ g_autofree gchar *path = NULL;
+
+ path = g_build_filename (g_get_home_dir (), ".gitconfig", NULL);
+ global_file = g_file_new_for_path (path);
+ }
+
+ config = ggit_config_new_from_file (global_file, NULL);
+ g_object_set_data_full (G_OBJECT (preferences), "GGIT_CONFIG", config, g_object_unref);
+
+ author_text = read_config_string (config, "user.name", NULL);
+ author = g_object_new (IDE_TYPE_PREFERENCES_ENTRY,
+ "text", author_text,
+ "title", "Author",
+ "visible", TRUE,
+ NULL);
+ g_signal_connect_object (author,
+ "changed",
+ G_CALLBACK (author_changed_cb),
+ config,
+ 0);
+
+ email_text = read_config_string (config, "user.email", NULL);
+ email = g_object_new (IDE_TYPE_PREFERENCES_ENTRY,
+ "text", email_text,
+ "title", "Email",
+ "visible", TRUE,
+ NULL);
+ g_signal_connect_object (email,
+ "changed",
+ G_CALLBACK (email_changed_cb),
+ config,
+ 0);
+
+ ide_preferences_add_list_group (preferences, "git", "attribution", _("Attribution"), 0);
+ ide_preferences_add_custom (preferences, "git", "attribution", author, NULL, 0);
+ ide_preferences_add_custom (preferences, "git", "attribution", email, NULL, 0);
+
+ size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+ gtk_size_group_add_widget (size_group, ide_preferences_entry_get_title_widget (IDE_PREFERENCES_ENTRY
(author)));
+ gtk_size_group_add_widget (size_group, ide_preferences_entry_get_title_widget (IDE_PREFERENCES_ENTRY
(email)));
+ g_clear_object (&size_group);
+}
+
+
+static void
+ide_git_preferences_addin_load (IdePreferencesAddin *addin,
+ IdePreferences *preferences)
+{
+ IdeGitPreferencesAddin *self = (IdeGitPreferencesAddin *)addin;
+
+ g_assert (IDE_IS_GIT_PREFERENCES_ADDIN (self));
+ g_assert (IDE_IS_PREFERENCES (preferences));
+
+ register_git (preferences);
+}
+
+static void
+ide_git_preferences_addin_unload (IdePreferencesAddin *addin,
+ IdePreferences *preferences)
+{
+ IdeGitPreferencesAddin *self = (IdeGitPreferencesAddin *)addin;
+
+ g_assert (IDE_IS_GIT_PREFERENCES_ADDIN (self));
+ g_assert (IDE_IS_PREFERENCES (preferences));
+
+ /* TODO: Unregister preferences */
+}
+
+static void
+preferences_addin_iface_init (IdePreferencesAddinInterface *iface)
+{
+ iface->load = ide_git_preferences_addin_load;
+ iface->unload = ide_git_preferences_addin_unload;
+}
diff --git a/plugins/git/ide-git-preferences-addin.h b/plugins/git/ide-git-preferences-addin.h
new file mode 100644
index 0000000..1067b6e
--- /dev/null
+++ b/plugins/git/ide-git-preferences-addin.h
@@ -0,0 +1,32 @@
+/* ide-git-preferences-addin.h
+ *
+ * Copyright (C) 2016 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_GIT_PREFERENCES_ADDIN_H
+#define IDE_GIT_PREFERENCES_ADDIN_H
+
+#include <ide.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_GIT_PREFERENCES_ADDIN (ide_git_preferences_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeGitPreferencesAddin, ide_git_preferences_addin, IDE, GIT_PREFERENCES_ADDIN, GObject)
+
+G_END_DECLS
+
+#endif /* IDE_GIT_PREFERENCES_ADDIN_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]