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("xt/target");
say $blamer.lines[2];  # show line #3
# c64c97c3 (Elizabeth Mattijsen 2022-07-27 20:40:22 +0200 3) And this the third line

.say for Git::Blame::File.new("xt/target", :line-numbers(2,4)).lines
#c64c97c3 (Elizabeth Mattijsen 2022-07-27 20:40:22 +0200 2) This became the second line.
#77877dbc (Elizabeth Mattijsen 2022-07-27 20:39:29 +0200 4) This is the second 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.

Stringifies to the filename specified.

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.

Finally, it can also be called with an optional :line-numbers named argument, which should contain the line numbers (in ascending order) of which to obtain blame information. The .lines method will then iterate over the blame information of these line numbers.

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

authors

Returns a list of unique authors of this file.

commits

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

created

Returns a DateTime object when this file was created, according to the oldest author-time information. Note that if no lines of the first commit exist in the file, this may actually be later.

modified

Returns a DateTime object when this file was last modified, according to the newest committer-time information.

file

The file from which the git blame information was obtained.

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.