[gnome-builder] git: allow notifying git callbacks they have been cancelled



commit f5c761c7222650bd535fbb5298eadd4e462127b0
Author: Christian Hergert <chergert redhat com>
Date:   Sun Mar 12 22:04:52 2017 -0700

    git: allow notifying git callbacks they have been cancelled
    
    We still don't have a way to make the clone to truely stop using the
    ggit_repository_clone() API, but this will allow us to stop sending update
    property notifications
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779933

 plugins/git/ide-git-remote-callbacks.c |   31 +++++++++++++++++++++++++++++++
 plugins/git/ide-git-remote-callbacks.h |    1 +
 2 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/plugins/git/ide-git-remote-callbacks.c b/plugins/git/ide-git-remote-callbacks.c
index e611178..f570fd6 100644
--- a/plugins/git/ide-git-remote-callbacks.c
+++ b/plugins/git/ide-git-remote-callbacks.c
@@ -34,6 +34,7 @@ struct _IdeGitRemoteCallbacks
   IdeProgress         *progress;
   gdouble              fraction;
   GgitCredtype         tried;
+  guint                cancelled : 1;
 };
 
 G_DEFINE_TYPE (IdeGitRemoteCallbacks, ide_git_remote_callbacks, GGIT_TYPE_REMOTE_CALLBACKS)
@@ -92,6 +93,9 @@ ide_git_remote_callbacks__notify_fraction_cb (gpointer data)
 
   g_assert (IDE_IS_GIT_REMOTE_CALLBACKS (self));
 
+  if (self->cancelled)
+    return G_SOURCE_REMOVE;
+
   if ((animation = self->animation))
     {
       ide_clear_weak_pointer (&self->animation);
@@ -122,6 +126,9 @@ ide_git_remote_callbacks_real_transfer_progress (GgitRemoteCallbacks  *callbacks
   g_assert (IDE_IS_GIT_REMOTE_CALLBACKS (self));
   g_assert (stats != NULL);
 
+  if (self->cancelled)
+    return;
+
   total = ggit_transfer_progress_get_total_objects (stats);
   received = ggit_transfer_progress_get_received_objects (stats);
   if (total == 0)
@@ -150,6 +157,15 @@ ide_git_remote_callbacks_real_credentials (GgitRemoteCallbacks  *callbacks,
 
   IDE_TRACE_MSG ("username=%s url=%s", username_from_url ?: "", url);
 
+  if (self->cancelled)
+    {
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_CANCELLED,
+                   "The operation has been canceled");
+      IDE_RETURN (NULL);
+    }
+
   allowed_types &= ~self->tried;
 
   if ((allowed_types & GGIT_CREDTYPE_SSH_KEY) != 0)
@@ -232,6 +248,7 @@ ide_git_remote_callbacks_class_init (IdeGitRemoteCallbacksClass *klass)
                          1.0,
                          0.0,
                          (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
   properties [PROP_PROGRESS] =
     g_param_spec_object ("progress",
                          "Progress",
@@ -247,3 +264,17 @@ ide_git_remote_callbacks_init (IdeGitRemoteCallbacks *self)
 {
   self->progress = g_object_new (IDE_TYPE_PROGRESS, NULL);
 }
+
+/**
+ * ide_git_remote_callbacks_cancel:
+ *
+ * This function should be called when a clone was canceled so that we can
+ * avoid dispatching more events.
+ */
+void
+ide_git_remote_callbacks_cancel (IdeGitRemoteCallbacks *self)
+{
+  g_return_if_fail (IDE_IS_GIT_REMOTE_CALLBACKS (self));
+
+  self->cancelled  = TRUE;
+}
diff --git a/plugins/git/ide-git-remote-callbacks.h b/plugins/git/ide-git-remote-callbacks.h
index 53206b4..aad2402 100644
--- a/plugins/git/ide-git-remote-callbacks.h
+++ b/plugins/git/ide-git-remote-callbacks.h
@@ -32,6 +32,7 @@ G_DECLARE_FINAL_TYPE (IdeGitRemoteCallbacks, ide_git_remote_callbacks,
 GgitRemoteCallbacks *ide_git_remote_callbacks_new          (void);
 gdouble              ide_git_remote_callbacks_get_fraction (IdeGitRemoteCallbacks *self);
 IdeProgress         *ide_git_remote_callbacks_get_progress (IdeGitRemoteCallbacks *self);
+void                 ide_git_remote_callbacks_cancel       (IdeGitRemoteCallbacks *self);
 
 G_END_DECLS
 


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