[projects/distfiles/distfiles2: 1/7] add support for PACKAGE/sources file containing additional checksum of files

glen glen at pld-linux.org
Sat Dec 1 11:01:25 CET 2012


commit 0617e168d3e2bcc3c9b656a792d1afc8a59a0974
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Fri Nov 30 10:05:52 2012 +0200

    add support for PACKAGE/sources file containing additional checksum of files

 request-handler.pl |  2 +-
 show_spec.sh       |  7 ++++++-
 specparser.pl      | 37 +++++++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 2 deletions(-)
---
diff --git a/request-handler.pl b/request-handler.pl
index 91c6e30..41addce 100755
--- a/request-handler.pl
+++ b/request-handler.pl
@@ -86,7 +86,7 @@ print S "$spec\n";
 print S "$flags\n";
 close(S);
 
-if (system("perl ./specparser.pl \"tmp/$id/$spec\" >> tmp/$id/to-spool") != 0) {
+if (system("perl ./specparser.pl \"tmp/$id/$spec\" tmp/$id/sources >> tmp/$id/to-spool") != 0) {
   report_fatal("cannot parse $spec ($branch)")
 }
 
diff --git a/show_spec.sh b/show_spec.sh
index 0b085a5..517f2f5 100755
--- a/show_spec.sh
+++ b/show_spec.sh
@@ -15,8 +15,13 @@ export GIT_DIR=`mktemp -d gitemp.XXXXXX --tmpdir`
     git ls-tree --name-only FETCH_HEAD | grep '.spec$' | while read file; do
         git show FETCH_HEAD:$file > $package || exitcode=1
     done
+
+    # checkout additional file for source/patch-md5
+    file=sources
+    if git ls-tree --name-only FETCH_HEAD | grep -q ^$file$; then
+        git show FETCH_HEAD:$file > $file || exitcode=1
+    fi
 )
 exitcode=$?
 rm -rf $GIT_DIR
 exit $exitcode
-
diff --git a/specparser.pl b/specparser.pl
index d449145..e2274e9 100755
--- a/specparser.pl
+++ b/specparser.pl
@@ -21,6 +21,8 @@ my $spec;
 my $base_spec;
 my @spec;
 my @sources;
+my $sources;
+my %patchset;
 
 sub next_spec($)
 {
@@ -121,6 +123,12 @@ sub preparse_spec($) # {{{
             push @spec, $_;
         } elsif (/^NoSource\s*:\s*(\d+)\s*$/i) {
             $no_source{ "source" . $1 } = 1;
+        } elsif (my ($patchset_pattern, $patchset_start, $patchset_end) = /^%patchset_source.+-f\s+(\S+)\s+(\S+)\s+(\S+)/i) {
+            %patchset = (
+                pattern => $patchset_pattern,
+                start => $patchset_start,
+                end => $patchset_end
+            );
         }
     }
     close(F);
@@ -128,6 +136,30 @@ sub preparse_spec($) # {{{
     shift @spec;
 } # }}}
 
+sub process_patchset($) {
+    my $macros = shift;
+    return unless %patchset or $sources;
+
+    # parse sources file
+    my %files;
+    open(my $fh, '<', $sources) or die $!;
+    while (<$fh>) {
+        chomp;
+        next unless my ($hash, $filename) = /^([a-f0-9]{32})\s+\*?(.+)$/;
+        $files{$filename} = $hash;
+    }
+
+    # print out patchset entries which source md5 is present in source file
+    my $start = expand($patchset{start}, $macros);
+    my $end = expand($patchset{end}, $macros);
+    for (my $i = $start; $i < $end; $i++) {
+        my $url = sprintf($patchset{pattern}, $i);
+        my ($basename) = $url =~ m{/([^/]+$)};
+        my $hash = $files{$basename} or next;
+        printf "%s %s\n", $hash, $url;
+    }
+}
+
 
 my $total = 0;
 
@@ -184,6 +216,9 @@ sub cont($$) # {{{
         }
     }
 
+    # so we have macros now, can parse patchset source
+    process_patchset($macros);
+
     # the end, yuppie !
     foreach my $s (@sources) {
         my $src = expand( $s->[2], $macros );
@@ -277,6 +312,8 @@ sub add_md5_to_print($) # {{{
 } # }}}
 
 next_spec(shift);
+$sources = shift if @ARGV;
+undef $sources if $sources and not -e $sources;
 preparse_spec($spec);
 add_md5_to_print($spec);
 cont( \@spec, { "nil" => "" } );
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/distfiles.git/commitdiff/baa40c188f518f942b1d8ad3584b44652d6ea9c6



More information about the pld-cvs-commit mailing list