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
pathinrepo.
Instance Method Summary collapse
-
#[](index) ⇒ Object
Returns the blame hunk data at the given
indexinblame. -
#count ⇒ Object
Returns the total
countof blame hunks inblame. -
#each ⇒ Object
If given a block, yields each
hunkthat is part ofblame. -
#for_line(line_no) ⇒ Object
Returns the blame hunk data for the given
line_noinblame. -
#size ⇒ Object
Returns the total
countof 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`).
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'ext/rugged/rugged_blame.c', line 144
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);
TypedData_Get_Struct(rb_repo, git_repository, &rugged_repository_type, 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 TypedData_Wrap_Struct(klass, &rugged_blame_type, 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.
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'ext/rugged/rugged_blame.c', line 223
static VALUE rb_git_blame_get_by_index(VALUE self, VALUE rb_index)
{
git_blame *blame;
int index;
uint32_t blame_count;
TypedData_Get_Struct(self, git_blame, &rugged_blame_type, 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.
200 201 202 203 204 205 |
# File 'ext/rugged/rugged_blame.c', line 200
static VALUE rb_git_blame_count(VALUE self)
{
git_blame *blame;
TypedData_Get_Struct(self, git_blame, &rugged_blame_type, 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.
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'ext/rugged/rugged_blame.c', line 261
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);
TypedData_Get_Struct(self, git_blame, &rugged_blame_type, 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.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'ext/rugged/rugged_blame.c', line 174
static VALUE rb_git_blame_for_line(VALUE self, VALUE rb_line_no)
{
git_blame *blame;
int line_no;
TypedData_Get_Struct(self, git_blame, &rugged_blame_type, 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.
200 201 202 203 204 205 |
# File 'ext/rugged/rugged_blame.c', line 200
static VALUE rb_git_blame_count(VALUE self)
{
git_blame *blame;
TypedData_Get_Struct(self, git_blame, &rugged_blame_type, blame);
return UINT2NUM(git_blame_get_hunk_count(blame));
}
|