use File::Spec;
use File::Copy;
+use Cwd;
use vars qw($DEBUG);
fail("Unable to determine which revision this is");
}
my $new_file = $file;
- $new_file =~ s{(\.[^\./]{,5}|)$}{_$revision$1};
- my ($v,$d,$nf) = File::Spec->splitfile($new_file);
+ $new_file =~ s/(\.[^\.\/]{1,5}|)$/_$revision$1/;
+ my ($v,$d,$nf) = File::Spec->splitpath($new_file);
for my $dir (make_list($options{archive_dir})) {
my $loc = File::Spec->join($dir,$nf);
+ next if -e $loc;
copy($file,$loc) or
fail("Unable to copy file $file to $loc: $!\n");
+ if ($options{git_annex}) {
+ git_annex($loc);
+ }
}
}
+sub git_annex{
+ my ($file) = @_;
+
+ my $abs_path = File::Spec->rel2abs($file);
+ my ($v,$d,$nf) = File::Spec->splitpath($abs_path);
+ my $old_dir = getcwd();
+ chdir($d);
+ system('git','annex','add',$nf);
+ chdir($old_dir);
+}
+
sub determine_vcs {
my ($file) = @_;
my $abs_path = File::Spec->rel2abs($file);
my @dirs = File::Spec->splitdir($abs_path);
- for my $i ($#dirs..0) {
- my $dir = File::Spec->catdir(@dirs[$i..0]);
+ for my $i (reverse 0..$#dirs) {
+ my $dir = File::Spec->catdir(@dirs[0..$i]);
for my $vcs (qw(git svn bzr)) {
if ( -e File::Spec->catdir($dir,'.'.$vcs)) {
return $vcs;
if ($vcs eq 'git') {
my $old_dir = getcwd();
my $abs_path = File::Spec->rel2abs($file);
- my ($v,$d,$nf) = File::Spec->splitfile($abs_path);
+ my ($v,$d,$nf) = File::Spec->splitpath($abs_path);
chdir($d);
my $branch = qx(git name-rev --name-only HEAD);
+ chomp $branch;
my $rev = qx(git rev-parse --short HEAD);
+ chomp $rev;
+ chdir($old_dir);
return $branch.'@'.$rev;
} else {
fail("vcs $vcs not currently supported");
exit 1;
}
+sub make_list {
+ return map {(ref($_) eq 'ARRAY')?@{$_}:$_} @_;
+}
__END__