[gnome-builder/wip/chergert/git-oop] add client API to get line changes
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/git-oop] add client API to get line changes
- Date: Fri, 22 Mar 2019 01:35:21 +0000 (UTC)
commit e41ebc369c6b17effde169a92cc59ab3e383f9e1
Author: Christian Hergert <chergert redhat com>
Date: Thu Mar 21 18:35:01 2019 -0700
add client API to get line changes
src/plugins/git/gbp-git-client.c | 76 ++++++++++++++++++++++++++++++++++++++++
src/plugins/git/gbp-git-client.h | 11 ++++++
2 files changed, 87 insertions(+)
---
diff --git a/src/plugins/git/gbp-git-client.c b/src/plugins/git/gbp-git-client.c
index 162ce57c5..991319495 100644
--- a/src/plugins/git/gbp-git-client.c
+++ b/src/plugins/git/gbp-git-client.c
@@ -1168,3 +1168,79 @@ gbp_git_client_discover_finish (GbpGitClient *self,
return FALSE;
}
+
+static void
+gbp_git_client_get_changes_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GbpGitClient *self = (GbpGitClient *)object;
+ g_autoptr(IdeTask) task = user_data;
+ g_autoptr(GVariant) reply = NULL;
+ g_autoptr(GError) error = NULL;
+ LineCache *cache;
+
+ g_assert (GBP_IS_GIT_CLIENT (self));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (IDE_IS_TASK (task));
+
+ if (!gbp_git_client_call_finish (self, result, &reply, &error))
+ {
+ ide_task_return_error (task, g_steal_pointer (&error));
+ return;
+ }
+
+ if (!(cache = line_cache_new_from_variant (reply)))
+ {
+ ide_task_return_new_error (task,
+ G_IO_ERROR,
+ G_IO_ERROR_INVALID_DATA,
+ "Invalid line-cache data from peer");
+ return;
+ }
+
+ ide_task_return_pointer (task, g_steal_pointer (&cache), line_cache_free);
+}
+
+void
+gbp_git_client_get_changes_async (GbpGitClient *self,
+ const gchar *path,
+ const gchar *contents,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_autoptr(IdeTask) task = NULL;
+ g_autoptr(GVariant) command = NULL;
+
+ g_assert (GBP_IS_GIT_CLIENT (self));
+ g_assert (path != NULL);
+ g_assert (contents != NULL);
+ g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, gbp_git_client_get_changes_async);
+
+ command = JSONRPC_MESSAGE_NEW (
+ "path", JSONRPC_MESSAGE_PUT_STRING (path),
+ "contents", JSONRPC_MESSAGE_PUT_STRING (contents)
+ );
+
+ gbp_git_client_call_async (self,
+ "git/getChanges",
+ command,
+ cancellable,
+ gbp_git_client_get_changes_cb,
+ g_steal_pointer (&task));
+}
+
+LineCache *
+gbp_git_client_get_changes_finish (GbpGitClient *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_return_val_if_fail (GBP_IS_GIT_CLIENT (self), NULL);
+ g_return_val_if_fail (IDE_IS_TASK (result), NULL);
+
+ return ide_task_propagate_pointer (IDE_TASK (result), error);
+}
diff --git a/src/plugins/git/gbp-git-client.h b/src/plugins/git/gbp-git-client.h
index 7a2b6504f..efc2d369f 100644
--- a/src/plugins/git/gbp-git-client.h
+++ b/src/plugins/git/gbp-git-client.h
@@ -22,6 +22,8 @@
#include <libide-core.h>
+#include "line-cache.h"
+
G_BEGIN_DECLS
#define GBP_TYPE_GIT_CLIENT (gbp_git_client_get_type())
@@ -140,5 +142,14 @@ gboolean gbp_git_client_discover_finish (GbpGitClient *sel
gchar **branch,
gboolean *is_worktree,
GError **error);
+void gbp_git_client_get_changes_async (GbpGitClient *self,
+ const gchar *path,
+ const gchar *contents,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+LineCache *gbp_git_client_get_changes_finish (GbpGitClient *self,
+ GAsyncResult *result,
+ GError **error);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]