class Rugged::Blame

Public Class Methods

new(repo, path, options = {}) → blame click to toggle source

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`).

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);
}

Public Instance Methods

blame[index] → hunk click to toggle source

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.

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 → count click to toggle source

Returns the total count of blame hunks in blame.

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));
}
Also aliased as: size
each { |hunk| ... } → blame click to toggle source
each → enumerator

If given a block, yields each hunk that is part of blame. If no block is given, an enumerator will be returned.

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) → hunk click to toggle source

Returns the blame hunk data for the given line_no in blame. Line number counting starts with 1.

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)
        );
}
size → count

Returns the total count of blame hunks in blame.

Alias for: count