git

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package git provides git-based versioning for key-value storage. It tracks all changes to keys in a local git repository with optional push to remote.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Author added in v0.4.0

type Author struct {
	Name  string
	Email string
}

Author represents the author of a git commit.

func DefaultAuthor added in v0.4.0

func DefaultAuthor() Author

DefaultAuthor returns the default author for git commits.

type CommitRequest added in v0.7.3

type CommitRequest struct {
	Key       string
	Value     []byte
	Operation string
	Format    string
	Author    Author
}

CommitRequest holds parameters for a git commit operation.

type Config

type Config struct {
	Path   string // local repository path
	Branch string // branch name (default: master)
	Remote string // remote name (optional, for push/pull)
	SSHKey string // path to SSH private key (optional, for push)
}

Config holds git repository configuration

type HistoryEntry added in v0.12.0

type HistoryEntry struct {
	Hash      string    `json:"hash"`
	Timestamp time.Time `json:"timestamp"`
	Author    string    `json:"author"`
	Operation string    `json:"operation"`
	Format    string    `json:"format"`
	Value     []byte    `json:"value"`
}

HistoryEntry represents a single revision of a key.

type KeyValue added in v0.7.3

type KeyValue struct {
	Value  []byte
	Format string
}

KeyValue holds a key's value and format metadata.

type Service added in v0.9.1

type Service struct {
	// contains filtered or unexported fields
}

Service wraps Store and provides orchestrated git operations. handles commit + optional pull/push sequence.

func NewService added in v0.9.1

func NewService(st Storer, pushSync bool) *Service

NewService creates a new git service. if pushSync is true, commits will be followed by pull and push.

func (*Service) Commit added in v0.9.1

func (s *Service) Commit(req CommitRequest) error

Commit commits a key-value change to git and optionally syncs with remote.

func (*Service) Delete added in v0.9.1

func (s *Service) Delete(key string, author Author) error

Delete removes a key from git and optionally syncs with remote.

func (*Service) GetRevision added in v0.12.0

func (s *Service) GetRevision(key, rev string) ([]byte, string, error)

GetRevision returns value and format at specific revision.

func (*Service) History added in v0.12.0

func (s *Service) History(key string, limit int) ([]HistoryEntry, error)

History returns commit history for a key.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store provides git-backed versioning for key-value storage

func New

func New(cfg Config) (*Store, error)

New creates a new git store, initializing or opening the repository

func (*Store) Checkout

func (s *Store) Checkout(rev string) error

Checkout switches to specified revision (commit, tag, or branch)

func (*Store) Commit

func (s *Store) Commit(req CommitRequest) error

Commit writes key-value to file and commits to git.

func (*Store) Delete

func (s *Store) Delete(key string, author Author) error

Delete removes key file and commits the deletion. The author parameter specifies who made the change.

func (*Store) GetRevision added in v0.12.0

func (s *Store) GetRevision(key, rev string) ([]byte, string, error)

GetRevision returns value and format at specific revision.

func (*Store) Head

func (s *Store) Head() (string, error)

Head returns the current HEAD commit hash as a short string

func (*Store) History added in v0.12.0

func (s *Store) History(key string, limit int) ([]HistoryEntry, error)

History returns commit history for a key (newest first). limit specifies maximum number of entries to return (0 = unlimited).

func (*Store) Pull

func (s *Store) Pull() error

Pull fetches and merges from remote repository

func (*Store) Push

func (s *Store) Push() error

Push pushes commits to remote repository

func (*Store) ReadAll

func (s *Store) ReadAll() (map[string]KeyValue, error)

ReadAll reads all key-value pairs from the repository with their formats. Format is extracted from the commit message metadata of the last commit that modified each file. If no format is found in the commit message, defaults to "text".

Note: this function has O(n) git log queries where n is the number of files, as getFileFormat opens a git log iterator for each file. This is acceptable for restore operations which are infrequent admin commands.

type Storer added in v0.9.1

type Storer interface {
	Commit(req CommitRequest) error
	Delete(key string, author Author) error
	Pull() error
	Push() error
	History(key string, limit int) ([]HistoryEntry, error)
	GetRevision(key string, rev string) ([]byte, string, error)
}

Storer defines the interface for git store operations needed by Service.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL