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))