[gnome-builder/wip/chergert/git-oop] more incremental git work
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/git-oop] more incremental git work
- Date: Sat, 23 Mar 2019 05:34:35 +0000 (UTC)
commit 29fa4b8b5159f27c5f35e10b4940d98101deafc9
Author: Christian Hergert <chergert redhat com>
Date: Fri Mar 22 22:34:15 2019 -0700
more incremental git work
src/plugins/git/gbp-git-vcs.c | 66 +++++++++-----------
src/plugins/git/gnome-builder-git.c | 2 +
src/plugins/git/meson.build | 9 +++
src/plugins/git/test-git-client.c | 120 ++++++++++++++++++++++++++++++++++++
4 files changed, 159 insertions(+), 38 deletions(-)
---
diff --git a/src/plugins/git/gbp-git-vcs.c b/src/plugins/git/gbp-git-vcs.c
index ee9adf1ca..c7ff38be8 100644
--- a/src/plugins/git/gbp-git-vcs.c
+++ b/src/plugins/git/gbp-git-vcs.c
@@ -243,28 +243,7 @@ gbp_git_vcs_is_ignored (IdeVcs *vcs,
return FALSE;
}
-typedef struct
-{
- GFile *repository_location;
- GFile *directory_or_file;
- GFile *workdir;
- GListStore *store;
- guint recursive : 1;
-} ListStatus;
-
static void
-list_status_free (gpointer data)
-{
- ListStatus *ls = data;
-
- g_clear_object (&ls->repository_location);
- g_clear_object (&ls->directory_or_file);
- g_clear_object (&ls->workdir);
- g_clear_object (&ls->store);
- g_slice_free (ListStatus, ls);
-}
-
-static gint
gbp_git_vcs_list_status_cb (const gchar *path,
GgitStatusFlags flags,
gpointer user_data)
@@ -396,35 +375,46 @@ gbp_git_vcs_list_status_async (IdeVcs *vcs,
gpointer user_data)
{
GbpGitVcs *self = (GbpGitVcs *)vcs;
+ g_autoptr(IdeContext) context = NULL;
g_autoptr(IdeTask) task = NULL;
- ListStatus *state;
+ g_autoptr(GFile) workdir = NULL;
+ g_autofree gchar *path = NULL;
+ GbpGitClient *client;
IDE_ENTRY;
+ g_return_if_fail (IDE_IS_MAIN_THREAD ());
g_return_if_fail (GBP_IS_GIT_VCS (self));
g_return_if_fail (!directory_or_file || G_IS_FILE (directory_or_file));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
- ide_object_lock (IDE_OBJECT (self));
- state = g_slice_new0 (ListStatus);
- state->directory_or_file = g_object_ref (directory_or_file);
- state->repository_location = ggit_repository_get_location (self->repository);
- state->recursive = !!include_descendants;
- ide_object_unlock (IDE_OBJECT (self));
-
task = ide_task_new (self, cancellable, callback, user_data);
ide_task_set_source_tag (task, gbp_git_vcs_list_status_async);
ide_task_set_priority (task, io_priority);
- ide_task_set_return_on_cancel (task, TRUE);
- ide_task_set_task_data (task, state, list_status_free);
- if (state->repository_location == 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_status_worker);
+ context = ide_object_ref_context (IDE_OBJECT (self));
+ client = gbp_git_client_from_context (context);
+ workdir = ide_context_ref_workdir (context);
+
+ if (!g_file_equal (directory_or_file, workdir) &&
+ !g_file_has_prefix (directory_or_file, workdir))
+ {
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_NOT_SUPPORTED,
+ "Status is not supported on this file");
+ IDE_EXIT;
+ }
+
+ if (!(path = g_file_get_relative_path (workdir, directory_or_file)))
+ path = g_strdup (".");
+
+ gbp_git_client_list_status_async (client,
+ path,
+ include_descendants,
+ cancellable,
+ gbp_git_vcs_list_status_cb,
+ g_steal_pointer (&task));
IDE_EXIT;
}
diff --git a/src/plugins/git/gnome-builder-git.c b/src/plugins/git/gnome-builder-git.c
index d72b9712f..8560af880 100644
--- a/src/plugins/git/gnome-builder-git.c
+++ b/src/plugins/git/gnome-builder-git.c
@@ -1103,6 +1103,8 @@ main (gint argc,
/* redirect logging to stderr */
g_log_set_handler (NULL, G_LOG_LEVEL_MASK, log_handler_cb, NULL);
+ ggit_init ();
+
main_loop = g_main_loop_new (NULL, FALSE);
git = gbp_git_new ();
server = jsonrpc_server_new ();
diff --git a/src/plugins/git/meson.build b/src/plugins/git/meson.build
index 179616672..5bcab0148 100644
--- a/src/plugins/git/meson.build
+++ b/src/plugins/git/meson.build
@@ -61,4 +61,13 @@ test_line_cache = executable('test-line-cache', ['test-line-cache.c', 'line-cach
)
test('test-line-cache', test_line_cache)
+test_git_client = executable('test-git-client',
+ ['test-git-client.c', 'gbp-git-client.c', 'line-cache.c'],
+ dependencies: [libgio_dep, libide_vcs_dep, libjsonrpc_glib_dep],
+ gui_app: false,
+ install: false,
+ c_args: exe_c_args,
+ link_args: exe_link_args,
+)
+
endif
diff --git a/src/plugins/git/test-git-client.c b/src/plugins/git/test-git-client.c
new file mode 100644
index 000000000..d010c84d9
--- /dev/null
+++ b/src/plugins/git/test-git-client.c
@@ -0,0 +1,120 @@
+/* test-git-client.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 "test-git-client"
+
+#include "config.h"
+
+#include <libide-core.h>
+#include <libide-vcs.h>
+#include <stdlib.h>
+
+#include "gbp-git-client.h"
+
+static GMainLoop *main_loop;
+
+static void
+discover_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GbpGitClient *client = (GbpGitClient *)object;
+ g_autoptr(GFile) file = user_data;
+ g_autoptr(GFile) meson_build = user_data;
+ g_autoptr(GError) error = NULL;
+ gboolean r;
+
+ g_assert (GBP_IS_GIT_CLIENT (client));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (G_IS_FILE (file));
+
+ r = gbp_git_client_create_repo_finish (client, result, &error);
+ g_assert_no_error (error);
+ g_assert_true (r);
+
+ meson_build = g_file_get_child (file, "meson.build");
+
+ gbp_git_client_discover_async (self,
+ meson_build,
+ NULL,
+ discover_cb,
+ g_object_ref (file));
+
+ g_main_loop_quit (main_loop);
+}
+
+static void
+create_repo_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GbpGitClient *client = (GbpGitClient *)object;
+ g_autoptr(GFile) file = user_data;
+ g_autoptr(GFile) meson_build = user_data;
+ g_autoptr(GError) error = NULL;
+ gboolean r;
+
+ g_assert (GBP_IS_GIT_CLIENT (client));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (G_IS_FILE (file));
+
+ r = gbp_git_client_create_repo_finish (client, result, &error);
+ g_assert_no_error (error);
+ g_assert_true (r);
+
+ meson_build = g_file_get_child (file, "meson.build");
+
+ gbp_git_client_discover_async (self,
+ meson_build,
+ NULL,
+ discover_cb,
+ g_object_ref (file));
+}
+
+gint
+main (gint argc,
+ gchar *argv[])
+{
+ g_autoptr(IdeContext) context = NULL;
+ g_autoptr(GFile) here = g_file_new_for_path (".");
+ g_autoptr(GFile) file = NULL;
+ g_autofree gchar *tmpdir = g_strdup ("test-git-client-XXXXXX");
+ GbpGitClient *client;
+
+ g_mkdtemp (tmpdir);
+ g_print ("Tmpdir: %s\n", tmpdir);
+ file = g_file_new_for_path (tmpdir);
+
+ main_loop = g_main_loop_new (NULL, FALSE);
+ context = ide_context_new ();
+ ide_context_set_workdir (context, here);
+ client = gbp_git_client_from_context (context);
+
+ gbp_git_client_create_repo_async (client,
+ file,
+ FALSE,
+ NULL,
+ create_repo_cb,
+ g_object_ref (file));
+
+ g_main_loop_run (main_loop);
+
+ return EXIT_SUCCESS;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]