| 1 | # | ||||||||||||||||||||||||||||
| 2 | # Copyright (c) 2015-2022 Christian Jaeger, copying@christianjaeger.ch | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # This is free software, offered under either the same terms as perl 5 | ||||||||||||||||||||||||||||
| 5 | # or the terms of the Artistic License version 2 or the terms of the | ||||||||||||||||||||||||||||
| 6 | # MIT License (Expat version). See the file COPYING.md that came | ||||||||||||||||||||||||||||
| 7 | # bundled with this file. | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # Depends: (git) | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | FP::Git::Repository | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | Implements: L<FP::Abstract::Show> | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head1 NOTE | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | This is alpha software! Read the status section in the package README | ||||||||||||||||||||||||||||
| 28 | or on the L<website|http://functional-perl.org/>. | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =cut | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | package FP::Git::Repository; | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 2 | ▶ | use warnings FATAL => 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2 | ▶ | use FP::Predicates ":all"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | use Chj::IO::Command; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 2 | ▶ | use FP::IOStream "fh_to_stream"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | 2 | ▶ | use FP::Ops "the_method"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 42 | 2 | ▶ | use FP::Combinators "compose"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | use Chj::xperlfunc qw(xchdir xexec); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 2 | ▶ | use Chj::singlequote qw(singlequote_many); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 2 | our @git = "git"; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 4 | ▶ | sub make_perhaps_VAR { | ||||||||||||||||||||||||||
|
Subroutine
make_perhaps_VAR: called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 49 | 4 | my ($var, $method) = @_; | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 51 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 52 | 0 | ▶ | if (defined(my $v = $self->$method)) { ($var => $v) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | else { () } | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 4 | } | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 2 | ▶ | use FP::Struct [ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 58 | 2 | [maybe(\&is_nonnullstring), "git_dir"], | |||||||||||||||||||||||||||
| 59 | [maybe(\&is_nonnullstring), "work_tree"], | ||||||||||||||||||||||||||||
| 60 | [maybe(\&is_nonnullstring), "chdir"] | ||||||||||||||||||||||||||||
| 61 | ], | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # 'FP::Abstract::Pure', can't, setting _git_dir_from_work_tree | ||||||||||||||||||||||||||||
| 64 | 2 | 'FP::Struct::Show'; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub git_dir_from_work_tree { | ||||||||||||||||||||||||||
|
Subroutine
git_dir_from_work_tree: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | $$self{_git_dir_from_work_tree} //= do { | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"_git_dir_from_work_tree"} //= do {
if (defined(my $wd = $self->work_tree)) {
$wd =~ s[/\z][];
my $d = "$wd/.git";
-d $d or die "can't find git_dir from work_tree";
$d;
}
else {
undef;
}
}
MC/DC0%0/2
$self->{"_git_dir_from_work_tree"} //= do {
if (defined(my $wd = $self->work_tree)) {
$wd =~ s[/\z][];
my $d = "$wd/.git";
-d $d or die "can't find git_dir from work_tree";
$d;
}
else {
undef;
}
}
$self->{"_git_dir_from_work_tree"}
do {
if (defined(my $wd = $self->work_tree)) {
$wd =~ s[/\z][];
my $d = "$wd/.git";
-d $d or die "can't find git_dir from work_tree";
$d;
}
else {
undef;
}
}
Truth table0%0/3
A //= B
A= $self->{"_git_dir_from_work_tree"}B= do {
if (defined(my $wd = $self->work_tree)) {
$wd =~ s[/\z][];
my $d = "$wd/.git";
-d $d or die "can't find git_dir from work_tree";
$d;
}
else {
undef;
}
}
| |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if (defined(my $wd = $self->work_tree)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | $wd =~ s|/\z||; | |||||||||||||||||||||||||||
| 71 | 0 | my $d = "$wd/.git"; | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | -d $d or die "can't find git_dir from work_tree"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | $d | |||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||
| 75 | undef | ||||||||||||||||||||||||||||
| 76 | 0 | } | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub git_dir { | ||||||||||||||||||||||||||
|
Subroutine
git_dir: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 82 | (exists $$self{git_dir} ? $$self{git_dir} : undef) | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | // $self->git_dir_from_work_tree | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
(exists $self->{"git_dir"} ? $self->{"git_dir"} : undef) // $self->git_dir_from_work_tree
MC/DC0%0/2
(exists $self->{"git_dir"} ? $self->{"git_dir"} : undef) // $self->git_dir_from_work_tree
(exists $self->{"git_dir"} ? $self->{"git_dir"} : undef)
$self->git_dir_from_work_tree
Truth table0%0/3
A // B
A= (exists $self->{"git_dir"} ? $self->{"git_dir"} : undef)B= $self->git_dir_from_work_tree
| |||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 2 | *perhaps_GIT_DIR = make_perhaps_VAR "GIT_DIR", "git_dir"; | |||||||||||||||||||||||||||
| 87 | 2 | *perhaps_GIT_WORK_TREE = make_perhaps_VAR "GIT_WORK_TREE", "work_tree"; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub command_records { | ||||||||||||||||||||||||||
|
Subroutine
command_records: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 90 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 91 | 0 | my ($read, $close, $cmd_and_args) = @_; | |||||||||||||||||||||||||||
| 92 | my $in = Chj::IO::Command->new_sender( | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if (defined(my $d = $self->chdir)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | xchdir $d; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 0 | my $env = { $self->perhaps_GIT_DIR, $self->perhaps_GIT_WORK_TREE }; | |||||||||||||||||||||||||||
| 98 | 0 | for my $var (keys %$env) { | |||||||||||||||||||||||||||
| 99 | 0 | $ENV{$var} = $$env{$var} | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 0 | xexec(@git, @$cmd_and_args); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | 0 | ); | |||||||||||||||||||||||||||
| 104 | 0 | fh_to_stream($in, $read, $close) | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # (Why is SIGPIPE no issue? Well, since git is the process that | ||||||||||||||||||||||||||||
| 108 | # receives it, and *if* it receives it, then it's because we're | ||||||||||||||||||||||||||||
| 109 | # dropping the stream without exhausting it, in which case | ||||||||||||||||||||||||||||
| 110 | # Chj::IO::CommandCommon::DESTROY is called, which closes the | ||||||||||||||||||||||||||||
| 111 | # filehandle and collects the child without complaining.) | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub command_lines { | ||||||||||||||||||||||||||
|
Subroutine
command_lines: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 114 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 115 | 0 | $self->command_records(the_method("xreadline"), the_method("xxfinish"), | |||||||||||||||||||||||||||
| 116 | [@_]) | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub command_lines_chomp { | ||||||||||||||||||||||||||
|
Subroutine
command_lines_chomp: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 120 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 121 | 0 | $self->command_records(the_method("xreadline_chomp"), | |||||||||||||||||||||||||||
| 122 | the_method("xxfinish"), [@_]) | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub command_lines0_chop { | ||||||||||||||||||||||||||
|
Subroutine
command_lines0_chop: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 126 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 127 | 0 | $self->command_records(the_method("xreadline0_chop"), | |||||||||||||||||||||||||||
| 128 | the_method("xxfinish"), [@_]) | ||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | sub perhaps_author_date { | ||||||||||||||||||||||||||
|
Subroutine
perhaps_author_date: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 132 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 133 | 0 | my $lines | |||||||||||||||||||||||||||
| 134 | = $self->command_lines_chomp("log", '--pretty=format:%aD', "--", @_); | ||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if (is_null $lines) { () } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | else { | ||||||||||||||||||||||||||||
| 137 | 0 | $lines->first | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub author_date { | ||||||||||||||||||||||||||
|
Subroutine
author_date: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 142 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 143 | 0 | ▶ | if (my ($d) = $self->perhaps_author_date(@_)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 0 | $d | |||||||||||||||||||||||||||
| 145 | } else { | ||||||||||||||||||||||||||||
| 146 | 0 | warn "Note: can't get author date for (file not committed): " | |||||||||||||||||||||||||||
| 147 | . singlequote_many(@_) . ".\n"; | ||||||||||||||||||||||||||||
| 148 | () | ||||||||||||||||||||||||||||
| 149 | 0 | } | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub ls_files { | ||||||||||||||||||||||||||
|
Subroutine
ls_files: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 153 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 154 | 0 | $self->command_lines0_chop("ls-files", "-z", @_) | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub describe { | ||||||||||||||||||||||||||
|
Subroutine
describe: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 158 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 159 | 0 | $self->command_lines_chomp("describe", @_)->xone | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | sub rev_parse { | ||||||||||||||||||||||||||
|
Subroutine
rev_parse: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 163 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 164 | 0 | $self->command_lines_chomp("rev-parse", @_)->xone | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 2 | _END_ | |||||||||||||||||||||||||||