summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2023-06-12 16:41:40 +0100
committerSean Whitton <spwhitton@spwhitton.name>2023-06-13 13:54:14 +0100
commitcde6c55e427ca03513399e333ff742bab67ed9f1 (patch)
tree6f91fe0305000b94aed5787ae9bd92a2c86c5f90
parentda524d1a1b6f0a0f522275834e2c67d2a9f46ca2 (diff)
downloaddotfiles-cde6c55e427ca03513399e333ff742bab67ed9f1.tar.gz
add git-annex-dropoldunused
-rwxr-xr-xbin/git-annex-dropoldunused24
-rw-r--r--lib-src/mr/config7
2 files changed, 26 insertions, 5 deletions
diff --git a/bin/git-annex-dropoldunused b/bin/git-annex-dropoldunused
new file mode 100755
index 00000000..881ddb49
--- /dev/null
+++ b/bin/git-annex-dropoldunused
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+use 5.036;
+
+use Getopt::Long qw(:config pass_through);
+use Scalar::Util "looks_like_number";
+
+my $d = 30;
+my ($from, $force, @args);
+GetOptions "days=i" => \$d, "from=s" => \$from, "force!" => \$force;
+
+my $s = time - $d*24*60*60;
+$from and unshift @ARGV, "--from=$from";
+$force and unshift @args, "--force";
+
+system qw(git annex unused), @ARGV and die "'git annex unused' failed\n";
+
+open my $fh, "<", ".git/annex/unused" or exit;
+for (<$fh>) {
+ my ($n, $k) = split;
+ my ($t) = `git log -1 --format="%ct" --no-textconv -S"$k"`;
+ looks_like_number $t and $t < $s and push @args, $n
+}
+
+exec qw(git annex dropunused), @args
diff --git a/lib-src/mr/config b/lib-src/mr/config
index 48d83a58..07e59e98 100644
--- a/lib-src/mr/config
+++ b/lib-src/mr/config
@@ -208,11 +208,8 @@ autoci =
fixups =
# Drop score files unused by master or origin/master for a week.
[ "$MR_ACTION" = checkout -o "$MR_ACTION" = update ] || git fetch origin
- git annex unused \
- --used-refspec="+refs/heads/master:+refs/remotes/origin/master" \
- | perl -wlne'BEGIN { $w = time - 7*24*60*60 } /^\s+(\d+)\s+/
- and $t = `git log -1 --format="%ct" --no-textconv -S"$'"'"'" -- News`
- and $t < $w and print $1' | xargs git annex dropunused --force
+ git annex dropoldunused --force --days=7 \
+ --used-refspec="+refs/heads/master:+refs/remotes/origin/master"
####################################################################