Documentation
¶
Index ¶
- Constants
- Variables
- type BareRepoStore
- type BranchInfo
- type BundleCreatedHook
- type CommitInfo
- type DiffPayload
- type DiffResponse
- type FetchByHashPayload
- type FetchIncrementalPayload
- type FetchIncrementalResponse
- type FileStat
- type FindLeavesResponse
- type Handler
- type HandlerConfig
- type HasCommitPayload
- type HasCommitResponse
- type ListCommitsPayload
- type ListCommitsResponse
- type MergeHook
- type MergeHookEvent
- type MergeResult
- type PushBundlePayload
- type PushBundleResponse
- type PushIncrementalBundlePayload
- type Request
- type RequestType
- type Response
- type Service
- func (s *Service) ApplyBundle(ctx context.Context, workspaceID string, bundle []byte) error
- func (s *Service) CreateBundle(ctx context.Context, workspaceID string) ([]byte, string, error)
- func (s *Service) CreateIncrementalBundle(ctx context.Context, workspaceID, baseCommit string) ([]byte, string, error)
- func (s *Service) CreateTaskBranch(ctx context.Context, workspaceID, taskID, baseBranch string) error
- func (s *Service) DeleteTaskBranch(ctx context.Context, workspaceID, taskID string) error
- func (s *Service) Diff(ctx context.Context, workspaceID, from, to string) (string, error)
- func (s *Service) DiffNumStat(ctx context.Context, workspaceID, from, to string) ([]FileStat, error)
- func (s *Service) HasCommit(ctx context.Context, workspaceID, commitHash string) (bool, error)
- func (s *Service) Init(ctx context.Context, workspaceID string) error
- func (s *Service) Leaves(ctx context.Context, workspaceID string) ([]string, error)
- func (s *Service) ListBranches(ctx context.Context, workspaceID string) ([]BranchInfo, error)
- func (s *Service) Log(ctx context.Context, workspaceID string, limit int) ([]CommitInfo, error)
- func (s *Service) MergeTaskBranch(ctx context.Context, workspaceID, taskID, targetBranch string) (*MergeResult, error)
- func (s *Service) SafeApplyBundle(ctx context.Context, workspaceID string, bundleData []byte) error
- func (s *Service) SetBundleCreatedHook(h BundleCreatedHook)
- func (s *Service) SetMergeHook(h MergeHook)
- func (s *Service) VerifyBundle(ctx context.Context, workspaceID string, bundleData []byte) error
- type SessionValidator
- type VerifyBundlePayload
- type VerifyBundleResponse
Constants ¶
const ( StatusOK = "ok" StatusError = "error" )
const ProtocolID = "/lango/p2p-git/1.0.0"
ProtocolID is the libp2p protocol identifier for git bundle exchange.
const TaskBranchPrefix = "task/"
TaskBranchPrefix is the ref prefix for per-task branches.
Variables ¶
var ErrEmptyRepo = errors.New("empty repository")
ErrEmptyRepo indicates the workspace repository has no commits.
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 BundleCreatedHook ¶ added in v0.7.0
BundleCreatedHook observes bundle creation.
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 ¶
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 FileStat ¶ added in v0.7.0
type FileStat struct {
FilePath string `json:"filePath"`
LinesAdded int `json:"linesAdded"`
LinesRemoved int `json:"linesRemoved"`
}
FileStat is a per-file diff summary.
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 ¶
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 MergeHook ¶ added in v0.7.0
type MergeHook func(ctx context.Context, event MergeHookEvent)
MergeHook observes task branch merges.
type MergeHookEvent ¶ added in v0.7.0
type MergeHookEvent struct {
WorkspaceID string
TaskID string
TargetBranch string
MergeCommit string
SourceCommit string
PreviousTarget string
Files []FileStat
}
MergeHookEvent captures a task-branch merge for external observers.
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 ¶
ApplyBundle applies a git bundle to the workspace repository.
func (*Service) CreateBundle ¶
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 ¶
DeleteTaskBranch deletes the task/{taskID} branch from the workspace. The operation is idempotent — if the branch doesn't exist, it returns nil.
func (*Service) DiffNumStat ¶ added in v0.7.0
func (s *Service) DiffNumStat(ctx context.Context, workspaceID, from, to string) ([]FileStat, error)
DiffNumStat returns per-file added/removed line counts between two commits.
func (*Service) ListBranches ¶
ListBranches returns all branches in 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 ¶
SafeApplyBundle verifies, snapshots refs, applies, and rolls back on failure.
func (*Service) SetBundleCreatedHook ¶ added in v0.7.0
func (s *Service) SetBundleCreatedHook(h BundleCreatedHook)
SetBundleCreatedHook registers a post-create bundle hook.
func (*Service) SetMergeHook ¶ added in v0.7.0
SetMergeHook registers a post-merge hook.
type SessionValidator ¶
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.