Git-SVNReplay
view release on metacpan or search on metacpan
SVNReplay.pm view on Meta::CPAN
if( m/^\.(?:git|svn)\z/ ) {
$File::Find::prune = 1;
} elsif( not m/^\.{1,2}\z/ ) {
push @dirs, $File::Find::name;
}
}
}}, '.' );
if( my $parent = $this->{dbm}{replayed_commits_in_order}[-1] ) {
for my $f (@{ $this->{dbm}{last_files}{$parent} }) {
unless( -f $f ) {
einfo "removing file \"$f\" from svn: ";
$this->logging_systemx(qw(svn rm), $f);
eend 1;
$this->{dbm}{already_tracking_file}{$f} = 0;
}
}
for my $d (@{ $this->{dbm}{last_dirs}{$parent} }) {
unless( -d $d ) {
einfo "removing directory \"$d\" from svn: ";
$this->logging_systemx(qw(svn rm), $d);
eend 1;
$this->{dbm}{already_tracking_dir}{$d} = 0;
}
}
}
for my $d (@dirs) {
next if $this->{dbm}{already_tracking_dir}{$d};
einfo "adding directory \"$d\" to svn: ";
$this->logging_systemx(qw(svn add), $d);
eend 1;
$this->{dbm}{already_tracking_dir}{$d} = 1;
}
for my $f (@files) {
next if $this->{dbm}{already_tracking_file}{$f};
einfo "adding file \"$f\" to svn: ";
$this->logging_systemx(qw(svn add), $f);
eend 1;
$this->{dbm}{already_tracking_file}{$f} = 1;
}
ebegin "comitting changes to svn";
$this->logging_systemx(qw(svn commit -F .msg));
eend 1;
if( my $gdate = capturex(qw(git show -s --pretty=format:%at)) ) {
my $date = strftime('%Y-%m-%dT%H:%M:%S.000000Z', gmtime($gdate));
ebegin "changing commit date to $date";
$this->logging_systemx(qw(svn propset --revprop -r HEAD svn:date), $date);
eend 1;
} else {
ewarn "date not found for $commit";
}
$this->{dbm}{last_dirs}{$commit} = \@dirs;
$this->{dbm}{last_files}{$commit} = \@files;
# svn commits sometimes alters things causing git merge problems (very rare).
# 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\///
( run in 0.516 second using v1.01-cache-2.11-cpan-71847e10f99 )