[libgit2-glib] Remote GgitPushProgress



commit e2a578e8da08ada2d0a069199dc7754aaa05bdf8
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Thu Dec 25 13:28:46 2014 +0100

    Remote GgitPushProgress
    
    Instead, provide signals on GgitPush to notify about
    progress.

 libgit2-glib/Makefile.am          |    2 -
 libgit2-glib/ggit-push-progress.c |   82 --------------------
 libgit2-glib/ggit-push-progress.h |   80 --------------------
 libgit2-glib/ggit-push.c          |  147 ++++++++++++++++++-------------------
 libgit2-glib/ggit-push.h          |   14 +++-
 5 files changed, 82 insertions(+), 243 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index 194e4ae..3718720 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -56,7 +56,6 @@ H_FILES =                                     \
        ggit-oid.h                              \
        ggit-patch.h                            \
        ggit-push.h                             \
-       ggit-push-progress.h                    \
        ggit-ref.h                              \
        ggit-ref-spec.h                         \
        ggit-reflog.h                           \
@@ -120,7 +119,6 @@ C_FILES =                                   \
        ggit-oid.c                              \
        ggit-patch.c                            \
        ggit-push.c                             \
-       ggit-push-progress.c                    \
        ggit-ref.c                              \
        ggit-ref-spec.c                         \
        ggit-reflog.c                           \
diff --git a/libgit2-glib/ggit-push.c b/libgit2-glib/ggit-push.c
index e07693c..e1770aa 100644
--- a/libgit2-glib/ggit-push.c
+++ b/libgit2-glib/ggit-push.c
@@ -22,9 +22,10 @@
 #include <git2.h>
 
 #include "ggit-push.h"
+#include "ggit-remote.h"
+#include "ggit-enum-types.h"
 #include "ggit-error.h"
 
-
 #define GGIT_PUSH_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GGIT_TYPE_PUSH, GgitPushPrivate))
 
 struct _GgitPushPrivate
@@ -38,6 +39,15 @@ enum
        PROP_REMOTE
 };
 
+enum
+{
+       TRANSFER_PROGRESS,
+       PACKBUILDER_PROGRESS,
+       NUM_SIGNALS
+};
+
+static guint signals[NUM_SIGNALS] = {0,};
+
 static void ggit_push_initable_iface_init (GInitableIface *iface);
 
 G_DEFINE_TYPE_EXTENDED (GgitPush, ggit_push, GGIT_TYPE_NATIVE,
@@ -113,6 +123,32 @@ ggit_push_class_init (GgitPushClass *klass)
                                                              G_PARAM_READWRITE |
                                                              G_PARAM_CONSTRUCT_ONLY));
 
+       signals[TRANSFER_PROGRESS] =
+               g_signal_new ("transfer-progress",
+                             G_TYPE_FROM_CLASS (object_class),
+                             G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET (GgitPushClass, transfer_progress),
+                             NULL, NULL,
+                             NULL,
+                             G_TYPE_NONE,
+                             3,
+                             G_TYPE_UINT,
+                             G_TYPE_UINT,
+                             G_TYPE_UINT);
+
+       signals[PACKBUILDER_PROGRESS] =
+               g_signal_new ("packbuilder-progress",
+                             G_TYPE_FROM_CLASS (object_class),
+                             G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET (GgitPushClass, packbuilder_progress),
+                             NULL, NULL,
+                             NULL,
+                             G_TYPE_NONE,
+                             3,
+                             GGIT_TYPE_PACKBUILDER_STAGE,
+                             G_TYPE_UINT,
+                             G_TYPE_UINT);
+
        g_type_class_add_private (object_class, sizeof (GgitPushPrivate));
 }
 
@@ -122,6 +158,26 @@ ggit_push_init (GgitPush *push)
        push->priv = GGIT_PUSH_GET_PRIVATE (push);
 }
 
+static gint
+packbuilder_progress_wrapper (gint     stage,
+                              guint    current,
+                              guint    total,
+                              gpointer payload)
+{
+       g_signal_emit (payload, signals[PACKBUILDER_PROGRESS], 0, stage, current, total);
+       return GIT_OK;
+}
+
+static gint
+transfer_progress_wrapper (guint    current,
+                           guint    total,
+                           gsize    bytes,
+                           gpointer payload)
+{
+       g_signal_emit (payload, signals[TRANSFER_PROGRESS], 0, current, total, bytes);
+       return GIT_OK;
+}
+
 static gboolean
 ggit_push_initable_init (GInitable    *initable,
                          GCancellable *cancellable,
@@ -151,6 +207,12 @@ ggit_push_initable_init (GInitable    *initable,
                          push,
                          (GDestroyNotify)git_push_free);
 
+       git_push_set_callbacks (push,
+                               packbuilder_progress_wrapper,
+                               initable,
+                               transfer_progress_wrapper,
+                               initable);
+
        return TRUE;
 }
 
@@ -209,97 +271,30 @@ ggit_push_add_refspec (GgitPush     *push,
        }
 }
 
-typedef struct
-{
-       GgitPushProgress  *progress;
-       GError           **error;
-} PushProgressInfo;
-
-static gint
-packbuilder_progress_wrapper (gint     stage,
-                              guint    current,
-                              guint    total,
-                              gpointer payload)
-{
-       PushProgressInfo *info;
-       info = payload;
-
-       if (!ggit_push_progress_packbuilder_progress (info->progress,
-                                                     stage,
-                                                     current,
-                                                     total,
-                                                     info->error))
-       {
-               return GIT_ERROR;
-       }
-
-       return GIT_OK;
-}
-
-static gint
-transfer_progress_wrapper (guint    current,
-                           guint    total,
-                           gsize    bytes,
-                           gpointer payload)
-{
-       PushProgressInfo *info;
-       info = payload;
-
-       if (!ggit_push_progress_transfer_progress (info->progress,
-                                                  current,
-                                                  total,
-                                                  bytes,
-                                                  info->error))
-       {
-               return GIT_ERROR;
-       }
-
-       return GIT_OK;
-}
-
 /**
  * ggit_push_finish:
  * @push: a #GgitPush.
- * @progress: (allow-none): a #GgitPushProgress, or %NULL.
  * @error: a #GError for error reporting, or %NULL.
  *
- * Actually push all given refspecs.
+ * Actually push all the refspecs added to the push object.
  */
 gboolean
-ggit_push_finish (GgitPush          *push,
-                  GgitPushProgress  *progress,
-                  GError           **error)
+ggit_push_finish (GgitPush  *push,
+                  GError   **error)
 {
        gint ret;
 
-       PushProgressInfo info = {0,};
-
        g_return_val_if_fail (GGIT_IS_PUSH (push), FALSE);
        g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-       info.progress = progress;
-       info.error = error;
-
-       if (progress != NULL)
-       {
-               git_push_set_callbacks (_ggit_native_get (push),
-                                       packbuilder_progress_wrapper,
-                                       &info,
-                                       transfer_progress_wrapper,
-                                       &info);
-       }
+       /* Options might have changed externally, need to make sure to set
+        * them again.
+        */
+       git_push_set_options (_ggit_native_get (push),
+                             _ggit_push_options_get_push_options (push->priv->options));
 
        ret = git_push_finish (_ggit_native_get (push));
 
-       if (progress != NULL)
-       {
-               git_push_set_callbacks (_ggit_native_get (push),
-                                       NULL,
-                                       NULL,
-                                       NULL,
-                                       NULL);
-       }
-
        if (ret != GIT_OK)
        {
                if (error && *error == NULL)
diff --git a/libgit2-glib/ggit-push.h b/libgit2-glib/ggit-push.h
index 9c295dc..24ebeda 100644
--- a/libgit2-glib/ggit-push.h
+++ b/libgit2-glib/ggit-push.h
@@ -24,8 +24,6 @@
 
 #include <libgit2-glib/ggit-native.h>
 #include <libgit2-glib/ggit-types.h>
-#include <libgit2-glib/ggit-remote.h>
-#include <libgit2-glib/ggit-push-progress.h>
 
 G_BEGIN_DECLS
 
@@ -52,6 +50,17 @@ struct _GgitPushClass
 {
        /*< private >*/
        GgitNativeClass parent_class;
+
+       /*< signals >*/
+       void (*packbuilder_progress) (GgitPush              *push,
+                                     GgitPackbuilderStage   stage,
+                                     guint                  current,
+                                     guint                  total);
+
+       void (*transfer_progress)    (GgitPush              *push,
+                                     guint                  current,
+                                     guint                  total,
+                                     gsize                  bytes);
 };
 
 GType             ggit_push_get_type                       (void) G_GNUC_CONST;
@@ -64,7 +73,6 @@ void              ggit_push_add_refspec                    (GgitPush          *p
                                                             GError           **error);
 
 gboolean          ggit_push_finish                         (GgitPush          *push,
-                                                            GgitPushProgress  *progress,
                                                             GError           **error);
 
 gboolean          ggit_push_is_unpack_ok                   (GgitPush          *push);


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