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 
import nimgit2
import types, free

proc initGitObjectId* (): GitObjectId = cast[GitObjectId](sizeof(git_oid).alloc)

proc fromString* (str: string): GitObjectId =
    result = initGitObjectId()
    let error = git_oid_fromstr(result, cstring(str))

    if error != 0:
        free(result)
        raise newException(CatchableError, "Cannot parse string to GitObjectId: " & $error.getResultCode)


proc toString* (obj: GitObjectId): string = $git_oid_tostr_s(obj)

proc isZero (obj: GitObjectId): bool = cast[bool](git_oid_is_zero(obj))

proc `$`* (obj: GitObjectId): string = obj.toString()

proc `==`* (a: GitObjectId, b: GitObjectId): bool =
    if a.isNil or b.isNil:
        result = false
    elif a.isZero or b.isZero:
        result = false
    else:   
        result = cast[bool](git_oid_equal(a, b))