NAME

Review::Helper::Registry - The reviews registered in a repository.

DESCRIPTION

The registry maps each review id to its file path and state (open or closed). One registry serves every worktree of a repository; it lives at registry.json in the VCS's shared state directory ("shared_state_dir" in Review::Helper::VCS). It exists so prune can find reviews that are closed or whose file is gone without searching every worktree.

The file is JSON: { "reviews": { "<id>": { "path": ..., "state": ... } } }. Paths are stored as text, so the file holds each path's UTF-8 encoding once; methods take and return paths as bytes. Every change holds an exclusive flock on it while reading and rewriting. A file of any other shape is refused with an error naming it, and left as it is.

SYNOPSIS

use Review::Helper::Registry;

my $registry = Review::Helper::Registry->new(repo => $repo);

$registry->register($id, $file);
$registry->set_state($id, 'closed');

my $reviews = $registry->reviews;
my $removed = $registry->prune(dry_run => 1);

ATTRIBUTES

$repo = $registry->repo()

The repository the registry belongs to, a Review::Helper::VCS. Required.

$path = $registry->path()

The registry file. Defaults to the repository's shared registry location.

PUBLIC METHODS

$registry->close_review($db, $path)

Mark the review open in $db (a Review::Helper::DB) closed, in the file and in the registry. $path is the review file's path.

$registry->register($id, $path)
$registry->register($id, $path, $state)

Record a review, replacing any earlier entry for $id. $path is stored as an absolute path; $state defaults to open. Croaks when the path is not valid UTF-8. Review ids may contain only letters, digits, - and _, so they are safe inside a pin name.

$registry->set_state($id, $state)

Set a registered review's state. Croaks when $id is not registered.

$reviews = $registry->reviews()

Hashref of id to { path => ..., state => ... }, with each path as bytes ready for file operations. Empty when there is no registry file.

$pins = $registry->prune(dry_run => $bool)

For every review that is closed or whose file no longer exists, remove its pins ("pins" in Review::Helper::VCS) and drop its entry. An entry whose id is not a valid review id is dropped too, removing no pins. Returns the names of the pins removed. With dry_run, changes nothing and returns the pins it would remove; the invalid entries it would drop are not listed, since they name no pins. Review files are never deleted.

SOURCE

The source code repository for Review-Helper can be found at https://github.com/exodist/Review-Helper.

MAINTAINERS

Chad Granum <exodist7@gmail.com>

AUTHORS

Chad Granum <exodist7@gmail.com>

COPYRIGHT

Copyright Chad Granum <exodist7@gmail.com>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See https://dev.perl.org/licenses/