[gnome-builder] vcs: add api to switch branches



commit 0334f33adbd709596bd6e5550e3399db042f96d7
Author: Christian Hergert <chergert redhat com>
Date:   Sun Jan 27 16:21:53 2019 -0800

    vcs: add api to switch branches

 src/libide/vcs/ide-vcs.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/libide/vcs/ide-vcs.h | 19 +++++++++++++++++
 2 files changed, 72 insertions(+)
---
diff --git a/src/libide/vcs/ide-vcs.c b/src/libide/vcs/ide-vcs.c
index 790159363..b9adc1b1f 100644
--- a/src/libide/vcs/ide-vcs.c
+++ b/src/libide/vcs/ide-vcs.c
@@ -89,6 +89,31 @@ ide_vcs_real_list_branches_finish (IdeVcs        *self,
   return g_task_propagate_pointer (G_TASK (result), error);
 }
 
+static void
+ide_vcs_real_switch_branch_async (IdeVcs              *self,
+                                  IdeVcsBranch        *branch,
+                                  GCancellable        *cancellable,
+                                  GAsyncReadyCallback  callback,
+                                  gpointer             user_data)
+{
+  g_task_report_new_error (self,
+                           callback,
+                           user_data,
+                           ide_vcs_real_switch_branch_async,
+                           G_IO_ERROR,
+                           G_IO_ERROR_NOT_SUPPORTED,
+                           "Not supported by %s",
+                           G_OBJECT_TYPE_NAME (self));
+}
+
+static gboolean
+ide_vcs_real_switch_branch_finish (IdeVcs        *self,
+                                   GAsyncResult  *result,
+                                   GError       **error)
+{
+  return g_task_propagate_boolean (G_TASK (result), error);
+}
+
 static void
 ide_vcs_default_init (IdeVcsInterface *iface)
 {
@@ -96,6 +121,8 @@ ide_vcs_default_init (IdeVcsInterface *iface)
   iface->list_status_finish = ide_vcs_real_list_status_finish;
   iface->list_branches_async = ide_vcs_real_list_branches_async;
   iface->list_branches_finish = ide_vcs_real_list_branches_finish;
+  iface->switch_branch_async = ide_vcs_real_switch_branch_async;
+  iface->switch_branch_finish = ide_vcs_real_switch_branch_finish;
 
   g_object_interface_install_property (iface,
                                        g_param_spec_string ("branch-name",
@@ -501,3 +528,29 @@ ide_vcs_list_branches_finish (IdeVcs        *self,
 
   return IDE_VCS_GET_IFACE (self)->list_branches_finish (self, result, error);
 }
+
+void
+ide_vcs_switch_branch_async (IdeVcs              *self,
+                             IdeVcsBranch        *branch,
+                             GCancellable        *cancellable,
+                             GAsyncReadyCallback  callback,
+                             gpointer             user_data)
+{
+  g_return_if_fail (IDE_IS_MAIN_THREAD ());
+  g_return_if_fail (IDE_IS_VCS (self));
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  IDE_VCS_GET_IFACE (self)->switch_branch_async (self, branch, cancellable, callback, user_data);
+}
+
+gboolean
+ide_vcs_switch_branch_finish (IdeVcs        *self,
+                              GAsyncResult  *result,
+                              GError       **error)
+{
+  g_return_val_if_fail (IDE_IS_MAIN_THREAD (), FALSE);
+  g_return_val_if_fail (IDE_IS_VCS (self), FALSE);
+  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
+
+  return IDE_VCS_GET_IFACE (self)->switch_branch_finish (self, result, error);
+}
diff --git a/src/libide/vcs/ide-vcs.h b/src/libide/vcs/ide-vcs.h
index 8641ab3c2..a654bb2e3 100644
--- a/src/libide/vcs/ide-vcs.h
+++ b/src/libide/vcs/ide-vcs.h
@@ -26,6 +26,7 @@
 
 #include <libide-core.h>
 
+#include "ide-vcs-branch.h"
 #include "ide-vcs-config.h"
 
 G_BEGIN_DECLS
@@ -64,6 +65,14 @@ struct _IdeVcsInterface
   GPtrArray              *(*list_branches_finish)      (IdeVcs               *self,
                                                         GAsyncResult         *result,
                                                         GError              **error);
+  void                    (*switch_branch_async)       (IdeVcs               *self,
+                                                        IdeVcsBranch         *branch,
+                                                        GCancellable         *cancellable,
+                                                        GAsyncReadyCallback   callback,
+                                                        gpointer              user_data);
+  gboolean                (*switch_branch_finish)      (IdeVcs               *self,
+                                                        GAsyncResult         *result,
+                                                        GError              **error);
 };
 
 IDE_AVAILABLE_IN_3_32
@@ -109,5 +118,15 @@ IDE_AVAILABLE_IN_3_32
 GPtrArray    *ide_vcs_list_branches_finish (IdeVcs               *self,
                                             GAsyncResult         *result,
                                             GError              **error);
+IDE_AVAILABLE_IN_3_32
+void          ide_vcs_switch_branch_async  (IdeVcs               *self,
+                                            IdeVcsBranch         *branch,
+                                            GCancellable         *cancellable,
+                                            GAsyncReadyCallback   callback,
+                                            gpointer              user_data);
+IDE_AVAILABLE_IN_3_32
+gboolean      ide_vcs_switch_branch_finish (IdeVcs               *self,
+                                            GAsyncResult         *result,
+                                            GError              **error);
 
 G_END_DECLS


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