A vibe coded tangled fork which supports pijul.
at 5bf28708dcf8972c724fb0c33fcab1281cbc3f27 91 lines 2.2 kB view raw
1package vcs 2 3import ( 4 "fmt" 5 6 "github.com/go-git/go-git/v5/plumbing" 7 "tangled.org/core/knotserver/git" 8 "tangled.org/core/knotserver/pijul" 9) 10 11// Open opens a repository at path with the given ref (branch/tag/hash). 12// It auto-detects the VCS type and returns the appropriate adapter. 13// For git, ref is resolved as a revision; for pijul, ref is the channel name. 14func Open(path, ref string) (ReadRepo, error) { 15 vcsType, err := DetectVCS(path) 16 if err != nil { 17 return nil, err 18 } 19 20 switch vcsType { 21 case "git": 22 g, err := git.Open(path, ref) 23 if err != nil { 24 return nil, err 25 } 26 return newGitReadAdapter(g), nil 27 case "pijul": 28 p, err := pijul.Open(path, ref) 29 if err != nil { 30 return nil, err 31 } 32 return newPijulReadAdapter(p), nil 33 default: 34 return nil, fmt.Errorf("unsupported VCS type: %s", vcsType) 35 } 36} 37 38// PlainOpen opens a repository at path without setting a specific ref. 39// Returns a MutableRepo since no ref is pinned. 40func PlainOpen(path string) (MutableRepo, error) { 41 vcsType, err := DetectVCS(path) 42 if err != nil { 43 return nil, err 44 } 45 46 switch vcsType { 47 case "git": 48 g, err := git.PlainOpen(path) 49 if err != nil { 50 return nil, err 51 } 52 return newGitMutableAdapter(g), nil 53 case "pijul": 54 p, err := pijul.PlainOpen(path) 55 if err != nil { 56 return nil, err 57 } 58 return newPijulMutableAdapter(p), nil 59 default: 60 return nil, fmt.Errorf("unsupported VCS type: %s", vcsType) 61 } 62} 63 64// AsGit returns the underlying *git.GitRepo if repo is a git adapter, or nil. 65// Use this for git-specific operations that don't belong in the VCS interface. 66func AsGit(repo ReadRepo) *git.GitRepo { 67 switch r := repo.(type) { 68 case *gitReadAdapter: 69 return r.Git() 70 case *gitMutableAdapter: 71 return r.Git() 72 } 73 return nil 74} 75 76// AsPijul returns the underlying *pijul.PijulRepo if repo is a pijul adapter, or nil. 77// Use this for pijul-specific operations that don't belong in the VCS interface. 78func AsPijul(repo ReadRepo) *pijul.PijulRepo { 79 switch r := repo.(type) { 80 case *pijulReadAdapter: 81 return r.Pijul() 82 case *pijulMutableAdapter: 83 return r.Pijul() 84 } 85 return nil 86} 87 88// gitHash converts a hex string to a plumbing.Hash. 89func gitHash(s string) plumbing.Hash { 90 return plumbing.NewHash(s) 91}