log = 50
summary = 17
</paging>
+
+<patches>
+ max = 16
+</patches>
sub patch : Local {
my ($self, $c) = @_;
+ $c->detach('patches', [1]);
+}
+
+sub patches : Local {
+ my ($self, $c, $count) = @_;
+ $count ||= Gitalist->config->{patches}{max};
my $commit = $self->_get_object($c);
my $parent = $c->req->param('hp') || undef;
- my $patch = $commit->patch( $parent );
+ my $patch = $commit->get_patch( $parent, $count );
$c->response->body($patch);
$c->response->content_type('text/plain');
$c->response->status(200);
-
-}
-
-sub patches : Local {
- # FIXME - implement patches
- Carp::croak "Not implemented.";
}
sub snapshot : Local {
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}/;
],
);
- method patch ( Maybe[NonEmptySimpleStr] $parent? ) {
- my @args = qw/format-patch --encoding=utf8 --stdout -1/;
- my $refspec = $self->sha1;
- if (defined $parent) {
- push @args, '-n';
- $refspec = $parent . '..' . $self->sha1;
+ 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;
}
- push @args, '--root', $refspec;
- my $out = $self->_run_cmd( @args );
- return $out;
+ return $self->_run_cmd( @cmd );
}
method diff ( Maybe[Bool] :$patch?,
test('/patch');
test('/patch', 'h=3f7567c7bdf7e7ebf410926493b92d398333116e');
test('/patch', 'h=3f7567c7bdf7e7ebf410926493b92d398333116e;hp=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
+ test('/patches');
+ test('/patches', 'h=3f7567c7bdf7e7ebf410926493b92d398333116e');
+ test('/patches', 'h=3f7567c7bdf7e7ebf410926493b92d398333116e;hp=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
}
done_testing;
', 'patch->{diff} is correct');
is($patch->{dst}, '5716ca5987cbf97d6bb54920bea6adde242d87e6', 'patch->{dst} is correct');
-is($commit_obj->patch, 'From 3f7567c7bdf7e7ebf410926493b92d398333116e Mon Sep 17 00:00:00 2001
+is($commit_obj->get_patch, 'From 3f7567c7bdf7e7ebf410926493b92d398333116e Mon Sep 17 00:00:00 2001
From: Florian Ragwitz <rafl@debian.org>
Date: Tue, 6 Mar 2007 20:39:45 +0100
Subject: [PATCH] bar
--
1.6.4.2
-', 'commit_obj->patch is correct');
+', 'commit_obj->get_patch can return a patch');
+
+like($commit_obj->get_patch(undef, 3), qr!PATCH 2/2!, 'commit_obj->get_patch can return a patchset');
test('/', 'a=patch;hb=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
test('/', 'a=patch;hb=3f7567c7bdf7e7ebf410926493b92d398333116e');
-TODO: {
- local $TODO = "Action: patches is not yet implemented.";
- test('/', 'a=patches');
- test('/', 'a=patches;h=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
- test('/', 'a=patches;h=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
- test('/', 'a=patches;h=3f7567c7bdf7e7ebf410926493b92d398333116e');
- test('/', 'a=patches;h=HEAD');
- test('/', 'a=patches;h=master');
- test('/', 'a=patches;h=refs/heads/master');
-}
+test('/', 'a=patches');
+test('/', 'a=patches;h=36c6c6708b8360d7023e8a1649c45bcf9b3bd818');
+test('/', 'a=patches;h=3bc0634310b9c62222bb0e724c11ffdfb297b4ac');
+test('/', 'a=patches;h=3f7567c7bdf7e7ebf410926493b92d398333116e');
+test('/', 'a=patches;h=HEAD');
+test('/', 'a=patches;h=master');
+test('/', 'a=patches;h=refs/heads/master');
test('/', 'a=search_help');
log = 50
summary = 16
</paging>
+
+<patches>
+ max = 16
+</patches>