From b244ddf7ca433b54e372b7d3267e742cd1674d26 Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Sun, 18 Oct 2015 15:18:30 +0200 Subject: [PATCH] Re-fixed bug #45841: Replacement string for total no of jobs. --bar works, too. --- src/parallel | 21 ++++++++-------- src/parallel.pod | 7 ++++-- testsuite/tests-to-run/parallel-local-0.3s.sh | 11 +++++---- testsuite/wanted-results/parallel-freebsd | 2 +- testsuite/wanted-results/parallel-local-0.3s | 24 +++++++++++++++---- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/parallel b/src/parallel index 14436175..323a8e91 100755 --- a/src/parallel +++ b/src/parallel @@ -5614,7 +5614,7 @@ sub sshcommand_of_sshlogin { $sshcmd = $opt::ssh; $serverlogin = $self->{'string'}; } } - + if($serverlogin =~ s/(\S+)\@(\S+)/$2/) { # convert user@server to '-l user server' # because lsh does not support user@server @@ -5748,7 +5748,7 @@ sub new { return bless { 'unget' => \@unget, 'commandlinequeue' => $commandlinequeue, - 'this_job_no' => 1, + 'this_job_no' => 0, 'total_jobs' => undef, }, ref($class) || $class; } @@ -5756,17 +5756,15 @@ sub new { sub get { my $self = shift; + $self->{'this_job_no'}++; if(@{$self->{'unget'}}) { - $self->{'this_job_no'}++; - my $job = shift @{$self->{'unget'}}; - return ($job); + return shift @{$self->{'unget'}}; } else { my $commandline = $self->{'commandlinequeue'}->get(); if(defined $commandline) { - $self->{'this_job_no'}++; - my $job = Job->new($commandline); - return $job; + return Job->new($commandline); } else { + $self->{'this_job_no'}--; return undef; } } @@ -5819,8 +5817,11 @@ sub total_jobs { } } $record_queue->unget(@arg_records); - $self->{'total_jobs'} = $#arg_records+1+$self->{'this_job_no'}; - ::debug("init","Total jobs: ".$self->{'total_jobs'}."\n"); + $self->{'total_jobs'} = + ::ceil((1+$#arg_records+$self->{'this_job_no'}) + / ::max($Global::max_number_of_args,1)); + ::debug("init","Total jobs: ".$self->{'total_jobs'}. + " (".(1+$#arg_records)."+".$self->{'this_job_no'}.")\n"); } return $self->{'total_jobs'}; } diff --git a/src/parallel.pod b/src/parallel.pod index 2b49aa01..65dd54c0 100644 --- a/src/parallel.pod +++ b/src/parallel.pod @@ -1198,13 +1198,16 @@ control on the command line (used by GNU B internally when called with B<--sshlogin>). -=item B<--plus> +=item B<--plus> (alpha testing) Activate additional replacement strings: {+/} {+.} {+..} {+...} {..} -{...} {/..} {/...}. The idea being that '{+foo}' matches the opposite of +{...} {/..} {/...} {##}. The idea being that '{+foo}' matches the opposite of '{foo}' and {} = {+/}/{/} = {.}.{+.} = {+/}/{/.}.{+.} = {..}.{+..} = {+/}/{/..}.{+..} = {...}.{+...} = {+/}/{/...}.{+...} +B<{##}> is the number of jobs to be run. It is incompatible with +B<-X>/B<-m>/B<--xargs>. + =item B<--progress> diff --git a/testsuite/tests-to-run/parallel-local-0.3s.sh b/testsuite/tests-to-run/parallel-local-0.3s.sh index d5a9b5d9..bd202c66 100644 --- a/testsuite/tests-to-run/parallel-local-0.3s.sh +++ b/testsuite/tests-to-run/parallel-local-0.3s.sh @@ -233,10 +233,10 @@ parallel --wd . 'pwd; echo $OLDPWD; echo' ::: OK echo '**' echo 'bug #46232: {%} with --bar/--eta/--shuf or --halt xx% broken' - parallel --bar -kj2 echo {%} ::: a b ::: c d e 2>/dev/null - parallel --halt now,fail=10% -kj2 echo {%} ::: a b ::: c d e - parallel --eta -kj2 echo {%} ::: a b ::: c d e 2>/dev/null - parallel --shuf -kj2 echo {%} ::: a b ::: c d e 2>/dev/null + parallel --bar -kj2 --delay 0.1 echo {%} ::: a b ::: c d e 2>/dev/null + parallel --halt now,fail=10% -kj2 --delay 0.1 echo {%} ::: a b ::: c d e + parallel --eta -kj2 --delay 0.1 echo {%} ::: a b ::: c d e 2>/dev/null + parallel --shuf -kj2 --delay 0.1 echo {%} ::: a b ::: c d e 2>/dev/null echo '**' @@ -251,6 +251,9 @@ echo '{##} bug #45841: Replacement string for total no of jobs' parallel --plus echo {##} ::: {a..j}; parallel -k 'echo {= $::G++ > 3 and ($_=$Global::JobQueue->total_jobs());=}' ::: {1..10} + parallel -N7 --plus echo {#} {##} ::: {1..14} + parallel -N7 --plus echo {#} {##} ::: {1..15} + parallel -X --plus echo {#} {##} ::: {1..15} echo '**' diff --git a/testsuite/wanted-results/parallel-freebsd b/testsuite/wanted-results/parallel-freebsd index 8f17f019..4641378d 100644 --- a/testsuite/wanted-results/parallel-freebsd +++ b/testsuite/wanted-results/parallel-freebsd @@ -69,6 +69,6 @@ Non-shellshock-hardened to shellshock-hardened Function shellshock-hardened echo '### Test --load (must give 1=true)' ### Test --load (must give 1=true) - parallel -j0 -N0 --timeout 5 --nice 10 'bzip2 < /dev/zero >/dev/null' ::: 1 2 3 & parallel --argsep ,, --joblog - -N0 parallel --load 100% echo ::: 1 ,, 1 | parallel --colsep '\t' --header : echo '{=4 $_=$_>5=}' + parallel -j0 -N0 --timeout 5 --nice 10 'bzip2 < /dev/zero >/dev/null' ::: 1 2 3 4 5 6 & parallel --argsep ,, --joblog - -N0 parallel --load 100% echo ::: 1 ,, 1 | parallel --colsep '\t' --header : echo '{=4 $_=$_>5=}' 1 diff --git a/testsuite/wanted-results/parallel-local-0.3s b/testsuite/wanted-results/parallel-local-0.3s index dd673dd4..1053c8b3 100644 --- a/testsuite/wanted-results/parallel-local-0.3s +++ b/testsuite/wanted-results/parallel-local-0.3s @@ -479,28 +479,28 @@ echo '**' ** echo 'bug #46232: {%} with --bar/--eta/--shuf or --halt xx% broken' bug #46232: {%} with --bar/--eta/--shuf or --halt xx% broken - parallel --bar -kj2 echo {%} ::: a b ::: c d e 2>/dev/null + parallel --bar -kj2 --delay 0.1 echo {%} ::: a b ::: c d e 2>/dev/null 1 2 1 2 1 2 - parallel --halt now,fail=10% -kj2 echo {%} ::: a b ::: c d e + parallel --halt now,fail=10% -kj2 --delay 0.1 echo {%} ::: a b ::: c d e 1 2 1 2 1 2 - parallel --eta -kj2 echo {%} ::: a b ::: c d e 2>/dev/null + parallel --eta -kj2 --delay 0.1 echo {%} ::: a b ::: c d e 2>/dev/null 1 2 1 2 1 2 - parallel --shuf -kj2 echo {%} ::: a b ::: c d e 2>/dev/null + parallel --shuf -kj2 --delay 0.1 echo {%} ::: a b ::: c d e 2>/dev/null 1 2 1 @@ -542,6 +542,22 @@ echo '{##} bug #45841: Replacement string for total no of jobs' 10 10 10 + parallel -N7 --plus echo {#} {##} ::: {1..14} +1 2 2 2 2 2 2 2 +2 2 2 2 2 2 2 2 + parallel -N7 --plus echo {#} {##} ::: {1..15} +1 3 3 3 3 3 3 3 +2 3 3 3 3 3 3 3 +3 3 + parallel -X --plus echo {#} {##} ::: {1..15} +1 15 15 +2 15 15 +3 15 15 +4 15 15 +5 15 15 +6 15 15 +7 15 15 +8 15 echo '**' ** ### 1 .par file from --files expected