vole
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software:2222/vole.git
A free and open-source forge that lives in your Git repo.
refactor
c5902451905acdaa478f8476844ccd4a510d9ca9 · Keenan Nemetz · 17d ago · parent ec2aba4b
internal/repo/repo.go → forge/repo/repo.go +12−13
| @@ -14,14 +14,13 @@ import ( | |||
| 14 | 14 | "strings" | |
| 15 | 15 | "time" | |
| 16 | 16 | ||
| 17 | "github.com/rodent-software/vole/internal/access" | ||
| 18 | "github.com/rodent-software/vole/internal/acl" | ||
| 19 | "github.com/rodent-software/vole/internal/gitx" | ||
| 17 | "github.com/rodent-software/vole/core/git" | ||
| 18 | "github.com/rodent-software/vole/forge/access" | ||
| 20 | 19 | ) | |
| 21 | 20 | ||
| 22 | 21 | const ( | |
| 23 | 22 | ACLRef = "refs/vole/acl" | |
| 24 | ACLPath = "acl.json" | ||
| 23 | ACLPath = "access.json" | ||
| 25 | 24 | idFile = "vole-id" | |
| 26 | 25 | descFile = "description" | |
| 27 | 26 | ) | |
| @@ -85,10 +84,10 @@ func (s *Store) Create(name, owner, description string) (*Meta, error) { | |||
| 85 | 84 | if _, err := os.Stat(dir); err == nil { | |
| 86 | 85 | return nil, fmt.Errorf("repo %q already exists", name) | |
| 87 | 86 | } | |
| 88 | if err := gitx.InitBare(dir, "main"); err != nil { | ||
| 87 | if err := git.InitBare(dir, "main"); err != nil { | ||
| 89 | 88 | return nil, err | |
| 90 | 89 | } | |
| 91 | g := gitx.Open(dir) | ||
| 90 | g := git.Open(dir) | ||
| 92 | 91 | if s.MaxInputBytes > 0 { | |
| 93 | 92 | if err := g.SetConfig("receive.maxInputSize", strconv.FormatInt(s.MaxInputBytes, 10)); err != nil { | |
| 94 | 93 | return nil, err | |
| @@ -113,7 +112,7 @@ func (s *Store) Create(name, owner, description string) (*Meta, error) { | |||
| 113 | 112 | } | |
| 114 | 113 | m := &Meta{ID: id, Name: name, Dir: dir, Created: time.Now().UTC(), Description: description, | |
| 115 | 114 | DefaultBranch: "main", ACLs: s.ACLs} | |
| 116 | if err := m.SetACL(acl.Empty(owner), owner); err != nil { | ||
| 115 | if err := m.SetACL(access.Empty(owner), owner); err != nil { | ||
| 117 | 116 | return nil, err | |
| 118 | 117 | } | |
| 119 | 118 | if err := s.InstallHooks(m.Dir); err != nil { | |
| @@ -143,7 +142,7 @@ func (s *Store) Open(name string) (*Meta, error) { | |||
| 143 | 142 | if b, err := os.ReadFile(filepath.Join(dir, descFile)); err == nil { | |
| 144 | 143 | m.Description = strings.TrimSpace(string(b)) | |
| 145 | 144 | } | |
| 146 | if br := gitx.Open(dir).Symref(); br != "" { | ||
| 145 | if br := git.Open(dir).Symref(); br != "" { | ||
| 147 | 146 | m.DefaultBranch = br | |
| 148 | 147 | } | |
| 149 | 148 | return m, nil | |
| @@ -209,12 +208,12 @@ func (s *Store) Delete(name string) error { | |||
| 209 | 208 | return nil | |
| 210 | 209 | } | |
| 211 | 210 | ||
| 212 | func (m *Meta) Git() *gitx.Repo { return gitx.Open(m.Dir) } | ||
| 211 | func (m *Meta) Git() *git.Repo { return git.Open(m.Dir) } | ||
| 213 | 212 | ||
| 214 | 213 | // ACL reads the repo's access rules from the instance database. A repository with no | |
| 215 | 214 | // row gets a deny-by-default ACL with no principals, which is also what a repository | |
| 216 | 215 | // whose rules were never written looks like. | |
| 217 | func (m *Meta) ACL() (*acl.ACL, error) { | ||
| 216 | func (m *Meta) ACL() (*access.ACL, error) { | ||
| 218 | 217 | if m.ACLs == nil { | |
| 219 | 218 | return nil, fmt.Errorf("repo %q has no access store wired, so its rules cannot be read", m.Name) | |
| 220 | 219 | } | |
| @@ -223,7 +222,7 @@ func (m *Meta) ACL() (*acl.ACL, error) { | |||
| 223 | 222 | return nil, err | |
| 224 | 223 | } | |
| 225 | 224 | if a == nil { | |
| 226 | return acl.Empty(""), nil | ||
| 225 | return access.Empty(""), nil | ||
| 227 | 226 | } | |
| 228 | 227 | return a, nil | |
| 229 | 228 | } | |
| @@ -231,7 +230,7 @@ func (m *Meta) ACL() (*acl.ACL, error) { | |||
| 231 | 230 | // SetACL replaces the repo's access rules. It is one row now, so two concurrent edits | |
| 232 | 231 | // are ordered by SQLite instead of by a compare-and-swap retry, and the old copy's | |
| 233 | 232 | // commit message (who changed what) is kept in the row and the audit log. | |
| 234 | func (m *Meta) SetACL(a *acl.ACL, actor string) error { | ||
| 233 | func (m *Meta) SetACL(a *access.ACL, actor string) error { | ||
| 235 | 234 | if m.ACLs == nil { | |
| 236 | 235 | return fmt.Errorf("repo %q has no access store wired, so its rules cannot be written", m.Name) | |
| 237 | 236 | } | |
| @@ -267,7 +266,7 @@ func (s *Store) ImportACLs() (int, error) { | |||
| 267 | 266 | if err != nil { | |
| 268 | 267 | return imported, fmt.Errorf("%s: read %s: %w", m.Name, ACLRef, err) | |
| 269 | 268 | } | |
| 270 | a, err := acl.Parse(data) | ||
| 269 | a, err := access.Parse(data) | ||
| 271 | 270 | if err != nil { | |
| 272 | 271 | return imported, fmt.Errorf("%s: %w", m.Name, err) | |
| 273 | 272 | } | |