ctucx.git: nimgit

[nimlang] nim-wrapper for libgit2

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 import nimgit2
import types, free, utils

proc type* (entry: GitTreeEntry): GitObjectKind = GitObjectKind(git_tree_entry_type(entry) - GIT_OBJECT_ANY)

proc id* (entry: GitTreeEntry): GitObjectId = git_tree_entry_id(entry)

proc name* (entry: GitTreeEntry): string = $git_tree_entry_name(entry)

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 compare* (x: GitTreeEntry, y: GitTreeEntry): int = cast[int](git_tree_entry_cmp(x, y))

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)