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
import times, posix, strutils
import nimgit2
import types
proc getLastError* (): GitErrorObj =
let error = git_error_last()
result.message = $error.message
result.class = error.klass.getErrorClass
proc parseGitTime* (time: git_time): GitTime =
result.time = fromUnix(time.time)
result.offset = time.offset
proc parseGitSignature* (signature: ptr git_signature): GitSignature =
result.name = $signature.name
result.email = $signature.email
result.when = parseGitTime(signature.when)
proc filemodeStr* (m: int): string =
var mode = align("", 10, '-')
if S_ISREG(cast[Mode](m)): mode[0] = '-'
elif S_ISBLK(cast[Mode](m)): mode[0] = 'b'
elif S_ISCHR(cast[Mode](m)): mode[0] = 'c'
elif S_ISDIR(cast[Mode](m)): mode[0] = 'd'
elif S_ISFIFO(cast[Mode](m)): mode[0] = 'p'
elif S_ISLNK(cast[Mode](m)): mode[0] = 'l'
elif S_ISSOCK(cast[Mode](m)): mode[0] = 's'
else: mode[0] = '?'
if cast[bool](m and S_IRUSR): mode[1] = 'r'
if cast[bool](m and S_IWUSR): mode[2] = 'w'
if cast[bool](m and S_IXUSR): mode[3] = 'x'
if cast[bool](m and S_IRGRP): mode[4] = 'r'
if cast[bool](m and S_IWGRP): mode[5] = 'w'
if cast[bool](m and S_IXGRP): mode[6] = 'x'
if cast[bool](m and S_IROTH): mode[7] = 'r'
if cast[bool](m and S_IWOTH): mode[8] = 'w'
if cast[bool](m and S_IXOTH): mode[9] = 'x'
if cast[bool](m and S_ISUID): mode[3] = if(mode[3] == 'x'): 's' else: 'S'
if cast[bool](m and S_ISGID): mode[6] = if(mode[6] == 'x'): 's' else: 'S'
if cast[bool](m and S_ISVTX): mode[9] = if(mode[9] == 'x'): 't' else: 'T'
result = mode