class Gitalist::Git::Object::Commit
extends Gitalist::Git::Object
with Gitalist::Git::Object::HasTree {
+ use MooseX::Types::Moose qw/Str Int Bool Maybe ArrayRef/;
+ use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
+ use Moose::Autobox;
use List::MoreUtils qw/any zip/;
our $SHA1RE = qr/[0-9a-fA-F]{40}/;
+ has '+type' => ( default => 'commit' );
has '+_gpp_obj' => ( handles => [ 'comment',
'tree_sha1',
'committer',
],
);
- method diff ( Maybe[Bool] :$patch?,
+ method get_patch ( Maybe[NonEmptySimpleStr] $parent_hash?,
+ Int $patch_count?) {
+ # assembling the git command to execute...
+ my @cmd = qw/format-patch --encoding=utf8 --stdout/;
+
+ # patch, or patch set?
+ push @cmd,
+ defined $patch_count
+ ? "-$patch_count -n" : "-1";
+
+ # refspec
+ if (defined $parent_hash) {
+ # if a parent is specified: hp..h
+ push @cmd, "$parent_hash.." . $self->sha1;
+ } else {
+ # if not, but a merge commit: --cc h
+ # otherwise: --root h
+ push @cmd, $self->parents->length > 1
+ ? '--cc' : '--root';
+ push @cmd, $self->sha1;
+ }
+ return $self->_run_cmd( @cmd );
+ }
+
+ method diff ( Maybe[Bool] :$patch?,
Maybe[NonEmptySimpleStr] :$parent?,
Maybe[NonEmptySimpleStr] :$file?
) {
-# method diff (:$patch?, :$parent?, :$file?) {
- # Use parent if specifed, else take the parent from the commit
- # if there is only one, otherwise it was a merge commit.
$parent = $parent
? $parent
: $self->parents <= 1