[gnome-builder] vcs: add API to list branch names



commit d0031c3fbef1348f046ab8162d355bd7658e047d
Author: Christian Hergert <chergert redhat com>
Date:   Sun Jan 27 14:13:12 2019 -0800

    vcs: add API to list branch names

 src/libide/vcs/ide-vcs-branch.c | 54 +++++++++++++++++++++++++++++++++++
 src/libide/vcs/ide-vcs-branch.h | 42 ++++++++++++++++++++++++++++
 src/libide/vcs/ide-vcs.c        | 61 ++++++++++++++++++++++++++++++++++++++++
 src/libide/vcs/ide-vcs.h        | 62 ++++++++++++++++++++++++++---------------
 src/libide/vcs/libide-vcs.h     |  1 +
 src/libide/vcs/meson.build      |  2 ++
 6 files changed, 199 insertions(+), 23 deletions(-)
---
diff --git a/src/libide/vcs/ide-vcs-branch.c b/src/libide/vcs/ide-vcs-branch.c
new file mode 100644
index 000000000..8b02085f8
--- /dev/null
+++ b/src/libide/vcs/ide-vcs-branch.c
@@ -0,0 +1,54 @@
+/* ide-vcs-branch.c
+ *
+ * Copyright 2019 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-vcs-branch"
+
+#include "config.h"
+
+#include "ide-vcs-branch.h"
+
+G_DEFINE_INTERFACE (IdeVcsBranch, ide_vcs_branch, IDE_TYPE_OBJECT)
+
+static void
+ide_vcs_branch_default_init (IdeVcsBranchInterface *iface)
+{
+}
+
+/**
+ * ide_vcs_branch_get_name:
+ * @self: an #IdeVcsBranch
+ *
+ * Gets the name of the branch, which is used in various UI elements
+ * to display to the user.
+ *
+ * Returns: (transfer full): a string containing the branch name
+ *
+ * Since: 3.32
+ */
+gchar *
+ide_vcs_branch_get_name (IdeVcsBranch *self)
+{
+  g_return_val_if_fail (IDE_IS_VCS_BRANCH (self), NULL);
+
+  if (IDE_VCS_BRANCH_GET_IFACE (self)->get_name)
+    return IDE_VCS_BRANCH_GET_IFACE (self)->get_name (self);
+
+  return NULL;
+}
diff --git a/src/libide/vcs/ide-vcs-branch.h b/src/libide/vcs/ide-vcs-branch.h
new file mode 100644
index 000000000..189066b34
--- /dev/null
+++ b/src/libide/vcs/ide-vcs-branch.h
@@ -0,0 +1,42 @@
+/* ide-vcs-branch.h
+ *
+ * Copyright 2019 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <libide-core.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_VCS_BRANCH (ide_vcs_branch_get_type ())
+
+IDE_AVAILABLE_IN_3_32
+G_DECLARE_INTERFACE (IdeVcsBranch, ide_vcs_branch, IDE, VCS_BRANCH, IdeObject)
+
+struct _IdeVcsBranchInterface
+{
+  GTypeInterface parent;
+
+  gchar *(*get_name) (IdeVcsBranch *self);
+};
+
+IDE_AVAILABLE_IN_3_32
+gchar *ide_vcs_branch_get_name (IdeVcsBranch *self);
+
+G_END_DECLS
diff --git a/src/libide/vcs/ide-vcs.c b/src/libide/vcs/ide-vcs.c
index f4c178efe..790159363 100644
--- a/src/libide/vcs/ide-vcs.c
+++ b/src/libide/vcs/ide-vcs.c
@@ -65,11 +65,37 @@ ide_vcs_real_list_status_finish (IdeVcs        *self,
   return g_task_propagate_pointer (G_TASK (result), error);
 }
 
+static void
+ide_vcs_real_list_branches_async (IdeVcs              *self,
+                                  GCancellable        *cancellable,
+                                  GAsyncReadyCallback  callback,
+                                  gpointer             user_data)
+{
+  g_task_report_new_error (self,
+                           callback,
+                           user_data,
+                           ide_vcs_real_list_branches_async,
+                           G_IO_ERROR,
+                           G_IO_ERROR_NOT_SUPPORTED,
+                           "Not supported by %s",
+                           G_OBJECT_TYPE_NAME (self));
+}
+
+static GPtrArray *
+ide_vcs_real_list_branches_finish (IdeVcs        *self,
+                                   GAsyncResult  *result,
+                                   GError       **error)
+{
+  return g_task_propagate_pointer (G_TASK (result), error);
+}
+
 static void
 ide_vcs_default_init (IdeVcsInterface *iface)
 {
   iface->list_status_async = ide_vcs_real_list_status_async;
   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;
 
   g_object_interface_install_property (iface,
                                        g_param_spec_string ("branch-name",
@@ -440,3 +466,38 @@ ide_vcs_ref_from_context (IdeContext *context)
 
   return g_steal_pointer (&ret);
 }
+
+void
+ide_vcs_list_branches_async (IdeVcs              *self,
+                             GCancellable        *cancellable,
+                             GAsyncReadyCallback  callback,
+                             gpointer             user_data)
+{
+  g_return_if_fail (IDE_IS_VCS (self));
+  g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+  IDE_VCS_GET_IFACE (self)->list_branches_async (self, cancellable, callback, user_data);
+}
+
+/**
+ * ide_vcs_list_branches_finish:
+ * @self: an #IdeVcs
+ * @result: a #GAsyncResult
+ * @error: location for a #GError
+ *
+ * Returns: (transfer full) (element-type IdeVcsBranch): an array of
+ *   #IdeVcsBranch.
+ *
+ * Since: 3.32
+ */
+GPtrArray *
+ide_vcs_list_branches_finish (IdeVcs        *self,
+                              GAsyncResult  *result,
+                              GError       **error)
+{
+  g_return_val_if_fail (IDE_IS_MAIN_THREAD (), NULL);
+  g_return_val_if_fail (IDE_IS_VCS (self), NULL);
+  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
+
+  return IDE_VCS_GET_IFACE (self)->list_branches_finish (self, result, error);
+}
diff --git a/src/libide/vcs/ide-vcs.h b/src/libide/vcs/ide-vcs.h
index 68ad04e39..8641ab3c2 100644
--- a/src/libide/vcs/ide-vcs.h
+++ b/src/libide/vcs/ide-vcs.h
@@ -57,41 +57,57 @@ struct _IdeVcsInterface
   GListModel             *(*list_status_finish)        (IdeVcs               *self,
                                                         GAsyncResult         *result,
                                                         GError              **error);
+  void                    (*list_branches_async)       (IdeVcs               *self,
+                                                        GCancellable         *cancellable,
+                                                        GAsyncReadyCallback   callback,
+                                                        gpointer              user_data);
+  GPtrArray              *(*list_branches_finish)      (IdeVcs               *self,
+                                                        GAsyncResult         *result,
+                                                        GError              **error);
 };
 
 IDE_AVAILABLE_IN_3_32
-IdeVcs       *ide_vcs_from_context       (IdeContext           *context);
+IdeVcs       *ide_vcs_from_context         (IdeContext           *context);
+IDE_AVAILABLE_IN_3_32
+IdeVcs       *ide_vcs_ref_from_context     (IdeContext           *context);
+IDE_AVAILABLE_IN_3_32
+GFile        *ide_vcs_get_workdir          (IdeVcs               *self);
 IDE_AVAILABLE_IN_3_32
-IdeVcs       *ide_vcs_ref_from_context   (IdeContext           *context);
+gboolean      ide_vcs_is_ignored           (IdeVcs               *self,
+                                            GFile                *file,
+                                            GError              **error);
 IDE_AVAILABLE_IN_3_32
-GFile        *ide_vcs_get_workdir        (IdeVcs               *self);
+gboolean      ide_vcs_path_is_ignored      (IdeVcs               *self,
+                                            const gchar          *path,
+                                            GError              **error);
 IDE_AVAILABLE_IN_3_32
-gboolean      ide_vcs_is_ignored         (IdeVcs               *self,
-                                          GFile                *file,
-                                          GError              **error);
+gint          ide_vcs_get_priority         (IdeVcs               *self);
 IDE_AVAILABLE_IN_3_32
-gboolean      ide_vcs_path_is_ignored    (IdeVcs               *self,
-                                          const gchar          *path,
-                                          GError              **error);
+void          ide_vcs_emit_changed         (IdeVcs               *self);
 IDE_AVAILABLE_IN_3_32
-gint          ide_vcs_get_priority       (IdeVcs               *self);
+IdeVcsConfig *ide_vcs_get_config           (IdeVcs               *self);
 IDE_AVAILABLE_IN_3_32
-void          ide_vcs_emit_changed       (IdeVcs               *self);
+gchar        *ide_vcs_get_branch_name      (IdeVcs               *self);
 IDE_AVAILABLE_IN_3_32
-IdeVcsConfig *ide_vcs_get_config         (IdeVcs               *self);
+void          ide_vcs_list_status_async    (IdeVcs               *self,
+                                            GFile                *directory_or_file,
+                                            gboolean              include_descendants,
+                                            gint                  io_priority,
+                                            GCancellable         *cancellable,
+                                            GAsyncReadyCallback   callback,
+                                            gpointer              user_data);
 IDE_AVAILABLE_IN_3_32
-gchar        *ide_vcs_get_branch_name    (IdeVcs               *self);
+GListModel   *ide_vcs_list_status_finish   (IdeVcs               *self,
+                                            GAsyncResult         *result,
+                                            GError              **error);
 IDE_AVAILABLE_IN_3_32
-void          ide_vcs_list_status_async  (IdeVcs               *self,
-                                          GFile                *directory_or_file,
-                                          gboolean              include_descendants,
-                                          gint                  io_priority,
-                                          GCancellable         *cancellable,
-                                          GAsyncReadyCallback   callback,
-                                          gpointer              user_data);
+void          ide_vcs_list_branches_async  (IdeVcs               *self,
+                                            GCancellable         *cancellable,
+                                            GAsyncReadyCallback   callback,
+                                            gpointer              user_data);
 IDE_AVAILABLE_IN_3_32
-GListModel   *ide_vcs_list_status_finish (IdeVcs               *self,
-                                          GAsyncResult         *result,
-                                          GError              **error);
+GPtrArray    *ide_vcs_list_branches_finish (IdeVcs               *self,
+                                            GAsyncResult         *result,
+                                            GError              **error);
 
 G_END_DECLS
diff --git a/src/libide/vcs/libide-vcs.h b/src/libide/vcs/libide-vcs.h
index bc6352468..de43ce6ad 100644
--- a/src/libide/vcs/libide-vcs.h
+++ b/src/libide/vcs/libide-vcs.h
@@ -26,6 +26,7 @@
 #define IDE_VCS_INSIDE
 
 #include "ide-directory-vcs.h"
+#include "ide-vcs-branch.h"
 #include "ide-vcs-cloner.h"
 #include "ide-vcs-config.h"
 #include "ide-vcs-enums.h"
diff --git a/src/libide/vcs/meson.build b/src/libide/vcs/meson.build
index 14beb6904..9cd80139d 100644
--- a/src/libide/vcs/meson.build
+++ b/src/libide/vcs/meson.build
@@ -8,6 +8,7 @@ libide_include_directories += include_directories('.')
 
 libide_vcs_public_headers = [
   'ide-directory-vcs.h',
+  'ide-vcs-branch.h',
   'ide-vcs-config.h',
   'ide-vcs-cloner.h',
   'ide-vcs-file-info.h',
@@ -31,6 +32,7 @@ install_headers(libide_vcs_public_headers, subdir: libide_vcs_header_subdir)
 
 libide_vcs_public_sources = [
   'ide-directory-vcs.c',
+  'ide-vcs-branch.c',
   'ide-vcs-config.c',
   'ide-vcs-cloner.c',
   'ide-vcs-file-info.c',


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