Only bother trying to fetch if we need to

This commit is contained in:
Daniel Wagner-Hall 2015-11-19 16:15:13 -05:00
parent 8872e17f93
commit 6f1d00097b

View file

@ -147,13 +147,21 @@ func (s *server) updateBase() error {
return runGitCommand(s.matrixDocCloneURL, []string{"fetch"})
}
func (s *server) knowsAbout(sha string) bool {
s.mu.Lock()
defer s.mu.Unlock()
return runGitCommand(s.matrixDocCloneURL, []string{"cat-file", "-e", sha + "^{commit}"}) == nil
}
// generateAt generates spec from repo at sha.
// Returns the path where the generation was done.
func (s *server) generateAt(sha string) (dst string, err error) {
if !s.knowsAbout(sha) {
err = s.updateBase()
if err != nil {
return
}
}
s.mu.Lock()
dst, err = gitClone(s.matrixDocCloneURL, true)
s.mu.Unlock()