GetOrCreateClock return a Lamport clock stored in the Repo. If the clock doesn't exist, it's created.
(name string)
| 861 | // GetOrCreateClock return a Lamport clock stored in the Repo. |
| 862 | // If the clock doesn't exist, it's created. |
| 863 | func (repo *GoGitRepo) GetOrCreateClock(name string) (lamport.Clock, error) { |
| 864 | repo.clocksMutex.Lock() |
| 865 | defer repo.clocksMutex.Unlock() |
| 866 | |
| 867 | c, err := repo.getClock(name) |
| 868 | if err == nil { |
| 869 | return c, nil |
| 870 | } |
| 871 | if err != ErrClockNotExist { |
| 872 | return nil, err |
| 873 | } |
| 874 | |
| 875 | c, err = lamport.NewPersistedClock(repo.LocalStorage(), filepath.Join(clockPath, name)) |
| 876 | if err != nil { |
| 877 | return nil, err |
| 878 | } |
| 879 | |
| 880 | repo.clocks[name] = c |
| 881 | return c, nil |
| 882 | } |
| 883 | |
| 884 | func (repo *GoGitRepo) getClock(name string) (lamport.Clock, error) { |
| 885 | if c, ok := repo.clocks[name]; ok { |
no test coverage detected