core

package
v0.0.0-...-dc8f43e Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MigrateRepository

func MigrateRepository(old interface{}) (*Repository, *Workspace, error)

MigrateRepository shows how to migrate from old Repository to new architecture This is a temporary helper during refactoring

Types

type Branch

type Branch struct {
	Name string
	Hash string
}

Branch represents a Git branch

type CleanRepository

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

CleanRepository represents the core immutable Git repository It only handles objects and references - no mutable state, no config, no webhooks

func Clone

func Clone(sourceRepo *CleanRepository, targetObjects ObjectStore, targetRefs RefStore) (*CleanRepository, error)

Clone clones a repository (simplified version)

func NewCleanRepository

func NewCleanRepository(objects ObjectStore, refs RefStore) *CleanRepository

NewCleanRepository creates a new clean repository

func (*CleanRepository) GetBlob

func (r *CleanRepository) GetBlob(hash string) (*object.Blob, error)

GetBlob retrieves a blob by hash

func (*CleanRepository) GetBranch

func (r *CleanRepository) GetBranch(name string) (string, error)

GetBranch retrieves a specific branch

func (*CleanRepository) GetCommit

func (r *CleanRepository) GetCommit(hash string) (*object.Commit, error)

GetCommit retrieves a commit by hash

func (*CleanRepository) GetHEAD

func (r *CleanRepository) GetHEAD() (string, error)

GetHEAD returns what HEAD points to

func (*CleanRepository) GetObject

func (r *CleanRepository) GetObject(hash string) (object.Object, error)

GetObject retrieves any Git object by hash

func (*CleanRepository) GetTag

func (r *CleanRepository) GetTag(name string) (string, error)

GetTag retrieves a specific tag

func (*CleanRepository) GetTree

func (r *CleanRepository) GetTree(hash string) (*object.Tree, error)

GetTree retrieves a tree by hash

func (*CleanRepository) ListBranches

func (r *CleanRepository) ListBranches() ([]Branch, error)

ListBranches returns all branches

func (*CleanRepository) ListTags

func (r *CleanRepository) ListTags() ([]Tag, error)

ListTags returns all tags

func (*CleanRepository) Log

func (r *CleanRepository) Log(startHash string, limit int) ([]*object.Commit, error)

Log returns commit history starting from a given commit

func (*CleanRepository) ResolveRef

func (r *CleanRepository) ResolveRef(ref string) (string, error)

ResolveRef resolves a reference to a commit hash

type CleanStagingArea

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

CleanStagingArea represents the Git index/staging area

func NewCleanStagingArea

func NewCleanStagingArea() *CleanStagingArea

NewCleanStagingArea creates a new staging area

type CleanWorkspace

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

CleanWorkspace manages the mutable working directory state Separated from repository to maintain clean architecture

func NewCleanWorkspace

func NewCleanWorkspace(repo *CleanRepository, working WorkingStorage) *CleanWorkspace

NewCleanWorkspace creates a new workspace

func (*CleanWorkspace) Add

func (w *CleanWorkspace) Add(path string) error

Add stages a file

func (*CleanWorkspace) Checkout

func (w *CleanWorkspace) Checkout(branch string) error

Checkout switches branches and updates working directory

func (*CleanWorkspace) GetStagingArea

func (w *CleanWorkspace) GetStagingArea() *CleanStagingArea

GetStagingArea returns the current staging area

func (*CleanWorkspace) ListFiles

func (w *CleanWorkspace) ListFiles() ([]string, error)

ListFiles returns all files in working directory

func (*CleanWorkspace) ReadFile

func (w *CleanWorkspace) ReadFile(path string) ([]byte, error)

ReadFile reads a file from working directory

func (*CleanWorkspace) Remove

func (w *CleanWorkspace) Remove(path string) error

Remove stages a file removal

func (*CleanWorkspace) Reset

func (w *CleanWorkspace) Reset()

Reset resets staging area

func (*CleanWorkspace) Status

func (w *CleanWorkspace) Status() (*Status, error)

Status returns the current workspace status

func (*CleanWorkspace) WriteFile

func (w *CleanWorkspace) WriteFile(path string, content []byte) error

WriteFile writes a file to working directory

type Config

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

Config manages repository configuration

func NewConfig

func NewConfig(store ConfigStore) *Config

NewConfig creates a new config manager

func (*Config) Delete

func (c *Config) Delete(key string) error

Delete removes a configuration value

func (*Config) Get

func (c *Config) Get(key string) (string, error)

Get retrieves a configuration value

func (*Config) List

func (c *Config) List() (map[string]string, error)

List returns all configuration values

func (*Config) Set

func (c *Config) Set(key, value string) error

Set sets a configuration value

type ConfigStore

type ConfigStore interface {
	// Get retrieves a config value
	Get(key string) (string, error)

	// Set stores a config value
	Set(key, value string) error

	// Delete removes a config value
	Delete(key string) error

	// List returns all config keys
	List() (map[string]string, error)

	// Close releases any resources
	io.Closer
}

ConfigStore defines the interface for configuration storage

type DiagnosticLogger

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

DiagnosticLogger provides detailed logging for debugging

func NewDiagnosticLogger

func NewDiagnosticLogger(prefix string) *DiagnosticLogger

NewDiagnosticLogger creates a diagnostic logger

func (*DiagnosticLogger) Log

func (d *DiagnosticLogger) Log(format string, args ...interface{})

Log logs a diagnostic message

func (*DiagnosticLogger) LogData

func (d *DiagnosticLogger) LogData(label string, data interface{})

LogData logs data with a label

func (*DiagnosticLogger) LogError

func (d *DiagnosticLogger) LogError(operation string, err error)

LogError logs an error

type Event

type Event struct {
	Type      string
	Timestamp time.Time
	Data      interface{}
}

Event represents a repository event

type EventHandler

type EventHandler func(event Event) error

EventHandler handles repository events

type EventManager

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

EventManager manages repository events and webhooks

func NewEventManager

func NewEventManager() *EventManager

NewEventManager creates a new event manager

func (*EventManager) Publish

func (em *EventManager) Publish(event Event)

Publish sends an event to all handlers

func (*EventManager) Subscribe

func (em *EventManager) Subscribe(handler EventHandler)

Subscribe adds an event handler

type FileWorkingStorage

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

FileWorkingStorage is a file-based implementation of WorkingStorage

func NewFileWorkingStorage

func NewFileWorkingStorage(root string) *FileWorkingStorage

func (*FileWorkingStorage) Clear

func (f *FileWorkingStorage) Clear() error

func (*FileWorkingStorage) Close

func (f *FileWorkingStorage) Close() error

func (*FileWorkingStorage) Delete

func (f *FileWorkingStorage) Delete(path string) error

func (*FileWorkingStorage) Exists

func (f *FileWorkingStorage) Exists(path string) bool

func (*FileWorkingStorage) List

func (f *FileWorkingStorage) List() ([]string, error)

func (*FileWorkingStorage) Read

func (f *FileWorkingStorage) Read(path string) ([]byte, error)

func (*FileWorkingStorage) Write

func (f *FileWorkingStorage) Write(path string, content []byte) error

type GitOperations

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

GitOperations provides high-level Git operations using the clean architecture

func NewGitOperations

func NewGitOperations(repo *Repository, workspace *Workspace, config *Config) *GitOperations

NewGitOperations creates a new Git operations handler

func (*GitOperations) Add

func (g *GitOperations) Add(path string) error

Add stages a file (example of how operations would work)

func (*GitOperations) Commit

func (g *GitOperations) Commit(message string) (string, error)

Commit creates a new commit (example of clean separation)

type MemoryConfigStore

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

MemoryConfigStore is an in-memory config store

func NewMemoryConfigStore

func NewMemoryConfigStore() *MemoryConfigStore

func (*MemoryConfigStore) Close

func (m *MemoryConfigStore) Close() error

func (*MemoryConfigStore) Delete

func (m *MemoryConfigStore) Delete(key string) error

func (*MemoryConfigStore) Get

func (m *MemoryConfigStore) Get(key string) (string, error)

func (*MemoryConfigStore) List

func (m *MemoryConfigStore) List() (map[string]string, error)

func (*MemoryConfigStore) Set

func (m *MemoryConfigStore) Set(key, value string) error

type MemoryObjectStore

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

MemoryObjectStore is a simple in-memory implementation of ObjectStore

func NewMemoryObjectStore

func NewMemoryObjectStore() *MemoryObjectStore

func (*MemoryObjectStore) Close

func (m *MemoryObjectStore) Close() error

func (*MemoryObjectStore) Exists

func (m *MemoryObjectStore) Exists(hash string) bool

func (*MemoryObjectStore) Get

func (m *MemoryObjectStore) Get(hash string) (object.Object, error)

func (*MemoryObjectStore) List

func (m *MemoryObjectStore) List() ([]string, error)

func (*MemoryObjectStore) Put

func (m *MemoryObjectStore) Put(obj object.Object) (string, error)

func (*MemoryObjectStore) Size

func (m *MemoryObjectStore) Size() (int64, error)

type MemoryRefStore

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

MemoryRefStore is a simple in-memory implementation of RefStore

func NewMemoryRefStore

func NewMemoryRefStore() *MemoryRefStore

func (*MemoryRefStore) Close

func (m *MemoryRefStore) Close() error

func (*MemoryRefStore) DeleteRef

func (m *MemoryRefStore) DeleteRef(name string) error

func (*MemoryRefStore) GetHEAD

func (m *MemoryRefStore) GetHEAD() (string, error)

func (*MemoryRefStore) GetRef

func (m *MemoryRefStore) GetRef(name string) (string, error)

func (*MemoryRefStore) ListRefs

func (m *MemoryRefStore) ListRefs() (map[string]string, error)

func (*MemoryRefStore) SetHEAD

func (m *MemoryRefStore) SetHEAD(ref string) error

func (*MemoryRefStore) UpdateRef

func (m *MemoryRefStore) UpdateRef(name, hash string) error

type MemoryWorkingStorage

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

MemoryWorkingStorage is an in-memory implementation of WorkingStorage

func NewMemoryWorkingStorage

func NewMemoryWorkingStorage() *MemoryWorkingStorage

func (*MemoryWorkingStorage) Clear

func (m *MemoryWorkingStorage) Clear() error

func (*MemoryWorkingStorage) Close

func (m *MemoryWorkingStorage) Close() error

func (*MemoryWorkingStorage) Delete

func (m *MemoryWorkingStorage) Delete(path string) error

func (*MemoryWorkingStorage) Exists

func (m *MemoryWorkingStorage) Exists(path string) bool

func (*MemoryWorkingStorage) List

func (m *MemoryWorkingStorage) List() ([]string, error)

func (*MemoryWorkingStorage) Read

func (m *MemoryWorkingStorage) Read(path string) ([]byte, error)

func (*MemoryWorkingStorage) Write

func (m *MemoryWorkingStorage) Write(path string, content []byte) error

type ObjectStore

type ObjectStore interface {
	// Get retrieves an object by its hash
	Get(hash string) (object.Object, error)

	// Put stores an object and returns its hash
	Put(obj object.Object) (string, error)

	// Exists checks if an object exists
	Exists(hash string) bool

	// List returns all object hashes
	List() ([]string, error)

	// Size returns the total size of stored objects
	Size() (int64, error)

	// Close releases any resources
	io.Closer
}

ObjectStore defines the interface for storing immutable Git objects

func AdaptOldStore

func AdaptOldStore(oldStore *storage.Store) ObjectStore

Example of how to adapt old store

type ObjectStoreAdapter

type ObjectStoreAdapter struct {
	Store *storage.Store
}

ObjectStoreAdapter adapts existing storage.Store to ObjectStore interface

func (*ObjectStoreAdapter) Close

func (a *ObjectStoreAdapter) Close() error

func (*ObjectStoreAdapter) Exists

func (a *ObjectStoreAdapter) Exists(hash string) bool

func (*ObjectStoreAdapter) Get

func (a *ObjectStoreAdapter) Get(hash string) (object.Object, error)

func (*ObjectStoreAdapter) List

func (a *ObjectStoreAdapter) List() ([]string, error)

func (*ObjectStoreAdapter) Put

func (a *ObjectStoreAdapter) Put(obj object.Object) (string, error)

func (*ObjectStoreAdapter) Size

func (a *ObjectStoreAdapter) Size() (int64, error)

type Operations

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

Operations provides high-level Git operations using clean architecture

func NewOperations

func NewOperations(repo *CleanRepository, workspace *CleanWorkspace, config *Config) *Operations

NewOperations creates a new operations handler

func (*Operations) Add

func (ops *Operations) Add(paths ...string) error

Add stages files

func (*Operations) Branch

func (ops *Operations) Branch(name string) error

Branch creates a new branch

func (*Operations) Checkout

func (ops *Operations) Checkout(branch string) error

Checkout switches to a branch

func (*Operations) Commit

func (ops *Operations) Commit(message string) (string, error)

Commit creates a new commit

func (*Operations) DeleteBranch

func (ops *Operations) DeleteBranch(name string) error

DeleteBranch deletes a branch

func (*Operations) Init

func (ops *Operations) Init() error

Init initializes a new repository

func (*Operations) Log

func (ops *Operations) Log(limit int) ([]*object.Commit, error)

Log returns commit history

func (*Operations) Merge

func (ops *Operations) Merge(branch string, message string) (string, error)

Merge merges another branch into current branch

func (*Operations) Status

func (ops *Operations) Status() (*Status, error)

Status returns repository status

func (*Operations) Tag

func (ops *Operations) Tag(name string) error

Tag creates a new tag

type RefStore

type RefStore interface {
	// GetRef returns the hash a reference points to
	GetRef(name string) (string, error)

	// UpdateRef updates a reference to point to a new hash
	UpdateRef(name string, hash string) error

	// DeleteRef removes a reference
	DeleteRef(name string) error

	// ListRefs returns all references
	ListRefs() (map[string]string, error)

	// GetHEAD returns what HEAD points to
	GetHEAD() (string, error)

	// SetHEAD updates HEAD
	SetHEAD(target string) error

	// Close releases any resources
	io.Closer
}

RefStore defines the interface for managing references

func AdaptOldRefManager

func AdaptOldRefManager(oldRefManager *refs.RefManager) RefStore

Example of how to use adapters during migration

type RefStoreAdapter

type RefStoreAdapter struct {
	RefManager *refs.RefManager
	Store      refs.RefStore
}

RefStoreAdapter adapts refs.RefManager to RefStore interface

func (*RefStoreAdapter) Close

func (a *RefStoreAdapter) Close() error

func (*RefStoreAdapter) DeleteRef

func (a *RefStoreAdapter) DeleteRef(name string) error

func (*RefStoreAdapter) GetHEAD

func (a *RefStoreAdapter) GetHEAD() (string, error)

func (*RefStoreAdapter) GetRef

func (a *RefStoreAdapter) GetRef(name string) (string, error)

func (*RefStoreAdapter) ListRefs

func (a *RefStoreAdapter) ListRefs() (map[string]string, error)

func (*RefStoreAdapter) SetHEAD

func (a *RefStoreAdapter) SetHEAD(ref string) error

func (*RefStoreAdapter) UpdateRef

func (a *RefStoreAdapter) UpdateRef(name, hash string) error

type Repository

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

Repository represents the core immutable Git repository It only handles objects and references, no mutable state

func NewRepository

func NewRepository(objects ObjectStore, refs RefStore) *Repository

NewRepository creates a new repository with the given stores

func (*Repository) Objects

func (r *Repository) Objects() ObjectStore

Objects returns the object store

func (*Repository) Refs

func (r *Repository) Refs() RefStore

Refs returns the reference store

type StagedEntry

type StagedEntry struct {
	Hash string
	Mode string
}

StagedEntry represents a file in the staging area

type StagingArea

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

StagingArea represents the Git staging area (index)

func NewStagingArea

func NewStagingArea() *StagingArea

NewStagingArea creates a new empty staging area

type Stash

type Stash struct {
	ID           string
	Message      string
	Author       object.Author
	TreeHash     string // Hash of the stashed tree
	ParentCommit string // Commit hash when stash was created
	Timestamp    time.Time
	Changes      map[string][]byte // Unstaged changes
	Index        map[string]string // Staged changes (path -> hash)
	Untracked    map[string][]byte // Untracked files
}

Stash represents a saved workspace state

type StashManager

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

StashManager manages repository stashes

func NewStashManager

func NewStashManager(repo *CleanRepository, workspace *CleanWorkspace) *StashManager

NewStashManager creates a new stash manager

func (*StashManager) Apply

func (sm *StashManager) Apply(id string) error

Apply applies a stash to the current workspace

func (*StashManager) Create

func (sm *StashManager) Create(message string, includeUntracked bool) (*Stash, error)

Create creates a new stash

func (*StashManager) Drop

func (sm *StashManager) Drop(id string) error

Drop removes a stash

func (*StashManager) Get

func (sm *StashManager) Get(id string) (*Stash, error)

Get returns a specific stash

func (*StashManager) List

func (sm *StashManager) List() []*Stash

List returns all stashes

func (*StashManager) Pop

func (sm *StashManager) Pop(id string) error

Pop applies and drops a stash

type Status

type Status struct {
	Branch    string
	Staged    []string
	Modified  []string
	Untracked []string
}

Status represents the workspace status

func (*Status) Clean

func (s *Status) Clean() bool

Clean checks if working directory is clean

type Tag

type Tag struct {
	Name string
	Hash string
}

Tag represents a Git tag

type Webhook

type Webhook struct {
	ID          string   `json:"id"`
	URL         string   `json:"url"`
	Events      []string `json:"events"`
	Secret      string   `json:"secret"`
	ContentType string   `json:"content_type"`
}

Webhook represents a repository webhook

type WebhookManager

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

WebhookManager manages repository webhooks

func NewWebhookManager

func NewWebhookManager() *WebhookManager

NewWebhookManager creates a new webhook manager

func (*WebhookManager) Get

func (wm *WebhookManager) Get(id string) (*Webhook, error)

Get returns a specific webhook

func (*WebhookManager) List

func (wm *WebhookManager) List() []*Webhook

List returns all webhooks

func (*WebhookManager) Register

func (wm *WebhookManager) Register(url string, events []string, secret string) (*Webhook, error)

Register adds a new webhook

func (*WebhookManager) Trigger

func (wm *WebhookManager) Trigger(event string, repoName string, data interface{})

Trigger sends an event to all registered webhooks

func (*WebhookManager) Unregister

func (wm *WebhookManager) Unregister(id string) error

Unregister removes a webhook

type WebhookPayload

type WebhookPayload struct {
	Event      string      `json:"event"`
	Repository string      `json:"repository"`
	Timestamp  time.Time   `json:"timestamp"`
	Data       interface{} `json:"data"`
}

WebhookPayload represents the payload sent to webhooks

type WorkingStorage

type WorkingStorage interface {
	// Read reads a file from working directory
	Read(path string) ([]byte, error)

	// Write writes a file to working directory
	Write(path string, data []byte) error

	// Delete removes a file from working directory
	Delete(path string) error

	// List returns all files in working directory
	List() ([]string, error)

	// Clear removes all files
	Clear() error

	// Exists checks if a file exists
	Exists(path string) bool

	// Close releases any resources
	io.Closer
}

WorkingStorage defines the interface for working directory storage

type Workspace

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

Workspace represents the mutable working directory state

func NewWorkspace

func NewWorkspace(repo *Repository, working WorkingStorage) *Workspace

NewWorkspace creates a new workspace

Jump to

Keyboard shortcuts

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