@@ -2,6 +2,7 @@ const std = @import("std");
2
2
const testing = std .testing ;
3
3
4
4
const c = @cImport ({
5
+ @cInclude ("git2.h" );
5
6
@cInclude ("hash.h" );
6
7
});
7
8
@@ -25,23 +26,29 @@ fn calcHashFile(
25
26
};
26
27
const actual = try allocator .alloc (u8 , size );
27
28
28
- var r : c_int = undefined ;
29
+ errdefer {
30
+ std .log .err ("{s}" , .{c .git_error_last ().* .message });
31
+ }
32
+
33
+ if (c .git_libgit2_init () < 0 ) return error .Unexpected ;
34
+ defer _ = c .git_libgit2_shutdown ();
35
+
29
36
var ctx : c.git_hash_ctx = undefined ;
30
- r = c .git_hash_ctx_init (& ctx , algorithm );
31
- if ( r != 0 ) return error .Unexpected ;
37
+ if ( c .git_hash_ctx_init (& ctx , algorithm ) != 0 )
38
+ return error .Unexpected ;
32
39
defer c .git_hash_ctx_cleanup (& ctx );
33
40
34
41
const reader = file .reader ();
35
42
while (true ) {
36
43
var buf : [2048 ]u8 = undefined ;
37
44
const len = try reader .read (& buf );
38
45
if (len == 0 ) break ;
39
- r = c .git_hash_update (& ctx , & buf , len );
40
- if ( r != 0 ) return error .Unexpected ;
46
+ if ( c .git_hash_update (& ctx , & buf , len ) != 0 )
47
+ return error .Unexpected ;
41
48
}
42
49
43
- r = c .git_hash_final (actual .ptr , & ctx );
44
- if ( r != 0 ) return error .Unexpected ;
50
+ if ( c .git_hash_final (actual .ptr , & ctx ) != 0 )
51
+ return error .Unexpected ;
45
52
46
53
return actual ;
47
54
}
0 commit comments