NAME
Git::Libgit2 - Low-level FFI bindings to libgit2
VERSION
version 0.004
SYNOPSIS
use Git::Libgit2 qw( init_lib version check_rc );
init_lib();
printf "libgit2 %s\n", version();
# Direct FFI calls live in Git::Libgit2::FFI
use Git::Libgit2::FFI;
my $rc = Git::Libgit2::FFI::git_repository_open(\my $repo, '/path/to/.git');
check_rc $rc;
DESCRIPTION
Low-level FFI::Platypus bindings to the libgit2 C library, via Alien::Libgit2.
This module is intentionally close to the C surface. Use Git::Native for an idiomatic Moo wrapper with RAII handle management.
init_lib
init_lib();
Initialise the libgit2 library (wraps git_libgit2_init). Safe to call repeatedly — libgit2 reference-counts initialisations and returns the new count, which this returns too. Croaks if the count comes back below 1.
shutdown_lib
shutdown_lib();
Decrement libgit2's initialisation count (wraps git_libgit2_shutdown) and return the remaining count. A no-op returning 0 if "init_lib" was never called. Call once per matching "init_lib".
version
my $string = version(); # "1.9.0"
my ($maj, $min, $rev) = version(); # (1, 9, 0)
Return the libgit2 library version (wraps git_libgit2_version). In scalar context returns a dotted "major.minor.revision" string; in list context returns the three numeric components.
check_rc
my $rc = check_rc( some_libgit2_call(...) );
Pass a libgit2 return code straight through when it is non-negative. On a negative code, throw the corresponding Git::Libgit2::Error (built from git_error_last); the exception stringifies to the libgit2 error message.
oid_from_hex
my $raw = oid_from_hex('39a3c8...'); # 40 hex chars
Convert a 40-character hex OID into a Perl scalar holding the raw 20 bytes (wraps git_oid_fromstr). Croaks unless the input is exactly 40 hex digits.
Lifetime: the returned scalar is the OID buffer — libgit2 is handed a pointer into its PV. Keep the scalar alive for as long as any libgit2 call still needs the OID.
oid_to_hex
my $hex = oid_to_hex($oid_ptr);
Convert a git_oid pointer into its 40-character hex string (wraps git_oid_tostr).
EXPORTS
init_lib, shutdown_lib, version, check_rc, oid_from_hex, oid_to_hex, plus object-type and repository-init constants.
SEE ALSO
Alien::Libgit2, Git::Native, FFI::Platypus, libgit2
SUPPORT
Issues
Please report bugs and feature requests on GitHub at https://github.com/Getty/p5-git-libgit2/issues.
CONTRIBUTING
Contributions are welcome! Please fork the repository and submit a pull request.
AUTHOR
Torsten Raudssus <getty@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.