Add support for repository specific hgrc files. Fixes HGKEEPER-2
--- a/hg/hg.go Thu Nov 12 00:53:46 2020 -0600
+++ b/hg/hg.go Thu Nov 12 00:55:06 2020 -0600
@@ -19,7 +19,7 @@
-func (c *Command) Setup() error {
+func (c *Command) Setup(repoName string) error { hgrc, err := createHgrc(c.writeable)
@@ -27,10 +27,14 @@
- filepath.Join(access.AdminRepoPath(), "site.hgrc"),
+ // site.hgrc is deprecated, but we still support it for now + rcs := []string{filepath.Join(access.AdminRepoPath(), "site.hgrc")} + // add the repo specific hgrc's + rcs = append(rcs, findHgrcsForRepo(repoName)...) + // add the hgrc that controls writability + rcs = append(rcs, c.tmpHgrc) @@ -49,8 +53,8 @@
-func (c *Command) Exec() (string, error) {
+func (c *Command) Exec(repoName string) (string, error) { raw, err := c.Cmd().CombinedOutput()
@@ -58,8 +62,8 @@
-func (c *Command) ExecPiped(stdin io.Reader, stdout, stderr io.Writer) error {
- if err := c.Setup(); err != nil {
+func (c *Command) ExecPiped(repoName string, stdin io.Reader, stdout, stderr io.Writer) error { + if err := c.Setup(repoName); err != nil { --- a/hg/hgrc.go Thu Nov 12 00:53:46 2020 -0600
+++ b/hg/hgrc.go Thu Nov 12 00:55:06 2020 -0600
@@ -2,8 +2,11 @@
+ "keep.imfreedom.org/grim/hgkeeper/access" func createHgrc(writeable bool) (string, error) {
@@ -29,3 +32,27 @@
return tmpfile.Name(), nil
+func findHgrcsForRepo(repoName string) []string { + adminPath := access.AdminRepoPath() + ret = append(ret, filepath.Join(adminPath, "config", repoName, "hgrc")) + repoName = filepath.Dir(repoName) + // we're assuming that the order of hgrc files is last wins, so we need to + // reverse the list so that the repository specific hgrc wins. If the list + // has an odd number of items, the middle is skipped as it's already in the + for i, j := 0, len(ret)-1; i < j; i, j = i+1, j-1 { + ret[i], ret[j] = ret[j], ret[i] --- a/hg/hgweb.go Thu Nov 12 00:53:46 2020 -0600
+++ b/hg/hgweb.go Thu Nov 12 00:55:06 2020 -0600
@@ -10,7 +10,7 @@
func TemplatesDir() (string, error) {
- templatesDir, err := Config("web.templates").Exec()
+ templatesDir, err := Config("web.templates").Exec("") if err != nil || templatesDir == "" {
--- a/once/command.go Thu Nov 12 00:53:46 2020 -0600
+++ b/once/command.go Thu Nov 12 00:55:06 2020 -0600
@@ -22,12 +22,8 @@
writeable := access.CanWrite(c.User, "/"+repoPath)
hgcmd := hg.Serve(filepath.Join(reposPath, repoPath), writeable)
- if err := hgcmd.Setup(); err != nil {
- return hgcmd.ExecPiped(os.Stdin, os.Stdout, os.Stderr)
+ return hgcmd.ExecPiped(repoPath, os.Stdin, os.Stdout, os.Stderr) func (c *Command) init(reposPath, repoPath string) error {
@@ -36,12 +32,8 @@
hgcmd := hg.Init(filepath.Join(reposPath, repoPath))
- if err := hgcmd.Setup(); err != nil {
- return hgcmd.ExecPiped(os.Stdin, os.Stdout, os.Stderr)
+ return hgcmd.ExecPiped(repoPath, os.Stdin, os.Stdout, os.Stderr) func (c *Command) Run(g *globals.Globals) error {
--- a/ssh/commands/init.go Thu Nov 12 00:53:46 2020 -0600
+++ b/ssh/commands/init.go Thu Nov 12 00:55:06 2020 -0600
@@ -28,7 +28,7 @@
return fmt.Errorf("access denied")
- if err := run(hg.Init(i.repoPath), session); err != nil {
+ if err := run(i.repoPath, hg.Init(i.repoPath), session); err != nil { --- a/ssh/commands/run.go Thu Nov 12 00:53:46 2020 -0600
+++ b/ssh/commands/run.go Thu Nov 12 00:55:06 2020 -0600
@@ -6,6 +6,6 @@
"keep.imfreedom.org/grim/hgkeeper/hg"
-func run(hgCmd *hg.Command, session ssh.Session) error {
- return hgCmd.ExecPiped(session, session, session.Stderr())
+func run(repoPath string, hgCmd *hg.Command, session ssh.Session) error { + return hgCmd.ExecPiped(repoPath, session, session, session.Stderr()) --- a/ssh/commands/serve.go Thu Nov 12 00:53:46 2020 -0600
+++ b/ssh/commands/serve.go Thu Nov 12 00:55:06 2020 -0600
@@ -30,7 +30,8 @@
writeable := access.CanWrite(username, "/"+s.repoName)
- if err := run(hg.Serve(s.repoPath, writeable), session); err != nil {
+ hgcmd := hg.Serve(s.repoPath, writeable) + if err := run(s.repoName, hgcmd, session); err != nil {