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 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 import os, times
import nimgit

if paramCount() == 0:
    echo "No git-repo given."
    quit(QuitFailure)

discard git_libgit2_init()

try:
    var gitRepository     = openGitRepository(paramStr(1))
    let gitRevisionWalker = gitRepository.walk()

    gitRevisionWalker.sort(GIT_SORT_TOPOLOGICAL)
    gitRevisionWalker.pushHead()

    echo "Commits on HEAD in repo: " & $gitRepository

    for gitOid in gitRevisionWalker:
        let
          commit       = gitRepository.lookupCommit(gitOid)
          author       = commit.author
          committer    = commit.committer
          parentCount  = commit.parentCount
          signature    = commit.gpgSignature
          tree         = commit.tree

        echo "==================="
        echo "hash: " & $gitOid
        echo "committer: " & committer.name & " <" & committer.email & ">"
        echo "author: " & author.name & " <" & author.email & ">"
        echo "when: " & $commit.time
        echo "message: " & commit.summary
        echo "tree id: " & $commit.treeId
        echo "parentCount: " & $parentCount

        for parentId in commit.parentIds:
            echo "parent: " & $parentId

        if signature[0] != "":
            echo "signature: " & $signature

        echo ""

        free(tree)
        free(commit)

    free(gitRepository)

except:
    echo "Error:\n", getCurrentExceptionMsg()