mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-15 10:12:06 +03:00
repo: remove the memory-only repo for now
This commit is contained in:
parent
4ef2c11040
commit
be6e653f15
@ -12,16 +12,13 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/99designs/keyring"
|
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
"github.com/go-git/go-billy/v5/memfs"
|
|
||||||
"github.com/go-git/go-billy/v5/osfs"
|
"github.com/go-git/go-billy/v5/osfs"
|
||||||
gogit "github.com/go-git/go-git/v5"
|
gogit "github.com/go-git/go-git/v5"
|
||||||
"github.com/go-git/go-git/v5/config"
|
"github.com/go-git/go-git/v5/config"
|
||||||
"github.com/go-git/go-git/v5/plumbing"
|
"github.com/go-git/go-git/v5/plumbing"
|
||||||
"github.com/go-git/go-git/v5/plumbing/filemode"
|
"github.com/go-git/go-git/v5/plumbing/filemode"
|
||||||
"github.com/go-git/go-git/v5/plumbing/object"
|
"github.com/go-git/go-git/v5/plumbing/object"
|
||||||
"github.com/go-git/go-git/v5/storage/memory"
|
|
||||||
|
|
||||||
"github.com/MichaelMure/git-bug/util/lamport"
|
"github.com/MichaelMure/git-bug/util/lamport"
|
||||||
)
|
)
|
||||||
@ -30,9 +27,8 @@ var _ ClockedRepo = &GoGitRepo{}
|
|||||||
var _ TestedRepo = &GoGitRepo{}
|
var _ TestedRepo = &GoGitRepo{}
|
||||||
|
|
||||||
type GoGitRepo struct {
|
type GoGitRepo struct {
|
||||||
r *gogit.Repository
|
r *gogit.Repository
|
||||||
path string
|
path string
|
||||||
isMemory bool
|
|
||||||
|
|
||||||
clocksMutex sync.Mutex
|
clocksMutex sync.Mutex
|
||||||
clocks map[string]lamport.Clock
|
clocks map[string]lamport.Clock
|
||||||
@ -41,6 +37,7 @@ type GoGitRepo struct {
|
|||||||
localStorage billy.Filesystem
|
localStorage billy.Filesystem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OpenGoGitRepo open an already existing repo at the given path
|
||||||
func OpenGoGitRepo(path string, clockLoaders []ClockLoader) (*GoGitRepo, error) {
|
func OpenGoGitRepo(path string, clockLoaders []ClockLoader) (*GoGitRepo, error) {
|
||||||
path, err := detectGitPath(path)
|
path, err := detectGitPath(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -60,7 +57,6 @@ func OpenGoGitRepo(path string, clockLoaders []ClockLoader) (*GoGitRepo, error)
|
|||||||
repo := &GoGitRepo{
|
repo := &GoGitRepo{
|
||||||
r: r,
|
r: r,
|
||||||
path: path,
|
path: path,
|
||||||
isMemory: false,
|
|
||||||
clocks: make(map[string]lamport.Clock),
|
clocks: make(map[string]lamport.Clock),
|
||||||
keyring: k,
|
keyring: k,
|
||||||
localStorage: osfs.New(filepath.Join(path, "git-bug")),
|
localStorage: osfs.New(filepath.Join(path, "git-bug")),
|
||||||
@ -100,7 +96,6 @@ func InitGoGitRepo(path string) (*GoGitRepo, error) {
|
|||||||
return &GoGitRepo{
|
return &GoGitRepo{
|
||||||
r: r,
|
r: r,
|
||||||
path: filepath.Join(path, ".git"),
|
path: filepath.Join(path, ".git"),
|
||||||
isMemory: false,
|
|
||||||
clocks: make(map[string]lamport.Clock),
|
clocks: make(map[string]lamport.Clock),
|
||||||
keyring: k,
|
keyring: k,
|
||||||
localStorage: osfs.New(filepath.Join(path, ".git", "git-bug")),
|
localStorage: osfs.New(filepath.Join(path, ".git", "git-bug")),
|
||||||
@ -122,32 +117,12 @@ func InitBareGoGitRepo(path string) (*GoGitRepo, error) {
|
|||||||
return &GoGitRepo{
|
return &GoGitRepo{
|
||||||
r: r,
|
r: r,
|
||||||
path: path,
|
path: path,
|
||||||
isMemory: false,
|
|
||||||
clocks: make(map[string]lamport.Clock),
|
clocks: make(map[string]lamport.Clock),
|
||||||
keyring: k,
|
keyring: k,
|
||||||
localStorage: osfs.New(filepath.Join(path, "git-bug")),
|
localStorage: osfs.New(filepath.Join(path, "git-bug")),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitMemoryGoGitRepo() (*GoGitRepo, error) {
|
|
||||||
r, err := gogit.Init(memory.NewStorage(), nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
k := keyring.NewArrayKeyring(nil)
|
|
||||||
|
|
||||||
repo := &GoGitRepo{
|
|
||||||
r: r,
|
|
||||||
isMemory: true,
|
|
||||||
clocks: make(map[string]lamport.Clock),
|
|
||||||
keyring: k,
|
|
||||||
localStorage: memfs.New(),
|
|
||||||
}
|
|
||||||
|
|
||||||
return repo, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func detectGitPath(path string) (string, error) {
|
func detectGitPath(path string) (string, error) {
|
||||||
// normalize the path
|
// normalize the path
|
||||||
path, err := filepath.Abs(path)
|
path, err := filepath.Abs(path)
|
||||||
@ -686,10 +661,6 @@ func (repo *GoGitRepo) GetLocalRemote() string {
|
|||||||
|
|
||||||
// EraseFromDisk delete this repository entirely from the disk
|
// EraseFromDisk delete this repository entirely from the disk
|
||||||
func (repo *GoGitRepo) EraseFromDisk() error {
|
func (repo *GoGitRepo) EraseFromDisk() error {
|
||||||
if repo.isMemory {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
path := filepath.Clean(strings.TrimSuffix(repo.path, string(filepath.Separator)+".git"))
|
path := filepath.Clean(strings.TrimSuffix(repo.path, string(filepath.Separator)+".git"))
|
||||||
|
|
||||||
// fmt.Println("Cleaning repo:", path)
|
// fmt.Println("Cleaning repo:", path)
|
||||||
|
Loading…
Reference in New Issue
Block a user