Jido. VFS. Adapter. Versioning behaviour
(Jido.VFS v1.0.0)
View Source
Behaviour for versioning operations in Jido.VFS adapters.
This behaviour defines a consistent interface for version control operations that can be implemented by adapters that support versioning functionality.
The versioning API is designed to be adapter-agnostic, allowing different storage backends to implement versioning in their own way while presenting a unified interface to the user.
Types
config- Adapter configuration structrevision- Version identifier (could be SHA, timestamp, ID, etc.)revision_info- Structured information about a revision
Callbacks
All callbacks are optional, allowing adapters to implement only the versioning features they support.
Core Operations
commit/3- Create a new version/commitrevisions/3- List available revisions for a pathread_revision/4- Read content at a specific revision
Advanced Operations
rollback/3- Rollback to a previous revisiondiff/4- Show differences between revisionsmerge/4- Merge changes from another revision
Summary
Callbacks
Commit staged changes with an optional message.
Show differences between two revisions.
Merge changes from another revision.
Read the content of a file as it existed at a specific revision.
List revisions for a given path.
Rollback to a previous revision.
Functions
Get supported versioning operations for an adapter.
Check if an adapter supports versioning operations.
Types
Callbacks
@callback commit(config(), message :: String.t() | nil, opts :: keyword()) :: :ok | {:error, term()}
Commit staged changes with an optional message.
Creates a new revision containing all current staged changes. The exact behavior depends on the adapter implementation.
Options
:author- Override author information for this commit:timestamp- Override timestamp for this commit
Examples
# Simple commit
:ok = MyAdapter.commit(config, "Add new feature")
# Commit with options
:ok = MyAdapter.commit(config, "Fix bug", author: [name: "Dev", email: "dev@example.com"])
@callback diff( config(), from_revision :: revision(), to_revision :: revision(), opts :: keyword() ) :: {:ok, String.t()} | {:error, term()}
Show differences between two revisions.
Examples
{:ok, diff} = MyAdapter.diff(config, "abc123", "def456")
@callback merge( config(), from_revision :: revision(), message :: String.t() | nil, opts :: keyword() ) :: :ok | {:error, term()}
Merge changes from another revision.
Examples
:ok = MyAdapter.merge(config, "feature-branch", "Merge feature branch")
@callback read_revision(config(), path :: Path.t(), revision(), opts :: keyword()) :: {:ok, binary()} | {:error, term()}
Read the content of a file as it existed at a specific revision.
Examples
{:ok, content} = MyAdapter.read_revision(config, "file.txt", "abc123")
@callback revisions(config(), path :: Path.t(), opts :: keyword()) :: {:ok, [revision_info()]} | {:error, term()}
List revisions for a given path.
Returns a list of revision information ordered by most recent first.
Options
:limit- Maximum number of revisions to return:since- Only revisions after this datetime:until- Only revisions before this datetime:author- Only revisions by this author
Examples
# List all revisions for a file
{:ok, revisions} = MyAdapter.revisions(config, "file.txt")
# List last 10 revisions
{:ok, revisions} = MyAdapter.revisions(config, ".", limit: 10)
Rollback to a previous revision.
The behavior depends on the adapter and options provided.
Options
:path- Only rollback changes to a specific path (if supported):create_commit- Whether to create a new commit for the rollback
Examples
# Rollback entire filesystem
:ok = MyAdapter.rollback(config, "abc123")
# Rollback single file
:ok = MyAdapter.rollback(config, "abc123", path: "file.txt")
Functions
Get supported versioning operations for an adapter.
Returns a list of atoms representing the versioning operations the adapter supports.
Check if an adapter supports versioning operations.
Returns true if the adapter implements any versioning callbacks.