s
This commit is contained in:
+2
-21
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user