NAME
Yukki::Model::Repository - model for accessing objects in a git repository
VERSION
version 0.140290
SYNOPSIS
my $repository = $app->model('Repository', { name => 'main' });
my $file = $repository->file({ path => 'foo.yukki' });
DESCRIPTION
This model contains methods for performing all the individual operations required to store files into and fetch files from the git repository. It includes tools for building trees, commiting, creating blobs, fetching file lists, etc.
EXTENDS
ATTRIBUTES
name
This is the name of the repository. This is used to lookup the configuration for the repository from the yukki.conf.
repository_settings
These are the settings telling this model where to find the git repository and how to access it. It is loaded automatically using the "name" to look up information in the yukki.conf.
repository_path
This is the path to the repository. It is located using the repository_path
and repository
keys in the configuration.
git
This is a Git::Repository object which helps us do the real work.
METHODS
author_name
This is the author name to use when making changes to the repository.
This is taken from the author_name
of the anonymous
key in the configuration or defaults to "Anonymous".
author_email
This is the author email to use when making changes to the repository.
This is taken from teh author_email
of the anonymous
key in the configuration or defaults to "anonymous@localhost".
make_tree
my $tree_id = $repository->make_tree($old_tree_id, \@parts, $object_id);
my $tree_id = $repository->make_tree($old_tree_id, \@parts);
my $tree_id = $repository->make_tree(
$old_tree_id, \@old_parts, \@new_parts, $object_id);
In any case described here, the method returns the object ID of the top level tree created.
Insert/Update
When $object_id
is given, this will construct one or more trees in the git repository to place the $object_id
into the deepest tree. This starts by reading the tree found using the object ID in $old_tree_id
. The first path part in @parts
is shifted off. If an existing path is found there, that path will be replaced. If not, a new path will be added. A tree object will be constructed for all byt he final path part in @parts
.
When the final part is reached, that path will be placed into the final tree as a blob using the given $object_id
.
This method will fail if it runs into a situation where a blob would be replaced by a tree or a tree would be replaced by a blob.
Remove
When $object_id
is not passed or undef
, this will cause the final tree or blob found to be removed. This works essentially the same as the case for storing a blob, but when it gets to the last tree or blob found, it will elide that name from the final tree constructed.
This method will fail if you attempt to remove something that does not exist.
Rename
When a second array reference is passed with the $object_id
, this method will perform a rename. In this case, the method will remove the path named in the @old_parts and add the path named in <@new_parts> using the given $object_id
at that new location.
This method will fail if a failure condition that would occur during either the insert/update or remove operation that is being performed simultaneously.
make_blob
my $object_id = $repository->make_blob($name, $content);
This creates a new file blob in the git repository with the given name and the file contents.
make_blob_from_file
my $object_id = $repository->make_blob_from_file($name, $filename);
This is identical to "make_blob", except that the contents are read from the given filename on the local disk.
find_root
my $tree_id = $repository->find_root;
This returns the object ID for the tree at the root of the "branch".
commit_tree
my $commit_id = $self->commit_tree($old_tree_id, $new_tree_id, $comment);
This takes an existing tree commit (generally found with "find_root"), a new tree to replace it (generally constructed by "make_tree") and creates a commit using the given comment.
The object ID of the committed ID is returned.
update_root
$self->update_root($old_tree_id, $new_tree_id);
Given a old commit ID and a new commit ID, this moves the HEAD of the "branch" so that it points to the new commit. This is called after "commit_tree" has setup the commit.
find_path
my $object_id = $self->find_path($path);
Given a path within the repository, this will find the object ID of that tree or blob at that path for the "branch".
show
my $content = $repository->show($object_id);
Returns the contents of the blob for the given object ID.
fetch_size
my $bytes = $repository->fetch_size($path);
Returns the size, in bites, of the blob at the given path.
list_files
my @files = $repository->list_files($path);
Returns a list of Yukki::Model::File objects for all the files found at $path
in the repository.
file
my $file = $repository->file({ path => 'foo', filetype => 'yukki' });
Returns a single Yukki::Model::File object for the given path and filetype.
default_file
my $file = $repository->default_file;
Return the default Yukki::Model::File configured for this repository.
log
my @log = $repository->log( full_path => 'foo.yukk' );
Returns a list of revisions. Each revision is a hash with the following keys:
- object_id
-
The object ID of the commit.
-
The name of the commti author.
- date
-
The date the commit was made.
- time_ago
-
A string showing how long ago the edit took place.
- comment
-
The comment the author made about the comment.
- lines_added
-
Number of lines added.
- lines_removed
-
Number of lines removed.
diff_blobs
my @chunks = $self->diff_blobs('file.yukki', 'a939fe...', 'b7763d...');
Given a file path and two object IDs, returns a list of chunks showing the difference between to revisions of that path. Each chunk is a two element array. The first element is the type of chunk and the second is any detail for that chunk.
The types are:
"+" This chunk was added to the second revision.
"-" This chunk was removed in the second revision.
" " This chunk is the same in both revisions.
AUTHOR
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Qubling Software LLC.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.