chiark / gitweb /
Merge branch 'stable-5.x'
[ypp-sc-tools.db-test.git] / yarrg / Commods.pm
index d9e9d34e48214fc3bfb5bb5168dff3e3572dc76b..5161af2e8a05a121ca690d41662ebd9012bb8c63 100644 (file)
@@ -22,6 +22,7 @@
 
 package Commods;
 use IO::File;
+use IO::Pipe;
 use HTTP::Request::Common ();
 use POSIX;
 use LWP::UserAgent;
@@ -45,7 +46,8 @@ BEGIN {
                      &pipethrough_run_gzip &http_useragent &version_core
                      &http_useragent_string_map
                      &cgipostform &yarrgpostform &cgi_get_caller
-                     &set_ctype_utf8 $masterinfoversion);
+                     &set_ctype_utf8 $masterinfoversion
+                     &source_tarball);
     %EXPORT_TAGS = ( );
 
     @EXPORT_OK   = qw();
@@ -192,6 +194,7 @@ sub parse_info1 ($$$) {
        
     %commods= ();
     my $ca;
+    my $lnoix=0;
     $ca= sub {
        my ($s,$ss,$ordbase) = @_;
 #print STDERR "ca($s,,".(defined $ordbase ? $ordbase : '?').")\n";
@@ -214,8 +217,9 @@ sub parse_info1 ($$$) {
                    $c->{Class}= $1;
                    die "$1" unless exists $commodclasses{$1};
                    $ordclassval= 1e7 + $commodclasses{$1} * 1e7;
-               } elsif ($prop =~ m/^\@(\d+)$/) {
+               } elsif ($prop =~ m/^\@(\d+\+?)$/) {
                    $ordval= $1;
+                   $ordval =~ s/^(\d+)\+$/ $1 + $lnoix * 10 /e;
                } else {
                    die "unknown property $prop for $ucname";
                }
@@ -239,7 +243,7 @@ sub parse_info1 ($$$) {
                     ? $ordbase+$ordcolour : undef);
        }
     };
-    foreach (@rawcm) { &$ca($_,$src,0); }
+    foreach (@rawcm) { $lnoix++; &$ca($_,$src,0); }
 }
 
 sub parse_info_clientside () {
@@ -266,6 +270,7 @@ sub fetch_with_rsync ($) {
 
 sub parse_info_serverside () {
     parse_info1('source-info.txt','s',0);
+    parse_info1('tree-info.txt','t',1);
 }
 sub parse_info_serverside_ocean ($) {
     my ($oceanname) = @_;
@@ -470,4 +475,38 @@ sub http_useragent ($) {
     return $ua;
 }
 
+sub source_tarball ($$) {
+    my ($sourcebasedir,$spitoutfn) = @_;
+
+    my $pipe= new IO::Pipe or die $!;
+    my $pid= fork();  defined $pid or die $!;
+    if (!$pid) {
+       $ENV{'YPPSC_YARRG_SRCBASE'}= $sourcebasedir;
+       $pipe->writer();
+       exec '/bin/sh','-c','
+               cd -P "$YPPSC_YARRG_SRCBASE"
+               (
+                git-ls-files -z;
+                git-ls-files -z --others --exclude-from=.gitignore;
+                if test -d .git; then find .git -print0; fi
+               ) | (
+                cpio -Hustar -o --quiet -0 -R 1000:1000 || \
+                cpio -Hustar -o --quiet -0
+               ) | gzip
+       ';
+       die $!;
+    }
+    $pipe->reader();
+
+    my ($d, $l);
+    while ($l= read $pipe, $d, 65536) {
+       $spitoutfn->($d);
+    }
+    waitpid $pid,0;
+    defined $l or die "read pipe $!";
+    $pipe->error and die "pipe error $!";
+    close $pipe;
+    # deliberately ignore errors
+}
+
 1;