示例#1
0
/**
 * ggit_patch_to_stream:
 * @patch: a #GgitPatch.
 * @stream: a #GOutputStream.
 * @error: a #GError for error reporting, or %NULL.
 *
 * Write the contents of a patch to the provided stream.
 *
 * Returns: %TRUE if the patch was written successfully, %FALSE otherwise.
 *
 **/
gboolean
ggit_patch_to_stream (GgitPatch      *patch,
                      GOutputStream  *stream,
                      GError        **error)
{
	PatchToStream info;
	gint ret;

	g_return_val_if_fail (patch != NULL, FALSE);
	g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	info.stream = stream;
	info.error = error;

	ret = git_patch_print (patch->patch,
	                       patch_to_stream,
	                       &info);

	if (ret != GIT_OK)
	{
		if (error != NULL && *error == NULL)
		{
			_ggit_error_set (error, ret);
		}

		return FALSE;
	}

	return TRUE;
}
示例#2
0
/*
 *  call-seq:
 *    patch.to_s -> str
 *
 *  Returns the contents of the patch as a single diff string.
 */
static VALUE rb_git_diff_patch_to_s(VALUE self)
{
    git_patch *patch;
    VALUE rb_buffer = rb_ary_new();
    Data_Get_Struct(self, git_patch, patch);

    rugged_exception_check(git_patch_print(patch, patch_print_cb, (void*)rb_buffer));

    return rb_ary_join(rb_buffer, Qnil);
}
示例#3
0
/*
 *  call-seq:
 *    patch.header -> str
 *
 *  Returns only the header of the patch as a string.
 */
static VALUE rb_git_diff_patch_header(VALUE self)
{
    git_patch *patch;
    int error = 0;
    VALUE rb_buffer = rb_ary_new();
    Data_Get_Struct(self, git_patch, patch);

    error = git_patch_print(patch, patch_print_header_cb, (void*)rb_buffer);
    if (error && error != GIT_ITEROVER)
        rugged_exception_check(error);

    return rb_ary_join(rb_buffer, Qnil);
}