diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-13 16:05:27 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-09-13 16:05:27 +0200 |
commit | bf11c08f5ad0894e494228c312235d674b58af6a (patch) | |
tree | 1f1b36341ed1e4d57a38d4f468aaac60001f45a4 /repository | |
parent | fb0f5530f100e8ae3b8561fe5dcfd19edc181b15 (diff) | |
download | git-bug-bf11c08f5ad0894e494228c312235d674b58af6a.tar.gz |
lamport: better perf by ensuring that the folder is created only once
Diffstat (limited to 'repository')
-rw-r--r-- | repository/git.go | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/repository/git.go b/repository/git.go index 3b5a3a1a..29417dc7 100644 --- a/repository/git.go +++ b/repository/git.go @@ -90,7 +90,10 @@ func NewGitRepo(path string, witnesser func(repo *GitRepo) error) (*GitRepo, err if err != nil { // No clock yet, trying to initialize them - repo.createClocks() + err = repo.createClocks() + if err != nil { + return nil, err + } err = witnesser(repo) if err != nil { @@ -111,9 +114,12 @@ func NewGitRepo(path string, witnesser func(repo *GitRepo) error) (*GitRepo, err // InitGitRepo create a new empty git repo at the given path func InitGitRepo(path string) (*GitRepo, error) { repo := &GitRepo{Path: path} - repo.createClocks() + err := repo.createClocks() + if err != nil { + return nil, err + } - _, err := repo.runGitCommand("init", path) + _, err = repo.runGitCommand("init", path) if err != nil { return nil, err } @@ -124,9 +130,12 @@ func InitGitRepo(path string) (*GitRepo, error) { // InitBareGitRepo create a new --bare empty git repo at the given path func InitBareGitRepo(path string) (*GitRepo, error) { repo := &GitRepo{Path: path} - repo.createClocks() + err := repo.createClocks() + if err != nil { + return nil, err + } - _, err := repo.runGitCommand("init", "--bare", path) + _, err = repo.runGitCommand("init", "--bare", path) if err != nil { return nil, err } @@ -336,12 +345,23 @@ func (repo *GitRepo) AddRemote(name string, url string) error { return err } -func (repo *GitRepo) createClocks() { +func (repo *GitRepo) createClocks() error { createPath := path.Join(repo.Path, createClockFile) - repo.createClock = lamport.NewPersisted(createPath) + createClock, err := lamport.NewPersisted(createPath) + if err != nil { + return err + } editPath := path.Join(repo.Path, editClockFile) - repo.editClock = lamport.NewPersisted(editPath) + editClock, err := lamport.NewPersisted(editPath) + if err != nil { + return err + } + + repo.createClock = createClock + repo.editClock = editClock + + return nil } func (repo *GitRepo) LoadClocks() error { |