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`).
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'ext/rugged/rugged_blame.c', line 145
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
.
219 220 221 222 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 |
# File 'ext/rugged/rugged_blame.c', line 219
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
.
201 202 203 204 205 206 |
# File 'ext/rugged/rugged_blame.c', line 201
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.
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'ext/rugged/rugged_blame.c', line 257
static VALUE rb_git_blame_each(VALUE self)
{
git_blame *blame;
uint32_t i, blame_count;
if (!rb_block_given_p()) {
return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each"), self);
}
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
.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'ext/rugged/rugged_blame.c', line 175
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
.
201 202 203 204 205 206 |
# File 'ext/rugged/rugged_blame.c', line 201
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));
}
|