summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeah (ctucx) <leah@ctu.cx>2021-03-19 13:51:34 +0100
committerLeah (ctucx) <leah@ctu.cx>2021-03-19 13:51:34 +0100
commit360711e20d8e71b7dd56a45091eec950ada13f4f (patch)
tree53ed151c9016eb49a6f33d4de952824e22726fce
parent1c90db75a8328034f81e809909f9c84ddd79a273 (diff)
downloadnimgit-360711e20d8e71b7dd56a45091eec950ada13f4f.tar.gz
nimgit-360711e20d8e71b7dd56a45091eec950ada13f4f.tar.bz2
nimgit-360711e20d8e71b7dd56a45091eec950ada13f4f.zip
add copy proc for GitBlob, GitCommit, GitObject, GitReference, GitTag, GitTree, GitTreeEntry
-rw-r--r--nimgit/blob.nim9
-rw-r--r--nimgit/commit.nim9
-rw-r--r--nimgit/objects.nim9
-rw-r--r--nimgit/reference.nim7
-rw-r--r--nimgit/tag.nim6
-rw-r--r--nimgit/tree.nim7
-rw-r--r--nimgit/treeEntry.nim7
7 files changed, 54 insertions, 0 deletions
diff --git a/nimgit/blob.nim b/nimgit/blob.nim
index bef4d82..e1f6217 100644
--- a/nimgit/blob.nim
+++ b/nimgit/blob.nim
@@ -8,6 +8,15 @@ proc lookupBlob* (repo: GitRepository, id: GitObjectId): GitBlob =
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)
diff --git a/nimgit/commit.nim b/nimgit/commit.nim
index 0cac63b..54dd714 100644
--- a/nimgit/commit.nim
+++ b/nimgit/commit.nim
@@ -9,6 +9,15 @@ proc lookupCommit* (repo: GitRepository, oid: GitObjectId): GitCommit =
free(result)
raise newException(CatchableError, "Commit lookup failed: " & $error.getResultCode)
+
+proc copy* (commit: GitCommit): GitCommit =
+ let error = git_commit_dup(addr result, commit)
+
+ if error != 0:
+ free(result)
+ raise newException(CatchableError, "Cannot copy GitCommit: " & $error.getResultCode)
+
+
proc type* (obj: GitCommit): GitObjectKind = cast[GitObject](obj).type
proc owner* (commit: GitCommit): GitRepository = git_commit_owner(commit)
diff --git a/nimgit/objects.nim b/nimgit/objects.nim
index bc6792d..d0aec01 100644
--- a/nimgit/objects.nim
+++ b/nimgit/objects.nim
@@ -23,6 +23,15 @@ proc lookupObject* (repo: GitRepository, name: string): GitObject =
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
diff --git a/nimgit/reference.nim b/nimgit/reference.nim
index 4840344..2e05fc4 100644
--- a/nimgit/reference.nim
+++ b/nimgit/reference.nim
@@ -20,6 +20,13 @@ proc repo* (reference: GitReference): GitRepository = reference.owner()
proc getType* (reference: GitReference): GitReferenceType = cast[GitReferenceType](git_reference_type(reference))
+proc copy* (reference: GitReference): GitReference =
+ let error = git_reference_dup(addr result, reference)
+
+ if error != 0:
+ free(result)
+ raise newException(CatchableError, "Cannot copy GitReference: " & $error.getResultCode)
+
proc resolveTarget(reference: GitReference): GitReference =
if reference.getType() != referenceSymbolic:
raise newException(ValueError, "Not a symbolic reference!")
diff --git a/nimgit/tag.nim b/nimgit/tag.nim
index c689566..a2db91a 100644
--- a/nimgit/tag.nim
+++ b/nimgit/tag.nim
@@ -22,6 +22,12 @@ proc message* (tag: GitTag): string = $git_tag_message(tag)
proc tagger* (tag: GitTag): GitSignature = git_tag_tagger(tag).parseGitSignature
+proc copy* (tag: GitTag): GitTag =
+ let error = git_tag_dup(addr result, tag)
+
+ if error != 0:
+ free(result)
+ raise newException(CatchableError, "Cannot copy GitTag: " & $error.getResultCode)
proc target* (tag: GitTag): GitObject =
let error = git_tag_target(addr result, tag)
diff --git a/nimgit/tree.nim b/nimgit/tree.nim
index b7bc4d3..27dedaa 100644
--- a/nimgit/tree.nim
+++ b/nimgit/tree.nim
@@ -24,6 +24,13 @@ proc entry* (tree: GitTree, id: GitObjectId): GitTreeEntry = git_tree_entry_byid
#proc entry* (tree: GitTree, name: string): GitTreeEntry = git_tree_entry_byname(tree, cstring(name))
+proc copy* (tree: GitTree): GitTree =
+ let error = git_tree_dup(addr result, tree)
+
+ if error != 0:
+ free(result)
+ raise newException(CatchableError, "Cannot copy GitTree: " & $error.getResultCode)
+
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 86f8f51..de6974b 100644
--- a/nimgit/treeEntry.nim
+++ b/nimgit/treeEntry.nim
@@ -11,6 +11,13 @@ proc mode* (entry: GitTreeEntry): int = cast[int](git_tree_entry_filemode(entry)
proc modeStr* (entry: GitTreeEntry): string = filemodeStr(entry.mode)
+proc copy* (entry: GitTreeEntry): GitTreeEntry =
+ let error = git_tree_entry_dup(addr result, entry)
+
+ if error != 0:
+ free(result)
+ raise newException(CatchableError, "Cannot copy GitTreeEntry: " & $error.getResultCode)
+
proc getObject* (repo: GitRepository, entry: GitTreeEntry): GitBlob =
var obj: GitObject
let error = git_tree_entry_to_object(addr obj, repo, entry)