[libgit2-glib] Added GgitPushProgress interface



commit c8879495ab21b07e39ebecc09c9cddb109e50fad
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Mon Jan 20 15:33:51 2014 +0100

    Added GgitPushProgress interface

 libgit2-glib/Makefile.am          |    2 +
 libgit2-glib/ggit-push-progress.c |   78 ++++++++++++++++++++++++++++++++
 libgit2-glib/ggit-push-progress.h |   80 +++++++++++++++++++++++++++++++++
 libgit2-glib/ggit-push.c          |   88 +++++++++++++++++++++++++++++++++++--
 libgit2-glib/ggit-push.h          |   18 ++++---
 libgit2-glib/ggit-types.c         |    3 +
 libgit2-glib/ggit-types.h         |   13 +++++
 7 files changed, 270 insertions(+), 12 deletions(-)
---
diff --git a/libgit2-glib/Makefile.am b/libgit2-glib/Makefile.am
index b85d497..c6c8e7a 100644
--- a/libgit2-glib/Makefile.am
+++ b/libgit2-glib/Makefile.am
@@ -51,6 +51,7 @@ INST_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                   \
@@ -109,6 +110,7 @@ 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-progress.c b/libgit2-glib/ggit-push-progress.c
new file mode 100644
index 0000000..48c52af
--- /dev/null
+++ b/libgit2-glib/ggit-push-progress.c
@@ -0,0 +1,78 @@
+/*
+ * ggit-push-progress.c
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2014 - Jesse van den Kieboom
+ *
+ * libgit2-glib is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ggit-push-progress.h"
+
+G_DEFINE_INTERFACE (GgitPushProgress, ggit_push_progress, G_TYPE_OBJECT)
+
+void
+ggit_push_progress_default_init (GgitPushProgressInterface *iface)
+{
+}
+
+gboolean
+ggit_push_progress_packbuilder_progress (GgitPushProgress      *push_progress,
+                                         GgitPackbuilderStage   stage,
+                                         guint                  current,
+                                         guint                  total,
+                                         GError               **error)
+{
+       GgitPushProgressInterface *iface;
+
+       g_return_val_if_fail (GGIT_IS_PUSH_PROGRESS (push_progress), TRUE);
+       g_return_val_if_fail (error == NULL || *error == NULL, TRUE);
+
+       iface = GGIT_PUSH_PROGRESS_GET_IFACE (push_progress);
+
+       if (iface->packbuilder_progress != NULL)
+       {
+               return iface->packbuilder_progress (push_progress,
+                                                   stage,
+                                                   current,
+                                                   total,
+                                                   error);
+       }
+
+       return TRUE;
+}
+
+gboolean
+ggit_push_progress_transfer_progress (GgitPushProgress  *push_progress,
+                                      guint              current,
+                                      guint              total,
+                                      gsize              bytes,
+                                      GError           **error)
+{
+       GgitPushProgressInterface *iface;
+
+       g_return_val_if_fail (GGIT_IS_PUSH_PROGRESS (push_progress), TRUE);
+       g_return_val_if_fail (error == NULL || *error == NULL, TRUE);
+
+       iface = GGIT_PUSH_PROGRESS_GET_IFACE (push_progress);
+
+       if (iface->transfer_progress != NULL)
+       {
+               return iface->transfer_progress (push_progress, current, total, bytes, error);
+       }
+
+       return TRUE;
+}
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-push-progress.h b/libgit2-glib/ggit-push-progress.h
new file mode 100644
index 0000000..f76291e
--- /dev/null
+++ b/libgit2-glib/ggit-push-progress.h
@@ -0,0 +1,80 @@
+/*
+ * ggit-push-progress.h
+ * This file is part of libgit2-glib
+ *
+ * Copyright (C) 2014 - Jesse van den Kieboom
+ *
+ * libgit2-glib is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * libgit2-glib 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GGIT_PUSH_PROGRESS_H__
+#define __GGIT_PUSH_PROGRESS_H__
+
+#include <glib-object.h>
+#include <libgit2-glib/ggit-types.h>
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define GGIT_TYPE_PUSH_PROGRESS                (ggit_push_progress_get_type ())
+#define GGIT_PUSH_PROGRESS(obj)                (G_TYPE_CHECK_INSTANCE_CAST ((obj), GGIT_TYPE_PUSH_PROGRESS, 
GgitPushProgress))
+#define GGIT_PUSH_PROGRESS_IFACE(obj)  (G_TYPE_CHECK_CLASS_CAST ((obj), GGIT_TYPE_PUSH_PROGRESS, 
GgitPushProgressInterface))
+#define GGIT_IS_PUSH_PROGRESS(obj)     (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GGIT_TYPE_PUSH_PROGRESS))
+#define GGIT_PUSH_PROGRESS_GET_IFACE(obj)      (G_TYPE_INSTANCE_GET_INTERFACE ((obj), 
GGIT_TYPE_PUSH_PROGRESS, GgitPushProgressInterface))
+
+typedef struct _GgitPushProgress           GgitPushProgress; /* dummy typedef */
+typedef struct _GgitPushProgressInterface  GgitPushProgressInterface;
+
+struct _GgitPushProgressInterface
+{
+       GTypeInterface g_iface;
+
+       /* Virtual public methods */
+       gboolean (*packbuilder_progress) (GgitPushProgress      *push_progress,
+                                         GgitPackbuilderStage   stage,
+                                         guint                  current,
+                                         guint                  total,
+                                         GError               **error);
+
+       gboolean (*transfer_progress)    (GgitPushProgress      *push_progress,
+                                         guint                  current,
+                                         guint                  total,
+                                         gsize                  bytes,
+                                         GError               **error);
+};
+
+/*
+ * Public methods
+ */
+GType   ggit_push_progress_get_type    (void)  G_GNUC_CONST;
+
+gboolean ggit_push_progress_packbuilder_progress (GgitPushProgress      *push_progress,
+                                                  GgitPackbuilderStage   stage,
+                                                  guint                  current,
+                                                  guint                  total,
+                                                  GError               **error);
+
+gboolean ggit_push_progress_transfer_progress    (GgitPushProgress      *push_progress,
+                                                  guint                  current,
+                                                  guint                  total,
+                                                  gsize                  bytes,
+                                                  GError               **error);
+
+G_END_DECLS
+
+#endif /* __GGIT_PUSH_PROGRESS_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-push.c b/libgit2-glib/ggit-push.c
index 263e93d..f702176 100644
--- a/libgit2-glib/ggit-push.c
+++ b/libgit2-glib/ggit-push.c
@@ -204,28 +204,108 @@ 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.
  */
-void
-ggit_push_finish (GgitPush  *push,
-                  GError   **error)
+gboolean
+ggit_push_finish (GgitPush          *push,
+                  GgitPushProgress  *progress,
+                  GError           **error)
 {
        gint ret;
 
+       PushProgressInfo info = {0,};
+
        g_return_if_fail (GGIT_IS_PUSH (push));
        g_return_if_fail (error == NULL || *error == NULL);
 
+       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);
+       }
+
        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)
        {
-               _ggit_error_set (error, ret);
+               if (error && *error == NULL)
+               {
+                       _ggit_error_set (error, ret);
+               }
+
+               return FALSE;
        }
+
+       return TRUE;
 }
 
 /**
diff --git a/libgit2-glib/ggit-push.h b/libgit2-glib/ggit-push.h
index d18981f..9c295dc 100644
--- a/libgit2-glib/ggit-push.h
+++ b/libgit2-glib/ggit-push.h
@@ -25,6 +25,7 @@
 #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
 
@@ -55,17 +56,18 @@ struct _GgitPushClass
 
 GType             ggit_push_get_type                       (void) G_GNUC_CONST;
 
-GgitPush         *ggit_push_new                            (GgitRemote   *remote,
-                                                            GError      **error);
+GgitPush         *ggit_push_new                            (GgitRemote        *remote,
+                                                            GError           **error);
 
-void              ggit_push_add_refspec                    (GgitPush     *push,
-                                                            const gchar  *refspec,
-                                                            GError      **error);
+void              ggit_push_add_refspec                    (GgitPush          *push,
+                                                            const gchar       *refspec,
+                                                            GError           **error);
 
-void              ggit_push_finish                         (GgitPush     *push,
-                                                            GError      **error);
+gboolean          ggit_push_finish                         (GgitPush          *push,
+                                                            GgitPushProgress  *progress,
+                                                            GError           **error);
 
-gboolean          ggit_push_is_unpack_ok                   (GgitPush     *push);
+gboolean          ggit_push_is_unpack_ok                   (GgitPush          *push);
 
 G_END_DECLS
 
diff --git a/libgit2-glib/ggit-types.c b/libgit2-glib/ggit-types.c
index 6041829..66158c8 100644
--- a/libgit2-glib/ggit-types.c
+++ b/libgit2-glib/ggit-types.c
@@ -214,4 +214,7 @@ ASSERT_ENUM (GGIT_ATTRIBUTE_CHECK_INDEX_THEN_FILE, GIT_ATTR_CHECK_INDEX_THEN_FIL
 ASSERT_ENUM (GGIT_ATTRIBUTE_CHECK_INDEX_ONLY,      GIT_ATTR_CHECK_INDEX_ONLY);
 ASSERT_ENUM (GGIT_ATTRIBUTE_CHECK_NO_SYSTEM,       GIT_ATTR_CHECK_NO_SYSTEM);
 
+ASSERT_ENUM (GGIT_PACKBUILDER_STAGE_ADDING_OBJECTS, GIT_PACKBUILDER_ADDING_OBJECTS);
+ASSERT_ENUM (GGIT_PACKBUILDER_STAGE_DELTAFICATION, GIT_PACKBUILDER_DELTAFICATION);
+
 /* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index f424012..66e6247 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -933,6 +933,19 @@ typedef enum
 } GgitAttributeCheckFlags;
 
 /**
+ * GgitPackbuilderStage:
+ * @GGIT_PACKBUILDER_STAGE_ADDING_OBJECTS: adding objects.
+ * @GGIT_PACKBUILDER_STAGE_DELTAFICATION: deltafication.
+ *
+ * Valid stages for pack building.
+ */
+typedef enum
+{
+       GGIT_PACKBUILDER_STAGE_ADDING_OBJECTS = 0,
+       GGIT_PACKBUILDER_STAGE_DELTAFICATION  = 1
+} GgitPackbuilderStage;
+
+/**
  * GgitConfigCallback:
  * @entry: a #GgitConfigEntry.
  * @user_data: (closure): user-supplied data.


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