summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeah (ctucx) <leah@ctu.cx>2021-03-18 13:27:33 +0100
committerLeah (ctucx) <leah@ctu.cx>2021-03-18 13:27:33 +0100
commit1570c7d00153181729832ad6f90466fe7d29b858 (patch)
tree6cb56a89d0f30d9f4c2bddc55fc12506ac8b81dc
parent8648e2ab324a4e59ae61f47df37cb4319bcdd823 (diff)
downloadnimgit-1570c7d00153181729832ad6f90466fe7d29b858.tar.gz
nimgit-1570c7d00153181729832ad6f90466fe7d29b858.tar.bz2
nimgit-1570c7d00153181729832ad6f90466fe7d29b858.zip
fix
-rw-r--r--nimgit/blob.nim6
-rw-r--r--nimgit/tree.nim2
-rw-r--r--nimgit/treeEntry.nim7
3 files changed, 10 insertions, 5 deletions
diff --git a/nimgit/blob.nim b/nimgit/blob.nim
index e209ce1..bef4d82 100644
--- a/nimgit/blob.nim
+++ b/nimgit/blob.nim
@@ -16,8 +16,10 @@ proc id* (blob: GitBlob): GitObjectId = git_blob_id(blob)
proc shortId* (blob: GitBlob): string = cast[GitObject](blob).shortId()
-proc content* (blob: GitBlob): string = cast[string](git_blob_rawcontent(blob))
-
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))
diff --git a/nimgit/tree.nim b/nimgit/tree.nim
index 7de0b0f..b7bc4d3 100644
--- a/nimgit/tree.nim
+++ b/nimgit/tree.nim
@@ -22,7 +22,7 @@ proc entry* (tree: GitTree, id: int): GitTreeEntry = git_tree_entry_byindex(tree
proc entry* (tree: GitTree, id: GitObjectId): GitTreeEntry = git_tree_entry_byid(tree, id)
-proc entry* (tree: GitTree, name: string): GitTreeEntry = git_tree_entry_byname(tree, cstring(name))
+#proc entry* (tree: GitTree, name: string): GitTreeEntry = git_tree_entry_byname(tree, cstring(name))
proc entry* (tree: GitTree, path: string): GitTreeEntry =
let error = git_tree_entry_bypath(addr result, tree, cstring(path)).getResultCode
diff --git a/nimgit/treeEntry.nim b/nimgit/treeEntry.nim
index a0a6c4c..86f8f51 100644
--- a/nimgit/treeEntry.nim
+++ b/nimgit/treeEntry.nim
@@ -11,9 +11,12 @@ proc mode* (entry: GitTreeEntry): int = cast[int](git_tree_entry_filemode(entry)
proc modeStr* (entry: GitTreeEntry): string = filemodeStr(entry.mode)
-proc getObject* (repo: GitRepository, entry: GitTreeEntry): GitObject =
- let error = git_tree_entry_to_object(addr result, repo, entry)
+proc getObject* (repo: GitRepository, entry: GitTreeEntry): GitBlob =
+ var obj: GitObject
+ let error = git_tree_entry_to_object(addr obj, repo, entry)
if error != 0:
free(result)
raise newException(CatchableError, "Cannot convert tree-entry into object: " & $error.getResultCode)
+
+ result = cast[GitBlob](obj) \ No newline at end of file