fork of go-git with some jj specific features
1# Extending go-git 2 3`go-git` was built in a highly extensible manner, which enables some of its functionalities to be changed or extended without the need of changing its codebase. Here are the key extensibility features: 4 5## Dot Git Storers 6 7Dot git storers are the components responsible for storing the Git internal files, including objects and references. 8 9The built-in storer implementations include [memory](storage/memory) and [filesystem](storage/filesystem). The `memory` storer stores all the data in memory, and its use look like this: 10 11```go 12 r, err := git.Init(memory.NewStorage(), nil) 13``` 14 15The `filesystem` storer stores the data in the OS filesystem, and can be used as follows: 16 17```go 18 r, err := git.Init(filesystem.NewStorage(osfs.New("/tmp/foo")), nil) 19``` 20 21New implementations can be created by implementing the [storage.Storer interface](storage/storer.go#L16). 22 23## Filesystem 24 25Git repository worktrees are managed using a filesystem abstraction based on [go-billy](https://github.com/go-git/go-billy). The Git operations will take place against the specific filesystem implementation. Initialising a repository in Memory can be done as follows: 26 27```go 28 fs := memfs.New() 29 r, err := git.Init(memory.NewStorage(), fs) 30``` 31 32The same operation can be done against the OS filesystem: 33 34```go 35 fs := osfs.New("/tmp/foo") 36 r, err := git.Init(memory.NewStorage(), fs) 37``` 38 39New filesystems (e.g. cloud based storage) could be created by implementing `go-billy`'s [Filesystem interface](https://github.com/go-git/go-billy/blob/326c59f064021b821a55371d57794fbfb86d4cb3/fs.go#L52). 40 41## Transport Schemes 42 43Git supports various transport schemes, including `http`, `https`, `ssh`, `git`, `file`. `go-git` defines the [transport.Transport interface](plumbing/transport/common.go#L48) to represent them. 44 45The built-in implementations can be replaced by calling `transport.Register`. 46 47An example of changing the built-in `https` implementation to skip TLS could look like this: 48 49```go 50 customClient := &http.Client{ 51 Transport: &http.Transport{ 52 TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, 53 }, 54 } 55 56 transport.Register("https", githttp.NewClient(customClient)) 57``` 58 59Some internal implementations enables code reuse amongst the different transport implementations. Some of these may be made public in the future (e.g. `plumbing/transport/internal/common`). 60 61## Cache 62 63Several different operations across `go-git` lean on caching of objects in order to achieve optimal performance. The caching functionality is defined by the [cache.Object interface](plumbing/cache/common.go#L17). 64 65Two built-in implementations are `cache.ObjectLRU` and `cache.BufferLRU`. However, the caching functionality can be customized by implementing the interface `cache.Object` interface. 66 67## Hash 68 69`go-git` uses the `crypto.Hash` interface to represent hash functions. The built-in implementations are `github.com/pjbgf/sha1cd` for SHA1 and Go's `crypto/SHA256`. 70 71The default hash functions can be changed by calling `hash.RegisterHash`. 72```go 73 func init() { 74 hash.RegisterHash(crypto.SHA1, sha1.New) 75 } 76``` 77 78New `SHA1` or `SHA256` hash functions that implement the `hash.RegisterHash` interface can be registered by calling `RegisterHash`.