diff --git a/std/git.joke b/std/git.joke index 6cd76a24..e46c9356 100644 --- a/std/git.joke +++ b/std/git.joke @@ -44,7 +44,7 @@ [^GitRepo repo]) (defn log - "Returns the commit historyk from the given opts." + "Returns the commit history from the given opts." {:added "1.3" :go "log(repo, opts)"} [^GitRepo repo ^Map opts]) @@ -68,4 +68,8 @@ :go "status(repo)"} [^GitRepo repo]) - +(defn commit + "Returns a commit with the given hash." + {:added "1.3" + :go "findCommit(repo, hash)"} + [^GitRepo repo ^String hash]) diff --git a/std/git/a_git.go b/std/git/a_git.go index 15dc4767..c210cef9 100644 --- a/std/git/a_git.go +++ b/std/git/a_git.go @@ -6,6 +6,24 @@ import ( . "github.com/candid82/joker/core" ) +var __commit__P ProcFn = __commit_ +var commit_ Proc = Proc{Fn: __commit__P, Name: "commit_", Package: "std/git"} + +func __commit_(_args []Object) Object { + _c := len(_args) + switch { + case _c == 2: + repo := ExtractGitRepo(_args, 0) + hash := ExtractString(_args, 1) + _res := findCommit(repo, hash) + return _res + + default: + PanicArity(_c) + } + return NIL +} + var __config__P ProcFn = __config_ var config_ Proc = Proc{Fn: __config__P, Name: "config_", Package: "std/git"} diff --git a/std/git/a_git_slow_init.go b/std/git/a_git_slow_init.go index 1e109b9c..0f71c73d 100644 --- a/std/git/a_git_slow_init.go +++ b/std/git/a_git_slow_init.go @@ -29,6 +29,11 @@ func InternsOrThunks() { user=> (joker.json/read-string (joker.bolt/get db "users" (str id))) {"id" 1, "name" "Joe Black"}`, "1.0")) + gitNamespace.InternVar("commit", commit_, + MakeMeta( + NewListFrom(NewVectorFrom(MakeSymbol("repo"), MakeSymbol("hash"))), + `Returns a commit with the given hash.`, "1.3")) + gitNamespace.InternVar("config", config_, MakeMeta( NewListFrom(NewVectorFrom(MakeSymbol("repo"))), @@ -42,7 +47,7 @@ func InternsOrThunks() { gitNamespace.InternVar("log", log_, MakeMeta( NewListFrom(NewVectorFrom(MakeSymbol("repo"), MakeSymbol("opts"))), - `Returns the commit historyk from the given opts.`, "1.3")) + `Returns the commit history from the given opts.`, "1.3")) gitNamespace.InternVar("object", object_, MakeMeta( diff --git a/std/git/git_native.go b/std/git/git_native.go index b590633a..0fece2e1 100644 --- a/std/git/git_native.go +++ b/std/git/git_native.go @@ -251,6 +251,12 @@ func resolveRevision(repo *git.Repository, rev string) string { return hash.String() } +func findCommit(repo *git.Repository, hash string) Map { + obj, err := repo.CommitObject(plumbing.NewHash(hash)) + PanicOnErr(err) + return makeCommit(obj) +} + func findObject(repo *git.Repository, hash string) Map { obj, err := repo.Object(plumbing.AnyObject, plumbing.NewHash(hash)) PanicOnErr(err)