Documentation
¶
Index ¶
- Constants
- func Bind(cc context.Context) context.Context
- func CloseAll(all []io.Closer, reverse bool) error
- type AlgorithmManager
- type Binding
- type ComponentHolder
- type ComponentLifecycleManager
- func (inst *ComponentLifecycleManager) CreateItems(callback func(h *ComponentHolder) error)
- func (inst *ComponentLifecycleManager) GetComponents() ComponentManager
- func (inst *ComponentLifecycleManager) GetLifecycles() LifecycleManager
- func (inst *ComponentLifecycleManager) Init(items []*ComponentRegistration, mode safe.Mode) *ComponentLifecycleManager
- type ComponentManager
- type ComponentRegistration
- type ComponentRegistry
- type Config
- type ConfigChain
- type ConfigChainFactory
- type ConfigChainParams
- type ConfigScope
- type Configuration
- type Context
- type Core
- type CoreConfigurer
- type Entity
- type FileReaderPool
- type Finder
- type HEAD
- type ImportPackParams
- type ImportPackResult
- type Index
- type InfoFolder
- type Layout
- type LayoutBuilder
- type Lib
- type LibAgent
- type Lifecycle
- type LifecycleManager
- type LifecycleRegistry
- type Loader
- type Locator
- type Meta
- type Node
- type NodeInfo
- type NodeType
- type Object
- type Objects
- type Pack
- type PackBuilder
- type PackFile
- type PackIndex
- type PackObject
- type PackReadCloser
- type Packs
- type Ref
- type Refs
- type Repository
- type RepositoryContext
- type RepositoryContextLoader
- type RepositoryParams
- type Service
- type ServiceManager
- type ServiceRegistration
- type ServiceRegistry
- type Session
- type SessionContext
- type SessionContextLoader
- type SessionFactory
- type SessionParams
- type SparseObject
- type SparseObjects
- type Submodule
- type SubmoduleContext
- type SubmoduleContextLoader
- type SubmoduleParams
- type Submodules
- type SystemContext
- type SystemContextLoader
- type SystemParams
- type SystemSpace
- type Task
- type TemporaryBuffer
- type UserContext
- type UserContextLoader
- type UserParams
- type UserSpace
- type Workspace
- type Worktree
- type WorktreeContext
- type WorktreeContextLoader
- type WorktreeParams
- type Worktrees
Constants ¶
const ( CONFIG = "config" INDEX = "index" OBJECTS = "objects" REFS = "refs" )
定义各个git组件的名称
const MaxPathDepth = 256
MaxPathDepth 最大路径深度
Variables ¶
This section is empty.
Functions ¶
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 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 ¶
func (inst *ComponentLifecycleManager) Init(items []*ComponentRegistration, mode safe.Mode) *ComponentLifecycleManager
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 ¶
CoreConfigurer 是用来配置 repository.Core 的组件 [inject:".git-core-configurer"]
type FileReaderPool ¶
type FileReaderPool interface {
io.Closer
OpenReader(file afs.Path, op *afs.Options) (io.ReadSeekCloser, error)
}
FileReaderPool ...
type ImportPackParams ¶
ImportPackParams ...
type ImportPackResult ¶
type ImportPackResult struct {
Params *ImportPackParams
ID git.PackID
Pack Pack
}
ImportPackResult ...
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 仓库布局对象创建器
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 ...
type Lifecycle ¶
type Lifecycle struct {
OnCreate application.OnCreateFunc
OnStartPre application.OnStartPreFunc
OnStart application.OnStartFunc
OnStartPost application.OnStartPostFunc
OnStopPre application.OnStopPreFunc
OnStop application.OnStopFunc
OnStopPost application.OnStopPostFunc
OnDestroy application.OnDestroyFunc
}
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 Meta ¶
type Meta struct {
Context context.Context
Name string // the command name
WD afs.Path // Working Directory
}
Meta 包含git-command-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 ¶
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 ¶
PackObject 表示包内对象
type PackReadCloser ¶
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 ServiceManager ¶
ServiceManager 用来管理已注册的服务
type ServiceRegistration ¶
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 ¶
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 ¶
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 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 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 ...
Source Files
¶
- algorithm_manager.go
- binding.go
- com_and_life.go
- components.go
- config.go
- const.go
- context_loaders.go
- contexts.go
- core.go
- file_pool.go
- head.go
- index.go
- instruction.go
- layout.go
- lib.go
- life.go
- location.go
- locator.go
- node.go
- objects.go
- objects_pack.go
- objects_sparse.go
- refs.go
- repository.go
- session.go
- space.go
- store_utils.go
- submodule.go
- temporary.go
- workspace.go
- worktree.go