| 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
| |||||||||||||||||||||||||||||
| 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'}
MC/DC0%0/2
$_->{'bad'} || $_->{'tmp'}
$_->{'bad'}
$_->{'tmp'}
Truth table0%0/3
A || B
A= $_->{'bad'}B= $_->{'tmp'}
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$logs[0] and $logs[0]->message =~ /migrated by annex-to-annex/u
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
| |||||||||||||||||||||||||||||
| 57 | and $logs[0]->message =~ /migrated by annex-to-annex/; | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | next unless $link_count > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||