[gnome-builder/gnome-builder-3-20] git: implement IdeVcsInitializer



commit 486299652fac23e9abf31b75e495efb7ca6bf427
Author: Christian Hergert <chergert redhat com>
Date:   Tue May 10 18:52:19 2016 +0300

    git: implement IdeVcsInitializer
    
    This can be used to initialize a new git repository in a given directory.

 plugins/git/Makefile.am               |    2 +
 plugins/git/ide-git-plugin.c          |    4 +
 plugins/git/ide-git-vcs-initializer.c |  113 +++++++++++++++++++++++++++++++++
 plugins/git/ide-git-vcs-initializer.h |   33 ++++++++++
 4 files changed, 152 insertions(+), 0 deletions(-)
---
diff --git a/plugins/git/Makefile.am b/plugins/git/Makefile.am
index 3c609f6..392831b 100644
--- a/plugins/git/Makefile.am
+++ b/plugins/git/Makefile.am
@@ -23,6 +23,8 @@ libgit_plugin_la_SOURCES = \
        ide-git-remote-callbacks.h \
        ide-git-vcs.c \
        ide-git-vcs.h \
+       ide-git-vcs-initializer.c \
+       ide-git-vcs-initializer.h \
        $(NULL)
 
 nodist_libgit_plugin_la_SOURCES = \
diff --git a/plugins/git/ide-git-plugin.c b/plugins/git/ide-git-plugin.c
index 2442769..e84a96b 100644
--- a/plugins/git/ide-git-plugin.c
+++ b/plugins/git/ide-git-plugin.c
@@ -22,6 +22,7 @@
 #include "ide-git-genesis-addin.h"
 #include "ide-git-preferences-addin.h"
 #include "ide-git-vcs.h"
+#include "ide-git-vcs-initializer.h"
 
 static gboolean
 register_ggit (void)
@@ -57,6 +58,9 @@ peas_register_types (PeasObjectModule *module)
                                                   IDE_TYPE_VCS,
                                                   IDE_TYPE_GIT_VCS);
       peas_object_module_register_extension_type (module,
+                                                  IDE_TYPE_VCS_INITIALIZER,
+                                                  IDE_TYPE_GIT_VCS_INITIALIZER);
+      peas_object_module_register_extension_type (module,
                                                   IDE_TYPE_PREFERENCES_ADDIN,
                                                   IDE_TYPE_GIT_PREFERENCES_ADDIN);
       peas_object_module_register_extension_type (module,
diff --git a/plugins/git/ide-git-vcs-initializer.c b/plugins/git/ide-git-vcs-initializer.c
new file mode 100644
index 0000000..bbbcbc2
--- /dev/null
+++ b/plugins/git/ide-git-vcs-initializer.c
@@ -0,0 +1,113 @@
+/* ide-git-vcs-initializer.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 <libgit2-glib/ggit.h>
+
+#include "ide-git-vcs-initializer.h"
+
+struct _IdeGitVcsInitializer
+{
+  GObject parent_instance;
+};
+
+static void vcs_initializer_init (IdeVcsInitializerInterface *iface);
+
+G_DEFINE_TYPE_EXTENDED (IdeGitVcsInitializer, ide_git_vcs_initializer, G_TYPE_OBJECT, 0,
+                        G_IMPLEMENT_INTERFACE (IDE_TYPE_VCS_INITIALIZER, vcs_initializer_init))
+
+IdeGitVcsInitializer *
+ide_git_vcs_initializer_new (void)
+{
+  return g_object_new (IDE_TYPE_GIT_VCS_INITIALIZER, NULL);
+}
+
+static void
+ide_git_vcs_initializer_class_init (IdeGitVcsInitializerClass *klass)
+{
+}
+
+static void
+ide_git_vcs_initializer_init (IdeGitVcsInitializer *self)
+{
+}
+
+static void
+ide_git_vcs_initializer_initialize_worker (GTask        *task,
+                                           gpointer      source_object,
+                                           gpointer      task_data,
+                                           GCancellable *cancellable)
+{
+  GFile *file = task_data;
+  g_autoptr(GgitRepository) repository = NULL;
+  GError *error = NULL;
+
+  g_assert (G_IS_TASK (task));
+  g_assert (IDE_IS_GIT_VCS_INITIALIZER (source_object));
+  g_assert (G_IS_FILE (file));
+
+  repository = ggit_repository_init_repository (file, FALSE, &error);
+
+  if (repository == NULL)
+    g_task_return_error (task, error);
+  else
+    g_task_return_boolean (task, TRUE);
+}
+
+static void
+ide_git_vcs_initializer_initialize_async (IdeVcsInitializer   *initializer,
+                                          GFile               *file,
+                                          GCancellable        *cancellable,
+                                          GAsyncReadyCallback  callback,
+                                          gpointer             user_data)
+{
+  IdeGitVcsInitializer *self = (IdeGitVcsInitializer *)initializer;
+  g_autoptr(GTask) task = NULL;
+
+  g_return_if_fail (IDE_IS_GIT_VCS_INITIALIZER (self));
+  g_return_if_fail (G_IS_FILE (file));
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  task = g_task_new (self, cancellable, callback, user_data);
+  g_task_set_task_data (task, g_object_ref (file), g_object_unref);
+  g_task_run_in_thread (task, ide_git_vcs_initializer_initialize_worker);
+}
+
+static gboolean
+ide_git_vcs_initializer_initialize_finish (IdeVcsInitializer  *initializer,
+                                           GAsyncResult       *result,
+                                           GError            **error)
+{
+  g_return_val_if_fail (IDE_IS_GIT_VCS_INITIALIZER (initializer), FALSE);
+  g_return_val_if_fail (G_IS_TASK (result), FALSE);
+
+  return g_task_propagate_boolean (G_TASK (result), error);
+}
+
+static gchar *
+ide_git_vcs_initializer_get_title (IdeVcsInitializer *initilizer)
+{
+  return g_strdup ("Git");
+}
+
+static void
+vcs_initializer_init (IdeVcsInitializerInterface *iface)
+{
+  iface->get_title = ide_git_vcs_initializer_get_title;
+  iface->initialize_async = ide_git_vcs_initializer_initialize_async;
+  iface->initialize_finish = ide_git_vcs_initializer_initialize_finish;
+}
diff --git a/plugins/git/ide-git-vcs-initializer.h b/plugins/git/ide-git-vcs-initializer.h
new file mode 100644
index 0000000..05ff906
--- /dev/null
+++ b/plugins/git/ide-git-vcs-initializer.h
@@ -0,0 +1,33 @@
+/* ide-git-vcs-initializer.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_VCS_INITIALIZER_H
+#define IDE_GIT_VCS_INITIALIZER_H
+
+#include <ide.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_GIT_VCS_INITIALIZER (ide_git_vcs_initializer_get_type())
+
+G_DECLARE_FINAL_TYPE (IdeGitVcsInitializer, ide_git_vcs_initializer, IDE, GIT_VCS_INITIALIZER, GObject)
+
+G_END_DECLS
+
+#endif /* IDE_GIT_VCS_INITIALIZER_H */
+


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