#!/usr/bin/env perl # $Id$ # Public domain. Originally written by Karl Berry, 2022. # # Update from CTAN to TL. First, run the test import with c2l; then, if # no files were added or removed (and it was an existing package), # automatically run c2l -p to "place" the new package in svn. # Do not run svn commit. (Code needs to be refactored for common calls.) use strict; use warnings; (my $prg = $0) =~ s,.*/,,; my $place_branch = 0; #my $chicken = ""; my $chicken = "-p"; exit (&main ()); sub main { my $place = 0; if ($ARGV[$#ARGV] =~ /^-?p$/) { pop (@ARGV); $place = 1; } printf "$prg: running c2l..."; my @lines = `set -o pipefail; c2l @ARGV &1 | tee /tmp/c2l.out`; if ($?) { print "first c2l failed, exiting.\n"; print @lines; exit $?; } my $status = 1; my $i; for ($i = 0; $i < @lines; $i++) { if ($lines[$i] =~ /^current vs.\ new/) { my $nextline = $lines[$i+1]; if ($nextline =~ /^[0-9]+ common files, ([0-9]+) changed/) { if ($1 == 0) { print "seems nothing changed, done.\n"; print @lines; $status = 0; last; } else { $status = &do_place ("no new or removed files"); last; } } elsif ($place) { $status = &do_place ("new/removed files, but p(lace) given"); last; } else { print "have new/removed files, exiting.\n"; print @lines; last; } } } if ($i == @lines) { if ($place) { $status = &do_place ("no current vs. new, but p(lace) given"); } else { print "no current vs. new, exiting.\n"; # new package, presumably print @lines; } } return $status; } sub do_place { my ($desc,$c2cmd) = @_; my $msg; if ($c2cmd && $c2cmd eq "c2b") { $msg = "$prg: $desc"; # place on branch } else { $c2cmd = "c2l"; my $branch_msg = $place_branch ? "(+branch)" : ""; $msg = "$desc, rerunning for svn$branch_msg..."; } print "$msg\n"; my $cmd = "set -o pipefail;" . "$c2cmd $chicken @ARGV &1 | tee /tmp/$c2cmd.out"; my @placelines = `$cmd`; my $status = $?; print @placelines; if ($status) { print "$prg: *** do_place($c2cmd) failed, exiting.\n"; } elsif ($c2cmd ne "c2b" && $place_branch) { $status = &do_place ("running c2b for svn branch", "c2b"); } return $status; }