PublicShow sourcegitty_driver_files.pl -- Gitty plain files driver

This version of the driver uses plain files to store the gitty data. It consists of a nested directory structure with files named after the hash. Objects and hash computation is the same as for git. The heads (files) are computed on startup by scanning all objects. There is a file ref/head that is updated if a head is updated. Other clients can watch this file and update their notion of the head. This implies that the store can handle multiple clients that can access a shared file system, optionally shared using NFS from different machines.

The store is simple and robust. The main disadvantages are long startup times as the store holds more objects and relatively high disk usage due to rounding the small objects to disk allocation units.

bug
- Shared access does not work on Windows.
Source gitty_open(+Store, +Options) is det
Driver specific initialization. Handles setting up a Redis connection when requested. This processes:
redis(+DB)
Name of the redis DB to connect to. See redis_server/3.
redis_ro(+DB)
Read-only redis DB.
redis_prefix(+Prefix)
Prefix for all keys. This can be used to host multiple SWISH servers on the same redis cluster. Default is swish.
Source gitty_close(+Store) is det
Close resources associated with a store.
Source gitty_file(+Store, ?File, ?Ext, ?Head) is nondet
True when File entry in the gitty store and Head is the HEAD revision.
Source load_plain_commit(+Store, +Hash, -Meta:dict) is semidet
Load the commit data as a dict. Loaded commits are cached in commit/3. Note that only adding a fact to the cache is synchronized. This means that during a race situation we may load the same object multiple times from disk, but this is harmless while a lock around the whole predicate serializes loading different objects, which is not needed.
Source store_object(+Store, +Hash, +Header:string, +Data:string) is det
Store the actual object. The store must associate Hash with the concatenation of Hdr and Data.
Source load_object(+Store, +Hash, -Data, -Type, -Size) is det
Load the given object.
Source gitty_rescan(?Store) is det
Update our view of the shared storage for all stores matching Store.
Source gitty_hash(+Store, ?Hash) is nondet
True when Hash is an object in the store.
Source delete_object(+Store, +Hash)
Delete an existing object
Source gitty_object_file(+Store, +Hash, -Path) is det
True when Path is the file at which the object with Hash is stored.
Source gitty_update_head(+Store, +Name, +OldCommit, +NewCommit, +DataHash) is det
Update the head of a gitty store for Name. OldCommit is the current head and NewCommit is the new head. If Name is created, and thus there is no head, OldCommit must be -.

This operation can fail because another writer has updated the head. This can both be in-process or another process.

Source delete_head(+Store, +Head) is det
Delete Head from Store. Used by gitty_fsck/1 to remove heads that have no commits. Should we forward this to remotes, or should they do their own thing?
Source set_head(+Store, +File, +Hash) is det
Set the head of the given File to Hash
Source repack_objects(+Store, +Options) is det[multifile]
Repack objects of Store for reduced disk usage and enhanced performance. By default this picks up all file objects of the store and all existing small pack files. Options:
small_pack(+Bytes)
Consider all packs with less than Bytes as small and repack them. Default 10Mb
min_files(+Count)
Do not repack if there are less than Count new files. Default 1,000.
Source pack_objects(+Store, +Objects, +Packs, +PackDir, -PackFile, +Options) is det
Pack the given objects and pack files into a new pack.
Source gitty_fsck(+Store) is det
Validate all packs associated with Store
Source fsck_pack(+File) is det
Validate the integrity of the pack file File.
Source attach_pack(+Store, +PackFile)
Load the index of Pack into memory.
Source load_object_from_pack(+Hash, -Data, -Type, -Size) is semidet
True when Hash is in a pack and can be loaded.
Source unpack_packs(+Store) is det[multifile]
Unpack all packs.
Source unpack_pack(+Store, +Pack) is det
Turn a pack back into a plain object files