Method: Rugged::Blob#diff

Defined in:
ext/rugged/rugged_blob.c

#diff(other, options = {}) ⇒ Object

Directly generate a Rugged::Patch from the difference between blob and other.

other can either be another Rugged::Blob instance, a string, or nil (treated as an empty blob).

The following options can be passed in the options Hash:

:max_size

An integer specifying the maximum byte size of a blob before a it will be treated as binary. The default value is 512MB.

:context_lines

The number of unchanged lines that define the boundary of a hunk (and to display before and after the actual changes). The default is 3.

:interhunk_lines

The maximum number of unchanged lines between hunk boundaries before the hunks will be merged into a one. The default is 0.

:reverse

If true, the sides of the diff will be reversed.

:force_text

If true, all files will be treated as text, disabling binary attributes & detection.

:ignore_whitespace

If true, all whitespace will be ignored.

:ignore_whitespace_change

If true, changes in amount of whitespace will be ignored.

:ignore_whitespace_eol

If true, whitespace at end of line will be ignored.

:patience

If true, the “patience diff” algorithm will be used (currently unimplemented).

:skip_binary_check

If true, diff deltas will be generated without spending time on binary detection. This is useful to improve performance in cases where the actual file content difference is not needed.

:old_path

An optional string to treat blob as if it had this filename.

:new_path

An optional string to treat other as if it had this filename.

[View source]

444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
# File 'ext/rugged/rugged_blob.c', line 444

static VALUE rb_git_blob_diff(int argc, VALUE *argv, VALUE self)
{
	git_blob *blob;
	git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
	git_patch *patch;
	const char *old_path = NULL, *new_path = NULL;
	VALUE rb_other, rb_options;
	int error;

	rb_scan_args(argc, argv, "10:", &rb_other, &rb_options);
	if (!NIL_P(rb_options)) {
		VALUE rb_value;

		rb_value = rb_hash_aref(rb_options, CSTR2SYM("old_path"));
		if (!NIL_P(rb_value)) {
			Check_Type(rb_value, T_STRING);
			old_path = StringValueCStr(rb_value);
		}

		rb_value = rb_hash_aref(rb_options, CSTR2SYM("new_path"));
		if (!NIL_P(rb_value)) {
			Check_Type(rb_value, T_STRING);
			new_path = StringValueCStr(rb_value);
		}

		rugged_parse_diff_options(&opts, rb_options);
	}

	TypedData_Get_Struct(self, git_blob, &rugged_object_type, blob);

	if (NIL_P(rb_other)) {
		error = git_patch_from_blobs(&patch, blob, old_path, NULL, new_path, &opts);
	} else if (rb_obj_is_kind_of(rb_other, rb_cRuggedBlob)) {
		git_blob *other_blob;

		TypedData_Get_Struct(rb_other, git_blob, &rugged_object_type, other_blob);

		error = git_patch_from_blobs(&patch, blob, old_path, other_blob, new_path, &opts);
	} else if (TYPE(rb_other) == T_STRING) {
		const char * buffer = StringValueCStr(rb_other);

		error = git_patch_from_blob_and_buffer(&patch, blob, old_path, buffer, RSTRING_LEN(rb_other), new_path, &opts);
	} else {
		rb_raise(rb_eTypeError, "wrong argument type %s (expected Rugged::Blob, String, or nil)",
			rb_obj_classname(rb_other));
	}

	rugged_exception_check(error);

	return rugged_patch_new(self, patch);
}