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
import nimgit2
import types, free, objects
proc lookupBlob* (repo: GitRepository, id: GitObjectId): GitBlob =
let error = git_blob_lookup(addr result, repo, id)
if error != 0:
free(result)
raise newException(CatchableError, "Blob lookup failed: " & $error.getResultCode)
proc copy* (blob: GitBlob): GitBlob =
let error = git_blob_dup(addr result, blob)
if error != 0:
free(result)
raise newException(CatchableError, "Cannot copy GitBlob: " & $error.getResultCode)
proc type* (obj: GitBlob): GitObjectKind = cast[GitObject](obj).type
proc owner* (blob: GitBlob): GitRepository = git_blob_owner(blob)
proc id* (blob: GitBlob): GitObjectId = git_blob_id(blob)
proc shortId* (blob: GitBlob): string = cast[GitObject](blob).shortId()
proc size* (blob: GitBlob): int = cast[int](git_blob_rawsize(blob))
proc content* (blob: GitBlob): string =
result = newString(blob.size)
copyMem(result.cstring, git_blob_rawcontent(blob), blob.size)
proc isBinary* (blob: GitBlob): bool = cast[bool](git_blob_is_binary(blob))