grim/hgkeeper

Add a caching layer to the hgweb portion. This should take some strain off of mercurial anf our cpu quota
package commands
import (
"fmt"
"path/filepath"
"github.com/gliderlabs/ssh"
log "github.com/sirupsen/logrus"
"bitbucket.org/rw_grim/hgkeeper/access"
"bitbucket.org/rw_grim/hgkeeper/hg"
)
type Serve struct {
repoPath string
repoName string
}
func NewServe(reposPath, repoName string) *Serve {
return &Serve{
repoPath: filepath.Join(reposPath, repoName),
repoName: repoName,
}
}
func (s *Serve) Run(session ssh.Session, username string) error {
if !access.CanRead(username, "/"+s.repoName) {
return fmt.Errorf("repository %q not found", s.repoName)
}
writeable := access.CanWrite(username, "/"+s.repoName)
if err := run(hg.Serve(s.repoPath, writeable), session); err != nil {
return err
}
if s.repoName == access.AdminRepo() {
log.Info("admin repo updated, refreshing access control")
return access.Refresh()
}
return nil
}