]> git.donarmstrong.com Git - bin.git/blobdiff - archive_analysis
add reset usb bus command
[bin.git] / archive_analysis
index a413f992def97f81f0b05f4a6e10ea26d6cb3a43..2294a4b6ce065c80ef35bc192648ecf84753a54c 100755 (executable)
@@ -52,6 +52,7 @@ archive_analysis
 
 use File::Spec;
 use File::Copy;
+use Cwd;
 
 use vars qw($DEBUG);
 
@@ -92,27 +93,42 @@ for my $file (@ARGV) {
     if (not defined $vcs) {
         fail("Unable to determine which VCS this is");
     }
-    my $revision = find_vcs_revision($vcs,$file);
+    my $revision = find_vcs_revision($file,$vcs);
     if (not defined $revision) {
         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;
@@ -123,15 +139,21 @@ sub determine_vcs {
 }
 
 sub find_vcs_revision{
-    my ($vcs,$file) = @_;
+    my ($file,$vcs) = @_;
+    if (not defined $vcs) {
+        $vcs = determine_vcs($file);
+    }
 
     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");
@@ -145,6 +167,9 @@ sub fail {
     exit 1;
 }
 
+sub make_list {
+     return map {(ref($_) eq 'ARRAY')?@{$_}:$_} @_;
+}
 
 
 __END__