Class: Rugged::Diff::Patch

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ownerObject Also known as: diff

Returns the value of attribute owner.



10
11
12
# File 'lib/rugged/diff/patch.rb', line 10

def owner
  @owner
end

Instance Method Details

#additionsInteger

Returns the number of addition lines in the patch.

Returns:

  • (Integer)


112
113
114
115
116
117
118
119
120
121
# File 'ext/rugged/rugged_diff_patch.c', line 112

static VALUE rb_git_diff_patch_additions(VALUE self)
{
	git_diff_patch *patch;
	size_t additions;
	Data_Get_Struct(self, git_diff_patch, patch);

	git_diff_patch_line_stats(NULL, &additions, NULL, patch);

	return INT2FIX(additions);
}

#changesObject

Returns the number of changes in the patch.



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

def changes
  additions + deletions
end

#contextInteger

Returns the number of context lines in the patch.

Returns:

  • (Integer)


146
147
148
149
150
151
152
153
154
155
# File 'ext/rugged/rugged_diff_patch.c', line 146

static VALUE rb_git_diff_patch_context(VALUE self)
{
	git_diff_patch *patch;
	size_t context;
	Data_Get_Struct(self, git_diff_patch, patch);

	git_diff_patch_line_stats(&context, NULL, NULL, patch);

	return INT2FIX(context);
}

#deletionsInteger

Returns the number of deletion lines in the patch.

Returns:

  • (Integer)


129
130
131
132
133
134
135
136
137
138
# File 'ext/rugged/rugged_diff_patch.c', line 129

static VALUE rb_git_diff_patch_deletions(VALUE self)
{
	git_diff_patch *patch;
	size_t deletions;
	Data_Get_Struct(self, git_diff_patch, patch);

	git_diff_patch_line_stats(NULL, NULL, &deletions, patch);

	return INT2FIX(deletions);
}

#deltaObject

Returns the delta object associated with the patch.



98
99
100
101
102
103
104
# File 'ext/rugged/rugged_diff_patch.c', line 98

static VALUE rb_git_diff_patch_delta(VALUE self)
{
	git_diff_patch *patch;
	Data_Get_Struct(self, git_diff_patch, patch);

	return rugged_diff_delta_new(rugged_owner(self), git_diff_patch_delta(patch));
}

#each_hunk {|hunk| ... } ⇒ self #each_hunkObject Also known as: each

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

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

Overloads:

  • #each_hunk {|hunk| ... } ⇒ self

    Yields:

    • (hunk)

    Returns:

    • (self)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'ext/rugged/rugged_diff_patch.c', line 52

static VALUE rb_git_diff_patch_each_hunk(VALUE self)
{
	git_diff_patch *patch;
	const git_diff_range *range;
	const char *header;
	size_t header_len, lines_in_hunk;
	int error = 0, hooks_count, h;

	if (!rb_block_given_p()) {
		return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each_hunk"), self);
	}

	Data_Get_Struct(self, git_diff_patch, patch);

	hooks_count = git_diff_patch_num_hunks(patch);
	for (h = 0; h < hooks_count; ++h) {
		error = git_diff_patch_get_hunk(&range, &header, &header_len, &lines_in_hunk, patch, h);
		if (error) break;

		rb_yield(rugged_diff_hunk_new(self, h, range, header, header_len, lines_in_hunk));
	}
	rugged_exception_check(error);

	return self;
}

#hunk_countInteger Also known as: size, count

Returns the number of hunks in the patch.

Returns:

  • (Integer)


84
85
86
87
88
89
90
# File 'ext/rugged/rugged_diff_patch.c', line 84

static VALUE rb_git_diff_patch_hunk_count(VALUE self)
{
	git_diff_patch *patch;
	Data_Get_Struct(self, git_diff_patch, patch);

	return INT2FIX(git_diff_patch_num_hunks(patch));
}

#hunksObject

Returns an Array containing all hunks of the patch.



23
24
25
# File 'lib/rugged/diff/patch.rb', line 23

def hunks
  each_hunk.to_a
end

#inspectObject



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

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