-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
modify git-bug to use go-billy filesystem and not touch OS filesystem directly #2
Comments
In short, your goal is going to be to remove entirely (of maybe keep it just for testing purpose?) the I see two different kind of usages: the Bleve full text search index, and writing/reading cache files. Disclaimer: the following is very raw thoughts, the reality is likely going to be different once confronted with the code. Bleve index: cache files: |
Thanks Michael that's very helpful and sounds exactly what I need. For the p2p features I'm going to use a filesystem like interface (so go-git and git-bug would behave as for the CLI reading and writing I'll also need to try making a git-bug library, so might try that first. |
@MichaelMure I've been familiarising myself with the parts of the code at commit (2 Nov, #25b0c71), so just repo cache and not bleve, which accesses the disk. The following is a summary of what is making use of Places which must be modified for use with either os or go-billy filesystem:
Optional / later - places which can continue calling
And here are the things that will or may need to be implemented by a new interface, when using
File methods used:
see also:
As I understand your suggestion, this can be done by adding Then Is this what you had in mind, sound sensible? If the above is good, what's the recommended way to implement this in ./repository, should I create a file gogit_storage.go containing a |
Pretty much. I looked in more details how GetPath is used:
So it seems that everything that is needed is an access to $RepoPath/.git/git-bug with a I believe the changes needed to the Repo interfaces is as follow: diff --git a/repository/repo.go b/repository/repo.go
index 4b45a1c5..d34995f9 100644
--- a/repository/repo.go
+++ b/repository/repo.go
@@ -4,6 +4,8 @@ package repository
import (
"errors"
+ "github.com/go-git/go-billy/v5"
+
"github.com/MichaelMure/git-bug/util/lamport"
)
@@ -20,6 +22,7 @@ type Repo interface {
RepoKeyring
RepoCommon
RepoData
+ RepoStorage
}
// ClockedRepo is a Repo that also has Lamport clocks
@@ -48,9 +51,6 @@ type RepoKeyring interface {
// RepoCommon represent the common function the we want all the repo to implement
type RepoCommon interface {
- // GetPath returns the path to the repo.
- GetPath() string
-
// GetUserName returns the name the the user has used to configure git
GetUserName() (string, error)
@@ -64,6 +64,11 @@ type RepoCommon interface {
GetRemotes() (map[string]string, error)
}
+type RepoStorage interface {
+ // LocalStorage return a billy.Filesystem giving access to $RepoPath/.git/git-bug
+ LocalStorage() billy.Filesystem
+}
+
// RepoData give access to the git data storage
type RepoData interface {
// FetchRefs fetch git refs from a remote
@@ -145,4 +150,10 @@ type TestedRepo interface {
type repoTest interface {
// AddRemote add a new remote to the repository
AddRemote(name string, url string) error
+
+ // GetLocalRemote return the URL to use to add this repo as a local remote
+ GetLocalRemote() string
+
+ // EraseFromDisk delete this repository entirely from the disk
+ EraseFromDisk() error
} |
Naming the function |
Thanks Michael, just skimming as I'm done for today. I'd shy away from using Will look more tomorrow. |
The browser LocalStorage could be a legit implementation of this interface, depending on your usage ;) It's the same name but a very different context so I think it's fine. |
|
type RepoStorage interface {
// LocalStorage return a billy.Filesystem giving access to $RepoPath/.git/git-bug
LocalStorage() billy.Filesystem
// ....
GlobalStorage() billy.Filesystem
// ...
TempStorage() billy.Filesystem
} Don't you think that's reasonable? |
The same concept is already used for |
What are the three categories used for? |
Only
|
My point is, |
The choice is yours obviously, but I may make suggestions when I understand better 😄. So your distinction is that LS is a store per repo, whereas GS is more like a PC filesystem holding several repos? |
It doesn't matter if this filesystem also hold the actual repos. What matter is that this function return the same shared filesystem when called from any repo. |
Ok. I'm not sure, but for my use case GS may be what's needed but I'm still familiarising myself with go-git, which to confuse matters can have both Storage (for git objects) and go-billy.Filesystem (for a working tree) as I expect you know. Storage's everywhere! I'll probably go to code next and figure out these details that way. You've been very helpful, thanks. So far it looks straightforward except perhaps for the file locking, although I think that should be ok too. EDIT: no worries for now, but I'm not getting the need for GS, LS and TS. If you need the repos to be on the same storage, you can just give them all the same storage object, if separate you give each one a separate storage object. I don't see why this would be the choice of the code accessing the repo. |
There is no need for GS and TS ... for now. But I could see usage for them in the future. An example would be the Keyring. The Keyring is a shared (=global in the git terminology) storage space for credentials. When a bridge is configured in a repo, the credentials become available in every other repo for when you configure your next bridge. At the moment the Keyring is already swapped out by a memory-only implementation in the mock repo so it's not a problem but if we were to re-implement that, we could use this GS and read/write files there. TS is just another example, I don't have usage in mind just yet, but a temporary file is useful sometimes. |
I think I'll start with |
@MichaelMure I see there's a 'select' mechanism which writes to disk, presumably so the CLI can have a current issue which is being addressed with multiple commands, so is git-bug writing cache and bleve index to disk for similar CLI convenience, or are there good reasons for wanting them to persist for longer periods (from one day to the next, ideally forever etc)? This is not an immediate issue, but something for me to think about. |
Persist over long period not necessarily but across multiple CLI call, yes. All those files (cache index, bleve, select) could be deleted without loosing too much. The downside is that everything will be re-indexed with the next call, which can be expensive. |
@MichaelMure I'm a month behind master, so maybe some things are in flux but I'm wondering about when git-bug uses git to do operations, and when it uses go-git. Is the code which spawns git commands obsolete or being refactored, or is it still in use and likely to remain so? A couple of other points:
|
The old git CLI implementation is still around but it's not used anymore in the master branch. I think I'll keep it around until I'm sure things are really stable. Which implementation is used is defined in those functions: https://github.com/MichaelMure/git-bug/blob/master/commands/env.go#L49-L137 |
So in your case we'll have to figure out a way to inject the proper Repo implementation. There is plenty of way to do that, we'll just have to find the less ugly one. |
Thanks, that's what I was hoping 😄. I've been looking at the code you reference just now. To call If we decide I should import them elsewhere I'd need to capitalise them, although my first thought is that I wouldn't use your I'm not sure there's an issue regarding 'injecting' the repos as you're already using |
Status updateThe branch gobilly-test-initfs at commit 25b0c71 is working with the git portal proof-of-concept, branch main at happybeing/p2p-git-portal-poc@9c6f2ef). The above allows work to continue in parallel on both the p2p git portal and to integrate these changes with the latest git-bug (including bleve indexing), and provide an improved API to allow use of git-bug with an external billy.Filesystem. Remaining git-bug tasks
|
git-bug currently uses operating system filesystem calls directly (e.g. https://golang.org/pkg/os/ in git-bug/cache) which prevents it being compiled for Web Assembly.
This task is modify git-bug to use the go-billy filesystem interface, also used by go-git which git-bug relies on for git functionality. Then to add support for wasm builds of git-bug, by building with this fork of go-billy (branch
support-build-wasm
) which has been modified to build successfully withGOARCH=wasm
.The text was updated successfully, but these errors were encountered: