From: Dan Brook Date: Sun, 20 Feb 2011 12:40:57 +0000 (+0000) Subject: Ignore ancient/malformed tags. X-Git-Tag: 0.002008~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FGitalist.git;a=commitdiff_plain;h=84f30d653a5b503c9e6e1d8784fb2d21db7736c4 Ignore ancient/malformed tags. Previously Gitalist::Git::Tag::BUILDARGS would croak when constructing DateTime for wonky tags i.e d6602ec5194c87b0fc87103ca4d67251c76f233a (the first tag in the git repo). Now we just ignore them because I think it's safe to presume they are very much the exception. --- diff --git a/lib/Gitalist/Git/Repository.pm b/lib/Gitalist/Git/Repository.pm index 571656e..2832505 100644 --- a/lib/Gitalist/Git/Repository.pm +++ b/lib/Gitalist/Git/Repository.pm @@ -25,12 +25,12 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils { # Last path component becomes $self->name # Full path to git objects becomes $self->path my $name = $dir->dir_list(-1); - if(-f $dir->file('.git', 'HEAD')) { # Non-bare repo above .git - $dir = $dir->subdir('.git'); - $name = $dir->dir_list(-2, 1); # .../name/.git - } elsif('.git' eq $dir->dir_list(-1)) { # Non-bare repo in .git - $name = $dir->dir_list(-2); - } + if(-f $dir->file('.git', 'HEAD')) { # Non-bare repo above .git + $dir = $dir->subdir('.git'); + $name = $dir->dir_list(-2, 1); # .../name/.git + } elsif('.git' eq $dir->dir_list(-1)) { # Non-bare repo in .git + $name = $dir->dir_list(-2); + } confess("Can't find a git repository at " . $dir) unless ( -f $dir->file('HEAD') ); return $class->$orig(name => $name, @@ -215,8 +215,8 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils { $description = $self->path->file('description')->slurp; chomp $description; }; - $description = "Unnamed repository, edit the .git/description file to set a description" - if $description eq "Unnamed repository; edit this file 'description' to name the repository."; + $description = "Unnamed repository, edit the .git/description file to set a description" + if $description eq "Unnamed repository; edit this file 'description' to name the repository."; return $description; } @@ -255,11 +255,10 @@ class Gitalist::Git::Repository with Gitalist::Git::HasUtils { '--format=%(objectname) %(objecttype) %(refname) %(*objectname) %(*objecttype) %(subject)%00%(creator)', 'refs/tags' ); - my @ret; - for my $line (@revlines) { - push @ret, Gitalist::Git::Tag->new($line); - } - return \@ret; + return [ + map Gitalist::Git::Tag->new($_), + grep Gitalist::Git::Tag::is_valid_tag($_), @revlines + ]; } method _build_references { diff --git a/lib/Gitalist/Git/Tag.pm b/lib/Gitalist/Git/Tag.pm index be53088..a0a8ea6 100644 --- a/lib/Gitalist/Git/Tag.pm +++ b/lib/Gitalist/Git/Tag.pm @@ -76,4 +76,10 @@ around BUILDARGS => sub { } }; +sub is_valid_tag { + local $_ = pop; + # Ignore tags like - http://git.kernel.org/?p=git/git.git;a=tag;h=d6602ec + return /^\S+ \S+ \S+ (?:\S+)? (?:\S+)?[^\0]+\0.*\s\d+\s+[+-]\d+$/; +} + 1; diff --git a/root/repository/tags.tt2 b/root/repository/tags.tt2 index 3518081..c9b0567 100755 --- a/root/repository/tags.tt2 +++ b/root/repository/tags.tt2 @@ -1,7 +1 @@ -
-
- [% Repository.name %] -
- - [% subinclude('/fragment/repository/tags', c.req.captures) %] -
+[% subinclude('/fragment/repository/tags', c.req.captures) %] diff --git a/t/02git_tag.t b/t/02git_tag.t index baa9983..350e9e5 100644 --- a/t/02git_tag.t +++ b/t/02git_tag.t @@ -13,12 +13,15 @@ use Data::Dumper; BEGIN { use_ok 'Gitalist::Git::Tag' } +my $ref_sha1 = '3f7567c7bdf7e7ebf410926493b92d398333116e'; # Create an instance from for-each-ref output -my $revline="36c6c6708b8360d7023e8a1649c45bcf9b3bd818 commit refs/tags/0.01 add dir1/file2\0Florian Ragwitz 1173210275 +0100"; -#my $revline="a92fb1c9282f7319099ce7f783c8be7d5360f6e3\0refs/heads/model-cleanup\0Zachary Stevens 1277601094 +0100"; +my $revline="36c6c6708b8360d7023e8a1649c45bcf9b3bd818 commit refs/tags/0.01 $ref_sha1 add dir1/file2\0Florian Ragwitz 1173210275 +0100"; + my $instance = Gitalist::Git::Tag->new($revline); isa_ok($instance, 'Gitalist::Git::Tag'); +ok($instance->$_, $_) for $instance->meta->get_attribute_list; + # Create an instance, passing last_change as a DateTime use DateTime; my $timespec = [1173210275, '+0100']; @@ -34,3 +37,12 @@ my $head = Gitalist::Git::Tag->new( last_change => $dt, ); isa_ok($head, 'Gitalist::Git::Tag'); + +my $oldtag = "d6602ec5194c87b0fc87103ca4d67251c76f233a tag refs/tags/v0.99 a3eb250f996bf5e12376ec88622c4ccaabf20ea8 commit Test-release for wider distribution."; + +ok(!Gitalist::Git::Tag::is_valid_tag($oldtag), 'Gitalist::Git::Tag::is_valid_tag ancient tag'); +ok(Gitalist::Git::Tag::is_valid_tag($revline), 'Gitalist::Git::Tag::is_valid_tag regular tag'); + +# Tags don't necessarily have a refname, check we deal with its absence. +$revline =~ s/$ref_sha1//; +ok(Gitalist::Git::Tag::is_valid_tag($revline), 'Gitalist::Git::Tag::is_valid_tag regular tag sans ref sha1');