| 1 | package Module::Release::Subversion; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use base qw(Exporter Module::Release); | ||
| 6 | |||
| 7 | our @EXPORT = qw(check_cvs cvs_tag); | ||
| 8 | |||
| 9 | use URI; # svn URL mangling | ||
| 10 | |||
| 11 | our $VERSION = '0.10'; | ||
| 12 | |||
| 13 | =head1 NAME | ||
| 14 | |||
| 15 | Module::Release::Subversion - Use Subversion instead of CVS with Module::Release | ||
| 16 | |||
| 17 | =head1 SYNOPSIS | ||
| 18 | |||
| 19 | In F<.releaserc> | ||
| 20 | |||
| 21 | release_subclass Module::Release::Subversion | ||
| 22 | |||
| 23 | In your subclasses of Module::Release: | ||
| 24 | |||
| 25 | use base qw(Module::Release::Subversion); | ||
| 26 | |||
| 27 | =head1 DESCRIPTION | ||
| 28 | |||
| 29 | Module::Release::Subversion subclasses Module::Release, and provides | ||
| 30 | its own implementations of the C<check_cvs()> and C<cvs_tag()> methods | ||
| 31 | that are suitable for use with a Subversion repository rather than a | ||
| 32 | CVS repository. | ||
| 33 | |||
| 34 | These methods are B<automatically> exported in to the callers namespace | ||
| 35 | using Exporter. | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | =head2 C<check_cvs()> | ||
| 40 | |||
| 41 | Check the state of the Subversion repository. | ||
| 42 | |||
| 43 | =cut | ||
| 44 | |||
| 45 | sub check_cvs { | ||
| 46 | my $self = shift; | ||
| 47 | |||
| 48 | print "Checking state of Subversion... "; | ||
| 49 | |||
| 50 | my $svn_update = $self->run('svn status --show-updates --verbose 2>&1'); | ||
| 51 | |||
| 52 | if($?) { | ||
| 53 | die sprintf("\nERROR: svn failed with non-zero exit status: %d\n\n" | ||
| 54 | . "Aborting release\n", $? >> 8); | ||
| 55 | } | ||
| 56 | |||
| 57 | # Trim $svn_update a bit to make the regex later a little simpler | ||
| 58 | $svn_update =~ s/^\?\s+/?/; # Collapse spaces after /^?/ | ||
| 59 | # Remove the revision number and author columns | ||
| 60 | $svn_update =~ s/^(........)\s+\d+\s+\d+\s+\S+\s+(.*)$/$1 $2/mg; | ||
| 61 | |||
| 62 | my %message = ( | ||
| 63 | qr/^C......./ => 'These files have conflicts', | ||
| 64 | qr/^M......./ => 'These files have not been checked in', | ||
| 65 | qr/^........\*/ => 'These files need to be updated', | ||
| 66 | qr/^P......./ => 'These files need to be patched', | ||
| 67 | qr/^A......./ => 'These files were added but not checked in', | ||
| 68 | qr/^D......./ => 'These files are scheduled for deletion', | ||
| 69 | qr/^\?......./ => 'I don\'t know about these files', | ||
| 70 | ); | ||
| 71 | |||
| 72 | my @svn_states = keys %message; | ||
| 73 | |||
| 74 | my %svn_state; | ||
| 75 | foreach my $state (@svn_states) { | ||
| 76 | $svn_state{$state} = [ $svn_update =~ /$state\s+(.*)/gm ]; | ||
| 77 | |||
| 78 | } | ||
| 79 | |||
| 80 | my $rule = "-" x 50; | ||
| 81 | my $count; | ||
| 82 | my $question_count; | ||
| 83 | |||
| 84 | foreach my $key (sort keys %svn_state) { | ||
| 85 | my $list = $svn_state{$key}; | ||
| 86 | next unless @$list; | ||
| 87 | $count += @$list unless $key eq qr/^\?......./; | ||
| 88 | $question_count += @$list if $key eq qr/^\?......./; | ||
| 89 | |||
| 90 | local $" = "\n\t"; | ||
| 91 | print "\n\t$message{$key}\n\t$rule\n\t@$list\n"; | ||
| 92 | } | ||
| 93 | |||
| 94 | die "\nERROR: Subversion is not up-to-date ($count files): Can't release files\n" | ||
| 95 | if $count; | ||
| 96 | |||
| 97 | if($question_count) { | ||
| 98 | print "\nWARNING: Subversion is not up-to-date ($question_count files unknown); ", | ||
| 99 | "continue anwyay? [Ny] " ; | ||
| 100 | die "Exiting\n" unless <> =~ /^[yY]/; | ||
| 101 | } | ||
| 102 | |||
| 103 | print "Subversion up-to-date\n"; | ||
| 104 | } # check_cvs | ||
| 105 | |||
| 106 | =head2 C<cvs_tag()> | ||
| 107 | |||
| 108 | Tag the release in local Subversion. | ||
| 109 | |||
| 110 | The approach is fairly simple. C<svn info> is run to extract the | ||
| 111 | Subversion URL for the current directory, and the first occurence of | ||
| 112 | '/trunk/' in the URL is replaced with '/tags/'. We check that the new URL | ||
| 113 | exists, and then C<svn copy> is used to do the tagging. | ||
| 114 | |||
| 115 | Failures are non fatal, since the upload has already happened. | ||
| 116 | |||
| 117 | =cut | ||
| 118 | |||
| 119 | sub cvs_tag { | ||
| 120 | my $self = shift; | ||
| 121 | |||
| 122 | my $svn_info = $self->run('svn info .'); | ||
| 123 | if($?) { | ||
| 124 | warn sprintf("\nWARNING: 'svn info .' failed with non-zero exit status: %d\n", $? >> 8); | ||
| 125 | return; | ||
| 126 | } | ||
| 127 | |||
| 128 | $svn_info =~ /^URL: (.*)$/m; | ||
| 129 | my $trunk_url = URI->new($1); | ||
| 130 | |||
| 131 | my @tag_url = $trunk_url->path_segments(); | ||
| 132 | if(! grep /^trunk$/, @tag_url) { | ||
| 133 | warn "\nWARNING: Current SVN URL:\n $trunk_url\ndoes not contain a 'trunk' component\n"; | ||
| 134 | warn "Aborting tagging.\n"; | ||
| 135 | return; | ||
| 136 | } | ||
| 137 | |||
| 138 | foreach (@tag_url) { # Find the first 'trunk' component, and | ||
| 139 | if($_ eq 'trunk') { # change it to 'tags' | ||
| 140 | $_ = 'tags'; | ||
| 141 | last; | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | my $tag_url = $trunk_url->clone(); | ||
| 146 | |||
| 147 | $tag_url->path_segments(@tag_url); | ||
| 148 | |||
| 149 | # Make sure the top-level path exists | ||
| 150 | # | ||
| 151 | # Can't use $self->run() because of a bug where $fh isn't closed, which | ||
| 152 | # stops $? from being properly propogated. Reported to brian d foy as | ||
| 153 | # part of RT#6489 | ||
| 154 | system "svn list $tag_url 2>&1"; | ||
| 155 | if($?) { | ||
| 156 | warn sprintf("\nWARNING:\n svn list $tag_url\nfailed with non-zero exit status: %d\n", $? >> 8); | ||
| 157 | warn "Assuming tagging directory does not exist in repo. Please create it.\n"; | ||
| 158 | warn "\nAborting tagging.\n"; | ||
| 159 | return; | ||
| 160 | } | ||
| 161 | |||
| 162 | my $tag = $self->make_cvs_tag; | ||
| 163 | push @tag_url, $tag; | ||
| 164 | $tag_url->path_segments(@tag_url); | ||
| 165 | print "Tagging release to $tag_url\n"; | ||
| 166 | |||
| 167 | system 'svn', 'copy', $trunk_url, $tag_url; | ||
| 168 | |||
| 169 | if ( $? ) { | ||
| 170 | # already uploaded, and tagging is not (?) essential, so warn, don't die | ||
| 171 | warn sprintf( | ||
| 172 | "\nWARNING: cvs failed with non-zero exit status: %d\n", | ||
| 173 | $? >> 8 | ||
| 174 | ); | ||
| 175 | } | ||
| 176 | |||
| 177 | } # cvs_tag | ||
| 178 | |||
| 179 | =head1 AUTHOR | ||
| 180 | |||
| 181 | Nik Clayton <nik@FreeBSD.org> | ||
| 182 | |||
| 183 | Copyright 2004 Nik Clayton. All Rights Reserved. | ||
| 184 | |||
| 185 | This program is free software; you can redistribute it | ||
| 186 | and/or modify it under the same terms as Perl itself. | ||
| 187 | |||
| 188 | =head1 BUGS | ||
| 189 | |||
| 190 | None known. | ||
| 191 | |||
| 192 | Bugs should be reported to me via the CPAN RT system. | ||
| 193 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Module::Release::Extras>. | ||
| 194 | |||
| 195 | |||
| 196 | =head1 SEE ALSO | ||
| 197 | |||
| 198 | Module::Release | ||
| 199 | |||
| 200 | =cut | ||
| 201 | |||
| 202 | 1; |