new(%args)
Creates a new object. If repodir 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.
Mandatory arguments:
• "repodir": the directory path where the bare Git repository is located.
• "branchname": 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.
Optional arguments:
• "writer": set to true if this object needs to write new files into the repository. Writing is always
done at the top of the branch.
• "goto": 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.
• "author_name", "author_email": name and email strings used for commits.
created_init_commit()
If a "Git::ObjectStore" object is created in writer mode and the branch did not exist, the "new()" method
creates an empty initial commit in this branch. This method returns the initial commit ID, or undef if
the branch already existed.
repo()
This method returns a Git::Raw::Repository object associated with this store object.
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.
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.
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.
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.
write_file($path,$data)
This method is similar to "write_and_check", but it does not compare the content revisions. It is useful
for massive write operations where speed is important.
delete_file($path)
This method deletes a file from the branch. It throws an error if the file does not exist in the branch.
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.
write_packfile()
This method writes the contents of mempack onto the disk. This method must be called after one or several
calls of "create_commit()", so that the changes are written to persistent storage.
create_commit_and_packfile([$msg])
This method combines "create_commit()" and "write_packfile". 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.
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.
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.