import nimgit2 import types, free, oid proc lookupObjectIdByName* (repo: GitRepository, name: string): GitObjectId = result = initGitObjectId() let error = git_reference_name_to_id(result, repo, cstring(name)) if error != 0: free(result) raise newException(CatchableError, "Lookup failed: " & $error.getResultCode) proc lookupObject* (repo: GitRepository, name: string): GitObject = let error = git_revparse_single(addr result, repo, cstring(name)).getResultCode if error != grcOk: free(result) case error: of grcNotFound: raise newException(CatchableError, "Object not found.") of grcAmbiguous: raise newException(CatchableError, "Object lookup was ambiguous") of grcInvalidSpec: raise newException(CatchableError, "Object lookup was ambiguous") else: raise newException(CatchableError, "Object lookup failed: " & $error) proc type* (obj: GitObject): GitObjectKind = GitObjectKind(git_object_type(obj) - GIT_OBJECT_ANY) proc copy* (obj: GitObject): GitObject = let error = git_object_dup(addr result, obj) if error != 0: free(result) raise newException(CatchableError, "Cannot copy GitObject: " & $error.getResultCode) proc shortId* (obj: GitObject): string = var buffer: git_buf let error = git_object_short_id(addr buffer, obj) if error != 0: git_buf_dispose(addr buffer); raise newException(CatchableError, "Cannot short id: " & $error.getResultCode) result = $buffer.ptr git_buf_dispose(addr buffer);