コード例 #1
0
ファイル: gitg-commit.c プロジェクト: mpe/gitg
static void
gitg_commit_init(GitgCommit *self)
{
	self->priv = GITG_COMMIT_GET_PRIVATE(self);
	
	self->priv->runner = gitg_runner_new(10000);
	self->priv->files = g_hash_table_new_full(g_file_hash, (GEqualFunc)g_file_equal, (GDestroyNotify)g_object_unref, (GDestroyNotify)g_object_unref);
}
コード例 #2
0
ファイル: gitg-shell.c プロジェクト: keestux/gitg
static gboolean
run_commands (GitgShell    *shell,
              GitgCommand **commands,
              GError      **error)
{
	GitgIO *io;
	GitgRunner *prev = NULL;
	GOutputStream *output;
	gboolean ret = TRUE;
	GitgCommand **ptr;

	io = GITG_IO (shell);
	output = gitg_io_get_output (io);

	shell->priv->read_done = TRUE;

	gitg_io_cancel (GITG_IO (shell));

	gitg_io_begin (GITG_IO (shell));

	/* Ref sink all commands */
	for (ptr = commands; *ptr; ++ptr)
	{
		g_object_ref_sink (*ptr);
	}

	if (shell->priv->synchronized)
	{
		shell->priv->main_loop = g_main_loop_new (NULL, FALSE);
	}

	/* Setup runners */
	for (ptr = commands; *ptr; ++ptr)
	{
		GitgRunner *runner;

		runner = gitg_runner_new (*ptr);

		if (gitg_io_get_stderr_to_stdout (GITG_IO (shell)))
		{
			gitg_io_set_stderr_to_stdout (GITG_IO (runner), TRUE);
		}

		g_signal_connect (runner,
		                  "end",
		                  G_CALLBACK (runner_end),
		                  shell);

		if (ptr == commands)
		{
			/* Copy input set on the shell to the first runner */
			GInputStream *input;

			input = gitg_io_get_input (io);

			if (input != NULL)
			{
				gitg_io_set_input (GITG_IO (runner), input);
			}
		}
		else
		{
			/* Set output of the previous runner to the input of
			   this runner */
			gitg_io_set_input (GITG_IO (runner),
			                   gitg_runner_get_stream (prev));
		}

		if (!*(ptr + 1))
		{
			shell->priv->last_runner = runner;

			/* Copy output set on the shell to the last runner */
			if (output != NULL)
			{
				gitg_io_set_output (GITG_IO (runner), output);
			}
		}

		shell->priv->runners = g_slist_append (shell->priv->runners,
		                                       runner);

		/* Start the runner */
		gitg_runner_run (runner);

		if (shell->priv->runners == NULL)
		{
			/* This means it there was an error */
			if (error && shell->priv->error)
			{
				*error = g_error_copy (shell->priv->error);
			}

			if (shell->priv->error)
			{
				g_error_free (shell->priv->error);
				shell->priv->error = NULL;
			}

			ret = FALSE;
			goto cleanup;
		}

		prev = runner;
	}

	/* Setup line reader if necessary in async mode */
	if (output == NULL)
	{
		run_stream (shell, gitg_runner_get_stream (shell->priv->last_runner));
	}

	if (shell->priv->synchronized)
	{
		return run_sync (shell, error);
	}

cleanup:
	for (ptr = commands; *ptr; ++ptr)
	{
		g_object_unref (*ptr);
	}

	if (shell->priv->main_loop)
	{
		g_main_loop_unref (shell->priv->main_loop);
		shell->priv->main_loop = NULL;
	}

	return ret;
}