commit 1c90db75a8328034f81e809909f9c84ddd79a273
parent 19b970dcb5cb1df3d96f23f020bea7ce5cb732fc
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 18 Mar 2021 22:12:48 +0100
parent 19b970dcb5cb1df3d96f23f020bea7ce5cb732fc
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 18 Mar 2021 22:12:48 +0100
allow reading of config-values
4 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/nimgit.nim b/nimgit.nim @@ -1,5 +1,5 @@ import nimgit2 -import nimgit/[types, free, repository, objects, oid, tag, blob, tree, treeEntry, reference, revisionWalker, branch, commit] +import nimgit/[types, free, repository, config, objects, oid, tag, blob, tree, treeEntry, reference, revisionWalker, branch, commit] export nimgit2 -export types, free, repository, objects, oid, tag, blob, tree, treeEntry, reference, revisionWalker, branch, commit +export types, free, repository, config, objects, oid, tag, blob, tree, treeEntry, reference, revisionWalker, branch, commit
diff --git a/nimgit/config.nim b/nimgit/config.nim @@ -0,0 +1,43 @@ +import nimgit2 +import types, free + +proc config* (repo: GitRepository): GitConfig = + let error = git_repository_config_snapshot(addr result, repo) + + if error != 0: + free(result) + raise newException(CatchableError, "Load config failed: " & $error.getResultCode) + + +proc get* (config: GitConfig, name: string): string = + var value: cstring + let error = git_config_get_string(addr value, config, cstring(name)) + + if error != 0: + return "" + + result = $value + +proc getString* (config: GitConfig, name: string): string = + var value: cstring + let error = git_config_get_string(addr value, config, cstring(name)) + + if error != 0: + raise newException(CatchableError, "Config-value lookup failed: " & $error.getResultCode) + + result = $value + +proc getBool* (config: GitConfig, name: string): bool = + var value: cint + let error = git_config_get_bool(addr value, config, cstring(name)) + + if error != 0: + raise newException(CatchableError, "Config-value lookup failed: " & $error.getResultCode) + + result = cast[bool](value) + +proc getInt* (config: GitConfig, name: string): int64 = + let error = git_config_get_int64(addr result, config, cstring(name)) + + if error != 0: + raise newException(CatchableError, "Config-value lookup failed: " & $error.getResultCode)
diff --git a/nimgit/free.nim b/nimgit/free.nim @@ -4,7 +4,7 @@ type NimGitTypes = git_clone_options | git_status_options | git_checkout_options | git_oid | git_diff_options - GitTypes = git_repository | git_reference | git_remote | git_tag | + GitTypes = git_repository | git_config | git_reference | git_remote | git_tag | git_strarray | git_object | git_commit | git_status_list | git_annotated_commit | git_tree_entry | git_revwalk | git_buf | git_pathspec | git_tree | git_diff | git_pathspec_match_list | @@ -17,6 +17,8 @@ proc free* [T: GitTypes] (point: ptr T) = ## perform a free of a git-managed pointer when T is git_repository: git_repository_free(point) + elif T is git_config: + git_config_free(point) elif T is git_reference: git_reference_free(point) elif T is git_remote:
diff --git a/nimgit/types.nim b/nimgit/types.nim @@ -3,6 +3,8 @@ import nimgit2 type GitRepository* = ptr git_repository + GitConfig* = ptr git_config + GitConfigEntry* = ptr git_config_entry GitObject* = ptr git_object GitObjectId* = ptr git_oid GitCommit* = ptr git_commit