App/annex_to_annex_dropunused.pm

filter: Statementstmt 54.8% 17 / 31 Branchbran 16.6% 1 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 83.3% 5 / 6 Podpod 100% 1 / 1 totaltotal 44.4% 24 / 54 CC 6 SCAR 31.5
CC
6
Cov
42%
main
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 23.4
« App/annex_to_annex_reinject.pm ↑ Summary Git/Annex/BatchCommand.pm »
1 package App::annex_to_annex_dropunused;
2 # ABSTRACT: drop old hardlinks migrated by annex-to-annex
3 #
4 # Copyright (C) 2019-2020 Sean Whitton <spwhitton@spwhitton.name>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or (at
9 # your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 1 $App::annex_to_annex_dropunused::VERSION = '0.008';
19 1 ▶use 5.028;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Git::Annex;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 # This script used to have a --dest option which specified the
27 # destination annex previously used with annex-to-annex. Then, if the
28 # unused file had a hardlink count of 1, but was present in the
29 # destination annex, this script would drop it.
30 #
31 # That was somewhat dangerous functionality because it involves this
32 # script running `git annex dropunused --force` for files with a
33 # hardlink count of 1. And further, it is not actually needed,
34 # because running annex-to-annex-reinject after
35 # annex-to-annex-dropunused handles such files in a way that is safer.
36 #
37 # It is still good to run this script before annex-to-annex-reinject
38 # to make the latter faster.
39  
40 1 ▶exit main() unless caller;
Branch: 1 branch
BranchTrueFalseTotal
unless caller 0 1 1
41  
42  
43 0 ▶sub main {
Subroutine main: not called CC=6 SCAR=37.4
Pod documented
44 0 my $annex = Git::Annex->new;
45  
46 0 my @to_drop;
47 0 ▶ my @unused_files = grep { !$_->{bad} && !$_->{tmp} } @{ $annex->unused };
Condition0%0/3
$_->{'bad'} || $_->{'tmp'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->{'bad'} || $_->{'tmp'}
$_->{'bad'} $_->{'tmp'}
Truth table0%0/3
A || B
A= $_->{'bad'}B= $_->{'tmp'}
ABresult
1X1
011
000
48  
49 0 foreach my $unused_file (@unused_files) {
50 0 my $content = $annex->abs_contentlocation($unused_file->{key});
51 0 my $link_count = (stat $content)[3];
52 my @logs
53 0 = $annex->git->log({ no_textconv => 1 }, "-S", $unused_file->{key});
54  
55 next
56 0 ▶ unless $logs[0]
Branch: 1 branch
BranchTrueFalseTotal
unless $logs[0] and $logs[0]->message =~ /migrated by annex-to-annex/u 0 0 0
Condition0%0/3
$logs[0] and $logs[0]->message =~ /migrated by annex-to-annex/u
!ll&&!rl&&r
000
MC/DC0%0/2
$logs[0] and $logs[0]->message =~ /migrated by annex-to-annex/u
$logs[0] $logs[0]->message =~ /migrated by annex-to-annex/u
Truth table0%0/3
A and B
A= $logs[0]B= $logs[0]->message =~ /migrated by annex-to-annex/u
ABresult
0X0
100
111
57 and $logs[0]->message =~ /migrated by annex-to-annex/;
58 0 ▶ next unless $link_count > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $link_count > 1 0 0 0
59  
60 0 push @to_drop, $unused_file->{number};
61 }
62  
63 0 $annex->annex->dropunused({ force => 1 }, @to_drop);
64  
65 0 return 0;
66 }
67  
68 1 1;
69  
70 __END__
« App/annex_to_annex_reinject.pm ↑ Summary Git/Annex/BatchCommand.pm »