[gnome-builder] git: implement list_tags for git vcs backend
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] git: implement list_tags for git vcs backend
- Date: Mon, 28 Jan 2019 04:00:12 +0000 (UTC)
commit 8bc248ed787ccd54fd010454495ce53adce873c9
Author: Christian Hergert <chergert redhat com>
Date: Sun Jan 27 19:59:02 2019 -0800
git: implement list_tags for git vcs backend
src/plugins/git/gbp-git-tag.c | 82 +++++++++++++++++++++++++++++++++
src/plugins/git/gbp-git-tag.h | 33 +++++++++++++
src/plugins/git/gbp-git-vcs.c | 105 ++++++++++++++++++++++++++++++++++++++++++
src/plugins/git/meson.build | 1 +
4 files changed, 221 insertions(+)
---
diff --git a/src/plugins/git/gbp-git-tag.c b/src/plugins/git/gbp-git-tag.c
new file mode 100644
index 000000000..5391f2db8
--- /dev/null
+++ b/src/plugins/git/gbp-git-tag.c
@@ -0,0 +1,82 @@
+/* gbp-git-tag.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 "gbp-git-tag"
+
+#include "config.h"
+
+#include <libide-vcs.h>
+
+#include "gbp-git-tag.h"
+
+struct _GbpGitTag
+{
+ GObject parent_instance;
+ gchar *name;
+};
+
+static gchar *
+gbp_git_tag_get_name (IdeVcsTag *tag)
+{
+ return g_strdup (GBP_GIT_TAG (tag)->name);
+}
+
+static void
+vcs_tag_iface_init (IdeVcsTagInterface *iface)
+{
+ iface->get_name = gbp_git_tag_get_name;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpGitTag, gbp_git_tag, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (IDE_TYPE_VCS_TAG, vcs_tag_iface_init))
+
+static void
+gbp_git_tag_finalize (GObject *object)
+{
+ GbpGitTag *self = (GbpGitTag *)object;
+
+ g_clear_pointer (&self->name, g_free);
+
+ G_OBJECT_CLASS (gbp_git_tag_parent_class)->finalize (object);
+}
+
+static void
+gbp_git_tag_class_init (GbpGitTagClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gbp_git_tag_finalize;
+}
+
+static void
+gbp_git_tag_init (GbpGitTag *self)
+{
+}
+
+GbpGitTag *
+gbp_git_tag_new (const gchar *name)
+{
+ GbpGitTag *self;
+
+ self = g_object_new (GBP_TYPE_GIT_TAG, NULL);
+ self->name = g_strdup (name);
+
+ return g_steal_pointer (&self);
+}
diff --git a/src/plugins/git/gbp-git-tag.h b/src/plugins/git/gbp-git-tag.h
new file mode 100644
index 000000000..870b36688
--- /dev/null
+++ b/src/plugins/git/gbp-git-tag.h
@@ -0,0 +1,33 @@
+/* gbp-git-tag.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 <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_GIT_TAG (gbp_git_tag_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpGitTag, gbp_git_tag, GBP, GIT_TAG, GObject)
+
+GbpGitTag *gbp_git_tag_new (const gchar *name);
+
+G_END_DECLS
diff --git a/src/plugins/git/gbp-git-vcs.c b/src/plugins/git/gbp-git-vcs.c
index 5c0e7f92b..2627a8117 100644
--- a/src/plugins/git/gbp-git-vcs.c
+++ b/src/plugins/git/gbp-git-vcs.c
@@ -22,7 +22,10 @@
#include "config.h"
+#include <stdlib.h>
+
#include "gbp-git-branch.h"
+#include "gbp-git-tag.h"
#include "gbp-git-vcs.h"
#include "gbp-git-vcs-config.h"
@@ -543,6 +546,106 @@ gbp_git_vcs_list_branches_finish (IdeVcs *vcs,
return ide_task_propagate_pointer (IDE_TASK (result), error);
}
+static gint
+compare_tags (gconstpointer a,
+ gconstpointer b)
+{
+ return g_utf8_collate (*(const gchar **)a, *(const gchar **)b);
+}
+
+static void
+gbp_git_vcs_list_tags_worker (IdeTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
+{
+ GbpGitVcs *self = source_object;
+ g_autoptr(GPtrArray) tags = NULL;
+
+ g_assert (IDE_IS_TASK (task));
+ g_assert (GBP_IS_GIT_VCS (self));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ tags = g_ptr_array_new_with_free_func (g_object_unref);
+
+ ide_object_lock (IDE_OBJECT (self));
+
+ if (self->repository != NULL)
+ {
+ g_autoptr(GgitBranchEnumerator) enumerator = NULL;
+ g_auto(GStrv) names = NULL;
+ g_autoptr(GError) error = NULL;
+
+ if (!(names = ggit_repository_list_tags (self->repository, &error)))
+ {
+ ide_task_return_error (task, g_steal_pointer (&error));
+ goto unlock;
+ }
+
+ qsort (names, g_strv_length (names), sizeof (gchar *), compare_tags);
+
+ for (guint i = 0; names[i] != NULL; i++)
+ g_ptr_array_add (tags, gbp_git_tag_new (names[i]));
+
+ ide_task_return_pointer (task,
+ g_steal_pointer (&tags),
+ (GDestroyNotify)g_ptr_array_unref);
+ }
+ else
+ {
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_FAILED,
+ "No repository to access");
+ }
+
+unlock:
+ ide_object_unlock (IDE_OBJECT (self));
+}
+
+static void
+gbp_git_vcs_list_tags_async (IdeVcs *vcs,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GbpGitVcs *self = (GbpGitVcs *)vcs;
+ g_autoptr(IdeTask) task = NULL;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ g_assert (GBP_IS_GIT_VCS (self));
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, gbp_git_vcs_list_status_async);
+ ide_task_set_return_on_cancel (task, TRUE);
+
+ ide_object_lock (IDE_OBJECT (self));
+ if (self->repository == NULL)
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_FAILED,
+ "No repository loaded");
+ else
+ ide_task_run_in_thread (task, gbp_git_vcs_list_tags_worker);
+ ide_object_unlock (IDE_OBJECT (self));
+
+ IDE_EXIT;
+}
+
+static GPtrArray *
+gbp_git_vcs_list_tags_finish (IdeVcs *vcs,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (GBP_IS_GIT_VCS (vcs), NULL);
+ g_return_val_if_fail (IDE_IS_TASK (result), NULL);
+
+ return ide_task_propagate_pointer (IDE_TASK (result), error);
+}
+
static void
gbp_git_vcs_switch_branch_worker (IdeTask *task,
gpointer source_object,
@@ -652,6 +755,8 @@ vcs_iface_init (IdeVcsInterface *iface)
iface->list_status_finish = gbp_git_vcs_list_status_finish;
iface->list_branches_async = gbp_git_vcs_list_branches_async;
iface->list_branches_finish = gbp_git_vcs_list_branches_finish;
+ iface->list_tags_async = gbp_git_vcs_list_tags_async;
+ iface->list_tags_finish = gbp_git_vcs_list_tags_finish;
iface->switch_branch_async = gbp_git_vcs_switch_branch_async;
iface->switch_branch_finish = gbp_git_vcs_switch_branch_finish;
}
diff --git a/src/plugins/git/meson.build b/src/plugins/git/meson.build
index 1cd512e99..79dc08181 100644
--- a/src/plugins/git/meson.build
+++ b/src/plugins/git/meson.build
@@ -10,6 +10,7 @@ plugins_sources += files([
'gbp-git-pipeline-addin.c',
'gbp-git-remote-callbacks.c',
'gbp-git-submodule-stage.c',
+ 'gbp-git-tag.c',
'gbp-git-vcs.c',
'gbp-git-vcs-cloner.c',
'gbp-git-vcs-config.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]