repositories

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	CONFIG  = "config"
	INDEX   = "index"
	OBJECTS = "objects"
	REFS    = "refs"
)

定义各个git组件的名称

View Source
const MaxPathDepth = 256

MaxPathDepth 最大路径深度

Variables

This section is empty.

Functions

func Bind

func Bind(cc context.Context) context.Context

Bind ...

func CloseAll

func CloseAll(all []io.Closer, reverse bool) error

CloseAll 关闭列表中的所有项目, 如果 reverse==true, 就从后往前执行

Types

type AlgorithmManager

type AlgorithmManager interface {
	Find(name string) (git.Algorithm, error)

	FindCompression(name string) (git.Compression, error)

	FindDigest(name string) (git.Digest, error)

	FindPathMapping(name string) (git.PathMapping, error)
}

AlgorithmManager 是用来管理各种算法的对象

type Binding

type Binding interface {
	SetLib(lib Lib) error
	GetLib() (Lib, error)
}

Binding ...

func GetBinding

func GetBinding(cc context.Context) (Binding, error)

GetBinding ...

type ComponentHolder

type ComponentHolder struct {
	Component any // 缓存的组件实例对象
	// Lifecycle    Lifecycle             // 用于组件的生命周期控制
	Registration ComponentRegistration // 注册信息
	Classes      []string              // Registration.Class 解析后的内容
	Aliases      []string              // Registration.Alias 解析后的内容
}

ComponentHolder ...

type ComponentLifecycleManager

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

ComponentLifecycleManager ...

func (*ComponentLifecycleManager) CreateItems

func (inst *ComponentLifecycleManager) CreateItems(callback func(h *ComponentHolder) error)

CreateItems 创建各个组件的实例,并把组件的生命周期添加到 LifecycleManager

func (*ComponentLifecycleManager) GetComponents

func (inst *ComponentLifecycleManager) GetComponents() ComponentManager

GetComponents ...

func (*ComponentLifecycleManager) GetLifecycles

func (inst *ComponentLifecycleManager) GetLifecycles() LifecycleManager

GetLifecycles ...

func (*ComponentLifecycleManager) Init

Init ...

type ComponentManager

type ComponentManager interface {
	Add(h *ComponentHolder) error
	Register(reg *ComponentRegistration) (*ComponentHolder, error)
	GetByName(name string) (*ComponentHolder, error)
	ListByClass(className string) ([]*ComponentHolder, error)
	ListAll() []*ComponentHolder
}

ComponentManager 代表组件管理器

func NewComponentManager

func NewComponentManager(mode safe.Mode) ComponentManager

NewComponentManager 新建 ComponentManager 对象

type ComponentRegistration

type ComponentRegistration struct {
	Name     string
	Class    string // 格式参考: <html class="" />
	Alias    string // 格式参考: <html class="" />
	Enabled  bool
	Priority int

	// 以下是针对各种上下文的初始化处理函数
	// 它们的返回值为(组件对象,错误信息)
	OnInitForSystem     func(ctx *SystemContext) (any, error)
	OnInitForUser       func(ctx *UserContext) (any, error)
	OnInitForRepository func(ctx *RepositoryContext) (any, error)
	OnInitForSession    func(ctx *SessionContext) (any, error)
	OnInitForWorktree   func(ctx *WorktreeContext) (any, error)
	OnInitForSubmodule  func(ctx *SubmoduleContext) (any, error)
}

ComponentRegistration 表示组件的注册信息

type ComponentRegistry

type ComponentRegistry interface {
	ListRegistrations() []*ComponentRegistration
}

ComponentRegistry ...

type Config

type Config interface {
	Node
	Configuration
	Save() error
	Load() error
}

Config 统一的抽象配置接口

type ConfigChain

type ConfigChain interface {
	Config() Config

	Mix() ConfigChain

	Parent() ConfigChain

	Scope() ConfigScope

	FindByScope(scope ConfigScope) ConfigChain

	Load() error
}

ConfigChain ... 表示配置对象构成的责任链

type ConfigChainFactory

type ConfigChainFactory interface {
	Create(p *ConfigChainParams) ConfigChain
	Root() ConfigChain
}

ConfigChainFactory ...

type ConfigChainParams

type ConfigChainParams struct {
	File       afs.Path
	Parent     ConfigChain
	Scope      ConfigScope
	Required   bool
	IgnoreCase bool
}

ConfigChainParams 创建配置连的参数

type ConfigScope

type ConfigScope int

ConfigScope 表示配置属性的作用域

const (
	ConfigScopeDefault    ConfigScope = 0
	ConfigScopeSystem     ConfigScope = 1
	ConfigScopeUser       ConfigScope = 2
	ConfigScopeRepository ConfigScope = 3
	ConfigScopeMix        ConfigScope = 4
	ConfigScopeCommand    ConfigScope = 11
	ConfigScopeWorktree   ConfigScope = 12
	ConfigScopeFinal      ConfigScope = 99
)

定义配置属性的作用域

type Configuration

type Configuration interface {
	Import(src map[string]string)
	Export() map[string]string
	GetProperty(name string) string
	SetProperty(name, value string)
	Clear()
}

Configuration 表示基本的配置文件

type Context

type Context struct {
	Closer         io.Closer
	ComLifeManager ComponentLifecycleManager
	FS             afs.FS
	SafeMode       safe.Mode
	Path           afs.Path
}

Context 表示仓库对象的周边环境

type Core

type Core struct {
	WD afs.Path // 工作目录

	Context *Context

	Config ConfigChain // 配置链:repo -> user -> system

	Head HEAD

	Index Index

	Layout Layout

	Objects Objects

	Refs Refs

	Repository Repository

	Workspace Workspace // aka the default worktree

	Worktrees Worktrees

	Submodules Submodules

	SessionFactory SessionFactory

	Digest      git.Digest      // default="SHA-1"
	Compression git.Compression // default="DEFLATE"
	PathMapping git.PathMapping // default="xx/xxxx"
}

Core 表示仓库对象的核心

type CoreConfigurer

type CoreConfigurer interface {
	Configure(c *Core) error
}

CoreConfigurer 是用来配置 repository.Core 的组件 [inject:".git-core-configurer"]

type Entity

type Entity interface {
	OpenReader() (io.ReadCloser, error)
}

Entity ...

type FileReaderPool

type FileReaderPool interface {
	io.Closer

	OpenReader(file afs.Path, op *afs.Options) (io.ReadSeekCloser, error)
}

FileReaderPool ...

type Finder

type Finder interface {
	Find(pwd afs.Path) ([]afs.Path, error)
}

Finder 表示一个git仓库查找器,用来查找指定路径下的所有仓库

type HEAD interface {
	Node

	GetValue(s Session) (git.ReferenceName, error)
}

HEAD ...

type ImportPackParams

type ImportPackParams struct {
	ID        git.PackID
	PackFile  afs.Path
	IdxFile   afs.Path
	MoveFiles bool
}

ImportPackParams ...

type ImportPackResult

type ImportPackResult struct {
	Params *ImportPackParams
	ID     git.PackID
	Pack   Pack
}

ImportPackResult ...

type Index

type Index interface {
	Node
}

Index ...

type InfoFolder

type InfoFolder interface {
	Path() afs.Path
}

InfoFolder 代表 {.git}/objects/info

type Layout

type Layout interface {

	// 取工作目录
	WD() afs.Path

	Workspace() afs.Path
	DotGit() afs.Path
	Repository() afs.Path
	Config() afs.Path
	Index() afs.Path
	HEAD() afs.Path
	Objects() afs.Path
	Refs() afs.Path

	IsBare() bool
	IsSubmodule() bool
	IsWorktree() bool
}

Layout 表示关于一个仓库的几个关键路径

type LayoutBuilder

type LayoutBuilder struct {
	WD     afs.Path
	DotGit afs.Path

	Repository afs.Path // the repository core dir
	Workspace  afs.Path

	SubmodulePoint afs.Path
	WorktreePoint  afs.Path
	CorePoint      afs.Path

	Config  afs.Path
	HEAD    afs.Path
	Index   afs.Path
	Objects afs.Path
	Refs    afs.Path
}

LayoutBuilder 仓库布局对象创建器

func (*LayoutBuilder) Create

func (inst *LayoutBuilder) Create() Layout

Create 创建仓库布局对象

type Lib

type Lib interface {
	FS() afs.FS

	SystemContext() *SystemContext

	Loader() Loader

	Finder() Finder

	Locator() Locator

	InstructionServiceManager() ServiceManager

	Connectors() pktline.ConnectorManager

	// 把这个 Lib 绑定到指定的 Context
	Bind(cc context.Context) context.Context
}

Lib ...

func GetLib

func GetLib(cc context.Context) (Lib, error)

GetLib 从给定的 Context 取与之绑定的 Lib 对象

type LibAgent

type LibAgent interface {
	GetLib() (Lib, error)
}

LibAgent ... [inject:"#git-lib-agent"]

type Lifecycle

Lifecycle 组件生命周期的注册信息

type LifecycleManager

type LifecycleManager interface {
	AddComponent(com any) (*Lifecycle, error)
	AddLifecycle(lc *Lifecycle) (*Lifecycle, error)
	AddRegistry(reg LifecycleRegistry) (*Lifecycle, error)

	// Open a new life
	Open() (io.Closer, error)
}

LifecycleManager ...

func NewLifecycleManager

func NewLifecycleManager(mode safe.Mode) LifecycleManager

NewLifecycleManager 新建一个生命周期管理器

type LifecycleRegistry

type LifecycleRegistry interface {
	Lifecycle() *Lifecycle
}

LifecycleRegistry ...

type Loader

type Loader interface {
	Load(l Layout) (Repository, error)
	LoadWithPath(path afs.Path) (Repository, error)
}

Loader ...

type Locator

type Locator interface {
	Locate(pwd afs.Path) (Layout, error)
}

Locator 表示一个git仓库定位器,用来确定仓库的准确位置

type Meta

type Meta struct {
	Context context.Context
	Name    string   // the command name
	WD      afs.Path // Working Directory
}

Meta 包含git-command-object 的基本字段

type Node

type Node interface {
	Path() afs.Path
	NodeType() NodeType
}

Node 提供节点的路径

type NodeInfo

type NodeInfo struct {
	Name string
	Path afs.FS
	Type NodeType
}

NodeInfo 表示 git 中的一个 dir 或者 file

type NodeType

type NodeType string

NodeType 表示Node的类型

const (
	NodeConfig    NodeType = ".git/config"
	NodeObjects   NodeType = ".git/objects"
	NodeDotGit    NodeType = ".git"
	NodeWorkspace NodeType = ".git/.."
	NodeIndex     NodeType = ".git/index"
	NodeHEAD      NodeType = ".git/HEAD"
)

定义各种 Node 的类型

type Object

type Object git.Object

Object ... 建议直接使用 git.Object

type Objects

type Objects interface {
	Path() afs.Path

	GetSparseObject(oid git.ObjectID) SparseObject

	GetPack(pid git.PackID) Pack

	ListPacks() []git.PackID

	Info() InfoFolder
}

Objects 接口代表 {.git}/objects

type Pack

type Pack interface {
	GetID() git.PackID

	GetDotIdx() afs.Path

	GetDotPack() afs.Path

	GetObject(oid git.ObjectID) PackObject

	Exists() bool
}

Pack 代表 {.git}/objects/pack

type PackBuilder

type PackBuilder interface {
	io.Closer

	WriteObject(o *Object, data io.Reader) (*Object, error)
}

PackBuilder 读写包对象

type PackFile

type PackFile interface {
	ReadPackObject(item *git.PackIndexItem) (io.ReadCloser, *git.Object, error)
}

PackFile 表示包内对象索引

type PackIndex

type PackIndex interface {
	Count() int64

	Get(index int64) (*git.PackIndexItem, error)

	List(index, limit int64) ([]*git.PackIndexItem, error)

	Find(id git.ObjectID) (*git.PackIndexItem, error)
}

PackIndex 表示包内对象索引

type PackObject

type PackObject interface {
	GetID() git.ObjectID
	Container() Pack
}

PackObject 表示包内对象

type PackReadCloser

type PackReadCloser interface {
	io.Closer
	GetIndex() PackIndex
	GetPack() PackFile
}

PackReadCloser 表示包内对象索引

type Packs

type Packs interface {
	FindPackObject(oid git.ObjectID) (PackObject, error)

	FindPackObjectInPack(pid git.PackID, oid git.ObjectID) (PackObject, error)

	ReadPackObject(o PackObject) (*git.Object, io.ReadCloser, error)

	CheckPack(pid git.PackID, flags pack.CheckFlag) error

	ListPacks() ([]git.PackID, error)

	NewPackBuilder() PackBuilder

	ImportPack(p *ImportPackParams) (*ImportPackResult, error)
}

Packs 读写包对象

type Ref

type Ref interface {
	Path() afs.Path

	Name() git.ReferenceName

	Exists() bool

	GetValue(s Session) (git.ObjectID, error)
}

Ref is the key-value for .git/refs/*

type Refs

type Refs interface {
	Path() afs.Path

	GetRef(name git.ReferenceName) Ref

	List() []git.ReferenceName
}

Refs is the key-value for .git/refs/*

type Repository

type Repository interface {
	Layout() Layout

	Config() ConfigChain

	HEAD() HEAD

	Index() Index

	Refs() Refs

	Objects() Objects

	Worktrees() Worktrees

	Submodules() Submodules

	Digest() git.Digest           // default="SHA-1"
	Compression() git.Compression // default="DEFLATE"
	PathMapping() git.PathMapping // default="xx/xxxx"

	OpenSession() (Session, error)
}

Repository ...

type RepositoryContext

type RepositoryContext struct {
	Context

	Parent      *UserContext
	Config      Config
	ConfigChain ConfigChain
	ConfigFile  afs.Path // like '.git/config'
	Layout      Layout
	Facade      Repository
	Submodules  Submodules
	Worktrees   Worktrees
}

RepositoryContext ...

type RepositoryContextLoader

type RepositoryContextLoader interface {
	Load(params *RepositoryParams) (*RepositoryContext, error)
}

RepositoryContextLoader ...

type RepositoryParams

type RepositoryParams struct {
	Mode   safe.Mode
	Layout Layout
	Parent *UserContext
}

RepositoryParams ...

type Service

type Service interface {
}

Service is the Runner for Command

type ServiceManager

type ServiceManager interface {
	Find(name string) (Service, error)
}

ServiceManager 用来管理已注册的服务

type ServiceRegistration

type ServiceRegistration struct {
	Name    string
	Service Service
}

ServiceRegistration ...

type ServiceRegistry

type ServiceRegistry interface {
	ListRegistrations() []*ServiceRegistration
}

ServiceRegistry ... [inject:".git-instruction-registry"]

type Session

type Session interface {
	io.Closer

	// 取仓库接口
	GetRepository() Repository

	// 根据名称,取指定的组件
	GetComponent(name string) (any, error)

	// 取工作目录
	GetWD() afs.Path

	// 取仓库布局
	GetLayout() Layout

	// 新建临时文件
	NewTemporaryFile(dir afs.Path) afs.Path

	NewTemporaryBuffer(dir afs.Path) TemporaryBuffer

	NewReaderPool(size int) afs.ReaderPool

	GetReaderPool() afs.ReaderPool

	GetObjectContext() *objects.Context

	// objects
	ReadObject(id git.ObjectID) (*git.Object, io.ReadCloser, error)

	WriteObject(o *git.Object, data io.Reader) (*git.Object, error)

	GetSparseObjects() SparseObjects

	GetPacks() Packs

	LoadText(id git.ObjectID) (string, *git.Object, error)
	LoadBinary(id git.ObjectID) ([]byte, *git.Object, error)

	// commit, tag, tree
	LoadCommit(id git.ObjectID) (*git.Commit, error)
	LoadTag(id git.ObjectID) (*git.Tag, error)
	LoadTree(id git.ObjectID) (*git.Tree, error)

	// refs
	LoadRef(r Ref) (*git.Ref, error)
	SaveRef(r *git.Ref) error

	// HEAD
	LoadHEAD(head HEAD) (*git.HEAD, error)
	SaveHEAD(h *git.HEAD) error
}

Session ...

type SessionContext

type SessionContext struct {
	Context

	Parent *RepositoryContext
	Facade Session
}

SessionContext ...

type SessionContextLoader

type SessionContextLoader interface {
	Load(params *SessionParams) (*SessionContext, error)
}

SessionContextLoader ...

type SessionFactory

type SessionFactory interface {
	OpenSession(repo Repository) (Session, error)
}

SessionFactory ...

type SessionParams

type SessionParams struct {
	Mode   safe.Mode
	Parent *RepositoryContext
}

SessionParams ...

type SparseObject

type SparseObject interface {
	Path() afs.Path

	GetID() git.ObjectID

	Exists() bool
}

SparseObject 表示稀疏对象

type SparseObjects

type SparseObjects interface {
	ReadSparseObject(o SparseObject) (*git.Object, io.ReadCloser, error)
	ReadSparseObjectRaw(o SparseObject) (io.ReadCloser, error)
	WriteSparseObject(o *git.Object, data io.Reader) (*git.Object, error)
	WriteSparseObjectRaw(o *git.Object, data io.Reader) (*git.Object, error)
}

SparseObjects 读写稀疏对象

type Submodule

type Submodule interface {
	Name() string
	URL() string
	Path() string
	IsActive() bool

	Workspace() Workspace
	Exists() bool
}

Submodule ...

type SubmoduleContext

type SubmoduleContext struct {
	Context

	Parent *RepositoryContext
	Layout Layout
	Facade Submodule
}

SubmoduleContext ...

type SubmoduleContextLoader

type SubmoduleContextLoader interface {
	Load(params *SubmoduleParams) (*SubmoduleContext, error)
}

SubmoduleContextLoader ...

type SubmoduleParams

type SubmoduleParams struct {
	Mode   safe.Mode
	Layout Layout
	Parent *RepositoryContext
}

SubmoduleParams ...

type Submodules

type Submodules interface {
	Get(name string) Submodule
	List() []Submodule
}

Submodules ...

type SystemContext

type SystemContext struct {
	Context

	Config             Config
	ConfigChain        ConfigChain
	ConfigChainFactory ConfigChainFactory
	ConfigFile         afs.Path // like '/etc/gitconfig'

	Facade SystemSpace
	Lib    Lib

	// components
	AllComponents        []ComponentRegistry
	SystemComponents     []*ComponentRegistration
	UserComponents       []*ComponentRegistration
	RepositoryComponents []*ComponentRegistration
	SessionComponents    []*ComponentRegistration
	WorktreeComponents   []*ComponentRegistration
	SubmoduleComponents  []*ComponentRegistration

	// loaders
	SystemContextLoader     SystemContextLoader
	UserContextLoader       UserContextLoader
	RepositoryContextLoader RepositoryContextLoader
	SessionContextLoader    SessionContextLoader
	WorktreeContextLoader   WorktreeContextLoader
	SubmoduleContextLoader  SubmoduleContextLoader

	// for repo
	RepositoryFinder  Finder
	RepositoryLocator Locator
	RepositoryLoader  Loader
}

SystemContext ...

type SystemContextLoader

type SystemContextLoader interface {
	Load(params *SystemParams) (*SystemContext, error)
}

SystemContextLoader ...

type SystemParams

type SystemParams struct {
	Mode safe.Mode
}

SystemParams ...

type SystemSpace

type SystemSpace interface {
	Lib() Lib
}

SystemSpace 是 SystemContext 的 facade

type Task

type Task interface {
	GetMeta() *Meta
	Run() error
}

Task 接口表示git-command-object 的外观

type TemporaryBuffer

type TemporaryBuffer interface {
	io.Closer
	io.Writer

	GetTemporaryFile() afs.Path

	GetFlushSize() int

	SetFlushSize(size int)

	SaveToFile(dst afs.Path) error
}

TemporaryBuffer ...

type UserContext

type UserContext struct {
	Context

	Parent      *SystemContext
	Home        afs.Path // 用户的主文件夹
	Config      Config
	ConfigChain ConfigChain
	ConfigFile  afs.Path // like '~/.gitconfig'
	Facade      UserSpace
}

UserContext ...

type UserContextLoader

type UserContextLoader interface {
	Load(params *UserParams) (*UserContext, error)
}

UserContextLoader ...

type UserParams

type UserParams struct {
	Mode   safe.Mode
	Home   afs.Path
	Parent *SystemContext
}

UserParams ...

type UserSpace

type UserSpace interface {
	Home() afs.Path

	SystemSpace() SystemSpace
}

UserSpace 是 UserContext 的 facade

type Workspace

type Workspace interface {

	// alias of WorkingDirectory
	Path() afs.Path

	// return the working directory
	WorkingDirectory() afs.Path

	// return the '.git' file or directory
	DotGit() afs.Path
}

Workspace 表示工作区目录

type Worktree

type Worktree interface {
	Name() string
	Workspace() Workspace
	Exists() bool
}

Worktree ...

type WorktreeContext

type WorktreeContext struct {
	Context

	Parent *RepositoryContext
	Layout Layout
	Facade Worktree
}

WorktreeContext ...

type WorktreeContextLoader

type WorktreeContextLoader interface {
	Load(params *WorktreeParams) (*WorktreeContext, error)
}

WorktreeContextLoader ...

type WorktreeParams

type WorktreeParams struct {
	Mode   safe.Mode
	Layout Layout
	Parent *RepositoryContext
}

WorktreeParams ...

type Worktrees

type Worktrees interface {
	Get(name string) Worktree
	List() []Worktree
}

Worktrees ...

Jump to

Keyboard shortcuts

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