Class: Rugged::Blame
- Inherits:
-
Object
- Object
- Rugged::Blame
- Includes:
- Enumerable
- Defined in:
- ext/rugged/rugged_blame.c
Class Method Summary collapse
-
.new(repo, path, options = {}) ⇒ Object
Get blame data for the file at
path
inrepo
.
Instance Method Summary collapse
-
#[](index) ⇒ Object
Returns the blame hunk data at the given
index
inblame
. -
#count ⇒ Object
Returns the total
count
of blame hunks inblame
. -
#each ⇒ Object
If given a block, yields each
hunk
that is part ofblame
. -
#for_line(line_no) ⇒ Object
Returns the blame hunk data for the given
line_no
inblame
. -
#size ⇒ Object
Returns the total
count
of blame hunks inblame
.
Class Method Details
.new(repo, path, options = {}) ⇒ Object
Get blame data for the file at path
in repo
.
The following options can be passed in the options
Hash:
- :newest_commit
-
The ID of the newest commit to consider in the blame. Defaults to
HEAD
. This can either be a Rugged::Object instance, or a full or abbreviated SHA1 id. - :oldest_commit
-
The id of the oldest commit to consider. Defaults to the first commit encountered with a NULL parent. This can either be a Rugged::Object instance, or a full or abbreviated SHA1 id.
- :min_line
-
The first line in the file to blame. Line numbers start with 1. Defaults to
1
. - :max_line
-
The last line in the file to blame. Defaults to the last line in the file.
- :track_copies_same_file
-
If this value is
true
, lines that have moved within a file will be tracked (like ‘git blame -M`). - :track_copies_same_commit_moves
-
If this value is
true
, lines that have moved across files in the same commit will be tracked (like ‘git blame -C`). - :track_copies_same_commit_copies
-
If this value is
true
, lines that have been copied from another file that exists in the same commit will be tracked (like ‘git blame -CC`). - :track_copies_any_commit_copies
-
If this value is
true
, lines that have been copied from another file that exists in any commit will be tracked (like ‘git blame -CCC`).
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'ext/rugged/rugged_blame.c', line 128
static VALUE rb_git_blame_new(int argc, VALUE *argv, VALUE klass)
{
VALUE rb_repo, rb_path, rb_options;
git_repository *repo;
git_blame *blame;
git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
rb_scan_args(argc, argv, "20:", &rb_repo, &rb_path, &rb_options);
rugged_check_repo(rb_repo);
Data_Get_Struct(rb_repo, git_repository, repo);
Check_Type(rb_path, T_STRING);
rugged_parse_blame_options(&opts, repo, rb_options);
rugged_exception_check(git_blame_file(
&blame, repo, StringValueCStr(rb_path), &opts
));
return Data_Wrap_Struct(klass, NULL, &git_blame_free, blame);
}
|
Instance Method Details
#[](index) ⇒ Object
Returns the blame hunk data at the given index
in blame
.
Negative indices count backward from the end of the blame hunks (-1 is the last element).
Returns nil
if no blame hunk exists at the given index
.
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'ext/rugged/rugged_blame.c', line 207
static VALUE rb_git_blame_get_by_index(VALUE self, VALUE rb_index)
{
git_blame *blame;
int index;
uint32_t blame_count;
Data_Get_Struct(self, git_blame, blame);
Check_Type(rb_index, T_FIXNUM);
index = NUM2INT(rb_index);
blame_count = git_blame_get_hunk_count(blame);
if (index < 0) {
if ((uint32_t)(-index) > blame_count) {
return Qnil;
}
return rb_git_blame_hunk_fromC(
git_blame_get_hunk_byindex(blame, (uint32_t)(blame_count + index))
);
}
if ((uint32_t)index > blame_count)
return Qnil;
return rb_git_blame_hunk_fromC(
git_blame_get_hunk_byindex(blame, (uint32_t)index)
);
}
|
#count ⇒ Object #size ⇒ Object
Returns the total count
of blame hunks in blame
.
184 185 186 187 188 189 |
# File 'ext/rugged/rugged_blame.c', line 184
static VALUE rb_git_blame_count(VALUE self)
{
git_blame *blame;
Data_Get_Struct(self, git_blame, blame);
return UINT2NUM(git_blame_get_hunk_count(blame));
}
|
#each {|hunk| ... } ⇒ Object #each ⇒ Object
If given a block, yields each hunk
that is part of blame
. If no block is given, an enumerator will be returned.
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'ext/rugged/rugged_blame.c', line 245
static VALUE rb_git_blame_each(VALUE self)
{
git_blame *blame;
uint32_t i, blame_count;
RETURN_SIZED_ENUMERATOR(self, 0, 0, rugged_blame_enum_size);
Data_Get_Struct(self, git_blame, blame);
blame_count = git_blame_get_hunk_count(blame);
for (i = 0; i < blame_count; ++i) {
rb_yield(rb_git_blame_hunk_fromC(
git_blame_get_hunk_byindex(blame, i)
));
}
return self;
}
|
#for_line(line_no) ⇒ Object
Returns the blame hunk data for the given line_no
in blame
. Line number counting starts with 1
.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'ext/rugged/rugged_blame.c', line 158
static VALUE rb_git_blame_for_line(VALUE self, VALUE rb_line_no)
{
git_blame *blame;
int line_no;
Data_Get_Struct(self, git_blame, blame);
Check_Type(rb_line_no, T_FIXNUM);
line_no = NUM2INT(rb_line_no);
if (line_no < 0) {
rb_raise(rb_eArgError, "line number can't be negative");
}
return rb_git_blame_hunk_fromC(
git_blame_get_hunk_byline(blame, (uint32_t)line_no)
);
}
|
#count ⇒ Object #size ⇒ Object
Returns the total count
of blame hunks in blame
.
184 185 186 187 188 189 |
# File 'ext/rugged/rugged_blame.c', line 184
static VALUE rb_git_blame_count(VALUE self)
{
git_blame *blame;
Data_Get_Struct(self, git_blame, blame);
return UINT2NUM(git_blame_get_hunk_count(blame));
}
|