Commit 455fad16 authored by Christian Hergert's avatar Christian Hergert

git: port to IdeTask

The git stuff interacts with UI quite a bit, so its somewhat
important to ensure we are more careful about where we finalize
task data.
parent c46777cf
......@@ -147,13 +147,13 @@ ide_git_buffer_change_monitor_calculate_finish (IdeGitBufferChangeMonitor *self
GAsyncResult *result,
GError **error)
{
GTask *task = (GTask *)result;
IdeTask *task = (IdeTask *)result;
DiffTask *diff;
g_assert (IDE_IS_GIT_BUFFER_CHANGE_MONITOR (self));
g_assert (G_IS_TASK (result));
g_assert (IDE_IS_TASK (result));
diff = g_task_get_task_data (task);
diff = ide_task_get_task_data (task);
/* Keep the blob around for future use */
if (diff->blob != self->cached_blob)
......@@ -162,7 +162,7 @@ ide_git_buffer_change_monitor_calculate_finish (IdeGitBufferChangeMonitor *self
/* If the file is a child of the working directory, we need to know */
self->is_child_of_workdir = diff->is_child_of_workdir;
return g_task_propagate_pointer (task, error);
return ide_task_propagate_pointer (task, error);
}
static void
......@@ -171,7 +171,7 @@ ide_git_buffer_change_monitor_calculate_async (IdeGitBufferChangeMonitor *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_autoptr(GTask) task = NULL;
g_autoptr(IdeTask) task = NULL;
DiffTask *diff;
IdeFile *file;
GFile *gfile;
......@@ -183,9 +183,9 @@ ide_git_buffer_change_monitor_calculate_async (IdeGitBufferChangeMonitor *self,
self->state_dirty = FALSE;
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, ide_git_buffer_change_monitor_calculate_async);
g_task_set_priority (task, G_PRIORITY_LOW);
task = ide_task_new (self, cancellable, callback, user_data);
ide_task_set_source_tag (task, ide_git_buffer_change_monitor_calculate_async);
ide_task_set_priority (task, G_PRIORITY_LOW);
file = ide_buffer_get_file (self->buffer);
g_assert (IDE_IS_FILE (file));
......@@ -195,10 +195,10 @@ ide_git_buffer_change_monitor_calculate_async (IdeGitBufferChangeMonitor *self,
if (gfile == NULL)
{
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_NOT_FOUND,
_("Cannot provide diff, no backing file provided."));
ide_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_NOT_FOUND,
_("Cannot provide diff, no backing file provided."));
return;
}
......@@ -209,7 +209,7 @@ ide_git_buffer_change_monitor_calculate_async (IdeGitBufferChangeMonitor *self,
diff->content = ide_buffer_get_content (self->buffer);
diff->blob = self->cached_blob ? g_object_ref (self->cached_blob) : NULL;
g_task_set_task_data (task, diff, diff_task_free);
ide_task_set_task_data (task, diff, diff_task_free);
self->in_calculation = TRUE;
......@@ -787,21 +787,21 @@ ide_git_buffer_change_monitor_worker (gpointer data)
{
IdeGitBufferChangeMonitor *self;
g_autoptr(GError) error = NULL;
g_autoptr(GTask) task = taskptr;
g_autoptr(IdeTask) task = taskptr;
DiffTask *diff;
self = g_task_get_source_object (task);
self = ide_task_get_source_object (task);
g_assert (IDE_IS_GIT_BUFFER_CHANGE_MONITOR (self));
diff = g_task_get_task_data (task);
diff = ide_task_get_task_data (task);
g_assert (diff != NULL);
if (!ide_git_buffer_change_monitor_calculate_threaded (self, diff, &error))
g_task_return_error (task, g_steal_pointer (&error));
ide_task_return_error (task, g_steal_pointer (&error));
else
g_task_return_pointer (task,
g_steal_pointer (&diff->lines),
(GDestroyNotify)g_array_unref);
ide_task_return_pointer (task,
g_steal_pointer (&diff->lines),
(GDestroyNotify)g_array_unref);
}
return NULL;
......
......@@ -258,7 +258,7 @@ ide_git_clone_widget_init (IdeGitCloneWidget *self)
static gboolean
open_after_timeout (gpointer user_data)
{
GTask *task = user_data;
IdeTask *task = user_data;
IdeGitCloneWidget *self;
IdeWorkbench *workbench;
g_autoptr(GError) error = NULL;
......@@ -266,10 +266,10 @@ open_after_timeout (gpointer user_data)
IDE_ENTRY;
g_assert (G_IS_TASK (task));
g_assert (IDE_IS_TASK (task));
self = g_task_get_source_object (task);
req = g_task_get_task_data (task);
self = ide_task_get_source_object (task);
req = ide_task_get_task_data (task);
workbench = ide_widget_get_workbench (GTK_WIDGET (self));
g_assert (req != NULL);
......@@ -293,13 +293,13 @@ open_after_timeout (gpointer user_data)
static gboolean
finish_animation_in_idle (gpointer data)
{
GTask *task = data;
IdeTask *task = data;
IdeGitCloneWidget *self;
IDE_ENTRY;
g_assert (G_IS_TASK (task));
self = g_task_get_source_object (task);
g_assert (IDE_IS_TASK (task));
self = ide_task_get_source_object (task);
g_assert (IDE_IS_GIT_CLONE_WIDGET (self));
dzl_object_animate_full (self->clone_progress,
......@@ -325,7 +325,7 @@ finish_animation_in_idle (gpointer data)
}
static void
ide_git_clone_widget_worker (GTask *task,
ide_git_clone_widget_worker (IdeTask *task,
gpointer source_object,
gpointer task_data,
GCancellable *cancellable)
......@@ -340,7 +340,7 @@ ide_git_clone_widget_worker (GTask *task,
CloneRequest *req = task_data;
IdeProgress *progress;
g_assert (G_IS_TASK (task));
g_assert (IDE_IS_TASK (task));
g_assert (IDE_IS_GIT_CLONE_WIDGET (self));
g_assert (req != NULL);
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
......@@ -372,11 +372,11 @@ ide_git_clone_widget_worker (GTask *task,
if (repository == NULL)
{
g_task_return_error (task, g_steal_pointer (&error));
ide_task_return_error (task, g_steal_pointer (&error));
return;
}
if (g_task_return_error_if_cancelled (task))
if (ide_task_return_error_if_cancelled (task))
return;
req->project_file = ggit_repository_get_workdir (repository);
......@@ -385,11 +385,11 @@ ide_git_clone_widget_worker (GTask *task,
g_object_ref (task),
g_object_unref);
/* We must complete the task in this worker, as GTask does not support
/* We must complete the task in this worker, as IdeTask does not support
* completing the task asynchronously after work completes. Another option
* would be to fix things to use mutliple async steps.
*/
g_task_return_boolean (task, TRUE);
ide_task_return_boolean (task, TRUE);
g_clear_object (&repository);
}
......@@ -400,7 +400,7 @@ ide_git_clone_widget_clone_async (IdeGitCloneWidget *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_autoptr(GTask) task = NULL;
g_autoptr(IdeTask) task = NULL;
g_autoptr(GFile) location = NULL;
g_autoptr(IdeVcsUri) uri = NULL;
g_autofree gchar *uristr = NULL;
......@@ -409,8 +409,8 @@ ide_git_clone_widget_clone_async (IdeGitCloneWidget *self,
g_return_if_fail (IDE_IS_GIT_CLONE_WIDGET (self));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, ide_git_clone_widget_clone_async);
task = ide_task_new (self, cancellable, callback, user_data);
ide_task_set_source_tag (task, ide_git_clone_widget_clone_async);
/*
* ggit_repository_clone() will block and we don't have a good way to
......@@ -420,7 +420,7 @@ ide_git_clone_widget_clone_async (IdeGitCloneWidget *self,
* FIXME: Find Ggit API to cancel clone. We might need access to the
* GgitRemote so we can ggit_remote_disconnect().
*/
g_task_set_return_on_cancel (task, TRUE);
ide_task_set_return_on_cancel (task, TRUE);
gtk_label_set_label (self->clone_error_label, NULL);
......@@ -431,10 +431,10 @@ ide_git_clone_widget_clone_async (IdeGitCloneWidget *self,
if (uri == NULL)
{
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_INVAL,
_("A valid Git URL is required"));
ide_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_INVAL,
_("A valid Git URL is required"));
return;
}
......@@ -455,8 +455,8 @@ ide_git_clone_widget_clone_async (IdeGitCloneWidget *self,
gtk_progress_bar_set_fraction (self->clone_progress, 0.0);
gtk_widget_show (GTK_WIDGET (self->clone_progress));
g_task_set_task_data (task, req, clone_request_free);
g_task_run_in_thread (task, ide_git_clone_widget_worker);
ide_task_set_task_data (task, req, clone_request_free);
ide_task_run_in_thread (task, ide_git_clone_widget_worker);
}
gboolean
......@@ -468,9 +468,9 @@ ide_git_clone_widget_clone_finish (IdeGitCloneWidget *self,
gboolean ret;
g_return_val_if_fail (IDE_IS_GIT_CLONE_WIDGET (self), FALSE);
g_return_val_if_fail (G_IS_TASK (result), FALSE);
g_return_val_if_fail (IDE_IS_TASK (result), FALSE);
ret = g_task_propagate_boolean (G_TASK (result), &local_error);
ret = ide_task_propagate_boolean (IDE_TASK (result), &local_error);
/* Only hide progress if we were cancelled */
if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
......
......@@ -131,15 +131,15 @@ ide_git_genesis_addin_run_cb (GObject *object,
{
IdeGitCloneWidget *widget = (IdeGitCloneWidget *)object;
g_autoptr(GError) error = NULL;
g_autoptr(GTask) task = user_data;
g_autoptr(IdeTask) task = user_data;
g_assert (G_IS_TASK (task));
g_assert (IDE_IS_TASK (task));
g_assert (IDE_IS_GIT_CLONE_WIDGET (widget));
if (!ide_git_clone_widget_clone_finish (widget, result, &error))
g_task_return_error (task, g_steal_pointer (&error));
ide_task_return_error (task, g_steal_pointer (&error));
else
g_task_return_boolean (task, TRUE);
ide_task_return_boolean (task, TRUE);
}
static void
......@@ -149,12 +149,12 @@ ide_git_genesis_addin_run_async (IdeGenesisAddin *addin,
gpointer user_data)
{
IdeGitGenesisAddin *self = (IdeGitGenesisAddin *)addin;
GTask *task;
IdeTask *task;
g_return_if_fail (IDE_IS_GIT_GENESIS_ADDIN (addin));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
task = g_task_new (self, cancellable, callback, user_data);
task = ide_task_new (self, cancellable, callback, user_data);
ide_git_clone_widget_clone_async (self->clone_widget,
cancellable,
ide_git_genesis_addin_run_cb,
......@@ -167,9 +167,9 @@ ide_git_genesis_addin_run_finish (IdeGenesisAddin *addin,
GError **error)
{
g_return_val_if_fail (IDE_IS_GIT_GENESIS_ADDIN (addin), FALSE);
g_return_val_if_fail (G_IS_TASK (result), FALSE);
g_return_val_if_fail (IDE_IS_TASK (result), FALSE);
return g_task_propagate_boolean (G_TASK (result), error);
return ide_task_propagate_boolean (IDE_TASK (result), error);
}
static gint
......
......@@ -47,7 +47,7 @@ ide_git_vcs_initializer_init (IdeGitVcsInitializer *self)
}
static void
ide_git_vcs_initializer_initialize_worker (GTask *task,
ide_git_vcs_initializer_initialize_worker (IdeTask *task,
gpointer source_object,
gpointer task_data,
GCancellable *cancellable)
......@@ -56,16 +56,16 @@ ide_git_vcs_initializer_initialize_worker (GTask *task,
g_autoptr(GError) error = NULL;
GFile *file = task_data;
g_assert (G_IS_TASK (task));
g_assert (IDE_IS_TASK (task));
g_assert (IDE_IS_GIT_VCS_INITIALIZER (source_object));
g_assert (G_IS_FILE (file));
repository = ggit_repository_init_repository (file, FALSE, &error);
if (repository == NULL)
g_task_return_error (task, g_steal_pointer (&error));
ide_task_return_error (task, g_steal_pointer (&error));
else
g_task_return_boolean (task, TRUE);
ide_task_return_boolean (task, TRUE);
}
static void
......@@ -76,15 +76,15 @@ ide_git_vcs_initializer_initialize_async (IdeVcsInitializer *initializer,
gpointer user_data)
{
IdeGitVcsInitializer *self = (IdeGitVcsInitializer *)initializer;
g_autoptr(GTask) task = NULL;
g_autoptr(IdeTask) task = NULL;
g_return_if_fail (IDE_IS_GIT_VCS_INITIALIZER (self));
g_return_if_fail (G_IS_FILE (file));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_task_data (task, g_object_ref (file), g_object_unref);
g_task_run_in_thread (task, ide_git_vcs_initializer_initialize_worker);
task = ide_task_new (self, cancellable, callback, user_data);
ide_task_set_task_data (task, g_object_ref (file), g_object_unref);
ide_task_run_in_thread (task, ide_git_vcs_initializer_initialize_worker);
}
static gboolean
......@@ -93,9 +93,9 @@ ide_git_vcs_initializer_initialize_finish (IdeVcsInitializer *initializer,
GError **error)
{
g_return_val_if_fail (IDE_IS_GIT_VCS_INITIALIZER (initializer), FALSE);
g_return_val_if_fail (G_IS_TASK (result), FALSE);
g_return_val_if_fail (IDE_IS_TASK (result), FALSE);
return g_task_propagate_boolean (G_TASK (result), error);
return ide_task_propagate_boolean (IDE_TASK (result), error);
}
static gchar *
......
......@@ -383,7 +383,7 @@ ide_git_vcs_load_monitor_locked (IdeGitVcs *self,
}
static void
ide_git_vcs_reload_worker (GTask *task,
ide_git_vcs_reload_worker (IdeTask *task,
gpointer source_object,
gpointer task_data,
GCancellable *cancellable)
......@@ -395,7 +395,7 @@ ide_git_vcs_reload_worker (GTask *task,
IDE_ENTRY;
g_assert (G_IS_TASK (task));
g_assert (IDE_IS_TASK (task));
g_assert (IDE_IS_GIT_VCS (self));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
......@@ -403,7 +403,7 @@ ide_git_vcs_reload_worker (GTask *task,
!(repository2 = ide_git_vcs_load (self, &error)))
{
g_debug ("%s", error->message);
g_task_return_error (task, g_steal_pointer (&error));
ide_task_return_error (task, g_steal_pointer (&error));
IDE_EXIT;
}
......@@ -413,9 +413,9 @@ ide_git_vcs_reload_worker (GTask *task,
g_set_object (&self->change_monitor_repository, repository2);
if (!ide_git_vcs_load_monitor_locked (self, &error))
g_task_return_error (task, g_steal_pointer (&error));
ide_task_return_error (task, g_steal_pointer (&error));
else
g_task_return_boolean (task, TRUE);
ide_task_return_boolean (task, TRUE);
g_mutex_unlock (&self->repository_mutex);
......@@ -428,15 +428,15 @@ ide_git_vcs_reload_async (IdeGitVcs *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_autoptr(GTask) task = NULL;
g_autoptr(IdeTask) task = NULL;
IDE_ENTRY;
g_assert (IDE_IS_GIT_VCS (self));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
task = g_task_new (self, cancellable, callback, user_data);
g_task_run_in_thread (task, ide_git_vcs_reload_worker);
task = ide_task_new (self, cancellable, callback, user_data);
ide_task_run_in_thread (task, ide_git_vcs_reload_worker);
IDE_EXIT;
}
......@@ -446,7 +446,7 @@ ide_git_vcs_reload_finish (IdeGitVcs *self,
GAsyncResult *result,
GError **error)
{
GTask *task = (GTask *)result;
IdeTask *task = (IdeTask *)result;
gboolean ret;
IDE_ENTRY;
......@@ -455,7 +455,7 @@ ide_git_vcs_reload_finish (IdeGitVcs *self,
self->reloading = FALSE;
ret = g_task_propagate_boolean (task, error);
ret = ide_task_propagate_boolean (task, error);
if (ret)
{
......@@ -606,7 +606,7 @@ ide_git_vcs_list_status_cb (const gchar *path,
}
static void
ide_git_vcs_list_status_worker (GTask *task,
ide_git_vcs_list_status_worker (IdeTask *task,
gpointer source_object,
gpointer task_data,
GCancellable *cancellable)
......@@ -620,7 +620,7 @@ ide_git_vcs_list_status_worker (GTask *task,
g_autofree gchar *relative = NULL;
gchar *strv[] = { NULL, NULL };
g_assert (G_IS_TASK (task));
g_assert (IDE_IS_TASK (task));
g_assert (IDE_IS_GIT_VCS (source_object));
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
g_assert (state != NULL);
......@@ -628,16 +628,16 @@ ide_git_vcs_list_status_worker (GTask *task,
if (!(repository = ggit_repository_open (state->repository_location, &error)))
{
g_task_return_error (task, g_steal_pointer (&error));
ide_task_return_error (task, g_steal_pointer (&error));
return;
}
if (!(workdir = ggit_repository_get_workdir (repository)))
{
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_FAILED,
"Failed to locate working directory");
ide_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_FAILED,
"Failed to locate working directory");
return;
}
......@@ -659,9 +659,9 @@ ide_git_vcs_list_status_worker (GTask *task,
ide_git_vcs_list_status_cb,
state,
&error))
g_task_return_error (task, g_steal_pointer (&error));
ide_task_return_error (task, g_steal_pointer (&error));
else
g_task_return_pointer (task, g_steal_pointer (&store), g_object_unref);
ide_task_return_pointer (task, g_steal_pointer (&store), g_object_unref);
}
static void
......@@ -674,7 +674,7 @@ ide_git_vcs_list_status_async (IdeVcs *vcs,
gpointer user_data)
{
IdeGitVcs *self = (IdeGitVcs *)vcs;
g_autoptr(GTask) task = NULL;
g_autoptr(IdeTask) task = NULL;
ListStatus *state;
IDE_ENTRY;
......@@ -690,19 +690,19 @@ ide_git_vcs_list_status_async (IdeVcs *vcs,
state->recursive = !!include_descendants;
g_mutex_unlock (&self->repository_mutex);
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, ide_git_vcs_list_status_async);
g_task_set_priority (task, io_priority);
g_task_set_return_on_cancel (task, TRUE);
g_task_set_task_data (task, state, list_status_free);
task = ide_task_new (self, cancellable, callback, user_data);
ide_task_set_source_tag (task, ide_git_vcs_list_status_async);
ide_task_set_priority (task, io_priority);
ide_task_set_return_on_cancel (task, TRUE);
ide_task_set_task_data (task, state, list_status_free);
if (state->repository_location == NULL)
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_FAILED,
"No repository loaded");
ide_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_FAILED,
"No repository loaded");
else
g_task_run_in_thread (task, ide_git_vcs_list_status_worker);
ide_task_run_in_thread (task, ide_git_vcs_list_status_worker);
IDE_EXIT;
}
......@@ -713,9 +713,9 @@ ide_git_vcs_list_status_finish (IdeVcs *vcs,
GError **error)
{
g_return_val_if_fail (IDE_IS_GIT_VCS (vcs), NULL);
g_return_val_if_fail (G_IS_TASK (result), NULL);
g_return_val_if_fail (IDE_IS_TASK (result), NULL);
return g_task_propagate_pointer (G_TASK (result), error);
return ide_task_propagate_pointer (IDE_TASK (result), error);
}
static void
......@@ -838,16 +838,16 @@ ide_git_vcs_init_async__reload_cb (GObject *object,
gpointer user_data)
{
IdeGitVcs *self = (IdeGitVcs *)object;
g_autoptr(GTask) task = user_data;
g_autoptr(IdeTask) task = user_data;
g_autoptr(GError) error = NULL;
g_assert (G_IS_TASK (task));
g_assert (IDE_IS_TASK (task));
g_assert (IDE_IS_GIT_VCS (self));
if (!ide_git_vcs_reload_finish (self, result, &error))
g_task_return_error (task, g_steal_pointer (&error));
ide_task_return_error (task, g_steal_pointer (&error));
else
g_task_return_boolean (task, TRUE);
ide_task_return_boolean (task, TRUE);
}
static void
......@@ -858,11 +858,11 @@ ide_git_vcs_init_async (GAsyncInitable *initable,
gpointer user_data)
{
IdeGitVcs *self = (IdeGitVcs *)initable;
g_autoptr(GTask) task = NULL;
g_autoptr(IdeTask) task = NULL;
g_return_if_fail (IDE_IS_GIT_VCS (self));
task = g_task_new (self, cancellable, callback, user_data);
task = ide_task_new (self, cancellable, callback, user_data);
ide_git_vcs_reload_async (self,
cancellable,
ide_git_vcs_init_async__reload_cb,
......@@ -874,11 +874,11 @@ ide_git_vcs_init_finish (GAsyncInitable *initable,
GAsyncResult *result,
GError **error)
{
GTask *task = (GTask *)result;
IdeTask *task = (IdeTask *)result;
g_return_val_if_fail (G_IS_TASK (task), FALSE);
g_return_val_if_fail (IDE_IS_TASK (task), FALSE);
return g_task_propagate_boolean (task, error);
return ide_task_propagate_boolean (task, error);
}
static void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment