summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeah (ctucx) <leah@ctu.cx>2021-03-18 22:12:48 +0100
committerLeah (ctucx) <leah@ctu.cx>2021-03-18 22:12:48 +0100
commit1c90db75a8328034f81e809909f9c84ddd79a273 (patch)
treea4432ca9a361bd7075a40706c57acb8e5732662c
parent19b970dcb5cb1df3d96f23f020bea7ce5cb732fc (diff)
downloadnimgit-1c90db75a8328034f81e809909f9c84ddd79a273.tar.gz
nimgit-1c90db75a8328034f81e809909f9c84ddd79a273.tar.bz2
nimgit-1c90db75a8328034f81e809909f9c84ddd79a273.zip
allow reading of config-values
-rw-r--r--nimgit.nim4
-rw-r--r--nimgit/config.nim43
-rw-r--r--nimgit/free.nim4
-rw-r--r--nimgit/types.nim2
4 files changed, 50 insertions, 3 deletions
diff --git a/nimgit.nim b/nimgit.nim
index 6c43b95..2237f23 100644
--- 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
new file mode 100644
index 0000000..d9f29e6
--- /dev/null
+++ 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
index 803f5ae..c14fd72 100644
--- 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
index 622b33c..8b1c5b8 100644
--- 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