App-reposdb
view release on metacpan or search on metacpan
lib/App/reposdb.pm view on Meta::CPAN
package App::reposdb;
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2020-10-10'; # DATE
our $DIST = 'App-reposdb'; # DIST
our $VERSION = '0.007'; # VERSION
use 5.010001;
use strict;
use warnings;
use Log::ger;
our %SPEC;
$SPEC{':package'} = {
v => 1.1,
summary => 'Manipulate repos.db',
description => <<'_',
`repos.db` is a SQLite database that lists repository names along with some
extra data. They have various uses, but my first use-case for this is to store
last commit/status/pull time (updated via a post-commit git hook or `gitwrap`).
This is useful to speed up like syncing of repositories in `Git::Bunch` that
wants to find out which of the hundreds/thousand+ git repositories are "the most
recently used" to prioritize these repositories first. Using information from
`repos.db` is faster than having to `git status` or even stat() each repository.
_
};
sub _complete_repo {
my %args = @_;
my $word = $args{word} // '';
my $cmdline = $args{cmdline};
my $r = $args{r};
return undef unless $cmdline;
# force reading config file
$r->{read_config} = 1;
my $res = $cmdline->parse_argv($r);
my $args = $res->[2];
_set_args_default($args);
my $dbh = _connect_db($args);
my @repos;
my $sth = $dbh->prepare("SELECT name FROM repos");
$sth->execute;
while (my ($n) = $sth->fetchrow_array) {
push @repos, $n;
}
require Complete::Util;
Complete::Util::complete_array_elem(
word => $word,
array => \@repos,
);
}
sub _complete_tag {
my %args = @_;
my $word = $args{word} // '';
my $cmdline = $args{cmdline};
my $r = $args{r};
return undef unless $cmdline;
# force reading config file
$r->{read_config} = 1;
my $res = $cmdline->parse_argv($r);
my $args = $res->[2];
_set_args_default($args);
my $dbh = _connect_db($args);
my %tags;
my $sth = $dbh->prepare("SELECT tags FROM repos WHERE tags IS NOT NULL");
$sth->execute;
while (my ($t) = $sth->fetchrow_array) {
my @tags = split /,/, $t;
$tags{$_} = 1 for @tags;
}
require Complete::Util;
Complete::Util::complete_array_elem(
lib/App/reposdb.pm view on Meta::CPAN
$dbh->commit;
[200];
}
$SPEC{remove_all_repo_tags} = {
v => 1.1,
summary => 'Remove all tags from a repo (by default the current repo)',
args => {
%common_args,
%repo_arg,
},
};
sub remove_all_repo_tags {
my %args = @_;
_set_args_default(\%args, 1);
my $dbh = _connect_db(\%args);
return [400, "Please specify repo name"] unless defined $args{repo};
$dbh->begin_work;
my ($tags) = $dbh->selectrow_array("SELECT tags FROM repos WHERE name=?",
{}, $args{repo});
defined($tags) or return [404, "No such repo '$args{repo}'"];
$dbh->do("UPDATE repos SET tags=NULL WHERE name=?",
{}, $args{repo});
$dbh->commit;
[200];
}
1;
# ABSTRACT: Manipulate repos.db
__END__
=pod
=encoding UTF-8
=head1 NAME
App::reposdb - Manipulate repos.db
=head1 VERSION
This document describes version 0.007 of App::reposdb (from Perl distribution App-reposdb), released on 2020-10-10.
=head1 SYNOPSIS
See L<reposdb>.
=head1 DESCRIPTION
C<repos.db> is a SQLite database that lists repository names along with some
extra data. They have various uses, but my first use-case for this is to store
last commit/status/pull time (updated via a post-commit git hook or C<gitwrap>).
This is useful to speed up like syncing of repositories in C<Git::Bunch> that
wants to find out which of the hundreds/thousand+ git repositories are "the most
recently used" to prioritize these repositories first. Using information from
C<repos.db> is faster than having to C<git status> or even stat() each repository.
=head1 FUNCTIONS
=head2 add_repo_tag
Usage:
add_repo_tag(%args) -> [status, msg, payload, meta]
Add a tag to a repo (by default the current repo).
This function is not exported.
Arguments ('*' denotes required arguments):
=over 4
=item * B<repo> => I<str>
=item * B<reposdb_path>* => I<str>
=item * B<tags>* => I<array[str]>
=back
Returns an enveloped result (an array).
First element (status) is an integer containing HTTP status code
(200 means OK, 4xx caller error, 5xx function error). Second element
(msg) is a string containing error message, or 'OK' if status is
200. Third element (payload) is optional, the actual result. Fourth
element (meta) is called result metadata and is optional, a hash
that contains extra information.
Return value: (any)
=head2 get_repo_metadata
Usage:
get_repo_metadata(%args) -> [status, msg, payload, meta]
Get metadata for a repo (by default the current repo).
This function is not exported.
Arguments ('*' denotes required arguments):
=over 4
=item * B<repo> => I<str>
=item * B<reposdb_path>* => I<str>
=back
( run in 1.051 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )