Skip to content

Commit

Permalink
Add joker.git/commit function.
Browse files Browse the repository at this point in the history
  • Loading branch information
candid82 committed Aug 3, 2023
1 parent 9fceeb8 commit ebe6fcd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
8 changes: 6 additions & 2 deletions std/git.joke
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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])
18 changes: 18 additions & 0 deletions std/git/a_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand Down
7 changes: 6 additions & 1 deletion std/git/a_git_slow_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))),
Expand All @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions std/git/git_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ebe6fcd

Please sign in to comment.