X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FGitalist%2FGit%2FObject%2FCommit.pm;h=f3202dfde5b344950719696fcce82a0c44c58710;hb=f707d2644b79c7a5563b130e89b160e1aad4f4bb;hp=7c6ebf0532b7b264971b512144b30028c588476d;hpb=9cd610f4cca51a71120666e508d7820122222351;p=catagits%2FGitalist.git diff --git a/lib/Gitalist/Git/Object/Commit.pm b/lib/Gitalist/Git/Object/Commit.pm index 7c6ebf0..f3202df 100644 --- a/lib/Gitalist/Git/Object/Commit.pm +++ b/lib/Gitalist/Git/Object/Commit.pm @@ -6,9 +6,11 @@ class Gitalist::Git::Object::Commit 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', @@ -21,7 +23,34 @@ class Gitalist::Git::Object::Commit ], ); - method diff ( Maybe[Bool] :$patch?, + method get_patch ( Maybe[NonEmptySimpleStr] $parent?, + Int $count?) { + $count ||= 1; + # Assemble the git command. + # common args: + my @cmd_args = qw/format-patch --encoding=utf8 --stdout/; + # single patch, or patch set? + if ($count > 1) { + push @cmd_args, "-$count", "-n"; + } else { + push @cmd_args, "-1"; + } + # ref spec: + # if a parent is specified: hp..h + # if not, but a merge commit: --cc h + # otherwise: --root h + if (defined $parent) { + push @cmd_args, "$parent.." . $self->sha1; + } else { + push @cmd_args, $self->parents->length > 1 + ? '--cc' : '--root'; + push @cmd_args, $self->sha1; + } + my $out = $self->_run_cmd( @cmd_args ); + return $out; + } + + method diff ( Maybe[Bool] :$patch?, Maybe[NonEmptySimpleStr] :$parent?, Maybe[NonEmptySimpleStr] :$file? ) {