Git-SVNReplay
view release on metacpan or search on metacpan
SVNReplay.pm view on Meta::CPAN
# This resets everything that's tracked by git.
$this->logging_systemx(qw(git reset --hard));
eoutdent;
return 1;
}
# }}}
# create_svn_repo {{{
sub create_svn_repo {
my $this = shift;
my $svn_repo = File::Spec->rel2abs( $this->{svn_repo} );
# automatically skip anything we don't need to bother doing
unless( -d $svn_repo ) {
einfo "creating svn repo: $this->{svn_repo}";
$this->logging_systemx(svnadmin => 'create', $svn_repo);
eend 1;
einfo "installing pre-revprop-change (svn:date only) hook";
my $prpc_file = "$svn_repo/hooks/pre-revprop-change";
my $prpc_text = slurp("$prpc_file.tmpl");
$prpc_text =~ s/svn:log/svn:date/g;
write_file( $prpc_file => $prpc_text );
chmod 0755, $prpc_file or edie "chmod() error: $!";
eend 1;
}
unless( -d $this->{svn_co} ) {
einfo "checking out new svn: $this->{svn_repo} -> $this->{svn_co}";
$this->logging_systemx(qw(svn co), "file://$svn_repo", $this->{svn_co});
eend 1;
}
$this;
}
# }}}
# add_svn_dir {{{
sub add_svn_dir {
my ($this, $cod) = @_;
$this->{_co} ||= File::Spec->rel2abs( $this->{svn_co} );
chdir $this->{_co} or edie "couldn't chdir into svn_co ($this->{svn_co}): $!";
my $r = File::Spec->rel2abs( $cod );
$r =~ s/^\Q$this->{_co}\E\///
or edie "$cod doesn't want to be located under $this->{svn_co}";
unless( -d $r ) {
ebegin "adding $cod to $this->{svn_co}";
eindent;
ebegin "mkdir -p $cod";
mkpath($r); # uses umask and 0777 to create
eend 1;
my @split = split m/\//, $r; $r = shift @split; {
ebegin "svn add $r";
$this->logging_systemx(qw(svn add), $r);
eend 1;
# NOTE: SVN apparnetly does this recursively
# if( @split ) {
# $r .= "/" . (shift @split);
# redo;
# }
}
ebegin "svn commit";
$this->logging_systemx(qw(svn commit -m), "git-svn-replay added $cod to $this->{svn_co}");
eend 1;
eoutdent;
eend 1;
}
$this;
}
# }}}
# stdoutlog {{{
sub stdoutlog {
my $this = shift;
return unless $this->{stdoutlog};
write_file( $this->{stdoutlog}, {append=>1}, scalar localtime, @_ );
$this;
}
# }}}
# logging_systemx {{{
sub logging_systemx {
my $this = shift;
my @res = eval { (capturex(@_), "my res pop") }; my $l = __LINE__;
my @c = caller;
unless( pop @res ) {
my $e = $@; $e =~ s/line $l/$c[2]/g;
edie $e;
}
$this->stdoutlog("-- execvp(@_)\n", @res);
$this;
}
# }}}
# quiet {{{
sub quiet {
no warnings 'redefine';
*eend = sub(@) {};
*einfo = sub($) {};
*ebegin = sub($) {};
*ewarn = sub($) {};
$_[0];
}
( run in 1.010 second using v1.01-cache-2.11-cpan-71847e10f99 )