refactor: use namespace instead of application of applicationName

This commit is contained in:
Steve Moyer 2022-05-26 13:39:13 -04:00
parent e29f58bf85
commit e120fdb97e
No known key found for this signature in database
GPG Key ID: D8D464C9D22FB8E0
5 changed files with 28 additions and 28 deletions

View File

@ -14,7 +14,7 @@ import (
"github.com/MichaelMure/git-bug/util/interrupt"
)
const gitBugApplicationName = "git-bug"
const gitBugNamespace = "git-bug"
// Env is the environment of a command
type Env struct {
@ -56,7 +56,7 @@ func loadRepo(env *Env) func(*cobra.Command, []string) error {
return fmt.Errorf("unable to get the current working directory: %q", err)
}
env.repo, err = repository.OpenGoGitRepo(cwd, gitBugApplicationName, []repository.ClockLoader{bug.ClockLoader})
env.repo, err = repository.OpenGoGitRepo(cwd, gitBugNamespace, []repository.ClockLoader{bug.ClockLoader})
if err == repository.ErrNotARepo {
return fmt.Errorf("%s must be run from within a git repo", rootCommandName)
}

View File

@ -336,15 +336,15 @@ func Read(repo repository.ClockedRepo, id entity.Id) (*ProjectConfig, error) {
}
func Example_entity() {
const gitBugApplicationName = "git-bug"
const gitBugNamespace = "git-bug"
// Note: this example ignore errors for readability
// Note: variable names get a little confusing as we are simulating both side in the same function
// Let's start by defining two git repository and connecting them as remote
repoRenePath, _ := os.MkdirTemp("", "")
repoIsaacPath, _ := os.MkdirTemp("", "")
repoRene, _ := repository.InitGoGitRepo(repoRenePath, gitBugApplicationName)
repoIsaac, _ := repository.InitGoGitRepo(repoIsaacPath, gitBugApplicationName)
repoRene, _ := repository.InitGoGitRepo(repoRenePath, gitBugNamespace)
repoIsaac, _ := repository.InitGoGitRepo(repoIsaacPath, gitBugNamespace)
_ = repoRene.AddRemote("origin", repoIsaacPath)
_ = repoIsaac.AddRemote("origin", repoRenePath)

View File

@ -11,7 +11,7 @@ import (
// This program will randomly generate a collection of bugs in the repository
// of the current path
func main() {
const gitBugApplicationName = "git-bug"
const gitBugNamespace = "git-bug"
dir, err := os.Getwd()
if err != nil {
@ -22,7 +22,7 @@ func main() {
bug.ClockLoader,
}
repo, err := repository.OpenGoGitRepo(dir, gitBugApplicationName, loaders)
repo, err := repository.OpenGoGitRepo(dir, gitBugNamespace, loaders)
if err != nil {
panic(err)
}

View File

@ -50,11 +50,11 @@ type GoGitRepo struct {
localStorage billy.Filesystem
}
// OpenGoGitRepo opens an already existing repo at the given path and with
// the specified application name. Given a repository path of "~/myrepo"
// and an application name of "git-bug", local storage for the application
// will be configured at "~/myrepo/.git/git-bug".
func OpenGoGitRepo(path, application string, clockLoaders []ClockLoader) (*GoGitRepo, error) {
// OpenGoGitRepo opens an already existing repo at the given path and
// with the specified LocalStorage namespace. Given a repository path
// of "~/myrepo" and a namespace of "git-bug", local storage for the
// GoGitRepo will be configured at "~/myrepo/.git/git-bug".
func OpenGoGitRepo(path, namespace string, clockLoaders []ClockLoader) (*GoGitRepo, error) {
path, err := detectGitPath(path)
if err != nil {
return nil, err
@ -76,7 +76,7 @@ func OpenGoGitRepo(path, application string, clockLoaders []ClockLoader) (*GoGit
clocks: make(map[string]lamport.Clock),
indexes: make(map[string]bleve.Index),
keyring: k,
localStorage: osfs.New(filepath.Join(path, application)),
localStorage: osfs.New(filepath.Join(path, namespace)),
}
for _, loader := range clockLoaders {
@ -98,11 +98,11 @@ func OpenGoGitRepo(path, application string, clockLoaders []ClockLoader) (*GoGit
return repo, nil
}
// InitGoGitRepo creates a new empty git repo at the given path and with
// the specified application name. Given a repository path of "~/myrepo"
// and an application name of "git-bug", local storage for the application
// will be configured at "~/myrepo/.git/git-bug".
func InitGoGitRepo(path, application string) (*GoGitRepo, error) {
// InitGoGitRepo creates a new empty git repo at the given path and
// with the specified LocalStorage namespace. Given a repository path
// of "~/myrepo" and a namespace of "git-bug", local storage for the
// GoGitRepo will be configured at "~/myrepo/.git/git-bug".
func InitGoGitRepo(path, namespace string) (*GoGitRepo, error) {
r, err := gogit.PlainInit(path, false)
if err != nil {
return nil, err
@ -119,15 +119,15 @@ func InitGoGitRepo(path, application string) (*GoGitRepo, error) {
clocks: make(map[string]lamport.Clock),
indexes: make(map[string]bleve.Index),
keyring: k,
localStorage: osfs.New(filepath.Join(path, ".git", application)),
localStorage: osfs.New(filepath.Join(path, ".git", namespace)),
}, nil
}
// InitBareGoGitRepo creates a new --bare empty git repo at the given path
// and with the specified application name. Given a repository path of
// "~/myrepo" and an application name of "git-bug", local storage for the
// application will be configured at "~/myrepo/.git/git-bug".
func InitBareGoGitRepo(path, application string) (*GoGitRepo, error) {
// InitBareGoGitRepo creates a new --bare empty git repo at the given
// path and with the specified LocalStorage namespace. Given a repository
// path of "~/myrepo" and a namespace of "git-bug", local storage for the
// GoGitRepo will be configured at "~/myrepo/.git/git-bug".
func InitBareGoGitRepo(path, namespace string) (*GoGitRepo, error) {
r, err := gogit.PlainInit(path, true)
if err != nil {
return nil, err
@ -144,7 +144,7 @@ func InitBareGoGitRepo(path, application string) (*GoGitRepo, error) {
clocks: make(map[string]lamport.Clock),
indexes: make(map[string]bleve.Index),
keyring: k,
localStorage: osfs.New(filepath.Join(path, application)),
localStorage: osfs.New(filepath.Join(path, namespace)),
}, nil
}
@ -306,7 +306,7 @@ func (repo *GoGitRepo) GetRemotes() (map[string]string, error) {
}
// LocalStorage returns a billy.Filesystem giving access to
// $RepoPath/.git/$ApplicationName.
// $RepoPath/.git/$Namespace.
func (repo *GoGitRepo) LocalStorage() billy.Filesystem {
return repo.localStorage
}

View File

@ -7,7 +7,7 @@ import (
"github.com/99designs/keyring"
)
const testApplicationName = "git-bug"
const namespace = "git-bug"
// This is intended for testing only
@ -25,7 +25,7 @@ func CreateGoGitTestRepo(bare bool) TestedRepo {
creator = InitGoGitRepo
}
repo, err := creator(dir, testApplicationName)
repo, err := creator(dir, namespace)
if err != nil {
log.Fatal(err)
}