Rand Stats

Git::Blame::File

zef:lizmat

Actions Status

NAME

Git::Blame::File - Who did what and when on a file in a Git repository

SYNOPSIS

use Git::Blame::File;

my $blamer = Git::Blame::File.new("t/target");
say $blamer.lines[2];  # show line #3
# c64c97c3 (Elizabeth Mattijsen 2022-07-27 20:40:22 +0200 3) And this the third line

DESCRIPTION

Git::Blame::File is a module that uses git blame to extract information from a single file in a Git repository. It processes the git blame information into Git::Blame::Line objects, while also keeping track of commits in Git::Blame::Commit objects.

METHODS ON Git::Blame::File

new

my $blamer = Git::Blame::File.new: "t/target";

The new method either takes a single positional argument as the filename or the IO::Path object of which to obtain git blame information.

It can also be called with a :file named argument, and an optional :commits argument. The latter is intended for a future Git::Blame::Repository module that would potentially contain all git blame information of a repository.

lines

Returns an Array with all the lines (as Git::Blame::Line objects) in the file. Note that these are 0-based, whereas line numbers are typically 1-based.

say $blamer.lines[2];  # show line #3
# c64c97c3 (Elizabeth Mattijsen 2022-07-27 20:40:22 +0200 3) And this the third line

commits

Returns a Map of all the commits that were seen for this file (and potentially other files in the future. Keyed to the sha of the commit, and having a Git::Blame::Commit object as a value.

ACCESSORS ON Git::Blame::Line

Note that Git::Blame::Line objects are created automatically by Git::Blame::File.new.

ACCESSORS ON Git::Blame::Commit

Note that Git::Blame::Commit objects are created automatically by Git::Blame::File.new.

AUTHORS

Elizabeth Mattijsen liz@raku.rocks

Source can be located at: https://github.com/lizmat/Git-Blame-File . Comments and Pull Requests are welcome.

If you like this module, or what I’m doing more generally, committing to a small sponsorship would mean a great deal to me!

COPYRIGHT AND LICENSE

Copyright 2022 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.