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".
(path, namespace string, clockLoaders []ClockLoader)
| 56 | // of "~/myrepo" and a namespace of "git-bug", local storage for the |
| 57 | // GoGitRepo will be configured at "~/myrepo/.git/git-bug". |
| 58 | func OpenGoGitRepo(path, namespace string, clockLoaders []ClockLoader) (*GoGitRepo, error) { |
| 59 | path, err := detectGitPath(path, 0) |
| 60 | if err != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | |
| 64 | r, err := gogit.PlainOpen(path) |
| 65 | if err != nil { |
| 66 | return nil, err |
| 67 | } |
| 68 | |
| 69 | k, err := defaultKeyring() |
| 70 | if err != nil { |
| 71 | return nil, err |
| 72 | } |
| 73 | |
| 74 | repo := &GoGitRepo{ |
| 75 | r: r, |
| 76 | path: path, |
| 77 | clocks: make(map[string]lamport.Clock), |
| 78 | indexes: make(map[string]Index), |
| 79 | keyring: k, |
| 80 | localStorage: billyLocalStorage{Filesystem: osfs.New(filepath.Join(path, namespace))}, |
| 81 | } |
| 82 | |
| 83 | loaderToRun := make([]ClockLoader, 0, len(clockLoaders)) |
| 84 | for _, loader := range clockLoaders { |
| 85 | loader := loader |
| 86 | allExist := true |
| 87 | for _, name := range loader.Clocks { |
| 88 | if _, err := repo.getClock(name); err != nil { |
| 89 | allExist = false |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if !allExist { |
| 94 | loaderToRun = append(loaderToRun, loader) |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | var errG errgroup.Group |
| 99 | for _, loader := range loaderToRun { |
| 100 | loader := loader |
| 101 | errG.Go(func() error { |
| 102 | return loader.Witnesser(repo) |
| 103 | }) |
| 104 | } |
| 105 | err = errG.Wait() |
| 106 | if err != nil { |
| 107 | return nil, err |
| 108 | } |
| 109 | |
| 110 | return repo, nil |
| 111 | } |
| 112 | |
| 113 | // InitGoGitRepo creates a new empty git repo at the given path and |
| 114 | // with the specified LocalStorage namespace. Given a repository path |