ctucx.git: nimgit

[nimlang] nim-wrapper for libgit2

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
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)