| 1 | # ABSTRACT: Walk commits in topological / time order | ||
| 2 | |||
| 3 | package Git::Native::Revwalker; | ||
| 4 | our $VERSION = '0.006'; | ||
| 5 | use Moo; | ||
| 6 | use Carp (); | ||
| 7 | use Git::Libgit2 qw( | ||
| 8 | GIT_ITEROVER | ||
| 9 | GIT_SORT_NONE GIT_SORT_TOPOLOGICAL GIT_SORT_TIME GIT_SORT_REVERSE | ||
| 10 | ); | ||
| 11 | use Git::Libgit2::FFI (); | ||
| 12 | use Git::Native::Error qw( check_rc ); | ||
| 13 | use FFI::Platypus::Buffer qw( scalar_to_buffer ); | ||
| 14 | use Git::Native::Oid (); | ||
| 15 | |||
| 16 | has _handle => ( is => 'ro', required => 1 ); | ||
| 17 | has _owner => ( is => 'ro', required => 1 ); | ||
| 18 | |||
| 19 | sub push_oid { | ||
| 20 | my ( $self, $oid ) = @_; | ||
| 21 | $oid = Git::Native::Oid->from_hex($oid) if !ref $oid; | ||
| 22 | check_rc Git::Libgit2::FFI::git_revwalk_push( $self->_handle, $oid->ptr ); | ||
| 23 | return $self; | ||
| 24 | } | ||
| 25 | |||
| 26 | sub push_head { check_rc Git::Libgit2::FFI::git_revwalk_push_head( $_[0]->_handle ); $_[0] } | ||
| 27 | sub push_ref { check_rc Git::Libgit2::FFI::git_revwalk_push_ref( $_[0]->_handle, $_[1] ); $_[0] } | ||
| 28 | sub push_glob { check_rc Git::Libgit2::FFI::git_revwalk_push_glob( $_[0]->_handle, $_[1] ); $_[0] } | ||
| 29 | sub push_range { check_rc Git::Libgit2::FFI::git_revwalk_push_range( $_[0]->_handle, $_[1] ); $_[0] } | ||
| 30 | |||
| 31 | sub hide_oid { | ||
| 32 | my ( $self, $oid ) = @_; | ||
| 33 | $oid = Git::Native::Oid->from_hex($oid) if !ref $oid; | ||
| 34 | check_rc Git::Libgit2::FFI::git_revwalk_hide( $self->_handle, $oid->ptr ); | ||
| 35 | return $self; | ||
| 36 | } | ||
| 37 | |||
| 38 | sub hide_head { check_rc Git::Libgit2::FFI::git_revwalk_hide_head( $_[0]->_handle ); $_[0] } | ||
| 39 | sub hide_ref { check_rc Git::Libgit2::FFI::git_revwalk_hide_ref( $_[0]->_handle, $_[1] ); $_[0] } | ||
| 40 | sub hide_glob { check_rc Git::Libgit2::FFI::git_revwalk_hide_glob( $_[0]->_handle, $_[1] ); $_[0] } | ||
| 41 | |||
| 42 | sub sorting { | ||
| 43 | my ( $self, $mode ) = @_; | ||
| 44 | check_rc Git::Libgit2::FFI::git_revwalk_sorting( $self->_handle, $mode ); | ||
| 45 | return $self; | ||
| 46 | } | ||
| 47 | |||
| 48 | sub reset { check_rc Git::Libgit2::FFI::git_revwalk_reset( $_[0]->_handle ); $_[0] } | ||
| 49 | sub simplify_first_parent { | ||
| 50 | check_rc Git::Libgit2::FFI::git_revwalk_simplify_first_parent( $_[0]->_handle ); | ||
| 51 | $_[0]; | ||
| 52 | } | ||
| 53 | |||
| 54 | sub next { | ||
| 55 | my $self = shift; | ||
| 56 | my $raw = "\0" x 20; | ||
| 57 | my ($p) = scalar_to_buffer($raw); | ||
| 58 | my $rc = Git::Libgit2::FFI::git_revwalk_next( $p, $self->_handle ); | ||
| 59 | return undef if $rc == GIT_ITEROVER; | ||
| 60 | check_rc $rc; | ||
| 61 | return Git::Native::Oid->from_raw($raw); | ||
| 62 | } | ||
| 63 | |||
| 64 | sub all { | ||
| 65 | my $self = shift; | ||
| 66 | my @out; | ||
| 67 | while ( defined( my $o = $self->next ) ) { push @out, $o } | ||
| 68 | return \@out; | ||
| 69 | } | ||
| 70 | |||
| 71 | sub DEMOLISH { | ||
| 72 | my $self = shift; | ||
| 73 | Git::Libgit2::FFI::git_revwalk_free( $self->{_handle} ) if $self->{_handle}; | ||
| 74 | } | ||
| 75 | |||
| 76 | 1; | ||
| 77 | |||
| 78 | __END__ |