Skip to content

Commit 91819fb

Browse files
committed
refactor: properly type git_signature
1 parent 9a0eff5 commit 91819fb

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/init.lua

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,17 @@ ffi.cdef [[
55
typedef struct git_commit git_commit;
66
typedef struct git_object git_object;
77
typedef struct git_reference git_reference;
8-
typedef struct git_signature git_signature;
8+
9+
typedef struct {
10+
char *name;
11+
char *email;
12+
struct {
13+
int64_t time;
14+
int offset;
15+
char sign;
16+
} when;
17+
} git_signature;
18+
919
typedef struct git_index git_index;
1020
typedef struct git_remote git_remote;
1121

@@ -75,7 +85,7 @@ lib.git_libgit2_init()
7585
---@class git2.ffi.Signature: ffi.cdata*
7686
---@field name string
7787
---@field email string
78-
---@field when_time integer
88+
---@field when { time: integer, offset: integer, sign: string }
7989

8090
-- value types
8191

@@ -95,7 +105,6 @@ lib.git_libgit2_init()
95105

96106
-- helpers
97107

98-
local sigLayout = ffi.typeof("struct { char *name; char *email; int64_t when_time; int when_offset; } *")
99108

100109
---@param code integer
101110
local function check(code)
@@ -116,8 +125,7 @@ end
116125
---@param sig git2.ffi.Signature
117126
---@return git2.Sig
118127
local function wrapSig(sig)
119-
local s = ffi.cast(sigLayout, sig)
120-
return { name = ffi.string(s.name), email = ffi.string(s.email), time = tonumber(s.when_time) }
128+
return { name = ffi.string(sig.name), email = ffi.string(sig.email), time = tonumber(sig.when.time) }
121129
end
122130

123131
---@param c git2.ffi.Commit

0 commit comments

Comments
 (0)