[libgit2-glib] Add push operation
- From: Alberto Fanjul <albfan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgit2-glib] Add push operation
- Date: Wed, 13 Mar 2019 21:12:45 +0000 (UTC)
commit 08dc475ed1fada75f64df51a12a19ab3f240d1a5
Author: Alan Knowles <alan roojs com>
Date: Wed Mar 13 19:21:55 2019 +0800
Add push operation
- Added ggit_remote_upload to push
- Added callbacks to inform user about progress pushing
libgit2-glib/ggit-push-options.c | 69 ++++++++++++++++++++++++++++++++++++++--
libgit2-glib/ggit-push-options.h | 4 +++
libgit2-glib/ggit-remote.c | 38 ++++++++++++++++++++++
libgit2-glib/ggit-remote.h | 6 ++++
libgit2-glib/ggit-repository.c | 2 +-
5 files changed, 116 insertions(+), 3 deletions(-)
---
diff --git a/libgit2-glib/ggit-push-options.c b/libgit2-glib/ggit-push-options.c
index f334834..c40d8d5 100644
--- a/libgit2-glib/ggit-push-options.c
+++ b/libgit2-glib/ggit-push-options.c
@@ -28,7 +28,8 @@
typedef struct _GgitPushOptionsPrivate
{
- git_push_options options;
+ git_push_options options;
+ GgitRemoteCallbacks *callbacks;
} GgitPushOptionsPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (GgitPushOptions, ggit_push_options, G_TYPE_OBJECT)
@@ -36,7 +37,8 @@ G_DEFINE_TYPE_WITH_PRIVATE (GgitPushOptions, ggit_push_options, G_TYPE_OBJECT)
enum
{
PROP_0,
- PROP_PARALLELISM
+ PROP_PARALLELISM,
+ PROP_CALLBACKS
};
static void
@@ -55,6 +57,10 @@ ggit_push_options_set_property (GObject *object,
case PROP_PARALLELISM:
priv->options.pb_parallelism = g_value_get_int (value);
break;
+ case PROP_CALLBACKS:
+ ggit_push_options_set_callbacks(options,
+ g_value_get_object (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -77,6 +83,9 @@ ggit_push_options_get_property (GObject *object,
case PROP_PARALLELISM:
g_value_set_int (value, priv->options.pb_parallelism);
break;
+ case PROP_CALLBACKS:
+ g_value_set_object (value, priv->callbacks);
+ break;
}
}
@@ -100,6 +109,15 @@ ggit_push_options_class_init (GgitPushOptionsClass *klass)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
+ PROP_CALLBACKS,
+ g_param_spec_object ("callbacks",
+ "Callbacks",
+ "Callbacks",
+ GGIT_TYPE_REMOTE_CALLBACKS,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
}
static void
@@ -191,4 +209,51 @@ ggit_push_options_set_parallelism (GgitPushOptions *options,
g_object_notify (G_OBJECT (options), "parallelism");
}
+/**
+ * ggit_push_options_set_callbacks:
+ * @options: a #GgitPushOptions.
+ * @callbacks: the #GgitRemoteCallbacks
+ *
+ * Set the remote callbacks for the push options
+ *
+ **/
+void
+ggit_push_options_set_callbacks (GgitPushOptions *options,
+ GgitRemoteCallbacks *callbacks)
+{
+ GgitPushOptionsPrivate *priv;
+
+ g_return_if_fail (GGIT_IS_PUSH_OPTIONS (options));
+ g_return_if_fail (callbacks != NULL || GGIT_IS_REMOTE_CALLBACKS (callbacks));
+
+
+ priv = ggit_push_options_get_instance_private (options);
+
+ priv->callbacks = g_object_ref (callbacks);
+ priv->options.callbacks = *_ggit_remote_callbacks_get_native (priv->callbacks);
+
+ g_object_notify (G_OBJECT (options), "callbacks");
+}
+
+/**
+ * ggit_push_options_get_callbacks:
+ * @options: a #GgitPushOptions.
+ *
+ * gets the remote callbacks object
+ *
+ * Returns: (transfer none) (nullable): the object's id or %NULL.
+ *
+ **/
+GgitRemoteCallbacks*
+ggit_push_options_get_callbacks (GgitPushOptions *options)
+{
+ GgitPushOptionsPrivate *priv;
+
+ g_return_val_if_fail (GGIT_IS_PUSH_OPTIONS (options), 0);
+
+ priv = ggit_push_options_get_instance_private (options);
+
+ return priv->callbacks;
+}
+
/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-push-options.h b/libgit2-glib/ggit-push-options.h
index 3e616b9..9bd9d72 100644
--- a/libgit2-glib/ggit-push-options.h
+++ b/libgit2-glib/ggit-push-options.h
@@ -23,6 +23,7 @@
#include <glib-object.h>
#include <git2.h>
+#include <libgit2-glib/ggit-remote-callbacks.h>
#include "ggit-types.h"
@@ -46,6 +47,9 @@ gint ggit_push_options_get_parallelism (GgitPushOptions *optio
void ggit_push_options_set_parallelism (GgitPushOptions *options,
gint parallelism);
+GgitRemoteCallbacks * ggit_push_options_get_callbacks (GgitPushOptions *options);
+void ggit_push_options_set_callbacks (GgitPushOptions *options,
+ GgitRemoteCallbacks *callbacks);
G_END_DECLS
diff --git a/libgit2-glib/ggit-remote.c b/libgit2-glib/ggit-remote.c
index a392d6c..d6565f0 100644
--- a/libgit2-glib/ggit-remote.c
+++ b/libgit2-glib/ggit-remote.c
@@ -29,6 +29,7 @@
#include "ggit-signature.h"
#include "ggit-transfer-progress.h"
#include "ggit-fetch-options.h"
+#include "ggit-push-options.h"
struct _GgitRemoteHead
{
@@ -547,4 +548,41 @@ ggit_remote_list (GgitRemote *remote,
return retval;
}
+/**
+ * ggit_remote_upload:
+ * @remote: a #GgitRemote.
+ * @specs: (array zero-terminated=1) (allow-none): the ref specs.
+ * @push_options: a #GgitPushOptions
+ * @error: a #GError for error reporting, or %NULL.
+ *
+ * Create a packfile and send it to the server
+ *
+ * Returns: %TRUE if successful, %FALSE otherwise.
+ */
+gboolean
+ggit_remote_upload (GgitRemote *remote,
+ const gchar * const *specs,
+ GgitPushOptions *push_options,
+ GError **error)
+{
+ gint ret;
+ git_strarray gspecs;
+
+ g_return_val_if_fail (GGIT_IS_REMOTE (remote), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ ggit_utils_get_git_strarray_from_str_array (specs, &gspecs);
+
+ ret = git_remote_upload (_ggit_native_get (remote), &gspecs,
+ _ggit_push_options_get_push_options (push_options));
+
+ if (ret != GIT_OK)
+ {
+ _ggit_error_set (error, ret);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-remote.h b/libgit2-glib/ggit-remote.h
index 5e47dba..e1f3138 100644
--- a/libgit2-glib/ggit-remote.h
+++ b/libgit2-glib/ggit-remote.h
@@ -28,6 +28,7 @@
#include <libgit2-glib/ggit-native.h>
#include <libgit2-glib/ggit-remote-callbacks.h>
#include <libgit2-glib/ggit-proxy-options.h>
+#include <libgit2-glib/ggit-push-options.h>
G_BEGIN_DECLS
@@ -104,6 +105,11 @@ gchar **ggit_remote_get_push_specs (GgitRemote *remot
GgitRemoteHead **ggit_remote_list (GgitRemote *remote,
GError **error);
+gboolean ggit_remote_upload (GgitRemote *remote,
+ const gchar * const *specs,
+ GgitPushOptions *push_options,
+ GError **error);
+
G_END_DECLS
#endif /* __GGIT_REMOTE_H__ */
diff --git a/libgit2-glib/ggit-repository.c b/libgit2-glib/ggit-repository.c
index 722ab18..1cdffad 100644
--- a/libgit2-glib/ggit-repository.c
+++ b/libgit2-glib/ggit-repository.c
@@ -2219,7 +2219,7 @@ ggit_repository_add_remote_push (GgitRepository *repository,
g_return_if_fail (error == NULL || *error == NULL);
ret = git_remote_add_push (_ggit_native_get (repository),
- _ggit_native_get (remote),
+ ggit_remote_get_name (remote),
refspec);
if (ret != GIT_OK)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]