Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
compare: 949c180bfb
Checking mergeability… Don't worry, you can still create the pull request.
  • 14 commits
  • 10 files changed
  • 0 commit comments
  • 3 contributors
View
3  .gitignore
@@ -0,0 +1,3 @@
+GitStore-*
+Makefile
+inc
View
21 Changes
@@ -1,25 +1,28 @@
Revision history for GitStore
-0.07 2010.7.23
+{{$NEXT}}
+ * Add history() method.
+
+0.07 2010-7-23
* fix the commits such that they don't clobber their branch anymore.
-0.06 2010.3.3
+0.06 2010-3-3
Change the way author is handled to work with new version
of Git::PurePerl::NewObject::Commit.
-0.05 2009.3.16
- fix commit date by time()
- fix commit author/committer by configurable author
+0.05 2009-3-16
+ - fix commit date by time()
+ - fix commit author/committer by configurable author
-0.04 2009.3.16
+0.04 2009-3-16
FAQ doc
-0.03 2009.3.14
+0.03 2009-3-14
big bug fix because I used Git::PurePerl wrong, thanks for acme
-0.02 2009.3.14
+0.02 2009-3-14
fix broken CPAN dist
-0.01 2009.3.14
+0.01 2009-3-14
First version, released on an unsuspecting world.
View
20 MANIFEST
@@ -1,4 +1,14 @@
+Build.PL
Changes
+INSTALL
+LICENSE
+MANIFEST
+META.json
+META.yml
+Makefile.PL
+README
+README.mkdn
+SIGNATURE
inc/Module/AutoInstall.pm
inc/Module/Install.pm
inc/Module/Install/AutoInstall.pm
@@ -11,13 +21,13 @@ inc/Module/Install/Metadata.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
lib/GitStore.pm
-Makefile.PL
-MANIFEST This list of files
-META.yml
-README
-t/.gitignore
+lib/GitStore/Revision.pm
+t/00-compile.t
t/00-load.t
+t/000-report-versions.t
t/01-basic.t
t/02-next.t
t/03-next-next.t
+t/history.t
+t/many-commits.t
t/pod.t
View
5 MANIFEST.SKIP
@@ -0,0 +1,5 @@
+^MANIFEST\.SKIP$
+^GitStore
+^Makefile$
+\.gitignore
+dist.ini
View
28 META.yml
@@ -1,28 +0,0 @@
----
-abstract: 'Git as versioned data store in Perl'
-author:
- - 'Fayland Lam <fayland@gmail.com>'
-build_requires:
- ExtUtils::MakeMaker: 6.42
- Test::More: 0
-configure_requires:
- ExtUtils::MakeMaker: 6.42
-distribution_type: module
-generated_by: 'Module::Install version 0.91'
-license: perl
-meta-spec:
- url: http://module-build.sourceforge.net/META-spec-v1.4.html
- version: 1.4
-name: GitStore
-no_index:
- directory:
- - inc
- - t
-requires:
- Git::PurePerl: 0.41
- Moose: 0.56
- Storable: 2.18
-resources:
- license: http://dev.perl.org/licenses/
- repository: http://github.com/fayland/perl-git-store/tree/master
-version: 0.06
View
19 Makefile.PL
@@ -1,19 +0,0 @@
-use inc::Module::Install;
-
-name 'GitStore';
-all_from 'lib/GitStore.pm';
-author 'Fayland Lam <fayland@gmail.com>';
-license 'perl';
-
-repository 'http://github.com/fayland/perl-git-store/tree/master';
-
-requires 'Moose' => '0.56';
-requires 'Storable' => '2.18';
-requires 'Git::PurePerl' => '0.41';
-
-build_requires 'Test::More';
-
-auto_install;
-
-WriteAll;
-
View
8 dist.ini
@@ -0,0 +1,8 @@
+name = GitStore
+copyright_holder= Fayland Lam <fayland@gmail.com>
+author= Fayland Lam <fayland@gmail.com>
+author= Yanick Champoux <yanick@cpan.org>
+
+[@Filter]
+-bundle=@YANICK
+-remove=Covenant
View
45 lib/GitStore.pm
@@ -43,10 +43,27 @@ has 'git' => (
isa => 'Git::PurePerl',
lazy => 1,
default => sub {
- Git::PurePerl->new( directory => shift->repo );
+ my $repo = $_[0]->repo;
+ return Git::PurePerl->new(
+ ( $repo =~ m/\.git$/ ? 'gitdir' : 'directory') => $repo
+ );
}
);
+# TODO use Git::PurePerl attribute instead
+has 'git_repo' => (
+ is => 'ro',
+ isa => 'Git::Repository',
+ lazy => 1,
+ default => sub {
+ require Git::Repository;
+ my $repo = shift->repo;
+ return Git::Repository->new(
+ ( $repo =~ m/\.git$/ ? 'git_dir' : 'work_tree') => $repo
+ )
+ },
+);
+
sub BUILD {
my $self = shift;
@@ -156,15 +173,15 @@ sub commit {
# there might not be a parent, if it's a new branch
my $parent = eval { $self->git->ref( 'refs/heads/'.$self->branch )->sha1 };
+ my $timestamp = DateTime->now;
my $commit = Git::PurePerl::NewObject::Commit->new(
( parent => $parent ) x !!$parent,
tree => $tree->sha1,
- #content => $content,
author => $self->author,
committer => $self->author,
comment => $message||'',
- authored_time => DateTime->now,
- committed_time => DateTime->now,
+ authored_time => $timestamp,
+ committed_time => $timestamp,
);
$self->git->put_object($commit);
@@ -198,6 +215,20 @@ sub _cond_thaw {
}
}
+sub history {
+ my ( $self, $path ) = @_;
+
+ require GitStore::Revision;
+
+ return reverse map { GitStore::Revision->new(
+ path => $path,
+ commit => $_,
+ gitstore => $self,
+ ) }
+ $self->git_repo->run( 'log', '--pretty=format:%H', '--', $path );
+}
+
+
no Moose;
__PACKAGE__->meta->make_immutable;
@@ -293,6 +324,12 @@ commit the B<set> changes into Git
discard the B<set> changes
+=head2 history($path)
+
+Returns a list of L<GitStore::Revision> objects representing the changes
+brought to the I<$path>. The changes are returned in ascending commit order.
+
+
=head1 FAQ
=head2 why the files are B<not> there?
View
112 lib/GitStore/Revision.pm
@@ -0,0 +1,112 @@
+package GitStore::Revision;
+#ABSTRACT: the state of a given path for a specific commit
+
+=head1 SYNOPSIS
+
+ use GitStore;
+
+ my $gs = GitStore->new('/path/to/repo');
+
+ my @history = $gs->history( 'path/to/object' );
+
+ for my $rev ( @history ) {
+ say "modified at: ", $rev->timestamp;
+ say "commit message was: ", $rev->message;
+ say "===\n", $rev->content;
+ }
+
+=head1 DESCRIPTION
+
+Represents an object in a L<GitStore> at a specific commit.
+
+=cut
+
+use strict;
+use warnings;
+
+use Moose;
+
+use GitStore;
+use DateTime;
+
+=head1 METHODS
+
+=head2 commit
+
+Returns the SHA-1 of the commit.
+
+=cut
+
+has commit => (
+ is => 'ro',
+ required => 1,
+);
+
+=head2 path
+
+Returns the path of the L<GitStore> object.
+
+=cut
+
+has path => (
+ is => 'ro',
+ required => 1,
+);
+
+has gitstore => (
+ is => 'ro',
+ isa => 'GitStore',
+ required => 1,
+ handles => {
+ git_repo => 'git_repo'
+ },
+);
+
+=head2 timestamp
+
+Returns the commit time of the revision as a L<DateTime> object.
+
+=cut
+
+sub timestamp {
+ my $self = shift;
+
+ return DateTime->from_epoch( epoch =>
+ ($self->git_repo->run( 'show', '--pretty=format:%at', $self->commit ))[0] );
+}
+
+=head2 message
+
+Returns the commit message of the revision. Note that the message might have
+additional trailing carriage returns.
+
+=cut
+
+sub message {
+ my $self = shift;
+
+ ( my $comment = $self->git_repo->run( 'show', '--pretty=format:%B',
+ $self->commit ) )
+ =~ s/^diff --git.*//sm;
+
+ return $comment;
+}
+
+=head2 content
+
+Returns the content of the object. If the object is a frozen ref, the
+structure will be returned, like for `GitStore`'s `get()`.
+
+=cut
+
+sub content {
+ my $self = shift;
+
+ GitStore::_cond_thaw(
+ scalar $self->git_repo->run('show', join ':', $self->commit, $self->path)
+ );
+}
+
+
+__PACKAGE__->meta->make_immutable;
+1;
View
61 t/history.t
@@ -0,0 +1,61 @@
+use strict;
+use warnings;
+
+use Test::More tests => 23;
+
+use Git::PurePerl;
+use Path::Class;
+use GitStore;
+use FindBin qw/$Bin/;
+
+# init the test
+my $directory = "$Bin/test";
+dir($directory)->rmtree;
+my $gitobj = Git::PurePerl->init( directory => $directory );
+
+my $gs = GitStore->new($directory);
+
+my $start_time = time;
+
+my @content = qw/ alpha beta gamma delta /;
+
+for ( 0..1 ) {
+ $gs->set( 'foo/bar/baz', $content[$_] );
+ $gs->commit("message for $content[$_]");
+}
+
+$gs->set( 'bar', { freeze => 'this' } );
+$gs->commit( 'not important' );
+
+for ( 2..3 ) {
+ $gs->set( 'foo/bar/baz', $content[$_] );
+ $gs->commit("message for $content[$_]");
+}
+
+my $end_time = time;
+
+my @history = $gs->history('foo/bar/baz');
+
+is @history => 4, '4 entries for foo/bar/baz';
+
+my $last_time = $start_time;
+my $i = 0;
+for ( @history ) {
+ isa_ok $_->timestamp, 'DateTime';
+ cmp_ok $_->timestamp->epoch, '>=', $last_time, "commited after last one";
+ cmp_ok $_->timestamp->epoch, '<=', $end_time, "commited before last time";
+ $last_time = $_->timestamp->epoch;
+
+ like $_->message => qr/^message for $content[$i]\s*$/, "message";
+ is $_->content => $content[$i], "content";
+
+ $i++
+}
+
+@history = $gs->history( 'bar' );
+
+is @history => 1, 'only one commit for bar';
+
+is_deeply scalar($history[0]->content) => { freeze => 'this' },
+ "returns expanded object";
+

No commit comments for this range

Something went wrong with that request. Please try again.