summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2020-02-10 20:41:06 -0700
committerSean Whitton <spwhitton@spwhitton.name>2020-02-10 20:41:06 -0700
commit9e44c51b844cb598dfdd617d893ab002b5a47816 (patch)
tree387215f2bcc6337b46f187674950757f24f4b281
parent8c5c28070f599b437033743786cbf5bdec08ca5d (diff)
downloadp5-Git-Annex-9e44c51b844cb598dfdd617d893ab002b5a47816.tar.gz
add 'annex' attribute
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--TODO8
-rw-r--r--lib/App/annex_review_unused.pm4
-rw-r--r--lib/App/annex_to_annex.pm4
-rw-r--r--lib/App/annex_to_annex_dropunused.pm2
-rw-r--r--lib/App/annex_to_annex_reinject.pm2
-rw-r--r--lib/Git/Annex.pm40
6 files changed, 41 insertions, 19 deletions
diff --git a/TODO b/TODO
deleted file mode 100644
index 99bef18..0000000
--- a/TODO
+++ /dev/null
@@ -1,8 +0,0 @@
-Would be cool to be able to do this, Git::Wrapper style:
-
- my $annex = Git::Annex->new;
- $annex->annex->find({ in => "here" });
-
-instead of
-
- $annex->git->annex("find", { in => "here" });
diff --git a/lib/App/annex_review_unused.pm b/lib/App/annex_review_unused.pm
index 4aac9ce..a1f9476 100644
--- a/lib/App/annex_review_unused.pm
+++ b/lib/App/annex_review_unused.pm
@@ -88,7 +88,7 @@ sub main {
if ($from_arg) {
#<<<
try {
- $annex->git->annex("readpresentkey", $unused_file->{key}, $uuid);
+ $annex->annex->readpresentkey($unused_file->{key}, $uuid);
} catch {
splice @unused_files, $i, 1;
next UNUSED;
@@ -174,7 +174,7 @@ sub main {
_say_spaced_bullet("Will dropunused"
. (exists $dropunused_args{force} ? " with --force:" : ":"));
say "@to_drop\n";
- $annex->git->annex("dropunused", \%dropunused_args, @to_drop)
+ $annex->annex->dropunused(\%dropunused_args, @to_drop)
if prompt_yn("Go ahead with this?");
}
diff --git a/lib/App/annex_to_annex.pm b/lib/App/annex_to_annex.pm
index 7336ffc..d68cc4a 100644
--- a/lib/App/annex_to_annex.pm
+++ b/lib/App/annex_to_annex.pm
@@ -88,7 +88,7 @@ sub main {
my $annex = Git::Annex->new($dir);
#<<<
try {
- $annex->git->annex("status");
+ $annex->annex->status;
} catch {
die "$source does not appear to lie within an annex\n";
};
@@ -111,7 +111,7 @@ sub main {
my $base = basename $source;
my @missing
- = $annex->git->annex("find", "--not", "--in", "here", $base);
+ = $annex->annex->find("--not", "--in", "here", $base);
if (@missing) {
say "Following annexed files are not present in this repo:";
say for @missing;
diff --git a/lib/App/annex_to_annex_dropunused.pm b/lib/App/annex_to_annex_dropunused.pm
index 89b16b5..099069f 100644
--- a/lib/App/annex_to_annex_dropunused.pm
+++ b/lib/App/annex_to_annex_dropunused.pm
@@ -66,7 +66,7 @@ sub main {
push @to_drop, $unused_file->{number};
}
- $annex->git->annex("dropunused", { force => 1 }, @to_drop);
+ $annex->annex->dropunused({ force => 1 }, @to_drop);
return 0;
}
diff --git a/lib/App/annex_to_annex_reinject.pm b/lib/App/annex_to_annex_reinject.pm
index 2e987ec..5a0296f 100644
--- a/lib/App/annex_to_annex_reinject.pm
+++ b/lib/App/annex_to_annex_reinject.pm
@@ -127,7 +127,7 @@ sub main {
# cause setpresentkey changes to be recorded in git-annex branch
undef $spk;
sleep 1;
- $source->git->annex("merge");
+ $source->annex->merge;
return 0;
}
diff --git a/lib/Git/Annex.pm b/lib/Git/Annex.pm
index 7080e88..e7c7295 100644
--- a/lib/Git/Annex.pm
+++ b/lib/Git/Annex.pm
@@ -34,9 +34,9 @@ package Git::Annex;
say "";
}
- # embedded Git::Wrapper instance; catch exceptions with Try::Tiny
- say for $annex->git->annex(qw(find --not --in here));
- $annex->git->annex(qw(copy -t cloud --in here --and --lackingcopies=1));
+ # embedded Git::Wrapper instance with shortcut to access annex subcommands
+ say for $annex->annex->find(qw(--not --in here));
+ $annex->annex->copy(qw(-t cloud --in here --and --lackingcopies=1));
=head1 DESCRIPTION
@@ -180,7 +180,7 @@ sub unused {
$self->{_unused}{unused_args} = \%unused_args;
# make a copy of %unused_args because Git::Wrapper will remove
# them from the hash
- for ($self->git->annex("unused", {%unused_args})) {
+ for ($self->annex->unused({%unused_args})) {
if (
/Some corrupted files have been preserved by fsck, just in case/
) {
@@ -253,7 +253,7 @@ Returns an absolute path to the content for git-annex key C<$key>.
sub abs_contentlocation {
my ($self, $key) = @_;
my $contentlocation;
- try { ($contentlocation) = $self->git->annex("contentlocation", $key) };
+ try { ($contentlocation) = $self->annex->contentlocation($key) };
$contentlocation ? rel2abs($contentlocation, $self->toplevel) : undef;
}
@@ -279,6 +279,36 @@ sub _git_path {
rel2abs $path, $self->toplevel;
}
+package Git::Annex::Wrapper {
+ AUTOLOAD {
+ my $self = shift;
+ (my $subcommand = our $AUTOLOAD) =~ s/.+:://;
+ return if $subcommand eq "DESTROY";
+ $subcommand =~ tr/_/-/;
+ $$self->git->RUN("annex", $subcommand, @_);
+ }
+}
+
+=attr annex
+
+Gives access to git-annex subcommands in the same way that
+Git::Annex::git gives access to git subcommands. So
+
+ $self->git->annex("contentlocation", $key);
+
+may be written
+
+ $self->annex->contentlocation($key);
+
+=cut
+
+# credits to Git::Wrapper's author for the idea of accessing
+# subcommands in this way; I've just extended that idea to
+# subsubcommands of git
+has annex => (
+ is => 'lazy',
+ default => sub { bless \$_[0] => "Git::Annex::Wrapper" });
+
around BUILDARGS => sub {
my (undef, undef, @args) = @_;