This commit is contained in:
Jabberwocky238
2026-07-16 09:14:16 -04:00
parent c64116069e
commit a289f1b911
4 changed files with 55 additions and 41 deletions
+2 -21
View File
@@ -185,22 +185,11 @@ func fingerprint(key ssh.PublicKey) string {
return "SHA256:" + hex.EncodeToString(sum[:])
}
// normalizeName strips one trailing ".git" so both "myrepo" and "myrepo.git"
// refer to the same repo.
func normalizeName(name string) string {
return strings.TrimSuffix(name, ".git")
}
// relPath returns the repo path relative to root: "owner/name.git".
func relPath(owner, name string) string {
return owner + "/" + normalizeName(name) + ".git"
}
// findRepo looks up a repo by (owner, name). name may include ".git". A missing
// row yields ErrRepoNotFound.
func (s *LocalState) findRepo(owner, name string) (*Repo, error) {
var r Repo
has, err := s.engine.Where("namespace = ? AND name = ?", owner, normalizeName(name)).Get(&r)
has, err := s.engine.Where("namespace = ? AND name = ?", owner, strings.TrimSuffix(name, ".git")).Get(&r)
if err != nil {
return nil, fmt.Errorf("lookup repo: %w", err)
}
@@ -210,16 +199,8 @@ func (s *LocalState) findRepo(owner, name string) (*Repo, error) {
return &r, nil
}
// RepoPath returns the absolute on-disk path for owner/name, but only if the
// repo is registered in the DB -- the DB is the authority, not the filesystem.
// In skip-auth mode the DB check is skipped (any path under root resolves).
func (s *LocalState) RepoPath(owner, name string) (string, error) {
name = normalizeName(name)
rel := relPath(owner, name)
if _, err := s.findRepo(owner, name); err != nil {
return "", err
}
return common.Resolve(s.cfg.RepoRoot(), rel)
return s.cfg.RepoPath(owner, name)
}
// Open returns a gitcmd.Repository for owner/name. The repo must be registered
+5 -5
View File
@@ -106,7 +106,7 @@ func (s *LocalState) nextNamespaceID() (int64, error) {
// namespace must already exist (have at least one repo) so NamespaceID can be
// resolved; NameID is freshly assigned. skip-auth: disk-only (git init, no DB).
func (s *LocalState) CreateRepo(ns, name string) error {
path, err := s.RepoPath(ns, name)
path, err := s.cfg.RepoPath(ns, name)
if err != nil {
return err
}
@@ -157,7 +157,7 @@ func (s *LocalState) ExistRepo(ns, name string) error {
// DeleteRepo removes the repo row, its repo-targeted ACL grants, and the
// on-disk bare directory. Hard-deletes. skip-auth: disk-only.
func (s *LocalState) DeleteRepo(ns, name string) error {
path, _ := s.RepoPath(ns, name)
path, _ := s.cfg.RepoPath(ns, name)
r, err := s.findRepo(ns, name)
if err != nil {
return err
@@ -186,11 +186,11 @@ func (s *LocalState) MoveRepo(old, new string) error {
if err != nil {
return err
}
oldPath, err := s.RepoPath(oldNs, oldName)
oldPath, err := s.cfg.RepoPath(oldNs, oldName)
if err != nil {
return err
}
newPath, err := s.RepoPath(newNs, newName)
newPath, err := s.cfg.RepoPath(newNs, newName)
if err != nil {
return err
}
@@ -207,7 +207,7 @@ func (s *LocalState) MoveRepo(old, new string) error {
if err != nil {
return err
}
upd := Repo{Namespace: newNs, Name: normalizeName(newName)}
upd := Repo{Namespace: newNs, Name: strings.TrimSuffix(newName, ".git")}
cols := []string{"namespace", "name"}
if newNs != oldNs {
nsID, err := s.resolveNamespaceID(newNs)