.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Git::ObjectStore 3pm" .TH Git::ObjectStore 3pm "2018-05-19" "perl v5.26.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Git::ObjectStore \- abstraction layer for Git::Raw and libgit2 .SH "VERSION" .IX Header "VERSION" version 0.007 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Git::ObjectStore; \& \& ### Writer example ### \& my $store = new Git::ObjectStore(\*(Aqrepodir\*(Aq => $dir, \& \*(Aqbranchname\*(Aq => $bname, \& \*(Aqwriter\*(Aq => 1); \& \& # write the documents into the store \& my $is_changed = $store\->write_and_check(\*(Aqdocs/001a\*(Aq, \e$doc1text); \& $store\->write_file(\*(Aqdocs/001b\*(Aq, \e$doc2text); \& \& # documents can be read from the writer object \& my $doc = $store\->read_file(\*(Aqdocs/001c\*(Aq); \& \& # check if a document exists and delete it \& if( $store\->file_exists(\*(Aqdocs/001d\*(Aq) ) { \& $store\->delete_file(\*(Aqdocs/001d\*(Aq); \& } \& \& # once the changes are finished, create commit and write it to disk \& $store\->create_commit_and_packfile(); \& \& ### Reader example ### \& my $store = new Git::ObjectStore(\*(Aqrepodir\*(Aq => $dir, \& \*(Aqbranchname\*(Aq => $bname); \& \& # checking existance or reading individual files \& $store\->file_exists(\*(Aqdocs/001d\*(Aq) and print "file exists\en"; \& my $doc = $store\->read_file(\*(Aqdocs/001c\*(Aq); \& \& # read all files in a directory and its subdirectories \& my $cb_read = sub { \& my ($path, $data) = @_; \& print("$path: $data\en"); \& }; \& $store\->recursive_read(\*(Aqdocs\*(Aq, $cb_read); \& \& # Check if there are changes and read the updates \& my $cb_updated = sub { \& my ($path, $data) = @_; \& print("Updated $path: $data\en"); \& }; \& my $cb_deleted = sub { \& my ($path) = @_; \& print("Deleted $path\en"); \& }; \& if( $store\->current_commit_id() ne $old_commit_id ) { \& $store\->read_updates($old_commit_id, $cb_updated, $cb_deleted); \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides an abstraction layer on top of Git::Raw, a Perl wrapper for \fIlibgit2\fR, in order to use a bare Git repository as an object store. The objects are written into a mempack, and then flushed to disk, so thousands of objects can be created without polluting your filesystem and exhausting its inode pool. .SH "METHODS" .IX Header "METHODS" .SS "new(%args)" .IX Subsection "new(%args)" Creates a new object. If \fIrepodir\fR is empty or does not exist, the method (in writer mode only) initializes a new bare Git repository. If multiple processes may call this method simultaneously, it is up to you to provide locking and prevent the race condition. .PP Mandatory arguments: .IP "\(bu" 4 \&\f(CW\*(C`repodir\*(C'\fR: the directory path where the bare Git repository is located. .IP "\(bu" 4 \&\f(CW\*(C`branchname\*(C'\fR: the branch name in the repository. Multiple Git::ObjectStore objects can co-exist at the same time in multiple or the same process, but the branch names in writer objects need to be unique. .PP Optional arguments: .IP "\(bu" 4 \&\f(CW\*(C`writer\*(C'\fR: set to true if this object needs to write new files into the repository. Writing is always done at the top of the branch. .IP "\(bu" 4 \&\f(CW\*(C`goto\*(C'\fR: commit identifier where the read operations will be performed. This argument cannot be combined with writer mode. By default, reading is performed from the top of the branch. .IP "\(bu" 4 \&\f(CW\*(C`author_name\*(C'\fR, \f(CW\*(C`author_email\*(C'\fR: name and email strings used for commits. .SS "\fIcreated_init_commit()\fP" .IX Subsection "created_init_commit()" If a \f(CW\*(C`Git::ObjectStore\*(C'\fR object is created in writer mode and the branch did not exist, the \f(CW\*(C`new()\*(C'\fR method creates an empty initial commit in this branch. This method returns the initial commit \s-1ID,\s0 or undef if the branch already existed. .SS "\fIrepo()\fP" .IX Subsection "repo()" This method returns a Git::Raw::Repository object associated with this store object. .SS "read_file($path)" .IX Subsection "read_file($path)" This method reads a file from a given path within the branch. It returns undef if the file is not found. In writer mode, the file is checked first in the in-memory mempack. The returned value is the file content as a scalar. .SS "file_exists($path)" .IX Subsection "file_exists($path)" This method returns true if the given file extsis in the branch. In reader mode, it also returns true if path is a directory name. .SS "\fIcurrent_commit_id()\fP" .IX Subsection "current_commit_id()" Returns the current commit identifier. This can be useful for detecting if there are any changes in the branch and retrieve the difference. .ie n .SS "write_and_check($path, $data)" .el .SS "write_and_check($path, \f(CW$data\fP)" .IX Subsection "write_and_check($path, $data)" This method writes the data scalar to the repository under specified file name. It returns true if the data differs from the previous version or a new file is created. It returns false if the new data is identical to what has been written before. The data can be a scalar or a reference to scalar. .ie n .SS "write_file($path, $data)" .el .SS "write_file($path, \f(CW$data\fP)" .IX Subsection "write_file($path, $data)" This method is similar to \f(CW\*(C`write_and_check\*(C'\fR, but it does not compare the content revisions. It is useful for massive write operations where speed is important. .SS "delete_file($path)" .IX Subsection "delete_file($path)" This method deletes a file from the branch. It throws an error if the file does not exist in the branch. .SS "create_commit([$msg])" .IX Subsection "create_commit([$msg])" This method checks if any new content is written, and creates a Git commit if there is a change. The return value is true if a new commit has been created, or false otherwise. An optional argument can specify the commit message. If a message is not specified, current localtime is used instead. .SS "\fIwrite_packfile()\fP" .IX Subsection "write_packfile()" This method writes the contents of mempack onto the disk. This method must be called after one or several calls of \f(CW\*(C`create_commit()\*(C'\fR, so that the changes are written to persistent storage. .SS "create_commit_and_packfile([$msg])" .IX Subsection "create_commit_and_packfile([$msg])" This method combines \f(CW\*(C`create_commit()\*(C'\fR and \f(CW\*(C`write_packfile\*(C'\fR. The packfile is only written if there is a change in the content. The method returns true if any changes were detected. If it's a new branch and it only contains the empty initial commit, a packfile is written and the method returns false. .ie n .SS "recursive_read($path, $callback, $no_content)" .el .SS "recursive_read($path, \f(CW$callback\fP, \f(CW$no_content\fP)" .IX Subsection "recursive_read($path, $callback, $no_content)" This method is only supported in reader mode. It reads the directories recursively and calls the callback for every file it finds. The callback arguments are the file name and scalar content. If called with string as path, all files in the branch are traversed. If the third argument is a true value, the method does not read the object contents, and the callback is only called with one argument. .ie n .SS "read_updates($old_commit_id, $callback_updated, $callback_deleted, $no_content)" .el .SS "read_updates($old_commit_id, \f(CW$callback_updated\fP, \f(CW$callback_deleted\fP, \f(CW$no_content\fP)" .IX Subsection "read_updates($old_commit_id, $callback_updated, $callback_deleted, $no_content)" This method is only supported in reader mode. It compares the current commit with the old commit, and executes the first callback for all added or updated files, and the second callback for all deleted files. The first callback gets the file name and scalar content as arguments, and the second callback gets only the file name. If the fourth argument is true, the update callback is called only with rhe file name. .SH "AUTHOR" .IX Header "AUTHOR" Stanislav Sinyagin .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2017 by Stanislav Sinyagin. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.