Class: Rugged::Diff::Hunk

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rugged/diff/hunk.rb,
ext/rugged/rugged_diff_hunk.c

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#headerObject (readonly)

#hunk_indexObject (readonly)

#line_countObject (readonly) Also known as: count, size

#new_linesObject (readonly)

#new_startObject (readonly)

#old_linesObject (readonly)

#old_startObject (readonly)

Instance Method Details

#deltaObject


9
10
11
# File 'lib/rugged/diff/hunk.rb', line 9

def delta
  @owner
end

#each_line {|line| ... } ⇒ self #each_lineEnumerator

If given a block, yields each line that is part of the current hunk.

If no block is given, an enumerator is returned instead.

Overloads:

  • #each_line {|line| ... } ⇒ self

    Yields:

    • (line)

    Returns:

    • (self)
  • #each_lineEnumerator

    Returns:

    • (Enumerator)

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'ext/rugged/rugged_diff_hunk.c', line 40

static VALUE rb_git_diff_hunk_each_line(VALUE self)
{
	git_patch *patch;
	int error = 0, l, lines_count, hunk_idx;

	RETURN_ENUMERATOR(self, 0, 0);

	Data_Get_Struct(rugged_owner(self), git_patch, patch);

	lines_count = FIX2INT(rb_iv_get(self, "@line_count"));
	hunk_idx = FIX2INT(rb_iv_get(self, "@hunk_index"));

	for (l = 0; l < lines_count; ++l) {
		const git_diff_line *line;
		error = git_patch_get_line_in_hunk(&line, patch, hunk_idx, l);
		if (error) break;

		rb_yield(rugged_diff_line_new(line));
	}
	rugged_exception_check(error);

	return self;
}

#each_line {|line| ... } ⇒ self #each_lineEnumerator

If given a block, yields each line that is part of the current hunk.

If no block is given, an enumerator is returned instead.

Overloads:

  • #each_line {|line| ... } ⇒ self

    Yields:

    • (line)

    Returns:

    • (self)
  • #each_lineEnumerator

    Returns:

    • (Enumerator)

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'ext/rugged/rugged_diff_hunk.c', line 40

static VALUE rb_git_diff_hunk_each_line(VALUE self)
{
	git_patch *patch;
	int error = 0, l, lines_count, hunk_idx;

	RETURN_ENUMERATOR(self, 0, 0);

	Data_Get_Struct(rugged_owner(self), git_patch, patch);

	lines_count = FIX2INT(rb_iv_get(self, "@line_count"));
	hunk_idx = FIX2INT(rb_iv_get(self, "@hunk_index"));

	for (l = 0; l < lines_count; ++l) {
		const git_diff_line *line;
		error = git_patch_get_line_in_hunk(&line, patch, hunk_idx, l);
		if (error) break;

		rb_yield(rugged_diff_line_new(line));
	}
	rugged_exception_check(error);

	return self;
}

#inspectObject


13
14
15
# File 'lib/rugged/diff/hunk.rb', line 13

def inspect
  "#<#{self.class.name}:#{object_id} {header: #{header.inspect}, count: #{count.inspect}}>"
end

#linesObject

Returns an Array containing all lines of the hunk.


18
19
20
# File 'lib/rugged/diff/hunk.rb', line 18

def lines
  each_line.to_a
end