From 77e5a1a9ea541970c061632995e93c4012f81ca5 Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Wed, 30 May 2012 14:50:24 +1200 Subject: [PATCH 1/8] add a FromHEAD method walker that doesn't need consttructor args --- example/ls_sha1.pl | 5 +-- .../Walker/Method/FirstParent/FromHEAD.pm | 33 +++++++++++++++++++ t/{02_firstparent.t => 0200_firstparent.t} | 0 t/0201_firstparent_fromhead.t | 33 +++++++++++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm rename t/{02_firstparent.t => 0200_firstparent.t} (100%) create mode 100644 t/0201_firstparent_fromhead.t diff --git a/example/ls_sha1.pl b/example/ls_sha1.pl index 3a651af..2999d61 100644 --- a/example/ls_sha1.pl +++ b/example/ls_sha1.pl @@ -49,12 +49,13 @@ sub trim { sub abbr_sha { my $sha = shift; - return substr $sha, 0, 5; + return substr $sha, 0, 8; } my $repo = Git::PurePerl->new( gitdir => find_git_dir( $cwd ), ); + my $walker = Git::PurePerl::Walker->new( repo => $repo, - method => Git::PurePerl::Walker::Method::FirstParent->new( start => $repo->head_sha1, ), + method => 'FirstParent::FromHEAD', on_commit => sub { my $commit = shift; my $is_merge = ' '; diff --git a/lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm b/lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm new file mode 100644 index 0000000..ccde99a --- /dev/null +++ b/lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm @@ -0,0 +1,33 @@ +use strict; +use warnings; +package Git::PurePerl::Walker::Method::FirstParent::FromHEAD; + +# FILENAME: FromHEAD.pm +# CREATED: 30/05/12 13:57:49 by Kent Fredric (kentnl) +# ABSTRACT: Start at the HEAD of the current repo. + +use Moose; +extends 'Git::PurePerl::Walker::Method::FirstParent'; + +has '+start' => ( + lazy_build => 1, + required => 0, +); + +has '+_repo' => ( + predicate => '_has_repo', +); + +sub _build_start { + my $self = shift; + unless ( $self->_has_repo ) { + die "No repo defined while trying to find a starting commit"; + } + return $self->_repo->head_sha1; +} + +no Moose; +__PACKAGE__->meta->make_immutable; +1; + + diff --git a/t/02_firstparent.t b/t/0200_firstparent.t similarity index 100% rename from t/02_firstparent.t rename to t/0200_firstparent.t diff --git a/t/0201_firstparent_fromhead.t b/t/0201_firstparent_fromhead.t new file mode 100644 index 0000000..1db4da0 --- /dev/null +++ b/t/0201_firstparent_fromhead.t @@ -0,0 +1,33 @@ +use strict; +use warnings; + +use Test::More; +use FindBin; +use Path::Class qw( dir ); + +use lib dir( $FindBin::Bin )->subdir( "tlib" )->absolute->stringify; +use t::util { '$repo' => 1 }; +use Git::PurePerl::Walker::Method::FirstParent::FromHEAD; + +my $expected = { + 'HEAD' => '010fb4bcf7d92c031213f43d0130c811cbb355e7', + 'HEAD~1' => '10003632f7b967108151e20639e4b425c5e4c731', +}; + +my $method_factory = Git::PurePerl::Walker::Method::FirstParent::FromHEAD->new(); +my $method = $method_factory->for_repository( $repo ); + +is( $method->_commit->sha1, $expected->{ HEAD }, 'At Head' ); +is( $method->current->sha1, $expected->{ HEAD }, 'At Head' ); +is( $method->start, $expected->{ HEAD }, 'At Head' ); +ok( $method->has_next, "Has more items" ); +is( $method->peek_next->sha1, $expected->{ 'HEAD~1' }, 'peak_next gives head~1' ); + +$method->next; + +is( $method->_commit->sha1, $expected->{ 'HEAD~1' }, 'At Head~1' ); +is( $method->current->sha1, $expected->{ 'HEAD~1' }, 'At Head~1' ); +is( $method->start, $expected->{ 'HEAD' }, 'At Head' ); +ok( !$method->has_next, "Has no more items" ); + +done_testing; From 3387631d5d3635c7d176c65461c3fc6cbceadf9e Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Wed, 30 May 2012 14:50:47 +1200 Subject: [PATCH 2/8] Document FromHEAD Method --- .../Walker/Method/FirstParent/FromHEAD.pm | 100 ++++++++++++++++-- 1 file changed, 89 insertions(+), 11 deletions(-) diff --git a/lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm b/lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm index ccde99a..8a8154b 100644 --- a/lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm +++ b/lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm @@ -1,5 +1,6 @@ use strict; use warnings; + package Git::PurePerl::Walker::Method::FirstParent::FromHEAD; # FILENAME: FromHEAD.pm @@ -7,27 +8,104 @@ package Git::PurePerl::Walker::Method::FirstParent::FromHEAD; # ABSTRACT: Start at the HEAD of the current repo. use Moose; + +=extends Git::PurePerl::Walker::Method::FirstParent + +L<< C>|Git::PurePerl::Walker::Method::FirstParent >> + +=cut + extends 'Git::PurePerl::Walker::Method::FirstParent'; +=imethod for_repository + +L<< C-EI>|Git::PurePerl::Walker::Role::HasRepo/for_repository >> + +=cut + +=imethod clone + +L<< C-EI>|MooseX::Clone/clone-params >> + +=cut + +=imethod _repo + +L<< C-EI<_repo( $repo )>>|Git::PurePerl::Walker::Role::HasRepo/_repo >> + +=imethod start + +L<< C-EI>|Git::PurePerl::Walker::Method::FirstParent/start >> + +=cut + +=imethod _commit + +L<< C-EI<_commit( $commit_object )>>|Git::PurePerl::Walker::Method::FirstParent/_commit >> + +=cut + has '+start' => ( - lazy_build => 1, - required => 0, + init_arg => undef, + lazy_build => 1, + required => 0, ); -has '+_repo' => ( - predicate => '_has_repo', -); +=p_attrmethod _has_repo + +=cut + +has '+_repo' => ( predicate => '_has_repo', ); + +=p_method _build_start + +=cut sub _build_start { - my $self = shift; - unless ( $self->_has_repo ) { - die "No repo defined while trying to find a starting commit"; - } - return $self->_repo->head_sha1; + my $self = shift; + unless ( $self->_has_repo ) { + die "No repo defined while trying to find a starting commit"; + } + return $self->_repo->head_sha1; } +=imethod _build_commit + +L<< C-EI<_build_commit()>>|Git::PurePerl::Walker::Method::FirstParent/_build_commit >> + +=cut + +=imethod current + +L<< C-EI>|Git::PurePerl::Walker::Method::FirstParent/current >> + +=cut + +=imethod has_next + +L<< C-EI>|Git::PurePerl::Walker::Method::FirstParent/has_next >> + +=cut + +=imethod next + +L<< C-EI>|Git::PurePerl::Walker::Method::FirstParent/next >> + +=cut + +=imethod peek_next + +L<< C-EI>|Git::PurePerl::Walker::Method::FirstParent/peek_next >> + +=cut + +=imethod reset + +L<< C-EI>|Git::PurePerl::Walker::Method::FirstParent/reset >> + +=cut + no Moose; __PACKAGE__->meta->make_immutable; 1; - From a53fe247b9d731abb159dd04bbc8a542f0d955be Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Wed, 30 May 2012 14:51:06 +1200 Subject: [PATCH 3/8] Add a ChangeLog format emitter --- example/ls_sha1_as_commit.pl | 78 ++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 example/ls_sha1_as_commit.pl diff --git a/example/ls_sha1_as_commit.pl b/example/ls_sha1_as_commit.pl new file mode 100644 index 0000000..faed15f --- /dev/null +++ b/example/ls_sha1_as_commit.pl @@ -0,0 +1,78 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +# FILENAME: ls_sha1.pl +# CREATED: 29/05/12 16:42:08 by Kent Fredric (kentnl) +# ABSTRACT: List all sha1's in parent order in current git repo + +use Path::Class qw( dir ); + + +my $cwd = dir( q{.} ); + +sub is_git_dir { + my ( $dir ) = @_; + return unless -e $dir->subdir( 'objects' ); + return unless -e $dir->subdir( 'refs' ); + return unless -e $dir->file( 'HEAD' ); + return 1; +} + +sub find_git_dir { + my $start = shift; + if ( is_git_dir( $start ) ) { + return $start; + } + if ( -e $start->subdir( '.git' ) && is_git_dir( $start->subdir( q{.git} ) ) ) { + return $start->subdir( '.git' ); + } + if ( $start->parent->stringify ne $start->stringify ) { + return find_git_dir( $start->parent ); + } + die "No Git Directory found"; +} + +require Git::PurePerl; +require Git::PurePerl::Walker; +require Git::PurePerl::Walker::Method::FirstParent; + +sub trim { + my $comment = shift; + $comment =~ s/\s+/ /g; + #if ( length( $comment ) > 80 ) { + # return substr( $comment, 0, 80 ) . '...'; + #} + return $comment; +} + +sub abbr_sha { + my $sha = shift; + return substr $sha, 0, 8; +} + +my $repo = Git::PurePerl->new( gitdir => find_git_dir( $cwd ), ); +use CPAN::Changes; +use CPAN::Changes::Release; +my $release = CPAN::Changes::Release->new( + version => '1.0', + date => '2012-05-30', + +); + +my $walker = Git::PurePerl::Walker->new( + repo => $repo, + method => 'FirstParent::FromHEAD', + on_commit => sub { + my $commit = shift; + $release->add_changes( { group => 'Git::Changes' }, sprintf "%s %s (%s)", abbr_sha( $commit->sha1 ), trim( $commit->comment ), $commit->author->name); + }, +); + +$walker->step_all; +my $changes = CPAN::Changes->new( + preamble => "Revision History for \$Project", +); +$changes->add_release( $release ); +print $changes->serialize(); From d059f592b970f4faa303de96a4d35c7f72e3b432 Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Wed, 30 May 2012 14:52:02 +1200 Subject: [PATCH 4/8] Update Changelog --- Changes | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Changes b/Changes index 936f08e..672e503 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,12 @@ Release history for Git-PurePerl-Walker {{$NEXT}} + [Git::Changes] + - a53fe247 Add a ChangeLog format emitter (Kent Fredric) + - 3387631d Document FromHEAD Method (Kent Fredric) + - 77e5a1a9 add a FromHEAD method walker that doesn't need consttructor + args (Kent Fredric) + 0.001002 2012-05-29T07:28:29Z - Greatly improve core documentation of ::Walker, covering user consumable parts. From 474f7725215da4d1388dab5b4c6733dc9c99d4d0 Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Wed, 30 May 2012 14:55:07 +1200 Subject: [PATCH 5/8] Tidyup / Critic --- lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm | 5 +++-- weaver.ini | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm b/lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm index 8a8154b..cbe22c7 100644 --- a/lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm +++ b/lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm @@ -63,8 +63,9 @@ has '+_repo' => ( predicate => '_has_repo', ); sub _build_start { my $self = shift; - unless ( $self->_has_repo ) { - die "No repo defined while trying to find a starting commit"; + if ( not $self->_has_repo ) { + require Carp; + Carp::confess('No repo defined while trying to find a starting commit'); } return $self->_repo->head_sha1; } diff --git a/weaver.ini b/weaver.ini index 70a44c2..3a61fe5 100644 --- a/weaver.ini +++ b/weaver.ini @@ -51,6 +51,10 @@ command = p_method header = PRIVATE ATTRIBUTE GENERATED METHODS command = p_attrmethod +[Collect / EXTENDS ] +header = EXTENDS +command = extends + [Collect / CONSUMED_ROLES] header = CONSUMED ROLES command = consumerole From 4822502446379365a389e5693b1f3ab3d5dda495 Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Wed, 30 May 2012 14:56:11 +1200 Subject: [PATCH 6/8] Tidy --- example/ls_sha1_as_commit.pl | 18 +++++++++++------- .../Walker/Method/FirstParent/FromHEAD.pm | 17 ++++++++--------- t/0201_firstparent_fromhead.t | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/example/ls_sha1_as_commit.pl b/example/ls_sha1_as_commit.pl index faed15f..295417e 100644 --- a/example/ls_sha1_as_commit.pl +++ b/example/ls_sha1_as_commit.pl @@ -9,7 +9,6 @@ use Path::Class qw( dir ); - my $cwd = dir( q{.} ); sub is_git_dir { @@ -41,6 +40,7 @@ sub find_git_dir { sub trim { my $comment = shift; $comment =~ s/\s+/ /g; + #if ( length( $comment ) > 80 ) { # return substr( $comment, 0, 80 ) . '...'; #} @@ -57,7 +57,7 @@ sub abbr_sha { use CPAN::Changes::Release; my $release = CPAN::Changes::Release->new( version => '1.0', - date => '2012-05-30', + date => '2012-05-30', ); @@ -65,14 +65,18 @@ sub abbr_sha { repo => $repo, method => 'FirstParent::FromHEAD', on_commit => sub { - my $commit = shift; - $release->add_changes( { group => 'Git::Changes' }, sprintf "%s %s (%s)", abbr_sha( $commit->sha1 ), trim( $commit->comment ), $commit->author->name); + my $commit = shift; + $release->add_changes( + { group => 'Git::Changes' }, + sprintf "%s %s (%s)", + abbr_sha( $commit->sha1 ), + trim( $commit->comment ), + $commit->author->name + ); }, ); $walker->step_all; -my $changes = CPAN::Changes->new( - preamble => "Revision History for \$Project", -); +my $changes = CPAN::Changes->new( preamble => "Revision History for \$Project", ); $changes->add_release( $release ); print $changes->serialize(); diff --git a/lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm b/lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm index cbe22c7..62caa57 100644 --- a/lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm +++ b/lib/Git/PurePerl/Walker/Method/FirstParent/FromHEAD.pm @@ -46,9 +46,9 @@ L<< C-EI<_commit( $commit_obje =cut has '+start' => ( - init_arg => undef, - lazy_build => 1, - required => 0, + init_arg => undef, + lazy_build => 1, + required => 0, ); =p_attrmethod _has_repo @@ -62,12 +62,12 @@ has '+_repo' => ( predicate => '_has_repo', ); =cut sub _build_start { - my $self = shift; - if ( not $self->_has_repo ) { + my $self = shift; + if ( not $self->_has_repo ) { require Carp; - Carp::confess('No repo defined while trying to find a starting commit'); - } - return $self->_repo->head_sha1; + Carp::confess( 'No repo defined while trying to find a starting commit' ); + } + return $self->_repo->head_sha1; } =imethod _build_commit @@ -109,4 +109,3 @@ L<< C-EI>|Git::PurePe no Moose; __PACKAGE__->meta->make_immutable; 1; - diff --git a/t/0201_firstparent_fromhead.t b/t/0201_firstparent_fromhead.t index 1db4da0..929aea2 100644 --- a/t/0201_firstparent_fromhead.t +++ b/t/0201_firstparent_fromhead.t @@ -15,7 +15,7 @@ my $expected = { }; my $method_factory = Git::PurePerl::Walker::Method::FirstParent::FromHEAD->new(); -my $method = $method_factory->for_repository( $repo ); +my $method = $method_factory->for_repository( $repo ); is( $method->_commit->sha1, $expected->{ HEAD }, 'At Head' ); is( $method->current->sha1, $expected->{ HEAD }, 'At Head' ); From 74f9436ebe350cb3728d47527b2b3ec8bf82894f Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Wed, 30 May 2012 14:56:55 +1200 Subject: [PATCH 7/8] Changes --- Changes | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changes b/Changes index 672e503..8cb14b8 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,9 @@ Release history for Git-PurePerl-Walker {{$NEXT}} [Git::Changes] + - 48225024 Tidy (Kent Fredric) + - 474f7725 Tidyup / Critic (Kent Fredric) + - d059f592 Update Changelog (Kent Fredric) - a53fe247 Add a ChangeLog format emitter (Kent Fredric) - 3387631d Document FromHEAD Method (Kent Fredric) - 77e5a1a9 add a FromHEAD method walker that doesn't need consttructor From f1ecf3eb66dc7c9bea29ba6eec277e2988bdcf21 Mon Sep 17 00:00:00 2001 From: Kent Fredric Date: Wed, 30 May 2012 14:57:55 +1200 Subject: [PATCH 8/8] v0.002000 [Git::Changes] - 48225024 Tidy (Kent Fredric) - 474f7725 Tidyup / Critic (Kent Fredric) - d059f592 Update Changelog (Kent Fredric) - a53fe247 Add a ChangeLog format emitter (Kent Fredric) - 3387631d Document FromHEAD Method (Kent Fredric) - 77e5a1a9 add a FromHEAD method walker that doesn't need consttructor args (Kent Fredric) --- Changes | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changes b/Changes index 8cb14b8..b3426c4 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,8 @@ Release history for Git-PurePerl-Walker {{$NEXT}} +0.002000 2012-05-30T02:57:21Z + [Git::Changes] - 48225024 Tidy (Kent Fredric) - 474f7725 Tidyup / Critic (Kent Fredric)