gitbundle

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusOK    = "ok"
	StatusError = "error"
)
View Source
const ProtocolID = "/lango/p2p-git/1.0.0"

ProtocolID is the libp2p protocol identifier for git bundle exchange.

View Source
const TaskBranchPrefix = "task/"

TaskBranchPrefix is the ref prefix for per-task branches.

Variables

View Source
var ErrEmptyRepo = errors.New("empty repository")

ErrEmptyRepo indicates the workspace repository has no commits.

View Source
var ErrMissingPrerequisite = errors.New("missing prerequisite commits")

ErrMissingPrerequisite indicates the bundle requires commits not present in the repo.

Functions

This section is empty.

Types

type BareRepoStore

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

BareRepoStore manages bare git repositories per workspace.

func NewBareRepoStore

func NewBareRepoStore(baseDir string, logger *zap.Logger) *BareRepoStore

NewBareRepoStore creates a BareRepoStore rooted at baseDir.

func (*BareRepoStore) Init

func (s *BareRepoStore) Init(workspaceID string) error

Init initializes a bare git repository for the given workspace.

func (*BareRepoStore) List

func (s *BareRepoStore) List() ([]string, error)

List returns all workspace IDs that have initialized repos.

func (*BareRepoStore) Remove

func (s *BareRepoStore) Remove(workspaceID string) error

Remove deletes the bare repo for a workspace.

func (*BareRepoStore) Repo

func (s *BareRepoStore) Repo(workspaceID string) (*git.Repository, error)

Repo returns the git.Repository for a workspace, opening it if needed.

func (*BareRepoStore) RepoPath

func (s *BareRepoStore) RepoPath(workspaceID string) string

RepoPath returns the filesystem path for a workspace's bare repo.

type BranchInfo

type BranchInfo struct {
	Name       string    `json:"name"`
	CommitHash string    `json:"commitHash"`
	IsHead     bool      `json:"isHead"`
	UpdatedAt  time.Time `json:"updatedAt"`
}

BranchInfo describes a branch in the workspace repository.

type CommitInfo

type CommitInfo struct {
	Hash      string    `json:"hash"`
	Message   string    `json:"message"`
	Author    string    `json:"author"`
	Timestamp time.Time `json:"timestamp"`
}

CommitInfo represents a summary of a git commit.

type DiffPayload

type DiffPayload struct {
	From string `json:"from"`
	To   string `json:"to"`
}

DiffPayload requests a diff between two commits.

type DiffResponse

type DiffResponse struct {
	Diff string `json:"diff"`
}

DiffResponse contains a diff output.

type FetchByHashPayload

type FetchByHashPayload struct {
	CommitHash string `json:"commitHash"`
}

FetchByHashPayload requests a bundle containing a specific commit.

type FetchIncrementalPayload

type FetchIncrementalPayload struct {
	BaseCommit string `json:"baseCommit"`
}

FetchIncrementalPayload requests an incremental bundle from a base commit.

type FetchIncrementalResponse

type FetchIncrementalResponse struct {
	Bundle     []byte `json:"bundle"`
	HeadCommit string `json:"headCommit"`
	IsFull     bool   `json:"isFull"`
}

FetchIncrementalResponse contains an incremental bundle.

type FindLeavesResponse

type FindLeavesResponse struct {
	Leaves []string `json:"leaves"`
}

FindLeavesResponse contains DAG leaf commit hashes.

type Handler

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

Handler handles git protocol streams.

func NewHandler

func NewHandler(cfg HandlerConfig) *Handler

NewHandler creates a new git protocol stream handler.

func (*Handler) StreamHandler

func (h *Handler) StreamHandler() network.StreamHandler

StreamHandler returns the libp2p stream handler function.

type HandlerConfig

type HandlerConfig struct {
	Service       *Service
	Validator     SessionValidator
	MaxBundleSize int64 // bytes, default 50MB
	Logger        *zap.Logger
}

HandlerConfig configures the git protocol handler.

type HasCommitPayload

type HasCommitPayload struct {
	CommitHash string `json:"commitHash"`
}

HasCommitPayload checks if a commit exists in the workspace.

type HasCommitResponse

type HasCommitResponse struct {
	Exists bool   `json:"exists"`
	Hash   string `json:"hash"`
}

HasCommitResponse indicates whether a commit exists.

type ListCommitsPayload

type ListCommitsPayload struct {
	Limit int `json:"limit,omitempty"`
}

ListCommitsPayload requests a commit listing.

type ListCommitsResponse

type ListCommitsResponse struct {
	Commits []CommitInfo `json:"commits"`
}

ListCommitsResponse contains commit information.

type MergeResult

type MergeResult struct {
	Success       bool     `json:"success"`
	MergeCommit   string   `json:"mergeCommit,omitempty"`
	ConflictFiles []string `json:"conflictFiles,omitempty"`
	Message       string   `json:"message"`
}

MergeResult describes the outcome of a branch merge.

type PushBundlePayload

type PushBundlePayload struct {
	Bundle    []byte `json:"bundle"`    // base64-encoded in JSON
	CommitMsg string `json:"commitMsg"` // description of the push
	SenderDID string `json:"senderDid"`
}

PushBundlePayload contains a git bundle for pushing.

type PushBundleResponse

type PushBundleResponse struct {
	Applied bool   `json:"applied"`
	Message string `json:"message,omitempty"`
}

PushBundleResponse is returned after a successful push.

type PushIncrementalBundlePayload

type PushIncrementalBundlePayload struct {
	Bundle     []byte `json:"bundle"`
	BaseCommit string `json:"baseCommit"`
	CommitMsg  string `json:"commitMsg"`
	SenderDID  string `json:"senderDid"`
}

PushIncrementalBundlePayload contains an incremental git bundle.

type Request

type Request struct {
	Type        RequestType     `json:"type"`
	WorkspaceID string          `json:"workspaceId"`
	Token       string          `json:"token"`
	Payload     json.RawMessage `json:"payload,omitempty"`
	Timestamp   time.Time       `json:"timestamp"`
}

Request is a git protocol request.

type RequestType

type RequestType string

RequestType identifies git protocol request types.

const (
	RequestPushBundle            RequestType = "push_bundle"
	RequestFetchByHash           RequestType = "fetch_by_hash"
	RequestListCommits           RequestType = "list_commits"
	RequestFindLeaves            RequestType = "find_leaves"
	RequestDiff                  RequestType = "diff"
	RequestPushIncrementalBundle RequestType = "push_incremental_bundle"
	RequestFetchIncremental      RequestType = "fetch_incremental"
	RequestVerifyBundle          RequestType = "verify_bundle"
	RequestHasCommit             RequestType = "has_commit"
)

type Response

type Response struct {
	Status string          `json:"status"`
	Error  string          `json:"error,omitempty"`
	Data   json.RawMessage `json:"data,omitempty"`
}

Response is a git protocol response.

type Service

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

Service provides git bundle operations for workspace repositories.

func NewService

func NewService(store *BareRepoStore, logger *zap.Logger) *Service

NewService creates a new git bundle service.

func (*Service) ApplyBundle

func (s *Service) ApplyBundle(ctx context.Context, workspaceID string, bundle []byte) error

ApplyBundle applies a git bundle to the workspace repository.

func (*Service) CreateBundle

func (s *Service) CreateBundle(ctx context.Context, workspaceID string) ([]byte, string, error)

CreateBundle creates a git bundle containing all refs in the workspace repo. Returns the bundle bytes and the HEAD commit hash.

func (*Service) CreateIncrementalBundle

func (s *Service) CreateIncrementalBundle(ctx context.Context, workspaceID, baseCommit string) ([]byte, string, error)

CreateIncrementalBundle creates a bundle containing only commits after baseCommit. If baseCommit is not found, it falls back to a full bundle.

func (*Service) CreateTaskBranch

func (s *Service) CreateTaskBranch(ctx context.Context, workspaceID, taskID, baseBranch string) error

CreateTaskBranch creates a task/{taskID} branch in the workspace bare repo. If baseBranch is empty, it defaults to the current HEAD. The operation is idempotent — if the branch already exists, it returns nil.

func (*Service) DeleteTaskBranch

func (s *Service) DeleteTaskBranch(ctx context.Context, workspaceID, taskID string) error

DeleteTaskBranch deletes the task/{taskID} branch from the workspace. The operation is idempotent — if the branch doesn't exist, it returns nil.

func (*Service) Diff

func (s *Service) Diff(ctx context.Context, workspaceID, from, to string) (string, error)

Diff returns the diff between two commits.

func (*Service) HasCommit

func (s *Service) HasCommit(ctx context.Context, workspaceID, commitHash string) (bool, error)

HasCommit checks if a commit exists in the workspace repository.

func (*Service) Init

func (s *Service) Init(ctx context.Context, workspaceID string) error

Init initializes a bare repository for a workspace.

func (*Service) Leaves

func (s *Service) Leaves(ctx context.Context, workspaceID string) ([]string, error)

Leaves returns the DAG leaf commits (commits with no children).

func (*Service) ListBranches

func (s *Service) ListBranches(ctx context.Context, workspaceID string) ([]BranchInfo, error)

ListBranches returns all branches in the workspace repository.

func (*Service) Log

func (s *Service) Log(ctx context.Context, workspaceID string, limit int) ([]CommitInfo, error)

Log returns the most recent commits from the workspace repository.

func (*Service) MergeTaskBranch

func (s *Service) MergeTaskBranch(ctx context.Context, workspaceID, taskID, targetBranch string) (*MergeResult, error)

MergeTaskBranch merges task/{taskID} into targetBranch using git merge-tree. This works on bare repos without a working tree by using merge-tree --write-tree, commit-tree, and update-ref.

func (*Service) SafeApplyBundle

func (s *Service) SafeApplyBundle(ctx context.Context, workspaceID string, bundleData []byte) error

SafeApplyBundle verifies, snapshots refs, applies, and rolls back on failure.

func (*Service) VerifyBundle

func (s *Service) VerifyBundle(ctx context.Context, workspaceID string, bundleData []byte) error

VerifyBundle verifies that a bundle's prerequisites are present in the workspace repo.

type SessionValidator

type SessionValidator func(token string) (string, bool)

SessionValidator validates a session token and returns the peer DID.

type VerifyBundlePayload

type VerifyBundlePayload struct {
	Bundle []byte `json:"bundle"`
}

VerifyBundlePayload contains a bundle to verify.

type VerifyBundleResponse

type VerifyBundleResponse struct {
	Valid   bool   `json:"valid"`
	Message string `json:"message,omitempty"`
}

VerifyBundleResponse indicates the verification result.

Jump to

Keyboard shortcuts

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